Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.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
Magento2 过滤器不会恢复产品属性中的系统值_Magento2 - Fatal编程技术网

Magento2 过滤器不会恢复产品属性中的系统值

Magento2 过滤器不会恢复产品属性中的系统值,magento2,Magento2,我有一个自定义的产品属性。在backoffice中,值可以很好地恢复,但在层导航中,筛选器找不到值 有什么想法吗 这是属性创建: $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); $eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'longueur_tasse_vertuo', [ '

我有一个自定义的产品属性。在backoffice中,值可以很好地恢复,但在层导航中,筛选器找不到值

有什么想法吗

这是属性创建:

$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);  

$eavSetup->addAttribute(
    \Magento\Catalog\Model\Product::ENTITY, 'longueur_tasse_vertuo', [
        'type'  => 'text',
        'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
        'frontend' => '',
        'label' => 'Longueur de tasse Vertuo',
        'input' => 'multiselect',
        'class' => '',
        'source' => 'Cpy\Catalog\Model\Config\Product\CupSizeVertuooption',
        'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
        'visible' => true,
        'required' => false,
        'group' => '',
        'sort_order' => 203,
        'searchable' => false,
        'filterable' => true,
        'comparable' => false,
        'used_in_product_listing' => true,
        'visible_on_front' => true
    ]
);
这是源模型

class CupSizeVertuooption extends AbstractSource
{
    /**
     * @var \Magento\Eav\Model\ResourceModel\Entity\AttributeFactory
     */
    protected $_eavAttrEntity;

    /**
     * @param \Magento\Eav\Model\ResourceModel\Entity\AttributeFactory $eavAttrEntity
     * @codeCoverageIgnore
     */
    public function __construct(
        \Magento\Eav\Model\ResourceModel\Entity\AttributeFactory $eavAttrEntity
    ) {
        $this->_eavAttrEntity = $eavAttrEntity;
    }

    public function getAllOptions()
    {
        $this->_options = [];
        $this->_options[] = ['label' => 'Espresso', 'value' => '1'];
        $this->_options[] = ['label' => 'Double Espresso', 'value' => '2'];
        $this->_options[] = ['label' => 'Gran Lungo', 'value' => '3'];
        $this->_options[] = ['label' => 'Mug', 'value' => '4'];
        $this->_options[] = ['label' => 'Alto', 'value' => '5'];

        return $this->_options;
    }

    /**
     * Retrieve option array
     *
     * @return array
     */
    public function getOptionArray()
    {
        $_options = array();
        foreach ($this->getAllOptions() as $option) {
            $_options[$option['value']] = $option['label'];
        }
        return $_options;
    }

    /**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string|bool
     */
    public function getOptionText($value)
    {
        foreach ($this->getAllOptions() as $option) {
            if ($option['value'] == $value) {
                return $option['label'];
            }
        }
        return false;
    }

    /**
     * Retrieve flat column definition
     *
     * @return array
     */
    public function getFlatColumns()
    {
        $attributeCode = $this->getAttribute()->getAttributeCode();

        return [
            $attributeCode => [
                'unsigned' => false,
                'default' => null,
                'extra' => null,
                'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                'length' => 255,
                'nullable' => true,
                'comment' => $attributeCode . ' column',
            ],
        ];
    }

    /**
     * Retrieve Indexes(s) for Flat
     *
     * @return array
     */
    public function getFlatIndexes()
    {
        $indexes = [];

        $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode());
        $indexes[$index] = ['type' => 'index', 'fields' => [$this->getAttribute()->getAttributeCode()]];

        return $indexes;
    }

    /**
     * Retrieve Select For Flat Attribute update
     *
     * @param int $store
     * @return \Magento\Framework\DB\Select|null
     */
    public function getFlatUpdateSelect($store)
    {
        return $this->_eavAttrEntity->create()->getFlatUpdateSelect($this->getAttribute(), $store);
    }
}
如您所见,他能够恢复属性…但不能恢复其内容

尽管如此,如果我去检查我的后端属性,这些值都在那里

