I want to override Magento\Sales\Block\Adminhtml\Totals this block I did but I don't know what I'm doing wrong.
app/code/[Vendor]/[Module]/etc/adminhtml/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Block\Adminhtml\Totals" type="EC\InStorePickupTax\Block\Adminhtml\Totals"/>
</config>
app/code/[Vendor]/[Vendor]/Block/Adminhtml/Totals.php
<?php
namespace [Vendor]\[Vendor]\Block\Adminhtml;
class Totals extends \Magento\Sales\Block\Adminhtml\Totals
{
/**
* Initialize order totals array
*
* @return $this
*/
protected function _initTotals()
{
$this->_totals = [];
$this->_totals['subtotal'] = new \Magento\Framework\DataObject(
[
'code' => 'subtotal',
'value' => $this->getSource()->getSubtotal(),
'base_value' => $this->getSource()->getBaseSubtotal(),
'label' => __('Subtotal'),
]
);
/**
* Add shipping
*/
if (!$this->getSource()->getIsVirtual() && ((double)$this->getSource()->getShippingAmount() ||
$this->getSource()->getShippingDescription())
) {
$shippingLabel = __('Shipping & Handling');
if ($this->isFreeShipping($this->getOrder()) && $this->getSource()->getDiscountDescription()) {
$shippingLabel .= sprintf(' (%s)', $this->getSource()->getDiscountDescription());
}
$this->_totals['shipping'] = new \Magento\Framework\DataObject(
[
'code' => 'shipping',
'value' => $this->getSource()->getShippingAmount(),
'base_value' => $this->getSource()->getBaseShippingAmount(),
'label' => $shippingLabel,
]
);
}
/**
* Add discount
*/
if ((double)$this->getSource()->getDiscountAmount() != 0) {
if ($this->getSource()->getDiscountDescription()) {
$discountLabel = __('Discount (%1)', $this->getSource()->getDiscountDescription());
} else {
$discountLabel = __('Discount');
}
$this->_totals['discount'] = new \Magento\Framework\DataObject(
[
'code' => 'discount',
'value' => $this->getSource()->getDiscountAmount(),
'base_value' => $this->getSource()->getBaseDiscountAmount(),
'label' => $discountLabel,
]
);
}
if($this->getOrder()->getShippingMethod() == 'flatrate_flatrate'){
$this->_totals['grand_total'] = new \Magento\Framework\DataObject(
[
'code' => 'grand_total',
'strong' => true,
'value' => $this->getOrder()->getGrandTotal(),
'base_value' => $this->getOrder()->getBaseGrandTotal(),
'label' => __('Grand Total'),
'area' => 'footer',
]
);
}else{
$this->_totals['grand_total'] = new \Magento\Framework\DataObject(
[
'code' => 'grand_total',
'strong' => true,
'value' => $this->getSource()->getGrandTotal(),
'base_value' => $this->getSource()->getBaseGrandTotal(),
'label' => __('Grand Total'),
'area' => 'footer',
]
);
}
return $this;
}
}
Also I also override Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer
block, it's working but I know why another block is not.