mirror of
https://github.com/bdnugget/magento2.git
synced 2026-11-07 17:27:36 +00:00
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Copyright © Magento, Inc. All rights reserved.
|
|
* See COPYING.txt for license details.
|
|
*/
|
|
declare(strict_types=1);
|
|
|
|
namespace Magento\SalesGraphQl\Model\Resolver;
|
|
|
|
use Magento\Catalog\Model\Product;
|
|
use Magento\CatalogGraphQl\Model\ProductDataProvider;
|
|
use Magento\Framework\Exception\LocalizedException;
|
|
use Magento\Framework\GraphQl\Config\Element\Field;
|
|
use Magento\Framework\GraphQl\Query\ResolverInterface;
|
|
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
|
|
|
|
/**
|
|
* Fetches the Product data according to the GraphQL schema
|
|
*/
|
|
class ProductResolver implements ResolverInterface
|
|
{
|
|
/**
|
|
* @var ProductDataProvider
|
|
*/
|
|
private $productDataProvider;
|
|
|
|
/**
|
|
* @param ProductDataProvider $productDataProvider
|
|
*/
|
|
public function __construct(ProductDataProvider $productDataProvider)
|
|
{
|
|
$this->productDataProvider = $productDataProvider;
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function resolve(
|
|
Field $field,
|
|
$context,
|
|
ResolveInfo $info,
|
|
array $value = null,
|
|
array $args = null
|
|
) {
|
|
if (!isset($value['associatedProduct'])) {
|
|
throw new LocalizedException(__('Missing key "associatedProduct" in Order Item value data'));
|
|
}
|
|
/** @var Product $product */
|
|
$product = $value['associatedProduct'];
|
|
|
|
return $this->productDataProvider->getProductDataById((int) $product->getId());
|
|
}
|
|
}
|