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

标签 php mysql magento

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

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

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

最佳答案

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

在我的例子中,我有可能有 20k 个选项的可配置属性。 产品详细信息页面需要很长时间才能加载。

经过一些研究,我发现其他人也有类似的问题: Link 1 Link 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;
}

关于php - Magento - 具有 1000 种颜色选项的可配置产品会减慢产品详细信息页面的加载时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11084476/

相关文章:

java - 泰语字符显示??????在jsp中标记文件上传

python - Django + InnoDB : random failure of model reading

magento - Magmi 列映射器错误

xml - Magento - 确定页面正在使用哪个 xml 布局文件?

mysql - 将临时表中的内容插入到更新查询中

email - 所有Magento电子邮件模板都位于哪里?

php - 试图创建一个类似于 Facebook 的 "like"系统

php - 在 php 和 MySql 中使用 highcharts 时仅显示我的标题

php - fine-uploader 无法使用 IE7 读取 iframe 响应

php - 如何在 javascript 中访问多维 PHP 数组作为 json 编码的变体?