/** * Converts value from currency to currency * * @param $value * @param Currency|null $toCurrency * @param Currency|null $fromCurrency * @return mixed */ public static function convertToCurrency($value, Currency $toCurrency = null, Currency $fromCurrency = null) { $config = Config::getConfig(); $configArray = $config->toArray(); if (!$fromCurrency instanceof Currency) { $fromCurrency = Currency::getById($configArray['base']['base-currency']); } if (!$toCurrency instanceof Currency) { $toCurrency = Tool::getCurrency(); } if ($fromCurrency instanceof Currency) { if ($toCurrency instanceof Currency && $toCurrency->getId() != $fromCurrency->getId()) { return $value * $toCurrency->getExchangeRate(); } } return $value; }
/** * 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) { //Check Cart Amount if ($this->getMinAmount() > 0) { $minAmount = $this->getMinAmount(); $minAmount = Tool::convertToCurrency($minAmount, $this->getCurrency(), Tool::getCurrency()); $cartTotal = $cart->getSubtotal(); if ($minAmount > $cartTotal) { if ($throwException) { throw new \Exception("You have not reached the minimum amount required to use this voucher"); } else { return false; } } } return true; }
public function paymentAction() { $configkey = \CoreShop\Model\Configuration::get('SOFORTUEBERWEISUNG.KEY'); $sofort = new \Sofort\SofortLib\Sofortueberweisung($configkey); $sofort->setAmount(Tool::numberFormat($this->cart->getTotal())); $sofort->setVersion('CoreShop ' . \CoreShop\Version::getVersion()); $sofort->setReason('Buy Order (CoreShop)'); $sofort->setCurrencyCode(Tool::getCurrency()->getIsoCode()); $sofort->setSuccessUrl(Pimcore\Tool::getHostUrl() . $this->getModule()->url($this->getModule()->getIdentifier(), 'payment-return')); $sofort->setAbortUrl(Pimcore\Tool::getHostUrl() . $this->getModule()->url($this->getModule()->getIdentifier(), 'payment-return-abort')); $sofort->sendRequest(); if ($sofort->isError()) { var_dump($sofort); die('error'); } else { $transactionId = $sofort->getTransactionId(); $this->cart->setCustomIdentifier($transactionId); $this->cart->save(); $this->redirect($sofort->getPaymentUrl()); } }
/** * Calculate discount * * @param Model\Object\CoreShopCart $cart * @return int */ public function getDiscount(Model\Object\CoreShopCart $cart) { return Tool::convertToCurrency($this->getAmount(), $this->getCurrency(), Tool::getCurrency()); }
/** * Calculate discount * * @param CoreShopCart $cart * @return int */ public function getDiscount(CoreShopCart $cart) { $discount = Tool::convertToCurrency($this->getGift()->getProductPrice(), Tool::getCurrency()); return $discount; }
/** * 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); }