1

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 1

2

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

1
  • Couldn't find this method in the debugger, but it works. Thanks :)
    – Zankar
    May 17, 2021 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.