SQL to get order items straight from the database?Get order items inside the order#1005 - Can't create table 'smartools.sales_flat_quote_item' (errno: -1)Get order data from database vs. using Mage functionsMagento 2: Get quantity item from the orderAdd property to AttributeSet class/databaseSimple products detached from configurabe products after importsql query to get Products price, sku, product_id, description and url to picturePicking items from the magento databaseMagento 1.9 Import Product with CSV but with Dynamic Product namesMagento 2 - Dimensional Weight Confusion

Why is this code 6.5x slower with optimizations enabled?

N.B. ligature in Latex

Why is "Reports" in sentence down without "The"

A Journey Through Space and Time

What is the command to reset a PC without deleting any files

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

When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?

Concept of linear mappings are confusing me

Circuitry of TV splitters

How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?

Does the radius of the Spirit Guardians spell depend on the size of the caster?

How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?

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

XeLaTeX and pdfLaTeX ignore hyphenation

What do you call something that goes against the spirit of the law, but is legal when interpreting the law to the letter?

Is there a familial term for apples and pears?

Extreme, but not acceptable situation and I can't start the work tomorrow morning

What would happen to a modern skyscraper if it rains micro blackholes?

Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?

How can bays and straits be determined in a procedurally generated map?

If Manufacturer spice model and Datasheet give different values which should I use?

how to create a data type and make it available in all Databases?

I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine

Why was the small council so happy for Tyrion to become the Master of Coin?



SQL to get order items straight from the database?


Get order items inside the order#1005 - Can't create table 'smartools.sales_flat_quote_item' (errno: -1)Get order data from database vs. using Mage functionsMagento 2: Get quantity item from the orderAdd property to AttributeSet class/databaseSimple products detached from configurabe products after importsql query to get Products price, sku, product_id, description and url to picturePicking items from the magento databaseMagento 1.9 Import Product with CSV but with Dynamic Product namesMagento 2 - Dimensional Weight Confusion






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








5















How do we get a list of order items and their data (name, sku, quantity, price, weight, and dimensions)? Without using Magento's own framework components.



The problem is if the order contains 5 products I would get maybe 7 items from querying the table. This is caused by the different product types (simple, group, voucher, configurable, etc.) and different product ids so cannot be combined.



$items = array();

$sql = (
"SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM $db->prefixsales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id .";"
);

if ($result = $mysqli->query($sql))

while ($row = $result->fetch_assoc())

$items[] = [
'name' => $row['name'],
'sku' => $row['sku'],
'quantity' => (float)$row['qty_ordered'],
'unit_price' => (float)$row['price'],
'unit_weight' => (float)$row['weight'],
//'unit_length' => (float)$row['length'], // Not present?
//'unit_width' => (float)$row['width'], // Not present?
//'unit_height' => (float)$row['height'], // Not present?
];


$result->close();



If I pass a filter AND product_type = 'simple' to get only the simple products, they do not contain price.










share|improve this question
















bumped to the homepage by Community 54 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Have you tried using "JOIN" query?

    – Chintan Kaneriya
    Sep 25 '18 at 3:55











  • Have you got the solution ? If not the i have it.

    – Aaditya
    Sep 27 '18 at 5:55











  • No not yet. I think a little PHP logic could be needed to distinguish simple products from configurable+simple products. It's like configurable snd group are parents of the sinple items. But price weight etc is a bit spread over them. One holds this, the other holds that.

    – tim
    Sep 28 '18 at 23:17

















5















How do we get a list of order items and their data (name, sku, quantity, price, weight, and dimensions)? Without using Magento's own framework components.



The problem is if the order contains 5 products I would get maybe 7 items from querying the table. This is caused by the different product types (simple, group, voucher, configurable, etc.) and different product ids so cannot be combined.



$items = array();

$sql = (
"SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM $db->prefixsales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id .";"
);

if ($result = $mysqli->query($sql))

while ($row = $result->fetch_assoc())

$items[] = [
'name' => $row['name'],
'sku' => $row['sku'],
'quantity' => (float)$row['qty_ordered'],
'unit_price' => (float)$row['price'],
'unit_weight' => (float)$row['weight'],
//'unit_length' => (float)$row['length'], // Not present?
//'unit_width' => (float)$row['width'], // Not present?
//'unit_height' => (float)$row['height'], // Not present?
];


