我在这里遵循演练:http ://www.excellencemagentoblog.com/magento-add-custom-fields-checkout-page 。
我最初要求打开一个关于自定义字段未保存到表中的问题,当该字段被移动到审查订单步骤而不是文章引用的计费步骤时。所以我重新表述我的问题,因为我尽可能地缩小了这个范围。这是我的观察者课
class Excellence_Custom_Model_Observer{
public function saveQuoteBefore($evt){
$quote = $evt->getQuote();
$post = Mage::app()->getFrontController()->getRequest()->getPost();
if(isset($post['custom']['sales_person'])){
$var = $post['custom']['sales_person'];
$quote->setSalesPerson($var);
}
}
public function saveQuoteAfter($evt){
$quote = $evt->getQuote();
if($quote->getSalesPerson()){
$var = $quote->getSalesPerson();
if(!empty($var)){
$model = Mage::getModel('custom/custom_quote');
$model->deteleByQuote($quote->getId(),'sales_person');
$model->setQuoteId($quote->getId());
$model->setKey('sales_person');
$model->setValue($var);
$model->save();
}
}
}
public function loadQuoteAfter($evt){
$quote = $evt->getQuote();
$model = Mage::getModel('custom/custom_quote');
$data = $model->getByQuote($quote->getId());
foreach($data as $key => $value){
$quote->setData($key,$value);
}
}
public function saveOrderAfter($evt){
$order = $evt->getOrder();
$quote = $evt->getQuote();
if($quote->getSalesPerson()){
$var = $quote->getSalesPerson();
if(!empty($var)){
$model = Mage::getModel('custom/custom_order');
$model->deleteByOrder($order->getId(),'sales_person');
$model->setOrderId($order->getId());
$model->setKey('sales_person');
$model->setValue($var);
$order->setSalesPerson($var);
$model->save();
}
}
}
public function loadOrderAfter($evt){
$order = $evt->getOrder();
$model = Mage::getModel('custom/custom_order');
$data = $model->getByOrder($order->getId());
foreach($data as $key => $value){
$order->setData($key,$value);
}
}
}
通过 Mage::log() 我能够看到 saveQuoteBefore() 仅在计费步骤中被调用。这就是为什么当我移动场地时,它从未记录过。
是否有另一个钩子需要我保存在审查订单步骤中?