- addCustomerAddress: function (address) {
- var fields = [
- 'customer_id', 'country_id', 'street', 'company', 'telephone', 'fax', 'postcode', 'city',
- 'firstname', 'lastname', 'middlename', 'prefix', 'suffix', 'vat_id', 'default_billing',
- 'default_shipping'
- ],
- customerAddress = {},
- hasAddress = 0,
- existingAddress;
-
- if (!this.customerData.addresses) {
- this.customerData.addresses = [];
- }
-
- customerAddress = _.pick(address, fields);
- if (address.hasOwnProperty('region_id')) {
- customerAddress.region = {
- region_id: address.region_id,
- region: address.region
- };
- }
- for (existingAddress in this.customerData.addresses) {
- if (this.customerData.addresses.hasOwnProperty(existingAddress)) {
- if (_.isEqual(this.customerData.addresses[existingAddress], customerAddress)) {
- hasAddress = existingAddress;
- break;
- }
- }
- }
- if (hasAddress === 0) {
- return this.customerData.addresses.push(customerAddress) - 1;
- }
- return hasAddress;
- },