I've been trying to add custom shipping methods to a Magento 2 webshop, using configurations in app/code/vendor/module/etc/config.xml, app/code/vendor/module/etc/system.xml and app/code/vendor/module/Model/Carrier/Shippingmethod.php.

So, this all works, and I can select the shipping methods. Also, when NOT logged in, the checkout works fine and can get completed.

The problem is, when logged in with a (new) customer, when using one of the custom shipping methods, it throws the following error: 'Please specify a shipping method' (freely translated from original language). The console throws the following error:

Error payment-information

When I go the following link: http://mywebshop.com/rest/default/V1/carts/mine/payment-information

It says "User not authorized for %resources" and a tag with a few php files:

enter image description here

Some research later, people talk about tokens and stuff, but can't figure it out.

up vote 1 down vote accepted

this possibly occurs because new customers do not have an address registered, I've pass throug problems with custom shipping too, see this question, maybe helps you.

And see my example of custom shipping method.

I hope it help

  • The new customers had an address specified beforehand, so that wouldn't have been the issue. I have used your example on Git, and after some modifications that works. I still want to know why mine did not work, cause it did not vary that much from yours, only that some values were obtained by setters and yours by a rand() or hardcoded. – Bram Mar 2 at 13:36
  • your shipping method code, setted on app/code/vendor/module/Model/Carrier/Shippingmethod.php, must not contain "_" and can't be bigger than 40, like @Siarhey Uchukhlebau says. Check the system.xml and config.xml too, all carriers_code must be the same, send me your github, I'll take a look. – lpFranz Mar 2 at 14:41
  • Due to the fact that this is for an internship, I cannot share my code with you unfortunately. But as @Siarhey Uchukhlebau, my method code did indeed include an '_' and was longer than 40 symbols! So that was the problem. Thank you for your help! – Bram Mar 2 at 15:24
  • Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334 – zus May 18 at 6:15

Another reason of that issue could be long method code (>40 symbols) or multiple symbols _ in the full method code (carrier code+method code). Check this data when it sending from the checkout to the backend.

  • What exactly are you meaning by 'long method code'? The Model/Carrier/Customshipping.php code itself is 76 lines long, so >40 symbols. – Bram Mar 2 at 13:34
  • 1
    @bramulous Before the 2.2.0 release the shipping_method column in the table quote_address has length 40, so if your code >40 bytes it will be cropped by mysql (during insert/update). After the 2.2.0 Magento update it's length set to the 120 byte. – Siarhey Uchukhlebau Mar 2 at 13:39
  • Okay okay, so maybe a stupid question: how do I know if my code is longer than '40 bytes'? – Bram Mar 2 at 13:41
  • @bramulous Sum the carrier_code, the method_code and one symbol _ – Siarhey Uchukhlebau Mar 2 at 13:52
  • Ah like so! And the code indeed contained an '_' and the name was to too long. Thank you, all settled now! – Bram Mar 2 at 15:25

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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