Your IP : 216.73.216.220


Current Path : /var/www/html/app/code/FlipsDigital/HappyMind/Setup/
Upload File :
Current File : /var/www/html/app/code/FlipsDigital/HappyMind/Setup/InstallData.php

<?php
namespace FlipsDigital\HappyMind\Setup;

use \Magento\Catalog\Model\Category;
use \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use \Magento\Framework\Exception\NoSuchEntityException;

class InstallData implements \Magento\Framework\Setup\InstallDataInterface
{
    protected $_goupName = 'HappyMind Textbook';
    protected $_textbookListCategory = 'Textbook List';
    protected $_textbookListBookCategory = 'Textbook List Book';

    public function __construct(
        \Magento\Customer\Model\GroupFactory $groupFactory,
        \Magento\Framework\ObjectManagerInterface $objectManagerInterface,
        \Magento\Framework\App\Config\ConfigResource\ConfigInterface $resourceConfig,
        \Magento\Catalog\Helper\DefaultCategoryFactory $defaultCategoryFactory,
        \Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory,
        \Magento\Eav\Setup\EavSetupFactory $eavSetupFactory,
        \Magento\Eav\Model\AttributeRepository $attributeRepository,
        \Magento\Cms\Model\PageFactory $pageFactory
    ) {
        $this->groupFactory = $groupFactory;
        $this->objectManager = $objectManagerInterface;
        $this->resourceConfig = $resourceConfig;
        $this->defaultCategoryFactory = $defaultCategoryFactory;
        $this->categorySetupFactory = $categorySetupFactory;
        $this->eavSetupFactory = $eavSetupFactory;
        $this->attributeRepository = $attributeRepository;
        $this->_pageFactory = $pageFactory;
    }

