Magento2:可配置产品:在list.phtml中获取样本属性需要太多时间 [英] Magento2 :Configurable product: Get swatch attributes in list.phtml takes too much time

查看:165
本文介绍了Magento2:可配置产品:在list.phtml中获取样本属性需要太多时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前提条件 Magento CE 2.2.0 PHP 7.0.23-1

Preconditions Magento CE 2.2.0 PHP 7.0.23-1

数据库从1.9.2迁移到2.2.0

Database migrated from 1.9.2 to 2.2.0

检查了不同的实例和不同的版本. 已配置的最高服务器配置.

Checked with different instances and various versions. Configured highest possible server configuration.

-我们有一个分类"类别,只有12种可配置产品.每个可配置产品至少包含1100个简单产品,其中一些产品包含1500多个简单产品,并且在一个分类"类别下总共包含超过13000个产品(包括可配置和简单变体).

-We have one 'classicrings' category, there are only 12 configurable products. Each configurable product containing minimum 1100 simple products, some of them have more than 1500 simple products and total more than 13k products (including with configurable and simple variations) under one 'classicrings' category.

一个可配置的产品具有5个属性'颜色,材料,饰面,厚度,宽度',我们在列表页上显示每个产品的属性,包括其所有色板选项(例如颜色:红色,绿色,黄色..,材料:10k,14k,18k ..,宽度:2mm,4mm至12mm ..等)

one configurable product have 5 attributes 'color, material,finishing,thickness,width' and we displaying the each product attributes on listing page, including with its all swatch options (like color :red,green,yellow.., material: 10k,14k,18k.., width:2mm,4mm to 12mm.. etc.)

复制步骤

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

When we click on classicrings category (i.e. listing page in frontend) to display the all 12 configurable products in frontend then server going to time out Or loading page some times after 10 to 15 min.

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

-So, we debugged the list.phtml code and commented the below code, through from which all swatch attributes and its options is coming on listing page :

//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秒(包括显示所有属性和选项).

category Product listing page should be load with all attribute and options, withing at least 2 to 5 seconds (Including with showing all attributes and options).

实际结果

请求超时

此请求的处理时间太长,服务器已将其超时.如果不应该超时.有时系统崩溃了.

This request takes too long to process, it is timed out by the server. If it should not be timed out. Sometime system crashed.

对于较小的产品版本,它的加载效果不错,但也需要40秒钟以上的时间.

For smaller product variations, it is loading good, but its also taking more than 40 seconds.

推荐答案

要改善列表页面的性能:

To improve the listing page performance :

我尝试通过ajax调用一个接一个地加载每个产品的swatch选项来为此页面实现单独的ajax调用,这样我可以提高页面速度,但是页面加载的时间却更多,而用户体验却不尽如人意好.

I have tried to implement seperate ajax call for this page by loading each product's swatch options one by one through ajax call then I can able to increase page speed, But still page is loading much more time to load and user experience is not good.

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

Also, I have tried to fetch and display the swatch data by another method , using the concept of filter only one swatch attribute (in my case "Width" attribute). For the same, I have overridden the "SwatchAttributesAsArray" function of class 'Magento\Swatches\Helper\Data' by using plugin. But still its taking min 5 to 8 min to load the page.

已通过以下方式实现了代码: //di.xml-输入名称="Magento \ Swatches \ Helper \ Data" //plugin name ="RestrictProductsOptions" type ="Synapsemage \ Import \ Plugin \ SwatchData"

Have implemented the code in below way: //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;
}

}

这篇关于Magento2:可配置产品:在list.phtml中获取样本属性需要太多时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