Hi there.. does anyone know of a shopping cart rule extenstion that leaves the price for custom options untouched?
At the moment if I apply a 10% off to an item in the checkout its also taking 10% of any custom options applied... these custom options have a fixed price for us and I need it to stay that way!
I need a cart rule that can take 10% off the product ONLY .. and leave the price for the custom options untouched!
Solved! Go to Solution.
Hello @matt_ayres ,
You can do it by yourself by a little bit of customization.
Magento\SalesRule\Model\Validator::getItemPrice($item) is responsible for returning the item price on which the discount is applied.
You can override this function or create a beforePlugin for this function. Please apply the check as
/** * Return item price * * @param AbstractItem $item * @return float */ public function getItemPrice($item) { $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $_objectManager->get('\Magento\Catalog\Model\Product')->load($item->getProductId()); $options = $product->getTypeInstance()->hasOptions($product); if ($options == 1) return $item->getOriginalPrice(); $price = $item->getDiscountCalculationPrice(); $calcPrice = $item->getCalculationPrice(); return $price === null ? $calcPrice : $price; }
Now it check if your item has custom options then it return the original price of product or else it works as it was working before.
Note:
I hope this works for you.
If it helps you, please give kudos and accept it as solution.
Regards.
Nope... just tried the demo and unfortunately there is no way to exclude the price of the custom options with any discount rules
Yes Vimal.. I can see that option and it does present itself on the cart rule page... But it does not help me in my quest to... APPLY the discount to the PRODUCT, and NOT the product PLUS the custom options.
eg:
TEST_PRODUCT = £100
Custom Option I select for the product = £10
I want my rule to just discount 10% from the PRODUCT
I want the price to be £90 (100 - 10%)
Instead I get £99 (100 - 10%)
So frustrating!
Hello @matt_ayres ,
You can do it by yourself by a little bit of customization.
Magento\SalesRule\Model\Validator::getItemPrice($item) is responsible for returning the item price on which the discount is applied.
You can override this function or create a beforePlugin for this function. Please apply the check as
/** * Return item price * * @param AbstractItem $item * @return float */ public function getItemPrice($item) { $_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $_objectManager->get('\Magento\Catalog\Model\Product')->load($item->getProductId()); $options = $product->getTypeInstance()->hasOptions($product); if ($options == 1) return $item->getOriginalPrice(); $price = $item->getDiscountCalculationPrice(); $calcPrice = $item->getCalculationPrice(); return $price === null ? $calcPrice : $price; }
Now it check if your item has custom options then it return the original price of product or else it works as it was working before.
Note:
I hope this works for you.
If it helps you, please give kudos and accept it as solution.
Regards.
It's not working when product has special price