Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Custom Promotion. Buy a product get another one for free

Vote:
 

Hello all,

I need to build a promotion that works like this:

In edit promotion mode I have 2 sections:

Condition - here I place a product

Reward - here I place another product (to be added to cart with 0 price)

I was able to do a front-end part (which is a class inherited from OrderPromotion)

But I have hard time on creating a processor for this promotion...

Do anybody have experience/sample code for this sprecific type of promotion?

BTW, the free product should be added to the cart(if it's not already there) in the Evaluate method of the Promotion processor.

Appreciate any help on this!

#300384
Apr 19, 2023 19:56
Vote:
 

Recommend you look at using Related Entries and have logic in your Add to cart method to add the associated free product to the cart. You can then use the built-in item promotion to run the discount for the free product.

Alternatively, you could use packages to combine the 2 products into a single sku?

https://support.optimizely.com/hc/en-us/articles/4413192106765-Packages-and-bundles

#300489
Apr 21, 2023 7:00
Vote:
 

I belive you can do that. You can extend EntryPromotion with the custom integration. You can put the free Item as Reward. Which should be added to the cart once you add the product from current promotion. 
This should look like this - 

   [ContentType(GUID = ".....", GroupName = "entrypromotion", Order = 20000,
        DisplayName = "Spend for free Items")]
    [ImageUrl("/EPiServer/Commerce/Images/SpendAmountGetGiftItems.png")]
    public class SpendAmountGetGiftItems : EntryPromotion, IPurchaseAmount
    {
        [Display(Order = 10, Name = "Promotion Reward")]
        [PromotionRegion("Reward")]
        public virtual ContentArea RewardContainers { get; set; }
    }

In the next step you can get specified gift items running under a promotion. So we should have an intercepter for this promotion, Which should look like this - 

    [ServiceConfiguration(Lifecycle = ServiceInstanceScope.Singleton)]
    public class SpendAmountGetGiftItemsProcessor : EntryPromotionProcessorBase<SpendAmountGetGiftItems>
    {
        protected override PromotionItems GetPromotionItems(SpendAmountGetGiftItems promotionData)
        {
            return new PromotionItems(promotionData, new CatalogItemSelection(null, CatalogItemSelectionType.All, true),
                                      new CatalogItemSelection(promotionData.RewardContainers.Items.GetItemsFromCatalog(),
                                                               CatalogItemSelectionType.Specific, false));
        }
     }

This is not tested and may need tweaks as well. But this should give you some ideas I belive.

For further reference, You can follow
https://docs.developers.optimizely.com/customized-commerce/v13.0.0-commerce-cloud/docs/custom-promotions

#300686
Edited, Apr 25, 2023 9:09
Vote:
 

thank you all, we decided to go with "Related entries" approach.

#300837
Apr 27, 2023 15:15
Manoj Kumawat - May 02, 2023 8:34
Ah! So you now saying the product which is free is now related?
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.