P.S I want to display grand total after store credit is applied because as of current it shows without store credit in it, for example customer applied 200 credit out of 500 purchase so his grand total should be 300$ but instead grand total shows 500$, the correct display is to show 300$ in grand total
I created an observer to change grand total and remove store credit from grand total, my observer is working fine and calculating customer balance and has the quote, however I cannot save the quote, I also tried $quote->collectTotals() but it gives me 502 Nginx error I am not sure how to make the quote understand to change the grand total, although I am setting the grand total I do not see it working on the page: here is the events.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_address_collect_totals_before">
<observer name="customer_get_balance" instance="ImplantDirect\Storecredit\Observer\GetCustomerBalance"/>
</event>
</config>
and here is part of observer execute function:
public function execute(EventObserver $observer)
{
/* @var $customer \Magento\Customer\Api\Data\CustomerInterface */
$quote = $observer->getEvent()->getQuote();
$customerId = $quote->getCustomer()->getId();
$websiteId =$this->_storeManager->getStore()->getWebsiteId();
$balanceModel = $this->_balanceFactory->create()->setCustomerId($customerId)->setWebsiteId($websiteId)->loadByCustomer();
$amount = $balanceModel->getAmount();
$grandTotal = $quote->getGrandTotal();
if($amount>=$grandTotal)
{
$quote->setGrandTotal(0);
}
else{
$quote->setGrandTotal($grandTotal-$amount);
}
please explain what can I do to make Quote understand to use the new updated grand total thank you