| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace Cpcommerce\ShippingNotifications\Model\Config\Source;
- use Magento\Framework\Data\OptionSourceInterface;
- use Magento\Catalog\Model\Product\Attribute\Repository;
- use \Magento\Framework\App\Config\ScopeConfigInterface;
- class ShippingCategories implements OptionSourceInterface
- {
- private $attribute;
- private $scopeConfig;
- public function __construct(
- Repository $attribute,
- ScopeConfigInterface $scopeConfig
- ){
- $this->attribute = $attribute;
- $this->scopeConfig = $scopeConfig;
- }
- public function toOptionArray()
- {
- $options = [];
- $attributeCode = $this->scopeConfig->getValue('cpcommerce_shipping_notifications/general/attribute',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
- $shippingCategories = $this->attribute->get($attributeCode)->getOptions();
- foreach($shippingCategories AS $shippingCategory){
- $options[] = [
- 'value' => $shippingCategory->getValue(),
- 'label' => $shippingCategory->getLabel()
- ];
- }
-
- return $options;
- }
- }
|