Hi Yehuda,
The Buy X Get Y discounts are capable of working with Product variants out of the box. Did you consider using this feature instead of the Product option approach?
The Buy X Get Y applicator is created from a dll class that is not modifiable. In theory you can replace the built-in MultiBuyDiscountsEvaluator class with your own, where you define that the discount should be applied to the specified Product option. It should then be picked up by the built in Applicator. However I have not tested this outside registering a simple evaluator class, so I cannot guarantee your scenario will be possible using this approach.
To do this, create a Custom info provider with an override of the method responsible for Evaluator initialization in MultiBuyDiscountInfoProvider. In this example I am using MultiBuyDiscountsEvaluator as base for the custom class, which may allow you to reuse some of the built-in functionality:
[assembly: RegisterCustomProvider(typeof(CustomMultiBuyDiscountInfoProvider))]
public class CustomMultiBuyDiscountInfoProvider : MultiBuyDiscountInfoProvider
{
/// <summary>
/// Returns an instance of MultiBuyDiscountsEvaluator to be used for given shopping cart.
/// </summary>
/// <param name="cart">Shopping cart info object to get applicator for.</param>
protected override MultiBuyDiscountsEvaluator GetMultiBuyDiscountsEvaluatorInternal(ShoppingCartInfo cart)
{
return new CustomMultiBuyDiscountsEvaluator(cart.CartProducts);
}
}
public class CustomMultiBuyDiscountsEvaluator : MultiBuyDiscountsEvaluator
{
/// <summary>
/// Creates a new instance of applicator for given cart items.
/// </summary>
/// <param name="cartItems">Cart items to be evaluated.</param>
public CustomMultiBuyDiscountsEvaluator(IEnumerable<ShoppingCartItemInfo> cartItems) : base(cartItems)
{
}
}
This way you can try to implement your custom logic based on the API reference. However I would still recommend using the Product variants instead.