Coupon/discount code for cart discount.

Vote:
 

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

#132679
Aug 17, 2015 14:04
Vote:
 

Hi, have you tried GetCartPromotions (under CartHelper)?
/K

#132701
Aug 17, 2015 16:35
Vote:
 
foreach (OrderForm form in CartHelper.Cart.OrderForms)
{
foreach (var disc form.Discounts.Cast().Where(x => !String.IsNullOrEmpty(x.DiscountCode)))
{
AddInDiscountList(disc);
}
}



#132702
Aug 17, 2015 16:42
Vote:
 

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

#132709
Aug 17, 2015 17:42
Vote:
 

Hi,

Maybe I'm missing something here, but you didn't add the condition for the promotion?

/Q

#132712
Aug 17, 2015 19:32
Vote:
 

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

#132717
Aug 18, 2015 8:52
Vote:
 

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

#132749
Aug 18, 2015 21:05
Vote:
 

Alright, 
I'll try it then. Thank you. 
Regards,
A

#132832
Aug 19, 2015 10:15
Vote:
 

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

#132869
Aug 19, 2015 16:54
Vote:
 

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

#132870
Aug 19, 2015 17:11
Vote:
 
#132997
Edited, Aug 24, 2015 9:54
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.