Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InitializeStoresAndWebsites.php
Go to the documentation of this file.
1 <?php
8 
14 
21 {
25  private $schemaSetup;
26 
30  private $defaultCategory;
31 
35  private $defaultCategoryFactory;
36 
41  public function __construct(
42  SchemaSetupInterface $schemaSetup,
43  \Magento\Catalog\Helper\DefaultCategoryFactory $defaultCategoryFactory
44  ) {
45  $this->schemaSetup = $schemaSetup;
46  $this->defaultCategoryFactory = $defaultCategoryFactory;
47  }
48 
52  public function apply()
53  {
54  $this->schemaSetup->startSetup();
55  $connection = $this->schemaSetup->getConnection();
56  $select = $connection->select()
57  ->from($this->schemaSetup->getTable('store_website'))
58  ->where('website_id = ?', 0);
59 
60  if ($connection->fetchOne($select) === false) {
64  $connection->insertForce(
65  $this->schemaSetup->getTable('store_website'),
66  [
67  'website_id' => 0,
69  'name' => 'Admin',
70  'sort_order' => 0,
71  'default_group_id' => 0,
72  'is_default' => 0
73  ]
74  );
75  $connection->insertForce(
76  $this->schemaSetup->getTable('store_website'),
77  [
78  'website_id' => 1,
79  'code' => 'base',
80  'name' => 'Main Website',
81  'sort_order' => 0,
82  'default_group_id' => 1,
83  'is_default' => 1
84  ]
85  );
86 
90  $connection->insertForce(
91  $this->schemaSetup->getTable('store_group'),
92  [
93  'group_id' => 0,
94  'website_id' => 0,
95  'name' => 'Default',
96  'root_category_id' => 0,
97  'default_store_id' => 0
98  ]
99  );
100  $connection->insertForce(
101  $this->schemaSetup->getTable('store_group'),
102  [
103  'group_id' => 1,
104  'website_id' => 1,
105  'name' => 'Main Website Store',
106  'root_category_id' => $this->getDefaultCategory()->getId(),
107  'default_store_id' => 1
108  ]
109  );
110 
114  $connection->insertForce(
115  $this->schemaSetup->getTable('store'),
116  [
117  'store_id' => 0,
118  'code' => 'admin',
119  'website_id' => 0,
120  'group_id' => 0,
121  'name' => 'Admin',
122  'sort_order' => 0,
123  'is_active' => 1
124  ]
125  );
126  $connection->insertForce(
127  $this->schemaSetup->getTable('store'),
128  [
129  'store_id' => 1,
130  'code' => 'default',
131  'website_id' => 1,
132  'group_id' => 1,
133  'name' => 'Default Store View',
134  'sort_order' => 0,
135  'is_active' => 1
136  ]
137  );
138  $this->schemaSetup->endSetup();
139  }
140  }
141 
148  private function getDefaultCategory()
149  {
150  if ($this->defaultCategory === null) {
151  $this->defaultCategory = $this->defaultCategoryFactory->create();
152  }
153  return $this->defaultCategory;
154  }
155 
159  public static function getDependencies()
160  {
161  return [];
162  }
163 
167  public static function getVersion()
168  {
169  return '2.0.0';
170  }
171 
175  public function getAliases()
176  {
177  return [];
178  }
179 }
__construct(SchemaSetupInterface $schemaSetup, \Magento\Catalog\Helper\DefaultCategoryFactory $defaultCategoryFactory)
$connection
Definition: bulk.php:13