0

I need to display the product custom attribute values in magento2 order details page but not display. Attributes having values in admin side. I tried both codes.

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load('4');
echo '<pre>'; print_r($product->getata());

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$product = $objectManager->create('\Magento\Catalog\Api\Data\ProductInterface'); 
$product->get('4');
echo '<pre>'; print_r($product->getData());
  • Have you checked my answer? – Nikunj Vadariya Jun 4 '18 at 9:27
  • yes, but code is not working in order details page – venkata prasad Jun 4 '18 at 10:47
0

You can get it by this way:

$customOptions = $objectManager->get('Magento\Catalog\Model\Product\Option')
    ->getProductOptionCollection($_product);

if (empty($customOptions)) { //check if product has custom options. If it doesn't go to the next product
    continue;
}

foreach($customOptions as $option) {
    $values = $option->getValues();
    if (empty($values)) { //check if option has values (Option can have values only if option type is checkbox, radio, multiselect or drop-down)
        continue;
    }

    foreach($values as $value) {
        $valueData = $value->getData(); //do whatever you want will value data
    }
}

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.