Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BundleItems.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
18 
23 {
27  private $bundleOptionCollection;
28 
32  private $valueFactory;
33 
37  private $metadataPool;
38 
44  public function __construct(
45  Collection $bundleOptionCollection,
46  ValueFactory $valueFactory,
47  MetadataPool $metadataPool
48  ) {
49  $this->bundleOptionCollection = $bundleOptionCollection;
50  $this->valueFactory = $valueFactory;
51  $this->metadataPool = $metadataPool;
52  }
53 
59  public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
60  {
61  $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
62  if ($value['type_id'] !== Type::TYPE_CODE
63  || !isset($value[$linkField])
64  || !isset($value[ProductInterface::SKU])
65  ) {
66  $result = function () {
67  return null;
68  };
69  return $this->valueFactory->create($result);
70  }
71 
72  $this->bundleOptionCollection->addParentFilterData(
73  (int)$value[$linkField],
74  (int)$value['entity_id'],
76  );
77 
78  $result = function () use ($value, $linkField) {
79  return $this->bundleOptionCollection->getOptionsByParentId((int)$value[$linkField]);
80  };
81 
82  return $this->valueFactory->create($result);
83  }
84 }
__construct(Collection $bundleOptionCollection, ValueFactory $valueFactory, MetadataPool $metadataPool)
Definition: BundleItems.php:44
$value
Definition: gender.phtml:16
resolve(Field $field, $context, ResolveInfo $info, array $value=null, array $args=null)
Definition: BundleItems.php:59
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52