getIsVirtual() && ($source->getShippingAmount() !== null || $source->getShippingDescription()) ) { $shippingLabel = __('Shipping & Handling'); if (!isset($this->_totals['discount'])) { if ($source->getCouponCode()) { $shippingLabel .= " ({$source->getCouponCode()})"; } elseif ($source->getDiscountDescription()) { $shippingLabel .= " ({$source->getDiscountDescription()})"; } } $this->_totals['shipping'] = new DataObject( [ 'code' => 'shipping', 'field' => 'shipping_amount', 'value' => $source->getShippingAmount(), 'label' => $shippingLabel, ] ); } } protected function _initTotals() { $source = $this->getSource(); $this->_totals = []; $this->_totals['subtotal'] = new \Magento\Framework\DataObject( ['code' => 'subtotal', 'value' => $source->getSubtotal(), 'label' => __('Subtotal')] ); /** * Add discount */ if ((double)$this->getSource()->getDiscountAmount() != 0) { if ($this->getSource()->getDiscountDescription()) { $discountLabel = __('Discount (%1)', $source->getDiscountDescription()); } else { $discountLabel = __('Discount'); } $this->_totals['discount'] = new \Magento\Framework\DataObject( [ 'code' => 'discount', 'field' => 'discount_amount', 'value' => $source->getDiscountAmount(), 'label' => $discountLabel, ] ); } $this->addShippingTotal($source); $this->_totals['customer_discount'] = new \Magento\Framework\DataObject( [ 'code' => 'customer_discount', 'field' => 'customer_discount', 'value' => $source->getData('customer_discount'), 'label' => '优惠金额', ] ); $this->_totals['grand_total'] = new \Magento\Framework\DataObject( [ '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 \Magento\Framework\DataObject( [ 'code' => 'base_grandtotal', 'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()), 'label' => __('Grand Total to be Charged'), 'is_formated' => true, ] ); } return $this; } }