Magento - 具有 1000 种颜色选项的可配置产品会减慢产品详细信息页面加载时间


Magento - Configurable products with 1000's of color options slow product detail page load time

我们有一个magento商店,里面有大约5k的可配置产品。对于这些产品,我们有 29k+ 的"颜色"属性选项。这严重减慢了我们的商店速度(加载产品详细信息页面需要 10-20 秒)。

许多开发人员告诉我们,他们可以使用直接查询来解决速度问题。然而,他们中没有一个人能够真正完成这项任务。

这里有人以前成功地做到这一点吗?任何建议、代码等。将不胜感激。我花了很多时间在这里环顾四周,没有看到这个问题的任何具体答案。

由于我今天遇到了类似或完全相同的问题,我想发布解决方案:

就我而言,我有可配置的属性,可能有 20k 个选项。商品详情页面需要很长时间才能加载。

经过一些研究,我发现其他人也有类似的问题:链接 1链接 2

解决方案如下:

我复制了:/app/code/core/Mage/ConfigurableSwatches/Model/Resource/Catalog/Product/Attribute/Super/Collection.php

到本地:/app/code/local/Mage/ConfigurableSwatches/Model/Resource/Catalog/Product/Attribute/Super/Collection.php

(请注意,您应该更改:$fallbackStoreId变量)

并进行了以下更改以加快速度:

/**
 * Load attribute option labels for current store and default (fallback)
 *
 * @return $this
 */
protected function _loadOptionLabels()
{
    if ($this->count()) {
        $labels = $this->_getOptionLabels();
        foreach ($this->getItems() as $item) {
            $item->setOptionLabels($labels);
        }
    }
    return $this;
}
/**
 * Get Option Labels
 *
 * @return array
 */
protected function _getOptionLabels()
{
    $attributeIds = $this->_getAttributeIds();
    // Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
    $fallbackStoreId = 2;
    $select = $this->getConnection()->select();
    $select->from(array('options' => $this->getTable('eav/attribute_option')))
        ->join(
            array('labels' => $this->getTable('eav/attribute_option_value')),
            'labels.option_id = options.option_id',
            array(
                'label' => 'labels.value',
                'store_id' => 'labels.store_id',
            )
        )
        ->where('options.attribute_id IN (?)', $attributeIds)
        ->where(
            'labels.store_id IN (?)',
            array($fallbackStoreId, $this->getStoreId())
        );

    $labels = array();
    $thisClass = $this;
    Mage::getSingleton('core/resource_iterator')->walk(
        $select,
        array(function($args) use (&$thisClass){
            $data = $args['row'];
            $labels[$data['option_id']][$data['store_id']] = $data['label'];
        })
    );
    return $labels;
}
/**
 * Get Attribute IDs
 *
 * @return array
 */
protected function _getAttributeIds()
{
    $attributeIds = array();
    foreach ($this->getItems() as $item) {
        $attributeIds[] = $item->getAttributeId();
    }
    $attributeIds = array_unique($attributeIds);
    return $attributeIds;
}