0

We enabled the price field in the configurable product edit form. The price is saving in the database but in the form always showing 0 value. please suggest how We show the saved price in the price field. enter image description here

my di file code

<type name="Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePrice">
       <plugin name="enable_price_configurable_product" type="Awa\ConfigurablePrice\Plugin\DataProvider\Product\Form\Modifier\ConfigurablePrice" sortOrder="20" disabled="false"/>
   </type>

my plugin file code

namespace Awa\ConfigurablePrice\Plugin\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableType;
use Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePrice as ConfigurablePriceCore;
/**
 * Data provider for price in the Configurable products
 */
class ConfigurablePrice extends ConfigurablePriceCore
{
    /**
     * {@inheritdoc}
     *
     * Added after listener for make price field editable in configurable produc edit page.
     */
    public function afterModifyMeta($subject, $result)
    {
        $groupCode = $this->getGroupCodeByField($result, ProductAttributeInterface::CODE_PRICE)
            ?: $this->getGroupCodeByField($result, ConfigurablePriceCore::CODE_GROUP_PRICE);

        if (!empty($result[$groupCode]['children'][ConfigurablePriceCore::CODE_GROUP_PRICE])) {
            $result[$groupCode]['children'][ConfigurablePriceCore::CODE_GROUP_PRICE]['children']['price']['arguments']['data']['config']['component'] = 'Magento_Ui/js/form/element/abstract';
        }

        return $result;
    }
}

1 Answer 1

0

Hello Rajat,

  1. Create a PHP file: app/code/Munesh/ConfigurablePrice/registration.php
<?php  

\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Munesh_ConfigurablePrice',
DIR
);

  1. Create a XML file: app/code/Munesh/ConfigurablePrice/etc/module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Munesh_ConfigurablePrice" setup_version="1.0.0">
    <sequence>
        <module name="Magento_Catalog" />
        <module name="Magento_ConfigurableProduct" />
    </sequence>
</module>
  1. Create a XML file: app/code/Munesh/ConfigurablePrice/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\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePrice">
    <plugin name="enable_price_configurable_product" type="Munesh\ConfigurablePrice\Plugin\DataProvider\Product\Form\Modifier\ConfigurablePrice" sortOrder="20" disabled="false"/>
</type>
  1. Create a file: app/code/Munesh/ConfigurablePrice/Plugin/DataProvider/Product/Form/Modifier/ConfigurablePrice.php
<?php
namespace Munesh\ConfigurablePrice\Plugin\DataProvider\Product\Form\Modifier;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable as ConfigurableType;
use Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\ConfigurablePrice as ConfigurablePriceCore;
/**
 * Data provider for price in the Configurable products
*/
class ConfigurablePrice extends ConfigurablePriceCore
{
    /**
     * {@inheritdoc}
     *
     * Added after listener for make price field editable in configurable produc edit page.
     */
    public function afterModifyMeta($subject, $result)
    {
        $groupCode = $this->getGroupCodeByField($result, ProductAttributeInterface::CODE_PRICE)
            ?: $this->getGroupCodeByField($result, ConfigurablePriceCore::CODE_GROUP_PRICE);
        if (!empty($result[$groupCode]['children'][ConfigurablePriceCore::CODE_GROUP_PRICE])) {
            $result[$groupCode]['children'][ConfigurablePriceCore::CODE_GROUP_PRICE]['children']['price']['arguments']['data']['config']['imports']['disabled'] = 0;
        }
        return $result;
    }
}

Now, please run below commands.

php bin/magento module:enable Munesh_ConfigurablePrice

php bin/magento setup:upgrade

php bin/magento setup:static-content:deploy -f.

Now price field is must be enabled

Please do accept the Answer, if it is helpfull for you.

Thanks

2
  • this code can enable the price field But in edit mode the value is coming 0 even in the database value is changed. Commented Jan 14, 2021 at 4:38
  • if the value is changes, in db thats mean it work, you have to debug, that why not appearing on frontend. Please do accept the answer as it will helps others also! Commented Jan 14, 2021 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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