2

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?

  • Can somebody help me out please? – Joey Apr 5 '18 at 12:25
  • have you find any solution? – surbhi agr Oct 9 at 13:01
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.

  • 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 '18 at 11:10
  • Check again. I update my answer. – Emipro Technologies Pvt. Ltd. Apr 5 '18 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 '18 at 11:18
  • Please add screenshot, which error occurred? – Emipro Technologies Pvt. Ltd. Apr 5 '18 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 '18 at 11:23
0

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

  • tested in Magento 2.3 – Moin Malek Apr 27 at 15:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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