AttributesList.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ConfigurableProduct\Model;
  7. class AttributesList implements AttributesListInterface
  8. {
  9. /**
  10. * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory
  11. */
  12. protected $collectionFactory;
  13. /**
  14. * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory
  15. */
  16. public function __construct(
  17. \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory
  18. ) {
  19. $this->collectionFactory = $collectionFactory;
  20. }
  21. /**
  22. * Retrieve list of attributes
  23. *
  24. * @param array $ids
  25. * @return array
  26. */
  27. public function getAttributes($ids)
  28. {
  29. $collection = $this->collectionFactory->create();
  30. $collection->addFieldToFilter('main_table.attribute_id', $ids);
  31. $attributes = [];
  32. foreach ($collection->getItems() as $attribute) {
  33. $attributes[] = [
  34. 'id' => $attribute->getId(),
  35. 'label' => $attribute->getFrontendLabel(),
  36. 'code' => $attribute->getAttributeCode(),
  37. 'options' => $attribute->getSource()->getAllOptions(false)
  38. ];
  39. }
  40. return $attributes;
  41. }
  42. }