Guest User

Untitled

a guest
Jul 23rd, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.85 KB | None | 0 0
  1. /**
  2. * Add discount
  3. */
  4. if ((double)$this->getSource()->getDiscountAmount()) {
  5. if ($this->getSource()->getDiscountDescription()) {
  6. $discountLabel = __('Discount (%1)', $source->getDiscountDescription());
  7. } else {
  8. $discountLabel = __('Discount');
  9. }
  10. $this->_totals['discount'] = new MagentoFrameworkDataObject(
  11. [
  12. 'code' => 'discount',
  13. 'field' => 'discount_amount',
  14. 'value' => $source->getDiscountAmount(),
  15. 'label' => $discountLabel,
  16. ]
  17. );
  18. }
  19.  
  20. class Totals extends MagentoSalesBlockOrderTotals
  21. {
  22.  
  23. public function _initTotals() {
  24. $source = $this->getSource();
  25.  
  26. $this->_totals = [];
  27. $this->_totals['subtotal'] = new MagentoFrameworkDataObject(
  28. ['code' => 'subtotal', 'value' => $source->getSubtotal(), 'label' => __('Subtotal')]
  29. );
  30.  
  31. /**
  32. * Add shipping
  33. */
  34. if (!$source->getIsVirtual() && ((double)$source->getShippingAmount() || $source->getShippingDescription())) {
  35. $this->_totals['shipping'] = new MagentoFrameworkDataObject(
  36. [
  37. 'code' => 'shipping',
  38. 'field' => 'shipping_amount',
  39. 'value' => $this->getSource()->getShippingAmount(),
  40. 'label' => __('Shipping & Handling'),
  41. ]
  42. );
  43. }
  44.  
  45. /**
  46. * Add discount
  47. */
  48. if ((double)$this->getSource()->getDiscountAmount() != 0 OR $this->getSource()->getDiscountDescription() != null) {
  49. if ($this->getSource()->getDiscountDescription()) {
  50. $discountLabel = __('Discount (%1)', $source->getDiscountDescription());
  51. } else {
  52. $discountLabel = __('Discount');
  53. }
  54. $this->_totals['discount'] = new MagentoFrameworkDataObject(
  55. [
  56. 'code' => 'discount',
  57. 'field' => 'discount_amount',
  58. 'value' => $source->getDiscountAmount(),
  59. 'label' => $discountLabel,
  60. ]
  61. );
  62. }
  63.  
  64. $this->_totals['grand_total'] = new MagentoFrameworkDataObject(
  65. [
  66. 'code' => 'grand_total',
  67. 'field' => 'grand_total',
  68. 'strong' => true,
  69. 'value' => $source->getGrandTotal(),
  70. 'label' => __('Grand Total'),
  71. ]
  72. );
  73.  
  74. /**
  75. * Base grandtotal
  76. */
  77. if ($this->getOrder()->isCurrencyDifferent()) {
  78. $this->_totals['base_grandtotal'] = new MagentoFrameworkDataObject(
  79. [
  80. 'code' => 'base_grandtotal',
  81. 'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
  82. 'label' => __('Grand Total to be Charged'),
  83. 'is_formated' => true,
  84. ]
  85. );
  86. }
  87. return $this;
  88.  
  89. }
  90. }
  91.  
  92. class Totals
  93. {
  94.  
  95. public function after_initTotals(
  96. MagentoSalesBlockOrderTotals $subject,
  97. $result
  98. ) {
  99. if ((double)$subject->getSource()->getDiscountAmount() != 0 OR $subject->getSource()->getDiscountDescription() != null) {
  100. if ($subject->getSource()->getDiscountDescription()) {
  101. $discountLabel = __('Offer (%1)', $source->getDiscountDescription());
  102. } else {
  103. $discountLabel = __('Offer');
  104. }
  105. $subject->_totals['discount'] = new MagentoFrameworkDataObject(
  106. [
  107. 'code' => 'discount',
  108. 'field' => 'discount_amount',
  109. 'value' => $source->getDiscountAmount(),
  110. 'label' => $discountLabel,
  111. ]
  112. );
  113. }
  114.  
  115. return $subject;
  116. }
  117. }
Add Comment
Please, Sign In to add comment