adjustment.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * Copyright © Magento, Inc. All rights reserved.
  3. * See COPYING.txt for license details.
  4. */
  5. define([
  6. 'Magento_Ui/js/grid/columns/column'
  7. ], function (Element) {
  8. 'use strict';
  9. return Element.extend({
  10. defaults: {
  11. bodyTmpl: 'Magento_Weee/price/adjustment',
  12. dataSource: '${ $.parentName }.provider',
  13. //Weee configuration constants can be configured from backend
  14. inclFptWithDesc: 1,//show FPT and description
  15. inclFpt: 0, //show FPT attribute
  16. exclFpt: 2, //do not show FPT
  17. bothFptPrices: 3 //show price without FPT and with FPT and with description
  18. },
  19. /**
  20. * Get Weee attributes.
  21. *
  22. * @param {Object} row
  23. * @return {HTMLElement} Weee html
  24. */
  25. getWeeeAttributes: function (row) {
  26. return row['price_info']['extension_attributes']['weee_attributes'];
  27. },
  28. /**
  29. * Get Weee without Tax attributes.
  30. *
  31. * @param {Object} taxAmount
  32. * @return {HTMLElement} Weee html
  33. */
  34. getWeeeTaxWithoutTax: function (taxAmount) {
  35. return taxAmount['amount_excl_tax'];
  36. },
  37. /**
  38. * Get Weee with Tax attributes.
  39. *
  40. * @param {Object} taxAmount
  41. * @return {HTMLElement} Weee html
  42. */
  43. getWeeeTaxWithTax: function (taxAmount) {
  44. return taxAmount['tax_amount_incl_tax'];
  45. },
  46. /**
  47. * Get Weee Tax name.
  48. *
  49. * @param {String} taxAmount
  50. * @return {String} Weee name
  51. */
  52. getWeeTaxAttributeName: function (taxAmount) {
  53. return taxAmount['attribute_code'];
  54. },
  55. /**
  56. * Set price type.
  57. *
  58. * @param {String} priceType
  59. * @return {Object}
  60. */
  61. setPriceType: function (priceType) {
  62. this.taxPriceType = priceType;
  63. return this;
  64. },
  65. /**
  66. * Check if Weee Tax must be shown.
  67. *
  68. * @param {Object} row
  69. * @return {Boolean}
  70. */
  71. isShown: function (row) {
  72. return row['price_info']['extension_attributes']['weee_attributes'].length;
  73. },
  74. /**
  75. * Get Weee final price.
  76. *
  77. * @param {Object} row
  78. * @return {HTMLElement} Weee final price html
  79. */
  80. getWeeeAdjustment: function (row) {
  81. return row['price_info']['extension_attributes']['weee_adjustment'];
  82. },
  83. /**
  84. * Return whether display setting is to display price including FPT only.
  85. *
  86. * @return {Boolean}
  87. */
  88. displayPriceInclFpt: function () {
  89. return +this.source.data.displayWeee === this.inclFpt;
  90. },
  91. /**
  92. * Return whether display setting is to display
  93. * price including FPT and FPT description.
  94. *
  95. * @return {Boolean}
  96. */
  97. displayPriceInclFptDescr: function () {
  98. return +this.source.data.displayWeee === this.inclFptWithDesc;
  99. },
  100. /**
  101. * Return whether display setting is to display price
  102. * excluding FPT but including FPT description and final price.
  103. *
  104. * @return {Boolean}
  105. */
  106. displayPriceExclFptDescr: function () {
  107. return +this.source.data.displayWeee === this.exclFpt;
  108. },
  109. /**
  110. * Return whether display setting is to display price excluding FPT.
  111. *
  112. * @return {Boolean}
  113. */
  114. displayPriceExclFpt: function () {
  115. return +this.source.data.displayWeee === this.bothFptPrices;
  116. },
  117. /**
  118. * Return whether display setting is to display price excluding tax.
  119. *
  120. * @return {Boolean}
  121. */
  122. displayPriceExclTax: function () {
  123. return +this.source.data.displayTaxes === this.inclFptWithDesc;
  124. },
  125. /**
  126. * Return whether display setting is to display price including tax.
  127. *
  128. * @return {Boolean}
  129. */
  130. displayPriceInclTax: function () {
  131. return +this.source.data.displayTaxes === this.exclFpt;
  132. },
  133. /**
  134. * Return whether display setting is to display
  135. * both price including tax and price excluding tax.
  136. *
  137. * @return {Boolean}
  138. */
  139. displayBothPricesTax: function () {
  140. return +this.source.data.displayTaxes === this.bothFptPrices;
  141. }
  142. });
  143. });