Developer forum
E-mail notifications
Change variant on a produkt in cart
I found this but no doc. on how to use it http://developer.dynamicweb-cms.com/forum/development/all-cart-commands-(cartcmd).aspx
Replies
You've probably already found a solution, but it may be my answer will help someone else:
there is Kevin Steffer's wonderful article on his blog:
Howto implement an AJAX based shopping experience in Dynamicweb eCommerce
You can see examle of it implementations here: http://mixofluxe.spiritwholesale.com/Produktvisning-550.aspx?ProductID=01059ML
Regards,
Vladimir
Hi
The links in Vladimirs answer are not working anymore. Anyone who now how to update the variant on an orderline in the cart?
Hi Lars
Variants cannot be changed, but you can remove and add the product. You can only update quantity and stock location.
When you render the product in the cart, you can add a variant selector. If another variant is selected, using ajax or other magic, you can remove the existing product and add a new one using js.
See cart commands available:
https://doc.dynamicweb.com/documentation-9/ecommerce/frontend/cart-commands
Hi Nicolai
We have tried what you propose, but removing the existing product and adding a new one adds the new one to the end of the orderlines. We would very much like to avoid that and update the existing orderline. I was just wondering if it is possible in kind of the same way as it is possible to update custom orderline fields?
Just a quick follow up question for Nicolai,
As Lars mension, our main goal is to avoid the product line to be moved to the end of the order lines.
Forexample if a user have put a 1L pain bucket in he's basket, and in the basket, he would like to change it to a 5L bucket.
Looking in the database, it seems like the key in the EcomOrderLines is the Field OrderLineId, and then I am guessing the order lines are rendered in order by OrderLineId, and that is why deleting and adding a order line, puts it in the end of the order.
Is that more or less correct?
No "easy" way to control the render order of the orderlines?
Hi Per
Yes, orderlines are ordered by OrderLineID, OrderLineParentLineID.
You can fairly simple update the variant in your razor template - something like this:
@{ var customCartCommand = Dynamicweb.Context.Current.Request.QueryString["customCartCommand"]; if (customCartCommand.Equals("updatevariantid")) { var orderlineid = Dynamicweb.Context.Current.Request.QueryString["CustomUpdateOrderlineID"]; var newVariantId = Dynamicweb.Context.Current.Request.QueryString["CustomUpdateNewVariantID"]; var cart = Dynamicweb.Ecommerce.Common.Context.Cart; foreach (var orderline in cart.OrderLines) { if (orderline.Id.Equals("orderlineid")) { orderline.ProductVariantId = newVariantId; //orderline.ProductVariantId = "5L"; } } Dynamicweb.Ecommerce.Services.Orders.Save(cart); Dynamicweb.Context.Current.Response.Redirect("/Default.aspx?ID=1234"); } }
The redirect is important to get rid of the querystring parameters and to ensure that minicart etc. are recalculated (they have already loaded and rendered at this point).
You must be logged in to post in the forum