I am creating simple product programmatically, but for displaying it on frontend I need to edit product from admin side and set its view from
All Store Views
to
Default Store View
Mannually, then it appears on the frontend.
I am creating product as:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager
$product = $objectManager->create('\Magento\Catalog\Model\Product');
$product->setSku('my-sku11'); // Set your sku here
$product->setName('Sample Simple Product11'); // Name of Product
$product->setAttributeSetId(4); // Attribute set id
$product->setStatus(1); // Status on product enabled/ disabled 1/0
$product->setWeight(10); // weight of product
$product->setVisibility(4); // visibilty of product (catalog / search / catalog, search / Not visible individually)
$product->setTaxClassId(0); // Tax class id
$product->setTypeId('simple'); // type of product (simple/virtual/downloadable/configurable)
$product->setPrice(100); // price of product
$product->setStockData(
array(
'use_config_manage_stock' => 0,
'manage_stock' => 1,
'is_in_stock' => 1,
'qty' => 99999
)
);
$product = $product->save();
I have tried this,
$product->setStoreId(0); //1,2,3,4
but it is not working. How can I achieve it ? Thanks