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

How to test if a transaction is standard without spending real money?

can i play a electric guitar through a bass amp?

Why can't I see bouncing of a switch on an oscilloscope?

What do the dots in this tr command do: tr .............A-Z A-ZA-Z <<< "JVPQBOV" (with 13 dots)

is the intersection of subgroups a subgroup of each subgroup

Writing rule which states that two causes for the same superpower is bad writing

Is it unprofessional to ask if a job posting on GlassDoor is real?

Why do falling prices hurt debtors?

Which models of the Boeing 737 are still in production?

Dragon forelimb placement

What does it mean to describe someone as a butt steak?

Why doesn't H₄O²⁺ exist?

Can I ask the recruiters in my resume to put the reason why I am rejected?

If I cast Expeditious Retreat, can I Dash as a bonus action on the same turn?

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

To string or not to string

What does "Puller Prush Person" mean?

Risk of getting Chronic Wasting Disease (CWD) in the United States?

Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?

Did Shadowfax go to Valinor?

Is this a crack on the carbon frame?

Is it legal for company to use my work email to pretend I still work there?

How does one intimidate enemies without having the capacity for violence?

Have astronauts in space suits ever taken selfies? If so, how?



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






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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
























  • 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

















1















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
























  • 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













1












1








1








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

658823




658823












  • 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

Sum ergo cogito? 1 nng

三茅街道4182Guuntc Dn precexpngmageondP