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

iPad being using in wall mount battery swollen

Should I cover my bicycle overnight while bikepacking?

Do UK voters know if their MP will be the Speaker of the House?

Why can't we play rap on piano?

Plagiarism or not?

Why didn't Miles's spider sense work before?

How to tell a function to use the default argument values?

Short story with a alien planet, government officials must wear exploding medallions

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

What about the virus in 12 Monkeys?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

Avoiding the "not like other girls" trope?

Apex Framework / library for consuming REST services

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

Method Does Not Exist error message

How to show a landlord what we have in savings?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

How do I handle a potential work/personal life conflict as the manager of one of my friends?

How do I gain back my faith in my PhD degree?

Assassin's bullet with mercury

Can compressed videos be decoded back to their uncompresed original format?

ssTTsSTtRrriinInnnnNNNIiinngg

Why doesn't using multiple commands with a || or && conditional work?

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"



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 5 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 5 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 5 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 5 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 duplicate PHPSESSID cookie when using session_start() in custom php scriptMagento 2: User cant logged in into to account page, no error showing!Magento duplicate on subdomainGrabbing storeview from cookie (after using language selector)How do I run php custom script on magento2Magento 2: Include PHP script in headerSession lock after using Cm_RedisSessionscript php to update stockMagento set cookie popupMagento 2 session id cookie - where to find it?How to import Configurable product from csv with custom attributes using php scriptMagento 2 run custom PHP script

How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2