Magento 2 Error message: Invalid state change requested
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
add a comment |
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
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
add a comment |
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
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
magento2
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
/**
* 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
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 theUSER_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
add a comment |
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.
add a comment |
I have same error and how to pass "Authentication Token" in headers?
New contributor
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
/**
* 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
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 theUSER_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
add a comment |
/**
* 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
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 theUSER_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
add a comment |
/**
* 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
/**
* 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
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 theUSER_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
add a comment |
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 theUSER_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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Apr 30 '18 at 11:27
Prabhu M.Prabhu M.
185
185
add a comment |
add a comment |
I have same error and how to pass "Authentication Token" in headers?
New contributor
add a comment |
I have same error and how to pass "Authentication Token" in headers?
New contributor
add a comment |
I have same error and how to pass "Authentication Token" in headers?
New contributor
I have same error and how to pass "Authentication Token" in headers?
New contributor
New contributor
answered 13 mins ago
Herry PatsHerry Pats
1
1
New contributor
New contributor
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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