1

I have added new action in catalog price rule.

enter image description here I have added this action through overriding below file.

module-catalog-rule/Model/Rule/Action/SimpleActionOptionsProvider.php

When this action is applied then how to calculate product price based on this action.

In magento module-catalog-rule which file/function is used to calculate product price when other action is applied.

Anyone knows then please help.

1

I have been recently fighting with something similar. Take a look at \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator class

public function calculate($ruleData, $productData = null)
{
    if ($productData !== null && isset($productData['rule_price'])) {
        $productPrice = $productData['rule_price'];
    } else {
        $productPrice = $ruleData['default_price'];
    }

    switch ($ruleData['action_operator']) {
        case 'to_fixed':
            $productPrice = min($ruleData['action_amount'], $productPrice);
            break;
        case 'to_percent':
            $productPrice = $productPrice * $ruleData['action_amount'] / 100;
            break;
        case 'by_fixed':
            $productPrice = max(0, $productPrice - $ruleData['action_amount']);
            break;
        case 'by_percent':
            $productPrice = $productPrice * (1 - $ruleData['action_amount'] / 100);
            break;
        default:
            $productPrice = 0;
    }

    return $this->priceCurrency->round($productPrice);
}

You'd validate your custom value is being received in $ruleData['action_operator'] and then add a new case with your custom logic

  • I have tried this way but its not working. – Emipro Technologies Pvt. Ltd. Dec 19 '18 at 11:33
  • That piece of code is fired when saving a product, or reindexing... Maybe you have tried just saving a catalogrule? Because in that case, the code is not fired – Raul Sanchez Dec 19 '18 at 11:50
  • That code is fired after catalogrule is applied and reindexing. – Emipro Technologies Pvt. Ltd. Dec 19 '18 at 12:24
  • I believe reindex does not occur when you save & apply a catalog rule (not in the Magento2 versions I have worked with). That just flags catalog rule prices index as invalid, so cron will reindex it next time it executes – Raul Sanchez Dec 19 '18 at 12:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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