Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • egeek 40 posts 179 karma points
    Mar 31, 2014 @ 19:33
    egeek
    0

    order.ToXml when changing order status

    When a order is finalized, I want TeaCommerce to send the customer information to Unifaun / Pacsoft and print a label automatically. 

    The customer already has a webshop, and as I understand it their current shop (not TeaCommerce/Umbraco)  creates an XML file which is placed in a folder Unifaun Online Connect listenes to. 

    I want to achieve the same in TeaCommerce. I was thinking best practise would be to hook into order status, when a order changes from "New" to "Completed". In this hook I would create an XML file of the order, place it in a folder or transfer with FTP. Unifaun will then grab the XML file, print a label and send the data to Post Danmark. Thoughts?

    Anders, you told me to use order.ToXml(), but I'm kinda lost. How do I hook into order status, and is it even possible? 

    No other people who have experience with Unifaun/Pacsoft and TeaCommerce?

    I'm running TC 2.2.3

  • Anders Burla 2560 posts 8256 karma points
    Apr 01, 2014 @ 08:23
    Anders Burla
    0

    Hi

    You should use the NotificationCenter and the order.Finalized event so you can be notified when an order is completed.
    http://documentation.teacommerce.net/net-api/notification-center/

    Kind regards
    Anders

  • egeek 40 posts 179 karma points
    Apr 06, 2014 @ 19:47
    egeek
    100

    Hi Anders,

    Thanks! Got it working after some playing around.

    I found out that Order.Finalized get's fired after the order is placed in the shop, not after changing order status from "New" to "Completed".

    The solution was to hook into OrderStatusChanged and test if order status was set to completed. Here's how I did it:

    using TeaCommerce.Api.Serialization;
    using Umbraco.Core;
    using TeaCommerce.Api.Models;
    using TeaCommerce.Api.Notifications;
    
    namespace Web.EventHandlers
    {
        public class ApplicationStartup : ApplicationEventHandler
        {
            public ApplicationStartup()
            {
                NotificationCenter.Order.OrderStatusChanging += Order_OrderStatusChanging;
                NotificationCenter.Order.OrderStatusChanged += Order_OrderStatusChanged;
            }
    
            //Hook into order status changed (debug)
            private void Order_OrderStatusChanged(Order order)
            {
                //Wirte the order status id (debug)
                string[] lines = { order.OrderStatusId.ToString() };
                System.IO.File.WriteAllLines(@"C:\Temp\OrderStatus.txt", lines);
            }
    
            //Hook into order status changing (need to be this event and not changed, otherwise OrderStatusId == 2 won't work
            void Order_OrderStatusChanging(Order order)
            {
                if (order.OrderStatusId == 2)
                {
                    order.ToXml().Save(@"C:\Temp\order.xml");
                }
    
            }
    
        }
    }
    
  • Anders Burla 2560 posts 8256 karma points
    Apr 07, 2014 @ 08:29
    Anders Burla
    0

    Order status doesnt change because the order is finalized. It is more a system for webshop owners to make an order flow.

    But glad you got it working.

    Kind regards
    Anders

Please Sign in or register to post replies

Write your reply to:

Draft