Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

What's the in-universe reasoning behind sorcerers needing material components?

What killed these X2 caps?

Why is consensus so controversial in Britain?

CAST throwing error when run in stored procedure but not when run as raw query

Assassin's bullet with mercury

Why do bosons tend to occupy the same state?

Ambiguity in the definition of entropy

What does the expression "A Mann!" means

Is it logically or scientifically possible to artificially send energy to the body?

Do scales need to be in alphabetical order?

Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?

Is it possible to create a QR code using text?

Should I tell management that I intend to leave due to bad software development practices?

Why no variance term in Bayesian logistic regression?

How badly should I try to prevent a user from XSSing themselves?

I would say: "You are another teacher", but she is a woman and I am a man

What mechanic is there to disable a threat instead of killing it?

What is a romance in Latin?

Cursor Replacement for Newbies

How could indestructible materials be used in power generation?

What about the virus in 12 Monkeys?

Am I breaking OOP practice with this architecture?

Mathematica command that allows it to read my intentions

Unlock My Phone! February 2018



Can not update quote_id field of “quote_item” table magento 2


Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller













0















I want to assign items added to cart by one customer to the other customer's cart.



For this I see two tables responsible for holding that data. One is table named "quote" and other is "Quote_item".The customer in which I want to transfer the cart item already has a quote created on quote table. so I thought changing the quote_id of that customer on quote_item table would do the trick.



Let me explain by example:



Let us assume we have two customer with quote id 1 and 2.
Customer 1 added a product to the cart so on quote_item table the item will be saved with quote id 1. so if I could change the quote id of that item to 2 than that product will be assigned to customer 2.



I tried it by manually changing to the database and it worked. But When I tried to update that table programatically than it couldn't update the row. I think there is some kind of dependencies that I couldn't figure out.So I hope if someone could help me figure it out.



Below is the update code that I have written.



$_objectManager = MagentoFrameworkAppObjectManager::getInstance();

