2017-10-05 46 views
2

將magento 2.1.9應用到我的項目時出現問題。Magento 2.1.9屬性在導航中不顯示。

我的屬性是ab_size

我已創建了代碼打擊該屬性。

$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]); 
     $entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY); 

     foreach ($singleAttributeCodes as $key => $label) { 
      $categorySetup->removeAttribute($entityTypeId, $key); 
      $categorySetup->addAttribute(
       $entityTypeId, 
       $key, 
       [ 
        'type' => 'varchar', 
        'label' => $label, 
        'input' => 'select', 
        'required' => false, 
        'sort_order' => $sortOrder, 
        'visible' => true, 
        'user_defined' => true, 
        'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL, 
        'filterable' => 0, 
        'visible_on_front' => true, 
        'used_in_product_listing' => true, 
        'group' => $group, 
        'apply_to' => 'simple,configurable,bundle,downloadable,grouped', 
       ] 
      ); 
     } 

在後端配置。

  1. 啓用過濾器(帶結果)
  2. 類是錨
  3. 重新編制
  4. 啓用範疇平
  5. 啓用產品平
  6. 個編制所有數據
  7. 清除緩存
  8. 使用的Magento乾淨沒有任何擴展
  9. 請與屬性顏色(做了導航顯示)
  10. 產品價格顯示
  11. 類別顯示

    我的系統信息

  12. 的CentOS 7.0

  13. 的Litespeed
  14. Php7.0
  15. Magento的CE 2.1.9

我已經調試了產品收集桶返回空

我認爲創建屬性代碼的問題,有任何人都有同樣的問題。

謝謝任何​​人有提示。

回答

2

隨着選擇屬性,我們必須使用INT類型..

0

我想你已經把你的屬性弄糟了。 看着它,它刪除所有的屬性,並添加它們,但作爲類型varchar,可能不適用於所有屬性。 我會建議重置您的Magento數據庫,然後使用如下代碼添加屬性。

因爲我不知道你打算使用這個屬性,下面的一些設置可能不適用於你的用例。

$categorySetup->addAttribute(
    \Magento\Catalog\Model\Product::ENTITY, 
     'ab_size', 
     [ 
      'type' => 'varchar', 
      'backend' => '', 
      'frontend' => '', 
      'label' => 'AB Size', 
      'input' => 'select', 
      'class' => '', 
      'source' => '', 
      'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend', 
      'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL, 
      'visible' => true, 
      'required' => false, 
      'user_defined' => true, 
      'default' => 0, 
      'searchable' => false, 
      'filterable' => true, 
      'comparable' => false, 
      'visible_on_front' => true, 
      'used_in_product_listing' => true, 
      'unique' => false, 
      'apply_to' => '' 
     ] 
    );