소스 검색

basic tests passed on frontend

dbm 5 년 전
부모
커밋
dce2adb44d

+ 23 - 3
ShippingNotifications/Block/ShippingCategory.php

@@ -6,17 +6,28 @@ use Magento\Catalog\Block\Product\View\Description;
 use Magento\Catalog\Model\Product\Attribute\Repository;
 use Magento\Framework\View\Element\Template;
 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;
 
 class ShippingCategory extends Template
 {
+    protected $resource;
+
     public function __construct(
         Description $description,
         Repository $attribute,
         Context $context,
-        array $data = []
+        array $data = [],
+        DelayedShippingCategory $delayedShippingCategory,
+        Collection $delayedCollection,
+        ResourceConnection $resource
     ) {
         $this->description = $description;
         $this->attribute = $attribute;
+        $this->delayedShippingCategory = $delayedShippingCategory;
+        $this->delayedCollection = $delayedCollection;
+        $this->resource = $resource;
         return parent::__construct($context, $data);
     }
 
@@ -26,7 +37,16 @@ class ShippingCategory extends Template
 
     public function getShippingCategory(){
         $_product = $this->description->getProduct();
-        $shipping_category = $_product->getResource()->getAttribute('shipping_category')->getFrontend()->getValue($_product);
-        return $shipping_category;
+        $option_id = $_product->getShippingCategory();
+
+        return $option_id;
+    }
+
+    public function getDelayedShippingCategories(){
+
+        $this->delayedCollection->getSelect()->where("is_delayed = '1'");
+
+        return $this->delayedCollection->load();
+
     }
 }

+ 1 - 1
ShippingNotifications/Model/ResourceModel/ShippingCategory/Collection.php

@@ -1,6 +1,6 @@
 <?php
 
-namespace Cpcommerce\ShippingNotification\Model\ResourceModel\ShippingCategory;
+namespace Cpcommerce\ShippingNotifications\Model\ResourceModel\ShippingCategory;
 
 use \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection;
 

+ 1 - 1
ShippingNotifications/Model/ShippingCategory.php

@@ -5,7 +5,7 @@ use \Magento\Framework\Model\AbstractModel;
 use \Magento\Framework\DataObject\IdentityInterface;
 use \Cpcommerce\ShippingNotifications\Api\Data\ShippingCategoryInterface;
 
-class ShippingCategory extends AbstractModel implements ShippingCategoryInterface, IdentityInterface
+class ShippingCategory extends AbstractModel implements ShippingCategoryInterface
 {
     protected function _construct()
     {

+ 10 - 14
ShippingNotifications/view/frontend/templates/shipping_notification.phtml

@@ -1,16 +1,12 @@
 <?php
-    
     $shipping_category = $block->getShippingCategory();
-
-    $attribute_info = $block->get('shipping_category');
-
-    if($shipping_category == 'Late'){
-        $ship_notif_enable = 1;
-    }
-?>
-
-<?php if($ship_notif_enable) : ?>
-<?php echo $block->getChildHtml('cpcommerce_shipping_notification'); ?>
-<?php endif; ?>
-
-
+    $delayedCategs = $block->getDelayedShippingCategories();  
+
+    if($delayedCategs){
+        foreach($delayedCategs as $categ){
+            if($shipping_category == $categ->getData("option_id")){
+                echo $block->getChildHtml('cpcommerce_shipping_notification');
+                break;
+            }
+        }
+    }