12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\ConfigurableProduct\Ui\DataProvider;
- class Attributes extends \Magento\Ui\DataProvider\AbstractDataProvider
- {
- /**
- * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
- */
- protected $collection;
- /**
- * @param string $name
- * @param string $primaryFieldName
- * @param string $requestFieldName
- * @param \Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler $configurableAttributeHandler
- * @param array $meta
- * @param array $data
- */
- public function __construct(
- $name,
- $primaryFieldName,
- $requestFieldName,
- \Magento\ConfigurableProduct\Model\ConfigurableAttributeHandler $configurableAttributeHandler,
- array $meta = [],
- array $data = []
- ) {
- parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
- $this->configurableAttributeHandler = $configurableAttributeHandler;
- $this->collection = $configurableAttributeHandler->getApplicableAttributes();
- }
- /**
- * @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
- */
- public function getCollection()
- {
- return $this->collection;
- }
- /**
- * {@inheritdoc}
- */
- public function getData()
- {
- $items = [];
- $skippedItems = 0;
- foreach ($this->getCollection()->getItems() as $attribute) {
- if ($this->configurableAttributeHandler->isAttributeApplicable($attribute)) {
- $items[] = $attribute->toArray();
- } else {
- $skippedItems++;
- }
- }
- return [
- 'totalRecords' => $this->collection->getSize() - $skippedItems,
- 'items' => $items
- ];
- }
- }
|