예제 #1
0
 function displayKlarnaLogos($method, $virtuemart_country_id, $shipTo, $total)
 {
     $session = JFactory::getSession();
     $sessionKlarna = $session->get('Klarna', 0, 'vm');
     if (empty($sessionKlarna)) {
         return '';
     }
     $sessionKlarnaData = unserialize($sessionKlarna);
     $address['virtuemart_country_id'] = $virtuemart_country_id;
     $cData = KlarnaHandler::getcData($method, $address);
     $country2 = strtolower(shopFunctions::getCountryByID($virtuemart_country_id, 'country_2_code'));
     switch ($sessionKlarnaData->klarna_option) {
         case 'invoice':
             $image = '/klarna_invoice_' . $country2 . '.png';
             $klarna_invoice_fee = KlarnaHandler::getInvoiceFeeInclTax($method, $cData['country_code_3']);
             $currency = CurrencyDisplay::getInstance();
             $display_fee = $currency->priceDisplay($klarna_invoice_fee);
             $text = JText::sprintf('VMPAYMENT_KLARNA_INVOICE_TITLE_NO_PRICE', $display_fee);
             break;
         case 'partpayment':
         case 'part':
             $image = '/klarna_part_' . $country2 . '.png';
             $address['virtuemart_country_id'] = $virtuemart_country_id;
             $pclasses = KlarnaHandler::getPClasses(NULL, $country2, KlarnaHandler::getKlarnaMode($method), $cData);
             if (!class_exists('Klarna_payments')) {
                 require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarna_payments.php';
             }
             if (!class_exists('KlarnaVm2API')) {
                 require JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarna_vm2api.php';
             }
             $payments = new klarna_payments($cData, $shipTo);
             //vmdebug('displaylogos',$cart_prices);
             $totalInPaymentCurrency = KlarnaHandler::convertPrice($total, $cData['currency_code']);
             $text = $payments->displayPclass($sessionKlarnaData->KLARNA_DATA['pclass'], $totalInPaymentCurrency);
             // .' '.$total;
             break;
         case 'speccamp':
             $image = 'klarna_logo.png';
             $text = JText::_('VMPAYMENT_KLARNA_SPEC_TITLE');
             break;
         default:
             $image = '';
             $text = '';
             break;
     }
     $html = $this->renderByLayout('payment_cart', array('logo' => $image, 'description' => $text));
     return $html;
 }
