在Magento 2.1中更改特定类别的产品视图
我需要为特定类别中的所有产品定制产品视图 我想删除右侧的产品图像和信息(红色)。在Magento 2.1中更改特定类别的产品视图,magento,Magento,我需要为特定类别中的所有产品定制产品视图 我想删除右侧的产品图像和信息(红色)。 然后我需要产品信息(黄色圆圈)来填充宽度(蓝色线)。您需要执行以下步骤: 1.您需要创建一个自定义模块ans createsetup/installData.php文件并添加此 <?php namespace Test\Customcategorymode\Setup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\M
然后我需要产品信息(黄色圆圈)来填充宽度(蓝色线)。您需要执行以下步骤: 1.您需要创建一个自定义模块ans create
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();
}
}
3.在model/Category/Attribute/source/Showmode.php
中添加一个源模型,并编写以下函数:-
<?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 <core@magentocommerce.com>
*/
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;
}
}
<?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 <core@magentocommerce.com>
*/
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;
}
}
$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
}