Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
products_with_websites_and_stores.php
Go to the documentation of this file.
1 <?php
7 require __DIR__ . '/../../Store/_files/second_website_with_two_stores.php';
8 
11 $websiteId = $website->load('test', 'code')->getId();
12 
15 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
16  ->setAttributeSetId(4)
17  ->setWebsiteIds([$websiteId])
18  ->setName('Simple Product on second website')
19  ->setSku('simple-2')
20  ->setPrice(10)
21  ->setDescription('Description with <b>html tag</b>')
22  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
23  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
24  ->setCategoryIds([2])
25  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
26  ->save();
27 
29 $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
30 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
31  ->setAttributeSetId(4)
32  ->setWebsiteIds([1])
33  ->setName('Simple Product')
34  ->setSku('simple-1')
35  ->setPrice(10)
36  ->setDescription('Description with <b>html tag</b>')
37  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
38  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
39  ->setCategoryIds([2])
40  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
41  ->save();
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60