Your IP : 216.73.216.220


Current Path : /var/www/html/app/code/FlipsDigital/CustomerTextbookList/Setup/
Upload File :
Current File : /var/www/html/app/code/FlipsDigital/CustomerTextbookList/Setup/UpgradeData.php

<?php

namespace FlipsDigital\CustomerTextbookList\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 $customertextbooklistSetupFactory;

	public function __construct(
        CustomerTextbookListSetupFactory $customertextbooklistSetupFactory,
        \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookListFactory $customerTextbookListFactory
    )
    {
        $this->customertextbooklistSetupFactory = $customertextbooklistSetupFactory;
        $this->_ctlFactory = $customerTextbookListFactory;
    }

	public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
	{
		$setup->startSetup();
        $eavSetup = $this->customertextbooklistSetupFactory->create(['setup' => $setup]);

        if (version_compare($context->getVersion(), '0.0.3', '<')) {
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'payment_method',
                [
                    'type' => 'varchar',
                    'label' => 'Payment Method',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'payment_amount',
                [
                    'type' => 'decimal',
                    'label' => 'Payment Amount',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'payment_date',
                [
                    'type' => 'datetime',
                    'label' => 'Payment Date',
                    'input' => 'datetime',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
        }

        if (version_compare($context->getVersion(), '0.0.6', '<')) {
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'chi_name',
                [
                    'type' => 'varchar',
                    'label' => 'Chinese Name',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'eng_name',
                [
                    'type' => 'varchar',
                    'label' => 'English Name',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );

            $objCTL = $this->_ctlFactory->create();
            $collectionCTL = $objCTL->getCollection();
            $collectionCTL->addAttributeToSelect('*');
            if($collectionCTL->count()){
                foreach ($collectionCTL->getItems() as $key => $value){
                    $studentName = $value['student_lastname'].' '.$value['student_firstname'];
                    $value->setChiName($studentName);
                    $value->setEngName($studentName);
                    $value->save();
                }
            }
        }

        if (version_compare($context->getVersion(), '0.0.9', '<')) {
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'prepare_oder_id',
                [
                    'type' => 'varchar',
                    'label' => 'Prepare Order Id',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'transaction_id',
                [
                    'type' => 'varchar',
                    'label' => 'Transaction Id',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
        }

        if (version_compare($context->getVersion(), '0.0.12', '<')) {
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'hkt_reference_id',
                [
                    'type' => 'varchar',
                    'label' => 'HKT Reference Id',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
        }

        if (version_compare($context->getVersion(), '0.0.13', '<')) {
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'payment_status',
                [
                    'type' => 'varchar',
                    'label' => 'Payment Status',
                    'input' => 'text',
                    'required' => true,
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
        }

        if (version_compare($context->getVersion(), '0.1.0', '<')) {
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'plastic_bag_levy',
                [
                    'type' => 'int',
                    'label' => 'Plastic Bag Levy',
                    'input' => 'text',
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
            $eavSetup->addAttribute(
                \FlipsDigital\CustomerTextbookList\Model\CustomerTextbookList::ENTITY,
                'plastic_bag_levy_amount',
                [
                    'type' => 'decimal',
                    'label' => 'Plastic Bag Levy Amount',
                    'input' => 'text',
                    'sort_order' => 100,
                    'global' => ScopedAttributeInterface::SCOPE_STORE,
                    'group' => 'General',
                ]
            );
        }
        $setup->endSetup();

        // if (version_compare($context->getVersion(), '0.0.8', '<')) {
        //     $objCTL = $this->_ctlFactory->create();
        //     $collectionCTL = $objCTL->getCollection();
        //     $collectionCTL->addAttributeToSelect('*');
        //     if($collectionCTL->count()){
        //         foreach ($collectionCTL->getItems() as $key => $value){
        //             $studentName = $value['student_lastname'].$value['student_firstname'];
        //             $value->setChiName($studentName);
        //             $value->setEngName($studentName);
        //             $value->save();
        //         }
        //     }
        // }
	}
}