예제 #2
0
 /**
  * Return an array with userFields in several formats.
  *
  * @access public
  * @param $_selection An array, as returned by getuserFields(), with fields that should be returned.
  * @param $_userData Array with userdata holding the values for the fields
  * @param $_prefix string Optional prefix for the formtag name attribute
  * @author Oscar van Eijk
  * @return array List with all userfield data in the format:
  * array(
  *    'fields' => array(   // All fields
  *                   <fieldname> => array(
  *                                     'name' =>       // Name of the field
  *                                     'value' =>      // Existing value for the current user, or the default
  *                                     'title' =>      // Title used for label and such
  *                                     'type' =>       // Field type as specified in the userfields table
  *                                     'hidden' =>     // True/False
  *                                     'required' =>   // True/False. If True, the formcode also has the class "required" for the Joomla formvalidator
  *                                     'formcode' =>   // Full HTML tag
  *                                  )
  *                   [...]
  *                )
  *    'functions' => array() // Optional javascript functions without <script> tags.
  *                           // Possible usage: if (count($ar('functions')>0) echo '<script ...>'.join("\n", $ar('functions')).'</script>;
  *    'scripts'   => array(  // Array with scriptsources for use with JHTML::script();
  *                      <name> => <path>
  *                      [...]
  *                   )
  *    'links'     => array(  // Array with stylesheets for use with JHTML::stylesheet();
  *                      <name> => <path>
  *                      [...]
  *                   )
  * )
  * @example This example illustrates the use of this function. For additional examples, see the Order view
  * and the User view in the administrator section.
  * <pre>
  *   // In the controller, make sure this model is loaded.
  *   // In view.html.php, make the following calls:
  *   $_usrDetails = getUserDetailsFromSomeModel(); // retrieve an user_info record, eg from the usermodel or ordermodel
  *   $_usrFieldList = $userFieldsModel->getUserFields(
  *                    'registration'
  *                  , array() // Default switches
  *                  , array('delimiter_userinfo', 'username', 'email', 'password', 'password2', 'agreed', 'address_type') // Skips
  *    );
  *   $usrFieldValues = $userFieldsModel->getUserFieldsFilled(
  *                      $_usrFieldList
  *                     ,$_usrDetails
  *   );
  *   $this->assignRef('userfields', $userfields);
  *   // In the template, use code below to display the data. For an extended example using
  *   // delimiters, JavaScripts and StyleSheets, see the edit_shopper.php in the user view
  *   <table class="admintable" width="100%">
  *     <thead>
  *       <tr>
  *         <td class="key" style="text-align: center;"  colspan="2">
  *            <?php echo JText::_('COM_VIRTUEMART_TABLE_HEADER') ?>
  *         </td>
  *       </tr>
  *     </thead>
  *      <?php
  *        foreach ($this->shipmentfields['fields'] as $_field ) {
  *          echo '  <tr>'."\n";
  *          echo '    <td class="key">'."\n";
  *          echo '      '.$_field['title']."\n";
  *          echo '    </td>'."\n";
  *          echo '    <td>'."\n";
  *
  *          echo '      '.$_field['value']."\n";    // Display only
  *       Or:
  *          echo '      '.$_field['formcode']."\n"; // Input form
  *
  *          echo '    </td>'."\n";
  *          echo '  </tr>'."\n";
  *        }
  *      ?>
  *    </table>
  * </pre>
  */
 public function getUserFieldsFilled($_selection, $_userData = null, $_prefix = '')
 {
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     $_return = array('fields' => array(), 'functions' => array(), 'scripts' => array(), 'links' => array());
     // 		vmdebug('my user data in getUserFieldsFilled',$_selection,$_userData);
     $_userData = (array) $_userData;
     if (is_array($_selection)) {
         foreach ($_selection as $_fld) {
             $_return['fields'][$_fld->name] = array('name' => $_prefix . $_fld->name, 'value' => $_userData == null || !array_key_exists($_fld->name, $_userData) ? $_fld->default : @$_userData[$_fld->name], 'title' => JText::_($_fld->title), 'type' => $_fld->type, 'required' => $_fld->required, 'hidden' => false, 'formcode' => '');
             // 				vmdebug ('getUserFieldsFilled',$_fld->name);
             // 			if($_fld->name==='email') vmdebug('user data email getuserfieldbyuser',$_userData);
             // First, see if there are predefined fields by checking the name
             switch ($_fld->name) {
                 // 				case 'email':
                 // 					$_return['fields'][$_fld->name]['formcode'] = $_userData->email;
                 // 					break;
                 case 'virtuemart_country_id':
                     $_return['fields'][$_fld->name]['formcode'] = ShopFunctions::renderCountryList($_return['fields'][$_fld->name]['value'], false, array(), $_prefix, $_fld->required);
                     // Translate the value from ID to name
                     $_return['fields'][$_fld->name]['value'] = shopFunctions::getCountryByID($_return['fields'][$_fld->name]['value']);
                     break;
                 case 'virtuemart_state_id':
                     $_return['fields'][$_fld->name]['formcode'] = shopFunctions::renderStateList($_return['fields'][$_fld->name]['value'], $_prefix, false, $_fld->required);
                     $_return['fields'][$_fld->name]['value'] = shopFunctions::getStateByID($_return['fields'][$_fld->name]['value']);
                     break;
                     //case 'agreed':
                     //	$_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" id="'.$_prefix.'agreed_field" name="'.$_prefix.'agreed" value="1" '
                     //		. ($_fld->required ? ' class="required"' : '') . ' />';
                     //	break;
                 //case 'agreed':
                 //	$_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" id="'.$_prefix.'agreed_field" name="'.$_prefix.'agreed" value="1" '
                 //		. ($_fld->required ? ' class="required"' : '') . ' />';
                 //	break;
                 case 'password':
                 case 'password2':
                     $_return['fields'][$_fld->name]['formcode'] = '<input type="password" id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" size="30" class="inputbox" />' . "\n";
                     break;
                 case 'agreed':
                     $_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" name="' . $_prefix . $_fld->name . '" id="' . $_prefix . $_fld->name . '_field" value="1" ' . ($_return['fields'][$_fld->name]['value'] ? 'checked="checked"' : '') . '/>';
                     break;
                     // It's not a predefined field, so handle it by it's fieldtype
                 // It's not a predefined field, so handle it by it's fieldtype
                 default:
                     if (strpos($_fld->type, 'plugin') !== false) {
                         JPluginHelper::importPlugin('vmuserfield');
                         $dispatcher = JDispatcher::getInstance();
                         $dispatcher->trigger('plgVmOnUserfieldDisplay', array($_prefix, $_fld, &$_return));
                         break;
                     }
                     switch ($_fld->type) {
                         case 'hidden':
                             $_return['fields'][$_fld->name]['formcode'] = '<input type="hidden" id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" size="' . $_fld->size . '" value="' . $_return['fields'][$_fld->name]['value'] . '" ' . ($_fld->required ? ' class="required"' : '') . ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '') . ($_fld->readonly ? ' readonly="readonly"' : '') . ' /> ';
                             $_return['fields'][$_fld->name]['hidden'] = true;
                             break;
                         case 'date':
                         case 'age_verification':
                             //echo JHTML::_('behavior.calendar');
                             /*
                              * TODO We must add the joomla.javascript here that contains the calendar,
                              * since Joomla does not load it when there's no user logged in.
                              * Gotta find out why... some security issue or a bug???
                              * Note by Oscar
                              */
                             // if ($_userData === null) { // Not logged in
                             // $_doc = JFactory::getDocument();
                             // $_doc->addScript( JURI::root(true).'/includes/js/joomla.javascript.js');
                             // }
                             $currentYear = date('Y');
                             $calendar = vmJsApi::jDate($_return['fields'][$_fld->name]['value'], $_prefix . $_fld->name, $_prefix . $_fld->name . '_field', false, $currentYear - 100 . ':' . $currentYear);
                             $_return['fields'][$_fld->name]['formcode'] = $calendar;
                             break;
                         case 'emailaddress':
                             if (empty($_return['fields'][$_fld->name]['value'])) {
                                 $_return['fields'][$_fld->name]['value'] = JFactory::getUser()->email;
                             }
                             // 							vmdebug('emailaddress',$_fld);
                         // 							vmdebug('emailaddress',$_fld);
                         case 'text':
                         case 'webaddress':
                             $_return['fields'][$_fld->name]['formcode'] = '<input type="text" id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" size="' . $_fld->size . '" value="' . $_return['fields'][$_fld->name]['value'] . '" ' . ($_fld->required ? ' class="required"' : '') . ($_fld->maxlength ? ' maxlength="' . $_fld->maxlength . '"' : '') . ($_fld->readonly ? ' readonly="readonly"' : '') . ' /> ';
                             break;
                         case 'textarea':
                             $_return['fields'][$_fld->name]['formcode'] = '<textarea id="' . $_prefix . $_fld->name . '_field" name="' . $_prefix . $_fld->name . '" cols="' . $_fld->cols . '" rows="' . $_fld->rows . '" class="inputbox" ' . ($_fld->readonly ? ' readonly="readonly"' : '') . '>' . $_return['fields'][$_fld->name]['value'] . '</textarea>';
                             break;
                         case 'editorta':
                             jimport('joomla.html.editor');
                             $editor = JFactory::getEditor();
                             $_return['fields'][$_fld->name]['formcode'] = $editor->display($_prefix . $_fld->name, $_return['fields'][$_fld->name]['value'], 300, 150, $_fld->cols, $_fld->rows);
                             break;
                         case 'checkbox':
                             $_return['fields'][$_fld->name]['formcode'] = '<input type="checkbox" name="' . $_prefix . $_fld->name . '" id="' . $_prefix . $_fld->name . '_field" value="1" ' . ($_return['fields'][$_fld->name]['value'] ? 'checked="checked"' : '') . '/>';
                             break;
                             // /*##mygruz20120223193710 { :*/
                             // case 'userfieldplugin': //why not just vmuserfieldsplugin ?
                             // JPluginHelper::importPlugin('vmuserfield');
                             // $dispatcher = JDispatcher::getInstance();
                             // //Todo to adjust to new pattern, using &
                             // $html = '' ;
                             // $dispatcher->trigger('plgVmOnUserFieldDisplay',array($_return['fields'][$_fld->name], &$html) );
                             // $_return['fields'][$_fld->name]['formcode'] = $html;
                             // break;
                             // /*##mygruz20120223193710 } */
                         // /*##mygruz20120223193710 { :*/
                         // case 'userfieldplugin': //why not just vmuserfieldsplugin ?
                         // JPluginHelper::importPlugin('vmuserfield');
                         // $dispatcher = JDispatcher::getInstance();
                         // //Todo to adjust to new pattern, using &
                         // $html = '' ;
                         // $dispatcher->trigger('plgVmOnUserFieldDisplay',array($_return['fields'][$_fld->name], &$html) );
                         // $_return['fields'][$_fld->name]['formcode'] = $html;
                         // break;
                         // /*##mygruz20120223193710 } */
                         case 'multicheckbox':
                         case 'select':
                         case 'multiselect':
                         case 'radio':
                             $_qry = 'SELECT fieldtitle, fieldvalue ' . 'FROM #__virtuemart_userfield_values ' . 'WHERE virtuemart_userfield_id = ' . $_fld->virtuemart_userfield_id . ' ORDER BY ordering ';
                             $_values = $this->_getList($_qry);
                             // We need an extra lok here, especially for the Bank info; the values
                             // must be translated.
                             // Don't check on the field name though, since others might be added in the future :-(
                             foreach ($_values as $_v) {
                                 $_v->fieldtitle = JText::_($_v->fieldtitle);
                             }
                             $_attribs = array();
                             if ($_fld->readonly) {
                                 $_attribs['readonly'] = 'readonly';
                             }
                             if ($_fld->required) {
                                 $_attribs['class'] = 'required';
                             }
                             if ($_fld->type == 'radio') {
                                 $_selected = $_return['fields'][$_fld->name]['value'];
                             } else {
                                 $_attribs['size'] = $_fld->size;
                                 // Use for all but radioselects
                                 $_selected = explode("|*|", $_return['fields'][$_fld->name]['value']);
                             }
                             // Nested switch...
                             switch ($_fld->type) {
                                 case 'multicheckbox':
                                     $_return['fields'][$_fld->name]['formcode'] = '';
                                     $_idx = 0;
                                     $rows = $_fld->rows;
                                     $row = 1;
                                     foreach ($_values as $_val) {
                                         if ($row > $rows) {
                                             $row = 1;
                                             $br = '<br />';
                                         } else {
                                             $row++;
                                             $br = '';
                                         }
                                         $_return['fields'][$_fld->name]['formcode'] .= '<input type="checkbox" name="' . $_prefix . $_fld->name . '[]" id="' . $_prefix . $_fld->name . '_field' . $_idx . '" value="' . $_val->fieldvalue . '" ' . (in_array($_val->fieldvalue, $_selected) ? 'checked="checked"' : '') . '/> ' . JText::_($_val->fieldtitle) . $br;
                                         $_idx++;
                                     }
                                     break;
                                 case 'select':
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix . $_fld->name, $_attribs, 'fieldvalue', 'fieldtitle', $_selected[0]);
                                     break;
                                 case 'multiselect':
                                     $_attribs['multiple'] = 'multiple';
                                     $_attribs['rows'] = $_fld->rows;
                                     $_attribs['cols'] = $_fld->cols;
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.genericlist', $_values, $_prefix . $_fld->name . '[]', $_attribs, 'fieldvalue', 'fieldtitle', $_selected);
                                     break;
                                 case 'radio':
                                     $_return['fields'][$_fld->name]['formcode'] = JHTML::_('select.radiolist', $_values, $_prefix . $_fld->name, $_attribs, $_selected, 'fieldvalue', 'fieldtitle');
                                     break;
                             }
                             break;
                     }
                     break;
             }
         }
     } else {
         vmdebug('getUserFieldsFilled $_selection is not an array ', $_selection);
         // 			$_return['fields'][$_fld->name]['formcode'] = '';
     }
     return $_return;
 }
