Get Quote ID from an Order ID or Order Number SQL?
-
13-12-2019 - |
Question
I need to query the Magento MySQL database to get an image path/name for a file.
What I have:
- Order ID
- Order Number
What I need:
- I need to get the image name/path from this table
sales_flat_quote_item_option
From what I can see so far following the foreign keys that lead to this table. I seem none of them use the order ID or order number as they all descend from the sales_flat_quote
table instead of the sales_flat_order
table.
Does anyone know of a fancy query I could use to get a value from the sales_flat_quote_item_option
table by using what I have, order ID and number?
If I can simply get the Quote ID
from my Order ID/Number then I can doing a join SQL query using the Quote ID to get my record from the sales_flat_quote_item_option
table.
I have to do this with SQL instead of Magento Models as it will be ran outside of Magento in a separate application.
Solution
There are only one relation between Magento quote item tables & sales order tables and that is sales_flat_order.quote_id=sales_flat_quote_item.quote_id.
In magento,sales_flat_quote_item_option
does not have any direct relation with sales_flat_order
.It have an indirection relation
sales_flat_order.quote_id=sales_flat_quote.quote_id
=> sales_flat_quote_item.item_id=sales_flat_quote_item_option.item_id
Query seem like:
SELECT * FROM sales_flat_quote_item_option where item_id in (
select item_id from sales_flat_quote_item where quote_id in (
SELECT quote_id FROM sales_flat_order where entity_id =ORDER_ID
)
)