dbm 5 лет назад
Родитель
Сommit
68545f09cc

+ 11 - 20
ShippingNotifications/Block/ShippingCategory.php

@@ -9,6 +9,7 @@ use Magento\Framework\View\Element\Template\Context;
 use Cpcommerce\ShippingNotifications\Model\ShippingCategory AS DelayedShippingCategory;
 use Cpcommerce\ShippingNotifications\Model\ResourceModel\ShippingCategory\Collection;
 use Magento\Framework\App\ResourceConnection;
+use \Magento\Framework\App\Config\ScopeConfigInterface;
 
 class ShippingCategory extends Template
 {
@@ -21,20 +22,18 @@ class ShippingCategory extends Template
         array $data = [],
         DelayedShippingCategory $delayedShippingCategory,
         Collection $delayedCollection,
-        ResourceConnection $resource
+        ResourceConnection $resource,
+        ScopeConfigInterface $scopeConfig
     ) {
         $this->description = $description;
         $this->attribute = $attribute;
         $this->delayedShippingCategory = $delayedShippingCategory;
         $this->delayedCollection = $delayedCollection;
         $this->resource = $resource;
+        $this->scopeConfig = $scopeConfig;
         return parent::__construct($context, $data);
     }
 
-    public function getAttributeData($attribute_code){
-        return $this->attribute->get($attribute_code);
-    }
-
     public function getShippingCategory(){
         $_product = $this->description->getProduct();
         $option_id = $_product->getShippingCategory();
@@ -44,22 +43,14 @@ class ShippingCategory extends Template
 
     public function getDelayedShippingCategories(){
 
-        $this->delayedCollection->getSelect()->where("is_delayed = '1'");
-
-        return $this->delayedCollection->load();
-
-    }
-
-    public function toOptionArray(){
-        $options =  $this->attribute->get($attribute_code)->getOptions;
+        $delayedShipCategs = $this->scopeConfig->getValue('cpcommerce_shipping_notifications/general/shipping_categories',\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
 
-        $options_array = [];
-
-        foreach($options as $option){
-            $options_array[] = [
-                'label' => $options->getTitle(),
-                'value' => $options->getId()
-            ];
+        if(isset($delayedShipCategs)){
+            $delayedShipCategsArray = explode(",",$delayedShipCategs);
+            return $delayedShipCategsArray;
         }
+        
+        return null;
     }
+
 }

+ 1 - 1
ShippingNotifications/view/frontend/templates/shipping_notification.phtml

@@ -4,7 +4,7 @@
 
     if($delayedCategs){
         foreach($delayedCategs as $categ){
-            if($shipping_category == $categ->getData("option_id")){
+            if($shipping_category == $categ){
                 echo $block->getChildHtml('cpcommerce_shipping_notification');
                 break;
             }