I'm writing a custom integration with an external CRM and I need to get all promotions applied to the order.
I was looking into this, but I can't find a way to list all the promotions applied to a specific order.

In the order, I only see applied promotions with discount code.

Proposed solution:
Add a 'loadMultipleByOrder' function in the PromotionsUsage file (src/PromotionUsage.php).
This function should return all promotions applied to a specific order.

Maybe we need to return promotions and 'coupon-promotions' in a diffrent way, but we can think about how we do this I guess.
I'm not sure how commerce core handles this in other use cases.

Thanks for the feedback.

Issue fork commerce-3120504

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

    Comments

    pietermouton created an issue. See original summary.

    AmeDSL’s picture

    Did you found a solution for that?

    santerref’s picture

    I am using this method to load the applied promotions on the order:

    $promotion_storage = $this->entityTypeManager->getStorage('commerce_promotion');
    foreach ($order->collectAdjustments() as $adjustment) {
      if ($adjustment->getType() == 'promotion') {
        $applied_promotions[] = $promotion_storage->load($adjustment->getSourceId());
      }
    }
    

    Seems to do the trick for the moment.

    anybody’s picture

    Category: Feature request » Support request
    Related issues: +#3489854: $order->getAdjustments('promotion') returns no result even for order promotions

    Alternatively you can use
    $order->collectAdjustments(['promotion']);

    Also see #3489854: $order->getAdjustments('promotion') returns no result even for order promotions

    Is your questions answered then @pietermouton?

    jsacksick’s picture

    Status: Active » Closed (outdated)
    pietermouton’s picture

    I suppose so. Don't remember how I got around the issue 4 years ago, but I did eventually.