0

we would like to check if products exists with the following code:

$foundProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

We only get positive results if "Use Flat Catalog Product" is disabled in the configuration.

1
  • try reindexing and recheck the results
    – MTM
    Commented Aug 14, 2014 at 19:02

3 Answers 3

0

Try using $_product = Mage::getModel('catalog/product')->load($productSku, 'sku'); instead of Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

2
  • I don't know why, but this seems to help. Thank you very much! Commented Aug 15, 2014 at 7:40
  • Remember to mark the question as resolved,
    – mbalparda
    Commented Aug 15, 2014 at 10:02
1

the only working solution for both disabled and enabled products I found here: http://magentoexplorer.com/how-load-product-by-sku-or-id-in-magento

$_sku = 'leathershoes';

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

$_productId = $_catalog->getIdBySku($_sku);

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

0

Just tested this on a category page, and it does work. On which page are u trying to do this, and in what code are you using $foundProduct?

Have you reindexed all indexes after enabling flat catalog? cleared all caches? Perhaps try to run the code with all caches disabled.

2
  • I use the line in a script to modify some product data. Yes, everything was reindexed, caches cleared. Commented Aug 14, 2014 at 19:18
  • In a custom module? or existing page? what's the scope of the code? frontend/backend? Commented Aug 14, 2014 at 19:43

Your Answer

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

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