0

Well, I have a problem, have a plugin which modifies the product price.

my plugin code:

    public function afterGetPrice(\Magento\Catalog\Model\Product $product, $price) {
 meter
        $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $requestInterface = $objectManager->get('Magento\Framework\App\RequestInterface');
        $moduleName = $requestInterface->getModuleName();

        if($product->getData('price_per_area')){
            if(strpos($moduleName, 'checkout') === false){
                if(strpos($moduleName, 'cart') === false){
                    $price = floatval($product->getData('price_per_area'));
                }
            }
        }
        return $price;
    }

so we modify price when a function getPrice() is called with an exception at checkout and cart page. but it seems to malfunction if the product has a special price.

this formula we use for frontend calculations on product view page:

$specialPriceExist ? $_product->getSpecialPrice() : $_product->getData('square_meters_in_area')*$_product->getPrice()

which leads us in case of special price to the following result:

$_product->getSpecialPrice() = $_product->getPrice() = $_product->getData('price_per_area')

any solutions/idea's to my problem?

Your Answer

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

Browse other questions tagged or ask your own question.