Magento – Magento 2 Catalog Price Rules applied to special_price

catalog-price-rulesmagento2

Catalog price rules by default are applied to the "price" field.

I need to make the Catalog Price Rules applied to "special_price" field.

Default use
Example:
If price=100 , special_price=90 and the catalog price rule is 80% the final_price = 80, 80% of "price"

I would like the discount to apply to special_price:
Example:
If price=100 , special_price=90 and the catalog price rule is 80% the final_price = 72, 80% of "special_price"

Best Answer

Create observer that starts on collection products loading. get event with this collection. Idea is next - you have yours database, where you have rules ( name, amount, id of product).Then you get collection of product from observer,just compare product id from observer collection with yours product ids in yours custom created database.If id from observer = id from database, we set discount/special_price/price/regullar price (that you can get from your db).

$qwe = $this->getEvent()->getCollection();
$your_custom_rule_amount=80%;//get from db your disscount amount.

foreach($qwe as $product)
{
  $product->setSpecialPrice($your_custom_rule_amount);//amount set.
   // $product->save(); // you can save this special price in magento db.
}

for me it works perfect.

and also you can read more about Rules Tutorials here :

https://www.mageplaza.com/kb/how-create-a-cart-price-rule-in-magento-2.html

https://docs.magento.com/m2/ce/user_guide/marketing/price-rules-catalog.html

Related Topic