2

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') ->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)) ->addAttributeToFilter('sku',$_sku); 

it does the job.

1 Answer 1

3

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:

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.