2017-10-14 14 views

答えて

0

は、次の手順を実行する必要があります。

1.Youは、カスタムモジュールを作成ANS setup/installData.phpファイルを作成し、この

<?php 

namespace Test\Customcategorymode\Setup; 

use Magento\Eav\Setup\EavSetupFactory; 
use Magento\Framework\Setup\ModuleContextInterface; 
use Magento\Framework\Setup\ModuleDataSetupInterface; 
use Magento\Framework\Setup\InstallDataInterface; 


class InstallData implements InstallDataInterface { 

    private $eavSetupFactory; 

    public function __construct(EavSetupFactory $eavSetupFactory) { 
     $this->eavSetupFactory = $eavSetupFactory; 
    } 

    public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { 
     $setup->startSetup(); 

     $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]); 
     $eavSetup->addAttribute(
       \Magento\Catalog\Model\Category::ENTITY, 'show_mode', [ 
      'type' => 'varchar', 
      'label' => 'Show Mode', 
      'input' => 'select', 
      'required' => false, 
      'source' => 'W3solver\Customcategorymode\Model\Category\Attribute\Source\Showmode', 
      'sort_order' => 102, 
      'visible' => true, 
      'user_defined' => true, 
      'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE, 
      'group' => 'Display Settings', 
       ] 
     ); 


     $setup->endSetup(); 
    } 

} 

2.Toはadminにショーモードフィールドを表示、追加する必要がありますパネルUIコンポーネントはにソースモデルを追加3.Also view/adminhtml/ui_component/category_form.xml

<?xml version="1.0" encoding="UTF-8"?> 
    <form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> 
     <fieldset name="display_settings"> 
      <field name="show_mode"> 
       <argument name="data" xsi:type="array"> 
       <item name="options" xsi:type="object">W3solver\Customcategorymode\Model\Category\Attribute\Source\Showmode</item> 
        <item name="config" xsi:type="array"> 
         <item name="sortOrder" xsi:type="number">102</item> 
         <item name="dataType" xsi:type="string">string</item> 
         <item name="formElement" xsi:type="string">select</item> 
         <item name="label" xsi:type="string" translate="true">Show Mode</item> 
        </item> 
       </argument> 
      </field> 
     </fieldset> 
</form> 

で作成する必要がありますおよび機能の下に書く: - :

あなたは、あなたが変更したいすべての製品ファイルに

5.Addこれらの条件を変更したいすべてのこれらのファイルを上書きする必要が

<?php 
/** 
* Copyright © 2013-2017 Magento, Inc. All rights reserved. 
* See COPYING.txt for license details. 
*/ 
namespace Test\Customcategorymode\Model\Category\Attribute\Source; 

/** 
* Catalog category landing page attribute source 
* 
* @author  Magento Core Team <[email protected]> 
*/ 
class ShowMode extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource 
{ 
    public function getAllOptions() 
    { 
     if (!$this->_options) { 
      $this->_options = [ 
       ['value' => 'type1', 'label' => __('type1')], 
       ['value' => 'type2', 'label' => __('type2')], 
      ]; 
     } 
     return $this->_options; 
    } 
} 

を4.Now

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
    $product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');//get current product 




     $cats = $product->getCategoryIds(); 
     if(count($cats)){ 
      $firstCategoryId = $cats[0]; 
      $category = $objectManager->create('Magento\Catalog\Model\Category')->load($firstCategoryId); 
     } 

    if ($category->getShowMode() == 'type1') { 
      // add your code 
    } else { 
     // add your code 
    } 
関連する問題