1

I need to retrieve 1 product attribute value from 1 product, I wonder if using the product repository in this way is the most effective in terms of performances:

$productColour = $this->productRepository->get($this->getSku())->getCustomAttribute('colour');

thanks

2
  • In which file you are using such code ? Oct 6 '17 at 10:02
  • @KishanPatadia in a custom block Adminhtml\Block\Adminhtml\Items\Column\Name.php. Basically, I have to show this attribute value in the sales_order_view template under the product_name column Oct 6 '17 at 10:06
0

try this

$_product_Object = $objectManager->get('\Magento\Catalog\Api\ProductRepositoryInterface')->getById(1);
$colorType = $_product_Object->getResource()->getAttribute('colour')->getFrontend()->getValue($_product_Object);
1
  • 1
    should not the object manager use avoided? Oct 6 '17 at 13:51

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.