How to get value from sales_flat_order_item table using quote_item_id?I want to alter the new custom fields to sales_flat_order and sales_flat_order_item tableHow to get collection from table 'sales_flat_creditmemo_item'save custom field from sales_flat_order_item to sales_flat_orderHow can I get special price of an ordered product in “sales_flat_order_item” tableget cart items from custom column valueMagento model not fetching dataUpdate “sales_flat_order_item” table when making an orderHow do i get to Magento Table value using APIGet custom values from sales_flat_order_item table in magento?Bundle items are missing from sales_flat_order_item table. Magento 1.9

How to not starve gigantic beasts

Is there any official lore on the Far Realm?

a sore throat vs a strep throat vs strep throat

Can SQL Server create collisions in system generated constraint names?

What happens to Mjolnir (Thor's hammer) at the end of Endgame?

"You've called the wrong number" or "You called the wrong number"

How could Tony Stark make this in Endgame?

How did Captain America manage to do this?

Phrase for the opposite of "foolproof"

How to display Aura JS Errors Lightning Out

Mistake in years of experience in resume?

Rivers without rain

Providing evidence of Consent of Parents for Marriage by minor in England in early 1800s?

Why does Mind Blank stop the Feeblemind spell?

Don’t seats that recline flat defeat the purpose of having seatbelts?

Is there a way to generate a list of distinct numbers such that no two subsets ever have an equal sum?

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

infinitely many negative and infinitely many positive numbers

Map of water taps to fill bottles

Why did C use the -> operator instead of reusing the . operator?

How do I reattach a shelf to the wall when it ripped out of the wall?

Which big number is bigger?

Can I criticise the more senior developers around me for not writing clean code?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?



How to get value from sales_flat_order_item table using quote_item_id?


I want to alter the new custom fields to sales_flat_order and sales_flat_order_item tableHow to get collection from table 'sales_flat_creditmemo_item'save custom field from sales_flat_order_item to sales_flat_orderHow can I get special price of an ordered product in “sales_flat_order_item” tableget cart items from custom column valueMagento model not fetching dataUpdate “sales_flat_order_item” table when making an orderHow do i get to Magento Table value using APIGet custom values from sales_flat_order_item table in magento?Bundle items are missing from sales_flat_order_item table. Magento 1.9






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








0















Using the sales_order_place_after event in my custom Observer.

I have the quote_item_id value (example 324).
How to get the corresponding item_id value from the sales_flat_order_item table?



I am able to successfully use getCollection method, but it returns the order item as an array.

($sales_order_item_id in below example)



How to get the string value? Eg 224 in example table

(in an efficient manner)



class Custom_Model_Observer 
public function booking(Varien_Event_Observer $observer)
$OrderId = $observer->getEvent()->getOrder()->getId(); //order entity id
$QuoteObject = Mage::getSingleton('checkout/session')->getQuote(); //quote object

foreach ($QuoteObject->getAllVisibleItems() as $item)

//get the quote item id - in example $quote_itemId = 324
$quote_itemId = $item->getData('item_id');

//get data from sales_flat_order_item table
$sales_order_item_id = Mage::getModel('sales/order_item')
->getCollection()
->addFieldToFilter('quote_item_id', $quote_itemId)
->getData('item_id');
//do more stuff here






Example sales_flat_order_item table:



sales_flat_order_item table










share|improve this question
























  • $sales_order_item_id = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('quote_item_id', $quote_itemId)->getItemId();

    – Aaditya
    Apr 22 at 18:44











  • Did already try that, but not working. Code stops dead, no log error, no exception.

    – Dan
    Apr 22 at 19:08

















0















Using the sales_order_place_after event in my custom Observer.

I have the quote_item_id value (example 324).
How to get the corresponding item_id value from the sales_flat_order_item table?



I am able to successfully use getCollection method, but it returns the order item as an array.

($sales_order_item_id in below example)



How to get the string value? Eg 224 in example table

(in an efficient manner)



class Custom_Model_Observer 
public function booking(Varien_Event_Observer $observer)
$OrderId = $observer->getEvent()->getOrder()->getId(); //order entity id
$QuoteObject = Mage::getSingleton('checkout/session')->getQuote(); //quote object

foreach ($QuoteObject->getAllVisibleItems() as $item)

//get the quote item id - in example $quote_itemId = 324
$quote_itemId = $item->getData('item_id');

//get data from sales_flat_order_item table
$sales_order_item_id = Mage::getModel('sales/order_item')
->getCollection()
->addFieldToFilter('quote_item_id', $quote_itemId)
->getData('item_id');
//do more stuff here






Example sales_flat_order_item table:



sales_flat_order_item table










share|improve this question
























  • $sales_order_item_id = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('quote_item_id', $quote_itemId)->getItemId();

    – Aaditya
    Apr 22 at 18:44











  • Did already try that, but not working. Code stops dead, no log error, no exception.

    – Dan
    Apr 22 at 19:08













0












0








0








Using the sales_order_place_after event in my custom Observer.

I have the quote_item_id value (example 324).
How to get the corresponding item_id value from the sales_flat_order_item table?



I am able to successfully use getCollection method, but it returns the order item as an array.

($sales_order_item_id in below example)



How to get the string value? Eg 224 in example table

(in an efficient manner)



class Custom_Model_Observer 
public function booking(Varien_Event_Observer $observer)
$OrderId = $observer->getEvent()->getOrder()->getId(); //order entity id
$QuoteObject = Mage::getSingleton('checkout/session')->getQuote(); //quote object

foreach ($QuoteObject->getAllVisibleItems() as $item)

//get the quote item id - in example $quote_itemId = 324
$quote_itemId = $item->getData('item_id');

//get data from sales_flat_order_item table
$sales_order_item_id = Mage::getModel('sales/order_item')
->getCollection()
->addFieldToFilter('quote_item_id', $quote_itemId)
->getData('item_id');
//do more stuff here






Example sales_flat_order_item table:



sales_flat_order_item table










share|improve this question
















Using the sales_order_place_after event in my custom Observer.

I have the quote_item_id value (example 324).
How to get the corresponding item_id value from the sales_flat_order_item table?



I am able to successfully use getCollection method, but it returns the order item as an array.

($sales_order_item_id in below example)



How to get the string value? Eg 224 in example table

(in an efficient manner)



class Custom_Model_Observer 
public function booking(Varien_Event_Observer $observer)
$OrderId = $observer->getEvent()->getOrder()->getId(); //order entity id
$QuoteObject = Mage::getSingleton('checkout/session')->getQuote(); //quote object

foreach ($QuoteObject->getAllVisibleItems() as $item)

//get the quote item id - in example $quote_itemId = 324
$quote_itemId = $item->getData('item_id');

//get data from sales_flat_order_item table
$sales_order_item_id = Mage::getModel('sales/order_item')
->getCollection()
->addFieldToFilter('quote_item_id', $quote_itemId)
->getData('item_id');
//do more stuff here






Example sales_flat_order_item table:



sales_flat_order_item table







magento-1.9 collection sales-order quoteitem






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 22 at 18:26







Dan

















asked Apr 22 at 18:18









DanDan

176




176












  • $sales_order_item_id = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('quote_item_id', $quote_itemId)->getItemId();

    – Aaditya
    Apr 22 at 18:44











  • Did already try that, but not working. Code stops dead, no log error, no exception.

    – Dan
    Apr 22 at 19:08

















  • $sales_order_item_id = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('quote_item_id', $quote_itemId)->getItemId();

    – Aaditya
    Apr 22 at 18:44











  • Did already try that, but not working. Code stops dead, no log error, no exception.

    – Dan
    Apr 22 at 19:08
















$sales_order_item_id = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('quote_item_id', $quote_itemId)->getItemId();

– Aaditya
Apr 22 at 18:44





$sales_order_item_id = Mage::getModel('sales/order_item')->getCollection()->addFieldToFilter('quote_item_id', $quote_itemId)->getItemId();

– Aaditya
Apr 22 at 18:44













Did already try that, but not working. Code stops dead, no log error, no exception.

– Dan
Apr 22 at 19:08





Did already try that, but not working. Code stops dead, no log error, no exception.

– Dan
Apr 22 at 19:08










1 Answer
1






active

oldest

votes


















1














Normally you can iterate through the order item collection and get both - the item_id and the quote_item_id in one loop, like this



$order = $observer->getEvent()->getOrder();
foreach ($order->getAllVisibleItems() as $orderItem)
//quote_item_id
$orderItem->getQuoteItemId();
//item_id
$orderItem->getId();



But I'm not sure that there already exist the item_id in the event you are using, sales_order_place_after.
That id is available only after the order and the order items are saved in the database. The right event for accessing that data would be sales_order_save_after.






share|improve this answer























  • in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

    – Dan
    Apr 22 at 18:59












  • $orderItem->getId() is the order item id. $order->getId() would be the order id.

    – HelgeB
    Apr 22 at 19:03











  • I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

    – Dan
    Apr 23 at 17:55











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%2f270991%2fhow-to-get-value-from-sales-flat-order-item-table-using-quote-item-id%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









1














Normally you can iterate through the order item collection and get both - the item_id and the quote_item_id in one loop, like this



$order = $observer->getEvent()->getOrder();
foreach ($order->getAllVisibleItems() as $orderItem)
//quote_item_id
$orderItem->getQuoteItemId();
//item_id
$orderItem->getId();



But I'm not sure that there already exist the item_id in the event you are using, sales_order_place_after.
That id is available only after the order and the order items are saved in the database. The right event for accessing that data would be sales_order_save_after.






share|improve this answer























  • in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

    – Dan
    Apr 22 at 18:59












  • $orderItem->getId() is the order item id. $order->getId() would be the order id.

    – HelgeB
    Apr 22 at 19:03











  • I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

    – Dan
    Apr 23 at 17:55















1














Normally you can iterate through the order item collection and get both - the item_id and the quote_item_id in one loop, like this



$order = $observer->getEvent()->getOrder();
foreach ($order->getAllVisibleItems() as $orderItem)
//quote_item_id
$orderItem->getQuoteItemId();
//item_id
$orderItem->getId();



But I'm not sure that there already exist the item_id in the event you are using, sales_order_place_after.
That id is available only after the order and the order items are saved in the database. The right event for accessing that data would be sales_order_save_after.






share|improve this answer























  • in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

    – Dan
    Apr 22 at 18:59












  • $orderItem->getId() is the order item id. $order->getId() would be the order id.

    – HelgeB
    Apr 22 at 19:03











  • I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

    – Dan
    Apr 23 at 17:55













1












1








1







Normally you can iterate through the order item collection and get both - the item_id and the quote_item_id in one loop, like this



$order = $observer->getEvent()->getOrder();
foreach ($order->getAllVisibleItems() as $orderItem)
//quote_item_id
$orderItem->getQuoteItemId();
//item_id
$orderItem->getId();



But I'm not sure that there already exist the item_id in the event you are using, sales_order_place_after.
That id is available only after the order and the order items are saved in the database. The right event for accessing that data would be sales_order_save_after.






share|improve this answer













Normally you can iterate through the order item collection and get both - the item_id and the quote_item_id in one loop, like this



$order = $observer->getEvent()->getOrder();
foreach ($order->getAllVisibleItems() as $orderItem)
//quote_item_id
$orderItem->getQuoteItemId();
//item_id
$orderItem->getId();



But I'm not sure that there already exist the item_id in the event you are using, sales_order_place_after.
That id is available only after the order and the order items are saved in the database. The right event for accessing that data would be sales_order_save_after.







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 22 at 18:44









HelgeBHelgeB

3,4481423




3,4481423












  • in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

    – Dan
    Apr 22 at 18:59












  • $orderItem->getId() is the order item id. $order->getId() would be the order id.

    – HelgeB
    Apr 22 at 19:03











  • I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

    – Dan
    Apr 23 at 17:55

















  • in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

    – Dan
    Apr 22 at 18:59












  • $orderItem->getId() is the order item id. $order->getId() would be the order id.

    – HelgeB
    Apr 22 at 19:03











  • I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

    – Dan
    Apr 23 at 17:55
















in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

– Dan
Apr 22 at 18:59






in your example (using sales_order_save_after event), does $orderItem->getId(); get the order id, or the order item id? I was able to extract the 'item_id' by using $orderitem_id_value = $sales_order_item_id[0]['item_id']; from the array, but this seems so inefficient. I will test your suggestion.

– Dan
Apr 22 at 18:59














$orderItem->getId() is the order item id. $order->getId() would be the order id.

– HelgeB
Apr 22 at 19:03





$orderItem->getId() is the order item id. $order->getId() would be the order id.

– HelgeB
Apr 22 at 19:03













I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

– Dan
Apr 23 at 17:55





I'm not able to use both foreach without refactoring code (too much effort, too little time), and as my method is working, I will stick to it. Will up vote your useful suggestion. Let me know if you think deserves more credit etc.

– Dan
Apr 23 at 17:55

















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%2f270991%2fhow-to-get-value-from-sales-flat-order-item-table-using-quote-item-id%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