3

有谁知道如何entity_id在前端显示为可排序属性?我去管理属性,我不能entity_id像它说的那样添加为属性

“属性码‘entity_id’已被系统保留,请尝试其他属性码”

因此,我尝试在 Magento 使用以下 SQL CMD 的整个数据库中进行搜索:

select attribute_id from eav_attribute where attribute_code = 'updated_at';

它返回零结果,我尝试了其他属性并且显示...

有谁知道我如何将其添加entity_id为属性,因为我什至无法使其可见,因为即使在整个数据库中搜索该值时我也不知道 attribute_id # 是什么。

这是我用来使属性在 magento 的管理部分可见的代码:

UPDATE `catalog_eav_attribute` 
SET `is_visible` = '1' 
WHERE `catalog_eav_attribute`.`attribute_id` = 105;

我已经尝试搜索高低几天,并尝试不同的变化 - 所以停留在这一点上,任何帮助都会很棒。

如果有帮助,我正在使用 Magento Enterprise 12.2,但老实说,数据库与社区版本没有太大区别,唯一的区别是添加的模块,但在产品方面几乎相同。

4

1 回答 1

3

这是令人惊讶的讨厌 - 我无法在数据库中简单地看到这样做的方法,因为 entity_id 不是标准属性(它实际上只是一个关键字段)并且核心代码在三个地方重复相同的逻辑(呃) .

自旧版 Magento 以来,它也发生了很大变化,因此许多关于此的教程和论坛帖子不再适用。

您可以做的是添加“entity_id”作为新的排序选项,类似于“最佳价值”作为排序选项存在的方式。在以下示例中,我将其标记为“最新”

通常的警告适用:您应该在扩展中执行此操作(或至少在 /local/ 覆盖中),但在 Community Edition 1.7 中需要覆盖的三个核心文件方法是:

Mage_Adminhtml_Model_System_Config_Source_Catalog_ListSort

public function toOptionArray()
{
    $options = array();
    $options[] = array(//benz001
            'label' => Mage::helper('catalog')->__('Newest'),
            'value' => 'entity_id'
        );  //end benz001       
    $options[] = array(
        'label' => Mage::helper('catalog')->__('Best Value'),
        'value' => 'position'
    );
    foreach ($this->_getCatalogConfig()->getAttributesUsedForSortBy() as $attribute) {
        $options[] = array(
            'label' => Mage::helper('catalog')->__($attribute['frontend_label']),
            'value' => $attribute['attribute_code']
        );
    }
    return $options;
}

然后 Mage_Catalog_Model_Category_Attribute_Source_Sortby

    /**
 * Retrieve All options
 *
 * @return array
 */
public function getAllOptions()
{
    if (is_null($this->_options)) {
        $this->_options = array(
        array(//benz001
            'label' => Mage::helper('catalog')->__('Newest'),
            'value' => 'entity_id'
        ),  //end benz001
        array(
            'label' => Mage::helper('catalog')->__('Best Value'),
            'value' => 'position'
        ));
        foreach ($this->_getCatalogConfig()->getAttributesUsedForSortBy() as $attribute) {
            $this->_options[] = array(
                'label' => Mage::helper('catalog')->__($attribute['frontend_label']),
                'value' => $attribute['attribute_code']
            );
        }
    }
    return $this->_options;
}

然后是 Mage_Catalog_Model_Config

    public function getAttributeUsedForSortByArray()
{
    $options = array(
        'entity_id' => Mage::helper('catalog')->__('Newest'),   //benz001   
        'position'  => Mage::helper('catalog')->__('Position'),             
    );
    foreach ($this->getAttributesUsedForSortBy() as $attribute) {
        /* @var $attribute Mage_Eav_Model_Entity_Attribute_Abstract */
        $options[$attribute->getAttributeCode()] = $attribute->getStoreLabel();
    }

    return $options;
}

有了这些,刷新缓存并刷新,然后您可以在配置、类别页面和前端选择按 Newest/entity_id 排序。

注意:即使您关闭了缓存,刷新缓存仍然是一个好主意 - 即使禁用了缓存,部分管理员也会被缓存。

于 2012-06-14T12:47:29.487 回答