$result->close();



If I pass a filter AND product_type = 'simple' to get only the simple products, they do not contain price.










share|improve this question
















bumped to the homepage by Community 54 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • Have you tried using "JOIN" query?

    – Chintan Kaneriya
    Sep 25 '18 at 3:55











  • Have you got the solution ? If not the i have it.

    – Aaditya
    Sep 27 '18 at 5:55











  • No not yet. I think a little PHP logic could be needed to distinguish simple products from configurable+simple products. It's like configurable snd group are parents of the sinple items. But price weight etc is a bit spread over them. One holds this, the other holds that.

    – tim
    Sep 28 '18 at 23:17













5












5








5


1






How do we get a list of order items and their data (name, sku, quantity, price, weight, and dimensions)? Without using Magento's own framework components.



The problem is if the order contains 5 products I would get maybe 7 items from querying the table. This is caused by the different product types (simple, group, voucher, configurable, etc.) and different product ids so cannot be combined.



$items = array();

$sql = (
"SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM $db->prefixsales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id .";"
);

if ($result = $mysqli->query($sql))

while ($row = $result->fetch_assoc())

$items[] = [
'name' => $row['name'],
'sku' => $row['sku'],
'quantity' => (float)$row['qty_ordered'],
'unit_price' => (float)$row['price'],
'unit_weight' => (float)$row['weight'],
//'unit_length' => (float)$row['length'], // Not present?
//'unit_width' => (float)$row['width'], // Not present?
//'unit_height' => (float)$row['height'], // Not present?
];


$result->close();



If I pass a filter AND product_type = 'simple' to get only the simple products, they do not contain price.










share|improve this question
















How do we get a list of order items and their data (name, sku, quantity, price, weight, and dimensions)? Without using Magento's own framework components.



The problem is if the order contains 5 products I would get maybe 7 items from querying the table. This is caused by the different product types (simple, group, voucher, configurable, etc.) and different product ids so cannot be combined.



$items = array();

$sql = (
"SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM $db->prefixsales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id .";"
);

if ($result = $mysqli->query($sql))

while ($row = $result->fetch_assoc())

$items[] = [
'name' => $row['name'],
'sku' => $row['sku'],
'quantity' => (float)$row['qty_ordered'],
'unit_price' => (float)$row['price'],
'unit_weight' => (float)$row['weight'],
//'unit_length' => (float)$row['length'], // Not present?
//'unit_width' => (float)$row['width'], // Not present?
//'unit_height' => (float)$row['height'], // Not present?
];


$result->close();



If I pass a filter AND product_type = 'simple' to get only the simple products, they do not contain price.







magento2 magento-1.9 database orders






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 28 '18 at 23:20







tim

















asked Sep 22 '18 at 23:45









timtim

263




263





bumped to the homepage by Community 54 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 54 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • Have you tried using "JOIN" query?

    – Chintan Kaneriya
    Sep 25 '18 at 3:55











  • Have you got the solution ? If not the i have it.

    – Aaditya
    Sep 27 '18 at 5:55











  • No not yet. I think a little PHP logic could be needed to distinguish simple products from configurable+simple products. It's like configurable snd group are parents of the sinple items. But price weight etc is a bit spread over them. One holds this, the other holds that.

    – tim
    Sep 28 '18 at 23:17

















  • Have you tried using "JOIN" query?

    – Chintan Kaneriya
    Sep 25 '18 at 3:55











  • Have you got the solution ? If not the i have it.

    – Aaditya
    Sep 27 '18 at 5:55











  • No not yet. I think a little PHP logic could be needed to distinguish simple products from configurable+simple products. It's like configurable snd group are parents of the sinple items. But price weight etc is a bit spread over them. One holds this, the other holds that.

    – tim
    Sep 28 '18 at 23:17
















Have you tried using "JOIN" query?

– Chintan Kaneriya
Sep 25 '18 at 3:55





Have you tried using "JOIN" query?

– Chintan Kaneriya
Sep 25 '18 at 3:55













Have you got the solution ? If not the i have it.

– Aaditya
Sep 27 '18 at 5:55





