1

I don't try to set price attribute during product import. Product is inserted into Magento catalog with its name, sku, description but price attribute is empty. The code I used is the following:

$product_model = Mage::getModel('catalog/product');
$productId = $product_model->getIdBySku($sku);
$categoriesIds = array($categoryId);
if (!$productId) {
    //inserimento
    $product_model
        ->setSku($sku)
        ->setName($name)
        ->setDescription($description)
        ->setShortDescription($shortDescription)
        ->setStatus(Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
        ->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
        ->setAttributeSetId(10)
        ->setCategoryIds($categoriesIds)
        ->setPrice($price)
        ->setPrice(11.22) 
        ->setCost(22.33) 
        ->setSpecialPrice(00.44) 
        ->setSpecialFromDate('06/1/2014') 
        ->setSpecialToDate('06/30/2014')
        ->setMsrpEnabled(1)
        ->setMsrpDisplayActualPriceType(1) 
        ->setMsrp(99.99)
        ->setTaxId(2); 
    $qty = 1;
    try {
        $productId = $product_model->save()->getId();
        $product = $product_model->load($productId);
        $product->setQty($qty);
        $product->setIsInStock(1); //->isInStock(1)
        $product->save();
    } catch(Exception $e) {
        Mage::log($e->getMessage());
    }
} else {

}

Can you help me, please? Thanks!!

3 Answers 3

1

As I think you added price two time and in first time there is no value in $ price. Please remove firset setPrice($price) and then try it will work.

1
  • I removed this row but price attribute is already empty
    – Federica
    Sep 9, 2016 at 10:52
1

Try with $product_model->setData('price', $price);

6
  • price isn't set..
    – Federica
    Sep 9, 2016 at 12:32
  • First debug whether you are receiving any amount in $price value or try with static value
    – mp196
    Sep 9, 2016 at 12:42
  • $price value arrives from a txt file.. I printed it and its value isn't empty..
    – Federica
    Sep 9, 2016 at 12:48
  • may be reading from text file is the issue it might be converting the price to string try using (float)$price
    – mp196
    Sep 9, 2016 at 12:53
  • the problem remains..
    – Federica
    Sep 9, 2016 at 13:22
1

Write below line in if block.

 $product_model->setStoreId(0);
 $product_model->setWebsiteId(0);

We need to set the store and website Id while importing products.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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