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, $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 = ""; // 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'] = ''; } //$aInputValues['nlBanner'] = (($country == KlarnaCountry::NL) ? '<div class="nlBanner"><img src="' . VMKLARNAPLUGINWEBASSETS . '/images/account/' . $notice . '" /></div>' : ""); return $aInputValues; // return $kCheckout->retrieveHTML($aInputValues, null, JPATH_VMKLARNAPLUGIN . '/klarna/tmpl/productprice_layout.html'); } return NULL; }
/** * @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 VMPATH_ADMIN . 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); try { $kCheckout = new KlarnaAPI($country, $lang, 'part', $price, KlarnaFlags::PRODUCT_PAGE, $this->klarna_virtuemart, $types, $this->path); } catch (Exception $e) { VmDebug('getViewData', 'Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode()); VmError($e->getMessage(), 'getViewData' . 'Error in ' . __METHOD__ . ': ' . $e->getMessage(), $e->getCode()); return NULL; } $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 = $this->cData['virtuemart_currency_id']; $currency = CurrencyDisplay::getInstance($countryCurrencyId); $fromCurrency = $currency->getCurrencyForDisplay(); //$paymentCurrency = CurrencyDisplay::getInstance($this->cart->paymentCurrency); //$totalInPaymentCurrency = $paymentCurrency->priceDisplay( $this->cart->cartPrices['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 = tsmText::_('VMPAYMENT_KLARNA_PPBOX_ACCOUNT'); } else { $pp_title = $pclass['pclass']->getMonths() . " " . tsmText::_('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; }