3

I need to get product attributes for product items in Order. How can I do this? I got order details per one order from below line of code and I used loop to cycle through every order.

$orderObj = $objectManager->create('Magento\Sales\Model\Order')->load($orderID);

I need to get certain attribute value from each item in the order. I tried getAllvisibleitems as follows,

$items =$orderObj->getAllVisibleItems();

but it doesn't include data for the attributes. For example I need to get value from attribute manufacturer,

How can I get manufacturer of each item in the order?

2
  • Can somebody help me out please?
    – Joey
    Apr 5, 2018 at 12:25
  • have you find any solution?
    – surbhi agr
    Oct 9, 2019 at 13:01

2 Answers 2

3

Please try to get all product attributes by

$orderObj = $objectManager->create('Magento\Sales\Model\Order')->load($orderID);
$orderAllItems = $orderObj->getAllItems();
if ($orderAllItems) {
    foreach ($orderAllItems as $item) {
        $customatt = $item->getProduct()->getCustomAtt();
    }
}

Thanks

2
  • tested in Magento 2.3
    – Moin Malek
    Apr 27, 2019 at 15:09
  • This works for me. The absence of the "getProduct()" was what was preventing this from getting the attribute. Jul 17, 2020 at 11:09
1

Use this code to get product attribute for product items in Order.

$orderObj = $objectManager->create('Magento\Sales\Model\Order')->load($orderID);
$orderAllItems = $orderObj->getAllItems();
if ($orderAllItems) {
    foreach ($orderAllItems as $item) {
        $product_manufacturer = $item->getManufacturer();
    }
}

You can get all attribute from $item.

6
  • Few problems actually. I tried above and when I try this, it throws a fatal error saying area code is not set. And also I need to get only one attribute at once. I just need the attribute value for certain single item each
    – Joey
    Apr 5, 2018 at 11:10
  • Check again. I update my answer. Apr 5, 2018 at 11:13
  • Thanks for the help. but still, I've problems. it wont show anything now. manufacturer is a custom attribute, I might add that
    – Joey
    Apr 5, 2018 at 11:18
  • Please add screenshot, which error occurred? Apr 5, 2018 at 11:19
  • No error shown, just nothing gets printed. I tried print_r($item->getData()); and it shows bunch of data about the product but nothing on attributes. I tried print_r($item->getManufacturer()); and it shows nothing
    – Joey
    Apr 5, 2018 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.