Question

I have tried searching for this one but haven't had much luck. I have over 15k products in my Magento store. At some point we set some of the product's weight to 999. Now I need to generate a list of all of the products that have that set for the weight. I have been trying to find which table in the mysql database that has this information but I can't seem to find it.

In the end I am trying to make a SQL statement that gives me all the product ids for products whose weight is set to 999.

Thank you in advance to anyone who can help.

Was it helpful?

Solution

The code approach:

Mage::app()->setCurrentStore(0);
$collection = Mage::getResourceModel('catalog/product_collection')
    ->addAttributeToFilter('weight', '999');
$ids = $collection->getAllIds();
//$ids is an array with what you are looking for

The SQL approach.

First get the weight attribute id.

SELECT 
    e.attribute_id 
FROM
    eav_attribute e 
LEFT JOIN 
    eav_entity_type et 
ON 
    e.entity_type_id = et.entity_type_id
WHERE 
    et.entity_type_code = 'catalog_product' AND
    e.attribute_code = 'weight'

Now get all the product ids with the weight 999

SELECT 
    entity_id 
FROM 
    catalog_product_entity_decimal
WHERE
    attribute_id = {RESULT FROM PREV QUERY} AND
    value = 999
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top