You can use sales_quote_address_collect_totals_before event for setting your custom totals related data before Magento collect final totals for a quoted address.
Use of address collects totals before event inside observer, You can fetch specific quote data, shipping_assignment, and total related data for a cart.
The event is defined under the Magento_Quote/Model/Quote/TotalsCollector.php file of the Quote module.
You can be interested to retrieve A Complete List of all events in Magento 2.
Using Event, You can set your custom data before the quoted address set final data. Define events in events.xml file,
<?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="your_event_observer_names_defination" instance="Jesadiya\TotalsBefore\Observer\TotalsBeforeEvent" />
</event>
</config>
Create an Observer file to handle your custom data,
<?php
namespace Jesadiya\TotalsBefore\Observer;
use Magento\Quote\Model\Quote;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use Magento\Quote\Api\Data\ShippingAssignmentInterface;
/**
* Class TotalsBeforeEvent
*/
class TotalsBeforeEvent 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();
}
}
The event is used for handling customer address data before the final address and total are set for a quote.
Using the event you can customization of your quote address related stuff in Magento 2.

One Reply to “Use of sales_quote_address_collect_totals_before events Magento 2.”