Productattributes.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\Config\Configuration;
  3. class Productattributes implements \Magento\Framework\Data\OptionSourceInterface
  4. {
  5. /**
  6. * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory
  7. */
  8. private $attributes;
  9. /**
  10. * Exclude incompatible product attributes from the mapping.
  11. * @var array
  12. */
  13. private $excluded = [
  14. 'quantity_and_stock_status'
  15. ];
  16. /**
  17. * Productattributes constructor.
  18. *
  19. * @param \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory
  20. */
  21. public function __construct(
  22. \Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory $collectionFactory
  23. ) {
  24. $this->attributes = $collectionFactory;
  25. }
  26. /**
  27. * Get options.
  28. *
  29. * @return array
  30. */
  31. public function toOptionArray()
  32. {
  33. $attributes = $this->attributes
  34. ->create()
  35. ->addVisibleFilter();
  36. $attributeArray = [];
  37. $attributeArray[] = [
  38. 'label' => __('---- Default Option ----'),
  39. 'value' => '0',
  40. ];
  41. foreach ($attributes as $attribute) {
  42. $attributeCode = $attribute->getAttributeCode();
  43. if (!in_array($attributeCode, $this->excluded)) {
  44. $attributeArray[] = [
  45. 'label' => $attribute->getFrontendLabel(),
  46. 'value' => $attributeCode,
  47. ];
  48. }
  49. }
  50. return $attributeArray;
  51. }
  52. }