0

I have created a script for import CSV products everything's working perfect but one issue is product video url not set.

<?php
use \Magento\Framework\App\Bootstrap;
include('app/bootstrap.php');
// add bootstrap
$bootstraps = Bootstrap::create(BP, $_SERVER);
$object_Manager = $bootstraps->getObjectManager();
$app_state = $object_Manager->get('\Magento\Framework\App\State');
$app_state->setAreaCode('frontend');
// get date 
$today_date = date("m/d/Y");
$added_date = date('m/d/Y',strtotime("+17 day"));
$set_product = $object_Manager->create('\Magento\Catalog\Model\Product');
try{
 $set_product->setWebsiteIds(array(1));
 $set_product->setAttributeSetId(4);
 $set_product->setTypeId('simple');
 $set_product->setCreatedAt(strtotime('now')); 
 $set_product->setName('Test Sample Products'); 
 $set_product->setSku('add-sku-1');
 $set_product->setWeight(1.0000);
 $set_product->setStatus(1);
 $category_id= array('3,4,5');
 $set_product->setCategoryIds($category_id); 
 $set_product->setTaxClassId(0); 
 $set_product->setPrice(100.99) ;
 $set_product->setStockData(
 array(
 'use_config_manage_stock' => 0, 
 // checkbox for 'Use config settings' 
 'manage_stock' => 1, // manage stock
 'min_sale_qty' => 1, // Shopping Cart Minimum Qty Allowed 
 'max_sale_qty' => 2, // Shopping Cart Maximum Qty Allowed
 'is_in_stock' => 1, // Stock Availability of product
 'qty' => 100 // qty of product
 )
 );
 $set_product->save();
 // get id of product
 $get_product_id = $set_product->getId();
 echo "Upload simple product id :: ".$get_product_id."\n";
}
catch (\Exception $e) {
 echo $e->getMessage();
}
$set_product->setVideoUrl('youtub.com/magento');

But it's not working category save and set product video URL?

asked Aug 25, 2017 at 9:21

1 Answer 1

2

Please remove single quotes from category id array. So it is look like below.

$category_id = array(3,4,5);
Dhaval Dave
4361 gold badge5 silver badges14 bronze badges
answered Aug 25, 2017 at 9:36
7
  • Thanx @ Bhavin. you know how to set product video URL? Commented Aug 25, 2017 at 9:43
  • No sorry. I am still not use video URL in product. Commented Aug 25, 2017 at 9:50
  • ok, no problem. thanx for the solution. let me know if you found solution about video. Commented Aug 25, 2017 at 9:56
  • how to remove existing categories and add new categories using setCategoryIds? Commented Nov 5, 2018 at 9:21
  • @jafar When you use setCategoryIds, Magento automatically replaced existing with new one.. Commented Nov 5, 2018 at 11:28

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.