Example #1
0
 /**
  * Initialize all order totals relates with tax
  *
  * @return \Magento\Tax\Block\Sales\Order\Tax
  */
 public function initTotals()
 {
     $parent = $this->getParentBlock();
     $this->_order = $parent->getOrder();
     $this->_source = $parent->getSource();
     // $store = $this->getStore();
     /*
     Calculates the shoppree discount dynamically 
     by substracting grandtotal from the Total amount.
     Also adds a row in the order view page in my orders page.
     */
     $sdcnt = 0;
     $totalAmnt = $this->_source->getSubTotal() + $this->_source->getShippingAmount();
     $grandTotal = $this->_source->getGrandTotal();
     if ($totalAmnt >= $grandTotal) {
         $sdcnt = $totalAmnt - $grandTotal;
     }
     $fee = new \Magento\Framework\DataObject(['code' => 'fee', 'strong' => false, 'value' => $sdcnt, 'label' => __('Shoppree Discount [-]')]);
     $parent->addTotal($fee, 'fee');
     return $this;
 }
Example #2
0
 /**
  * @return $this
  */
 protected function _initGrandTotal()
 {
     $store = $this->getStore();
     $parent = $this->getParentBlock();
     $grandototal = $parent->getTotal('grand_total');
     if (!$grandototal || !(double) $this->_source->getGrandTotal()) {
         return $this;
     }
     if ($this->_config->displaySalesTaxWithGrandTotal($store)) {
         $grandtotal = $this->_source->getGrandTotal();
         $baseGrandtotal = $this->_source->getBaseGrandTotal();
         $grandtotalExcl = $grandtotal - $this->_source->getTaxAmount();
         $baseGrandtotalExcl = $baseGrandtotal - $this->_source->getBaseTaxAmount();
         $grandtotalExcl = max($grandtotalExcl, 0);
         $baseGrandtotalExcl = max($baseGrandtotalExcl, 0);
         $totalExcl = new \Magento\Framework\DataObject(['code' => 'grand_total', 'strong' => true, 'value' => $grandtotalExcl, 'base_value' => $baseGrandtotalExcl, 'label' => __('Grand Total (Excl.Tax)')]);
         $totalIncl = new \Magento\Framework\DataObject(['code' => 'grand_total_incl', 'strong' => true, 'value' => $grandtotal, 'base_value' => $baseGrandtotal, 'label' => __('Grand Total (Incl.Tax)')]);
         $parent->addTotal($totalExcl, 'grand_total');
         $this->_addTax('grand_total');
         $parent->addTotal($totalIncl, 'tax');
     }
     return $this;
 }