It works beautifully if I'm trying to get collection but it won't for single product by SKU. for example:

$product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_sku);
    echo $test =  $product->getSelect()->__toString();

How can I get sql for a single product can I? or I must get collection with filter by sku then getSelect()....

... after a quick research ...

        $products = Mage::getModel('catalog/product')
                    ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED))

it does the job.


load() (or loadByAttribute()) would execute the query already - so you'll have to catch the query before it is executed. As you say, for example by using ->getSelect()->__toString() on your getCollection().

Some references on this topic:

| improve this answer | |

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.