Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item....

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

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

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

Apex Framework / library for consuming REST services

Assassin's bullet with mercury

What is the most common color to indicate the input-field is disabled?

How do I deal with an unproductive colleague in a small company?

How does a predictive coding aid in lossless compression?

Why do bosons tend to occupy the same state?

Madden-Julian Oscillation (MJO) - How to interpret the index?

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

Probability that a draw from a normal distribution is some number greater than another draw from the same distribution

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

How to prevent "they're falling in love" trope

Arrow those variables!

Examples of smooth manifolds admitting inbetween one and a continuum of complex structures

iPad being using in wall mount battery swollen

Cursor Replacement for Newbies

What about the virus in 12 Monkeys?

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

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

What type of content (depth/breadth) is expected for a short presentation for Asst Professor interview in the UK?

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

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



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 3 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 3 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 3 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 3 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

“%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...