Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Attributes.php
Go to the documentation of this file.
1 <?php
8 
10 {
14  protected $collection;
15 
24  public function __construct(
25  $name,
28  \Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler $configurableAttributeHandler,
29  array $meta = [],
30  array $data = []
31  ) {
32  parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
33  $this->configurableAttributeHandler = $configurableAttributeHandler;
34  $this->collection = $configurableAttributeHandler->getApplicableAttributes();
35  }
36 
40  public function getCollection()
41  {
42  return $this->collection;
43  }
44 
48  public function getData()
49  {
50  $items = [];
51  $skippedItems = 0;
52  foreach ($this->getCollection()->getItems() as $attribute) {
53  if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) {
54  $items[] = $attribute->toArray();
55  } else {
56  $skippedItems++;
57  }
58  }
59  return [
60  'totalRecords' => $this->collection->getSize() - $skippedItems,
61  'items' => $items
62  ];
63  }
64 }
__construct( $name, $primaryFieldName, $requestFieldName, \Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler $configurableAttributeHandler, array $meta=[], array $data=[])
Definition: Attributes.php:24
$items