ProductDataProvider.php 1008 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\CatalogGraphQl\Model;
  8. use Magento\Catalog\Api\ProductRepositoryInterface;
  9. /**
  10. * Product data provider
  11. *
  12. * TODO: will be replaces on deferred mechanism
  13. */
  14. class ProductDataProvider
  15. {
  16. /**
  17. * @var ProductRepositoryInterface
  18. */
  19. private $productRepository;
  20. /**
  21. * @param ProductRepositoryInterface $productRepository
  22. */
  23. public function __construct(ProductRepositoryInterface $productRepository)
  24. {
  25. $this->productRepository = $productRepository;
  26. }
  27. /**
  28. * Get product data by id
  29. *
  30. * @param int $productId
  31. * @return array
  32. */
  33. public function getProductDataById(int $productId): array
  34. {
  35. $product = $this->productRepository->getById($productId);
  36. $productData = $product->toArray();
  37. $productData['model'] = $product;
  38. return $productData;
  39. }
  40. }