Esempio n. 1
0
 /**
  * @throws OnlineShop_Framework_Exception_UnsupportedException
  */
 public function calculate()
 {
     //sum up all item prices
     $subTotal = 0;
     $currency = null;
     foreach ($this->cart->getItems() as $item) {
         if (is_object($item->getPrice())) {
             if (!$currency) {
                 $currency = $item->getPrice()->getCurrency();
             }
             if ($currency->compare($item->getPrice()->getCurrency()) != 0) {
                 throw new OnlineShop_Framework_Exception_UnsupportedException("Different currencies within one cart are not supported");
             }
             $subTotal += $item->getTotalPrice()->getAmount();
         }
     }
     //by default currency is retrieved from item prices. if there are no items, its loaded from the default locale defined in the environment
     if (!$currency) {
         $currency = $this->getDefaultCurrency();
     }
     $this->subTotal = $this->getDefaultPriceObject($subTotal, $currency);
     //consider all price modificators
     $currentSubTotal = $this->getDefaultPriceObject($subTotal, $currency);
     $this->modifications = array();
     foreach ($this->modificators as $modificator) {
         /* @var OnlineShop_Framework_ICartPriceModificator $modificator */
         $modification = $modificator->modify($currentSubTotal, $this->cart);
         if ($modification !== null) {
             $this->modifications[$modificator->getName()] = $modification;
             $currentSubTotal->setAmount($currentSubTotal->getAmount() + $modification->getAmount());
         }
     }
     $this->gradTotal = $currentSubTotal;
     $this->isCalculated = true;
 }
Esempio n. 2
0
 /**
  * remove item from wishlist
  */
 public function removeAction()
 {
     // remove item from wishlist
     if ($id = $this->getParam('item')) {
         $this->wishlist->removeItem($id);
         $this->wishlist->save();
     }
     // its a ajax request?
     if ($this->getRequest()->isXmlHttpRequest()) {
         $this->_helper->json(array());
     } else {
         $url = $this->view->url(array('action' => 'list'), 'wishlist');
         $this->redirect($url);
     }
 }
Esempio n. 3
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);
         }
     }
 }
Esempio n. 4
0
 /**
  * @param string $code
  * @param OnlineShop_Framework_ICart $cart
  * @return bool
  */
 public static function releaseToken($code, OnlineShop_Framework_ICart $cart = null)
 {
     $db = \Pimcore\Resource::get();
     $query = "DELETE FROM " . OnlineShop_Framework_VoucherService_Reservation_Resource::TABLE_NAME . " WHERE token = ?";
     $params[] = $code;
     if (isset($cart)) {
         $query .= " AND cart_id = ?";
         $params[] = $cart->getId();
     }
     try {
         $db->query($query, $params);
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
Esempio n. 5
0
 /**
  * @param string $code
  * @param OnlineShop_Framework_ICart $cart
  * @return bool|string
  */
 public function get($code, OnlineShop_Framework_ICart $cart = null)
 {
     $query = "SELECT * FROM " . self::TABLE_NAME . " WHERE token = ?";
     $params[] = $code;
     if (isset($cart)) {
         $query .= " AND cart_id = ?";
         $params[] = $cart->getId();
     }
     try {
         $result = $this->db->fetchRow($query, $params);
         if (empty($result)) {
             //                throw new Exception("Reservation for token " . $code . " not found.");
             return false;
         }
         $this->assignVariablesToModel($result);
         $this->model->setValue('id', $result['id']);
         $this->model->setCartId($result['cart_id']);
         return true;
     } catch (Exception $e) {
         var_dump($e);
         return false;
     }
 }
Esempio n. 6
0
 /**
  * Remove a voucher token from cart, sets error messages and
  * redirects to list action.
  */
 public function releasevoucherAction()
 {
     $voucherError = "";
     if ($code = $this->getParam('voucherToken')) {
         try {
             $this->cart->removeVoucherToken($code);
         } catch (OnlineShop_Framework_Exception_VoucherServiceException $e) {
             $voucherError = $this->view->t('cart.msg-error.' . $e->getCode());
         }
     } else {
         $voucherError = $this->view->t('cart.msg-error-token-missing');
     }
     $url = $this->view->url(array('action' => 'list', 'voucherError' => $voucherError), 'cart');
     $this->redirect($url);
 }
Esempio n. 7
0
 /**
  * @throws OnlineShop_Framework_Exception_InvalidConfigException
  * @param OnlineShop_Framework_ICart $cart
  * @param string $name optional name of checkout manager, in case there are more than one configured
  * @return OnlineShop_Framework_ICheckoutManager
  */
 public function getCheckoutManager(OnlineShop_Framework_ICart $cart, $name = null)
 {
     if (empty($this->checkoutManagers[$cart->getId()])) {
         if ($name) {
             $managerConfigName = "checkoutmanager_" . $name;
             $manager = new $this->config->onlineshop->{$managerConfigName}->class($cart, $this->config->onlineshop->{$managerConfigName}->config);
             if (!$manager instanceof OnlineShop_Framework_ICheckoutManager) {
                 throw new OnlineShop_Framework_Exception_InvalidConfigException("Checkoutmanager class " . $this->config->onlineshop->{$managerConfigName}->class . " does not implement OnlineShop_Framework_ICheckoutManager.");
             }
         } else {
             $manager = new $this->config->onlineshop->checkoutmanager->class($cart, $this->config->onlineshop->checkoutmanager->config);
             if (!$manager instanceof OnlineShop_Framework_ICheckoutManager) {
                 throw new OnlineShop_Framework_Exception_InvalidConfigException("Checkoutmanager class " . $this->config->onlineshop->checkoutmanager->class . " does not implement OnlineShop_Framework_ICheckoutManager.");
             }
         }
         $this->checkoutManagers[$cart->getId()] = $manager;
     }
     return $this->checkoutManagers[$cart->getId()];
 }
 public function setCart(OnlineShop_Framework_ICart $cart)
 {
     $this->cart = $cart;
     $this->cartId = $cart->getId();
 }
Esempio n. 9
0
 public function getOffersForCart(OnlineShop_Framework_ICart $cart)
 {
     $offerListClass = $this->offerClass . "_List";
     $list = new $offerListClass();
     $list->setCondition("cartId = ?", array($cart->getId()));
     return $list->load();
 }
Esempio n. 10
0
 protected function applyVoucherTokens(OnlineShop_Framework_AbstractOrder $order, OnlineShop_Framework_ICart $cart)
 {
     $voucherTokens = $cart->getVoucherTokenCodes();
     if (is_array($voucherTokens)) {
         $service = OnlineShop_Framework_Factory::getInstance()->getVoucherService();
         foreach ($voucherTokens as $code) {
             $service->applyToken($code, $cart, $order);
         }
     }
 }