4

I would like to create a new custom option price type for the products in the 'Customizable Options' section. Could you please help me out how to add? Is it a possible to add this in Magento 2.x ? if possible could you please explain how to add.

Please find the below screenshot:

screenshot

1
  • For this you need to overide core file in custom extension. Jan 12, 2017 at 13:30

1 Answer 1

2

Create a plugin for that. So you need to create new module Or add following code into your existing module.

SR/StackExchange/etc/adminhtml/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\Config\Source\Product\Options\Price">
        <plugin name="sr_stackexchange_add_price_type" type="SR\StackExchange\Plugin\Catalog\Model\Config\Source\Product\Options\Price" sortOrder="1"/>
    </type>
</config>

SR/StackExchange/Plugin/Catalog/Model/Config/Source/Product/Options/Price.php

namespace SR\StackExchange\Plugin\Catalog\Model\Config\Source\Product\Options;

class Price
{
    /**
     * {@inheritdoc}
     *
     * @codeCoverageIgnore
     */
    public function afterToOptionArray(
        \Magento\Catalog\Model\Config\Source\Product\Options\Price $subject,
        array  $priceTypeOption
    ){
        $priceTypeOption[] = ['value' => 'new_type', 'label' => __('New Type')];
        return $priceTypeOption;
    }
}

Clear magento cache.

1
  • One thing to note: When defining the value new_type in this instance it can only be a maximum of 7 characters May 24, 2017 at 22:56

Your Answer

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

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