foreach (OrderForm form in CartHelper.Cart.OrderForms) { foreach (var disc form.Discounts.Cast().Where(x => !String.IsNullOrEmpty(x.DiscountCode))) { AddInDiscountList(disc); } }
I tried the CartHelper.GetCartPromotions, but it returned nothing for me.
I got the Promotion from PromotionManager and compared it's CouponCode with my entered "code".
Dictionary<PromotionDto.PromotionRow, decimal?> entryDiscountApplicationCount = new Dictionary<PromotionDto.PromotionRow, decimal?>(); PromotionDto promotionDto = PromotionManager.GetPromotionDto(FrameworkContext.Current.CurrentDateTime); foreach (PromotionDto.PromotionRow promotion in promotionDto.Promotion.Where(x => x.CouponCode.Equals(code))) { if (!promotion.IsMaxEntryDiscountQuantityNull()) { entryDiscountApplicationCount.Add(promotion, promotion.MaxEntryDiscountQuantity); } }
Now I've got my promotion set up here, with coupon code. And the reward is that you get off 10%
https://gyazo.com/53527a317b2b84848ed9ca0d106043ed (picture)
The question is,
How can I use that reward on my cart lineItems ? Or Cart.SubTotal?
Or maybe I can somehow add that promotion to the OrderForm.Discounts?
Sorry if I didn't phrase my problem accurately.
Regards,
A
Hi,
Maybe I'm missing something here, but you didn't add the condition for the promotion?
/Q
Hi Quan,
Yes I did not, because I did not find the condition I'm looking for. There were conditions only for LineItems if I'm correct?
But I'd like to enter a discount code and apply it to the whole cart.
Or how should I approach this? Or should I enter some condition to match all products in the cart and then 10% can be taken off from each product?
Regards,
A
Hi,
Depends on the type of promotion you're creating, you can create condition for LineItem or order or shipment.
I don't think you have to get all the promotion codes to check, instead, you should only add the promotion code to the order and let the promotion engine do it for you. You can take a look at our Sample site to see how it's done.
MarketingContext.Current.AddCouponToMarketingContext(DiscountCouponCode.Text); var isEmpty = CartHelper.IsEmpty; // Make sure to check that prices has not changed if (!isEmpty) { CartHelper.Cart.ProviderId = "FrontEnd"; CartHelper.RunWorkflow(Constants.CartValidateWorkflowName); CartHelper.Cart.AcceptChanges(); }
Regards,
/Q
Hello again,
I now added promotion for order, but when I run the RunWorkflow for CartHelper then it removes all products from the cart. Also Total and SubTotal values are 0.
Did I miss something? The CartHelper.RunWorkFlow() method doesn't give any errors either.
Regards,
A
Hi,
The workflow can remove the lineitems from cart in those cases:
- The lineitem is no longer available
- There are not enough quantity in inventories to fullfil the order.
You can download our workflow project, here: http://world.episerver.com/download/Items/EPiServer-Commerce/episerver-commerce-8-tools-and-code-samples/
build it and debug to see why your line items are deleted. One thing to look into is ValidateItems in CheckInventoryActivity.
Regards.
/Q
Hi,
I have an input to enter a coupon/discount code in the cart view.
But I'm having trouble getting all the promotion codes in my cart controller to check against the entered discount code.
How do I get all promotion's codes ? Should I use PromotionHelper, MarketingContext, PromotionProcessor or something else? I'm a little confused. Please help.
Or am I approching this wrong?
Using version 8.13