From c616bc268dba0b84262853ece738ba54e73a3d35 Mon Sep 17 00:00:00 2001
From: Henning Leutz <leutz@pcsg.de>
Date: Thu, 4 Jul 2019 16:09:09 +0200
Subject: [PATCH] fix: started shipping rules

---
 database.xml                                  |  10 +
 locale.xml                                    |  16 +-
 .../ERP/Shipping/Api/AbstractShippingType.php | 122 ++++++++++++
 .../Shipping/Api/ShippingTypeInterface.php    |   2 +-
 .../Shipping/Methods/Standard/Shipping.php    |   5 -
 .../Methods/Standard/ShippingType.php         |   2 +-
 src/QUI/ERP/Shipping/Order/Shipping.php       |   4 +-
 src/QUI/ERP/Shipping/Rules/Factory.php        | 164 +++++++++++++++
 src/QUI/ERP/Shipping/Rules/ShippingRule.php   | 186 ++++++++++++++++++
 src/QUI/ERP/Shipping/Shipping.php             |   4 -
 src/QUI/ERP/Shipping/Types/Factory.php        |  39 ++--
 src/QUI/ERP/Shipping/Types/ShippingEntry.php  |  90 +--------
 12 files changed, 514 insertions(+), 130 deletions(-)
 create mode 100644 src/QUI/ERP/Shipping/Api/AbstractShippingType.php
 create mode 100644 src/QUI/ERP/Shipping/Rules/Factory.php
 create mode 100644 src/QUI/ERP/Shipping/Rules/ShippingRule.php

diff --git a/database.xml b/database.xml
index ce3abc1..160fe61 100644
--- a/database.xml
+++ b/database.xml
@@ -7,6 +7,16 @@
             <field type="INT(1) NOT NULL DEFAULT 0">active</field>
             <field type="VARCHAR(255) NOT NULL">shipping_type</field>
             <field type="VARCHAR(255) NOT NULL">icon</field>
+            <field type="TEXT">shipping_rules</field>
+            <field type="INT(4) NULL">priority</field>
+
+            <primary>id</primary>
+            <auto_increment>id</auto_increment>
+        </table>
+
+        <table name="shipping_rules">
+            <field type="INT(11) NOT NULL">id</field>
+            <field type="INT(1) NOT NULL DEFAULT 0">active</field>
             <field type="text NULL">date_from</field>
             <field type="text NULL">date_until</field>
             <field type="INT(10) NULL DEFAULT 0">purchase_quantity_from</field>
diff --git a/locale.xml b/locale.xml
index 5a2b317..a0ff145 100644
--- a/locale.xml
+++ b/locale.xml
@@ -42,16 +42,16 @@
         </locale>
 
         <locale name="shipping.standard.title">
-            <de><![CDATA[Standard Versand Methode]]></de>
-            <en><![CDATA[Standard shipping type]]></en>
+            <de><![CDATA[Standard Versand]]></de>
+            <en><![CDATA[Standard shipping]]></en>
         </locale>
         <locale name="shipping.free.description">
-            <de><![CDATA[Standard Versand Methode]]></de>
-            <en><![CDATA[Standard shipping type]]></en>
+            <de><![CDATA[Standard Versand]]></de>
+            <en><![CDATA[Standard shipping]]></en>
         </locale>
         <locale name="shipping.free.workingTitle">
-            <de><![CDATA[Standard Versand Methode]]></de>
-            <en><![CDATA[Standard shipping type]]></en>
+            <de><![CDATA[Standard Versand]]></de>
+            <en><![CDATA[Standard shipping]]></en>
         </locale>
     </groups>
 
@@ -106,6 +106,10 @@
 
 
     <groups name="quiqqer/shipping" datatype="js">
+        <locale name="shipping.type">
+            <de><![CDATA[Versand Art]]></de>
+            <en><![CDATA[Shipping type]]></en>
+        </locale>
         <locale name="shipping.edit.template.title">
             <de><![CDATA[Titel]]></de>
             <en><![CDATA[Title]]></en>
