public function init() { parent::init(); Plugin::getEventManager()->trigger('controller.init', $this); $this->view->setScriptPath(array_merge($this->view->getScriptPaths(), array(PIMCORE_WEBSITE_PATH . '/views/scripts/', PIMCORE_WEBSITE_PATH . '/views/layouts/', PIMCORE_WEBSITE_PATH . '/views/scripts/coreshop/'))); $this->view->addHelperPath(CORESHOP_PATH . '/lib/CoreShop/View/Helper', 'CoreShop\\View\\Helper'); $this->session = $this->view->session = Tool::getSession(); /* if(!$this->session->country instanceof CoreShopCountry) { if($this->session->user instanceof \CoreShop\Plugin\User && count($this->session->user->getAddresses()) > 0) { $this->session->country = $this->session->user->getAddresses()->get(0)->getCountry(); } else $this->session->country = Tool::getCountry(); } */ if ($this->getParam("currency")) { if (Currency::getById($this->getParam("currency")) instanceof Currency) { $this->session->currencyId = $this->getParam("currency"); } } $this->view->country = Tool::getCountry(); $this->enableLayout(); $this->setLayout(Plugin::getLayout()); $this->prepareCart(); $this->view->isShop = true; }
/** * Check if Cart is Valid for Condition * * @param Cart $cart * @param PriceRule $priceRule * @param bool|false $throwException * @return bool * @throws \Exception */ public function checkCondition(Cart $cart, PriceRule $priceRule, $throwException = false) { if ($this->getCountry()->getId() !== Tool::getCountry()->getId()) { if ($throwException) { throw new \Exception("You cannot use this voucher in your country of delivery"); } else { return false; } } return true; }
/** * Calculate Product Price * * @depcreated: Should be replaced with PriceRules * * @return float|mixed * @throws \Exception */ public function getProductPrice() { $cacheKey = "coreshop_product_price_" . $this->getId(); if ($price = \Pimcore\Model\Cache::load($cacheKey)) { return $price; } $price = $this->getPrice(); if (count($this->getSpecificPrice()) > 0) { $session = Tool::getSession(); //Process Specific Prices foreach ($this->getSpecificPrice() as $sPrice) { $date = \Zend_Date::now(); $hasCustomer = false; $hasCountry = false; $hasCurrency = false; if ($sPrice->getFrom() instanceof \Zend_Date) { if ($date->get(\Zend_Date::TIMESTAMP) < $sPrice->getFrom()->get(\Zend_Date::TIMESTAMP)) { continue; } } if ($sPrice->getTo() instanceof \Zend_Date) { if ($date->get(\Zend_Date::TIMESTAMP) > $sPrice->getTo()->get(\Zend_Date::TIMESTAMP)) { continue; } } if (count($sPrice->getCustomers()) > 0 && $session->user instanceof CoreShopUser) { foreach ($sPrice->getCustomers() as $cust) { if ($cust->getId() == $session->user->getId()) { $hasCustomer = true; } } } else { if (count($sPrice->getCustomers()) == 0) { //Non is selected means all Users $hasCustomer = true; } } if (count($sPrice->getCountries()) > 0 && Tool::objectInList(Tool::getCountry(), $sPrice->getCountries())) { $hasCountry = true; } else { if (count($sPrice->getCountries()) == 0) { //Non selected means all $hasCountry = true; } } if (count($sPrice->getCurrencies()) > 0 && Tool::objectInList(Tool::getCurrency(), $sPrice->getCurrencies())) { $hasCurrency = true; } else { if (count($sPrice->getCountries()) == 0) { //Non selected means all $hasCurrency = true; } } if ($hasCountry && $hasCustomer && $hasCurrency) { $price = $this->applySpecificPrice($sPrice); break; } } } return Tool::convertToCurrency($price); }