Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GroupedItems.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
16 
21 {
25  private $productResolver;
26 
30  public function __construct(
31  Product $productResolver
32  ) {
33  $this->productResolver = $productResolver;
34  }
35 
39  public function resolve(
40  Field $field,
41  $context,
43  array $value = null,
44  array $args = null
45  ) {
46  if (!isset($value['model'])) {
47  throw new GraphQlInputException(__('"model" value should be specified'));
48  }
49 
50  $data = [];
51  $productModel = $value['model'];
52  $links = $productModel->getProductLinks();
53  foreach ($links as $link) {
54  if ($link->getLinkType() !== Grouped::TYPE_NAME) {
55  continue;
56  }
57 
58  $data[] = [
59  'position' => (int)$link->getPosition(),
60  'qty' => $link->getExtensionAttributes()->getQty(),
61  'sku' => $link->getLinkedProductSku()
62  ];
63  }
64 
65  return $data;
66  }
67 }
__()
Definition: __.php:13
$value
Definition: gender.phtml:16
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
$productModel
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52