Magento 2 you can use sales quote address collect totals after the event to Collect address total related data after Magento completed the process for a current quote total.
Event Name to used:
sales_quote_address_collect_totals_after
Using the above event in the observer, you can fetch specific quote data, shipping_assignment, and total related data for a cart.
Simple code snippet for use events, Define 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_after">
<observer name="your_event_observeranme" instance="Jesadiya\Totals\Observer\MyObserver" />
</event>
</config>
Create an Observer file to fetch quote related data,
<?php
namespace Jesadiya\Totals\Observer;
use Magento\Quote\Model\Quote;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
/**
* Class MyObserver
*/
class MyObserver implements ObserverInterface
{
/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer)
{
/** Fetch Address related data */
$shippingAssignment = $observer->getEvent()->getShippingAssignment();
$address = $shippingAssignment->getShipping()->getAddress();
// fetch quote data
/** @var Quote $quote */
$quote = $observer->getEvent()->getQuote();
// fetch totals data
$total = $observer->getEvent()->getTotal();
}
}
You can use the above way your observer with the required data after collecting totals in Magento 2.
Check Use of sales_quote_address_collect_totals_before events Magento 2.
You can refer for more details to use in your custom module using the Magento_Quote module.
You can be interested to learn A Complete List of events used in Magento 2.