예제 #3
0
파일: klarna.php 프로젝트: sergy444/joomla
	/**
	 * @param $method
	 * @param $virtuemart_country_id
	 * @param $shipTo
	 * @param $total
	 * @return string
	 */
	protected function renderKlarnaPluginName ($method, $virtuemart_country_id, $shipTo, $total, $cartPricesCurrency) {

		$session = JFactory::getSession ();
		$sessionKlarna = $session->get ('Klarna', 0, 'vm');
		if (empty($sessionKlarna)) {
			return '';
		}
		$sessionKlarnaData = unserialize ($sessionKlarna);
		$address['virtuemart_country_id'] = $virtuemart_country_id;
		$cData = KlarnaHandler::getcData ($method, $address);
		$country2 = strtolower (shopFunctions::getCountryByID ($virtuemart_country_id, 'country_2_code'));
		$text = "";
		if (isset($sessionKlarnaData->klarna_option)) {
			switch ($sessionKlarnaData->klarna_option) {
				case 'invoice':
					$sType='invoice';
					$image = '/klarna_invoice_' . $country2 . '.png';
					//$logo = VMKLARNAPLUGINWEBASSETS . '/images/' . 'logo/klarna_' . $sType . '_' . $code2 . '.png';
					$image ="https://cdn.klarna.com/public/images/".strtoupper($country2)."/badges/v1/". $sType ."/".$country2."_". $sType ."_badge_std_blue.png?height=55&eid=".$cData['eid'];
					$display_invoice_fee = NULL;
					$invoice_fee = 0;
					KlarnaHandler::getInvoiceFeeInclTax ($method, $cData['country_code_3'], $cartPricesCurrency, $cData['virtuemart_currency_id'], $display_invoice_fee, $invoice_fee);
					$text = JText::sprintf ('VMPAYMENT_KLARNA_INVOICE_TITLE_NO_PRICE', $display_invoice_fee);
					break;
				case 'partpayment':
				case 'part':
					$sType='account';
					//$image = '/klarna_part_' . $country2 . '.png';
					$image ="https://cdn.klarna.com/public/images/".strtoupper($country2)."/badges/v1/". $sType ."/".$country2."_". $sType ."_badge_std_blue.png?height=55&eid=".$cData['eid'];

					$address['virtuemart_country_id'] = $virtuemart_country_id;
					//$pclasses                         = KlarnaHandler::getPClasses(NULL,   KlarnaHandler::getKlarnaMode($method), $cData);
					if (!class_exists ('Klarna_payments')) {
						require (JPATH_VMKLARNAPLUGIN . DS . 'klarna' . DS . 'helpers' . DS . 'klarna_payments.php');
					}

					$payments = new klarna_payments($cData, $shipTo);
					//vmdebug('displaylogos',$cart_prices);
					$totalInPaymentCurrency = KlarnaHandler::convertPrice ($total, $cData['vendor_currency'], $cData['virtuemart_currency_id']);
					vmdebug ('totalInPaymentCurrency', $totalInPaymentCurrency);
					if (isset($sessionKlarnaData->KLARNA_DATA)) {
						$text = $payments->displayPclass ($sessionKlarnaData->KLARNA_DATA['pclass'], $totalInPaymentCurrency); // .' '.$total;
					}
					break;
				case 'speccamp':
					$image = 'klarna_logo.png';
					$text = JText::_ ('VMPAYMENT_KLARNA_SPEC_TITLE');
					break;
				default:
					$image = '';
					$text = '';
					break;
			}

			$plugin_name = $this->_psType . '_name';
			$plugin_desc = $this->_psType . '_desc';
			$payment_description = '';
			if (!empty($method->$plugin_desc)) {
				$payment_description = $method->$plugin_desc;
			}
			$payment_name = $method->$plugin_name;

			$html = $this->renderByLayout ('payment_cart', array(
				'logo'                => $image,
				'text'                => $text,
				'payment_description' => $payment_description,
				'payment_name'        => $payment_name
			));
			return $html;
		}
	}
