Developer forum

Forum » Development » Notify on every cart step (v1)

Notify on every cart step (v1)

Nuno Aguiar
Reply
Hi,

We have to limit products to shops according the Shop configured in the paragraph. The question in that we need to run our code in every cart v1 step. Is there a best/safe way to do that?

Basically when we detect products from another eComShop we need to empty the cart, so any further actions are irrelevant (discounts, shippings, etc...).

Should we simply run our code on every notification we encounter?

Nuno

Replies

 
Diogo Lino
Reply
Hi, adding more information to the question, to catch the event on every load of the cart (v1) we have the code:
[Dynamicweb.Extensibility.Subscribe(Dynamicweb.Notifications.eCommerce.Cart.Loaded)]
    public class CartLoadSubscriber : Dynamicweb.Extensibility.NotificationSubscriber
    {
        public override void OnNotify(string notification, object[] args)
        {
            Order order = null;
            Extranet extranet = null;
            PageView pageView = null;

            if (args.Length > 0 && args[0] != null)
            {
                order = (Order)args[0];
                Product product1 = order.Products[0];
                Group group1 = product1.Groups.get_Item(0);
                string shopId = group1.ShopID;
            }

            if (args.Length > 1 && args[1] != null)
            {
                extranet = (Extranet)args[1];
            }

            if (args.Length > 2 && args[2] != null)
            {
                pageView = (PageView)args[2];
            }

The args array allways brings just one position, with the Order object. I can get the ShopID from a product through its group, as you can see. Now I want to compare if that ShopID is the same as the Shop configured on the shopping cart module in the paragraph.

Or if it is not possible, at least to know the current AreaId and I will make a table with the correspondence of a ShopID to a AreaId, but a less efficient solution.

By the way, I also want to make this validation on every step of the order process, but the problem is when a user re-orders an already made order, which I think is on the CustomerCenter module. What event should I subscribe for the user re-order?

Thanks,
Diogo Lino
 


 
Nicolai Høeg Pedersen
Reply
May I ask why on earth you are doing development against the Cartv1 - and not converting the templates to Cartv2 and code against that?

Cartv1 is deprecated, still supported though, but go with v2 please!

 
Nuno Aguiar
Reply
Hi Nicolai,

I know it's a bummer. We needed a quick fix on specific solution because of a lot of custom development. We cannot afford to simply update it free of charge right now

Rest assure, it's going to be updated  :)

Best Regards,
Nuno
 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer
Glad to hear :-).

The best way is to make a method that you can call, and then make a notification subscriber for each of the steps in Cartv1 that calls that method.

Votes for this answer: 0
 
Nuno Aguiar
Reply
Hi Nicolai,

Yes, that was the original idea, but when I asked I actually meant the best DW notification to subscribe to. We managed with Before.Render and it's working great.

Thanks,
Nuno

 

You must be logged in to post in the forum