adjustment.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. 'mage/translate'
  8. ], function (Element, $t) {
  9. 'use strict';
  10. return Element.extend({
  11. defaults: {
  12. bodyTmpl: 'Magento_Tax/price/adjustment',
  13. taxPriceType: 'final_price',
  14. taxPriceCssClass: 'price-including-tax',
  15. bothPrices: 3,
  16. inclTax: 2,
  17. exclTax: 1,
  18. modules: {
  19. price: '${ $.parentName }'
  20. },
  21. listens: {
  22. price: 'initializePriceAttributes'
  23. }
  24. },
  25. /**
  26. * {@inheritdoc}
  27. */
  28. initialize: function () {
  29. this._super()
  30. .initializePriceAttributes();
  31. return this;
  32. },
  33. /**
  34. * Update parent price.
  35. *
  36. * @returns {Object} Chainable.
  37. */
  38. initializePriceAttributes: function () {
  39. if (this.displayBothPrices && this.price()) {
  40. this.price().priceWrapperCssClasses = this.taxPriceCssClass;
  41. this.price().priceWrapperAttr = {
  42. 'data-label': $t('Incl. Tax')
  43. };
  44. }
  45. return this;
  46. },
  47. /**
  48. * Get price tax adjustment.
  49. *
  50. * @param {Object} row
  51. * @return {HTMLElement} tax html
  52. */
  53. getTax: function (row) {
  54. return row['price_info']['extension_attributes']['tax_adjustments']['formatted_prices'][this.taxPriceType];
  55. },
  56. /**
  57. * Set price tax type.
  58. *
  59. * @param {String} priceType
  60. * @return {Object}
  61. */
  62. setPriceType: function (priceType) {
  63. this.taxPriceType = priceType;
  64. return this;
  65. },
  66. /**
  67. * Return whether display setting is to display
  68. * both price including tax and price excluding tax.
  69. *
  70. * @return {Boolean}
  71. */
  72. displayBothPrices: function () {
  73. return +this.source.data.displayTaxes === this.bothPrices;
  74. },
  75. /**
  76. * Return whether display setting is to display price including tax.
  77. *
  78. * @return {Boolean}
  79. */
  80. displayPriceIncludeTax: function () {
  81. return +this.source.data.displayTaxes === this.inclTax;
  82. },
  83. /**
  84. * Return whether display setting is to display price excluding tax.
  85. *
  86. * @return {Boolean}
  87. */
  88. displayPriceExclTax: function () {
  89. return +this.source.data.displayTaxes === this.exclTax;
  90. }
  91. });
  92. });