November Happy Hour will be moved to Thursday December 5th.

Adding a new line item to a basket

Vote:
 

Hello,

We would like to add a new line item to a basket (instead of using CartHelper.AddEntry, which would just append the quantity if the entry is already in the cart). However this seems to be a very "manual" process, the CartHelper.CreateLineItem method is private, so we would have to rewrite this method, then manually set PlacedPrice, Quantity, Code, Name/Display Name etc.

Is there something I'm missing? It just seems odd having to rewrite code already in the EPi dlls. Is there a flag or something I can pass to AddEntry which will do this?

Thanks!


Dean

#145343
Mar 02, 2016 11:11
Vote:
 

Hi,

The project which contains CartHelper (Mediachase.Commerce.Website) is open-source and you can modify it your self http://world.episerver.com/download/Items/EPiServer-Commerce/episerver-commerce-9-tools-and-code-samples/

Regards,

/Q

#145363
Mar 02, 2016 14:10
Vote:
 

Hi,

I am not sure about question but if I am correct in understanding you can use one of those

public virtual LineItem AddEntry(Entry entry);

public virtual LineItem AddEntry(Entry entry, bool fixedQuantity);

public virtual LineItem AddEntry(Entry entry, params CartHelper[] helpersToRemove);

public virtual LineItem AddEntry(Entry entry, bool fixedQuantity, params CartHelper[] helpersToRemove);

public virtual LineItem AddEntry(Entry entry, decimal quantity, bool fixedQuantity, string warehouseCode, params CartHelper[] helpersToRemove);

a line item can also be added in OrderForm.LineItemCollection I guess

/K

#145365
Mar 02, 2016 14:16
Vote:
 

CartHelper.AddEntry will wrap up the items by default. Unfortunately there is no flag to control this, but you can re-implement the relevant methods in CartHelper (as they are private). From what I've heard there will eventually be a surgery on CartHelper since it's not a very helpful (or extendable) class.

Also check Quan's answer in other topic: http://world.episerver.com/forum/developer-forum/Episerver-Commerce/Thread-Container/2016/3/several-rows-in-tha-cart-for-same-variant/

#147308
Edited, Apr 11, 2016 16:21
Vote:
 

I used Quan's code in the link above, worked perfect.

#147327
Apr 12, 2016 9:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.