/** * Changes the virtuemart_currency_id into the right currency_code * For exampel 47 => EUR * * @author Max Milbers * @author Frederic Bidon */ function ensureUsingCurrencyCode($curr) { if (is_numeric($curr) and $curr != 0) { if (!class_exists('ShopFunctions')) { require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php'; } return ShopFunctions::getCurrencyByID($curr, 'currency_code_3'); } return $curr; }
protected function getListFEPayment(VirtueMartCart $cart, $method) { $currency_code = ShopFunctions::getCurrencyByID($cart->pricesCurrency, 'currency_code_3'); $this->_getCartAddressCountryCode($cart, $country_code, $countryId); if (!($cData = $this->checkCountryCondition($method, $country_code, $cart))) { return NULL; } $pclasses = KlarnaHandler::getPClasses(NULL, $country_code, KlarnaHandler::getKlarnaMode($method), $cData); $this->getNbPClasses($pclasses, $specCamp, $partPay); $sessionKlarnaData = $this->getKlarnaSessionData(); $klarna_paymentmethod = ""; if (isset($sessionKlarnaData->KLARNA_DATA['klarna_paymentmethod'])) { $klarna_paymentmethod = $sessionKlarnaData->KLARNA_DATA['klarna_paymentmethod']; } $html = ''; $payments = new klarna_payments($cData, KlarnaHandler::getShipToAddress($cart)); $payment_params = $payments->invoice($method); $payment_form = $this->renderByLayout('payment_form', array('checkout' => $payment_params['fields']['checkout'], 'input' => $payment_params['fields']['input'], 'value' => $payment_params['fields']['value'], 'setup' => $payment_params['fields']['setup'], 'sType' => $payment_params['fields']['sType'], 'pClasses' => $payment_params['pClasses']), 'klarna', 'payment'); $html .= $this->renderByLayout('displaypayment', array('stype' => 'invoice', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod)); if ($partPay > 0) { if ($payment_params = $payments->partPay($cart)) { $payment_form = $this->renderByLayout('payment_form', array('checkout' => $payment_params['fields']['checkout'], 'input' => $payment_params['fields']['input'], 'value' => $payment_params['fields']['value'], 'setup' => $payment_params['fields']['setup'], 'sType' => $payment_params['fields']['sType'], 'pClasses' => $payment_params['pClasses']), 'klarna', 'payment'); $html .= $this->renderByLayout('displaypayment', array('stype' => 'part', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod)); } } if ($specCamp > 0) { if ($payment_params = $payments->specCamp($cart)) { $payment_form = $this->renderByLayout('payment_form', array('checkout' => $payment_params['fields']['checkout'], 'input' => $payment_params['fields']['input'], 'value' => $payment_params['fields']['value'], 'setup' => $payment_params['fields']['setup'], 'sType' => $payment_params['fields']['sType'], 'pClasses' => $payment_params['pClasses']), 'klarna', 'payment'); $html .= $this->renderByLayout('displaypayment', array('stype' => 'spec', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod)); } } // TO DO add html: $pluginHtml = $html; return $pluginHtml; }
/** * Retrieve a list of calculation rules from the database. * * @author Max Milbers * @param string $onlyPuiblished True to only retreive the published Calculation rules, false otherwise * @param string $noLimit True if no record count limit is used, false otherwise * @return object List of calculation rule objects */ public function getCalcs($onlyPublished = false, $noLimit = false, $search = false) { $where = array(); $this->_noLimit = $noLimit; // add filters if ($onlyPublished) { $where[] = '`published` = 1'; } $db = JFactory::getDBO(); if ($search) { $search = '"%' . $db->escape($search, true) . '%"'; $where[] = ' `calc_name` LIKE ' . $search . ' OR `calc_descr` LIKE ' . $search . ' OR `calc_value` LIKE ' . $search . ' '; } $whereString = ''; if (count($where) > 0) { $whereString = ' WHERE ' . implode(' AND ', $where); } $datas = $this->exeSortSearchListQuery(0, '*', ' FROM `#__tsmart_calcs`', $whereString, '', $this->_getOrdering()); if (!class_exists('ShopFunctions')) { require VMPATH_ADMIN . DS . 'helpers' . DS . 'shopfunctions.php'; } foreach ($datas as &$data) { $data->currencyName = ShopFunctions::getCurrencyByID($data->calc_currency); JPluginHelper::importPlugin('vmcalculation'); $dispatcher = JDispatcher::getInstance(); $error = $dispatcher->trigger('plgVmGetPluginInternalDataCalcList', array(&$data)); } return $datas; }
/** * @param VirtueMartCart $cart * @param $method * @return null|string */ protected function getListFEPayment (VirtueMartCart $cart, $method) { $cart_currency_code = ShopFunctions::getCurrencyByID ($cart->pricesCurrency, 'currency_code_3'); $country_code = NULL; $countryId = 0; $this->_getCountryCode ($cart, $country_code, $countryId); if (!($cData = $this->checkCountryCondition ($method, $country_code, $cart))) { return NULL; } try { $pclasses = KlarnaHandler::getPClasses (NULL, KlarnaHandler::getKlarnaMode ($method, $cData['country_code_3']), $cData); } catch (Exception $e) { vmError ($e->getMessage (), $e->getMessage ()); return NULL; } $specCamp = 0; $partPay = 0; $this->getNbPClasses ($pclasses, $specCamp, $partPay); $sessionKlarnaData = $this->getKlarnaSessionData (); $klarna_paymentmethod = ""; if (isset($sessionKlarnaData->klarna_paymentmethod)) { $klarna_paymentmethod = $sessionKlarnaData->klarna_paymentmethod; } $html = ''; $checked = 'checked="checked"'; $payments = new klarna_payments($cData, KlarnaHandler::getShipToAddress ($cart)); if (in_array ('invoice', $cData['payments_activated'])) { $payment_params = $payments->get_payment_params ($method, 'invoice', $cart); $payment_form = $this->renderByLayout ('payment_form', array('payment_params' => $payment_params, 'payment_currency_info' => $payment_params['payment_currency_info'],), 'klarna', 'payment'); $selected = ($klarna_paymentmethod == 'klarna_invoice' AND $method->virtuemart_paymentmethod_id == $cart->virtuemart_paymentmethod_id) ? $checked : ""; $html .= $this->renderByLayout ('displaypayment', array( 'stype' => 'invoice', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod, 'selected' => $selected )); } if (in_array ('part', $cData['payments_activated'])) { if (strtolower ($country_code) == 'nld') { // Since 12/09/12: merchants can sell goods with Klarna Invoice up to thousands of euros. So the price check has been moved here if (!KlarnaHandler::checkPartNLpriceCondition ($cart)) { // We can't show our payment options for Dutch customers // if price exceeds 250 euro. Will be replaced with ILT in // the future. $partPay = 0; } } if (!KlarnaHandler::checkPartpriceCondition ($cData, $cart)) { $partPay = 0; } if ($partPay > 0) { if ($payment_params = $payments->get_payment_params ($method, 'part', $cart, $cData['virtuemart_currency_id'], $cData['vendor_currency'])) { $payment_form = $this->renderByLayout ('payment_form', array('payment_params' => $payment_params, 'payment_currency_info' => $payment_params['payment_currency_info'],), 'klarna', 'payment'); $selected = ($klarna_paymentmethod == 'klarna_part' AND $method->virtuemart_paymentmethod_id == $cart->virtuemart_paymentmethod_id) ? $checked : ""; $html .= $this->renderByLayout ('displaypayment', array( 'stype' => 'part', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod, 'selected' => $selected )); } } } // not tested yet /* if ( $specCamp > 0) { if ($payment_params = $payments->get_payment_params ($method, 'spec', $cart, $cData['virtuemart_currency_id'])) { $payment_form = $this->renderByLayout ('payment_form', array('payment_params' => $payment_params, 'payment_currency_info' => $payment_params['payment_currency_info'],), 'klarna', 'payment'); $selected = ($klarna_paymentmethod == 'klarna_spec' AND $method->virtuemart_paymentmethod_id == $cart->virtuemart_paymentmethod_id) ? $checked : ""; $html .= $this->renderByLayout ('displaypayment', array( 'stype' => 'spec', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod, 'selected' => $selected )); } } */ return $html; }
/** * @param VirtueMartCart $cart * @param $method * @return null|string */ protected function getListFEPayment(VirtueMartCart $cart, $method) { $cart_currency_code = ShopFunctions::getCurrencyByID($cart->pricesCurrency, 'currency_code_3'); $this->_getCartAddressCountryCode($cart, $country_code, $countryId); if (!($cData = $this->checkCountryCondition($method, $country_code, $cart))) { return NULL; } $pclasses = KlarnaHandler::getPClasses(NULL, KlarnaHandler::getKlarnaMode($method, $cData['country_code_3']), $cData); $this->getNbPClasses($pclasses, $specCamp, $partPay); $sessionKlarnaData = $this->getKlarnaSessionData(); $klarna_paymentmethod = ""; if (isset($sessionKlarnaData->klarna_paymentmethod)) { $klarna_paymentmethod = $sessionKlarnaData->klarna_paymentmethod; } $html = ''; $checked = 'checked="checked"'; $payments = new klarna_payments($cData, KlarnaHandler::getShipToAddress($cart)); $payment_params = $payments->get_payment_params($method, 'invoice', $cart); $payment_form = $this->renderByLayout('payment_form', array('payment_params' => $payment_params, 'payment_currency_info' => $payment_params['payment_currency_info']), 'klarna', 'payment'); $selected = ($klarna_paymentmethod == 'klarna_invoice' and $method->virtuemart_paymentmethod_id == $cart->virtuemart_paymentmethod_id) ? $checked : ""; $html .= $this->renderByLayout('displaypayment', array('stype' => 'invoice', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod, 'selected' => $selected)); if ($partPay > 0) { if ($payment_params = $payments->get_payment_params($method, 'part', $cart, $cData['virtuemart_currency_id'])) { $payment_form = $this->renderByLayout('payment_form', array('payment_params' => $payment_params, 'payment_currency_info' => $payment_params['payment_currency_info']), 'klarna', 'payment'); $selected = ($klarna_paymentmethod == 'klarna_part' and $method->virtuemart_paymentmethod_id == $cart->v) ? $checked : ""; $html .= $this->renderByLayout('displaypayment', array('stype' => 'part', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod, 'selected' => $selected)); } } if ($specCamp > 0) { if ($payment_params = $payments->get_payment_params($method, 'spec', $cart, $cData['virtuemart_currency_id'])) { $payment_form = $this->renderByLayout('payment_form', array('payment_params' => $payment_params, 'payment_currency_info' => $payment_params['payment_currency_info']), 'klarna', 'payment'); $selected = ($klarna_paymentmethod == 'klarna_spec' and $method->virtuemart_paymentmethod_id == $cart->virtuemart_paymentmethod_id) ? $checked : ""; $html .= $this->renderByLayout('displaypayment', array('stype' => 'spec', 'id' => $payment_params['id'], 'module' => $payment_params['module'], 'klarna_form' => $payment_form, 'virtuemart_paymentmethod_id' => $method->virtuemart_paymentmethod_id, 'klarna_paymentmethod' => $klarna_paymentmethod, 'selected' => $selected)); } } return $html; }