Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

116 wiersze
3.4 KiB

  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. /**
  6. * @api
  7. */
  8. define([
  9. 'jquery',
  10. 'jquery-ui-modules/widget',
  11. 'Magento_Catalog/js/price-box'
  12. ], function ($) {
  13. 'use strict';
  14. /**
  15. * Downloadable widget
  16. */
  17. $.widget('mage.downloadable', {
  18. options: {
  19. priceHolderSelector: '.price-box',
  20. linkElement: '',
  21. allElements: ''
  22. },
  23. /**
  24. * @inheritdoc
  25. */
  26. _init: function initLinks() {
  27. var element = this.element,
  28. options = $(this.options.linkElement, element);
  29. options.trigger('change');
  30. },
  31. /**
  32. * @inheritdoc
  33. */
  34. _create: function () {
  35. var self = this;
  36. this.element.find(this.options.linkElement).on('change', $.proxy(function () {
  37. this._reloadPrice();
  38. }, this));
  39. this.element.find(this.options.allElements).on('change', function () {
  40. if (this.checked) {
  41. $('label[for="' + this.id + '"] > span').text($(this).attr('data-checked'));
  42. self.element.find(self.options.linkElement + ':not(:checked)').each(function () {
  43. $(this).trigger('click');
  44. });
  45. } else {
  46. $('[for="' + this.id + '"] > span').text($(this).attr('data-notchecked'));
  47. self.element.find(self.options.linkElement + ':checked').each(function () {
  48. $(this).trigger('click');
  49. });
  50. }
  51. });
  52. this._reloadPrice();
  53. },
  54. /**
  55. * Reload product price with selected link price included
  56. * @private
  57. */
  58. _reloadPrice: function () {
  59. var finalPrice = 0,
  60. basePrice = 0;
  61. this.element.find(this.options.linkElement + ':checked').each($.proxy(function (index, element) {
  62. finalPrice += this.options.config.links[$(element).val()].finalPrice;
  63. basePrice += this.options.config.links[$(element).val()].basePrice;
  64. }, this));
  65. $(this.options.priceHolderSelector).trigger('updatePrice', {
  66. 'prices': {
  67. 'finalPrice': {
  68. 'amount': finalPrice
  69. },
  70. 'basePrice': {
  71. 'amount': basePrice
  72. }
  73. }
  74. });
  75. this.reloadAllCheckText();
  76. },
  77. /**
  78. * Reload all-elements-checkbox's label
  79. * @private
  80. */
  81. reloadAllCheckText: function () {
  82. var allChecked = true,
  83. allElementsCheck = $(this.options.allElements),
  84. allElementsLabel = $('label[for="' + allElementsCheck.attr('id') + '"] > span');
  85. $(this.options.linkElement).each(function () {
  86. if (!this.checked) {
  87. allChecked = false;
  88. }
  89. });
  90. if (allChecked) {
  91. allElementsLabel.text(allElementsCheck.attr('data-checked'));
  92. allElementsCheck.prop('checked', true);
  93. } else {
  94. allElementsLabel.text(allElementsCheck.attr('data-notchecked'));
  95. allElementsCheck.prop('checked', false);
  96. }
  97. }
  98. });
  99. return $.mage.downloadable;
  100. });