Have you got the solution ? If not the i have it.

– Aaditya
Sep 27 '18 at 5:55













No not yet. I think a little PHP logic could be needed to distinguish simple products from configurable+simple products. It's like configurable snd group are parents of the sinple items. But price weight etc is a bit spread over them. One holds this, the other holds that.

– tim
Sep 28 '18 at 23:17





No not yet. I think a little PHP logic could be needed to distinguish simple products from configurable+simple products. It's like configurable snd group are parents of the sinple items. But price weight etc is a bit spread over them. One holds this, the other holds that.

– tim
Sep 28 '18 at 23:17










4 Answers
4






active

oldest

votes


















0














how about with this query, I try joined your query with catalog_product_entity and catalog_product_index_price tables, so you will get all products with contain price :



SELECT DISTINCT oi.name, oi.sku, oi.qty_ordered, oi.weight, 
`idx_price`.`price`
FROM sales_flat_order_item AS oi
INNER JOIN `catalog_product_entity` AS `cpe` ON oi.sku = cpe.sku
INNER JOIN `catalog_product_index_price` AS `idx_price` ON idx_price.entity_id = cpe.entity_id
WHERE oi.order_id = <order_id>


then you can add the product_type filtering on the end query like this :



AND oi.product_type = 'configurable'


or



AND oi.product_type = 'simple'


hope this can help






share|improve this answer























  • Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

    – tim
    Sep 25 '18 at 14:03











  • yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

    – mrfizh
    Sep 26 '18 at 3:42


















0














If you have the configuration setting for Catalog->Frontend->Use Flat Catalog Product set to ON, you can join the sales_flat_order_item table to catalog_product_flat_[#]. If you only have one (catalog_product_flat_1), that is fairly easy, but it can still be done with more if you use a Union



For one flat product table:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
join catalog_product_flat_1 flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


For multiple flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
JOIN (
select entity_id, width, height, length from catalog_product_flat_1
UNION DISTINCT
select entity_id, width, height, length from catalog_product_flat_2
/*
REPEAT 2 LINES ABOVE FOR catalog_product_flat_3, catalog_product_flat_4, etc
*/
) flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


EDIT



This will accomplish the same goal regardless of whether you are using flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
w.value 'width',
h.value 'height',
l.value 'length'
FROM sales_flat_order_item oi
JOIN catalog_product_entity_decimal w
ON oi.product_id = w.entity_id
JOIN catalog_product_entity_decimal h
ON oi.product_id = h.entity_id
JOIN catalog_product_entity_decimal l
ON oi.product_id = l.entity_id
WHERE oi.order_id = <order_id>
AND w.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'width'
)
AND h.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'height'
)
AND l.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'length'
);





share|improve this answer

























  • Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

    – tim
    Sep 28 '18 at 23:12











  • @tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

    – mtr.web
    Oct 1 '18 at 19:07



















0















 SELECT 
CONCAT(address.firstname,' ',
address.lastname) AS Name,
address.email AS Email,
items.created_at AS Date,
items.name AS Description,
items.store_id AS Logon,
items.name AS Category,
items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode,
items.order_id AS Orderref
FROM sales_flat_order AS orders
JOIN sales_flat_order_item AS items
ON items.order_id = orders.entity_id
LEFT JOIN sales_flat_order_address AS address
ON orders.entity_id = address.parent_id
WHERE
items .created_at BETWEEN '2014-04-15 00:00:00' AND '2014-07-30
00:00:00' AND orders.status = 'complete'



Also you can add AND orders.status in ('processing', 'complete') depending upon your requirement.






share|improve this answer























  • I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

    – tim
    Sep 28 '18 at 23:06


















0














its simple, use group by will give you your results:



 "SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM sales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id . " group by sku ;"


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
enter image description here






share|improve this answer

























  • And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

    – tim
    Sep 28 '18 at 23:08











  • price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

    – Hassan Ali Shahzad
    Sep 29 '18 at 21:31











  • I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

    – Hassan Ali Shahzad
    Sep 30 '18 at 17:05











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%2f243378%2fsql-to-get-order-items-straight-from-the-database%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














how about with this query, I try joined your query with catalog_product_entity and catalog_product_index_price tables, so you will get all products with contain price :



