Magento flat indexer不会将'image'属性复制到catalog_product_flat表

1 magento flat

我正在使用Magento Community 1.7.0.2.

最近我决定在我的商店打开"使用平面目录类别"和"使用平面目录类别"选项.我前端使用'image'属性的所有图像都消失了(它们被默认的图像占位符替换).使用"small_image"或"thumbnail"属性显示的所有图像都会正确显示.

我查看了catalog_product_flat_1表,那里没有'image'列(但是'image_label'列...).我查看了平面索引器代码,并能够打印用于获取插入到平面表中的所有属性的SQL语句:

SELECT `main_table`.*, `additional_table`.* 
FROM `eav_attribute` AS `main_table` 
INNER JOIN `catalog_eav_attribute` AS `additional_table` 
ON additional_table.attribute_id = main_table.attribute_id 
WHERE (main_table.entity_type_id = :entity_id) AND (main_table.backend_type = 'static'     
OR additional_table.is_used_for_promo_rules = 1 OR additional_table.used_in_product_listing = 1 OR additional_table.used_for_sort_by = 1 
OR main_table.attribute_code IN('sku', 'type_id', 'name', 'status', 'visibility', 'price', 'weight', 'url_path', 'url_key', 'thumbnail', 'small_image', 
'tax_class_id', 'special_from_date', 'special_to_date', 'special_price', 'cost', 'is_recurring', 'recurring_profile', 'msrp_enabled', 'msrp',
'msrp_display_actual_price_type', 'enable_googlecheckout', 'gift_message_available', 'price_view', 'price_type', 'shipment_type', 'weight_type', 
'sku_type', 'links_purchased_separately', 'links_title', 'short_description', 'image_label', 'thumbnail_label', 'small_image_label', 'news_from_date',
'news_to_date', 'created_at', 'updated_at', 'required_options'))
Run Code Online (Sandbox Code Playgroud)

正如您在列表中看不到'image'属性.

'image'属性用于默认Magento发行版的前端,所以我想知道这是一个bug吗?

Ari*_*lon 5

虽然@Jordi Buj的答案可行,但它不是很可持续.例如,如果您在另一个Magento实例上重用该代码,则在有人按照所述步骤将图像包含在平面表中之前,它可能无法工作.

更正确,基于代码的方法是将以下内容添加到Mage_Catalog_Model_Resource_Product_Collection中:

->joinAttribute('image', 'catalog_product/image', 'entity_id', null, 'left')
Run Code Online (Sandbox Code Playgroud)

而不是典型的:

->addAttributeToSelect('image')
Run Code Online (Sandbox Code Playgroud)

而后者只是将"图像"添加到SELECT的列中(这不会有帮助,因为它不是该平面产品表中的列),前者将明确地与EAV表中的image属性连接.

希望有所帮助.


ebu*_*989 5

我只花了一些时间来解决这个问题,这里是我发现最干净的解决方案,并使用Magento的XML样式抽象来将image列添加到catalog_product_flat_1表中:

在config.xml中:

<config>
    <frontend>
        <product>
            <collection>
                <attributes>
                    <image />
               </attributes>
            </collection>
        </product>
    </frontend>
</config>
Run Code Online (Sandbox Code Playgroud)

然后重新索引您的平面目录表(管理>索引管理>全选+重新索引)并清除所有Magento缓存.