I am creating a custom shipping module for magento 2.1.8.
I read on another post that shipping carriers divided into two types: online and offline shipping. (see How to programmaticlly create custom shipping method for third party API)
I seem to be having a problem with getting the shipping methods to display on the checkout with online shipping. The reason i want to use online shipping is because i need to create a shipping label in the admin panel when shipping the order, this functionality doesnt seem to be available with offline shipping.
I have tested the following code and the offline shipping code shows shipping methods on Checkout
Offline Shpping
use Magento\Shipping\Model\Carrier\AbstractCarrier;
class Carrier extends AbstractCarrier implements
\Magento\Shipping\Model\Carrier\CarrierInterface
{
/**
* Collect and get rates
*
* @param RateRequest $request
*
* @return bool|Result
*/
public function collectRates(RateRequest $request)
{
/** @var \Magento\Shipping\Model\Rate\Result $result */
$result = $this->_rateResultFactory->create();
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
$method = $this->_shippingRateMethodFactory->create();
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->_title);
$method->setMethod("Shipper");
$method->setMethodTitle("My Shipping Method");
$amount = 120;
$method->setPrice($amount);
$method->setCost($amount);
$result->append($method);
return $result;
}
}
The following online shipping code doesnt show shipping methods on checkout
Online Shipping
use Magento\Shipping\Model\Carrier\AbstractCarrierOnline;
class Carrier extends AbstractCarrierOnline
implements \Magento\Shipping\Model\Carrier\CarrierInterface
{
/**
* Collect and get rates
*
* @param RateRequest $request
*
* @return bool|Result
*/
public function collectRates(RateRequest $request)
{
/** @var \Magento\Shipping\Model\Rate\Result $result */
$result = $this->_rateResultFactory->create();
/** @var \Magento\Quote\Model\Quote\Address\RateResult\Method $method */
$method = $this->_shippingRateMethodFactory->create();
$method->setCarrier($this->_code);
$method->setCarrierTitle($this->_title);
$method->setMethod("Shipper");
$method->setMethodTitle("My Shipping Method");
$amount = 120;
$method->setPrice($amount);
$method->setCost($amount);
$result->append($method);
return $result;
}
}
My problem is why is the shipping methods not displaying on checkout when i use the online shipping method code but it works fine with the offline code?
can someone hint me or guide in the right direction? Thanks