Ejemplo n.º 1
0
 public function isValid($value, $context = null)
 {
     $registry = Zend_Registry::getInstance();
     $signedUserInfo = $registry->get("signedUserInfo");
     $valueString = (string) $value;
     $this->_setValue($valueString);
     if (mb_strlen($value) > 16) {
         $this->_error(self::INVALID_Redeem);
         return false;
     }
     if (empty($value)) {
         $this->_error(self::EMPTY_Redeem);
         return false;
     }
     $coupons = Ml_Model_Coupons::getInstance();
     $token = $coupons->get($value);
     if (!$token) {
         $this->_error(self::NOTFOUND_Redeem);
         return false;
     }
     if (!$token['active']) {
         $this->_error(self::USED_Redeem);
         return false;
     }
     if (!$token['unique_use']) {
         $credits = Ml_Model_Credits::getInstance();
         $isItUsed = $credits->getCouponRedeemed($signedUserInfo['id'], $token['id']);
         if ($isItUsed) {
             $this->_error(self::YUSED_Redeem);
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 2
0
 public function orderAction()
 {
     $registry = Zend_Registry::getInstance();
     $config = $registry->get("config");
     $signedUserInfo = $registry->get("signedUserInfo");
     $request = $this->getRequest();
     $orderPid = $request->getUserParam("order_pid");
     $credits = Ml_Model_Credits::getInstance();
     $order = $credits->getByPid($orderPid);
     if (!$order || $order['uid'] != $signedUserInfo['id']) {
         $registry->set("notfound", true);
         throw new Exception("Order doesn't exists.");
     }
     if ($order['reason_type'] == 'redeem') {
         $coupons = Ml_Model_Coupons::getInstance();
         $this->view->orderCoupon = $coupons->getById($order['reason_id']);
     }
     $this->view->order = $order;
 }