2

What is the difference between using \Magento\Catalog\Model\ProductRepository and \Magento\Catalog\Api\ProductRepositoryInterface?
Which one is better and recommended to use?

Anshu Mishra
  • 8,950
  • 7
  • 40
  • 88
  • API folder used for handle Interface related classes,contains any PHP classes exposed to the api & Model use to handle module related logic & Datamodel (CRUD) – Birjitsinh Zala Jan 22 '18 at 07:07

1 Answers1

2

I am not 100% deep knowledge of this.

But i am pretty sure that you should use

\Magento\Catalog\Api\ProductRepositoryInterface

As it can use for both api and model layer

See the magento document:

http://devdocs.magento.com/guides/v2.1//extension-dev-guide/service-contracts/design-patterns.html#service-interfaces

http://devdocs.magento.com/guides/v2.1/extension-dev-guide/service-contracts/service-contracts.html

How to implement service contract for a custom module in Magento 2?

Amit Bera
  • 77,456
  • 20
  • 123
  • 237