I am developing a module which set discount to total, Whenever customer will press Get Discount.
I can able to reduce Subtotal and GrandTotal in customer quote, Also my quote table is getting updated.
Check my controller below.
public function execute()
{
echo "<pre>";
$label = 'My Custom Discount';
$discountAmount = 10;
$quoteSession = $this->salesQuote->getQuote()->getData();
$quoteId = $quoteSession['entity_id'];
$quote = $this->quoteFactory->create()->load($quoteId);
// print_r($quote->getData()); exit;
$quote->setSubtotal($quote->getSubtotal() - $discountAmount);
$quote->setBaseSubtotal($quote->getBaseSubtotal() - $discountAmount);
$quote->setSubtotalWithDiscount($quote->getSubtotalWithDiscount() - $discountAmount);
$quote->setBaseSubtotalWithDiscount($quote->getBaseSubtotalWithDiscount() - $discountAmount);
$quote->setGrandTotal(30);
$quote->setBaseGrandTotal(30);
$quote->save();
But how can I render my Updated Grand Total at Cart Page as well as other further steps like checkout, Invoice, etc etc?
I am stuck here, No idea what is next step !!
Any help would be really great.
Best Answer
First, create new file
sales.xml
insideetc
folder with the following code:Next, create the file
Vendor\Module\Model\Total\Quote\CustomTotal.php
with the code below:Hope it help!