I need to add some logic to weight package calculation before shipping rates are calculated. So I created a custom module with an observer on sales_quote_address_collect_totals_after
event.
The observer looks like this
use Magento\Framework\Event\ObserverInterface;
class AfterCollectTotals implements ObserverInterface{
public function execute(\Magento\Framework\Event\Observer $observer){
foreach ($items as $item) {
// My custom logic here to get the correct weight in $weight
}
$observer->getQuote()->getShippingAddress()->setWeight($weight);
}
}
Weight appears to be set correctly, but when the Shipping Rates are calculated this value is ignored.
In the carrier model, $request->getPackageWeight()
returns the package weight before my manipulation.
Where am I wrong?
Thank you
sales_quote_address_collect_totals_before
instead..._after
?