Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在比较页面Magento上显示相同的产品属性排序_Magento_Sorting_Attributes_Compare_Webpage - Fatal编程技术网

如何在比较页面Magento上显示相同的产品属性排序

如何在比较页面Magento上显示相同的产品属性排序,magento,sorting,attributes,compare,webpage,Magento,Sorting,Attributes,Compare,Webpage,我不知道为什么比较页面上的产品属性排序与产品页面上的排序不一样。就像在产品页面上一样,阿曲布他类是 在产品页面上 但在comapre页面上,当我比较这两种产品具有相同的属性时,属性排序顺序变为 比较页面上的 1 name 2 color 3 new attribute 4 new attribute1 我在谷歌上搜索了很多答案,但是找不到。请帮我解决这个问题 下面是我找到的函数 public function getComparableAttributes() { i

我不知道为什么比较页面上的产品属性排序与产品页面上的排序不一样。就像在产品页面上一样,阿曲布他类是

在产品页面上

但在comapre页面上,当我比较这两种产品具有相同的属性时,属性排序顺序变为

比较页面上的

1 name
2 color
3 new attribute
4 new attribute1 
我在谷歌上搜索了很多答案,但是找不到。请帮我解决这个问题

下面是我找到的函数

public function getComparableAttributes()
    {
        if (is_null($this->_comparableAttributes)) {
            $this->_comparableAttributes = array();
            $setIds = $this->_getAttributeSetIds();
            if ($setIds) {
                $attributeIds = $this->_getAttributeIdsBySetIds($setIds);

                $select = $this->getConnection()->select()
                    ->from(array('main_table' => $this->getTable('eav/attribute')))
                    ->join(
                        array('additional_table' => $this->getTable('catalog/eav_attribute')),
                        'additional_table.attribute_id=main_table.attribute_id'
                    )
                    ->joinLeft(
                        array('al' => $this->getTable('eav/attribute_label')),
                        'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int) $this->getStoreId(),
                        array('store_label' => $this->getConnection()->getCheckSql('al.value IS NULL', 'main_table.frontend_label', 'al.value'))
                    )
                    ->where('additional_table.is_comparable=?', 1)
                    ->where('main_table.attribute_id IN(?)', $attributeIds);
                $attributesData = $this->getConnection()->fetchAll($select);
                if ($attributesData) {
                    $entityType = Mage_Catalog_Model_Product::ENTITY;
                    Mage::getSingleton('eav/config')
                        ->importAttributesData($entityType, $attributesData);
                    foreach ($attributesData as $data) {
                        $attribute = Mage::getSingleton('eav/config')
                            ->getAttribute($entityType, $data['attribute_code']);
                        $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
                    }
                    unset($attributesData);
                }
            }
        }
        return $this->_comparableAttributes;
    }

/**
 * Load Comparable attributes
 *
 * @return Mage_Catalog_Model_Resource_Product_Compare_Item_Collection
 */
public function loadComparableAttributes()
{
    $comparableAttributes = $this->getComparableAttributes();
    $attributes = array();
    foreach ($comparableAttributes as $attribute) {
        $attributes[] = $attribute->getAttributeCode();
    }
    $this->addAttributeToSelect($attributes);

    return $this;
}

但我不知道如何按排序顺序进行筛选。请建议在产品页面上按属性集中的顺序对属性进行排序

在比较页上,属性根本没有排序。 您可以在类中重写函数GetCompariableAttribute,并实现自己的排序逻辑


但请注意,此功能在不同的Magento版本中有所不同。您可以尝试使用免费扩展或从此扩展中获取部分代码(代码可在bitbucket.org.link i的扩展页上找到)

检查以下功能中的修改: 使用的文件是供应商/magento/module catalog/Model/ResourceModel/Product/Compare/Item/Collection.php
但这不是最好的方法。您需要按照Magento标准覆盖它。 我正在努力,很快就会更新

public function getComparableAttributes()
{
    if ($this->_comparableAttributes === null) {
        $this->_comparableAttributes = [];
        $setIds = $this->_getAttributeSetIds();
        if ($setIds) {
            $attributeIds = $this->_getAttributeIdsBySetIds($setIds);

            $select = $this->getConnection()->select()->from(
                ['main_table' => $this->getTable('eav_attribute')]
            )->join(
                ['additional_table' => $this->getTable('catalog_eav_attribute')],
                'additional_table.attribute_id=main_table.attribute_id'
            )->joinLeft(
                ['al' => $this->getTable('eav_attribute_label')],
                'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$this->getStoreId(),
                [
                    'store_label' => $this->getConnection()->getCheckSql(
                        'al.value IS NULL',
                        'main_table.frontend_label',
                        'al.value'
                    )
                ]
            )
                    ->joinLeft( //add sort order to sort the attributes as per backend sort.  -- Abid
                ['as' => $this->getTable('eav_entity_attribute')],
                'as.attribute_id = main_table.attribute_id'
            )
                    ->where(
                'additional_table.is_comparable=?',
                1
            )->where(
                'main_table.attribute_id IN(?)',
                $attributeIds
            )
                    ->order('as.sort_order') //sort by sort_order -- Abid
                    ;
            $attributesData = $this->getConnection()->fetchAll($select);
            if ($attributesData) {
                $entityType = \Magento\Catalog\Model\Product::ENTITY;
                $this->_eavConfig->importAttributesData($entityType, $attributesData);
                foreach ($attributesData as $data) {
                    $attribute = $this->_eavConfig->getAttribute($entityType, $data['attribute_code']);
                    $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
                }
                unset($attributesData);
            }
        }
    }
    return $this->_comparableAttributes;
}

我使用的是企业版,扩展与此版本不兼容。您可以从AdvancedCompare扩展()获取此已更改的函数是的,我已经从那里获得了它,它可以正常工作,谢谢您的帮助
public function getComparableAttributes()
{
    if ($this->_comparableAttributes === null) {
        $this->_comparableAttributes = [];
        $setIds = $this->_getAttributeSetIds();
        if ($setIds) {
            $attributeIds = $this->_getAttributeIdsBySetIds($setIds);

            $select = $this->getConnection()->select()->from(
                ['main_table' => $this->getTable('eav_attribute')]
            )->join(
                ['additional_table' => $this->getTable('catalog_eav_attribute')],
                'additional_table.attribute_id=main_table.attribute_id'
            )->joinLeft(
                ['al' => $this->getTable('eav_attribute_label')],
                'al.attribute_id = main_table.attribute_id AND al.store_id = ' . (int)$this->getStoreId(),
                [
                    'store_label' => $this->getConnection()->getCheckSql(
                        'al.value IS NULL',
                        'main_table.frontend_label',
                        'al.value'
                    )
                ]
            )
                    ->joinLeft( //add sort order to sort the attributes as per backend sort.  -- Abid
                ['as' => $this->getTable('eav_entity_attribute')],
                'as.attribute_id = main_table.attribute_id'
            )
                    ->where(
                'additional_table.is_comparable=?',
                1
            )->where(
                'main_table.attribute_id IN(?)',
                $attributeIds
            )
                    ->order('as.sort_order') //sort by sort_order -- Abid
                    ;
            $attributesData = $this->getConnection()->fetchAll($select);
            if ($attributesData) {
                $entityType = \Magento\Catalog\Model\Product::ENTITY;
                $this->_eavConfig->importAttributesData($entityType, $attributesData);
                foreach ($attributesData as $data) {
                    $attribute = $this->_eavConfig->getAttribute($entityType, $data['attribute_code']);
                    $this->_comparableAttributes[$attribute->getAttributeCode()] = $attribute;
                }
                unset($attributesData);
            }
        }
    }
    return $this->_comparableAttributes;
}