i'm using magento 2 and i've to update particular product by sku,

i've used below code to load but it is taking too much time

$objectManager = $bootstrap->getObjectManager();
$productRepository = $objectManager->get('\Magento\Catalog\Model\ProductRepository');
$product = $productRepository->get(trim($sku));

is there any other solution to load product from root which take less then above code,

Thank you,


Repository(\Magento\Catalog\Model\ProductRepository) always faster process for getting data.But donot know why is running show at your system.Please run complier at system

So, Let try use Model class \Magento\Catalog\Model\Product instead of \Magento\Catalog\Model\ProductRepository.

$objectManager = $bootstrap->getObjectManager();
$productModel = $objectManager->get('\Magento\Catalog\Model\Product');
$product = $productModel->loadByAttribute(sku', $sku);

Please try this

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.