/** * 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); }