在magento 2中为产品创建日期和时间属性


11

我试图为产品创建一个属性,该属性必须显示日期和时间日历,并且应该仅作为日期和时间格式存储在数据库中。这是我的剧本

$ eavSetup- > addAttribute (
        \ Magento \ Catalog \ Model \ Product :: ENTITY ,'xyz_start_time' ,[ 'group' => 'xyz' ,'type' => 'datetime' ,'backend' => '' ,' frontend' => '' ,'label' => '开始时间' ,'input' => '日期' ,'class' => '' ,'source' =>'' ,'全局' =>
        
        
          
          
          
          
          
          
          
          
         \ Magento \ Catalog \ Model \ ResourceModel \ Eav \ Attribute :: SCOPE_GLOBAL ,'visible' => true ,'required' => false ,'user_defined' => true ,'default' => '' ,'searchable' => false ,'filterable' => false ,'comparable' => false ,'visible_on_front' => false ,'used_in_product_listing' => true ,'唯一=> 错误,
          
          
          
          
          
          
          
          
          
          
        'apply_to' => '简单,可配置,虚拟,捆绑,可下载' ] );  
        
        

$eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'xyz_end_time', [ 'group' => 'xyz', 'type' => 'datetime', 'backend' => '', 'frontend' => '', 'label' => 'End Time', 'input' => 'date', 'class' => '', 'source' => '', 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL, 'visible' => true, 'required' => false, 'user_defined' => true, 'default' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'used_in_product_listing' => true, 'unique' => false, 'apply_to' => 'simple,configurable,virtual,bundle,downloadable' ] );


它正在创建日期选择器,其中日期仅不显示时间。


您好Shankar,您是否创建了日期时间属性?
— Priya Ponnusamy

1
请在这里查看我对类似问题的回答:magento.stackexchange.com/questions/174840/…–
— Mageinn

Answers:


2

一种可能的解决方案是使用修饰符。您需要在Vendor \ Module \ etc \ adminhtml \ di.xml中定义一个修饰符,然后在Vendor \ Module \ Ui \ DataProvider \ Product \ Form \ Modifier \ Datetime.php中创建修饰符本身。修改器应为您的属性设置时间配置。

请参考此答案以获取更多信息:Magento 2为产品创建带有时间的日期属性


0

magento2是一个错误。该字段实际上是一个日期时间,但是日期选择器只是没有时间的日期。作为快速解决方法,您可以使用API​​设置日期时间。否则,您将需要覆盖Magento的datepicker或文件,以查找github中的错误。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.