コード例 #1
0
ファイル: Resource.php プロジェクト: ascertain/NGshop
 public function load()
 {
     $tokens = array();
     $unitIds = $this->db->fetchAll("SELECT * FROM " . OnlineShop_Framework_VoucherService_Token_Resource::TABLE_NAME . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     foreach ($unitIds as $row) {
         $item = new OnlineShop_Framework_VoucherService_Token();
         $item->getResource()->assignVariablesToModel($row);
         $tokens[] = $item;
     }
     $this->model->setTokens($tokens);
     return $tokens;
 }
コード例 #2
0
 /**
  * Only token per cart setting
  *
  * @param OnlineShop_Framework_ICart $cart
  *
  * @throws Exception
  */
 protected function checkOnlyToken(OnlineShop_Framework_ICart $cart)
 {
     $cartCodes = $cart->getVoucherTokenCodes();
     $cartVoucherCount = sizeof($cartCodes);
     if ($cartVoucherCount && method_exists($this->configuration, 'getOnlyTokenPerCart')) {
         if ($this->configuration->getOnlyTokenPerCart()) {
             throw new OnlineShop_Framework_Exception_VoucherServiceException("OnlyTokenPerCart: This token is only allowed as only token in this cart.", 6);
         }
         $cartToken = OnlineShop_Framework_VoucherService_Token::getByCode($cartCodes[0]);
         $cartTokenSettings = Object_OnlineShopVoucherSeries::getById($cartToken->getVoucherSeriesId())->getTokenSettings()->getItems()[0];
         if ($cartTokenSettings->getOnlyTokenPerCart()) {
             throw new OnlineShop_Framework_Exception_VoucherServiceException("OnlyTokenPerCart: There is a token of type onlyToken in your this cart already.", 7);
         }
     }
 }
コード例 #3
0
ファイル: VoucherToken.php プロジェクト: ascertain/NGshop
 /**
  * @param OnlineShop_Framework_Pricing_IEnvironment $environment
  *
  * @return boolean
  */
 public function check(OnlineShop_Framework_Pricing_IEnvironment $environment)
 {
     if (!($cart = $environment->getCart())) {
         return false;
     }
     $voucherTokenCodes = $cart->getVoucherTokenCodes();
     if (is_array($voucherTokenCodes)) {
         foreach ($voucherTokenCodes as $code) {
             if (in_array(OnlineShop_Framework_VoucherService_Token::getByCode($code)->getVoucherSeriesId(), $this->whiteListIds)) {
                 return true;
             }
         }
     }
     return false;
 }
コード例 #4
0
ファイル: Pattern.php プロジェクト: ascertain/NGshop
 /**
  * @param string $code
  * @param OnlineShop_Framework_ICart $cart
  * @param OnlineShop_Framework_AbstractOrder $order
  *
  * @throws Exception
  *
  * @return bool|\Pimcore\Model\Object\OnlineShopVoucherToken
  */
 public function applyToken($code, OnlineShop_Framework_ICart $cart, OnlineShop_Framework_AbstractOrder $order)
 {
     if ($token = OnlineShop_Framework_VoucherService_Token::getByCode($code)) {
         if ($token->isUsed()) {
             throw new Exception('Token has already been used.', 1);
         }
         if ($token->apply()) {
             $orderToken = new \Pimcore\Model\Object\OnlineShopVoucherToken();
             $orderToken->setTokenId($token->getId());
             $orderToken->setToken($token->getToken());
             $series = \Pimcore\Model\Object\OnlineShopVoucherSeries::getById($token->getVoucherSeriesId());
             $orderToken->setVoucherSeries($series);
             $orderToken->setParent($series);
             $orderToken->setKey(\Pimcore\File::getValidFilename($token->getToken()));
             $orderToken->setPublished(1);
             $orderToken->save();
             return $orderToken;
         }
     }
     return false;
 }
コード例 #5
0
ファイル: Default.php プロジェクト: ascertain/NGshop
 /**
  * @param $code
  * @return bool|OnlineShop_Framework_VoucherService_ITokenManager
  */
 public function getTokenManager($code)
 {
     if ($token = OnlineShop_Framework_VoucherService_Token::getByCode($code)) {
         if ($series = \Pimcore\Model\Object\OnlineShopVoucherSeries::getById($token->getVoucherSeriesId())) {
             return $series->getTokenManager();
         }
     }
     return false;
 }
コード例 #6
0
ファイル: Single.php プロジェクト: ascertain/NGshop
 /**
  * @param string $code
  * @param OnlineShop_Framework_ICart $cart
  * @return bool
  */
 public function checkToken($code, OnlineShop_Framework_ICart $cart)
 {
     parent::checkToken($code, $cart);
     if ($token = OnlineShop_Framework_VoucherService_Token::getByCode($code)) {
         if ($token->check($this->configuration->getUsages())) {
             return true;
         }
     }
     return false;
 }