예제 #4
0
 /**
  * @static
  * @param $method
  * @return array
  */
 public static function fetchAllPClasses($method)
 {
     $message = '';
     $success = '';
     $results = array();
     $countries = self::getKlarnaCountries();
     $pc_type = KlarnaHandler::getKlarna_pc_type();
     if (empty($pc_type)) {
         return FALSE;
     } else {
         // delete the file directly
         if (file_exists($pc_type)) {
             unlink($pc_type);
         }
     }
     foreach ($countries as $country) {
         $active_country = "klarna_active_" . $country;
         if ($method->{$active_country}) {
             // country is CODE 3==> converting to 2 letter country
             //$country = self::convertCountryCode($method, $country);
             $lang = self::getLanguageForCountry($method, $country);
             $flagImg = JURI::root(TRUE) . '/administrator/components/com_virtuemart/assets/images/flag/' . strtolower($lang) . '.png';
             $flag = "<img src='" . $flagImg . "' />";
             try {
                 $settings = self::getCountryData($method, $country);
                 $klarna = new Klarna_virtuemart();
                 $klarna->config($settings['eid'], $settings['secret'], $settings['country'], $settings['language'], $settings['currency'], KlarnaHandler::getKlarnaMode($method, $settings['country_code_3']), VMKLARNA_PC_TYPE, $pc_type, TRUE);
                 $klarna->fetchPClasses($country);
                 $success .= shopFunctions::getCountryByID($settings['virtuemart_country_id']);
             } catch (Exception $e) {
                 $message .= $flag . " " . shopFunctions::getCountryByID($settings['virtuemart_country_id']) . ": " . $e->getMessage() . ' Error Code #' . $e->getCode() . '</span></br>';
             }
         }
     }
     $results['msg'] = $message;
     $results['notice'] = $success;
     return $results;
     //echo $notice;
 }
