3

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

  • For this you need to overide core file in custom extension. – Dhiren Vasoya Jan 12 '17 at 13:30
1

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.

  • One thing to note: When defining the value new_type in this instance it can only be a maximum of 7 characters – Adam Paterson May 24 '17 at 22:56

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.