0

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,

1 Answer 1

3

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

1
  • cool !! ! it's works Commented Sep 7, 2020 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.