3

I have imported some products into Magento and I am faced with this problem. enter image description here enter image description here

I don't really know where to start debugging this. This is how I am setting the price at the moment (removed some data for clarity):

$productData = array(
        'price'                             => $sellPrice          
    );
$mc = new Mage_Catalog_Model_Product_Api();
$mc->update($productId, $productData);

Should I be updating another attribute somewhere?

Edit When debugging the SQL that runs, I can see in Grid.php _prepareCollection that $collection->addAttributeToSelect('price'); is called but when I do (string)$this->getCollection()->getSelect() the price column isn't selected in the SQL which I assume is why they all default to zero.

8
  • Did you rebuild the price indexes after saving?
    – Marius
    Commented Mar 10, 2014 at 10:12
  • I didn't, running it now.
    – webnoob
    Commented Mar 10, 2014 at 10:12
  • @Marius - I have just re-indexed everything and it's still showing as above.
    – webnoob
    Commented Mar 10, 2014 at 10:14
  • When you have more than one storeview, what storeview is chosen above the product grid? And I would dig into the collection and check what is selected to show in the grid. Whatever is selected is wrong - but I'm to lazy... ahh have too much work to do, to dig into the code. Commented Mar 10, 2014 at 11:43
  • @FabianBlechschmidt - The snide comments about debugging aside, the price isn't in the collection SQL that runs.
    – webnoob
    Commented Mar 10, 2014 at 14:05

2 Answers 2

3

I don't know how the Mage_Catalog_Model_Product_Api works so I'm writing this alternative.

$productId = 10; //replace with your product id
$sellPrice = 9.90; //replace with own price
$productData = array(
    'price' => $sellPrice          
);

Mage::getSingleton('catalog/product_action')->updateAttributes(
    array($productId), //list of product ids to be updated
    $productData, //array with attributes to be updated
    0 //store id - 0 means "default values"
);

This always worked for me.

[EDIT]
For websites use this to add products to websites:

Mage::getModel('catalog/product_website')->addProducts($websiteIds, $productIds)

and this to remove products from websites:

Mage::getModel('catalog/product_website')->removeProducts($websiteIds, $productIds);
3
  • I get Call to a member function getAttributeId() on a non-object in Mage\Catalog\Model\Resource\Product\Action.php line 69. The attribute it's complaining about is websites which I populate in the same way as the price but passing through an array of website Ids 'websites' => $productWebsiteIds,
    – webnoob
    Commented Mar 10, 2014 at 11:07
  • @webnoob for websites is a little different. See my updated answer.
    – Marius
    Commented Mar 10, 2014 at 11:20
  • Thanks for that. Would you be able to cast your eye over my edit please? I'm hesitant to change parts of the code until I understand what is causing the problem in the first place.
    – webnoob
    Commented Mar 10, 2014 at 14:08
2

I actually ran into the same problem importing a large amount of products. After importing prices were showing an incorrect value when browsing but the correct price when viewing the product on the product page.

The solution: If you have a store with multiple views, you need to assign the problem products to those views and re-index.

4
  • Could you clarify what you mean by assign the items to the view? I assign them to a store, isn't that enough?
    – webnoob
    Commented Mar 10, 2014 at 13:27
  • In my case, they were assigned on import but for some reason I had to reassign (within the admin panel) and re-index. Also ensure that the Price attribute is using the global value and not store value (if you've changed the defaults). Try a few problem products instead of the whole store to confirm.
    – SR_Magento
    Commented Mar 10, 2014 at 13:37
  • Could you take a look at my edit please? Editing 7000 items in the database via the admin panel isn't an option for me :)
    – webnoob
    Commented Mar 10, 2014 at 14:08
  • You can select all the affected products and update them with the "Update attributes" drop down on the Manage Products view in the admin panel.
    – SR_Magento
    Commented Mar 10, 2014 at 14:13

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