0

I have a Custom attribute name ( product string ) on Product in which i have save a string i want to get that custom attribute value for ordered product.

I have getting the ordered product by this code

 $orderId = 32;
 $order = $block->getOrderData($orderId);
 foreach ($order->getAllVisibleItems() as $_item) {
 echo $_item->getId();
    echo $_item->getSku();
    echo $_item->getName();
    echo $_item->getProductType();
    echo $_item->getQtyOrdered();
 echo "<pre>";print_r($_item->debug());
}
1

You can get it with $item->getProduct()->getData('attribute_code_here')

But there is a problem.
Actually a few:

  • Product may have been deleted
  • the attribute value has been changed after the order was placed.
  • the attribute may have been deleted

The best approach would be to save the value of the product attribute on the order item when the order is placed.
Here are some examples on how you can do that

1
  • Thanks for the response and help. Actually my requirement is different anyway thanks for the link. @Marius
    – Prits
    Aug 8 '20 at 6:58

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.