0

I have created a custom option checkbox field, now on save, i have to update the value(0/1) to the table 'catalog_product_option' so that i can utilize this field on frontend.

enter image description here

How can i achieve this using Schema Patch ?

1 Answer 1

0

Using following code, we can create :-

<?php

/**
 * Copyright © 2019 Magenest. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace MyNamespace\MyModule\Setup\Patch\Schema;


use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\Patch\SchemaPatchInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;


class AddCrAllowedBrandAutoserachProductCustomOptionField implements SchemaPatchInterface
{
    /** @var ModuleDataSetupInterface */
    private $moduleDataSetup;

     /**
     * @param ModuleDataSetupInterface $moduleDataSetup
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
    }


    public static function getDependencies()
    {
        return [];
    }


    public function getAliases()
    {
        return [];
    }


    public function apply()
    {
        $this->moduleDataSetup->startSetup();


        $this->moduleDataSetup->getConnection()->addColumn(
            $this->moduleDataSetup->getTable('catalog_product_option'),
            'cr_allowed_brand_autoserach',
            [
                'type' => Table::TYPE_BOOLEAN,
                'nullable' => false,
                'default' => 0,
                'comment'  => 'Allowed Brand Autoserach',
            ]
        );


        $this->moduleDataSetup->endSetup();
    }
}

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.