예제 #1
0
 public function syncPromoCode()
 {
     $config = $this->getConfigValues(get_class($this));
     $strPromoCode = $config['promocode'];
     //Entered promo code
     $objPromoCode = PromoCode::LoadByShipping(get_class($this));
     if (!$objPromoCode) {
         //If we're this far without an object, create one
         $objPromoCode = new PromoCode();
         $objPromoCode->lscodes = "shipping:,";
         $objPromoCode->exception = 0;
         $objPromoCode->enabled = 1;
         $objPromoCode->module = get_class($this);
     }
     //Sync any fields with the promo code table
     if (strlen($strPromoCode) == 0) {
         $strPromoCode = get_class($this) . ":";
     }
     $objPromoCode->code = $strPromoCode;
     $objPromoCode->valid_from = isset($config['startdate']) && !empty($config['startdate']) ? $config['startdate'] : null;
     $objPromoCode->valid_until = isset($config['enddate']) && !empty($config['enddate']) ? $config['enddate'] : null;
     $objPromoCode->amount = 0;
     $objPromoCode->type = PromoCodeType::Percent;
     //Needs to be 0% so UpdatePromoCode() returns valid test
     $objPromoCode->threshold = $config['rate'] == "" ? "0" : $config['rate'];
     if ($config['qty_remaining'] == '') {
         $objPromoCode->qty_remaining = -1;
     } else {
         $objPromoCode->qty_remaining = $config['qty_remaining'];
     }
     $objPromoCode->save();
 }
 /**
  * Make sure at least one module is active, otherwise throw warning
  */
 public function verifyActive()
 {
     $objModules = Modules::model()->findAllByAttributes(array('category' => 'shipping', 'active' => 1));
     if (count($objModules) == 0) {
         Yii::app()->user->setFlash('error', Yii::t('admin', 'WARNING: You have no shipping modules activated. No one can checkout.'));
     } else {
         $blnRestrictionWarning = false;
         foreach ($objModules as $objModule) {
             if ($objModule->active) {
                 if ($blnRestrictionWarning) {
                     $objPromo = PromoCode::LoadByShipping($objModule->module);
                     if (!$objPromo instanceof Promocode || !$objPromo->enabled) {
                         //nothing defined or turned off
                         $blnRestrictionWarning = false;
                     }
                 }
             }
             if ($blnRestrictionWarning) {
                 Yii::app()->user->setFlash('warning', Yii::t('admin', 'WARNING: You have product restrictions set on all active shipping modules. This could lead to a scenario where a customer orders an item and no shipping method applies. Check your restrictions carefully to avoid gaps in coverage.'));
             }
         }
     }
 }
예제 #3
0
 protected function checkAffected()
 {
     $objPromoCode = PromoCode::LoadByShipping(get_class($this));
     if ($objPromoCode) {
         if (strpos($objPromoCode->code, ":") !== false) {
             //This is restriction without actually using a code
             $cart = $this->objCart;
             $bolApplied = true;
             if ($objPromoCode) {
                 foreach ($cart->cartItems as $objItem) {
                     if (!$objPromoCode->IsProductAffected($objItem)) {
                         $bolApplied = false;
                     } elseif ($objPromoCode->exception == 2) {
                         return true;
                     }
                 }
             }
             //Scenario if just one item qualifies the shipping
             return $bolApplied;
         }
     }
     return true;
 }