我是magento的新手.我想在一个类别中添加两个自定义图像字段.我已经为我的模块创建了一个带有安装程序文件的模块
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$entityTypeId = $setup->getEntityTypeId('catalog_category');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('catalog_category', 'image1', array(
'input' => 'image',
'type' => 'file',
'group' => 'General',
'label' => 'Additional image 1',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'frontend_input' =>'',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible_on_front' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'image1',
'999' //sort_order
);
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)
我可以在编辑或添加新类别时看到图像字段,但不保存到数据库.如何使它工作?谢谢
我想在Magento的一个页面结帐中添加一个新的自定义字段.我用安装程序创建了一个模块:
$installer = $this;
$installer->startSetup();
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('order', 'deliverydate', array(
'position' => 1,
'input' => 'text',
'type' => 'varchar',
'label' => 'Choose delivery date',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'global' => 1,
'visible_on_front' => 1,
));
$installer->endSetup();
Run Code Online (Sandbox Code Playgroud)
我可以通过phpmyadmin看到该字段已添加到mage_eav_attribute表中.我还将此添加到shipping-method.phtml:
<div class="form-list field">
<label for="deliverydate"><?php echo $this->__('Choose delivery date') ?></label>
<div class="input-box">
<input type="text" name="deliverydate" id="deliverydate" title="<?php echo $this->__('deliverydate') ?>" class="input-text" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
当我下订单时,自定义字段将不会保存.如何使它工作?我已经用这种方式向客户添加了一些自定义字段,它们工作正常.我还可以在admin/customer上自动查看我的自定义客户字段,但无法在admin/sales_order中看到我的自定义订单字段.谢谢
*编辑:
这就是我所做的:
我将observer.php添加到companyname/module/model/observer.php
class Company_Module_Model_Observer
{
public function Deliverydate($observer){
//get …Run Code Online (Sandbox Code Playgroud) 在mysql4-install-0.1.0.php中,我可以在我的magento模块中添加自定义文本字段,如下所示:
$entityTypeId = $setup->getEntityTypeId('customer');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);
$setup->addAttribute('customer', 'resale', array(
'input' => 'text',
'type' => 'varchar',
'label' => 'Resale number',
'visible' => 1,
'required' => 1,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId,
'resale',
'999' //sort_order
);
$oAttribute = Mage::getSingleton('eav/config')->getAttribute('customer', 'resale');
$oAttribute->setData('used_in_forms', array('adminhtml_customer','customer_account_create'));
$oAttribute->save();
Run Code Online (Sandbox Code Playgroud)
我还想添加一个复选框字段.我这样添加:
$setup->addAttribute('customer', 'marketattended1', array(
'input' => 'checkbox',
'type' => 'int',
'label' => 'San Francisco International Gift Fair',
'visible' => 1,
'required' => 0,
'user_defined' => 1,
));
$setup->addAttributeToGroup(
$entityTypeId,
$attributeSetId,
$attributeGroupId, …Run Code Online (Sandbox Code Playgroud)