diff --git a/src/QUI/ERP/Shipping/Api/AbstractShippingType.php b/src/QUI/ERP/Shipping/Api/AbstractShippingType.php
new file mode 100644
index 0000000..5945831
--- /dev/null
+++ b/src/QUI/ERP/Shipping/Api/AbstractShippingType.php
@@ -0,0 +1,122 @@
+<?php
+
+/**
+ * This file contains \QUI\ERP\Shipping\Api\AbstractShippingEntry
+ */
+
+namespace QUI\ERP\Shipping\Api;
+
+use QUI;
+
+/**
+ * Shipping abstract class
+ * This is the parent shipping class for all shipping methods
+ *
+ * @author www.pcsg.de (Henning Leutz)
+ */
+abstract class AbstractShippingType extends QUI\QDOM implements QUI\ERP\Shipping\Api\ShippingTypeInterface
+{
+    /**
+     * @return string
+     */
+    public function getType()
+    {
+        return \get_class($this);
+    }
+
+    /**
+     * @param QUI\Interfaces\Users\User $User
+     * @return bool
+     */
+    public function canUsedBy(QUI\Interfaces\Users\User $User)
+    {
+        return true;
+    }
+
+    /**
+     * @param QUI\Locale|null $Locale
+     * @return array
+     */
+    public function toArray($Locale = null)
+    {
+        if ($Locale === null) {
+            $Locale = QUI::getLocale();
+        }
+
+        return [
+            'title'        => $this->getTitle($Locale),
+            'description'  => $this->getDescription($Locale),
+            'workingTitle' => $this->getWorkingTitle($Locale),
+            'shippingType' => $this->getType(),
+            'icon'         => $this->getIcon()
+        ];
+    }
+
+    /**
+     * @param $Locale
+     * @return array|string
+     */
+    public function getName($Locale = null)
+    {
+        $ShippingType = $this->getShipping();
+
+        if ($Locale !== null) {
+            $ShippingType->setLocale($Locale);
+        }
+
+        return $ShippingType->getTitle();
+    }
+
+    /**
+     * @param $Locale
+     * @return array|string
+     */
+    public function getTitle($Locale = null)
+    {
+        $ShippingType = $this->getShipping();
+
+        if ($Locale !== null) {
+            $ShippingType->setLocale($Locale);
+        }
+
+        return $ShippingType->getTitle();
+    }
+
+    /**
+     * @param $Locale
+     * @return array|string
+     */
+    public function getWorkingTitle($Locale = null)
+    {
+        $ShippingType = $this->getShipping();
+
+        if ($Locale !== null) {
+            $ShippingType->setLocale($Locale);
+        }
+
+        return $ShippingType->getWorkingTitle();
+    }
+
+    /**
+     * @param $Locale
+     * @return array|string
+     */
+    public function getDescription($Locale = null)
+    {
+        $ShippingType = $this->getShipping();
+
+        if ($Locale !== null) {
+            $ShippingType->setLocale($Locale);
+        }
+
+        return $ShippingType->getDescription();
+    }
+
+    /**
+     * @return string
+     */
+    public function getIcon()
+    {
+        return $this->getShipping()->getIcon();
+    }
+}
diff --git a/src/QUI/ERP/Shipping/Api/ShippingTypeInterface.php b/src/QUI/ERP/Shipping/Api/ShippingTypeInterface.php
index a3b827a..19e1861 100644
--- a/src/QUI/ERP/Shipping/Api/ShippingTypeInterface.php
+++ b/src/QUI/ERP/Shipping/Api/ShippingTypeInterface.php
@@ -47,7 +47,7 @@ public function toArray($Locale = null);
     /**
      * @return \QUI\ERP\Shipping\Api\AbstractShippingEntry
      */
