1

i have created a script to import configurable product with its associated products. it was working fine in magento 1.9.0.1 .after i updated my magento to latest version(1.9.2.2) the script is not working.

it showing error while calling $product->save();

the snippet of displaying error - Invalid method Mage_CatalogRule_Model_Rule::loadProductRules(Array ( [0] => Mage_Catalog_Model_Product Object ( [_cacheTag:protected] => catalog_product [_eventPrefix:protected] => catalog_product [_eventObject:protected] => product [_canAffectOptions:protected] => [_typeInstance:protected] => [_typeInstanceSingleton:protected] => Mage_Catalog_Model_Product_Type_Simple Object ( [_product:protected] => [_typeId:protected] => [_setAttributes:protected] => [_editableAttributes:protected] => [_isComposite:protected] => [_canConfigure:protected] => [_canUseQtyDecimals:protected] => 1 [_storeFilter:protected] => [_fileQueue:protected] => Array ( ))

Snippet of Code in Script
$sProduct = Mage::getModel('catalog/product'); $sProduct -> setName($product['name']); $sProduct -> setSku($product['sku']); $sProduct -> setWeight($product['weight']); $sProduct -> setAttributeSetId($product['attribute_set_id']); $sProduct -> setDescription($product['description']); $sProduct -> setShortDescription($product['short_description']); $sProduct -> setTypeId($product['type_id']) -> setWebsiteIds(array(1)) -> setStatus($product['status']) -> setVisibility($product['visibility']) -> setTaxClassId($product['tax_class_id']); $sProduct -> setPrice($product['price']); $sProduct -> setStockData($product['stock_data']); $sProduct -> setCategoryId($product['category_ids']); $optionId = $this -> getOptionId('size', $product['size']); $sProduct -> setData('size', $optionId); $optionIdcolor = $this -> getOptionId('color', $product['color']); $sProduct -> setData('color', $optionIdcolor); $mode = array("small_image", "thumbnail", "image"); $mode1 = array(); $imges = explode(',',$product['img']); $ij = 0; foreach ($imges as $nml) { $imges[$ij] = $nml.'.jpg'; $ij++; } $a = 0; foreach ($imges as $im) { $img = $mediaDir.'/import/'.$im; Mage::log($img); if ($a == 0) { Mage::log($im); if (file_exists($img)) { $sProduct -> addImageToMediaGallery($img, $mode, false, false); } } else { if(substr($im, 0, 1) == ' ') { $im = substr($im, 1); } Mage::log($im); if (file_exists($img)) { $sProduct -> addImageToMediaGallery($img, $mode1, false, false); } } $a++; } $sProduct->save();

i am getting correct values while print_r($sProduct) but it shows error while saving

  • 1
    Share your code as well – Vishwas Bhatnagar Dec 10 '15 at 6:42
  • @VishwasBhatnagar i have added the code – Piyush Dec 10 '15 at 6:56
1

Try bellow script

$sProduct = Mage::getModel('catalog/product');

$optionId = $this->getOptionId('size', $product['size']);
$optionIdcolor = $this->getOptionId('color', $product['color']);

$productData = array(
    'size' => $optionId,
    'color' => $optionIdcolor,
);
$mode = array("small_image", "thumbnail", "image");
$mode1 = array();


$sProduct->setName($product['name']);
$sProduct->setSku($product['sku']);
$sProduct->setWeight($product['weight']);
$sProduct->setAttributeSetId($product['attribute_set_id']);
$sProduct->setDescription($product['description']);
$sProduct->setShortDescription($product['short_description']);
$sProduct->setTypeId($product['type_id']);
$sProduct->setWebsiteIds(array(1));
$sProduct->setStatus($product['status']);
$sProduct->setVisibility($product['visibility']);
$sProduct->setTaxClassId($product['tax_class_id']);
$sProduct->setPrice($product['price']);
$sProduct->setStockData($product['stock_data']);
$sProduct->setCategoryIds($product['category_ids']);
$sProduct->setMediaGallery(array('images'=>array (), 'values'=>array ()));
$sProduct->setData($productData);


$imges = explode(',',$product['img']);
$ij = 0;
foreach ($imges as $nml) {
    $imges[$ij] = $nml.'.jpg';
    $ij++;
}
$a = 0;
foreach ($imges as $im) {
    $img = $mediaDir.'/import/'.$im;
    Mage::log($img);
    if ($a == 0) {
        Mage::log($im);
        if (file_exists($img)) {
            $sProduct->addImageToMediaGallery($img, $mode, false, false);
        }
    } else {
        if(substr($im, 0, 1) == ' ')
            {
                $im = substr($im, 1);
            }
        Mage::log($im);
        if (file_exists($img)) {
            $sProduct->addImageToMediaGallery($img, $mode1, false, false);
        }
    }
    $a++;
}

try {
    $sProduct->save();
} catch (Mage_Core_Exception $e) {
    echo $e->getMessage();
}
  • no change same result – Piyush Dec 10 '15 at 7:36
  • can you share error? – Abdul Dec 10 '15 at 7:37
  • it showing the same error which i mentioned above. – Piyush Dec 10 '15 at 7:37
  • If your tried to create product to admin end then got same error. First check in admin side – Abdul Dec 10 '15 at 7:41
  • no its not working either – Piyush Dec 10 '15 at 7:47
0

I found the proper solution for the issue. it was giving error because during updation some of magento's core files were not downloaded properly . So i replaced the whole core folder with magento's latest version core folder and now its working perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.