0

I have a bpmn tool, it will generate CSV, that CSV contains single product. I need to import that csv file programatically. Already magento admin have that feature.

please can anyone point key code to trigger that import module from cron Job?

asked Mar 7, 2017 at 7:32
4
  • This answer should help you magento.stackexchange.com/questions/102922/… Commented Mar 7, 2017 at 8:09
  • it seems like we fetch csv data after that applied in your suggested answer, but I'm looking something just point the csv into the import module, it will handle the whole process of product creation like admin what does. I'm not sure about this so I need to research about this. If you need any clarity, please mention in comment. Commented Mar 7, 2017 at 8:54
  • Maybe not usefull, but Magento 2 EE have a schedule Import Module. You can try to find community extension in the marketplace or create your own CRON which trigger the same admin method which handle the import process. Commented Mar 8, 2017 at 7:36
  • did you find any solution? Commented May 28, 2020 at 5:38

1 Answer 1

-1

This code works for me. Please click here for more details. https://www.pearlbells.co.uk/code-snippets/import-simple-products-magento-2-programmatically/

$product = $objectManager->create('\Magento\Catalog\Model\Product');
 $product->setWebsiteIds(array(1));
 $product->setAttributeSetId(4);
 $product->setTypeId('simple');
 $product->setCreatedAt(strtotime('now')); 
 $product->setName($importProduct[1]); 
 $product->setSku($importProduct[3]);
 $product->setWeight($importProduct[16]);
 $product->setStatus(1);
 $category_id= array(30,24);
 $product->setCategoryIds($category_id); 
 $product->setTaxClassId(0); // (0 - none, 1 - default, 2 - taxable, 4 - shipping)
 $product->setVisibility(4); // catalog and search visibility
 $product->setColor(24);
 $product->setPrice($importProduct[11]) ;
 $product->setCost(1); 
 $product->setMetaTitle($importProduct[1]);
 $product->setMetaKeyword($importProduct[26]);
 $product->setMetaDescription($importProduct[28]);
 $product->setDescription($importProduct[27]);
 $product->setShortDescription($importProduct[27]);
 $product->setStockData(
 array(
 'use_config_manage_stock' => 0, 
 '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' => (int)$importProduct[6]
 )
 );
 $product->save();
 echo "Upload simple product id :: ".$product->getId()."\n";
 }
catch(Exception $e)
{
 echo 'Something failed for product import ' . $importProduct[1] . PHP_EOL;
 print_r($e);
}
answered Nov 25, 2018 at 0:25

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.