SELECT DISTINCT oi.name, oi.sku, oi.qty_ordered, oi.weight, 
`idx_price`.`price`
FROM sales_flat_order_item AS oi
INNER JOIN `catalog_product_entity` AS `cpe` ON oi.sku = cpe.sku
INNER JOIN `catalog_product_index_price` AS `idx_price` ON idx_price.entity_id = cpe.entity_id
WHERE oi.order_id = <order_id>


then you can add the product_type filtering on the end query like this :



AND oi.product_type = 'configurable'


or



AND oi.product_type = 'simple'


hope this can help






share|improve this answer























  • Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

    – tim
    Sep 25 '18 at 14:03











  • yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

    – mrfizh
    Sep 26 '18 at 3:42















0














how about with this query, I try joined your query with catalog_product_entity and catalog_product_index_price tables, so you will get all products with contain price :



SELECT DISTINCT oi.name, oi.sku, oi.qty_ordered, oi.weight, 
`idx_price`.`price`
FROM sales_flat_order_item AS oi
INNER JOIN `catalog_product_entity` AS `cpe` ON oi.sku = cpe.sku
INNER JOIN `catalog_product_index_price` AS `idx_price` ON idx_price.entity_id = cpe.entity_id
WHERE oi.order_id = <order_id>


then you can add the product_type filtering on the end query like this :



AND oi.product_type = 'configurable'


or



AND oi.product_type = 'simple'


hope this can help






share|improve this answer























  • Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

    – tim
    Sep 25 '18 at 14:03











  • yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

    – mrfizh
    Sep 26 '18 at 3:42













0












0








0







how about with this query, I try joined your query with catalog_product_entity and catalog_product_index_price tables, so you will get all products with contain price :



SELECT DISTINCT oi.name, oi.sku, oi.qty_ordered, oi.weight, 
`idx_price`.`price`
FROM sales_flat_order_item AS oi
INNER JOIN `catalog_product_entity` AS `cpe` ON oi.sku = cpe.sku
INNER JOIN `catalog_product_index_price` AS `idx_price` ON idx_price.entity_id = cpe.entity_id
WHERE oi.order_id = <order_id>


then you can add the product_type filtering on the end query like this :



AND oi.product_type = 'configurable'


or



AND oi.product_type = 'simple'


hope this can help






share|improve this answer













how about with this query, I try joined your query with catalog_product_entity and catalog_product_index_price tables, so you will get all products with contain price :



SELECT DISTINCT oi.name, oi.sku, oi.qty_ordered, oi.weight, 
`idx_price`.`price`
FROM sales_flat_order_item AS oi
INNER JOIN `catalog_product_entity` AS `cpe` ON oi.sku = cpe.sku
INNER JOIN `catalog_product_index_price` AS `idx_price` ON idx_price.entity_id = cpe.entity_id
WHERE oi.order_id = <order_id>


then you can add the product_type filtering on the end query like this :



AND oi.product_type = 'configurable'


or



AND oi.product_type = 'simple'


hope this can help







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 25 '18 at 10:15









mrfizhmrfizh

8482723




8482723












  • Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

    – tim
    Sep 25 '18 at 14:03











  • yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

    – mrfizh
    Sep 26 '18 at 3:42

















  • Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

    – tim
    Sep 25 '18 at 14:03











  • yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

    – mrfizh
    Sep 26 '18 at 3:42
















Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

– tim
Sep 25 '18 at 14:03





Price is already present in sales_flat_order_item.price so I would be asking for trouble if I grab that from the products table. The only thing I can't find in sales_flat_order_item are dimensions.

– tim
Sep 25 '18 at 14:03













yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

– mrfizh
Sep 26 '18 at 3:42





yes you will get trouble if your product included in catalog promotions or customer using voucher discount, it will cause actual price in the sales_flat_order_item will be different with catalog_product_index_price

– mrfizh
Sep 26 '18 at 3:42













0














