I am trying to insert products into a Magento Web Shop using the following code:
public static function addProduct($product, $categorieId) {
$productModel = Mage::getModel('catalog/product');
$productModel->setTypeId(Mage_Catalog_Model_Product_Type::TYPE_SIMPLE)
->setWebsiteIDs(array(1))
->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
->setCreatedAt(strtotime('now'))
->setName($product->PRODUCT_DETAILS[0]->DESCRIPTION_SHORT)
->setCategoryIds(array($categorieId))
->setDescription($product->PRODUCT_DETAILS[0]->DESCRIPTION_LONG ? $product->PRODUCT_DETAILS[0]->DESCRIPTION_LONG : $product->PRODUCT_DETAILS[0]->DESCRIPTION_SHORT)
->setShortDescription($product->PRODUCT_DETAILS[0]->DESCRIPTION_SHORT)
->setPrice($product->PRODUCT_PRICE_DETAILS->PRODUCT_PRICE->PRICE_AMOUNT)
->setAttributeSetId($productModel->getResource()->getEntityType()->getDefaultAttributeSetId());
$productModel->setStockData(array(
'is_in_stock' => 1,
'qty' => 99999
));
try {
$productModel->save();
return $productModel->getId();
} catch (Exception $ex) {
Mage::log($ex->getMessage());
}
}
Nevertheless, the code inserts items into the right categories. After about 38 items it stops, with no error and nothing. The Ajax call returns no errors, nothing. Any ideas what this can be caused by?
cheers
Wolfgang
I would guess that you are hitting the script execution time limit (php.ini max_execution_time)
Assuming you are not running in PHP’s “Safe Mode”, try inserting the following at the top of your method. (I am assuming this method gets called over and over again. It will reset the time limit each time)