6

I have a product with custom options and a catalog price rule (that applies to a certain customer group). When your in this customer group (group X), you get a discount of 15%.

This works for the product price, but not for custom options. For example: if I have a product of EUR 100,- with a custom option that costs EUR 10,- and I apply a discount of 15%, the resulting price is not EUR 93.50 (85.00 + 8.50), but EUR 95.00 (85.00 + 10.00).

I've created a plugin for Magento\Quote\Model\Quote\Item\Processor to be able to set a custom price:

<!--
    Plugin for price manipulation
-->
<type name="Magento\Quote\Model\Quote\Item\Processor">
    <plugin name="price_manipulation" type="Vendor\Module\Plugin\Magento\Quote\Model\Quote\Item\Processor"/>
</type>

Processor.php:

class Processor
{
    /**
     * Manipulate the price
     *
     * @param \Magento\Quote\Model\Quote\Item\Processor $subject
     * @param \Magento\Quote\Model\Quote\Item $item
     * @param \Magento\Framework\DataObject $request
     * @param \Magento\Catalog\Model\Product $candidate
     * @return array
     */
    public function beforePrepare(
        \Magento\Quote\Model\Quote\Item\Processor $subject,
        \Magento\Quote\Model\Quote\Item $item,
        \Magento\Framework\DataObject $request,
        \Magento\Catalog\Model\Product $candidate
    ) {
        // $request->setData('custom_price', 999);

        return [$item, $request, $candidate];
    }
}

But at this point in the code I don't have the discounted base price. So when I ask $item->getPrice() I get NULL. I guess I'm too early in the chain here. And when I ask $item->getProduct()->getPrice()` I get the non-discounted price, so that's also not what I want.

Can anyone share some insight in how to apply discount to custom options?

2
  • Did you ever get to the bottom of this one?
    – Erfan
    Sep 25, 2017 at 5:37
  • @Giel Berkers have you found the solution of this problem? Aug 26, 2020 at 9:59

1 Answer 1

1

This is a common issue that many Magento users face, and there are different ways to solve it.

One possible solution is to use a third-party extension that allows you to set discounts for custom options based on customer groups, such as Scommerce Mage Custom Option Discount. This extension lets you create custom option price rules that can be applied to specific customer groups, products, categories, or store views. You can also choose whether to apply the discount as a fixed amount or a percentage of the custom option price.

With this extension, you can easily achieve the result you want: a product of EUR 100,- with a custom option that costs EUR 10,- and a discount of 15% for customer group X, will have a final price of EUR 93.50 (85.00 + 8.50).

I hope this helps you solve your problem.

1
  • This extension does not seem to exist. Oct 19, 2023 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.