Discount prices are shown without fulfilled criteria

Vote:
 

Hi!

I have a promotion where you can get products with 100% discount if you buy something else.

When I activate that campaign the products that you get for free gets the price 0 without that the criteria, "buy something else" eg adding another item to the cart, is fulfilled.
And if I add a regualar product and then a free product, the price is 0 which is correct, but when I remove the regular item from the cart the price is not updated for the free item?

What is the correct way to get the actuall current price? I mean the price should be 100 until I added a regular item to the cart and then get the price 0.
Is there a Epi standard way or do I need to check each product for active campaigns?

Thanks!

/Kristoffer

#231011
Nov 17, 2020 11:45
Vote:
 

Do you rerun the ApplyDiscounts() when an item is removed from the cart - because that is supposed to run 

#231014
Nov 17, 2020 15:59
Vote:
 

Yes, I do, in the ValidateCart function.

cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings());
#231015
Nov 17, 2020 16:01
Vote:
 

Strange. do you use a built-in promotion, or a custom one? 

#231016
Nov 17, 2020 16:06
Vote:
 
  1. Re-run the ApplyDiscount and save the cart _orderRepository.Save(cart);
  2. Try with the below code to check the full-filled status.
                cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings())
                    .Where(r => r.Status == FulfillmentStatus.Fulfilled)
                    .Select(c => c.Promotion?.Coupon?.Code)
                    .Where(i => i != null)
                    .Any(c => c.Equals(couponCode, StringComparison.OrdinalIgnoreCase));
#231027
Edited, Nov 17, 2020 22:08
Vote:
 

Hi!

It is actually my own Promotions.

In the start up I do this:

var promotionTypeHandler = context.Locate.Advanced.GetInstance<PromotionTypeHandler>();
promotionTypeHandler.DisableBuiltinPromotions();

And then I have made my own by inheriting the basic ones:

[ContentType(GUID = "95c36376-eadc-4d2d-9142-3e1f70814422", DisplayName = "Köp artiklar få rabatt på utvalda artiklar", GroupName = "entrypromotion")]
[PromotionSettings(FixedRedemptionsPerOrder = 1)]
[ImageUrl("Images/BuyQuantityGetItemDiscount.png")]
public class BuyQuantityGetItemDiscountPromotion : BuyQuantityGetItemDiscount, IBasePromotion
{
    [UIHint("image")]
    [Display(Order = 5, Name = "Bild")]
    public virtual ContentReference Image { get; set; }

    [Display(Order = 7, Name = "Beskrivning (lång)")]
    public virtual XhtmlString MainBody { get; set; }
}
public interface IBasePromotion
{
    XhtmlString MainBody { get; set; }

    ContentReference Image { get; set; }
}

But I guess that should not matter?

If I run this in an inkognito browser:

var s = _promotionEngine.Run(cart, new PromotionEngineSettings(RequestFulfillmentStatus.All, false));

All promotions has the status NotFullfilled but this line of code:

var discountPrices = _promotionEngine.GetDiscountPrices(variantLink, _currentMarket.GetCurrentMarket(), _currencyService.GetCurrentCurrency());

gives me discounted prices for the variantLink even to the promotion is not fullfilled. Should that be the case? I thougth GetDiscountPrices() should give me prices only if the promotion is fullfilled? I have my own pricing service, maybe I have to check that the promotion of the discounted price is fullfilled before I show it?

And then add one regular product and one free and then _promotionEngine.Run() gives me one fullfilled promotion.
I remove the regular one and still I get one fullfilled promotion until I remove the free one. 
So the problem is that the free one should not be free unless there is on regular product in the cart?

Maybe I'm just missing some basics here?

Thanks!

/Kristoffer

#231052
Nov 18, 2020 7:55
Vote:
 

With an empty cart:

_promotionEngine.Evaluate(variantLink, _currentMarket.GetCurrentMarket(),
                    _currencyService.GetCurrentCurrency());

Gives me one Fullfiled RewardDescritpion mean while this:

_promotionEngine.Run(cart, new PromotionEngineSettings(RequestFulfillmentStatus.All, false));

Gives me a list of RewardDescriptions where all item has the status NotFulfilled.

/Kristoffer

#231054
Edited, Nov 18, 2020 8:12
Vote:
 

What's about BuyQuantityGetFreeItem instead? Sounds like a better match for you

#231055
Nov 18, 2020 8:49
Vote:
 

No, actually not.

The customer has a lot of older products they wanted to get rid of and if you buy something you are supposed to be able to add 2 of these items with the price 0. So the price on the items should be there regular price until you add something with a price.

I found one user error and that is that you could choose whatever from the whole catalog, including the free items, which of couse fulfills the promotion when I add one of the free ones.
So in test purpose I now changed it to that the user needs to buy one specific item and then can then get items for free. And this is what happens starting with an empty cart.

All free items have a price by default in the product listing. Correct.
I add the specific item in the cart but there is still a price for the free items in the listing, _promotionEngine.GetDiscountPrices() returns nothing for the free items. Not correct.
I add one free item to the cart, and in the checkout the price for the free item is 0, and the price is shown using lineItem.GetExtendedPrice(currency). Correct.
I remove the specific item, price is back in the cart for the free item. Correct.

Wheter I have the specific item in the cart or not, these give me nothing:

var s = _promotionEngine.Evaluate(variantLink, _currentMarket.GetCurrentMarket(), _currencyService.GetCurrentCurrency(), RequestFulfillmentStatus.Fulfilled);
var discountPrices = _promotionEngine.GetDiscountPrices(variantLink, _currentMarket.GetCurrentMarket(), _currencyService.GetCurrentCurrency());

why is

lineItem.GetExtendedPrice(currency)

giving me the discounted price not the two above?

Thanks!

/Kristoffer

#231057
Nov 18, 2020 9:51
Vote:
 

Hi!

I still need some help to understand here:

  1. Why does _promotionEngine.GetDiscountPrices() give me prices when the criteria of a least one item in the cart is not fulfilled? This is when you can select from the whole catalog.
  2. Why does not _promotionEngine.GetDiscountPrices() give me any prices after adding one specific item in the cart? This is when you have to select a special variant to fulfill the promotion.
  3. When using option 2, lineItem.GetExtendedPrice() gives me the the discounted price, why is that?

I am a bit confused here how to use the promotion engine the correct way.

Thanks!

/Kristoffer

#231133
Nov 19, 2020 14:05
Vote:
 

Hi!

I just tested this in Foundation, Commerce 13.21 and this must be a bug or I just totally misunderstand the functionallity.

I'm using a "Buy Products for Discount from Other Selection" promotion.

1st case.

Buy at least 1 item of from these entries:
Fashion [catalog]
Include subcategories: Yes

Get these entries:
Morgan Sneaker [variant, SKU-42518256]
Morgan Sneaker [variant, Morgan-Sneaker_1]

At the following discount:
100% off

Price for Morgan Sneaker with an empty cart:
$0

Price in the cart with only one Morgan Sneaker in the cart:
$0

2nd case

Buy at least 1 item of from these entries:
Jodhpur Boot [variant, JODHPUR-BOOT_1]
Jodhpur Boot [variant, SKU-39813617]
Include subcategories: Yes

Get these entries:
Morgan Sneaker [variant, SKU-42518256]
Morgan Sneaker [variant, Morgan-Sneaker_1]

At the following discount:
100% off

Price for Morgan Sneaker with an empty cart:
$280, correct

Price for Morgan Sneaker with a Jodhpur Boot [variant, JODHPUR-BOOT_1] in the cart:
$280

Price for Morgan Sneaker in then cart with a Jodhpur Boot [variant, JODHPUR-BOOT_1] and a Morgan Sneaker in the cart:
$0

Both these examples are according to me wrong except $280 with an empty cart in the second case.
In the first case you can by something for $0 even though the promotion says you have to buy at least one other thing.
You should not have to add an item to the cart to get the promotion price, how can you promote it in that case?

Maybe I'm on the wrong track here then please let me know how it should work, otherwise please look into this so that we can figure out how to use the promotion manager, thanks!

/Kristoffer


#231177
Nov 20, 2020 15:51
* 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.