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 _initShipping()
 {
     $store = $this->getStore();
     $parent = $this->getParentBlock();
     $shipping = $parent->getTotal('shipping');
     if (!$shipping) {
         return $this;
     }
     if ($this->_config->displaySalesShippingBoth($store)) {
         $shipping = (double) $this->_source->getShippingAmount();
         $baseShipping = (double) $this->_source->getBaseShippingAmount();
         $shippingIncl = (double) $this->_source->getShippingInclTax();
         if (!$shippingIncl) {
             $shippingIncl = $shipping + (double) $this->_source->getShippingTaxAmount();
         }
         $baseShippingIncl = (double) $this->_source->getBaseShippingInclTax();
         if (!$baseShippingIncl) {
             $baseShippingIncl = $baseShipping + (double) $this->_source->getBaseShippingTaxAmount();
         }
         $totalExcl = new \Magento\Framework\DataObject(['code' => 'shipping', 'value' => $shipping, 'base_value' => $baseShipping, 'label' => __('Shipping & Handling (Excl.Tax)')]);
         $totalIncl = new \Magento\Framework\DataObject(['code' => 'shipping_incl', 'value' => $shippingIncl, 'base_value' => $baseShippingIncl, 'label' => __('Shipping & Handling (Incl.Tax)')]);
         $parent->addTotal($totalExcl, 'shipping');
         $parent->addTotal($totalIncl, 'shipping');
     } elseif ($this->_config->displaySalesShippingInclTax($store)) {
         $shippingIncl = $this->_source->getShippingInclTax();
         if (!$shippingIncl) {
             $shippingIncl = $this->_source->getShippingAmount() + $this->_source->getShippingTaxAmount();
         }
         $baseShippingIncl = $this->_source->getBaseShippingInclTax();
         if (!$baseShippingIncl) {
             $baseShippingIncl = $this->_source->getBaseShippingAmount() + $this->_source->getBaseShippingTaxAmount();
         }
         $total = $parent->getTotal('shipping');
         if ($total) {
             $total->setValue($shippingIncl);
             $total->setBaseValue($baseShippingIncl);
         }
     }
     return $this;
 }
 /**
  * Retrieve subtotal price include tax html formated content
  *
  * @param \Magento\Framework\DataObject $order
  * @return string
  */
 public function displayShippingPriceInclTax($order)
 {
     $shipping = $order->getShippingInclTax();
     if ($shipping) {
         $baseShipping = $order->getBaseShippingInclTax();
     } else {
         $shipping = $order->getShippingAmount() + $order->getShippingTaxAmount();
         $baseShipping = $order->getBaseShippingAmount() + $order->getBaseShippingTaxAmount();
     }
     return $this->displayPrices($baseShipping, $shipping, false, ' ');
 }