Search code examples
mysqlmagento-1.9

How to get all custom attribute data using product id with custom query?


I have no idea about how to get all products custom attributes data using product id but not using like this : $_product = Mage::getModel('catalog/product')->load(674);

I need using custom MySql query.


Solution

  • You can use this:

    $collection = Mage::getResourceModel('catalog/product_collection')
        ->addIdFilter(674)
        ->addAttributeToSelect('*');
    

    Using echo $collection->getSelect()->__toString(); will print a SQL query like:

    SELECT e.entity_id, e.type_id, e.attribute_set_id, [...] FROM catalog_product_flat_2 AS e WHERE (e.status = 1) AND (e.entity_id = '674')

    If you want to outpu all data you can use

    var_dump($collection->getFirstItem()->getData());