我尝试使用 magento 1.4.2 的现有代码创建magento onepage checkout功能。我在opcheckout.js中修改了一些东西。在那里我评论了一些功能,因为它返回一些错误。现在验证和流程一切都很好。即使我在下订单后遇到一些问题。这里只收取账单并运送现有账单地址的相同地址 即使我更改了地址未采取的新送货地址..还有一个问题是无法保存送货地址。关于这个我想做什么?
var Shipping = Class.create();
Shipping.prototype = {
initialize: function(form, addressUrl, saveUrl, methodsUrl) {
this.form = form;
if ($(this.form)) {
$(this.form).observe('submit', function(event)
{
this.save();
Event.stop(event);
} .bind(this));
}
this.addressUrl = addressUrl;
this.saveUrl = saveUrl;
this.methodsUrl = methodsUrl;
this.onAddressLoad = this.fillForm.bindAsEventListener(this);
this.onSave = this.nextStep.bindAsEventListener(this);
this.onComplete = this.resetLoadWaiting.bindAsEventListener(this);
},
fillForm: function(transport) {
var elementValues = {};
if (transport && transport.responseText) {
try {
elementValues = eval('(' + transport.responseText + ')');
}
catch (e) {
elementValues = {};
}
}
else {
this.resetSelectedAddress();
}
arrElements = Form.getElements(this.form);
for (var elemIndex in arrElements) {
if (arrElements[elemIndex].id) {
var fieldName = arrElements[elemIndex].id.replace( / ^ shipping: / , '');
arrElements[elemIndex].value = elementValues[fieldName] ? elementValues[fieldName] : '';
if (fieldName == 'country_id' && shippingForm) {
shippingForm.elementChildLoad(arrElements[elemIndex]);
}
}
}
},
setSameAsBilling: function(flag) {
$('shipping:same_as_billing').checked = flag;
// #5599. Also it hangs up, if the flag is not false
// $('billing:use_for_shipping_yes').checked = flag;
if (flag) {
this.syncWithBilling();
}
},
syncWithBilling: function () {
$('billing-address-select') && this.newAddress(!$('billing-address-select').value);
$('shipping:same_as_billing').checked = true;
if (!$('billing-address-select') || !$('billing-address-select').value) {
arrElements = Form.getElements(this.form);
for (var elemIndex in arrElements) {
if (arrElements[elemIndex].id) {
var sourceField = $(arrElements[elemIndex].id.replace( / ^ shipping: / , 'billing:'));
if (sourceField) {
arrElements[elemIndex].value = sourceField.value;
}
}
}
//$('shipping:country_id').value = $('billing:country_id').value;
shippingRegionUpdater.update();
$('shipping:region_id').value = $('billing:region_id').value;
$('shipping:region').value = $('billing:region').value;
//shippingForm.elementChildLoad($('shipping:country_id'), this.setRegionValue.bind(this));
} else {
$('shipping-address-select').value = $('billing-address-select').value;
}
},
setRegionValue: function() {
$('shipping:region').value = $('billing:region').value;
},
save: function() {
//if (checkout.loadWaiting!=false) return;
var Res = "";
var validator = new Validation(this.form);
if (validator.validate()) {
//checkout.setLoadWaiting('shipping');
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)
}
);
}
else
{
Res = "False";
}
return Res;
},
resetLoadWaiting: function(transport) {
checkout.setLoadWaiting(false);
},
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.shippingRegionUpdater) {
shippingRegionUpdater.update();
}
alert(response.message.join("\n"));
}
return false;
}
checkout.setStepResponse(response);
/*
var updater = new Ajax.Updater(
'checkout-shipping-method-load',
this.methodsUrl,
{method:'get', onSuccess: checkout.setShipping.bind(checkout)}
);
*/
//checkout.setShipping();
}
}