If I understand what you want to do correctly then a ShippingRewardApplicator seem a bit too invasive.
Creating a custom promotion with an attribute for store id and a custom processor should be the way to go:
https://world.episerver.com/documentation/developer-guides/commerce/marketing/custom-promotions/
You also should extend the shipment with a field for store id and set it when creating the shipment, that way the processor can check against that to make sure it is only applied to the correct shipment:
https://world.episerver.com/documentation/developer-guides/commerce/orders/Extending-order-classes/
This is of course assuming you want a shipping promotion, that is a promotion that gives a discount to the shipping cost.
If you want to give discounts to the actual items from a specific store then you should go for custom entry promotions and possibly extend the LineItem with store id if necessary.
Hi Erik, thanks for your answer.
Yes i am talking about a shipping promotions.
So far, i have created a custom promotion that has a StoreId property (is that what you meant by "Creating a custom promotion with an attribute for store id" ?), a custom shipping promotion processor, and yeah, our shipments already have a storeId informatin associated.
I am still in the middle of coding all of that, but the concern i am trying to address is what i read on the new Promotions page in the developer guide (sorry not allowed to add links) :
Note: If an order has several shipments, the shipping discount only applies to the shipment with the greatest shipping cost.
For example:
* Shipment 1 has a shipping cost of $39.76.
* Shipment 2 (in the same order form) has a shipping cost of $28.00.
If you apply a 10% discount, the discount amount is $3.98.
Decompiling some codes and lloking at what has been done, i think that i may select the shipment that the promotion is going to apply to by overriding the GetRedemtions() method :
protected override IEnumerable<RedemptionDescription> GetRedemptions(
StoreFreeShippingCoupon promotionData,
IOrderForm orderForm,
PromotionProcessorContext context)
{
var redemptionDescriptionList = new List<RedemptionDescription>();
var shipments = GetApplicableShipments(promotionData, context.OrderForm).ToList(); // this is where the correct shipment will be selected
if (shipments.Any())
redemptionDescriptionList.Add(CreateRedemptionDescription(shipments, context));
return redemptionDescriptionList;
}
Does this make sense at all ? Is this how "the processor can check against that to make sure it is only applied to the correct shipment" ?
That note is what will happen if more than one shipment is found and it is what happens for the built-in shipping promotions.
Yes exactly like that, with the GetApplicableShipments looking something like this:
IEnumerable<IShipment> shipments = ShippingPromotionProcessorBase<TShippingPromotion>.GetShipments(orderForm, (IEnumerable<Guid>) promotionData.ShippingMethods).Where(s=>s["StoreId"] == promotionData.StoreId).ToList();
Of course adapt it to correct data types if you have store ids that are integers or strings. (the context.OrderForm is a bit redundant as you already have the orderForm parameter. ;))
Most likely you have already worked it out by the time i post this. :D
Hi,
I have looked everywhere on the forum, but could not find an answer to my question :
I am creating a custom shipping promotion type for an eCommerce website that is used by multiple stores.
When a customer places an order, he can put items from multiple stores in the cart. Cart items are then grouped into multiple shipments, one shipment per store.
The custom shipping promotion will need to apply for one store only, so it will carry a store id.
The problem is that i don't know how to apply a shipping promotion only to a specific shipment. i found some interesting piece of information which suggests to implement a custom ShippingRewardApplicator but don't know how to do this(if that is the right way to do it).
Anyone already had to do this?
Many thanks !