Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Add discount
- */
- if ((double)$this->getSource()->getDiscountAmount()) {
- if ($this->getSource()->getDiscountDescription()) {
- $discountLabel = __('Discount (%1)', $source->getDiscountDescription());
- } else {
- $discountLabel = __('Discount');
- }
- $this->_totals['discount'] = new MagentoFrameworkDataObject(
- [
- 'code' => 'discount',
- 'field' => 'discount_amount',
- 'value' => $source->getDiscountAmount(),
- 'label' => $discountLabel,
- ]
- );
- }
- class Totals extends MagentoSalesBlockOrderTotals
- {
- public function _initTotals() {
- $source = $this->getSource();
- $this->_totals = [];
- $this->_totals['subtotal'] = new MagentoFrameworkDataObject(
- ['code' => 'subtotal', 'value' => $source->getSubtotal(), 'label' => __('Subtotal')]
- );
- /**
- * Add shipping
- */
- if (!$source->getIsVirtual() && ((double)$source->getShippingAmount() || $source->getShippingDescription())) {
- $this->_totals['shipping'] = new MagentoFrameworkDataObject(
- [
- 'code' => 'shipping',
- 'field' => 'shipping_amount',
- 'value' => $this->getSource()->getShippingAmount(),
- 'label' => __('Shipping & Handling'),
- ]
- );
- }
- /**
- * Add discount
- */
- if ((double)$this->getSource()->getDiscountAmount() != 0 OR $this->getSource()->getDiscountDescription() != null) {
- if ($this->getSource()->getDiscountDescription()) {
- $discountLabel = __('Discount (%1)', $source->getDiscountDescription());
- } else {
- $discountLabel = __('Discount');
- }
- $this->_totals['discount'] = new MagentoFrameworkDataObject(
- [
- 'code' => 'discount',
- 'field' => 'discount_amount',
- 'value' => $source->getDiscountAmount(),
- 'label' => $discountLabel,
- ]
- );
- }
- $this->_totals['grand_total'] = new MagentoFrameworkDataObject(
- [
- 'code' => 'grand_total',
- 'field' => 'grand_total',
- 'strong' => true,
- 'value' => $source->getGrandTotal(),
- 'label' => __('Grand Total'),
- ]
- );
- /**
- * Base grandtotal
- */
- if ($this->getOrder()->isCurrencyDifferent()) {
- $this->_totals['base_grandtotal'] = new MagentoFrameworkDataObject(
- [
- 'code' => 'base_grandtotal',
- 'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
- 'label' => __('Grand Total to be Charged'),
- 'is_formated' => true,
- ]
- );
- }
- return $this;
- }
- }
- class Totals
- {
- public function after_initTotals(
- MagentoSalesBlockOrderTotals $subject,
- $result
- ) {
- if ((double)$subject->getSource()->getDiscountAmount() != 0 OR $subject->getSource()->getDiscountDescription() != null) {
- if ($subject->getSource()->getDiscountDescription()) {
- $discountLabel = __('Offer (%1)', $source->getDiscountDescription());
- } else {
- $discountLabel = __('Offer');
- }
- $subject->_totals['discount'] = new MagentoFrameworkDataObject(
- [
- 'code' => 'discount',
- 'field' => 'discount_amount',
- 'value' => $source->getDiscountAmount(),
- 'label' => $discountLabel,
- ]
- );
- }
- return $subject;
- }
- }
Add Comment
Please, Sign In to add comment