此外,这是块定义:

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.cafe.cupsize" template="Magento_Catalog::product/view/cafe/cup-size.phtml" before="product.info.price" >
    <arguments>
        <argument name="at_call" xsi:type="string">getLongueurTasse</argument>
        <argument name="at_code" xsi:type="string">longueur_tasse</argument>
        <argument name="at_type" xsi:type="string">text</argument>
        <argument name="css_class" xsi:type="string">product-nespresso-cupsize</argument>
        <argument name="at_label" xsi:type="string">Taille des tasses :</argument>
        <argument name="add_attribute" xsi:type="string">itemprop="nespresso-cupsize"</argument>
    </arguments>
</block>

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.cafe.cupsize.vertuo" template="Magento_Catalog::product/view/cafe/vertuo/cup-size.phtml" before="product.info.price" >
    <arguments>
        <argument name="at_call" xsi:type="string">getLongueurTasseVertuo</argument>
        <argument name="at_code" xsi:type="string">longueur_tasse_vertuo</argument>
        <argument name="css_class" xsi:type="string">product-nespresso-cupsize-vertuo</argument>
        <argument name="at_label" xsi:type="string">Taille des tasses :</argument>
        <argument name="add_attribute" xsi:type="string">itemprop="nespresso-cupsize"</argument>
    </arguments>
</block>

格特朗格乌塔斯
隆古尔塔塞
文本
产品nespresso cupsize
塔塞斯泰勒:
itemprop=“nespresso杯形尺寸”
格特隆古尔塔塞维托
隆古尔·塔斯沃·维托
产品nespresso cupsize vertuo
塔塞斯泰勒:
itemprop=“nespresso杯形尺寸”

主要问题属于类
供应商/magento/module catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

方法

protected function _getIndexableAttributes($multiSelect)
{
    $select = $this->getConnection()->select()->from(
        ['ca' => $this->getTable('catalog_eav_attribute')],
        'attribute_id'
    )->join(
        ['ea' => $this->getTable('eav_attribute')],
        'ca.attribute_id = ea.attribute_id',
        []
    )->where(
        $this->_getIndexableAttributesCondition()
    );

    if ($multiSelect == true) {
        $select->where('ea.backend_type = ?', 'varchar')->where('ea.frontend_input = ?', 'multiselect');
    } else {
        $select->where('ea.backend_type = ?', 'int')->where('ea.frontend_input IN( ? )', ['select', 'boolean']);
    }
    return $this->getConnection()->fetchCol($select);
}
对于multiselect,所需的类型是varchar,而我的属性的类型是text

因此,我们所要做的就是将属性类型更改为varchar,然后再次播放索引器,以将关联geing写入表
catalog\u product\u index\u eav
,从而使其可能出现在过滤器中


这是一个快速、即时的解决方案。同时,我将问题发送给magento,以使此multiselect条件能够读取文本和varchar类型,请随意检查:

主要问题属于类
vendor/magento/module catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php

方法

protected function _getIndexableAttributes($multiSelect)
{
    $select = $this->getConnection()->select()->from(
        ['ca' => $this->getTable('catalog_eav_attribute')],
        'attribute_id'
    )->join(
        ['ea' => $this->getTable('eav_attribute')],
        'ca.attribute_id = ea.attribute_id',
        []
    )->where(
        $this->_getIndexableAttributesCondition()
    );

    if ($multiSelect == true) {
        $select->where('ea.backend_type = ?', 'varchar')->where('ea.frontend_input = ?', 'multiselect');
    } else {
        $select->where('ea.backend_type = ?', 'int')->where('ea.frontend_input IN( ? )', ['select', 'boolean']);
    }
    return $this->getConnection()->fetchCol($select);
}
对于multiselect,所需的类型是varchar,而我的属性的类型是text

因此,我们所要做的就是将属性类型更改为varchar,然后再次播放索引器,以将关联geing写入表
catalog\u product\u index\u eav
,从而使其可能出现在过滤器中


这是一个快速、即时的解决方案。同时,我将问题发送给magento,以使此multiselect where条件能够读取文本和varchar类型,请随意检查:

问题仍未解决:/issue仍然未解决:/