Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
multiple_products_with_non_saleable_product.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
10 $product->isObjectNew(true);
11 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
12  ->setAttributeSetId(4)
13  ->setName('Simple Product')
14  ->setSku('simple_saleable')
15  ->setTaxClassId('none')
16  ->setDescription('description')
17  ->setShortDescription('short description')
18  ->setOptionsContainer('container1')
19  ->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_IN_CART)
20  ->setPrice(10)
21  ->setWeight(1)
22  ->setMetaTitle('meta title')
23  ->setMetaKeyword('meta keyword')
24  ->setMetaDescription('meta description')
25  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
26  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
27  ->setWebsiteIds([1])
28  ->setCategoryIds([])
29  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
30  ->save();
31 
32 $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
33 $product->isObjectNew(true);
34 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
35  ->setAttributeSetId(4)
36  ->setName('Simple Product2')
37  ->setSku('simple_not_saleable')
38  ->setTaxClassId('none')
39  ->setDescription('description')
40  ->setShortDescription('short description')
41  ->setOptionsContainer('container1')
42  ->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_ON_GESTURE)
43  ->setPrice(20)
44  ->setWeight(1)
45  ->setMetaTitle('meta title')
46  ->setMetaKeyword('meta keyword')
47  ->setMetaDescription('meta description')
48  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_IN_CATALOG)
49  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
50  ->setWebsiteIds([1])
51  ->setCategoryIds([])
52  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 50, 'is_qty_decimal' => 0, 'is_in_stock' => 0])
53  ->save();