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
How old can references or sources in a thesis be?
least quadratic residue under GRH: an EXPLICIT bound
How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)
When blogging recipes, how can I support both readers who want the narrative/journey and ones who want the printer-friendly recipe?
How is the relation "the smallest element is the same" reflexive?
Patience, young "Padovan"
Concept of linear mappings are confusing me
Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)
Motorized valve interfering with button?
New order #4: World
Is it possible to make sharp wind that can cut stuff from afar?
Infinite past with a beginning?
What do you call a Matrix-like slowdown and camera movement effect?
I’m planning on buying a laser printer but concerned about the life cycle of toner in the machine
My colleague's body is amazing
Circuitry of TV splitters
Why was the small council so happy for Tyrion to become the Master of Coin?
Copycat chess is back
What is the command to reset a PC without deleting any files
What is the white spray-pattern residue inside these Falcon Heavy nozzles?
Is there a familial term for apples and pears?
Schwarzchild Radius of the Universe
Draw simple lines in Inkscape
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
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;
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
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
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
bumped to the homepage by Community♦ 15 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
add a comment |
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
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
magento2 magento-1.9 database orders
edited Sep 28 '18 at 23:20
tim
asked Sep 22 '18 at 23:45
timtim
263
263
bumped to the homepage by Community♦ 15 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♦ 15 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
add a comment |
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
add a comment |
4 Answers
4
active
oldest
votes
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
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 thesales_flat_order_item
will be different withcatalog_product_index_price
– mrfizh
Sep 26 '18 at 3:42
add a comment |
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'
);
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 addAND oi.product_type <> 'configurable'
to any of these. If you prefer to see the parent-product, addAND 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
add a comment |
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.
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
add a comment |
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 ;"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 thesales_flat_order_item
will be different withcatalog_product_index_price
– mrfizh
Sep 26 '18 at 3:42
add a comment |
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
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 thesales_flat_order_item
will be different withcatalog_product_index_price
– mrfizh
Sep 26 '18 at 3:42
add a comment |
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
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
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 thesales_flat_order_item
will be different withcatalog_product_index_price
– mrfizh
Sep 26 '18 at 3:42
add a comment |
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 thesales_flat_order_item
will be different withcatalog_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
add a comment |
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'
);
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 addAND oi.product_type <> 'configurable'
to any of these. If you prefer to see the parent-product, addAND 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
add a comment |
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'
);
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 addAND oi.product_type <> 'configurable'
to any of these. If you prefer to see the parent-product, addAND 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
add a comment |
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'
);
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'
);
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 addAND oi.product_type <> 'configurable'
to any of these. If you prefer to see the parent-product, addAND 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
add a comment |
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 addAND oi.product_type <> 'configurable'
to any of these. If you prefer to see the parent-product, addAND 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
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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 ;"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
add a comment |
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 ;"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
add a comment |
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 ;"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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 ;"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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