示例:
<?php
/**
* @Author 秋枫雁飞
* @Email aiweline@qq.com/1714255949@qq.com
* @Desc 文件由Aiweline(秋枫雁飞)编写,若有升级需要
* 建议不要随意修改文件源码。
**/
namespace Aiweline\Upsell\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Setup\EavSetupFactory;
class InstallData implements \Magento\Framework\Setup\InstallDataInterface
{
const attr_IS_ON_UPSELL = 'is_on_upsell';
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
/**
* @inheritDoc
*/
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
self::attr_IS_ON_UPSELL,
[
'type' => 'int',
'backend' => '',
'frontend' => '',
'label' => 'Is On Upsell ',
'input' => 'text',
'class' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => false,
'required' => false,
'user_defined' => true,
'default' => 0,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
}
}
上一篇:
Magento2 PHP7.4 "message": "Type Error occurred when creating object: %type"根本原因解析下一篇:
Php 解析Url函数,去除Url的host部分如何从php中的URL去除域名
这家伙太懒了,什么也没留下。