예제 #5
0
	/**
	 * get the partial shipping address (city, state, postal code, and country) by calling the GetOrderReferenceDetails operation
	 * to compute taxes and shipping costs or possible applicable shipping speed, and options.
	 * @param $client
	 * @param $cart
	 */
	function updateCartWithAmazonAddress () {

		$this->loadVmClass('VirtueMartCart', JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
		$return = array();
		//$this->debug('', 'updateCartWithAmazonAddress', 'debug');
		$cart = VirtueMartCart::getCart();

		$physicalDestination = $this->getPhysicalDestination();
		if (!$physicalDestination) {
			$return['error'] = 'NoPhysicalDestination';
			$return['error_msg'] = vmText::_('VMPAYMENT_AMAZON_UPDATECART_ERROR');
			return $return;
		}

		$update_data = $this->getUserInfoFromAmazon($physicalDestination);
		if (!$this->isValidCountry($update_data['virtuemart_country_id'])) {
			$this->updateCartWithDefaultAmazonAddress($cart, $this->isOnlyDigitalGoods($cart));
			$country = shopFunctions::getCountryByID($update_data['virtuemart_country_id']);
			$cart->_dataValidated = false;
			$cart->BT['virtuemart_country_id'] = 0;
			$cart->setCartIntoSession();
			$return['error'] = 'deliveryCountryNotAllowed';
			$return['error_msg'] = vmText::sprintf('VMPAYMENT_AMAZON_UPDATECART_DELIVERYCOUNTRYNOTALLOWED', $country);
			return $return;

		}
		if ($this->isSameAddress($update_data, $cart)) {
			$return['error'] = 'sameAddress';
			return $return;

		}
		$update_data ['address_type'] = 'BT';
		$cart->saveAddressInCart($update_data, $update_data['address_type'], TRUE);


		// update BT and ST with Amazon Partial Address
		$prefix = 'shipto_';
		$update_data = $this->getUserInfoFromAmazon($physicalDestination, $prefix);
		$update_data ['address_type'] = 'ST';
		$cart->saveAddressInCart($update_data, $update_data['address_type'], TRUE);
		$cart->STsameAsBT = 0;
		$cart->setCartIntoSession();

		$return['error'] = 'addressUpdated';
		return $return;
	}
예제 #6
0
 function setCountryAndState($address)
 {
     // get rid of the references
     $address = $this->copyObj($address);
     if (!class_exists('ShopFunctions')) {
         require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
     }
     if (isset($address) && !is_object($address) || !is_object($address) && empty($address->virtuemart_country_id)) {
         if (!empty($address['virtuemart_country_id']) && !empty($address['virtuemart_country_id']['value']) && is_numeric($address['virtuemart_country_id']['value'])) {
             $address['virtuemart_country_id']['value_txt'] = shopFunctions::getCountryByID($address['virtuemart_country_id']['value']);
             //shopFunctions::getCountryByID($address['virtuemart_country_id']['value']);
         } else {
             $address['virtuemart_country_id']['value'] = '';
         }
         if (!empty($address['virtuemart_state_id']) && !empty($address['virtuemart_state_id']['value']) && is_numeric($address['virtuemart_state_id']['value'])) {
             $address['virtuemart_state_id']['value_txt'] = shopFunctions::getStateByID($address['virtuemart_state_id']['value']);
         } else {
             $address['virtuemart_state_id']['value'] = '';
         }
     } else {
         if (!empty($address->virtuemart_country_id) && is_numeric($address->virtuemart_country_id)) {
             $address->virtuemart_country_id = shopFunctions::getCountryByID($address->virtuemart_country_id);
         } else {
             $address->virtuemart_country_id = '';
         }
         if (!empty($address->virtuemart_state_id) && is_numeric($address->virtuemart_state_id)) {
             $address->virtuemart_state_id = shopFunctions::getStateByID($address->virtuemart_state_id);
         } else {
             $address->virtuemart_state_id = '';
         }
     }
     return $address;
 }
예제 #7
0
 public static function setShopperGroupsController($cart = null)
 {
     // we need to alter shopper group for business when set to:
     $is_business = JRequest::getVar('opc_is_business', 0);
     $remove = array();
     //require_once(JPATH_OPC.DS.'helpers'.DS.'loader.php');
     OPCShopperGroups::getSetShopperGroup();
     if (!class_exists('VirtueMartModelShopperGroup')) {
         if (file_exists(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'shoppergroup.php')) {
             require JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'shoppergroup.php';
         } else {
             return;
         }
     }
     if (!method_exists('VirtueMartModelShopperGroup', 'appendShopperGroups')) {
         return 1;
     }
     include JPATH_ROOT . DS . 'components' . DS . 'com_onepage' . DS . 'config' . DS . 'onepage.cfg.php';
     if (!empty($business_shopper_group) || !empty($visitor_shopper_group)) {
         if (class_exists('VirtueMartModelShopperGroup')) {
             $shoppergroupmodel = new VirtueMartModelShopperGroup();
             if (method_exists($shoppergroupmodel, 'removeSessionSgrps')) {
                 if (method_exists($shoppergroupmodel, 'appendShopperGroups')) {
                     if (!empty($is_business)) {
                         // we will differenciate between default and anonymous shopper group
                         // default is used for non-logged users
                         // anononymous is used for logged in users as guests
                         OPCShopperGroups::setShopperGroups($business_shopper_group);
                         $remove[] = $visitor_shopper_group;
                         // function appendShopperGroups(&$shopperGroups,$user,$onlyPublished = FALSE,$vendorId=1){
                         // remove previous:
                         /*
                         $session = JFactory::getSession();
                         $shoppergroup_ids = $session->get('vm_shoppergroups_add',array(),'vm');
                         $shoppergroupmodel->removeSessionSgrps($shoppergroup_ids); 
                         $new_shoppergroups = array(); 
                         $new_shoppergroups[] = $business_shopper_group;  
                         $shoppergroup_ids = $session->set('vm_shoppergroups_add',$new_shoppergroups,'vm');
                         $shoppergroupmodel->appendShopperGroups($new_shoppergroups, null); 
                         
                         JRequest::setVar('virtuemart_shoppergroup_id', $new_shoppergroups, 'post');
                         */
                         //appendShopperGroups
                     } else {
                         OPCShopperGroups::setShopperGroups($visitor_shopper_group);
                         $remove[] = $business_shopper_group;
                         /*
                         	 $shoppergroupmodel = new VirtueMartModelShopperGroup(); 
                         	 // function appendShopperGroups(&$shopperGroups,$user,$onlyPublished = FALSE,$vendorId=1){
                         	 // remove previous: 
                         	 $session = JFactory::getSession();
                         	 $shoppergroup_ids = $session->get('vm_shoppergroups_add',array(),'vm');
                         	 $shoppergroupmodel->removeSessionSgrps($shoppergroup_ids); 
                         	 $new_shoppergroups = array(); 
                         	 $new_shoppergroups[] = $visitor_shopper_group; 
                         	 $shoppergroup_ids = $session->set('vm_shoppergroups_add',$new_shoppergroups,'vm');
                         	 $shoppergroupmodel->appendShopperGroups($new_shoppergroups, null); 
                         	 JRequest::setVar('virtuemart_shoppergroup_id', $new_shoppergroups, 'post');
                         */
                     }
                 }
             }
         }
     }
     // EU VAT shopper group:
     if (!empty($euvat_shopper_group)) {
         $removeu = true;
         $session = JFactory::getSession();
         $vatids = $session->get('opc_vat', array());
         if (!is_array($vatids)) {
             $vatids = @unserialize($vatids);
         }
         //BIT vat checker:
         if (!empty($vatids['field'])) {
             $euvat = JRequest::getVar($vatids['field'], '');
             $euvat = preg_replace("/[^a-zA-Z0-9]/", "", $euvat);
             $euvat = strtoupper($euvat);
             if (!empty($cart)) {
                 $address = $cart->ST == 0 ? $cart->BT : $cart->ST;
                 $country = $address['virtuemart_country_id'];
             } else {
                 $country = JRequest::getVar('virtuemart_country_id');
             }
             $vathash = $country . '_' . $euvat;
             $home = 'NL';
             if (!class_exists('ShopFunctions')) {
                 require JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'shopfunctions.php';
             }
             $country_2_code = shopFunctions::getCountryByID($country, 'country_2_code');
             $home = explode(',', $home_vat_countries);
             $list = array();
             if (is_array($home)) {
                 foreach ($home as $k => $v) {
                     $list[] = strtoupper(trim($v));
                 }
             } else {
                 $list[] = $v;
             }
             if (!in_array($country_2_code, $list)) {
                 if (!empty($euvat)) {
                     $euvat = strtoupper($euvat);
                     if (!empty($vatids[$vathash])) {
                         //change OPC VAT shopper group:
                         OPCShopperGroups::setShopperGroups($euvat_shopper_group);
                         $removeu = false;
                     }
                 }
             }
         }
         if ($removeu) {
             $remove[] = $euvat_shopper_group;
         }
     }
     OPCShopperGroups::setShopperGroups(-1, $remove);
     if (class_exists('calculationHelper')) {
         calculationHelper::$_instance = null;
     }
     $session = JFactory::getSession();
     $shoppergroup_ids = $session->get('vm_shoppergroups_add', array(), 'vm');
 }
예제 #8
0
 public function plgVmDisplayListFEPaymentOPCNocache(&$cart, $selected = 0, &$htmlIn)
 {
     if ($this->_psType != 'payment') {
         return;
     }
     if (!isset($cart->vendorId)) {
         $cart->vendorId = 1;
     }
     if (!class_exists('CurrencyDisplay')) {
         require JPATH_VM_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'currencydisplay.php';
     }
     $currency = CurrencyDisplay::getInstance();
     if ($this->_name == 'klarna') {
         $address = $cart->ST == 0 ? $cart->BT : $cart->ST;
         if (isset($address['virtuemart_country_id'])) {
             $country = $address['virtuemart_country_id'];
         }
         if (empty($country) && !empty($cart->BT['virtuemart_country_id'])) {
             $country = $cart->BT['virtuemart_country_id'];
         }
         if (!class_exists('ShopFunctions')) {
             require JPATH_VM_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'shopfunctions.php';
         }
         if (empty($country)) {
             return;
         }
         $countryCode = shopFunctions::getCountryByID($country, 'country_2_code');
         $avai = array('SE', 'DE', 'NL', 'NO', 'DK', 'FI');
         $countryCode = strtoupper($countryCode);
         if (!in_array($countryCode, $avai)) {
             return;
         }
     }
     if ($this->getPluginMethodsOPC($cart->vendorId) === 0) {
         return FALSE;
     }
     $return = array();
     if (isset($this->methods)) {
         $ref =& $this;
         foreach ($this->methods as $key => &$method) {
             if (isset($method->virtuemart_paymentmethod_id)) {
                 $this->_setMissingOPC($method);
                 $vm_id = $method->virtuemart_paymentmethod_id;
                 $html = '';
                 //$filename = 'plg_' . $this->_type . '_' . $this->_name;
                 $name = $this->_name;
                 jimport('joomla.filesystem.file');
                 $name = JFile::makeSafe($name);
                 $type = $this->_psType;
                 if ($type == 'vmpayment') {
                     $type = 'payment';
                 }
                 if ($type == 'vmshipment') {
                     $type = 'shipment';
                 }
                 $type = JFile::makeSafe($type);
                 static $theme;
                 if (empty($theme)) {
                     include JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'onepage.cfg.php';
                     $theme = $selected_template;
                 }
                 $layout_name = 'after_render';
                 $layout = JPATH_SITE . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_onepage' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'overrides' . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $name . DIRECTORY_SEPARATOR . $layout_name . '.php';
                 if (file_exists($layout)) {
                     $method_name = $this->_psType . '_name';
                     $plugin =& $method;
                     $pluginmethod_id = $this->_idName;
                     $plugin_name = $this->_psType . '_name';
                     $plugin_desc = $this->_psType . '_desc';
                     $logosFieldName = $this->_psType . '_logos';
                     $logo_list = $plugin->{$logosFieldName};
                     $pricesUnformatted = $cart->pricesUnformatted;
                     $arr = array($this, 'setCartPrices');
                     if (is_callable($arr)) {
                         $pluginSalesPrice = $this->setCartPrices($cart, $pricesUnformatted, $method);
                     } else {
                         $pluginSalesPrice = 0;
                     }
                     $url = JURI::root() . 'images/stories/virtuemart/' . $this->_psType . '/';
                     if (!is_array($logo_list)) {
                         $logo_list = (array) $logo_list;
                     }
                     $name = JFile::makeSafe($name);
                     $layout_name = JFile::makeSafe($layout_name);
                     ob_start();
                     include $layout;
                     if (!empty($html)) {
                         $null = ob_get_clean();
                     } else {
                         $html = ob_get_clean();
                     }
                     $isset = true;
                 } else {
                     OPCtransform::overridePaymentHtml($html, $cart, $vm_id, $this->_name, $this->_type, $method);
                 }
                 if ($html != '') {
                     $return[] = $html;
                 }
                 //break;
             }
         }
         if (!empty($return)) {
             $htmlIn[] = $return;
             return true;
         }
     } else {
         return null;
     }
     if (empty($htmlIn)) {
         $htmlIn = array();
     }
     $new = array();
     $return = $this->plgVmDisplayListFEPayment($cart, $selected, $new);
     // loads render_after
     foreach ($new as $html) {
         OPCtransform::overridePaymentHtml($html, $cart, $vm_id, $this->_name, $this->_type);
         $htmlIn[] = $html;
     }
     return $return;
 }
예제 #9
0
 public static function fetchPClasses($method)
 {
     $message = '';
     $success = '';
     $results = array();
     $countries = self::getKlarnaCountries();
     foreach ($countries as $country) {
         $active_country = "klarna_active_" . $country;
         if ($method->{$active_country}) {
             // country is CODE 3==> converting to 2 letter country
             //$country = self::convertCountryCode($method, $country);
             $lang = self::getLanguageForCountry($method, $country);
             $flagImg = JURI::root(true) . '/administrator/components/com_virtuemart/assets/images/flag/' . strtolower($lang) . '.png';
             $flag = "<img src='" . $flagImg . "' />";
             try {
                 $settings = self::getCountryData($method, $country);
                 $klarna = new Klarna_virtuemart();
                 $klarna->config($settings['eid'], $settings['secret'], $settings['country'], $settings['language'], $settings['currency'], KlarnaHandler::getKlarnaMode($method), VMKLARNA_PC_TYPE, KlarnaHandler::getKlarna_pc_type(), true);
                 // fetch pclass from file
                 $klarna->fetchPClasses($country);
                 $success .= '<span style="padding: 5px;">' . $flag . " " . shopFunctions::getCountryByID($settings['virtuemart_country_id']) . '</span>';
             } catch (Exception $e) {
                 $message .= '<br><span style="font-size: 15px;">' . $flag . " " . shopFunctions::getCountryByID($settings['virtuemart_country_id']) . ": " . $e->getMessage() . ' Error Code #' . $e->getCode() . '</span></br>';
             }
         }
     }
     $results['msg'] = $message;
     $results['notice'] = 'PClasses fetched for : ' . $success;
     return $results;
     //echo $notice;
 }