【问题标题】:Magento SQL Query to show product manufacturerMagento SQL 查询以显示产品制造商
【发布时间】:2016-03-19 03:05:05
【问题描述】:

我正在尝试在 Magento 1.7.0.2 中查询产品制造商。我一遍又一遍地浏览所有表格,找到制造商表格并将其与产品 SKU 连接起来。

我试试这个查询,希望能得到产品的厂家:

SELECT 
eav_attribute_option_value.value FROM 
eav_attribute,
eav_attribute_option,
eav_attribute_option_value 
WHERE 
eav_attribute.attribute_code = 'manufacturer' AND
eav_attribute_option.attribute_id = eav_attribute.attribute_id AND
eav_attribute_option_value.option_id = eav_attribute_option.option_id

但当我将结果与我的 magento admin 产品制造商进行比较时,它不等于产品制造商。

我的问题是,我应该怎么做才能查询到该产品的制造商列表,以便我可以sql joincatalog_product_enitySKU

有人知道我的案子吗?我是 magento 的新手,所以请对我温柔一点。 任何帮助将不胜感激,在此先感谢

【问题讨论】:

    标签: sql magento


    【解决方案1】:

    希望我理解正确。
    如果您想获得产品的制造商,您不需要任何查询。
    这应该有效。假设您已经拥有 var $_product 中的产品;

    $_product->getAttributeText('manufacturer');//this gets you the label
    $_product->getManufacturer(); //gets the manufacturer id
    

    [编辑]
    要为所有产品获取此信息,请执行以下操作:

    $collection = Mage::getModel('catalog/product')->getCollection()
        ->addAttributeToSelect('manufacturer');
    $collection->addAttributeToFilter('status', 1);//optional for only enabled products
    $collection->addAttributeToFilter('visibility', 4);//optional for products only visible in catalog and search
    foreach ($collection as $product) {
       $sku = $product->getSku();
       $manufacturerId = $product->getManufacturer();
       $manufacturerLabel = $product->getAttributeText('manufacturer');
       //do something with the values above - like write them in a csv or excel
    }
    

    【讨论】:

    • 我需要一个查询,因为我正试图将它放在 excel 文件中...但是感谢您的回答 Marius..
    • 我已经编辑了答案,并附上了有关如何为所有产品获取此信息的附加信息。
    • @gadss,您是否曾经提出过使用相关产品拉动制造商的查询?我正在尝试这样做
    【解决方案2】:

    有点晚了,但这是我想出的。像魅力一样工作。

    SELECT cpe.sku, cpev.value, cpf1.manufacturer_value 
    FROM catalog_product_entity cpe 
    JOIN catalog_product_entity_varchar cpev ON cpev.entity_id = cpe.entity_id
    JOIN catalog_product_flat_1 cpf1 ON cpf1.entity_id = cpe.entity_id
    WHERE cpev.attribute_id = 191
    

    【讨论】:

    • "cpf1.manufacturer" 而不是 "c​​pf1.manufacturer_value" 对我很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多