You have to load the quote first:
<?php
$quote = Mage::getModel('checkout/session')->getQuote();
$quoteData = $quote->getData();
$grandTotal = $quoteData['grand_total'];
?>
Then simply replace $this->getSubtotal()
with $grandTotal
.
To get the actual discount amount, you can use this:
$discountTotal = 0;
foreach ($quote->getAllItems() as $item){
$discountTotal += $item->getDiscountAmount();
}
you don't have to override the preference and you should not.
You can easily use a Plugin to set the allow_products data before the method is called. You find a nice tutorial about plugins here:
http://alanstorm.com/magento_2_object_manager_plugin_system
To create your Plugin, you first need to add a type to your etc/frontend/di.xml
<type name="Magento\ConfigurableProduct\Block\Product\View\Type\Configurable">
<plugin name="changeAllowProductsBehaviour" type="Vendor\Module\Model\ConfigurableProduct\Block\Product\View\Type\Configurable\Plugin" sortOrder="10" />
</type>
Then Your Plugin Class should look like this:
<?php
namespace Vendor\Module\Model\ConfigurableProduct\Block\Product\View\Type\Configurable;
class Plugin
{
/**
* getAllowProducts
*
* @param \Magento\ConfigurableProduct\Block\Product\View\Type\Configurable $subject
*
* @return array
*/
public function beforeGetAllowProducts($subject)
{
if (!$subject->hasData('allow_products')) {
$products = [];
$allProducts = $subject->getProduct()->getTypeInstance()->getUsedProducts($subject->getProduct(), null);
foreach ($allProducts as $product) {
$products[] = $product;
}
$subject->setData('allow_products', $products);
}
return [];
}
}
Be sure to clear cache and also your var/generation dir to have this changes applied
Best Answer
registration.php file,
filepath
app/code/Package/Modulename/registration.php
composer.json file,
app/code/Package/Modulename/composer.json
module.xml file,
filepath
app/code/Package/Modulename/etc/module.xml
di.xml file
, filepathapp/code/Package/Modulename/etc/di.xml
Cart.php file, file path,
app/code/Package/Modulename/CustomerData/Cart.php
you can changes funciton code inside file function.