예제 #1
0
 /**
  * Create the table for this plugin if it does not yet exist.
  * This functions checks if the called plugin is active one.
  * When yes it is calling the standard method to create the tables
  * @author Valérie Isaksen
  *
  */
 function plgVmOnStoreInstallPaymentPluginTable($jplugin_id)
 {
     /*
      * if the file Klarna.cfg does not exist, then create it
      */
     $filename = VMKLARNA_CONFIG_FILE;
     if (!JFile::exists($filename)) {
         $fileContents = "<?php defined('_JEXEC') or die();\n\tdefine('VMKLARNA_SHIPTO_SAME_AS_BILLTO', '1'); ?>";
         $result = JFile::write($filename, $fileContents);
         if (!$result) {
             VmInfo(JText::sprintf('VMPAYMENT_KLARNA_CANT_WRITE_CONFIG', $filename, $result));
         }
     }
     $method = $this->getPluginMethod(JRequest::getInt('virtuemart_paymentmethod_id'));
     // we have to chek that the following Shopper fields are there
     $required_shopperfields_vm = Klarnahandler::getKlarnaVMGenericShopperFields();
     $required_shopperfields_bycountry = KlarnaHandler::getKlarnaSpecificShopperFields();
     $userFieldsModel = VmModel::getModel('UserFields');
     $switches['published'] = true;
     $userFields = $userFieldsModel->getUserFields('', $switches);
     // TEST that all Vm shopperfields are there
     foreach ($userFields as $userField) {
         $fields_name_vm[] = $userField->name;
     }
     $result = array_intersect($fields_name_vm, $required_shopperfields_vm);
     $vm_required_not_found = array_diff($required_shopperfields_vm, $result);
     if (count($vm_required_not_found)) {
         VmError(JText::sprintf('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_NOT_FOUND', implode(", ", $vm_required_not_found)));
     } else {
         VmInfo(JText::_('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_OK'));
     }
     $klarna_required_not_found = array();
     // TEST that all required Klarna shopper fields are there, if not create them
     foreach ($required_shopperfields_bycountry as $key => $shopperfield_country) {
         $active = 'klarna_active_' . strtolower($key);
         if ($method->{$active}) {
             $resultByCountry = array_intersect($fields_name_vm, $shopperfield_country);
             $klarna_required_country_not_found = array_diff($shopperfield_country, $resultByCountry);
             $klarna_required_not_found = array_merge($klarna_required_country_not_found, $klarna_required_not_found);
         }
     }
     $klarna_required_not_found = array_unique($klarna_required_not_found, SORT_STRING);
     if (count($klarna_required_not_found)) {
         VmError(JText::sprintf('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_NOT_FOUND', implode(", ", $klarna_required_not_found)));
     } else {
         VmInfo(JText::_('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_OK'));
     }
     //vmDebug('plgVmOnStoreInstallPaymentPluginTable', $create_shopperfield);
     /*
      * TODO: create all required shopperfields
      *
      */
     $result = $this->onStoreInstallPluginTable($jplugin_id);
     if (jrequest::getvar('redirect') == "no" and $result) {
         echo 'ok';
         jexit();
     }
     return $result;
 }
