Magento 2 Error message: Invalid state change requested












2















I've created custom Rest API for adding and removing products from cart.



I am able to add and delete products from my cart, but when I log in as a customer, I can't add or delete products from cart.



API throws message: Invalid state change requested.



How can I solve this?










share|improve this question

























  • Have you got any solution ?

    – Aditya Shah
    Oct 4 '18 at 16:17






  • 1





    Yes, this error disappeared when we pass the Authentication Token n headers.

    – Prabhu M.
    Oct 6 '18 at 16:28
















2















I've created custom Rest API for adding and removing products from cart.



I am able to add and delete products from my cart, but when I log in as a customer, I can't add or delete products from cart.



API throws message: Invalid state change requested.



How can I solve this?










share|improve this question

























  • Have you got any solution ?

    – Aditya Shah
    Oct 4 '18 at 16:17






  • 1





    Yes, this error disappeared when we pass the Authentication Token n headers.

    – Prabhu M.
    Oct 6 '18 at 16:28














2












2








2


1






I've created custom Rest API for adding and removing products from cart.



I am able to add and delete products from my cart, but when I log in as a customer, I can't add or delete products from cart.



API throws message: Invalid state change requested.



How can I solve this?










share|improve this question
















I've created custom Rest API for adding and removing products from cart.



I am able to add and delete products from my cart, but when I log in as a customer, I can't add or delete products from cart.



API throws message: Invalid state change requested.



How can I solve this?







magento2






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 15 '18 at 13:02









Bare Feet

1,5611732




1,5611732










asked Mar 15 '18 at 12:50









Prabhu M.Prabhu M.

185




185













  • Have you got any solution ?

    – Aditya Shah
    Oct 4 '18 at 16:17






  • 1





    Yes, this error disappeared when we pass the Authentication Token n headers.

    – Prabhu M.
    Oct 6 '18 at 16:28



















  • Have you got any solution ?

    – Aditya Shah
    Oct 4 '18 at 16:17






  • 1





    Yes, this error disappeared when we pass the Authentication Token n headers.

    – Prabhu M.
    Oct 6 '18 at 16:28

















Have you got any solution ?

– Aditya Shah
Oct 4 '18 at 16:17





Have you got any solution ?

– Aditya Shah
Oct 4 '18 at 16:17




1




1





Yes, this error disappeared when we pass the Authentication Token n headers.

– Prabhu M.
Oct 6 '18 at 16:28





Yes, this error disappeared when we pass the Authentication Token n headers.

– Prabhu M.
Oct 6 '18 at 16:28










3 Answers
3






active

oldest

votes


















0















