0

Q1. Why does getData() return null, I need to do load() first?

They seem to be the same class type..

function (Magento\Catalog\Model\Product $product):
$product->getData('my_attribute_1');
//returns null

I'm forced to use deprecated function load:

function (Magento\Catalog\Model\Product $product):
$product->load($product->getId())->getData('my_attribute_1');
//returns 'somedata 11332'

Q2. Is there another method to load the product properly that is not deprecated ?

  • Edit: I have figured out that i can use Magento\Catalog\Api\ProductRepositoryInterface->getById($product->getId, false, $product->getStoreId()); Instead of load(). Any answer that describes why this much be done will still be graciously accepted. Thanks – Pathfinder Jan 21 at 0:19

Your Answer

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

Browse other questions tagged or ask your own question.