1

我正在使用 magento 1.7.2,我想添加带有时间的日期属性,以保存该产品的数据库中的日期和时间。

我曾尝试使用此代码在我的模块中使用 mysql-setup 文件添加新属性。

$setup->addAttribute('catalog_product', 'new_date', array(
    'group' => 'General',
    'input' => 'date',
    'type' => 'datetime',
    'label' => 'New Date',
    'backend' => 'eav/entity_attribute_backend_datetime',
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'searchable' => 1,
    'filterable' => 1,
    'comparable' => 1,
    'visible_on_front' => 1,
    'visible_in_advanced_search' => 0,
    'is_html_allowed_on_front' => 1,
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
)); 

但这给了我只选择日期而不是时间。

请帮我。

谢谢。

4

4 回答 4

8

试试这个后端(任何管理面板形式):

$fieldset->addField('your_column_name', 'date',array(
          'name'      =>    'image_link', /* should match with your table column name where the data should be inserted */
          'time'      =>    true,
          'class'     => 'required-entry',
          'required'  => true,        
          'format'    =>    $this->escDates(),
          'label'     =>    Mage::helper('featuredpopup')->__('From:'),
          'image'     =>    $this->getSkinUrl('images/grid-cal.gif')
      ));

在格式中,您可以直接编写'yyyy-MM-dd HH:mm:ss'或另一种方法,例如

private function escDates() {
        return 'yyyy-MM-dd HH:mm:ss';   
    }

希望这能给你一个想法。

于 2012-11-21T10:46:29.000 回答
4

试试这些(适用于 Magento 1.8):

   $this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'test_date_time', array(
     'input'         => 'datetime',
     'type'          => 'datetime',
     'time'          => true,
     'label'         => 'Date&Time',
     'visible'       => true,
     'required'      => false,
     'user_defined'  => true,
     'visible_on_front' => true,
     'backend'       => 'eav/entity_attribute_backend_time_created',
     'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
 ));
于 2014-07-04T09:43:21.593 回答
0

你好检查app/code/local/Magik/Popup/Block/Adminhtml/Popup/Edit/Tab/Form.php

添加以下代码

$dateFormatIso=Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);  
    $fieldset->addField("text_name", "date", array(
    "name"   => "text_name",
    "label"  => Mage::helper("modelname")->__("Start Date"),
    "title"  => Mage::helper("modelname")->__("Start Date"),
    "image"  => $this->getSkinUrl('images/grid-cal.gif'),
    "input_format" => Varien_Date::DATE_INTERNAL_FORMAT,
    "format"       => $dateFormatIso,
     "time" => false,
    "value" => "textstart", 
    ));
于 2012-11-22T05:41:10.257 回答
0

创建自定义属性时,您只需要添加

'input'=> 'datetime'代替 'input'=> 'date'

于 2016-11-18T05:59:06.163 回答