예제 #2
0
파일: klarna.php 프로젝트: sergy444/joomla
	/**
	 * Create the table for this plugin if it does not yet exist.
	 * This functions checks if the called plugin is active one.
	 * When yes it is calling the standard method to create the tables
	 *
	 */
	function plgVmOnStoreInstallPaymentPluginTable ($jplugin_id) {

		if ($jplugin_id != $this->_jid) {
			return FALSE;
		}
		if (!class_exists ('JFile')) {
			require(JPATH_SITE . DS . 'libraries' . DS . 'joomla' . DS . 'filesystem' . DS . 'file.php');
		}
		/*
		 * if the file Klarna.cfg does not exist, then create it
		 */
		$filename = VMKLARNA_CONFIG_FILE;
		if (!JFile::exists ($filename)) {
			$fileContents = "<?php defined('_JEXEC') or die();
	define('VMKLARNA_SHIPTO_SAME_AS_BILLTO', '1');
	define('VMKLARNA_SHOW_PRODUCTPRICE', '1');
	?>";
			$result = JFile::write ($filename, $fileContents);
			if (!$result) {
				VmError (JText::sprintf ('VMPAYMENT_KLARNA_CANT_WRITE_CONFIG', $filename, $result));
			}
		}

		$method = $this->getPluginMethod (JRequest::getInt ('virtuemart_paymentmethod_id'));
		if (KlarnaHandler::createKlarnaFolder ()) {
			$results = KlarnaHandler::fetchAllPClasses ($method);
			if (is_array ($results) and $results['msg']) {
				vmError ($results['msg']);
			}
		}
		vmDebug ('PClasses fetched for : ', $results['notice']);

		// we have to check that the following Shopper fields are there
		$required_shopperfields_vm = Klarnahandler::getKlarnaVMGenericShopperFields ();

		$required_shopperfields_bycountry = KlarnaHandler::getKlarnaSpecificShopperFields ();

		$userFieldsModel = VmModel::getModel ('UserFields');
		$switches['published'] = TRUE;
		$userFields = $userFieldsModel->getUserFields ('', $switches);
		// TEST that all Vm shopperfields are there
		foreach ($userFields as $userField) {
			$fields_name_vm[] = $userField->name;
		}
		$result = array_intersect ($fields_name_vm, $required_shopperfields_vm);
		$vm_required_not_found = array_diff ($required_shopperfields_vm, $result);
		if (count ($vm_required_not_found)) {
			VmError (JText::sprintf ('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_NOT_FOUND', implode (", ", $vm_required_not_found)));
		} else {
			VmInfo (JText::_ ('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_OK'));
		}
		VmConfig::loadJLang('com_virtuemart_shoppers', true);

		$klarna_required_not_found = array();
		// TEST that all required Klarna shopper fields are there, if not create them
		foreach ($required_shopperfields_bycountry as $key => $shopperfield_country) {
			$active = 'klarna_active_' . strtolower ($key);
			if ($method->$active) {
				$resultByCountry = array_intersect ($fields_name_vm, $shopperfield_country);
				$klarna_required_country_not_found = array_diff ($shopperfield_country, $resultByCountry);
				$klarna_required_not_found = array_merge ($klarna_required_country_not_found, $klarna_required_not_found);
			}
		}
		$klarna_required_not_found = array_unique ($klarna_required_not_found, SORT_STRING);
		if (count ($klarna_required_not_found)) {
			VmError (JText::sprintf ('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_NOT_FOUND', implode (", ", $klarna_required_not_found)));
			$shopperFieldsType = KlarnaHandler::getKlarnaShopperFieldsType ();
			$userfieldsModel = VmModel::getModel ('userfields');
			$data['virtuemart_userfield_id'] = 0;

			$data['published'] = 1;
			$data['required'] = 0;
			$data['account'] = 1;
			$data['shipment'] = 0;
			$data['vNames'] = array();
			$data['vValues'] = array();
			VmConfig::loadJLang('com_virtuemart_shoppers', true);

			foreach ($klarna_required_not_found as $requiredfield) {
				$data['name'] = $requiredfield;
				$data['type'] = $shopperFieldsType[$requiredfield];
				$data['title'] = strtoupper ('COM_VIRTUEMART_SHOPPER_FORM_' . $requiredfield);
				$ret = $userfieldsModel->store ($data);
				if (!$ret) {
					vmError (JText::_ ('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_ERROR_STORING') . $requiredfield);
				} else {
					vmInfo (JText::_ ('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_CREATE_OK') . $requiredfield);
				}
			}

		} else {
			VmInfo (JText::_ ('VMPAYMENT_KLARNA_REQUIRED_USERFIELDS_OK'));
		}

		$result = $this->onStoreInstallPluginTable ($jplugin_id);

		return $result;
	}