private function setRecognizedParams(Pap_Contexts_Action $context) { $context->setUserObject($this->affiliate); $context->setBannerObject($this->banner); $context->setCampaignObject($this->campaign); $context->setAccountId($this->campaign->getAccountId(), Pap_Contexts_Tracking::ACCOUNT_RECOGNIZED_FROM_CAMPAIGN); $context->setTrackingMethod(Pap_Common_Transaction::TRACKING_METHOD_COUPON); $context->getTransaction()->setCouponId($this->coupon->getId()); $context->getTransaction()->set(Pap_Db_Table_Transactions::BANNER_ID, $this->banner->getId()); }
protected function insertCoupon(Pap_Db_Coupon $coupon) { $coupon->setCode($this->generator->generate()); parent::insertCoupon($coupon); }
protected function onConstraintException(Pap_Db_Coupon $coupon) { throw new Gpf_Exception($this->_('Importing coupons was stopped, because coupon code %s already exists', $coupon->getCode())); }
public function getCouponText(Pap_Db_Coupon $coupon) { $couponFormat = $this->getData3(); $couponFormat = str_replace('{$couponcode}', $coupon->getCode(), $couponFormat); $couponFormat = str_replace('{$couponid}', $coupon->getId(), $couponFormat); $couponFormat = str_replace('{$validfrom}', $coupon->get(Pap_Db_Table_Coupons::VALID_FROM), $couponFormat); $couponFormat = str_replace('{$validto}', $coupon->get(Pap_Db_Table_Coupons::VALID_TO), $couponFormat); $couponFormat = str_replace('{$limituse}', ($coupon->get(Pap_Db_Table_Coupons::MAX_USE_COUNT) == 0 ? $this->_('unlimited') : $coupon->get(Pap_Db_Table_Coupons::MAX_USE_COUNT)), $couponFormat); if (strstr($couponFormat, '{$barcodeimage}') !== false) { $barCode = new Gpf_BarCode_BarCode(); $couponFormat = str_replace('{$barcodeimage}', $barCode->getLink($coupon->getId()), $couponFormat); } if (strstr($couponFormat, '{$qrcodeimage}') !== false) { $QrCode = new Gpf_QrCode_QrCode(); $couponFormat = str_replace('{$qrcodeimage}', $QrCode->getLink($coupon->getCode()), $couponFormat); } return $couponFormat; }
/** * @throws Gpf_DbEngine_NoRowException * @throws Gpf_DbEngine_TooManyRowsException */ private function loadCoupon(Pap_Db_Coupon $coupon) { try { $coupon->load(); return; } catch (Gpf_DbEngine_NoRowException $e) { } $coupon->loadFromCode(); }
private function replaceConstants(Gpf_Data_Record $row) { $coupon = new Pap_Db_Coupon(); $coupon->setId($row->get('id')); $coupon->setCode($row->get('code')); $coupon->setStatus($row->get('status')); $coupon->set(Pap_Db_Table_Coupons::MAX_USE_COUNT, $row->get('limit_use')); $coupon->set(Pap_Db_Table_Coupons::VALID_FROM, $row->get('valid_from')); $coupon->set(Pap_Db_Table_Coupons::VALID_TO, $row->get('valid_to')); $row->add('coupon', $this->banner->getCouponText($coupon)); $row->add('validity', $coupon->isValid()); }
public function replaceConstants($text, $constantPrefix = '{$coupon_', $userID) { $constantPrefixLenght = strlen($constantPrefix); $constantLenght = $constantPrefixLenght + 9; $offset = 0; while (($start = strpos($text, $constantPrefix, $offset)) !== false && strlen(substr($text, $start)) >= $constantLenght) { $offset = $start + $constantLenght; $couponConstant = substr($text, $start, $constantLenght); $bannerID = substr($couponConstant, $constantPrefixLenght, -1); try { $couponBanner = $this->getCouponBanner($bannerID); } catch (Gpf_Exception $e) { continue; } foreach ($this->getCoupons($bannerID, $userID) as $couponData) { $coupon = new Pap_Db_Coupon(); $coupon->fillFromRecord($couponData); if ($constantPrefix == '{$coupon_') { $couponText = $couponBanner->getCouponText($coupon); $text = str_replace($couponConstant, $couponText, $text); $offset = $start + strlen($couponText); continue; } $text = str_replace($couponConstant, $coupon->getCode(), $text); $offset = $start + strlen($coupon->getCode()); } } return $text; }
protected function insertCoupon(Pap_Db_Coupon $coupon) { for ($i = 0; $i < self::MAX_REGENERATE_CODE_COUNT; $i++) { try { $coupon->insert(); return; } catch (Gpf_DbEngine_Row_ConstraintException $e) { $this->onConstraintException($coupon); } catch (Gpf_DbEngine_DuplicateEntryException $e) { $coupon->generateCouponID(); } } throw new Gpf_Exception($this->getOnFailMessage()); }