try{
$_product->setName($product["name"]);
$_product->setTypeId('simple');
$_product->setAttributeSetId(4);
$_product->setSku($product["sku"]); // this must be unique everytime and get the exception in frontend
$_product->setWebsiteIds(array(1));
$_product->setVisibility(4);
$_product->setDescription($product["description"]);
$_product->setPrice($product["price"]);
//$imagePath = $product['imgpath'];
$_product->setMediaGallery(array('images'=>array (),'values'=>array ()));
$_product->addImageToMediaGallery('https://beebom-redkapmedia.netdna-ssl.com/wp-content/uploads/2016/01/Reverse-Image-Search-Engines-Apps-And-Its-Uses-2016.jpg', array('image', 'small_image', 'thumbnail'),false);
// $_product->setImage('https://beebom-redkapmedia.netdna-ssl.com/wp-content/uploads/2016/01/Reverse-Image-Search-Engines-Apps-And-Its-Uses-2016.jpg');
// $_product->setSmallImage('/testimg/test.jpg');
// $_product->setThumbnail('/testimg/test.jpg');
$_product->setStockData(array(
'use_config_manage_stock' => 0, //'Use config settings' checkbox
'manage_stock' => 1, //manage stock
'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
'is_in_stock' => $product['stockstatus'], //Stock Availability
'qty' => $product['quantity']
)
);
$_product->save();
}
catch(\Exception $e) {
echo $e->getMessage();
}
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Kishan Patadia
- 5.6k
- 3
- 25
- 36