2

I have all configurable products on my website and I want to add the extra charges (after some calculation and conditions) to product price by overriding method or anything else which follow the Magento standard.

I have follow the following scenario:

I have tried this by using plugin method. It override the configurable product price only not it's child. Also not working properly on product list page.

1.etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Product">
    <plugin name="product_price_change"
            type="Namespace\Modulename\Plugin\Updateprice"
            sortOrder="1"/>
</type>
</config>

2.Plugin/Updateprice.php

<?php
namespace Namespace\Modulename\Plugin;

class Updateprice
{
    /**
     *  \Namespace\Modulename\Helper\Data $helper
     *
     * @var Namespace\Modulename\Helper\Data
     */
    protected $_helper;

    protected $_configurable;

    protected $product;

    public function __construct(
        \Namespace\Modulename\Helper\Data $helper,
        \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable $configurable,
        \Magento\Catalog\Model\Product $product
    ) {
        $this->_helper = $helper;
        $this->_configurable = $configurable;
        $this->_product = $product;
    }

    public function afterGetPrice(\Magento\Catalog\Model\Product $subject, $result) {
        if($subject->getTypeId() == "configurable"){
            return $result + $this->_helper->getAdditionalPrice($subject);
        }else{
            return $result + $this->_helper->chkAdditionalPrice($subject);
        }
    }
}

getAdditionalPrice function is defined in helper which have some calculation and return additional price according to product attribute otherwise it returns false;

I have also tried catalog_product_get_final_price magento event. This is working fine for "Simple Product" not for the associated simple product (configurable simple product).

I want to carry configurable product price to cart and checkout.

Any suggestion would be appreciated.

Thanks

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.