Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ReadHandler.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
21  private $optionLoader;
22 
28  public function __construct(Loader $optionLoader)
29  {
30  $this->optionLoader = $optionLoader;
31  }
32 
39  public function execute($entity, $arguments = [])
40  {
41  if ($entity->getTypeId() !== Configurable::TYPE_CODE) {
42  return $entity;
43  }
44 
45  $extensionAttributes = $entity->getExtensionAttributes();
46 
47  $extensionAttributes->setConfigurableProductLinks($this->getLinkedProducts($entity));
48  $extensionAttributes->setConfigurableProductOptions($this->optionLoader->load($entity));
49 
50  $entity->setExtensionAttributes($extensionAttributes);
51 
52  return $entity;
53  }
54 
61  private function getLinkedProducts(ProductInterface $product)
62  {
64  $typeInstance = $product->getTypeInstance();
65  $childrenIds = $typeInstance->getChildrenIds($product->getId());
66 
67  if (isset($childrenIds[0])) {
68  return $childrenIds[0];
69  } else {
70  return [];
71  }
72  }
73 }
$entity
Definition: element.phtml:22
$arguments