If you have the configuration setting for Catalog->Frontend->Use Flat Catalog Product set to ON, you can join the sales_flat_order_item table to catalog_product_flat_[#]. If you only have one (catalog_product_flat_1), that is fairly easy, but it can still be done with more if you use a Union



For one flat product table:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
join catalog_product_flat_1 flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


For multiple flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
JOIN (
select entity_id, width, height, length from catalog_product_flat_1
UNION DISTINCT
select entity_id, width, height, length from catalog_product_flat_2
/*
REPEAT 2 LINES ABOVE FOR catalog_product_flat_3, catalog_product_flat_4, etc
*/
) flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


EDIT



This will accomplish the same goal regardless of whether you are using flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
w.value 'width',
h.value 'height',
l.value 'length'
FROM sales_flat_order_item oi
JOIN catalog_product_entity_decimal w
ON oi.product_id = w.entity_id
JOIN catalog_product_entity_decimal h
ON oi.product_id = h.entity_id
JOIN catalog_product_entity_decimal l
ON oi.product_id = l.entity_id
WHERE oi.order_id = <order_id>
AND w.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'width'
)
AND h.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'height'
)
AND l.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'length'
);





share|improve this answer

























  • Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

    – tim
    Sep 28 '18 at 23:12











  • @tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

    – mtr.web
    Oct 1 '18 at 19:07
















0














If you have the configuration setting for Catalog->Frontend->Use Flat Catalog Product set to ON, you can join the sales_flat_order_item table to catalog_product_flat_[#]. If you only have one (catalog_product_flat_1), that is fairly easy, but it can still be done with more if you use a Union



For one flat product table:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
join catalog_product_flat_1 flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


For multiple flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
JOIN (
select entity_id, width, height, length from catalog_product_flat_1
UNION DISTINCT
select entity_id, width, height, length from catalog_product_flat_2
/*
REPEAT 2 LINES ABOVE FOR catalog_product_flat_3, catalog_product_flat_4, etc
*/
) flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


EDIT



This will accomplish the same goal regardless of whether you are using flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
w.value 'width',
h.value 'height',
l.value 'length'
FROM sales_flat_order_item oi
JOIN catalog_product_entity_decimal w
ON oi.product_id = w.entity_id
JOIN catalog_product_entity_decimal h
ON oi.product_id = h.entity_id
JOIN catalog_product_entity_decimal l
ON oi.product_id = l.entity_id
WHERE oi.order_id = <order_id>
AND w.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'width'
)
AND h.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'height'
)
AND l.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'length'
);





share|improve this answer

























  • Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

    – tim
    Sep 28 '18 at 23:12











  • @tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

    – mtr.web
    Oct 1 '18 at 19:07














0












0








0







If you have the configuration setting for Catalog->Frontend->Use Flat Catalog Product set to ON, you can join the sales_flat_order_item table to catalog_product_flat_[#]. If you only have one (catalog_product_flat_1), that is fairly easy, but it can still be done with more if you use a Union



For one flat product table:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
join catalog_product_flat_1 flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


For multiple flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
JOIN (
select entity_id, width, height, length from catalog_product_flat_1
UNION DISTINCT
select entity_id, width, height, length from catalog_product_flat_2
/*
REPEAT 2 LINES ABOVE FOR catalog_product_flat_3, catalog_product_flat_4, etc
*/
) flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


EDIT



This will accomplish the same goal regardless of whether you are using flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
w.value 'width',
h.value 'height',
l.value 'length'
FROM sales_flat_order_item oi
JOIN catalog_product_entity_decimal w
ON oi.product_id = w.entity_id
JOIN catalog_product_entity_decimal h
ON oi.product_id = h.entity_id
JOIN catalog_product_entity_decimal l
ON oi.product_id = l.entity_id
WHERE oi.order_id = <order_id>
AND w.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'width'
)
AND h.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'height'
)
AND l.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'length'
);





share|improve this answer















