In Magento2, how to get the product description from Sales order tableExport from the database brand, quantity and size/color varchar: MySQL & EEHow to customize admin sales order grid collection?Querying a table using data from another tablemagento2 Item (MagentoSalesModelOrder) with the same id “x” already existWritting SQL query to remove product description from database tableGet Sku, Name and Description Joined With 'Value' from `catalog_product_entity_media_gallery`Add column in sales order grid table in magento2Join a calculated column from a table to a collectionSQL to get order items straight from the database?Magento2 remove columns from admin sales order view page items grid
Implement Own Vector Class in C++
Were Alexander the Great and Hephaestion lovers?
Is an entry level DSLR going to shoot nice portrait pictures?
Soft question: Examples where lack of mathematical rigour cause security breaches?
is it possible for a vehicle to be manufactured witout a catalitic converter
How to produce a more sophisticated pie chart?
How to handle self harm scars on the arm in work environment?
What is the actual quality of machine translations?
You have (3^2 + 2^3 + 2^2) Guesses Left. Figure out the Last one
How can I end combat quickly when the outcome is inevitable?
Arriving at the same result with the opposite hypotheses
Is using haveibeenpwned to validate password strength rational?
What speaks against investing in precious metals?
English word for "product of tinkering"
Should I give professor gift at the beginning of my PhD?
Jargon request: "Canonical Form" of a word
How does an ordinary object become radioactive?
Mathematically, why does mass matrix / load vector lumping work?
Why are trash cans referred to as "zafacón" in Puerto Rico?
Cascading Switches. Will it affect performance?
How to communicate to my GM that not being allowed to use stealth isn't fun for me?
Playing a Character as Unobtrusive and Subservient, Yet Not Passive
Colloquialism for “see you later”
Extreme flexible working hours: how to control people and activities?
In Magento2, how to get the product description from Sales order table
Export from the database brand, quantity and size/color varchar: MySQL & EEHow to customize admin sales order grid collection?Querying a table using data from another tablemagento2 Item (MagentoSalesModelOrder) with the same id “x” already existWritting SQL query to remove product description from database tableGet Sku, Name and Description Joined With 'Value' from `catalog_product_entity_media_gallery`Add column in sales order grid table in magento2Join a calculated column from a table to a collectionSQL to get order items straight from the database?Magento2 remove columns from admin sales order view page items grid
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I want to display the order id, item description, sku and price of products from the sales order and sales order item tables. For some reason, the description columns in my sales order item table is null. So I want to retrieve the description from the catalog product table by joining it to the sales order or sales order item table. Anyone know the query for that ?
magento2 magento-2.1 database
add a comment |
I want to display the order id, item description, sku and price of products from the sales order and sales order item tables. For some reason, the description columns in my sales order item table is null. So I want to retrieve the description from the catalog product table by joining it to the sales order or sales order item table. Anyone know the query for that ?
magento2 magento-2.1 database
Display where? Within admin?
– Dominic Xigen
May 31 at 10:55
I need to write it in to a csv file. My requirement is such that I want to join tables
– MGento
May 31 at 12:24
Build an array. Write the array to CSV. magestore.com/magento-2-tutorial/…
– Dominic Xigen
May 31 at 13:10
add a comment |
I want to display the order id, item description, sku and price of products from the sales order and sales order item tables. For some reason, the description columns in my sales order item table is null. So I want to retrieve the description from the catalog product table by joining it to the sales order or sales order item table. Anyone know the query for that ?
magento2 magento-2.1 database
I want to display the order id, item description, sku and price of products from the sales order and sales order item tables. For some reason, the description columns in my sales order item table is null. So I want to retrieve the description from the catalog product table by joining it to the sales order or sales order item table. Anyone know the query for that ?
magento2 magento-2.1 database
magento2 magento-2.1 database
edited May 31 at 12:25
MGento
asked May 31 at 10:32
MGentoMGento
1,268319
1,268319
Display where? Within admin?
– Dominic Xigen
May 31 at 10:55
I need to write it in to a csv file. My requirement is such that I want to join tables
– MGento
May 31 at 12:24
Build an array. Write the array to CSV. magestore.com/magento-2-tutorial/…
– Dominic Xigen
May 31 at 13:10
add a comment |
Display where? Within admin?
– Dominic Xigen
May 31 at 10:55
I need to write it in to a csv file. My requirement is such that I want to join tables
– MGento
May 31 at 12:24
Build an array. Write the array to CSV. magestore.com/magento-2-tutorial/…
– Dominic Xigen
May 31 at 13:10
Display where? Within admin?
– Dominic Xigen
May 31 at 10:55
Display where? Within admin?
– Dominic Xigen
May 31 at 10:55
I need to write it in to a csv file. My requirement is such that I want to join tables
– MGento
May 31 at 12:24
I need to write it in to a csv file. My requirement is such that I want to join tables
– MGento
May 31 at 12:24
Build an array. Write the array to CSV. magestore.com/magento-2-tutorial/…
– Dominic Xigen
May 31 at 13:10
Build an array. Write the array to CSV. magestore.com/magento-2-tutorial/…
– Dominic Xigen
May 31 at 13:10
add a comment |
3 Answers
3
active
oldest
votes
If you are making changes to the frotnend. Not great but easiest way I can think of doing it is loading product by id inside the loop
foreach ($_order->getAllVisibleItems() as $_item)
echo $_item->getProductId();
Then using standard load
$productRepository;
public function __construct(
Context $context,
MagentoCatalogApiProductRepositoryInterface $productRepositoryInterface
// ...
)
$this->productRepository = $productRepositoryInterface;
// ....
try
$product = $productRepository->getById(1234);
// got description here
catch (MagentoFrameworkExceptionNoSuchEntityException $e)
Reason to go against the join is that you would have to join sales_order_item soi, catalog_product_entity_text cpet where cpet.entity_id = soi.product_id.
But then filter by cpet.attribute_id = 75 (for my install) and cpet.store_id = 0
Hardcoded IDs is never great. You can work out those IDs with additional lookups but already you see this is turning into a larger task.
If this is for the backend maybe this changes things a little.
add a comment |
Using
MagentoCatalogModelProductRepository you get product descriptionlike below
public function __construct(MagentoCatalogModelProductRepository $productRepository)
$this->$productRepository=$productRepository;
public function customMethod()
$sku=//get from order object;
$product=$this->$productRepository->get($sku);
$product->getDescription();
**Note:**if you are using magento's older version where may be ProductRepository class not exits so you need to get product from Product Model
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
add a comment |
I'm not recommending this approach but since this is what you asked, this query should get you going.
SELECT sales_order.entity_id AS order_id,
product_id,
price,
sku,
value AS product_description
FROM sales_order
JOIN sales_order_item
ON order_id = sales_order_item.product_id
JOIN catalog_product_entity_text
ON product_id = catalog_product_entity_text.entity_id
WHERE catalog_product_entity_text.attribute_id = (SELECT attribute_id
FROM eav_attribute
WHERE
attribute_code = 'description'
AND entity_type_id = 4);
You might also what to consider store_id
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
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%2f276851%2fin-magento2-how-to-get-the-product-description-from-sales-order-table%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you are making changes to the frotnend. Not great but easiest way I can think of doing it is loading product by id inside the loop
foreach ($_order->getAllVisibleItems() as $_item)
echo $_item->getProductId();
Then using standard load
$productRepository;
public function __construct(
Context $context,
MagentoCatalogApiProductRepositoryInterface $productRepositoryInterface
// ...
)
$this->productRepository = $productRepositoryInterface;
// ....
try
$product = $productRepository->getById(1234);
// got description here
catch (MagentoFrameworkExceptionNoSuchEntityException $e)
Reason to go against the join is that you would have to join sales_order_item soi, catalog_product_entity_text cpet where cpet.entity_id = soi.product_id.
But then filter by cpet.attribute_id = 75 (for my install) and cpet.store_id = 0
Hardcoded IDs is never great. You can work out those IDs with additional lookups but already you see this is turning into a larger task.
If this is for the backend maybe this changes things a little.
add a comment |
If you are making changes to the frotnend. Not great but easiest way I can think of doing it is loading product by id inside the loop
foreach ($_order->getAllVisibleItems() as $_item)
echo $_item->getProductId();
Then using standard load
$productRepository;
public function __construct(
Context $context,
MagentoCatalogApiProductRepositoryInterface $productRepositoryInterface
// ...
)
$this->productRepository = $productRepositoryInterface;
// ....
try
$product = $productRepository->getById(1234);
// got description here
catch (MagentoFrameworkExceptionNoSuchEntityException $e)
Reason to go against the join is that you would have to join sales_order_item soi, catalog_product_entity_text cpet where cpet.entity_id = soi.product_id.
But then filter by cpet.attribute_id = 75 (for my install) and cpet.store_id = 0
Hardcoded IDs is never great. You can work out those IDs with additional lookups but already you see this is turning into a larger task.
If this is for the backend maybe this changes things a little.
add a comment |
If you are making changes to the frotnend. Not great but easiest way I can think of doing it is loading product by id inside the loop
foreach ($_order->getAllVisibleItems() as $_item)
echo $_item->getProductId();
Then using standard load
$productRepository;
public function __construct(
Context $context,
MagentoCatalogApiProductRepositoryInterface $productRepositoryInterface
// ...
)
$this->productRepository = $productRepositoryInterface;
// ....
try
$product = $productRepository->getById(1234);
// got description here
catch (MagentoFrameworkExceptionNoSuchEntityException $e)
Reason to go against the join is that you would have to join sales_order_item soi, catalog_product_entity_text cpet where cpet.entity_id = soi.product_id.
But then filter by cpet.attribute_id = 75 (for my install) and cpet.store_id = 0
Hardcoded IDs is never great. You can work out those IDs with additional lookups but already you see this is turning into a larger task.
If this is for the backend maybe this changes things a little.
If you are making changes to the frotnend. Not great but easiest way I can think of doing it is loading product by id inside the loop
foreach ($_order->getAllVisibleItems() as $_item)
echo $_item->getProductId();
Then using standard load
$productRepository;
public function __construct(
Context $context,
MagentoCatalogApiProductRepositoryInterface $productRepositoryInterface
// ...
)
$this->productRepository = $productRepositoryInterface;
// ....
try
$product = $productRepository->getById(1234);
// got description here
catch (MagentoFrameworkExceptionNoSuchEntityException $e)
Reason to go against the join is that you would have to join sales_order_item soi, catalog_product_entity_text cpet where cpet.entity_id = soi.product_id.
But then filter by cpet.attribute_id = 75 (for my install) and cpet.store_id = 0
Hardcoded IDs is never great. You can work out those IDs with additional lookups but already you see this is turning into a larger task.
If this is for the backend maybe this changes things a little.
edited May 31 at 11:06
Amit Bera♦
60.9k1682181
60.9k1682181
answered May 31 at 10:57
Dominic XigenDominic Xigen
1,090211
1,090211
add a comment |
add a comment |
Using
MagentoCatalogModelProductRepository you get product descriptionlike below
public function __construct(MagentoCatalogModelProductRepository $productRepository)
$this->$productRepository=$productRepository;
public function customMethod()
$sku=//get from order object;
$product=$this->$productRepository->get($sku);
$product->getDescription();
**Note:**if you are using magento's older version where may be ProductRepository class not exits so you need to get product from Product Model
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
add a comment |
Using
MagentoCatalogModelProductRepository you get product descriptionlike below
public function __construct(MagentoCatalogModelProductRepository $productRepository)
$this->$productRepository=$productRepository;
public function customMethod()
$sku=//get from order object;
$product=$this->$productRepository->get($sku);
$product->getDescription();
**Note:**if you are using magento's older version where may be ProductRepository class not exits so you need to get product from Product Model
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
add a comment |
Using
MagentoCatalogModelProductRepository you get product descriptionlike below
public function __construct(MagentoCatalogModelProductRepository $productRepository)
$this->$productRepository=$productRepository;
public function customMethod()
$sku=//get from order object;
$product=$this->$productRepository->get($sku);
$product->getDescription();
**Note:**if you are using magento's older version where may be ProductRepository class not exits so you need to get product from Product Model
Using
MagentoCatalogModelProductRepository you get product descriptionlike below
public function __construct(MagentoCatalogModelProductRepository $productRepository)
$this->$productRepository=$productRepository;
public function customMethod()
$sku=//get from order object;
$product=$this->$productRepository->get($sku);
$product->getDescription();
**Note:**if you are using magento's older version where may be ProductRepository class not exits so you need to get product from Product Model
answered May 31 at 10:40
Rutvee SojitraRutvee Sojitra
2,1151322
2,1151322
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
add a comment |
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
My requirement is like suh that I want to join these tables , sales order, sales order item, and catalog_product_entity and catalog product entity varchar
– MGento
May 31 at 11:54
add a comment |
I'm not recommending this approach but since this is what you asked, this query should get you going.
SELECT sales_order.entity_id AS order_id,
product_id,
price,
sku,
value AS product_description
FROM sales_order
JOIN sales_order_item
ON order_id = sales_order_item.product_id
JOIN catalog_product_entity_text
ON product_id = catalog_product_entity_text.entity_id
WHERE catalog_product_entity_text.attribute_id = (SELECT attribute_id
FROM eav_attribute
WHERE
attribute_code = 'description'
AND entity_type_id = 4);
You might also what to consider store_id
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
add a comment |
I'm not recommending this approach but since this is what you asked, this query should get you going.
SELECT sales_order.entity_id AS order_id,
product_id,
price,
sku,
value AS product_description
FROM sales_order
JOIN sales_order_item
ON order_id = sales_order_item.product_id
JOIN catalog_product_entity_text
ON product_id = catalog_product_entity_text.entity_id
WHERE catalog_product_entity_text.attribute_id = (SELECT attribute_id
FROM eav_attribute
WHERE
attribute_code = 'description'
AND entity_type_id = 4);
You might also what to consider store_id
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
add a comment |
I'm not recommending this approach but since this is what you asked, this query should get you going.
SELECT sales_order.entity_id AS order_id,
product_id,
price,
sku,
value AS product_description
FROM sales_order
JOIN sales_order_item
ON order_id = sales_order_item.product_id
JOIN catalog_product_entity_text
ON product_id = catalog_product_entity_text.entity_id
WHERE catalog_product_entity_text.attribute_id = (SELECT attribute_id
FROM eav_attribute
WHERE
attribute_code = 'description'
AND entity_type_id = 4);
You might also what to consider store_id
I'm not recommending this approach but since this is what you asked, this query should get you going.
SELECT sales_order.entity_id AS order_id,
product_id,
price,
sku,
value AS product_description
FROM sales_order
JOIN sales_order_item
ON order_id = sales_order_item.product_id
JOIN catalog_product_entity_text
ON product_id = catalog_product_entity_text.entity_id
WHERE catalog_product_entity_text.attribute_id = (SELECT attribute_id
FROM eav_attribute
WHERE
attribute_code = 'description'
AND entity_type_id = 4);
You might also what to consider store_id
answered May 31 at 13:21
vitoriodachefvitoriodachef
1,297424
1,297424
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
add a comment |
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
this gives error, Unknown column 'catalog_product_entity_text.entity_id' in 'on clause'
– MGento
Jun 1 at 5:32
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
I wont be writing raw query, I will convert this in to Magento DB functions
– MGento
Jun 1 at 5:45
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
The query work on a clean install. You can see it here snag.gy/RezN5s.jpg
– vitoriodachef
Jun 1 at 9:34
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
I get empty result set on unmodified 2.3.0 store with sample data. Although the query looks good. Weird. imgur.com/FqPq7WZ
– Dominic Xigen
Jun 1 at 22:33
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%2f276851%2fin-magento2-how-to-get-the-product-description-from-sales-order-table%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
Display where? Within admin?
– Dominic Xigen
May 31 at 10:55
I need to write it in to a csv file. My requirement is such that I want to join tables
– MGento
May 31 at 12:24
Build an array. Write the array to CSV. magestore.com/magento-2-tutorial/…
– Dominic Xigen
May 31 at 13:10