2
            $product_sku = $mpn; 
        $obj = Mage::getModel('catalog/product');
        $product_id = $obj->getIdBySku( $product_sku );
        $_product = $obj->load($product_id); // this is the problematic line

The above code is in a ajax controller. I am attempting to pull in the short description using the. The sku is fine and the product id is fine. The problem occurs when we get to $obj->load($product_id). The page load times out when I include this line though I have read numerous tutorials which instruct you to use this same sequence of methods. I thought that it might be because some of the products don't have a short description?? The next stage would be to use $_product->getShortDescription() but I can't get any further. I have tried everything I can think of. Has anybody got any ideas on why this is wrong?

2

You could also try simply loading the attribute raw value. Firstly you need the class Mage_Catalog_Model_Resource_Product, then you need to get the product id from the sku and then you can load the store specific value.

$resourceModel = Mage::getResourceModel('catalog/product');
$productId = $resourceModel->getIdBySku('your-product-sku');
$attributeValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue($productId, 'attribute_code', $storeId);
| improve this answer | |
1

Load the product directly by the attribute:

$_product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'my-product-sku');
echo($_product->getShortDescription());
| improve this answer | |
  • enzo - $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'my-product-sku'); worked successfully. $_product->getShortDescription() just returns a boolean so i just did $_product->shortDescription which worked. thanks for the help. – jonnjo2005 Oct 2 '14 at 14:28

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.