cancel
Showing results for 
Search instead for 
Did you mean: 

Importing products programatically - script stops after importing 158 products, why?

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

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?

--
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution"

Re: Importing products programatically - script stops after importing 158 products, why?

my mistake, I was missing set_time_limit(800); in the script

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.
If Issue Solved, Click Kudos/Accept As solutions.