Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
product_with_two_websites.php
Go to the documentation of this file.
1 <?php
8 
11 $website = $objectManager->get(Magento\Store\Model\Website::class);
12 
13 $website->setData(
14  [
15  'code' => 'second_website',
16  'name' => 'Test Website',
17  ]
18 );
19 
20 $website->save();
21 
22 $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->reinitStores();
23 
26  ->create(ProductInterface::class);
28  ->setTypeId('simple')
29  ->setAttributeSetId(4)
30  ->setWebsiteIds([1, $website->getId()])
31  ->setName('Simple Product')
32  ->setSku('unique-simple-azaza')
33  ->setPrice(10)
34  ->setMetaTitle('meta title')
35  ->setMetaKeyword('meta keyword')
36  ->setMetaDescription('meta description')
37  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
38  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
39  ->setStockData(['use_config_manage_stock' => 0])
40  ->save();