Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
simple_products_not_visible_individually.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  ->setId(67)
13  ->setAttributeSetId(4)
14  ->setName('Simple Product Not visible 1')
15  ->setSku('simple_not_visible_1')
16  ->setTaxClassId('none')
17  ->setDescription('description')
18  ->setShortDescription('short description')
19  ->setOptionsContainer('container1')
20  ->setMsrpDisplayActualPriceType(\Magento\Msrp\Model\Product\Attribute\Source\Type::TYPE_IN_CART)
21  ->setPrice(10)
22  ->setWeight(1)
23  ->setMetaTitle('meta title product Not visible')
24  ->setMetaKeyword('meta keyword')
25  ->setMetaDescription('meta description')
26  ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_NOT_VISIBLE)
27  ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
28  ->setWebsiteIds([1])
29  ->setCategoryIds([300])
30  ->setStockData(['use_config_manage_stock' => 1, 'qty' => 30, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
31  ->setSpecialPrice('5.99')
32  ->save();