0

前提条件 Magento CE 2.2.0 PHP 7.0.23-1

数据库从 1.9.2 迁移到 2.2.0

检查了不同的实例和各种版本。配置了最高可能的服务器配置。

-我们有一个“经典戒指”类别,只有 12 种可配置产品。每个可配置产品至少包含 1100 个简单产品,其中一些具有 1500 多个简单产品,并且在一个“经典环”类别下总共有 13k 多个产品(包括可配置和简单变体)。

一种可配置产品有 5 个属性“颜色、材料、表面处理、厚度、宽度”,我们在列表页面上显示每个产品属性,包括其所有样本选项(如颜色:红色、绿色、黄色..,材料:10k, 14k,18k..,宽度:2mm,4mm to 12mm..等)

重现步骤

当我们点击 classicrings 类别(即前端的列表页面)以在前端显示所有 12 个可配置产品时,服务器将在 10 到 15 分钟后超时或加载页面。

-因此,我们调试了 list.phtml 代码并注释了以下代码,所有样本属性及其选项都通过该代码出现在列表页面上:

//echo $block->getProductDetailsHtml($_product);

After commenting above line of code, listing page start loading quickly within 2 sec. But this is not the solution. As client want to display the all attributes with its options, which is taking too much time to load and going server time out most of the time.

预期结果

类别产品列表页面应加载所有属性和选项,至少需要 2 到 5 秒(包括显示所有属性和选项)。

实际结果

请求超时

此请求处理时间过长,已被服务器超时。如果不应该超时。有时系统崩溃。

对于较小的产品变化,它加载良好,但也需要 40 多秒。

4

1 回答 1

0

提高列表页性能:

我试图通过ajax调用一个一个地加载每个产品的样本选项来为此页面实现单独的ajax调用,然后我可以提高页面速度,但是页面加载的时间仍然更长,用户体验不好。

此外,我尝试通过另一种方法获取和显示样本数据,使用仅过滤一个样本属性(在我的情况下为“宽度”属性)的概念。同样,我通过使用插件覆盖了类“Magento\Swatches\Helper\Data”的“SwatchAttributesAsArray”函数。但仍然需要 5 到 8 分钟来加载页面。

已按以下方式实现代码: //di.xml -- type name="Magento\Swatches\Helper\Data" //plugin name="RestrictProductsOptions" type="Synapsemage\Import\Plugin\SwatchData"

public function afterGetSwatchAttributesAsArray($subject, $attributesData)
{
    // die('mritu');
    $actions = ['catalog_category_view','catalogsearch_result_index','catalogsearch_advanced_result','import_index_listswatch'];
    if (in_array($this->getFullAction(), $actions))
    {   
        $objectManager = ObjectManager::getInstance();
        //get current category
        $categoryId = $parentId = 0;
        $category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');
        if($category!=null){
            $categoryId = $category->getId();
            $parentId = $category->getParentCategory()->getId();
        }
        if($categoryId==34){
            $newAttributesData = array();
            $newAttributesData[182] = $attributesData[182];
            // print_r($newAttributesData);die;
            return $newAttributesData;
        }

        foreach($attributesData as $attr)
        {
            $attrcode = $attr['attribute_code'];
            if(!empty($attrcode))
            {
                if($categoryId==44){
                    if($attrcode=='stone'){
                      unset($attributesData[$attr['attribute_id']]);
                    }
                }elseif($categoryId==31 || $parentId==31 || $categoryId==28){
                    if($attrcode=='material'){
                      unset($attributesData[$attr['attribute_id']]);
                    }
                    if($categoryId==31 || $parentId==31){
                        if($attrcode=='color'){
                          unset($attributesData[$attr['attribute_id']]);
                        }
                    }
                    if($categoryId==33 ){
                        if($attrcode=='stone'){
                          unset($attributesData[$attr['attribute_id']]);
                        }
                    }
                }elseif($categoryId==21 || $parentId==21){

                    if($attrcode=='stone'){
                      unset($attributesData[$attr['attribute_id']]);
                    }
                }               
            }           
        }
    }
    return $attributesData;
}

}

于 2018-07-18T11:20:04.633 回答