Calculated price field formatter on products does not consider coupons that the user has applied

Created on 30 December 2020, almost 4 years ago
Updated 15 February 2023, almost 2 years ago

When using the calculated price field formatter and selecting "Apply promotions to the calculated price" only promotions that don't require a coupon are reflected in the adjusted price on the product page.

If the promotion requires a coupon and a user has that coupon applied to their cart, The price does not reflect the promotion.

Is this the intended behavior? it feels like a bug. I would expect ay promotion coupons that are currently applied to the users active cart to be reflected in the adjusted price.

πŸ› Bug report
Status

Active

Version

2.0

Component

Price

Created by

πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States derekw

    I've gotten >< this close to a solution.

    I want to apply a coupon that takes $100 off every matching purchased variation... and see that reflected on the relevant cart line items.

    I am using a rendered product variation view mode 'cart' to display selected attributes and the calculated price in the cart view.

    So I took the suggestions in this issue:

    1) Extended the commerce_order PriceCalculated formatter to add the current user's cart to the context.
    2) used hook_field_formatter_info_alter to set the commerce_price_calculated class to my extended formatter.

    3) Extended the PriceCalculator and changed added to the prepareOrder function to check for the cart in the context (set in the custom formatter), and use that rather than creating a fake one. (... but maybe I should just copy the coupons from the user's cart to the fake order.)

    4) Used mymodule.services.yml to override commerce_order.price_calculator and set the class to my custom priceCalculator.

    5) Extended the CouponRedeption views area to reload the page vs just updating the total price.

    That got me pretty close, but the rendered product variation 'cart' view on the line items was not refreshing, although the unit price and totals for the line items in the cart were.

    6) So I used hook_preprocess_commerce_product_variation and invalidated the cache tags for cart and summary view modes.

    The coupon discounts are shown in the cart line item rendered variations along with promotions, etc.

    But... when I check out and the order confirmation email rolls in... the line item total is right but the coupon discount is no longer shown in the rendered product variation (using the same summary view which works in the checkout and review pane).

    So frustrating for something that seems like it should just work out of the box: Apply a coupon that affects specific product variations, and see that coupon reflected in the calculated price.

  • πŸ‡·πŸ‡ΈSerbia bojanz

    The calculated price formatter was never designed to show discounts coming from coupons. In fact, it was never designed to be used in a real order / cart context. The cart knows all of its discounts and coupons, it doesn't need the calculated price formatter to repeat the calculations. The point of the formatter is to show a product in the catalog with a valid offer applied (e.g. price list for that day/customer, discount for that product category, etc).

    Should we be making an effort to forbid using this formatter on a cart / order item?

  • πŸ‡ΊπŸ‡ΈUnited States derekw

    That's very helpful to understand. I always know when I have to do a lot of workarounds that I'm probably just going about it the wrong way, kicking against the goads. (The price difference formatter for order line items also does not factor in coupons applied.)

    To show the adjustments (including coupons) applied to a line item in the cart, it looks like "the way" is to create a commerce_adjustment field formatter to display the order item adjustments field, since it does not seem to have a formatter out of the box.

Production build 0.71.5 2024