- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2018
01:17 PM
06-02-2018
01:17 PM
Importing products programatically - script stops after importing 158 products, why?
magento 1.9.3.7
This script stops executing after importing about 158 products, do you see what might cause it? There are 168000 products totally in the database, so it shouldn't stop like that.. (I'm moving products from cubecart to magento)
$sql = "SELECT * FROM cubecart_inventory where productId > 82300 LIMIT 2000"; $fullpath = 'media/import/'; $res = mysqli_query($db_source,$sql); $count = 0; while($obj = mysqli_fetch_object($res)) { echo "<h3>" . $obj->name . " - " . $obj->productCode . "</h3>"; try { $count++; $product = Mage::getModel('catalog/product'); $product->setSku($obj->productCode); $product->setName($obj->name); $product->setDescription($obj->description); $product->setShortDescription(''); $product->setPrice($obj->price); $product->setTypeId('simple'); $product->addImageToMediaGallery($fullpath . $obj->image, array('image','thumbnail','small_image'), false); $product->setAttributeSetId(4); $categories = get_categories($obj->cat_id,$db_source,$db_target); $product->setCategoryIds($categories); $product->setWeight($obj->prodWeight); $product->setTaxClassId(2); // taxable goods $product->setVisibility(4); // catalog, search $product->setStatus(1); // enabled $product->setTaxClassId(0); //0 = no tax // assign product to the default website $product->setWebsiteIds(array(Mage::app()->getStore(true)->getWebsite()->getId())); $product->setCreatedAt(strtotime('now')); $product->setStockData(array( 'use_config_manage_stock' => 0, 'is_in_stock' => 1, 'qty' => 9999, 'manage_stock' => 0, 'use_config_notify_stock_qty' => 0 )); $product->save(); } catch (Exception $e) { echo $e . "<br>"; } echo "<hr>"; }
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2018
11:02 PM
06-02-2018
11:02 PM
Re: Importing products programatically - script stops after importing 158 products, why?
Hi @Loginname,
Maybe you can add a try/catch to your code to handle the exception and get a better error description?
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2018
11:13 PM
06-02-2018
11:13 PM
Re: Importing products programatically - script stops after importing 158 products, why?
my mistake, I was missing set_time_limit(800); in the script
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2018
11:27 PM
06-02-2018
11:27 PM
Re: Importing products programatically - script stops after importing 158 products, why?
We can set the time to unlimited value by making it to 0 value. Like this
set_time_limit (0);
For keep 800 means they will run upto 800 seconds. And after completing of 800 second they will throw error again.
set_time_limit (0);
For keep 800 means they will run upto 800 seconds. And after completing of 800 second they will throw error again.
If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial
Magento 2 Blogs/Tutorial