1

We are trying to extend the Catalog Price Rules to make it possible to increase the price of a small group of products.

We have already tried to adjust the calculation in the file below, but this has no effect at all.

vendor\magento\module-catalog-rule\Helper\Data.php

All help is greatly appreciated!

5

1 Answer 1

0

I'm suggesting you to create a plugin

<type name="\Magento\Checkout\Controller\Index\Index">
    <plugin name="before-checkout-index" type="\Cpy\Checkout\Plugin\Controller\Checkout\Index" sortOrder="1" disabled="false"/>
</type>

Then in that plugin you can call you helper

Something like that

/**
 * @param $subject
 * @param $proceed
 * @return mixed
 */
public function aroundExecute($subject, $proceed)
{
    $errors =  $this->addToCartHelper->checkCart();

    if(is_array($errors)) {
        foreach($errors as $error) {
            $this->messageManager->addErrorMessage($error);
        }
        return $this->redirectFactory->create()->setPath('checkout/cart');
    } else {
        return $proceed();
    }
}

Where addToCartHelper is your custom helper and checkCart() the method that will return you all the errors messages depending on your logic

On the helper, you can reach all the items like below

public function checkCart()
{
    $errors = [];
    $items = $this->_checkoutSession->getQuote()->getAllVisibleItems();
    // ...

    if(!count($errors)) {
        return true;
    } else {
        return $errors;
    }
}
1
  • Thank you for your answer! Only I am looking for a solution within the Catalog Price Rule
    – Timo
    Nov 15, 2021 at 11:04

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.