/** * Changes the currency_code into the right virtuemart_currency_id * For exampel 'currency_code_3' : EUR => 47 * * @author Max Milbers * @author Kohl Patrick */ function getCurrencyIdByField($value = 0, $fieldName = 'currency_code_3') { if (is_string($value)) { if (!class_exists('ShopFunctions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'; } return ShopFunctions::getCurrencyIDByName($value, $fieldName); } return $value; }
/** * @static * @param $price * @param string $toCurrency * @return float */ static function convertPrice($price, $fromCurrency, $toCurrency = '', $cartPricesCurrency = '') { if (!(is_int($toCurrency) or is_numeric($toCurrency)) && !empty($toCurrency)) { $toCurrency = ShopFunctions::getCurrencyIDByName($toCurrency); } if ($fromCurrency == $toCurrency) { return $price; } // product prices or total in cart is always in vendor currency $priceInNewCurrency = vmPSPlugin::getAmountInCurrency($price, $toCurrency); // set back the currency display if (empty($cartPricesCurrency)) { $cartPricesCurrency = $fromCurrency; } $cd = CurrencyDisplay::getInstance($cartPricesCurrency); vmDebug('convertPrice', $price, $toCurrency, $fromCurrency, $cartPricesCurrency, $priceInNewCurrency); return $priceInNewCurrency['value']; }
/** * @return delivery cost for the shipping method instance * @author Zasilkovna */ function getCosts(VirtueMartCart $cart, $method, $cart_prices) { //get actual display currency. in $cart->pricesCurrency its not updated immediately.. but if we dont use change currency, getUserStateFromRequest doesnt return anything.. so then use cart pricesCurrency $currency = CurrencyDisplay::getInstance(); $pricesCurrencyId = $currency->_app->getUserStateFromRequest('virtuemart_currency_id', 'virtuemart_currency_id', $currency->_vendorCurrency); if (empty($pricesCurrencyId)) { //this is pretty weird $pricesCurrencyId = $cart->pricesCurrency; } $pobocka = $this->getSelectedPobocka(); if (empty($pobocka)) { return 0; } require_once dirname(__FILE__) . DS . 'helper.php'; $pobockaObj = UlozenkaHelper::getDataPobocky($method, $pobocka); $parcel_price = 'parcelprice' . $pobocka; $dobierka_price = 'codprice' . $pobocka; $price = $method->pobocky->{$parcel_price}; if (!class_exists('ShopFunctions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'; } $cid = ShopFunctions::getCurrencyIDByName("CZK"); /* Set free shipping */ $total = $cart->pricesUnformatted['billTotal']; if (!empty($cart->pricesUnformatted['salesPriceShipment'])) { $total -= (double) $cart->pricesUnformatted['salesPriceShipment']; } if (!empty($cart->pricesUnformatted['salesPricePayment'])) { $total -= (double) $cart->pricesUnformatted['salesPricePayment']; } if (!empty($pobockaObj->sk)) { $method->free_start_sk = (double) $method->free_start_sk; if (!empty($method->free_start_sk)) { if ($total >= $method->free_start_sk) { return 0; } } } else { if (!empty($pobockaObj->partner)) { if (!empty($method->free_start_partner)) { $fs = (double) $method->free_start_partner; if ($total >= $fs) { return 0; } } } else { if (!empty($method->free_start_ulozenka)) { $fs = (double) $method->free_start_ulozenka; if ($total >= $fs) { return 0; } } } } if (!empty($method->cod_payments)) { if (!empty($cart->virtuemart_paymentmethod_id)) { if (in_array($cart->virtuemart_paymentmethod_id, $method->cod_payments)) { if (!empty($method->pobocky->{$dobierka_price})) { $price += $method->pobocky->{$dobierka_price}; } } } } $orderWeight = $this->getOrderWeight($cart, $method->weight_unit); if (!empty($method->weight_stop)) { if ($orderWeight > $method->weight_stop) { $w = (double) $method->weight_stop; $times = $orderWeight / $w; $c = ceil($times); $price = $price * $c; } } return $price; }
function getStoreInternalData($klarna_data, &$dbValues, $action = NULL, $message) { $dbValues['data'] = json_encode($klarna_data); $dbValues['payment_order_total'] = $klarna_data['order_amount']; $dbValues['payment_currency'] = ShopFunctions::getCurrencyIDByName($klarna_data['purchase_currency']); $dbValues['action'] = $action; $dbValues['klarna_id'] = $klarna_data['order_id']; $dbValues['klarna_status'] = $klarna_data['status']; $dbValues['klarna_fraud_status'] = $klarna_data['fraud_status']; //$dbValues['klarna_reservation'] = $klarna_checkout_order['reservation']; $dbValues['klarna_reference'] = isset($klarna_data['klarna_reference']) ? $klarna_data['klarna_reference'] : ''; $dbValues['klarna_started_at'] = isset($klarna_data['started_at']) ? $klarna_data['started_at'] : ''; $dbValues['klarna_completed_at'] = isset($klarna_data['completed_at']) ? $klarna_data['completed_at'] : ''; $dbValues['klarna_expires_at'] = isset($klarna_data['expires_at']) ? $klarna_data['expires_at'] : ''; $dbValues['format'] = 'json'; $data = json_decode($dbValues['data']); }
function getStoreInternalData($klarna_checkout_order, $dbValues) { $dbValues['payment_order_total'] = $klarna_checkout_order['cart']['total_price_including_tax'] / 100; $dbValues['payment_currency'] = ShopFunctions::getCurrencyIDByName($klarna_checkout_order['purchase_currency']); $dbValues['klarna_id'] = $klarna_checkout_order['id']; $dbValues['klarna_status'] = $klarna_checkout_order['status']; $dbValues['klarna_reservation'] = $klarna_checkout_order['reservation']; $dbValues['klarna_reference'] = $klarna_checkout_order['reference']; $dbValues['klarna_started_at'] = $klarna_checkout_order['started_at']; $dbValues['klarna_completed_at'] = $klarna_checkout_order['completed_at']; $dbValues['klarna_expires_at'] = $klarna_checkout_order['expires_at']; $dbValues['format'] = 'none'; }
static function convertPrice($price, $toCurrency = '') { if (!is_int($toCurrency) && !empty($toCurrency)) { $toCurrency = ShopFunctions::getCurrencyIDByName($toCurrency); } $currency = CurrencyDisplay::getInstance($toCurrency); $fromCurrency = $currency->getCurrencyForDisplay(); $price = round($currency->convertCurrencyTo($toCurrency, $price, false), 2); $cd = CurrencyDisplay::getInstance($fromCurrency); return $price; }
/** * @param $product * @return array|null */ private function getViewData($product) { if (!class_exists('KlarnaAPI')) { require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarnaapi.php'; } if (!class_exists('VirtueMartModelCurrency')) { require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'currency.php'; } $price = $product->prices['salesPrice']; $country = $this->cData['country']; $lang = $this->cData['language_code']; $types = array(KlarnaPClass::CAMPAIGN, KlarnaPClass::ACCOUNT, KlarnaPClass::FIXED); $kCheckout = new KlarnaAPI($country, $lang, 'part', $price, KlarnaFlags::PRODUCT_PAGE, $this->klarna_virtuemart, $types, $this->path); $kCheckout->setCurrency($this->cData['currency']); // TODO : Not top to get setup values here! $this->settings = $kCheckout->getSetupValues(); if ($price > 0 && count($kCheckout->aPClasses) > 0) { $currencydisplay = CurrencyDisplay::getInstance(); $sMonthDefault = NULL; $sTableHtml = ""; $monthTable = array(); // either in vendor's currency, or shipTo Currency $countryCurrencyId = ShopFunctions::getCurrencyIDByName($this->cData['currency_code']); $currency = CurrencyDisplay::getInstance($countryCurrencyId); $fromCurrency = $currency->getCurrencyForDisplay(); //$paymentCurrency = CurrencyDisplay::getInstance($this->cart->paymentCurrency); //$totalInPaymentCurrency = $paymentCurrency->priceDisplay( $this->cart->pricesUnformatted['billTotal'],$this->cart->paymentCurrency) ; //$currencyDisplay = CurrencyDisplay::getInstance($this->cart->pricesCurrency); $i = 0; foreach ($kCheckout->aPClasses as $pclass) { if ($sMonthDefault === NULL || $pclass['monthlyCost'] < $sMonthDefault) { $sMonthDefault = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId); } if ($pclass['pclass']->getType() == KlarnaPClass::ACCOUNT) { $pp_title = JText::_('VMPAYMENT_KLARNA_PPBOX_ACCOUNT'); } else { $pp_title = $pclass['pclass']->getMonths() . " " . JText::_('VMPAYMENT_KLARNA_PPBOX_TH_MONTH'); } $pp_price = $currency->priceDisplay($pclass['monthlyCost'], $countryCurrencyId); $monthTable[$i] = array('pp_title' => html_entity_decode($pp_title), 'pp_price' => $pp_price, 'country' => $country); $i++; } $cd = CurrencyDisplay::getInstance($fromCurrency); $aInputValues = array(); $aInputValues['defaultMonth'] = $sMonthDefault; $aInputValues['monthTable'] = $monthTable; $aInputValues['eid'] = $this->cData['eid']; $aInputValues['country'] = KlarnaCountry::getCode($country); if ($country == KlarnaCountry::DE) { $aInputValues['asterisk'] = '*'; } else { $aInputValues['asterisk'] = ''; } return $aInputValues; } return NULL; }
/** * @static * @param $price * @param string $toCurrency * @return float */ static function convertPrice($price, $cartPricesCurrency, $toCurrency = '') { if (!(is_int($toCurrency) or is_numeric($toCurrency)) && !empty($toCurrency)) { $toCurrency = ShopFunctions::getCurrencyIDByName($toCurrency); } if ($cartPricesCurrency == $toCurrency) { return $price; } $currencyToConvert = CurrencyDisplay::getInstance($toCurrency); // product prices or total in cart is always in vendor currency $priceInNewCurrency = round($currencyToConvert->convertCurrencyTo($toCurrency, $price, FALSE), 2); // set back the currency display $cd = CurrencyDisplay::getInstance($cartPricesCurrency); vmDebug('convertPrice', $price, $cartPricesCurrency, $toCurrency, $priceInNewCurrency); return $priceInNewCurrency; }