multi-shipping.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'jquery/ui'
  8. ], function ($) {
  9. 'use strict';
  10. $.widget('mage.multiShipping', {
  11. options: {
  12. addNewAddressBtn: 'button[data-role="add-new-address"]', // Add a new multishipping address.
  13. addNewAddressFlag: '#add_new_address_flag', // Hidden input field with value 0 or 1.
  14. canContinueBtn: 'button[data-role="can-continue"]', // Continue (update quantity or go to shipping).
  15. canContinueFlag: '#can_continue_flag' // Hidden input field with value 0 or 1.
  16. },
  17. /**
  18. * Bind event handlers to click events for corresponding buttons.
  19. * @private
  20. */
  21. _create: function () {
  22. $(this.options.addNewAddressBtn).on('click', $.proxy(this._addNewAddress, this));
  23. $(this.options.canContinueBtn).on('click', $.proxy(this._canContinue, this));
  24. },
  25. /**
  26. * Add a new address. Set the hidden input field and submit the form. Then enter a new shipping address.
  27. * @private
  28. */
  29. _addNewAddress: function () {
  30. $(this.options.addNewAddressFlag).val(1);
  31. this.element.submit();
  32. },
  33. /**
  34. * Can the user continue to the next step? The data-flag attribute holds either 0 (no) or 1 (yes).
  35. * @private
  36. * @param {Event} event - Click event on the corresponding button.
  37. */
  38. _canContinue: function (event) {
  39. $(this.options.canContinueFlag).val(parseInt($(event.currentTarget).data('flag'), 10));
  40. }
  41. });
  42. return $.mage.multiShipping;
  43. });