Himberjack Himberjack - 1 year ago 137
PHP Question

Magento ->getSku() or getData(’sku’) returns empty string

I have Magento 1.3.2 and I have weird issue:

When I am in

, and I try to fetch the SKU by using
I get empty string.
does work. However, when I do that from other pages, it works well.

-ed it and no SKU is shown.

What can cause this?

Answer Source

The other option is to re-load the product object in the list.phtml using the ID of the product you already have. The code reads something a little like:

$sku = Mage::getModel('catalog/product')->load($_product->getId())->getSku();

Note that $_product is what you are getting in your collection already, and note that getSku is case sensitive (as are all Magento attributes getter/setters).

@Prattski's solution is preferable as you don't really want to be messing with loading/manipulating the objects, but it sounds as though your collection is a little messed up. SKU is one of the core fields that exists in the base catalog_product_entity table, so would be unusual not to be loaded.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download