Please specify shipping method with custom shipping method - Magento 2












4















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 <trace> 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.










share|improve this question





























    4















    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 <trace> 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.










    share|improve this question



























      4












      4








      4








      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 <trace> 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.










      share|improve this question
















      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 <trace> 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.







      magento2 custom-shipping-method






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 15 at 13:46









      magefms

      43313




      43313










      asked Mar 2 '18 at 10:54









      BramBram

      14519




      14519






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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






          share|improve this answer
























          • 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 '18 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 '18 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 '18 at 15:24













          • Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

            – zus
            May 18 '18 at 6:15



















          4














          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.






          share|improve this answer
























          • 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 '18 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 '18 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 '18 at 13:41











          • @bramulous Sum the carrier_code, the method_code and one symbol _

            – Siarhey Uchukhlebau
            Mar 2 '18 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 '18 at 15:25











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "479"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f215756%2fplease-specify-shipping-method-with-custom-shipping-method-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          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






          share|improve this answer
























          • 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 '18 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 '18 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 '18 at 15:24













          • Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

            – zus
            May 18 '18 at 6:15
















          1














          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






          share|improve this answer
























          • 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 '18 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 '18 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 '18 at 15:24













          • Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

            – zus
            May 18 '18 at 6:15














          1












          1








          1







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 2 '18 at 12:08









          lpFranzlpFranz

          315112




          315112













          • 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 '18 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 '18 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 '18 at 15:24













          • Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

            – zus
            May 18 '18 at 6:15



















          • 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 '18 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 '18 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 '18 at 15:24













          • Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

            – zus
            May 18 '18 at 6:15

















          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 '18 at 13:36





          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 '18 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 '18 at 14:41





          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 '18 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 '18 at 15:24







          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 '18 at 15:24















          Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

          – zus
          May 18 '18 at 6:15





          Will you pls help me : “Please specify a shipping method” error @ magento.stackexchange.com/q/225297/57334

          – zus
          May 18 '18 at 6:15













          4














          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.






          share|improve this answer
























          • 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 '18 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 '18 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 '18 at 13:41











          • @bramulous Sum the carrier_code, the method_code and one symbol _

            – Siarhey Uchukhlebau
            Mar 2 '18 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 '18 at 15:25
















          4














          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.






          share|improve this answer
























          • 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 '18 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 '18 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 '18 at 13:41











          • @bramulous Sum the carrier_code, the method_code and one symbol _

            – Siarhey Uchukhlebau
            Mar 2 '18 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 '18 at 15:25














          4












          4








          4







          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.






          share|improve this answer













          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 2 '18 at 12:21









          Siarhey UchukhlebauSiarhey Uchukhlebau

          9,44692757




          9,44692757













          • 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 '18 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 '18 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 '18 at 13:41











          • @bramulous Sum the carrier_code, the method_code and one symbol _

            – Siarhey Uchukhlebau
            Mar 2 '18 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 '18 at 15:25



















          • 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 '18 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 '18 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 '18 at 13:41











          • @bramulous Sum the carrier_code, the method_code and one symbol _

            – Siarhey Uchukhlebau
            Mar 2 '18 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 '18 at 15:25

















          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 '18 at 13:34





          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 '18 at 13:34




          1




          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 '18 at 13:39





          @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 '18 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 '18 at 13:41





          Okay okay, so maybe a stupid question: how do I know if my code is longer than '40 bytes'?

          – Bram
          Mar 2 '18 at 13:41













          @bramulous Sum the carrier_code, the method_code and one symbol _

          – Siarhey Uchukhlebau
          Mar 2 '18 at 13:52





          @bramulous Sum the carrier_code, the method_code and one symbol _

          – Siarhey Uchukhlebau
          Mar 2 '18 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 '18 at 15:25





          Ah like so! And the code indeed contained an '_' and the name was to too long. Thank you, all settled now!

          – Bram
          Mar 2 '18 at 15:25


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Magento Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f215756%2fplease-specify-shipping-method-with-custom-shipping-method-magento-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          William S. Burroughs

          Eda skans

          1924