我添加了产品属性如下
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'product_activation',
[
'type' => 'datetime',
'backend' => '',
'frontend' => '',
'label' => 'Product Activation Timestamp',
'input' => 'date',
'class' => '',
'source' => '',
'time' => true,
'date_format' => 'yyyy-MM-dd',
'time_format' => 'hh:mm:ss',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'default' => '',
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => false,
'unique' => false,
'apply_to' => ''
]
);
仍然无法在我的管理产品表单中获取日期时间选择器。
请帮我解决这个问题
答案 0 :(得分:0)
请尝试以下代码:
<?php
namespace Vendor\Module\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
/**
* Install attributes
*/
class InstallData implements \Magento\Framework\Setup\InstallDataInterface
{
/**
* @var \Magento\Catalog\Setup\CategorySetupFactory
*/
protected $categorySetupFactory;
/**
* Init
*
* @param \Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory
*/
public function __construct(
\Magento\Catalog\Setup\CategorySetupFactory $categorySetupFactory
) {
$this->categorySetupFactory = $categorySetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$setup->startSetup();
$categorySetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'product_activation',
[
'type' => 'datetime',
'backend' => '',
'frontend' => 'Magento\Eav\Model\Entity\Attribute\Frontend\Datetime',
'label' => 'Product Activation Timestamp',
'input' => 'date',
'class' => '',
'source' => '',
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => true,
'user_defined' => false,
'default' => '',
'sort_order' => 9,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false,
'apply_to' => ''
]
);
$setup->endSetup();
}
}