Пример #1
0
 /**
  * Returns a rule form if needed
  * @access public
  * @param  object $objModule
  * @return string
  */
 public function getCouponForm($objModule)
 {
     $arrCoupons = deserialize(Isotope::getCart()->coupons);
     if (!is_array($arrCoupons)) {
         $arrCoupons = array();
     }
     $strCoupon = \Input::get('coupon_' . $objModule->id);
     if ($strCoupon == '') {
         $strCoupon = \Input::get('coupon');
     }
     if ($strCoupon != '') {
         $objRule = Rule::findOneByCouponCode($strCoupon, Isotope::getCart()->getItems());
         if (null === $objRule) {
             $_SESSION['COUPON_FAILED'][$objModule->id] = sprintf($GLOBALS['TL_LANG']['MSC']['couponInvalid'], $strCoupon);
         } else {
             if (in_array(strtolower($strCoupon), array_map('strtolower', $arrCoupons))) {
                 $_SESSION['COUPON_FAILED'][$objModule->id] = sprintf($GLOBALS['TL_LANG']['MSC']['couponDuplicate'], $strCoupon);
             } else {
                 $arrCoupons[] = $objRule->code;
                 Isotope::getCart()->coupons = serialize($arrCoupons);
                 Isotope::getCart()->save();
                 $_SESSION['COUPON_SUCCESS'][$objModule->id] = sprintf($GLOBALS['TL_LANG']['MSC']['couponApplied'], $objRule->code);
             }
         }
         \Controller::redirect(preg_replace('@[?&]coupon(_[0-9]+)?=[^&]*@', '', \Environment::get('request')));
     }
     $objRules = Rule::findForCartWithCoupons();
     if (null === $objRules) {
         return '';
     }
     //build template
     $objTemplate = new \Isotope\Template('iso_coupons');
     $objTemplate->id = $objModule->id;
     $objTemplate->action = \Environment::get('request');
     $objTemplate->headline = $GLOBALS['TL_LANG']['MSC']['couponHeadline'];
     $objTemplate->inputLabel = $GLOBALS['TL_LANG']['MSC']['couponLabel'];
     $objTemplate->sLabel = $GLOBALS['TL_LANG']['MSC']['couponApply'];
     $objTemplate->usedCoupons = $arrCoupons;
     $objTemplate->rules = $objRules;
     if ($_SESSION['COUPON_FAILED'][$objModule->id] != '') {
         $objTemplate->message = $_SESSION['COUPON_FAILED'][$objModule->id];
         $objTemplate->mclass = 'failed';
         unset($_SESSION['COUPON_FAILED']);
     } elseif ($_SESSION['COUPON_SUCCESS'][$objModule->id] != '') {
         $objTemplate->message = $_SESSION['COUPON_SUCCESS'][$objModule->id];
         $objTemplate->mclass = 'success';
         unset($_SESSION['COUPON_SUCCESS']);
     }
     return $objTemplate->parse();
 }