1

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

1
  • pls share how to implement me fallowed above link but not working it not showing in frontend
    – Pawankumar
    Jun 1, 2020 at 18:03

2 Answers 2

0

add this method in your class.

public function proccessAdditionalValidation(\Magento\Framework\DataObject $request) {
        return true;
    }
0

If you are creating online shipping module the add below to your config.xml file and issue will be solved.

<max_package_weight>70</max_package_weight>

Your Answer

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

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