| Current Path : /var/www/html/app/code/FlipsDigital/TextbookListBook/Setup/ |
| Current File : /var/www/html/app/code/FlipsDigital/TextbookListBook/Setup/UpgradeData.php |
<?php
namespace FlipsDigital\TextbookListBook\Setup;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
class UpgradeData implements UpgradeDataInterface
{
protected $TextbookListBookSetupFactory;
public function __construct(
TextbookListBookSetupFactory $TextbookListBookSetupFactory,
\FlipsDigital\TextbookListBook\Model\TextbookListBookFactory $TextbookListBookFactory
)
{
$this->TextbookListBookSetupFactory = $TextbookListBookSetupFactory;
$this->_tlbFactory = $TextbookListBookFactory;
}
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->TextbookListBookSetupFactory->create(['setup' => $setup]);
if (version_compare($context->getVersion(), '0.0.2', '<')) {
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'magento_hidden',
[
'type' => 'int',
'label' => 'Magento Hidden',
'input' => 'select',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'buy_default',
[
'type' => 'int',
'label' => 'Magento Buy Default',
'input' => 'select',
'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'must_buy_tgt',
[
'type' => 'text',
'label' => 'Must Buy Together',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'cannot_buy_tgt',
[
'type' => 'text',
'label' => 'Cannot Buy Together',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'buy_at_least_one',
[
'type' => 'text',
'label' => 'Buy At Least One',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
}
if (version_compare($context->getVersion(), '0.0.3', '<')) {
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'GroupItemDisplayName',
[
'type' => 'text',
'label' => 'GroupItemDisplayName',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'GroupItemDisplayPublisher',
[
'type' => 'text',
'label' => 'GroupItemDisplayPublisher',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'GroupNameEng',
[
'type' => 'text',
'label' => 'GroupNameEng',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
$eavSetup->addAttribute(
\FlipsDigital\TextbookListBook\Model\TextbookListBook::ENTITY,
'GroupNameChi',
[
'type' => 'text',
'label' => 'GroupNameChi',
'input' => 'text',
'sort_order' => 100,
'global' => ScopedAttributeInterface::SCOPE_STORE,
'group' => 'General',
]
);
}
if (version_compare($context->getVersion(), '0.0.4', '<')) {
$objTLB = $this->_tlbFactory->create();
$collectionTLB = $objTLB->getCollection();
$collectionTLB->addAttributeToSelect('*');
if($collectionTLB->count()){
foreach ($collectionTLB->getItems() as $key => $value){
if($value['magento_hidden'] == ''){
$value->setMagentoHidden(0);
$value->save();
}
}
}
}
$setup->endSetup();
}
}