| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace Cpcommerce\ShippingNotifications\Model\Config\Source;
- use Magento\Framework\Data\OptionSourceInterface;
- use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
- class Attributes implements OptionSourceInterface{
-
- public function __construct(
- CollectionFactory $collectionFactory
- ){
- $this->collectionFactory = $collectionFactory;
- }
-
- public function toOptionArray()
- {
- $options = [];
- foreach($this->getOptions() as $optionValue => $optionLabel){
- $options[] = ['value' => $optionValue, 'label' => $optionLabel];
- }
- return $options;
- }
- public function getOptions()
- {
- $collection = $this->collectionFactory->create();
- $collection->addFieldToFilter('main_table.frontend_input', 'select');
- $collection->addOrder('attribute_code', 'asc');
- $options = ['' => _('-- Empty --')];
- foreach($collection->getItems() as $attribute){
- $options[$attribute->getAttributeCode()] = $attribute->getAttributeCode();
- }
- return $options;
- }
- }
|