123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Store\Setup\Patch\Schema;
- use Magento\Catalog\Helper\DefaultCategory;
- use Magento\Framework\Setup\SchemaSetupInterface;
- use Magento\Framework\Setup\Patch\PatchVersionInterface;
- use Magento\Framework\Setup\Patch\SchemaPatchInterface;
- use Magento\Store\Api\Data\WebsiteInterface;
- /**
- * Create stores and websites. Actually stores and websites are part of schema as
- * other modules schema relies on store and website presence.
- * @package Magento\Store\Setup\Patch\Schema
- */
- class InitializeStoresAndWebsites implements SchemaPatchInterface, PatchVersionInterface
- {
- /**
- * @var SchemaSetupInterface
- */
- private $schemaSetup;
- /**
- * @var DefaultCategory
- */
- private $defaultCategory;
- /**
- * @var \Magento\Catalog\Helper\DefaultCategoryFactory
- */
- private $defaultCategoryFactory;
- /**
- * PatchInitial constructor.
- * @param SchemaSetupInterface $schemaSetup
- */
- public function __construct(
- SchemaSetupInterface $schemaSetup,
- \Magento\Catalog\Helper\DefaultCategoryFactory $defaultCategoryFactory
- ) {
- $this->schemaSetup = $schemaSetup;
- $this->defaultCategoryFactory = $defaultCategoryFactory;
- }
- /**
- * {@inheritdoc}
- */
- public function apply()
- {
- $this->schemaSetup->startSetup();
- $connection = $this->schemaSetup->getConnection();
- $select = $connection->select()
- ->from($this->schemaSetup->getTable('store_website'))
- ->where('website_id = ?', 0);
- if ($connection->fetchOne($select) === false) {
- /**
- * Insert websites
- */
- $connection->insertForce(
- $this->schemaSetup->getTable('store_website'),
- [
- 'website_id' => 0,
- 'code' => WebsiteInterface::ADMIN_CODE,
- 'name' => 'Admin',
- 'sort_order' => 0,
- 'default_group_id' => 0,
- 'is_default' => 0
- ]
- );
- $connection->insertForce(
- $this->schemaSetup->getTable('store_website'),
- [
- 'website_id' => 1,
- 'code' => 'base',
- 'name' => 'Main Website',
- 'sort_order' => 0,
- 'default_group_id' => 1,
- 'is_default' => 1
- ]
- );
- /**
- * Insert store groups
- */
- $connection->insertForce(
- $this->schemaSetup->getTable('store_group'),
- [
- 'group_id' => 0,
- 'website_id' => 0,
- 'name' => 'Default',
- 'root_category_id' => 0,
- 'default_store_id' => 0
- ]
- );
- $connection->insertForce(
- $this->schemaSetup->getTable('store_group'),
- [
- 'group_id' => 1,
- 'website_id' => 1,
- 'name' => 'Main Website Store',
- 'root_category_id' => $this->getDefaultCategory()->getId(),
- 'default_store_id' => 1
- ]
- );
- /**
- * Insert stores
- */
- $connection->insertForce(
- $this->schemaSetup->getTable('store'),
- [
- 'store_id' => 0,
- 'code' => 'admin',
- 'website_id' => 0,
- 'group_id' => 0,
- 'name' => 'Admin',
- 'sort_order' => 0,
- 'is_active' => 1
- ]
- );
- $connection->insertForce(
- $this->schemaSetup->getTable('store'),
- [
- 'store_id' => 1,
- 'code' => 'default',
- 'website_id' => 1,
- 'group_id' => 1,
- 'name' => 'Default Store View',
- 'sort_order' => 0,
- 'is_active' => 1
- ]
- );
- $this->schemaSetup->endSetup();
- }
- }
- /**
- * Get default category.
- *
- * @deprecated 101.0.0
- * @return DefaultCategory
- */
- private function getDefaultCategory()
- {
- if ($this->defaultCategory === null) {
- $this->defaultCategory = $this->defaultCategoryFactory->create();
- }
- return $this->defaultCategory;
- }
- /**
- * {@inheritdoc}
- */
- public static function getDependencies()
- {
- return [];
- }
- /**
- * {@inheritdoc}
- */
- public static function getVersion()
- {
- return '2.0.0';
- }
- /**
- * {@inheritdoc}
- */
- public function getAliases()
- {
- return [];
- }
- }
|