我是Magento的新手,我需要的是在后端添加一个自定义字段,然后在PDF上打印该值。
我希望在从后端添加订单时保存带有订单的销售人员姓名,并在PDF上打印销售人员姓名。
任何想法?任何更好的模块或任何东西?
答案 0 :(得分:1)
假设您要将mageigniter_sales_person
添加到订单数据库并将输入字段添加到管理创建订单并在订单详细信息视图中显示
在/app/code/local/MageIgniter/CustomOrderSalesPerson/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MageIgniter_CustomOrderSalesPerson>
<version>1.1</version>
</MageIgniter_CustomOrderSalesPerson>
</modules>
<global>
<fieldsets>
<sales_convert_quote>
<mageigniter_sales_person><to_order>*</to_order></mageigniter_sales_person>
</sales_convert_quote>
<sales_convert_order>
<mageigniter_sales_person><to_quote>*</to_quote></mageigniter_sales_person>
</sales_convert_order>
</fieldsets>
<helpers>
<customordersalesperson>
<class>MageIgniter_CustomOrderSalesPerson_Helper</class>
</customordersalesperson>
</helpers>
<models>
<customordersalesperson>
<class>MageIgniter_CustomOrderSalesPerson_Model</class>
<resourceModel>customordersalesperson_mysql4</resourceModel>
</customordersalesperson>
</models>
<resources>
<customordersalesperson_setup>
<setup>
<module>MageIgniter_CustomOrderSalesPerson</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</customordersalesperson_setup>
<customordersalesperson_write>
<connection>
<use>core_write</use>
</connection>
</customordersalesperson_write>
<customordersalesperson_read>
<connection>
<use>core_read</use>
</connection>
</customordersalesperson_read>
</resources>
<events>
<adminhtml_sales_order_create_process_data_before>
<observers>
<customordersalesperson>
<type>singleton</type>
<class>customordersalesperson/observer</class>
<method>saveCustomData</method>
</customordersalesperson>
</observers>
</adminhtml_sales_order_create_process_data_before>
</events>
<blocks>
<customordersalesperson>
<class>MageIgniter_CustomOrderSalesPerson_Block</class>
</customordersalesperson>
</blocks>
</global>
</config>
在/app/code/local/MageIgniter/CustomOrderSalesPerson/sql/customordersalesperson_setup/mysql4-install-1.1.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("order", "mageigniter_sales_person", array("type"=>"varchar"));
$installer->addAttribute("quote", "mageigniter_sales_person", array("type"=>"varchar"));
$installer->endSetup();
在/app/code/local/MageIgniter/CustomOrderSalesPerson/Model/Observer.php
class MageIgniter_CustomOrderSalesPerson_Model_Observer
{
public function saveCustomData($event)
{
$quote = $event->getSession()->getQuote();
$quote->setData('mageigniter_sales_person', $event->getRequestModel()->getPost('mageigniter_sales_person'));
return $this;
}
}
(你应该避免对核心默认值进行更改 - 你应该对此进行一些研究)
在/app/design/adminhtml/default/default/template/sales/order/create/form/account.phtml
<input id="mageigniter_sales_person" name="mageigniter_sales_person" value="<?php echo Mage::getSingleton('adminhtml/session_quote')->getQuote()->getMageigniterSalesPerson() ?>" class="input-text" type="text">
在/app/design/adminhtml/default/default/template/sales/order/view/info.phtml
<?php if($_order->getMageigniterSalesPerson()): ?>
<tr>
<td class="label"><label><?php echo Mage::helper('sales')->__('Sales Person') ?></label></td>
<td class="value"><strong><?php echo $_order->getMageigniterSalesPerson() ?></strong></td>
</tr>
<?php endif; ?>
您可以使用获取当前的管理员名称 $ _user = Mage :: getSingleton('admin / session'); $ user ['email'] = $ _user-&gt; getUser() - &gt; getEmail(); $ user ['firstname'] = $ _user-&gt; getUser() - &gt; getFirstname(); $ user ['lastname'] = $ _user-&gt; getUser() - &gt; getLastname();
在您的pdf中,您应该可以访问$ _order-&gt; getMageigniterSalesPerson(),看看@ Add custom attribute to Magento’s PDF invoice
答案 1 :(得分:1)
首先,您需要在billing.phtml
文件中添加html文本字段。在此文件中找到以下代码。
<?php if ($this->canShip()): ?>
在
行上方添加以下代码<li class="fields">
<div class="field">
<label for="billing:ssn" class="required"><em>*</em><?php echo $this->__('SSN') ?></label>
<div class="input-box">
<input type="text" name="custom[ssn]" value="<?php echo $this->htmlEscape($this->getQuote()->getSsn()) ?>" title="<?php echo $this->__('SSN') ?>" class="input-text required-entry" id="billing:ssn" />
</div>
</div>
</li>
现在您必须在报价单和订单表中保存该字段
创建两个表。销售的'sales_quote_custom'和订单的'sales_order_custom'。检查phpmyadmin以确认是否已创建两个表。接下来在config.xml
文件中编写一些事件观察器。在<global>
标记内添加以下代码。
<events>
<sales_quote_save_before> <!-- Event Called Before Quote Object is saved -->
<observers>
<save_before>
<type>singleton</type>
<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
<method>saveQuoteBefore</method> <!-- name of function -->
</save_before>
</observers>
</sales_quote_save_before>
<sales_quote_save_after> <!-- Event called After Quote Object is saved -->
<observers>
<save_after>
<type>singleton</type>
<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
<method>saveQuoteAfter</method> <!-- name of function -->
</save_after>
</observers>
</sales_quote_save_after>
<sales_quote_load_after> <!-- Event called when Quote Object is loaded -->
<observers>
<load_after>
<type>singleton</type>
<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
<method>loadQuoteAfter</method> <!-- name of function -->
</load_after>
</observers>
</sales_quote_load_after>
<sales_model_service_quote_submit_after> <!-- Event called after order placed -->
<observers>
<sales_model_service_quote_submit_after>
<type>singleton</type>
<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
<method>saveOrderAfter</method> <!-- name of function -->
</sales_model_service_quote_submit_after>
</observers>
</sales_model_service_quote_submit_after>
<sales_order_load_after> <!-- Event called after Order Object is loaded -->
<observers>
<sales_order_load_after>
<type>singleton</type>
<class>Excellence_Custom_Model_Observer</class> <!-- Over Model Class -->
<method>loadOrderAfter</method> <!-- name of function -->
</sales_order_load_after>
</observers>
</sales_order_load_after>
</events>
有关完整的分步教程,请访问: Add custom field to Order page