Files
stemcell/app/code/Stemcell/Sales/Block/Order/Totals.php
T
2026-09-15 10:26:34 +08:00

97 lines
3.2 KiB
PHP

<?php
namespace Stemcell\Sales\Block\Order;
use Magento\Framework\DataObject;
class Totals extends \Magento\Sales\Block\Order\Totals
{
protected function addShippingTotal($source)
{
if (!$source->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;
}
}