    public function install(
        \Magento\Framework\Setup\ModuleDataSetupInterface $setup, 
        \Magento\Framework\Setup\ModuleContextInterface $context
    ) {
        $setup->startSetup();

        $group = $this->groupFactory->create(['setup' => $setup]);
        $group->setCode( $this->_goupName )
            ->setTaxClassId(3)
            ->save();
        $this->resourceConfig->saveConfig(
            'happymind/create_account/default_group',
            $group->getId()
        );
        $rootCategoryId = Category::TREE_ROOT_ID;
        $defaultCategory = $this->defaultCategoryFactory->create();
        $defaultCategoryId = $defaultCategory->getId();

        $categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
        $objCategory = $categorySetup->createCategory();
        $objCategory->setStoreId(0)
            ->setParentId($rootCategoryId)
            ->setName($this->_goupName)
            ->setIsActive(true)
            ->setLevel(1)
            ->setIncludeInMenu(false)
//            ->setInitialSetupFlag(true)
            ->save();
        $objCategory->setPath($rootCategoryId . '/' . $objCategory->getId())
            ->save();
        $objParentCategory = $objCategory;

        $sortOrder = 100;
        foreach ([
            'textbook_list' => $this->_textbookListCategory,
            'textbook_list_book' => $this->_textbookListBookCategory,
        ] as $key => $value) {
            $classCategory = $this->objectManager->create(Category::class);
            $objCategory = $classCategory->getCollection()
                    ->addAttributeToFilter('name', $value)
                    ->getFirstItem();

            if($objCategory->getId() == NULL) {
                $classCategory->setPath($objParentCategory->getPath())
                    ->setParentId($objParentCategory->getId())
                    ->setName($value)
                    ->setIncludeInMenu(false)
                    ->setIsActive(true);
                $classCategory->save();
                $categoryId = $classCategory->getId();
            }else{
                $categoryId = $objCategory->getId();
            }
            $this->resourceConfig->saveConfig(
                'happymind/textbook/default_'.$key.'_category',
                $categoryId
            );
        }
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        try {
            $this->attributeRepository->get(Category::ENTITY, 'mers_stock_source_type');
        } catch (NoSuchEntityException $e) {
            $eavSetup->addAttribute(
                Category::ENTITY,
                'mers_stock_source_type',
                [
                    'type'         => 'varchar',
                    'label'        => 'MersStock - Source Type',
                    'input'        => 'text',
                    'source'       => '',
                    'global'       => ScopedAttributeInterface::SCOPE_GLOBAL,
                    'visible'      => true,
                    'required'     => false,
                    'user_defined' => false,
                    'default'      => null,
                    'group'        => '',
                    'backend'      => ''
                ]
            );
        }
        try {
            $this->attributeRepository->get(Category::ENTITY, 'mers_stock_source_id');
        } catch (NoSuchEntityException $e) {
            $eavSetup->addAttribute(
                Category::ENTITY,
                'mers_stock_source_id',
                [
                    'type'         => 'int',
                    'label'        => 'MersStock - Source Id',
                    'input'        => 'text',
                    'source'       => '',
                    'global'       => ScopedAttributeInterface::SCOPE_GLOBAL,
                    'visible'      => true,
                    'required'     => false,
                    'user_defined' => false,
                    'default'      => null,
                    'group'        => '',
                    'backend'      => ''
                ]
            );
        }
        try {
            $this->attributeRepository->get(Category::ENTITY, 'mers_stock_source_code');
        } catch (NoSuchEntityException $e) {
            $eavSetup->addAttribute(
                Category::ENTITY,
                'mers_stock_source_code',
                [
                    'type'         => 'varchar',
                    'label'        => 'MersStock - Source Code',
                    'input'        => 'text',
                    'source'       => '',
                    'global'       => ScopedAttributeInterface::SCOPE_GLOBAL,
                    'visible'      => true,
                    'required'     => false,
                    'user_defined' => false,
                    'default'      => null,
                    'group'        => '',
                    'backend'      => ''
                ]
            );
        }
        try {
            $this->attributeRepository->get(Category::ENTITY, 'mers_stock_source_unit_price_date');
        } catch (NoSuchEntityException $e) {
            $eavSetup->addAttribute(
                Category::ENTITY,
                'mers_stock_source_unit_price_date',
                [
                    'type'         => 'datetime',
                    'label'        => 'MersStock - Unit Price Date',
                    'input'        => 'datetime',
                    'source'       => '',
                    'global'       => ScopedAttributeInterface::SCOPE_GLOBAL,
                    'visible'      => true,
                    'required'     => false,
                    'user_defined' => false,
                    'default'      => null,
                    'group'        => '',
                    'backend'      => ''
                ]
            );
        }
        $page = $this->_pageFactory->create();
        $page->setTitle('Privacy Statement 私隱聲明')
            ->setIdentifier('privacy-statement')
            ->setIsActive(true)
            ->setPageLayout('1column')
            ->setStores(array(0))
            ->setContent('<h3 style="text-align: center;">Privacy Statement</h3><p>Happy Mind Ltd. assures that users of this website can have their privacy respected and protected. Without permission of the users, the website will not modify or disclose any private information entered by users, except under the following circumstances:</p><ul><li>To follow the law of Hong Kong Special Administrative Region of the People\'s Republic of China and the order of her government;</li><li>To execute the content of the terms of usage; or</li><li>To execute required actions in protecting the interest of the affected user or other users.</li></ul><p>Web Links<br>The above declaration applies only to this website and is not applicable to other websites linked from this website.</p><p>Data Storage<br>This website will also fulfil the above declaration when storing private data of the users.</p><h3 style="text-align: center;">私隱聲明</h3><p>泰有限公司確保用戶在使用本網站時,其個人私隱將受到尊重和保護。本網站不會在沒有用戶同意的情況下,修改或公開用戶所輸入的個人資料。除非在以下情況:</p><ul><li>依照中華人民共和國香港特別行政區有關法律及理行政府之要求;</li><li>履行使用條款的內容;或</li><li>保障用戶及其他使用者利益有關的所需行動。</li></ul><p>網址連結<br>以上聲明只適用於本網站,如閣下從本網址連結到其他網址,本聲明則不適用。</p><p>資料保存<br>本網站在保存有關個人資料時,同時亦會履行以上的聲明。</p>')
            ->save();
        $page = $this->_pageFactory->create();
        $page->setTitle('Terms of Service 使用條款')
            ->setIdentifier('terms-of-service')
            ->setIsActive(true)
            ->setPageLayout('1column')
            ->setStores(array(0))
            ->setContent('<h3 style="text-align: center; font-family: Arial;"><br>Terms of Service</h3><p style="font-family: Arial;">Welcome to the website of Happy Mind Ltd. and its subsidiary China Bookstore (the Website). Please read the following terms and conditions regarding the use of the website before the registration process is completed.</p><p style="font-family: Arial;">User’s obligation:<br>You may not use the content or service provided by the Website to engage in any illegal activities, including but not limited to copyright infringement and intellectual property infringement.</p><p style="font-family: Arial;">All material of this Website is owned by Happy Mind Ltd. (Happy Mind). You may not sell, rent, lease, loan or publish any portion of the above said material by any means, in any format.</p><p style="font-family: Arial;">You may not allow a third party to use your user account. In the event where Happy Mind has identified misused of the account and its content, Happy Mind has to right to terminate your account. You should immediately notify Happy Mind of any unauthorized use of your password or user account.</p><p style="font-family: Arial;">Happy Mind\'s services and responsibilities:<br>The content and services provided by the Website is free of charge. Happy Mind reserves the right to charge for any additional content or services.</p><p style="font-family: Arial;">Use of information:<br>Happy Mind and its partners have the right to use your information and any material which you submitted for data.</p><p style="font-family: Arial;">Change to the Terms of Service:<br>Happy Mind reserves the right to change the Terms of Service without prior notice.</p><p style="font-family: Arial;">By submitting your registration, you agree to be bound by the Terms of Service. If you do not accept the Terms of Service, you should not use the Website. If you violate the Terms of Service, Happy Mind has the right to terminate the services provided to you.&nbsp; In case of misuse or unauthorized use of the data and content in this website, Happy Mind reserves the rights to bring legal proceedings against such action.<br><br></p><h3 style="text-align: center; font-family: Arial;">使用條款</h3><p style="font-family: Arial;">歡迎瀏覽「超泰有限公司」及「中國書局」(超泰有限公司全資附屬有限公司)公司網站(下稱本網站),登記前請先細閱以下使用條款。</p><p style="font-family: Arial;">使用義務:<br>不得使用本網站的服務或內容從事任何不合法的活動,包括但不限於侵害他人之版權或知識產權。</p><p style="font-family: Arial;">不得將本網站的任何部分,以單獨或組合形式出售、出租、出借或發佈,或作為任何產品或服務的部分轉售。</p><p style="font-family: Arial;">不得將戶口借予他人使用,否則「超泰有限公司」有權取消您的戶口。如您發現戶口被盜用,應立即聯絡我們。</p><p style="font-family: Arial;">「超泰有限公司」的服務及責任:<br>現時本網站的所有服務均為免費,但如您要求任何附加的功能或服務,「超泰有限公司」有權向您徵收服務費。</p><p style="font-family: Arial;">「超泰有限公司」的使用資料權利:<br>「超泰有限公司」及其合作伙伴,有權使用您提供予本網站的檔案及資料作分析用途。</p><p style="font-family: Arial;">修改使用條款之權利:<br>「超泰有限公司」保留修改以上條款的權利,事前無需通知用戶。</p><p style="font-family: Arial;">當您使用本網站,即表示同意接受本條款之約束;如您不同意此等條款,則請勿使用本網站。如有違反上述事項,「超泰有限公司」可隨時終止服務並保留法律追究權利。</p>')
            ->save();
        $setup->endSetup();
    }
}