If you have the configuration setting for Catalog->Frontend->Use Flat Catalog Product set to ON, you can join the sales_flat_order_item table to catalog_product_flat_[#]. If you only have one (catalog_product_flat_1), that is fairly easy, but it can still be done with more if you use a Union



For one flat product table:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
join catalog_product_flat_1 flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


For multiple flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
flat.width,
flat.height,
flat.length
FROM sales_flat_order_item oi
JOIN (
select entity_id, width, height, length from catalog_product_flat_1
UNION DISTINCT
select entity_id, width, height, length from catalog_product_flat_2
/*
REPEAT 2 LINES ABOVE FOR catalog_product_flat_3, catalog_product_flat_4, etc
*/
) flat
on oi.product_id = flat.entity_id
WHERE oi.order_id = <order_id>;


EDIT



This will accomplish the same goal regardless of whether you are using flat product tables:



SELECT 
oi.name,
oi.sku,
oi.qty_ordered,
oi.price,
oi.weight,
w.value 'width',
h.value 'height',
l.value 'length'
FROM sales_flat_order_item oi
JOIN catalog_product_entity_decimal w
ON oi.product_id = w.entity_id
JOIN catalog_product_entity_decimal h
ON oi.product_id = h.entity_id
JOIN catalog_product_entity_decimal l
ON oi.product_id = l.entity_id
WHERE oi.order_id = <order_id>
AND w.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'width'
)
AND h.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'height'
)
AND l.attribute_id = (
select attribute_id from eav_attribute
where entity_type_id = 4
and attribute_code = 'length'
);






share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 27 '18 at 13:41

























answered Sep 27 '18 at 13:33









mtr.webmtr.web

758516




758516












  • Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

    – tim
    Sep 28 '18 at 23:12











  • @tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

    – mtr.web
    Oct 1 '18 at 19:07


















  • Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

    – tim
    Sep 28 '18 at 23:12











  • @tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

    – mtr.web
    Oct 1 '18 at 19:07

















Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

– tim
Sep 28 '18 at 23:12





Thank for your efforts trying. How will this distinguish what is a simple product or simple+configurable? Where it occurs multiple times in the table.

– tim
Sep 28 '18 at 23:12













@tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

– mtr.web
Oct 1 '18 at 19:07






@tim these should all be specific to the actual item used, but yes, the configurable and simple product will both be listed. If you want the child-product's sku and dimensions as configured simply add AND oi.product_type <> 'configurable' to any of these. If you prefer to see the parent-product, add AND oi.parent_item_id is null. If this solves it for you, let me know which one and I will update my answer.

– mtr.web
Oct 1 '18 at 19:07












0















 SELECT 
CONCAT(address.firstname,' ',
address.lastname) AS Name,
address.email AS Email,
items.created_at AS Date,
items.name AS Description,
items.store_id AS Logon,
items.name AS Category,
items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode,
items.order_id AS Orderref
FROM sales_flat_order AS orders
JOIN sales_flat_order_item AS items
ON items.order_id = orders.entity_id
LEFT JOIN sales_flat_order_address AS address
ON orders.entity_id = address.parent_id
WHERE
items .created_at BETWEEN '2014-04-15 00:00:00' AND '2014-07-30
00:00:00' AND orders.status = 'complete'



Also you can add AND orders.status in ('processing', 'complete') depending upon your requirement.






share|improve this answer























  • I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

    – tim
    Sep 28 '18 at 23:06















0















 SELECT 
CONCAT(address.firstname,' ',
address.lastname) AS Name,
address.email AS Email,
items.created_at AS Date,
items.name AS Description,
items.store_id AS Logon,
items.name AS Category,
items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode,
items.order_id AS Orderref
FROM sales_flat_order AS orders
JOIN sales_flat_order_item AS items
ON items.order_id = orders.entity_id
LEFT JOIN sales_flat_order_address AS address
ON orders.entity_id = address.parent_id
WHERE
items .created_at BETWEEN '2014-04-15 00:00:00' AND '2014-07-30
00:00:00' AND orders.status = 'complete'



Also you can add AND orders.status in ('processing', 'complete') depending upon your requirement.






share|improve this answer























  • I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

    – tim
    Sep 28 '18 at 23:06













0












0








0








 SELECT 
CONCAT(address.firstname,' ',
address.lastname) AS Name,
address.email AS Email,
items.created_at AS Date,
items.name AS Description,
items.store_id AS Logon,
items.name AS Category,
items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode,
items.order_id AS Orderref
FROM sales_flat_order AS orders
JOIN sales_flat_order_item AS items
ON items.order_id = orders.entity_id
LEFT JOIN sales_flat_order_address AS address
ON orders.entity_id = address.parent_id
WHERE
items .created_at BETWEEN '2014-04-15 00:00:00' AND '2014-07-30
00:00:00' AND orders.status = 'complete'