-    public function getShippingType();
+    public function getShipping();
 
     /**
      * @param QUI\Interfaces\Users\User $User
diff --git a/src/QUI/ERP/Shipping/Methods/Standard/Shipping.php b/src/QUI/ERP/Shipping/Methods/Standard/Shipping.php
index 9f4a22d..73577a8 100644
--- a/src/QUI/ERP/Shipping/Methods/Standard/Shipping.php
+++ b/src/QUI/ERP/Shipping/Methods/Standard/Shipping.php
@@ -16,11 +16,6 @@
  */
 class Shipping extends QUI\ERP\Shipping\Api\AbstractShippingEntry
 {
-    /**
-     * Standard shipping id
-     */
-    const ID = -1;
-
     /**
      * @return array|string
      */
diff --git a/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php b/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php
index b0d4296..95d8399 100644
--- a/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php
+++ b/src/QUI/ERP/Shipping/Methods/Standard/ShippingType.php
@@ -19,7 +19,7 @@ class ShippingType extends QUI\ERP\Shipping\Api\AbstractShippingType
     /**
      * @return Shipping
      */
-    public function getShippingType()
+    public function getShipping()
     {
         return new Shipping();
     }
diff --git a/src/QUI/ERP/Shipping/Order/Shipping.php b/src/QUI/ERP/Shipping/Order/Shipping.php
index 06def33..a4cd186 100644
--- a/src/QUI/ERP/Shipping/Order/Shipping.php
+++ b/src/QUI/ERP/Shipping/Order/Shipping.php
@@ -24,7 +24,7 @@ public function __construct($attributes = [])
     {
         parent::__construct($attributes);
 
-        $this->addCSSFile(dirname(__FILE__).'/Shipping.css');
+        $this->addCSSFile(\dirname(__FILE__).'/Shipping.css');
     }
 
     /**
@@ -78,7 +78,7 @@ public function getBody()
             'shippingList'     => $shippingList
         ]);
 
-        return $Engine->fetch(dirname(__FILE__).'/Shipping.html');
+        return $Engine->fetch(\dirname(__FILE__).'/Shipping.html');
     }
 
     /**
diff --git a/src/QUI/ERP/Shipping/Rules/Factory.php b/src/QUI/ERP/Shipping/Rules/Factory.php
new file mode 100644
index 0000000..c20cb79
--- /dev/null
+++ b/src/QUI/ERP/Shipping/Rules/Factory.php
@@ -0,0 +1,164 @@
+<?php
+
+/**
+ * This file contains QUI\ERP\Shipping\Rules\Factory
+ */
+
+namespace QUI\ERP\Shipping\Rules;
+
+use QUI;
+use QUI\Permissions\Permission;
+
+/**
+ * Class Factory
+ *
+ * @package QUI\ERP\Shipping\Types
+ */
+class Factory extends QUI\CRUD\Factory
+{
+    /**
+     * Handler constructor.
+     */
+    public function __construct()
+    {
+        parent::__construct();
+
+        $self = $this;
+
+        $this->Events->addEvent('onCreateBegin', function () {
+            Permission::checkPermission('quiqqer.shipping.rule.create');
+        });
+
+        // create new translation var for the area
+        $this->Events->addEvent('onCreateEnd', function () use ($self) {
+            QUI\Translator::publish('quiqqer/shipping');
+        });
+    }
+
+    /**
+     * @param array $data
+     *
+     * @return ShippingRule
+     *
+     * @throws QUI\Exception
+     */
+    public function createChild($data = [])
+    {
+        if (!isset($data['active']) || !\is_integer($data['active'])) {
+            $data['active'] = 0;
+        }
+
+        if (!isset($data['purchase_quantity_from']) || !\is_integer($data['purchase_quantity_from'])) {
+            $data['purchase_quantity_from'] = 0;
+        }
+
+        if (!isset($data['purchase_quantity_until']) || !\is_integer($data['purchase_quantity_until'])) {
+            $data['purchase_quantity_until'] = 0;
+        }
+
+        if (!isset($data['priority']) || !\is_integer($data['priority'])) {
+            $data['priority'] = 0;
+        }
+
+        QUI::getEvents()->fireEvent('shippingRuleCreateBegin', [$data]);
+
+        /* @var $NewChild ShippingRule */
+        $NewChild = parent::createChild($data);
+
+        $this->createShippingLocale(
+            'shipping.'.$NewChild->getId().'.title',
+            ''
+        );
+
+        try {
+            QUI\Translator::publish('quiqqer/shipping');
+        } catch (QUI\Exception $Exception) {
+            QUI\System\Log::writeException($Exception);
+        }
+
+        QUI::getEvents()->fireEvent('shippingCreateEnd', [$NewChild]);
+
+        return $NewChild;
+    }
+
+    /**
+     * @return string
+     */
+    public function getDataBaseTableName()
+    {
+        return 'shipping_rules';
+    }
+
+    /**
+     * @return string
+     */
+    public function getChildClass()
+    {
+        return ShippingRule::class;
+    }
+
+    /**
+     * @return array
+     */
+    public function getChildAttributes()
+    {
+        return [
+            'id',
+            'active',
+
+            'date_from',
+            'date_until',
+            'purchase_quantity_from',
+            'purchase_quantity_until',
+            'purchase_value_from',
+            'purchase_value_until',
+            'priority',
+
+            'areas',
+            'articles',
+            'categories',
+            'user_groups'
+        ];
+    }
+
+    /**
+     * @param int $id
+     *
+     * @return QUI\ERP\Shipping\Api\AbstractShippingEntry
+     *
+     * @throws QUI\Exception
+     */
+    public function getChild($id)
+    {
+        /* @var QUI\ERP\Shipping\Api\AbstractShippingEntry $Shipping */
+        $Shipping = parent::getChild($id);
+
+        return $Shipping;
+    }
+
+    /**
+     * Creates a locale
+     *
+     * @param $var
+     * @param $title
+     */
+    protected function createShippingLocale($var, $title)
+    {
+        $current = QUI::getLocale()->getCurrent();
+
+        if (QUI::getLocale()->isLocaleString($title)) {
+            $parts = QUI::getLocale()->getPartsOfLocaleString($title);
+            $title = QUI::getLocale()->get($parts[0], $parts[1]);
+        }
+
+        try {
+            QUI\Translator::addUserVar('quiqqer/shipping', $var, [
+                $current   => $title,
+                'datatype' => 'php,js',
+                'package'  => 'quiqqer/shipping'
+            ]);
+        } catch (QUI\Exception $Exception) {
+            QUI\System\Log::addNotice($Exception->getMessage());
+        }
+    }
+}
diff --git a/src/QUI/ERP/Shipping/Rules/ShippingRule.php b/src/QUI/ERP/Shipping/Rules/ShippingRule.php
new file mode 100644
index 0000000..7afa2db
--- /dev/null
+++ b/src/QUI/ERP/Shipping/Rules/ShippingRule.php
@@ -0,0 +1,186 @@
+<?php
+
+/**
+ * This file contains QUI\ERP\Shipping\Rules\ShippingRule
+ */
+
+namespace QUI\ERP\Shipping\Rules;
+
+use QUI;
+use QUI\CRUD\Factory;
+use QUI\Permissions\Permission;
+
+use QUI\ERP\Areas\Utils as AreaUtils;
+use QUI\ERP\Shipping\Exceptions\ShippingCanNotBeUsed;
+
+/**
+ * Class ShippingEntry
+ * A user created shipping entry
+ *
+ * @package QUI\ERP\Shipping\Types
+ */
+class ShippingRule extends QUI\CRUD\Child
+{
+    /**
+     * Shipping constructor.
+     *
+     * @param int $id
+     * @param Factory $Factory
+     */
+    public function __construct($id, Factory $Factory)
+    {
+        parent::__construct($id, $Factory);
+
+        $this->Events->addEvent('onDeleteBegin', function () {
+            Permission::checkPermission('quiqqer.shipping.delete');
+        });
+
+        $this->Events->addEvent('onSaveBegin', function () {
+            Permission::checkPermission('quiqqer.shipping.edit');
+        });
+    }
+
+    /**
+     * is the user allowed to use this shipping
+     *
+     * @param QUI\Interfaces\Users\User $User
+     * @return boolean
+     */
+    public function canUsedBy(QUI\Interfaces\Users\User $User)
+    {
+        if ($this->isActive() === false) {
+            return false;
+        }
+
+        try {
+            QUI::getEvents()->fireEvent('quiqqerShippingCanUsedBy', [$this, $User]);
+        } catch (ShippingCanNotBeUsed $Exception) {
+            return false;
+        } catch (QUI\Exception $Exception) {
+            QUI\System\Log::writeDebugException($Exception);
+
+            return false;
+        }
+
+
+        // usage definitions / limits
+        $dateFrom  = $this->getAttribute('date_from');
+        $dateUntil = $this->getAttribute('date_until');
+        $now       = \time();
+
+        if ($dateFrom && \strtotime($dateFrom) > $now) {
+            return false;
+        }
+
+        if ($dateUntil && \strtotime($dateUntil) < $now) {
+            return false;
+        }
+
+        // assignment
+        $userGroupValue = $this->getAttribute('user_groups');
+        $areasValue     = $this->getAttribute('areas');
+
+        // if groups and areas are empty, everybody is allowed
+        if (empty($userGroupValue) && empty($areasValue)) {
+            return true;
+        }
+
+        // not in area
+        $areasValue = \explode(',', $areasValue);
+
+        if (!empty($areasValue) && !AreaUtils::isUserInAreas($User, $areasValue)) {
+            return false;
+        }
+
+        $userGroups = QUI\Utils\UserGroups::parseUsersGroupsString(
+            $this->getAttribute('user_groups')
+        );
+
+        $discountUsers  = $userGroups['users'];
+        $discountGroups = $userGroups['groups'];
+
+        if (empty($discountUsers) && empty($discountGroups)) {
+            return true;
+        }
+
+        // user checking
+        foreach ($discountUsers as $uid) {
+            if ($User->getId() == $uid) {
+                return true;
+            }
+        }
+
+        // group checking
+        $groupsOfUser = $User->getGroups();
+
+        /* @var $Group QUI\Groups\Group */
+        foreach ($discountGroups as $gid) {
+            foreach ($groupsOfUser as $Group) {
+                if ($Group->getId() == $gid) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
+     * is the shipping allowed in the order?
+     *
+     * @param QUI\ERP\Order\OrderInterface $Order
+     * @return bool
+     */
+    public function canUsedInOrder(QUI\ERP\Order\OrderInterface $Order)
+    {
+        try {
+            QUI::getEvents()->fireEvent('shippingCanUsedInOrder', [$this, $Order]);
+        } catch (ShippingCanNotBeUsed $Exception) {
+            return false;
+        } catch (QUI\Exception $Exception) {
+            QUI\System\Log::addDebug($Exception->getMessage());
+
+            return false;
+        }
+
+        return true;
+    }
+
+    // region activation / deactivation
+
+    /**
+     * Activate the shipping type
+     *
+     * @throws QUI\ExceptionStack|QUI\Exception
+     */
+    public function activate()
+    {
+        $this->setAttribute('active', 1);
+        $this->update();
+        $this->refresh();
+    }
+
+    /**
+     * Is the shipping active?
+     *
+     * @return bool
+     */
+    public function isActive()
+    {
+        return !!$this->getAttribute('active');
+    }
+
+    /**
+     * Deactivate the shipping type
+     *
+     * @throws QUI\ExceptionStack|QUI\Exception
+     */
+    public function deactivate()
+    {
+        $this->setAttribute('active', 0);
+        $this->update();
+        $this->refresh();
+    }
+
+    //endregion
+}
diff --git a/src/QUI/ERP/Shipping/Shipping.php b/src/QUI/ERP/Shipping/Shipping.php
index 10eaeae..60081fd 100644
--- a/src/QUI/ERP/Shipping/Shipping.php
+++ b/src/QUI/ERP/Shipping/Shipping.php
@@ -144,10 +144,6 @@ public function getShippingType($shippingType)
      */
     public function getShippingEntry($shippingId)
     {
-        if ((int)$shippingId == Methods\Free\Shipping::ID) {
-            return new Methods\Free\Shipping();
-        }
-
         try {
             return Factory::getInstance()->getChild($shippingId);
         } catch (QUI\Exception $Exception) {
diff --git a/src/QUI/ERP/Shipping/Types/Factory.php b/src/QUI/ERP/Shipping/Types/Factory.php
index bbfa815..d4c044e 100644
--- a/src/QUI/ERP/Shipping/Types/Factory.php
+++ b/src/QUI/ERP/Shipping/Types/Factory.php
@@ -45,23 +45,23 @@ public function __construct()
      */
     public function createChild($data = [])
     {
-        if (!isset($data['active']) || !is_integer($data['active'])) {
+        if (!isset($data['active']) || !\is_integer($data['active'])) {
             $data['active'] = 0;
         }
 
-        if (!isset($data['purchase_quantity_from']) || !is_integer($data['purchase_quantity_from'])) {
-            $data['purchase_quantity_from'] = 0;
-        }
-
-        if (!isset($data['purchase_quantity_until']) || !is_integer($data['purchase_quantity_until'])) {
-            $data['purchase_quantity_until'] = 0;
-        }
+//        if (!isset($data['purchase_quantity_from']) || !\is_integer($data['purchase_quantity_from'])) {
+//            $data['purchase_quantity_from'] = 0;
+//        }
+//
+//        if (!isset($data['purchase_quantity_until']) || !\is_integer($data['purchase_quantity_until'])) {
+//            $data['purchase_quantity_until'] = 0;
+//        }
 
-        if (!isset($data['priority']) || !is_integer($data['priority'])) {
+        if (!isset($data['priority']) || !\is_integer($data['priority'])) {
             $data['priority'] = 0;
         }
 
-        if (!isset($data['shipping_type']) || !class_exists($data['shipping_type'])) {
+        if (!isset($data['shipping_type']) || !\class_exists($data['shipping_type'])) {
             throw new QUI\ERP\Shipping\Exception([
                 'quiqqer/shipping',
                 'exception.create.shipping.class.not.found'
@@ -75,12 +75,12 @@ public function createChild($data = [])
 
         $this->createShippingLocale(
             'shipping.'.$NewChild->getId().'.title',
-            '[quiqqer/shipping] new.shipping.placeholder'
+            $NewChild->getShippingType()->getTitle()
         );
 
         $this->createShippingLocale(
             'shipping.'.$NewChild->getId().'.workingTitle',
-            '[quiqqer/shipping] new.shipping.placeholder'
+            $NewChild->getShippingType()->getTitle().' - '.$NewChild->getId()
         );
 
         $this->createShippingLocale(
@@ -125,19 +125,8 @@ public function getChildAttributes()
             'shipping_type',
             'active',
             'icon',
-
-            'date_from',
-            'date_until',
-            'purchase_quantity_from',
-            'purchase_quantity_until',
-            'purchase_value_from',
-            'purchase_value_until',
-            'priority',
-
-            'areas',
-            'articles',
-            'categories',
-            'user_groups'
+            'shipping_rules',
+            'priority'
         ];
     }
 
diff --git a/src/QUI/ERP/Shipping/Types/ShippingEntry.php b/src/QUI/ERP/Shipping/Types/ShippingEntry.php
index e239059..65bd54f 100644
--- a/src/QUI/ERP/Shipping/Types/ShippingEntry.php
+++ b/src/QUI/ERP/Shipping/Types/ShippingEntry.php
@@ -106,14 +106,14 @@ public function toArray()
     /**
      * Return the shipping type of the type
      *
-     * @return Api\AbstractShippingEntry
+     * @return Api\ShippingTypeInterface
      * @throws QUI\ERP\Shipping\Exception
      */
     public function getShippingType()
     {
         $type = $this->getAttribute('shipping_type');
 
-        if (!class_exists($type)) {
+        if (!\class_exists($type)) {
             throw new QUI\ERP\Shipping\Exception([
                 'quiqqer/shipping',
                 'exception.shipping.type.not.found',
@@ -123,7 +123,7 @@ public function getShippingType()
 
         $Type = new $type();
 
-        if (!($Type instanceof Api\AbstractShippingEntry)) {
+        if (!($Type instanceof Api\ShippingTypeInterface)) {
             throw new QUI\ERP\Shipping\Exception([
                 'quiqqer/shipping',
                 'exception.shipping.type.not.abstractShipping',
@@ -142,89 +142,7 @@ public function getShippingType()
      */
     public function canUsedBy(QUI\Interfaces\Users\User $User)
     {
-        if ($this->isActive() === false) {
-            return false;
-        }
-
-        try {
-            QUI::getEvents()->fireEvent('quiqqerShippingCanUsedBy', [$this, $User]);
-        } catch (ShippingCanNotBeUsed $Exception) {
-            return false;
-        } catch (QUI\Exception $Exception) {
-            QUI\System\Log::writeDebugException($Exception);
-
-            return false;
-        }
-
-
-        try {
-            $this->getShippingType();
-        } catch (QUI\Exception $Exception) {
-            QUI\System\Log::writeException($Exception);
-
-            return false;
-        }
-
-        // usage definitions / limits
-        $dateFrom  = $this->getAttribute('date_from');
-        $dateUntil = $this->getAttribute('date_until');
-        $now       = time();
-
-        if ($dateFrom && strtotime($dateFrom) > $now) {
-            return false;
-        }
-
-        if ($dateUntil && strtotime($dateUntil) < $now) {
-            return false;
-        }
-
-        // assignment
-        $userGroupValue = $this->getAttribute('user_groups');
-        $areasValue     = $this->getAttribute('areas');
-
-        // if groups and areas are empty, everybody is allowed
-        if (empty($userGroupValue) && empty($areasValue)) {
-            return true;
-        }
-
-        // not in area
-        $areasValue = explode(',', $areasValue);
-
-        if (!empty($areasValue) && !AreaUtils::isUserInAreas($User, $areasValue)) {
-            return false;
-        }
-
-        $userGroups = QUI\Utils\UserGroups::parseUsersGroupsString(
-            $this->getAttribute('user_groups')
-        );
-
-        $discountUsers  = $userGroups['users'];
-        $discountGroups = $userGroups['groups'];
-
-        if (empty($discountUsers) && empty($discountGroups)) {
-            return true;
-        }
-
-        // user checking
-        foreach ($discountUsers as $uid) {
-            if ($User->getId() == $uid) {
-                return true;
-            }
-        }
-
-        // group checking
-        $groupsOfUser = $User->getGroups();
-
-        /* @var $Group QUI\Groups\Group */
-        foreach ($discountGroups as $gid) {
-            foreach ($groupsOfUser as $Group) {
-                if ($Group->getId() == $gid) {
-                    return true;
-                }
-            }
-        }
-
-        return false;
+        // @todo check shipping rules
     }
 
     /**
-- 
GitLab