Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

66 lignes
2.2 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'jquery',
  7. 'Magento_Customer/js/customer-data',
  8. 'jquery-ui-modules/widget'
  9. ], function ($, customerData) {
  10. 'use strict';
  11. $.widget('mage.multiShipping', {
  12. options: {
  13. itemsQty: 0,
  14. addNewAddressBtn: 'button[data-role="add-new-address"]', // Add a new multishipping address.
  15. addNewAddressFlag: '#add_new_address_flag', // Hidden input field with value 0 or 1.
  16. canContinueBtn: 'button[data-role="can-continue"]', // Continue (update quantity or go to shipping).
  17. canContinueFlag: '#can_continue_flag' // Hidden input field with value 0 or 1.
  18. },
  19. /**
  20. * Bind event handlers to click events for corresponding buttons.
  21. * @private
  22. */
  23. _create: function () {
  24. this._prepareCartData();
  25. $(this.options.addNewAddressBtn).on('click', $.proxy(this._addNewAddress, this));
  26. $(this.options.canContinueBtn).on('click', $.proxy(this._canContinue, this));
  27. },
  28. /**
  29. * Takes cart items qty from current cart data and compare it with current items qty
  30. * Reloads cart data if cart items qty is wrong
  31. * @private
  32. */
  33. _prepareCartData: function () {
  34. var cartData = customerData.get('cart');
  35. if (cartData()['summary_count'] !== this.options.itemsQty) {
  36. customerData.reload(['cart'], false);
  37. }
  38. },
  39. /**
  40. * Add a new address. Set the hidden input field and submit the form. Then enter a new shipping address.
  41. * @private
  42. */
  43. _addNewAddress: function () {
  44. $(this.options.addNewAddressFlag).val(1);
  45. this.element.submit();
  46. },
  47. /**
  48. * Can the user continue to the next step? The data-flag attribute holds either 0 (no) or 1 (yes).
  49. * @private
  50. * @param {Event} event - Click event on the corresponding button.
  51. */
  52. _canContinue: function (event) {
  53. $(this.options.canContinueFlag).val(parseInt($(event.currentTarget).data('flag'), 10));
  54. }
  55. });
  56. return $.mage.multiShipping;
  57. });