Also you can add AND orders.status in ('processing', 'complete') depending upon your requirement.






share|improve this answer














 SELECT 
CONCAT(address.firstname,' ',
address.lastname) AS Name,
address.email AS Email,
items.created_at AS Date,
items.name AS Description,
items.store_id AS Logon,
items.name AS Category,
items.store_id AS FeedbackDate,
items.sku AS ProductSearchcode,
items.order_id AS Orderref
FROM sales_flat_order AS orders
JOIN sales_flat_order_item AS items
ON items.order_id = orders.entity_id
LEFT JOIN sales_flat_order_address AS address
ON orders.entity_id = address.parent_id
WHERE
items .created_at BETWEEN '2014-04-15 00:00:00' AND '2014-07-30
00:00:00' AND orders.status = 'complete'



Also you can add AND orders.status in ('processing', 'complete') depending upon your requirement.







share|improve this answer












share|improve this answer



share|improve this answer










answered Sep 27 '18 at 13:42









P RamuluP Ramulu

7617




7617












  • I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

    – tim
    Sep 28 '18 at 23:06

















  • I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

    – tim
    Sep 28 '18 at 23:06
















I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

– tim
Sep 28 '18 at 23:06





I think you confused Item Name with customer name. This doesn't sort out the problem where a simple product also is present in a group or configurable product, so there will be duplicate rows for the same item. I just need to acess sales_flar_order_item and extract the items without dupes.

– tim
Sep 28 '18 at 23:06











0














its simple, use group by will give you your results:



 "SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM sales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id . " group by sku ;"


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
enter image description here






share|improve this answer

























  • And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

    – tim
    Sep 28 '18 at 23:08











  • price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

    – Hassan Ali Shahzad
    Sep 29 '18 at 21:31











  • I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

    – Hassan Ali Shahzad
    Sep 30 '18 at 17:05















0














its simple, use group by will give you your results:



 "SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM sales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id . " group by sku ;"


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
enter image description here






share|improve this answer

























  • And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

    – tim
    Sep 28 '18 at 23:08











  • price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

    – Hassan Ali Shahzad
    Sep 29 '18 at 21:31











  • I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

    – Hassan Ali Shahzad
    Sep 30 '18 at 17:05













0












0








0







its simple, use group by will give you your results:



 "SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM sales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id . " group by sku ;"


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
enter image description here






share|improve this answer















its simple, use group by will give you your results:



 "SELECT oi.name, oi.sku, oi.qty_ordered, oi.price, oi.weight
FROM sales_flat_order_item oi
WHERE oi.order_id = ". (int)$order_entity_id . " group by sku ;"


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 29 '18 at 21:28

























answered Sep 27 '18 at 14:20









Hassan Ali ShahzadHassan Ali Shahzad

655317




655317












  • And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

    – tim
    Sep 28 '18 at 23:08











  • price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

    – Hassan Ali Shahzad
    Sep 29 '18 at 21:31











  • I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

    – Hassan Ali Shahzad
    Sep 30 '18 at 17:05

















  • And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

    – tim
    Sep 28 '18 at 23:08











  • price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

    – Hassan Ali Shahzad
    Sep 29 '18 at 21:31











  • I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

    – Hassan Ali Shahzad
    Sep 30 '18 at 17:05
















And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

– tim
Sep 28 '18 at 23:08





And how will they be grouped when the price is in configurable but the quantity in simple. See the product_type column.

– tim
Sep 28 '18 at 23:08













price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

– Hassan Ali Shahzad
Sep 29 '18 at 21:31





price and qty always be in configurable. if 2qty selected for any of child product. 2 will also the configurable quantity., and present in above query. look at above image attached. Let me know if you still have any questions

– Hassan Ali Shahzad
Sep 29 '18 at 21:31













I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

– Hassan Ali Shahzad
Sep 30 '18 at 17:05





I case of simple product added as stand alone product this will work properly as well. in that case price & qty will be for that simple product.

– Hassan Ali Shahzad
Sep 30 '18 at 17:05

















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%2f243378%2fsql-to-get-order-items-straight-from-the-database%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

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