JSMA address

Overview

The JSMA address allows access and manipulation of addresses used in carts and orders. This JSMA is critical to building a shopping workflow.

What can JSMA address do for me?

With the JSMA address you can edit addresses for carts and orders in your shopping website.

Index

Usage

writing data

Here is an example on how to write data to a JSMA address:

CartApi.prototype.doSetShipping = function ()
 {
   var countryCode = request.parameter("countryCode");
   [...]
    
   var cart = carts.current;
    
   if (cart.shippingAddress.countryCode === null) {
     cart.shippingAddress.update({country: countryCode}); // updating countryCode
   }
    
   [...]
    
   return this.doUpdate();
 }
 

Note: the fields are filled with hashes like {country: countryCode}

reading data

Here is an example on how to read data from a JSMA address:

function getCartInvoiceAddress(cart, parameters)
{ 
  var address = cart.invoiceAddress; 
   
  var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber, 
    zipCode : address.zipCode,  
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
  };   
   
  return result;
}

Methods

The JSMA address provides the following methods:

string address.city

Returns the city field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,

    city : address.city,  // => 'Stuttgart'

    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}

string address.company

Returns the company field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,

    company : address.company, // => 'A Company Name'

    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}

string address.country

Returns the country field of a JSMA address.

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,

    country : address.country, // => 'Deutschland'

    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}

string address.countryCode

Returns the country code field of a JSMA address. The result will be a two-letter, I18n-conform country code string.

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,

    countryCode: address.countryCode, // => 'DE'

    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}

string address.email

Returns the email field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,

    email : address.email // => 'mail@example.org'
 };    
  
  return result;
}

string address.extra

Returns the extra field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,

    extra : address.extra, // => '1st floor'

    phone : address.phone,
    email : address.email
 };    
  
  return result;
}



string address.firstName

Returns the firstName field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,

    firstName : address.firstName, // => 'Bob'

    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}



string address.lastName

Returns the lastName field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,

    lastName : address.lastName, // => 'Walker'

    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}



string address.gender

Returns the firstName field of a JSMA address

The default values should be either 'male', 'female', 'unspecified', 'diverse', 'company' or 'family'.

in script with JSMA you can sets any value but the masks in the management just allow for the 6 defaulted ones.


{
    'male' : 'Herr',
    'female' : 'Frau',
    'unspecified' : 'Unspezifiziert',
    'family' : 'Familie',
    'diverse' : 'Divers',
    'company' : 'Firma'
}


Mask in IFE management for orders

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {

    gender : (address.gender !== "undefined") ? address.gender : null , // => 'male'

    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}



string address.houseNumber

Returns the houseNumber field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,

    houseNumber : address.houseNumber, // => '1a'

    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}



string address.phone

Returns the phone field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,

    phone : address.phone, // => '555 378 520'

    email : address.email
 };    
  
  return result;
}



string address.street

Returns the street field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,

    street : address.street, // => 'Evergreen Terrace'

    houseNumber : address.houseNumber,
    zipCode : address.zipCode,
    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}



bool address.update(attributes)

Updates a JSMA address

Returns true when update succeeded, otherwise returns false.

Parameter attributes (required)

An object that may have all of the previous method names as keys to set the respective field (except for country, it is only used for reading and set by countryCode)

Example 1

...
address.update({ city: 'Berlin', street: 'Friedrichstr.', houseNumber: '5b', countryCode: 'DE' })
...

Example 2

 CartApi.prototype.doSetShipping = function ()
  {
    var countryCode = request.parameter("countryCode");
    [...]
    
    var cart = carts.current;
    
    if (cart.shippingAddress.countryCode === null) {
      cart.shippingAddress.update({country: countryCode}); // updating countryCode
    }
    
    [...]
    
    return this.doUpdate();
  }

string address.zipCode

Returns the zipCode field of a JSMA address

Example

function getCartInvoiceAddress(cart, parameters)
{  
  var address = cart.invoiceAddress;  
  
 var result = {
    gender : (address.gender !== "undefined") ? address.gender : null ,
    firstName : address.firstName,
    lastName : address.lastName,
    street : address.street,
    houseNumber : address.houseNumber,

    zipCode : address.zipCode, // => '80337'

    city : address.city,
    country : address.country,
    company : address.company,
    extra : address.extra,
    phone : address.phone,
    email : address.email
 };    
  
  return result;
}