When used on order items, work with the given adjustments

Created on 10 January 2025, about 2 months ago

Problem/Motivation

Like the parent class, the formatter uses the PriceCalculater.

What that does is create an order, an order item, apply quantity, recalculate adjustments and then return that information.

What the formatter currently does is get the purchased entity from the order item, and then calculate it.

There are cases when that's not the right, for example when viewing completed orders or generating invoices for them, as the promotions/adjustments might have changed in the meantime.

Steps to reproduce

Proposed resolution

Directly use the price and adjusted price API on the order item.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

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

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I created a first merge request, this still needs to be properly tested on our side.

    The logic is a bit convoluted now due all the if/else conditions, it might make sense to introduce two methods to abstract this, wanted to keep the changes minimal for now.

    At first I wasn't sure if the adjustment types setting works with order items then, but I think it actually works very well, all the API's we need allow to provide adjustment types, just have to be careful about when it ends up being empty.

  • πŸ‡¬πŸ‡·Greece fotisp

    Thanks for the patch.

    It works unless promotions are set to "Include the discount in the displayed unit price."
    (This option was introduced in: https://www.drupal.org/project/commerce/issues/3025383 β†’ )

    When "Include the discount in the displayed unit price" is enabled, order items only show the final price, as "original_price" and "final_price" are identical.

    I wasn’t able to fully understand the API used to fix this issue, but if someone can give me any tips, I’d be happy to create a patch.

    Additionally, the code below seems to have the exact same statement within both the if and else blocks:

    if ($items->getName() === 'total_price') {
              $result = new PriceCalculatorResult($purchasable_entity->getAdjustedTotalPrice($adjustment_types), $purchasable_entity->getTotalPrice(), $adjustments);
            }
            else {
              $result = new PriceCalculatorResult($purchasable_entity->getAdjustedTotalPrice($adjustment_types), $purchasable_entity->getTotalPrice(), $adjustments);
            }

    thanks

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States loze Los Angeles

    this works well for my needs. (showing price difference in the views order cart table)

    I made one small change that @fostip pointed out.

Production build 0.71.5 2024