$quoteItemModel = $_objectManager->create('MagentoQuoteModelQuoteItem');
//filter the product with same quote id
$productCollection = $_objectManager->create('MagentoQuoteModelResourceModelQuoteItemCollection')->addFieldToFilter('quote_id',$quoteId);
if($products = $productCollection->getData()){
foreach ($products as $product)
$itemId = $product['item_id'];
$data = array();
//just putting a static value to check if the data gets updated
$data['quote_id']='2';
//updating the quote_item table
$quoteItemModel->load($itemId)->addData($data);
try
$quoteItemModel->setId($itemId)->save();
echo "Data updated successfully.";

catch (Exception $e)
echo $e->getMessage();




I know the code works perfectly with other custom tables.But in this case it is not updating the data.
Its gives below error:




Fatal error: Call to a member function getStoreId() on null in
E:xampphtdocs...vendormagentomodule-quoteModelQuoteItemAbstractItem.php
on line 144




When I checked that file. The function is:



 public function getProduct()
{
$product = $this->_getData('product');
if ($product === null && $this->getProductId())
$product = clone $this->productRepository->getById(
$this->getProductId(),
false,
$this->getQuote()->getStoreId()
);
$this->setProduct($product);



I don't understand what it has to do with the update of table quote_item.I think there is some foreign key constraints or some dependency which is why it is not letting me update the quote_id of quote_item table.



Can some genius mind please help me out here or clearify what could have possibly gone wrong?



Actually I searched the whole internet and also posted question on stackoverflow about the migration of customer cart from one customer to another but still I haven't got a perfect working solution for it.



If someone could help me on this, it would be greatly appreciated.



Thanks.










share|improve this question
















bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • What I don't understand is why you want to add this item in one person's cart to another user.

    – camdixon
    Dec 11 '16 at 21:18











  • That's my requirement.actually one customer should be able to assign products to another customer cart.

    – aton1004
    Dec 12 '16 at 9:02















0















I want to assign items added to cart by one customer to the other customer's cart.



For this I see two tables responsible for holding that data. One is table named "quote" and other is "Quote_item".The customer in which I want to transfer the cart item already has a quote created on quote table. so I thought changing the quote_id of that customer on quote_item table would do the trick.



Let me explain by example:



Let us assume we have two customer with quote id 1 and 2.
Customer 1 added a product to the cart so on quote_item table the item will be saved with quote id 1. so if I could change the quote id of that item to 2 than that product will be assigned to customer 2.



I tried it by manually changing to the database and it worked. But When I tried to update that table programatically than it couldn't update the row. I think there is some kind of dependencies that I couldn't figure out.So I hope if someone could help me figure it out.



Below is the update code that I have written.



$_objectManager = MagentoFrameworkAppObjectManager::getInstance();

$quoteItemModel = $_objectManager->create('MagentoQuoteModelQuoteItem');
//filter the product with same quote id
$productCollection = $_objectManager->create('MagentoQuoteModelResourceModelQuoteItemCollection')->addFieldToFilter('quote_id',$quoteId);
if($products = $productCollection->getData()){
foreach ($products as $product)
$itemId = $product['item_id'];
$data = array();
//just putting a static value to check if the data gets updated
$data['quote_id']='2';
//updating the quote_item table
$quoteItemModel->load($itemId)->addData($data);
try
$quoteItemModel->setId($itemId)->save();
echo "Data updated successfully.";

catch (Exception $e)
echo $e->getMessage();




I know the code works perfectly with other custom tables.But in this case it is not updating the data.
Its gives below error:




Fatal error: Call to a member function getStoreId() on null in
E:xampphtdocs...vendormagentomodule-quoteModelQuoteItemAbstractItem.php
on line 144




When I checked that file. The function is:



 public function getProduct()
{
$product = $this->_getData('product');
if ($product === null && $this->getProductId())
$product = clone $this->productRepository->getById(
$this->getProductId(),
false,
$this->getQuote()->getStoreId()
);
$this->setProduct($product);



I don't understand what it has to do with the update of table quote_item.I think there is some foreign key constraints or some dependency which is why it is not letting me update the quote_id of quote_item table.



Can some genius mind please help me out here or clearify what could have possibly gone wrong?



Actually I searched the whole internet and also posted question on stackoverflow about the migration of customer cart from one customer to another but still I haven't got a perfect working solution for it.



If someone could help me on this, it would be greatly appreciated.



Thanks.










share|improve this question
















bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • What I don't understand is why you want to add this item in one person's cart to another user.

    – camdixon
    Dec 11 '16 at 21:18











  • That's my requirement.actually one customer should be able to assign products to another customer cart.

    – aton1004
    Dec 12 '16 at 9:02













0












0








0








I want to assign items added to cart by one customer to the other customer's cart.



For this I see two tables responsible for holding that data. One is table named "quote" and other is "Quote_item".The customer in which I want to transfer the cart item already has a quote created on quote table. so I thought changing the quote_id of that customer on quote_item table would do the trick.



Let me explain by example:



Let us assume we have two customer with quote id 1 and 2.
Customer 1 added a product to the cart so on quote_item table the item will be saved with quote id 1. so if I could change the quote id of that item to 2 than that product will be assigned to customer 2.



I tried it by manually changing to the database and it worked. But When I tried to update that table programatically than it couldn't update the row. I think there is some kind of dependencies that I couldn't figure out.So I hope if someone could help me figure it out.



Below is the update code that I have written.



$_objectManager = MagentoFrameworkAppObjectManager::getInstance();

$quoteItemModel = $_objectManager->create('MagentoQuoteModelQuoteItem');
//filter the product with same quote id
$productCollection = $_objectManager->create('MagentoQuoteModelResourceModelQuoteItemCollection')->addFieldToFilter('quote_id',$quoteId);
if($products = $productCollection->getData()){
foreach ($products as $product)
$itemId = $product['item_id'];
$data = array();
//just putting a static value to check if the data gets updated
$data['quote_id']='2';
//updating the quote_item table
$quoteItemModel->load($itemId)->addData($data);
try
$quoteItemModel->setId($itemId)->save();
echo "Data updated successfully.";

catch (Exception $e)
echo $e->getMessage();




I know the code works perfectly with other custom tables.But in this case it is not updating the data.
Its gives below error:




Fatal error: Call to a member function getStoreId() on null in
E:xampphtdocs...vendormagentomodule-quoteModelQuoteItemAbstractItem.php
on line 144




When I checked that file. The function is:



 public function getProduct()
{
$product = $this->_getData('product');
if ($product === null && $this->getProductId())
$product = clone $this->productRepository->getById(
$this->getProductId(),
false,
$this->getQuote()->getStoreId()
);
$this->setProduct($product);



I don't understand what it has to do with the update of table quote_item.I think there is some foreign key constraints or some dependency which is why it is not letting me update the quote_id of quote_item table.



Can some genius mind please help me out here or clearify what could have possibly gone wrong?



Actually I searched the whole internet and also posted question on stackoverflow about the migration of customer cart from one customer to another but still I haven't got a perfect working solution for it.



If someone could help me on this, it would be greatly appreciated.



Thanks.










share|improve this question
















I want to assign items added to cart by one customer to the other customer's cart.



For this I see two tables responsible for holding that data. One is table named "quote" and other is "Quote_item".The customer in which I want to transfer the cart item already has a quote created on quote table. so I thought changing the quote_id of that customer on quote_item table would do the trick.



Let me explain by example:



Let us assume we have two customer with quote id 1 and 2.
Customer 1 added a product to the cart so on quote_item table the item will be saved with quote id 1. so if I could change the quote id of that item to 2 than that product will be assigned to customer 2.



I tried it by manually changing to the database and it worked. But When I tried to update that table programatically than it couldn't update the row. I think there is some kind of dependencies that I couldn't figure out.So I hope if someone could help me figure it out.



Below is the update code that I have written.



$_objectManager = MagentoFrameworkAppObjectManager::getInstance();

$quoteItemModel = $_objectManager->create('MagentoQuoteModelQuoteItem');
//filter the product with same quote id
$productCollection = $_objectManager->create('MagentoQuoteModelResourceModelQuoteItemCollection')->addFieldToFilter('quote_id',$quoteId);
if($products = $productCollection->getData()){
foreach ($products as $product)
$itemId = $product['item_id'];
$data = array();
//just putting a static value to check if the data gets updated
$data['quote_id']='2';
//updating the quote_item table
$quoteItemModel->load($itemId)->addData($data);
try
$quoteItemModel->setId($itemId)->save();
echo "Data updated successfully.";

catch (Exception $e)
echo $e->getMessage();




I know the code works perfectly with other custom tables.But in this case it is not updating the data.
Its gives below error:




Fatal error: Call to a member function getStoreId() on null in
E:xampphtdocs...vendormagentomodule-quoteModelQuoteItemAbstractItem.php
on line 144




When I checked that file. The function is:



 public function getProduct()
{
$product = $this->_getData('product');
if ($product === null && $this->getProductId())
$product = clone $this->productRepository->getById(
$this->getProductId(),
false,
$this->getQuote()->getStoreId()
);
$this->setProduct($product);



I don't understand what it has to do with the update of table quote_item.I think there is some foreign key constraints or some dependency which is why it is not letting me update the quote_id of quote_item table.



Can some genius mind please help me out here or clearify what could have possibly gone wrong?



Actually I searched the whole internet and also posted question on stackoverflow about the migration of customer cart from one customer to another but still I haven't got a perfect working solution for it.



If someone could help me on this, it would be greatly appreciated.



Thanks.







magento2 magento-2.1






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 11 '16 at 15:11









Nitin Pawar

79911438




79911438










asked Dec 11 '16 at 14:59









aton1004aton1004

653823




653823





bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community 16 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • What I don't understand is why you want to add this item in one person's cart to another user.

    – camdixon
    Dec 11 '16 at 21:18











  • That's my requirement.actually one customer should be able to assign products to another customer cart.

    – aton1004
    Dec 12 '16 at 9:02

















  • What I don't understand is why you want to add this item in one person's cart to another user.

    – camdixon
    Dec 11 '16 at 21:18











  • That's my requirement.actually one customer should be able to assign products to another customer cart.

    – aton1004
    Dec 12 '16 at 9:02
















What I don't understand is why you want to add this item in one person's cart to another user.

– camdixon
Dec 11 '16 at 21:18





What I don't understand is why you want to add this item in one person's cart to another user.

– camdixon
Dec 11 '16 at 21:18













That's my requirement.actually one customer should be able to assign products to another customer cart.

– aton1004
Dec 12 '16 at 9:02





That's my requirement.actually one customer should be able to assign products to another customer cart.

– aton1004
Dec 12 '16 at 9:02










1 Answer
1






active

oldest

votes


















0














could you explain more your task ? the customer 1 has to keep his quote and items ? and the customer 2 just have the same items than the customer 1 that's it?
In this case just use the addProduct method which take 2 parameters ($product, $qty).



Get the items from customer 1's quote. Loop on it, and add product to your customer 2's quote.






share|improve this answer























  • Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

    – aton1004
    Dec 12 '16 at 9:01











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%2f149798%2fcan-not-update-quote-id-field-of-quote-item-table-magento-2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














could you explain more your task ? the customer 1 has to keep his quote and items ? and the customer 2 just have the same items than the customer 1 that's it?
In this case just use the addProduct method which take 2 parameters ($product, $qty).



Get the items from customer 1's quote. Loop on it, and add product to your customer 2's quote.






share|improve this answer























  • Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

    – aton1004
    Dec 12 '16 at 9:01















0














could you explain more your task ? the customer 1 has to keep his quote and items ? and the customer 2 just have the same items than the customer 1 that's it?
In this case just use the addProduct method which take 2 parameters ($product, $qty).



Get the items from customer 1's quote. Loop on it, and add product to your customer 2's quote.






share|improve this answer























  • Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

    – aton1004
    Dec 12 '16 at 9:01













0












0








0







could you explain more your task ? the customer 1 has to keep his quote and items ? and the customer 2 just have the same items than the customer 1 that's it?
In this case just use the addProduct method which take 2 parameters ($product, $qty).



Get the items from customer 1's quote. Loop on it, and add product to your customer 2's quote.






share|improve this answer













could you explain more your task ? the customer 1 has to keep his quote and items ? and the customer 2 just have the same items than the customer 1 that's it?
In this case just use the addProduct method which take 2 parameters ($product, $qty).



Get the items from customer 1's quote. Loop on it, and add product to your customer 2's quote.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 11 '16 at 22:49









SonySony

397312




397312












  • Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

    – aton1004
    Dec 12 '16 at 9:01

















  • Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

    – aton1004
    Dec 12 '16 at 9:01
















Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

– aton1004
Dec 12 '16 at 9:01





Yes that could be one of the solution. can you post some code snippet. Actually I have complex bundle products with many options, so I guess doing that would be quite difficult. Can you post some code to verify your logic. THanks

– aton1004
Dec 12 '16 at 9:01

















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%2f149798%2fcan-not-update-quote-id-field-of-quote-item-table-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

Magento 2 disable Secret Key on URL's from terminal The Next CEO of Stack OverflowMagento 2 Shortcut/GUI tool to perform commandline tasks for windowsIn menu add configuration linkMagento oAuth : Generating access token and access secretMagento 2 security key issue in Third-Party API redirect URIPublic actions in admin controllersHow to Disable Cache in Custom WidgetURL Key not changing in Magento 2Product URL Key gets deleted when importing custom options - Magento 2Problem with reindex terminalMagento 2 - bin/magento Commands not working in Cpanel Terminal

Aasi (pallopeli) Navigointivalikko