在Magento Checkout Onepage 中SaveBilling处理大致可分以下几步 var billing = new Billing('co-billing-form', '<?php echo $this->getUrl('checkout/onepage/getAddress') ?>address/', '<?php echo $this->getUrl('checkout/onepage/saveBilling') ?>'); //javascript'save方法 save: function(){ if (checkout.loadWaiting!=false) return; var validator = new Validation(this.form); if (validator.validate()) { if (checkout.method=='register' && $('billing:customer_password').value != $('billing:confirm_password').value) { alert(Translator.translate('Error: Passwords do not match')); return; } checkout.setLoadWaiting('billing'); // if ($('billing:use_for_shipping') && $('billing:use_for_shipping').checked) { // $('billing:use_for_shipping').value=1; // } var request = new Ajax.Request( this.saveUrl, { method: 'post', onComplete: this.onComplete, onSuccess: this.onSave, onFailure: checkout.ajaxFailure.bind(checkout), parameters: Form.serialize(this.form) } ); } }
$address = $this->getQuote()->getBillingAddress();
if (!empty($customerAddressId)) {
$customerAddress = Mage::getModel('customer/address')->load($customerAddressId);
if ($customerAddress->getId()) {
if ($customerAddress->getCustomerId() != $this->getQuote()->getCustomerId()) {
return array('error' => 1,
'message' => Mage::helper('checkout')->__('Customer Address is not valid.')
);
}
$address->importCustomerAddress($customerAddress);
}
} else {
unset($data['address_id']);
$address->addData($data);
//$address->setId(null);
}
$this->getQuote()->collectTotals();进行金额计算
public function collectTotals()
{
foreach ($this->getTotalModels() as $model) {
if (is_callable(array($model, 'collect'))) {
$model->collect($this);
}
}
return $this;
}
protected function _getShippingMethodsHtml()
{
$layout = $this->getLayout();
$update = $layout->getUpdate();
$update->load('checkout_onepage_shippingmethod');
$layout->generateXml();
$layout->generateBlocks();
$output = $layout->getOutput();
return $output;
}
$result['update_section'] = array(
'name' => 'shipping-method',
'html' => $this->_getShippingMethodsHtml()
);
$this->getResponse()->setBody(Zend_Json::encode($result));
nextStep: function(transport){ if (transport && transport.responseText){ try{ response = eval('(' + transport.responseText + ')'); } catch (e) { response = {}; } } if (response.error){ if ((typeof response.message) == 'string') { alert(response.message); } else { if (window.billingRegionUpdater) { billingRegionUpdater.update(); } alert(response.message.join("/n")); } return false; } checkout.setStepResponse(response); } //而checkout.setStepResponse(response)为基类checkout的方法 setStepResponse: function(response){ if (response.update_section) { //response.update_section.html $('checkout-'+response.update_section.name+'-load').update(response.update_section.html); } //这里的response.update_section.html就是返回在服务器端返回的json,其格式如下{"update_section":{"html":"<div>...</div>"}}
|