Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
is_salable_product.php
Go to the documentation of this file.
1 <?php
9 $product = $objectManager->create(\Magento\Catalog\Model\Product::class);
10 $product->isObjectNew(true);
11 $product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
12  ->setId(99)
13  ->setAttributeSetId(4)
14  ->setWebsiteIds([1])
15  ->setName('Simple Product')
16  ->setSku('simple-99')
17  ->setPrice(10)
18  ->setWeight(1)
19  ->setShortDescription("Short description")
20  ->setTaxClassId(0)
21  ->setDescription('Description with <b>html tag</b>')
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  ->setStockData(
28  [
29  'use_config_manage_stock' => 1,
30  'qty' => 100,
31  'is_qty_decimal' => 0,
32  'is_in_stock' => 1,
33  ]
34  )
35  ->setCanSaveCustomOptions(true)
36  ->setHasOptions(true);
37 
39 $productRepositoryFactory = $objectManager->get(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$productRepositoryFactory
$objectManager