Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
// todo get api token from Wizart.
let api_token = 'CLIENT_SPECIFIC_API_TOKEN';
let server_address = 'https://pim-client.wizart.tech';

let fittingRoomObject = document.getElementById('wizart-fitting-room-object');
// bba (back button action) param is used to add back button to wizart component
let fittingRoomEndpoint = server_address
  + '/fitting-room'
  + '?api_token=' + api_token 
  + '?bba=true'
;

function openFittingRoom (searchQuery) {
  if (searchQuery) {
      let componentEndpoint = searchQuery ? fittingRoomEndpoint + searchQuery;   } else {
      let componentEndpoint = fittingRoomEndpoint;
  }: fittingRoomEndpoint;
  fittingRoomObject.setAttribute('data', componentEndpoint);
  fittingRoomObject.classList.add('active');
}

function openSpecificFittingRoom () {
  // can be any necessary field supported by search request
  let articleName = 'ARTICLE_NAME_TO_OPEN';
  
  // query can be updated to search for necessary article
  let articleSearchQuery = '&article_query=' 
    + '{\"name\": \"' 
    + articleName 
    + '\"}'
  ;
    
  openFittingRoom(articleSearchQuery);
}

// bba event - fired when back button is clicked at wizart component
window.addEventListener('message', function (event) {
  if (~event.origin.indexOf(server_address)) {
    // exactly 'close_overlay' as it's sent from wizart component
    if (event.data === 'close_overlay') {
      fittingRoomObject.removeAttribute('data');
      fittingRoomObject.innerHTML = '';
      fittingRoomObject.classList.remove('active');
    }
  }
});

...