Developer forum

Forum » Development » Remove x qty of a product from orderline

Remove x qty of a product from orderline

Kasper Legarth
Reply

Is it possible to remove x number of a product in the cart. Without retrieving the whole cart first?

Is have a page where i through the client adds product to the cart async. I use fetch and the cart command "AddMulti" for this purpace. (And som more stuff in between with loading trhough products, adding them as "new formData()")

Lets say the user have added 9 of a product but only needed 7. Is it possible to send a command saying "Remove 2 times {{product number}} from cart" on the same page. Or do i have to have to redirect the user to the cart and make them change it there?

 

Thanks in advanced

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Kasper

You can use the command Updateorderlines - see: https://doc.dynamicweb.com/template-tags/introduction/ecommerce/cart-commands#10186 - with that you cannot remove 2 from 9, but you can set the new number (9-2)

You also have a decreaseorderline command - but it will remove only one at a time: https://doc.dynamicweb.com/template-tags/introduction/ecommerce/cart-commands#10182

BR Nicolai

 
Kasper Legarth
Reply

Hi Nicolai.

So all in all, i need to get the orderlineid after adding to cart to make it happend? It is not possible to update to a new number on a product instead? 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Setmulti is what you need?

https://doc.dynamicweb.com/template-tags/introduction/ecommerce/cart-commands#10180

 
Kasper Legarth
Reply

Not exactly-

There is an edge case. Where a user can put 10 x product 1 in the basket. Shops around with other products. Goes back to product 1. Add 9 to basket. If i now set the qty to be 9-2 i would be 7 and not 17.

Its properly not likly but not impossible that this would happen. 

So it seems that i would need to retrieve the orderline first so i can check how many products there is in total of the product. And then setmulti? 🤷‍♂️

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Yes - the options on the cart commands page is the available options for cart manipulation.

I am not sure how "Remove 2" would work and make sense in that scenario as well. 

 

You must be logged in to post in the forum