Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
websites_different_countries.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
13 
14 $objectManager = Bootstrap::getObjectManager();
15 //Creating second website with a store.
17 $website = $objectManager->create(Website::class);
18 $website->load('test', 'code');
19 
20 if (!$website->getId()) {
21  $website->setData([
22  'code' => 'test',
23  'name' => 'Test Website',
24  'default_group_id' => '1',
25  'is_default' => '0',
26  ]);
27  $website->save();
28 }
29 
30 $websiteId = $website->getId();
31 $store = $objectManager->create(Store::class);
32 $store->load('fixture_second_store', 'code');
33 
34 if (!$store->getId()) {
35  $groupId = $website->getDefaultGroupId();
36  $store->setData([
37  'code' => 'fixture_second_store',
38  'website_id' => $websiteId,
39  'group_id' => $groupId,
40  'name' => 'Fixture Second Store',
41  'sort_order' => 10,
42  'is_active' => 1,
43  ]);
44  $store->save();
45 }
46 
47 //Setting up allowed countries
48 $configResource = $objectManager->get(\Magento\Config\Model\ResourceModel\Config::class);
49 //Allowed countries for default website.
50 $configResource->saveConfig(
51  'general/country/allow',
52  'FR',
53  \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES,
54  1
55 );
56 //Allowed countries for second website
57 $configResource->saveConfig(
58  'general/country/allow',
59  'ES,US,UK,DE',
60  \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES,
62 );
63 
64 /* Refresh CatalogSearch index */
66 $indexerRegistry = $objectManager->create(\Magento\Framework\Indexer\IndexerRegistry::class);
67 $indexerRegistry->get(FulltextIndex::INDEXER_ID)->reindexAll();
68 //Clear config cache.
69 $objectManager->get(ReinitableConfigInterface::class)->reinit();
if(! $website->getId()) $websiteId
if(! $store->getId()) $configResource