簡體   English   中英

Magento-具有1000種顏色選項的可配置產品會減慢產品詳細信息頁面的加載時間

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

我們有一家magento商店,提供約5k可配置產品。 對於這些產品,“顏色”屬性有29k +個選項。 這嚴重降低了我們的存儲速度(加載產品詳細信息頁面需要10-20秒)。

許多開發人員告訴我們,他們可以使用直接查詢來解決速度問題。 但是,實際上沒有一個人能夠完成此任務。

這里有沒有人成功完成此操作? 任何建議,代碼等。將不勝感激。 我花了很多時間在這里四處張望,還沒有看到針對此問題的任何具體答案。

使用redis,nginx和php-fpm在Amazon EC2上進行托管研究。 該數據庫是一個單獨的EC2實例,不是在主機ubuntu安裝上設置的。 我們現在正在這樣做,以推出1.7.0.0安裝。 有了緩存並且沒有優化,我們的速度與專門研究Magento托管的優化虛擬主機公司一樣快。

由於我今天遇到過類似或完全相同的問題,因此我想發布解決方案:

就我而言,我有可配置的屬性,可能有20k個選項。 產品詳細信息頁面花了永遠的時間。

經過一番研究,我發現其他人也有類似的問題: 鏈接1 鏈接2

解決方案如下:

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

到本地:/ app / code / 本地 /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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM