Php Magento-可配置的产品,具有1000';颜色选项的数量减少了产品详细信息页面加载时间
我们有一家magento商店,拥有约5k可配置产品。对于这些产品,“颜色”属性有29k+选项。 这严重降低了我们商店的速度(10-20秒加载产品详细信息页面) 许多开发人员告诉我们,他们可以使用直接查询来绕过速度问题。然而,他们中没有一个人真正能够完成这项任务Php Magento-可配置的产品,具有1000';颜色选项的数量减少了产品详细信息页面加载时间,php,mysql,magento,Php,Mysql,Magento,我们有一家magento商店,拥有约5k可配置产品。对于这些产品,“颜色”属性有29k+选项。 这严重降低了我们商店的速度(10-20秒加载产品详细信息页面) 许多开发人员告诉我们,他们可以使用直接查询来绕过速度问题。然而,他们中没有一个人真正能够完成这项任务 这里有没有人成功地做到了这一点??任何建议、代码等。。非常感谢。我在这里花了很多时间四处看看,还没有看到这个问题的任何具体答案。因为我今天遇到了类似或可能完全相同的问题,所以我想发布解决方案: 在我的例子中,我有一个可配置的属性,可能有2
这里有没有人成功地做到了这一点??任何建议、代码等。。非常感谢。我在这里花了很多时间四处看看,还没有看到这个问题的任何具体答案。因为我今天遇到了类似或可能完全相同的问题,所以我想发布解决方案: 在我的例子中,我有一个可配置的属性,可能有20k个选项。 加载产品详细信息页面花费了很长时间 经过一些研究,我发现其他ppl也有类似的问题: 解决办法如下: 我复制了: /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;
}
由于我今天遇到了类似或完全相同的问题,我想发布解决方案: 在我的例子中,我有一个可配置的属性,可能有20k个选项。 加载产品详细信息页面花费了很长时间 经过一些研究,我发现其他ppl也有类似的问题: 解决办法如下: 我复制了: /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;
}
你能将颜色选项的HTML预生成到一个静态HTML文件中,并将其包含在其中吗?颜色选择器是否适合你,还是你只需要特定的颜色?颜色属性的29k选项:O如何命名这些颜色?我将从分析页面开始,找出慢速查询的位置。问题可能不是核心的Magento代码,而是失控的查询或Magento试图加载颜色过多的产品选项选择。即使不是这样,知道是什么让你的页面变慢也是加速的第一步。你能把颜色选项的HTML预生成成一个静态HTML文件吗,只需将其包括在内?颜色选择器是否适用于您,还是您只需要特定的颜色?颜色属性的29k选项:O如何命名这些颜色?我将从分析页面开始,找出慢速查询的位置。问题可能不是核心的Magento代码,而是失控的查询或Magento试图加载颜色过多的产品选项选择。即使不是这样,知道是什么让你的页面变慢也是加速的第一步。