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.
How can i achieve this using Schema Patch ?
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();
}
}