/**
* Checks if change quote's customer id is allowed for current user.
*
* @param CartRepositoryInterface $subject
* @param Quote $quote
* @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id
* or unknown user's type
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/




  • https://github.com/magento/magento2/blob/2.2/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php#L46


Judging by the methods docs there may be issues with the Quote not matching or not allowed.



Checks if change quote's customer id is allowed for current user.



...



StateException if Guest has customer_id or Customer's customer_id not much with user_id or unknown user's type






share|improve this answer
























  • It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

    – Prabhu M.
    Mar 16 '18 at 7:37













  • If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

    – B00MER
    Mar 19 '18 at 13:04











  • I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

    – Prabhu M.
    Mar 20 '18 at 12:02





















0














Actually the custom REST API is throwing "Error message: Invalid state change requested" when customer does not pass the Authentication Token in headers. Magento 2 doesn't give access to Quote for users without authentication token.






share|improve this answer































    0














    I have same error and how to pass "Authentication Token" in headers?






    share|improve this answer








    New contributor




    Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















      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%2f217519%2fmagento-2-error-message-invalid-state-change-requested%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0















      /**
      * Checks if change quote's customer id is allowed for current user.
      *
      * @param CartRepositoryInterface $subject
      * @param Quote $quote
      * @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id
      * or unknown user's type
      * @return void
      * @SuppressWarnings(PHPMD.UnusedFormalParameter)
      */




      • https://github.com/magento/magento2/blob/2.2/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php#L46


      Judging by the methods docs there may be issues with the Quote not matching or not allowed.



      Checks if change quote's customer id is allowed for current user.



      ...



      StateException if Guest has customer_id or Customer's customer_id not much with user_id or unknown user's type






      share|improve this answer
























      • It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

        – Prabhu M.
        Mar 16 '18 at 7:37













      • If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

        – B00MER
        Mar 19 '18 at 13:04











      • I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

        – Prabhu M.
        Mar 20 '18 at 12:02


















      0















      /**
      * Checks if change quote's customer id is allowed for current user.
      *
      * @param CartRepositoryInterface $subject
      * @param Quote $quote
      * @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id
      * or unknown user's type
      * @return void
      * @SuppressWarnings(PHPMD.UnusedFormalParameter)
      */




      • https://github.com/magento/magento2/blob/2.2/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php#L46


      Judging by the methods docs there may be issues with the Quote not matching or not allowed.



      Checks if change quote's customer id is allowed for current user.



      ...



      StateException if Guest has customer_id or Customer's customer_id not much with user_id or unknown user's type






      share|improve this answer
























      • It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

        – Prabhu M.
        Mar 16 '18 at 7:37













      • If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

        – B00MER
        Mar 19 '18 at 13:04











      • I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

        – Prabhu M.
        Mar 20 '18 at 12:02
















      0












      0








      0








      /**
      * Checks if change quote's customer id is allowed for current user.
      *
      * @param CartRepositoryInterface $subject
      * @param Quote $quote
      * @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id
      * or unknown user's type
      * @return void
      * @SuppressWarnings(PHPMD.UnusedFormalParameter)
      */




      • https://github.com/magento/magento2/blob/2.2/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php#L46


      Judging by the methods docs there may be issues with the Quote not matching or not allowed.



      Checks if change quote's customer id is allowed for current user.



      ...



      StateException if Guest has customer_id or Customer's customer_id not much with user_id or unknown user's type






      share|improve this answer














      /**
      * Checks if change quote's customer id is allowed for current user.
      *
      * @param CartRepositoryInterface $subject
      * @param Quote $quote
      * @throws StateException if Guest has customer_id or Customer's customer_id not much with user_id
      * or unknown user's type
      * @return void
      * @SuppressWarnings(PHPMD.UnusedFormalParameter)
      */




      • https://github.com/magento/magento2/blob/2.2/app/code/Magento/Quote/Model/QuoteRepository/Plugin/AccessChangeQuoteControl.php#L46


      Judging by the methods docs there may be issues with the Quote not matching or not allowed.



      Checks if change quote's customer id is allowed for current user.



      ...



      StateException if Guest has customer_id or Customer's customer_id not much with user_id or unknown user's type







      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 15 '18 at 14:46









      B00MERB00MER

      8,17321443




      8,17321443













      • It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

        – Prabhu M.
        Mar 16 '18 at 7:37













      • If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

        – B00MER
        Mar 19 '18 at 13:04











      • I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

        – Prabhu M.
        Mar 20 '18 at 12:02





















      • It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

        – Prabhu M.
        Mar 16 '18 at 7:37













      • If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

        – B00MER
        Mar 19 '18 at 13:04











      • I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

        – Prabhu M.
        Mar 20 '18 at 12:02



















      It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

      – Prabhu M.
      Mar 16 '18 at 7:37







      It is checking the below case in AccessChangeQuoteControl.php case UserContextInterface::USER_TYPE_GUEST: $isAllowed = ($quote->getCustomerId() === null); break; when i echo $quote->getCustomerId(), it returns me null, hence the above case breaks, $isAllowed variable is set to false and returns me message: Invalid state change requested. Why is my $quote->getCustomerId() is null?

      – Prabhu M.
      Mar 16 '18 at 7:37















      If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

      – B00MER
      Mar 19 '18 at 13:04





      If the context is hitting the USER_TYPE_GUEST then the customer hasn't been logged in properly over the API possibly.

      – B00MER
      Mar 19 '18 at 13:04













      I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

      – Prabhu M.
      Mar 20 '18 at 12:02







      I checked it by creating new customer account too, but still the context is hitting USER_TYPE_GUEST when i try to add product using custom Rest Api . $params = array( 'form_key' => $this->_formkey->getFormKey(), 'product' => $productId, 'qty' =>$qty ); $this->_cart->addProduct($product_collection, $params); $this->_cart->save();

      – Prabhu M.
      Mar 20 '18 at 12:02















      0














      Actually the custom REST API is throwing "Error message: Invalid state change requested" when customer does not pass the Authentication Token in headers. Magento 2 doesn't give access to Quote for users without authentication token.






      share|improve this answer




























        0














        Actually the custom REST API is throwing "Error message: Invalid state change requested" when customer does not pass the Authentication Token in headers. Magento 2 doesn't give access to Quote for users without authentication token.






        share|improve this answer


























          0












          0








          0







          Actually the custom REST API is throwing "Error message: Invalid state change requested" when customer does not pass the Authentication Token in headers. Magento 2 doesn't give access to Quote for users without authentication token.






          share|improve this answer













          Actually the custom REST API is throwing "Error message: Invalid state change requested" when customer does not pass the Authentication Token in headers. Magento 2 doesn't give access to Quote for users without authentication token.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 30 '18 at 11:27









          Prabhu M.Prabhu M.

          185




          185























              0














              I have same error and how to pass "Authentication Token" in headers?






              share|improve this answer








              New contributor




              Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.

























                0














                I have same error and how to pass "Authentication Token" in headers?






                share|improve this answer








                New contributor




                Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.























                  0












                  0








                  0







                  I have same error and how to pass "Authentication Token" in headers?






                  share|improve this answer








                  New contributor




                  Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.










                  I have same error and how to pass "Authentication Token" in headers?







                  share|improve this answer








                  New contributor




                  Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered 13 mins ago









                  Herry PatsHerry Pats

                  1




                  1




                  New contributor




                  Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  Herry Pats is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






























                      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%2f217519%2fmagento-2-error-message-invalid-state-change-requested%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

                      Magento 2 controller redirect on button click in phtml file

                      Polycentropodidae