/**
     * @service coupon read
     * @param $fields
     * @return Gpf_Rpc_Form
     */
    public function load(Gpf_Rpc_Params $params) {
        $form = new Gpf_Rpc_Form($params);
        $form->addField(Pap_Db_Table_Coupons::CODE, null);

        $coupon = new Pap_Db_Coupon();
        $coupon->setId($form->getFieldValue(Gpf_View_FormService::ID));
        $coupon->setCode($form->getFieldValue(Gpf_View_FormService::ID));
        $banner = new Pap_Features_Coupon_Coupon();
        $affiliate = new Pap_Affiliates_User();

        try {
            $this->loadCoupon($coupon);
            if (!$coupon->isValid()) {
                return $form;
            }
            $banner->setPrimaryKeyValue($coupon->getBannerID());
            $banner->load();
            $affiliate->setPrimaryKeyValue($coupon->getUserID());
            $affiliate->load();
            $form->addField('couponid', $coupon->getId());
            $form->addField('couponcode', $coupon->getCode());
            $form->addField('name', $banner->getName());
            $form->addField('description', $banner->getData1());
            $this->fillFromUser($form, $affiliate);
            
            Gpf_Plugins_Engine::extensionPoint('PostAffiliate.OfflineSaleForm.load', $form);
            
        } catch (Gpf_Exception $e) {
        }

        return $form;
    }
 protected function insertCoupon(Pap_Db_Coupon $coupon) {
     $coupon->setCode($this->generator->generate());
     parent::insertCoupon($coupon);
 }
示例#3
0
 /**
  * @throws Gpf_DbEngine_NoRowException
  * @throws Gpf_DbEngine_TooManyRowsException
  * @param $couponCode
  */
 protected function getCoupon($couponCode) {
     $coupon = new Pap_Db_Coupon();
     $coupon->setCode($couponCode);
     $coupon->loadFromCode();
     return $coupon;
 }
 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());
 }