I am implementing a shipping method for my store. My method is based on the subtotal value so I need to get subtotal value in my module. How can I call subtotal value in magento 2.2? for example I want my shipping price be: subtotal/100
1 Answer
use below code to get subtotal in custom shipping method.
<?php namespace Meetanshi\Flatshipping\Model\Carrier;
use Magento\Quote\Model\Quote\Address\RateRequest;
use Magento\Shipping\Model\Carrier\AbstractCarrier;
use Magento\Shipping\Model\Carrier\CarrierInterface;
class Flatrate extends AbstractCarrier implements CarrierInterface
{
public function collectRates(RateRequest $request)
{
$subtotal = $request->getBaseSubtotalInclTax();
//Here use your own conditions.
}
}
Thanks
-
Couldn't find this method in the debugger, but it works. Thanks :)– ZankarCommented May 17, 2021 at 6:27