AAAAhome/academiac/www/administrator/components/com_virtuemart/plugins/vmpsplugin.php 0000604 00000130570 15137320355 0024720 0 ustar 00 _tablepkey = 'id'; //virtuemart_order_id';
$this->_idName = 'virtuemart_' . $this->_psType . 'method_id';
$this->_configTable = '#__virtuemart_' . $this->_psType . 'methods';
$this->_configTableFieldName = $this->_psType . '_params';
$this->_configTableFileName = $this->_psType . 'methods';
$this->_configTableClassName = 'Table' . ucfirst ($this->_psType) . 'methods'; //TablePaymentmethods
// $this->_configTableIdName = $this->_psType.'_jplugin_id';
$this->_loggable = TRUE;
$this->_tableChecked = TRUE;
}
public function getVarsToPush () {
$black_list = array('spacer');
$data = array();
if (JVM_VERSION === 2) {
$filename = JPATH_SITE . '/plugins/' . $this->_type . '/' . $this->_name . '/' . $this->_name . '.xml';
} else {
$filename = JPATH_SITE . '/plugins/' . $this->_type . '/' . $this->_name . '.xml';
}
// Check of the xml file exists
$filePath = JPath::clean ($filename);
if (is_file ($filePath)) {
$xml = JFactory::getXMLParser ('simple');
$result = $xml->loadFile ($filename);
if ($result) {
if ($params = $xml->document->params) {
foreach ($params as $param) {
if ($param->_name = "params") {
if ($children = $param->_children) {
foreach ($children as $child) {
if (isset($child->_attributes['name'])) {
$data[$child->_attributes['name']] = array('', 'char');
$result = TRUE;
}
}
}
}
}
}
}
}
return $data;
}
/**
* check if it is the correct type
*
* @param string $psType either payment or shipment
* @return boolean
*/
public function selectedThisType ($psType) {
if ($this->_psType <> $psType) {
return FALSE;
} else {
return TRUE;
}
}
/**
* 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
*
*/
protected function onStoreInstallPluginTable ($jplugin_id, $name = FALSE) {
if ($res = $this->selectedThisByJPluginId ($jplugin_id)) {
parent::onStoreInstallPluginTable ($this->_psType);
}
return $res;
}
/**
* This event is fired after the payment method has been selected. It can be used to store
* additional payment info in the cart.
*
* @author Max Milbers
* @author Valérie isaksen
*
* @param VirtueMartCart $cart: the actual cart
* @return null if the payment was not selected, true if the data is valid, error message if the data is not vlaid
*
*/
public function onSelectCheck (VirtueMartCart $cart) {
$idName = $this->_idName; //vmdebug('OnSelectCheck',$idName);
if (!$this->selectedThisByMethodId ($cart->$idName)) {
return NULL; // Another method was selected, do nothing
}
return TRUE; // this method was selected , and the data is valid by default
}
/**
* displayListFE
* This event is fired to display the pluginmethods in the cart (edit shipment/payment) for example
*
* @param object $cart Cart object
* @param integer $selected ID of the method selected
* @return boolean True on success, false on failures, null when this plugin was not selected.
* On errors, JError::raiseWarning (or JError::raiseError) must be used to set a message.
*
* @author Valerie Isaksen
* @author Max Milbers
*/
public function displayListFE (VirtueMartCart $cart, $selected = 0, &$htmlIn) {
if ($this->getPluginMethods ($cart->vendorId) === 0) {
if (empty($this->_name)) {
vmAdminInfo ('displayListFE cartVendorId=' . $cart->vendorId);
$app = JFactory::getApplication ();
$app->enqueueMessage (JText::_ ('COM_VIRTUEMART_CART_NO_' . strtoupper ($this->_psType)));
return FALSE;
} else {
return FALSE;
}
}
$html = array();
$method_name = $this->_psType . '_name';
foreach ($this->methods as $method) {
if ($this->checkConditions ($cart, $method, $cart->pricesUnformatted)) {
//$methodSalesPrice = $this->calculateSalesPrice ($cart, $method, $cart->pricesUnformatted);
/* Because of OPC: the price must not be overwritten directly in the cart */
$pricesUnformatted= $cart->pricesUnformatted;
$methodSalesPrice = $this->setCartPrices ($cart, $pricesUnformatted,$method);
$method->$method_name = $this->renderPluginName ($method);
$html [] = $this->getPluginHtml ($method, $selected, $methodSalesPrice);
}
}
if (!empty($html)) {
$htmlIn[] = $html;
return TRUE;
}
return FALSE;
}
/*
* onSelectedCalculatePrice
* Calculate the price (value, tax_id) of the selected method
* It is called by the calculator
* This function does NOT to be reimplemented. If not reimplemented, then the default values from this function are taken.
* @author Valerie Isaksen
* @cart: VirtueMartCart the current cart
* @cart_prices: array the new cart prices
* @return null if the method was not selected, false if the shipping rate is not valid any more, true otherwise
*
*/
public function onSelectedCalculatePrice (VirtueMartCart $cart, array &$cart_prices, &$cart_prices_name) {
$id = $this->_idName;
//vmTime('onSelectedCalculatePrice before test '.$cart->$id,'prepareCartData');
if (!($method = $this->selectedThisByMethodId ($cart->$id))) {
return NULL; // Another method was selected, do nothing
}
if (!($method = $this->getVmPluginMethod ($cart->$id))) {
return NULL;
}
$cart_prices_name = '';
$cart_prices['cost'] = 0;
if (!$this->checkConditions ($cart, $method, $cart_prices)) {
return FALSE;
}
$cart_prices_name = $this->renderPluginName ($method);
$this->setCartPrices ($cart, $cart_prices, $method);
return TRUE;
}
/**
* onCheckAutomaticSelected
* Checks how many plugins are available. If only one, the user will not have the choice. Enter edit_xxx page
* The plugin must check first if it is the correct type
*
* @author Valerie Isaksen
* @param VirtueMartCart cart: the cart object
* @return null if no plugin was found, 0 if more then one plugin was found, virtuemart_xxx_id if only one plugin is found
*
*/
function onCheckAutomaticSelected (VirtueMartCart $cart, array $cart_prices = array(), &$methodCounter = 0) {
$virtuemart_pluginmethod_id = 0;
$nbMethod = $this->getSelectable ($cart, $virtuemart_pluginmethod_id, $cart_prices);
$methodCounter += $nbMethod;
if ($nbMethod == NULL) {
return NULL;
} else {
if ($nbMethod == 1) {
return $virtuemart_pluginmethod_id;
} else {
return 0;
}
}
}
/**
* This method is fired when showing the order details in the frontend.
* It displays the method-specific data.
*
* @param integer $order_id The order ID
* @return mixed Null for methods that aren't active, text (HTML) otherwise
* @author Max Milbers
* @author Valerie Isaksen
*/
protected function onShowOrderFE ($virtuemart_order_id, $virtuemart_method_id, &$method_info) {
if (!($this->selectedThisByMethodId ($virtuemart_method_id))) {
return NULL;
}
$method_info = $this->getOrderMethodNamebyOrderId ($virtuemart_order_id);
}
/**
*
* @author Valerie Isaksen
* @author Max Milbers
* @param int $virtuemart_order_id
* @return string pluginName from the plugin table
*/
private function getOrderMethodNamebyOrderId ($virtuemart_order_id) {
$db = JFactory::getDBO ();
$q = 'SELECT * FROM `' . $this->_tablename . '` '
. 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id;
$db->setQuery ($q);
$err =$db->getErrorMsg ();
if (!($pluginInfo = $db->loadObject ())) {
vmdebug ('Attention, ' . $this->_tablename . ' has not any entry for order_id = '.$virtuemart_order_id);
if(!empty($err)){
vmWarn ('Attention, ' . $this->_tablename . ' has not any entry for order_id = '.$virtuemart_order_id. ' err = '.$err);
}
return NULL;
}
$idName = $this->_psType . '_name';
return $pluginInfo->$idName;
}
/**
*
* @author Valerie Isaksen
* @author Max Milbers
* @param int $virtuemart_order_id
* @return string pluginName from the plugin table
*/
private function getOrderPluginNamebyOrderId ($virtuemart_order_id) {
$db = JFactory::getDBO ();
$q = 'SELECT * FROM `' . $this->_tablename . '` '
. 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id;
$db->setQuery ($q);
if (!($pluginInfo = $db->loadObject ())) {
vmWarn (500, $q . " getOrderPluginNamebyOrderId " . $db->getErrorMsg ());
return NULL;
}
$idName = $this->_idName;
return $pluginInfo->$idName;
}
/**
* check if it is the correct element
*
* @param string $element either standard or paypal
* @return boolean
*/
public function selectedThisElement ($element) {
if ($this->_name <> $element) {
return FALSE;
} else {
return TRUE;
}
}
/**
* This method is fired when showing the order details in the backend.
* It displays the the payment method-specific data.
* All plugins *must* reimplement this method.
*
* @param integer $_virtuemart_order_id The order ID
* @param integer $_paymethod_id Payment method used for this order
* @return mixed Null when for payment methods that were not selected, text (HTML) otherwise
* @author Max Milbers
* @author Valerie Isaksen
*/
function onShowOrderBE ($_virtuemart_order_id, $_method_id) {
return NULL;
}
/**
* This method is fired when showing when priting an Order
* It displays the the payment method-specific data.
*
* @param integer $_virtuemart_order_id The order ID
* @param integer $method_id method used for this order
* @return mixed Null when for payment methods that were not selected, text (HTML) otherwise
* @author Valerie Isaksen
*/
function onShowOrderPrint ($order_number, $method_id) {
if (!$this->selectedThisByMethodId ($method_id)) {
return NULL; // Another method was selected, do nothing
}
if (!($order_name = $this->getOrderPluginName ($order_number, $method_id))) {
return NULL;
}
VmConfig::loadJLang('com_virtuemart');
$html = '
' . "\n";
return $html;
}
private function getOrderPluginName ($order_number, $pluginmethod_id) {
$db = JFactory::getDBO ();
$q = 'SELECT * FROM `' . $this->_tablename . '` WHERE `order_number` = "' . $order_number . '"
AND `' . $this->_idName . '` =' . $pluginmethod_id;
$db->setQuery ($q);
if (!($order = $db->loadObject ())) {
return NULL;
}
$plugin_name = $this->_psType . '_name';
return $order->$plugin_name;
}
/**
* Save updated order data to the method specific table
*
* @param array $_formData Form data
* @return mixed, True on success, false on failures (the rest of the save-process will be
* skipped!), or null when this method is not actived.
* @author Oscar van Eijk
*/
public function onUpdateOrder ($formData) {
return NULL;
}
/**
* Save updated orderline data to the method specific table
*
* @param array $_formData Form data
* @return mixed, True on success, false on failures (the rest of the save-process will be
* skipped!), or null when this method is not actived.
* @author Oscar van Eijk
*/
public function onUpdateOrderLine ($formData) {
return NULL;
}
/**
* OnEditOrderLineBE
* This method is fired when editing the order line details in the backend.
* It can be used to add line specific package codes
*
* @param integer $_orderId The order ID
* @param integer $_lineId
* @return mixed Null for method that aren't active, text (HTML) otherwise
* @author Oscar van Eijk
*/
public function onEditOrderLineBE ($orderId, $lineId) {
return NULL;
}
/**
* This method is fired when showing the order details in the frontend, for every orderline.
* It can be used to display line specific package codes, e.g. with a link to external tracking and
* tracing systems
*
* @param integer $_orderId The order ID
* @param integer $_lineId
* @return mixed Null for method that aren't active, text (HTML) otherwise
* @author Oscar van Eijk
*/
public function onShowOrderLineFE ($orderId, $lineId) {
return NULL;
}
/**
* This event is fired when the method notifies you when an event occurs that affects the order.
* Typically, the events represents for payment authorizations, Fraud Management Filter actions and other actions,
* such as refunds, disputes, and chargebacks.
*
* NOTE for Plugin developers:
* If the plugin is NOT actually executed (not the selected payment method), this method must return NULL
*
* @param $return_context: it was given and sent in the payment form. The notification should return it back.
* Used to know which cart should be emptied, in case it is still in the session.
* @param int $virtuemart_order_id : payment order id
* @param char $new_status : new_status for this order id.
* @return mixed Null when this method was not selected, otherwise the true or false
*
* @author Valerie Isaksen
*
*/
public function onNotification () {
return NULL;
}
/**
* OnResponseReceived
* This event is fired when the method returns to the shop after the transaction
*
* the method itself should send in the URL the parameters needed
* NOTE for Plugin developers:
* If the plugin is NOT actually executed (not the selected payment method), this method must return NULL
*
* @param int $virtuemart_order_id : should return the virtuemart_order_id
* @param text $html: the html to display
* @return mixed Null when this method was not selected, otherwise the true or false
*
* @author Valerie Isaksen
*
*/
function onResponseReceived (&$virtuemart_order_id, &$html) {
return NULL;
}
function getDebug () {
return $this->_debug;
}
function setDebug ($params) {
return $this->_debug = $params->get ('debug', 0);
}
/**
* Get Plugin Data for a go given plugin ID
*
* @author Valérie Isaksen
* @param int $pluginmethod_id The method ID
* @return method data
*/
final protected function getPluginMethod ($method_id) {
if (!$this->selectedThisByMethodId ($method_id)) {
return FALSE;
}
return $this->getVmPluginMethod ($method_id);
}
/**
* Fill the array with all plugins found with this plugin for the current vendor
*
* @return True when plugins(s) was (were) found for this vendor, false otherwise
* @author Oscar van Eijk
* @author max Milbers
* @author valerie Isaksen
*/
protected function getPluginMethods ($vendorId) {
if (!class_exists ('VirtueMartModelUser')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'user.php');
}
$usermodel = VmModel::getModel ('user');
$user = $usermodel->getUser ();
$user->shopper_groups = (array)$user->shopper_groups;
$db = JFactory::getDBO ();
$select = 'SELECT l.*, v.*, ';
if (JVM_VERSION === 1) {
$extPlgTable = '#__plugins';
$extField1 = 'id';
$extField2 = 'element';
$select .= 'j.`' . $extField1 . '`, j.`name`, j.`element`, j.`folder`, j.`client_id`, j.`access`,
j.`params`, j.`checked_out`, j.`checked_out_time`, s.virtuemart_shoppergroup_id ';
} else {
$extPlgTable = '#__extensions';
$extField1 = 'extension_id';
$extField2 = 'element';
$select .= 'j.`' . $extField1 . '`,j.`name`, j.`type`, j.`element`, j.`folder`, j.`client_id`, j.`enabled`, j.`access`, j.`protected`, j.`manifest_cache`,
j.`params`, j.`custom_data`, j.`system_data`, j.`checked_out`, j.`checked_out_time`, j.`state`, s.virtuemart_shoppergroup_id ';
}
if(!defined(VMLANG)){
VmConfig::setdbLanguageTag();
}
$q = $select . ' FROM `#__virtuemart_' . $this->_psType . 'methods_' . VMLANG . '` as l ';
$q .= ' JOIN `#__virtuemart_' . $this->_psType . 'methods` AS v USING (`virtuemart_' . $this->_psType . 'method_id`) ';
$q .= ' LEFT JOIN `' . $extPlgTable . '` as j ON j.`' . $extField1 . '` = v.`' . $this->_psType . '_jplugin_id` ';
$q .= ' LEFT OUTER JOIN `#__virtuemart_' . $this->_psType . 'method_shoppergroups` AS s ON v.`virtuemart_' . $this->_psType . 'method_id` = s.`virtuemart_' . $this->_psType . 'method_id` ';
$q .= ' WHERE v.`published` = "1" AND j.`' . $extField2 . '` = "' . $this->_name . '"
AND (v.`virtuemart_vendor_id` = "' . $vendorId . '" OR v.`virtuemart_vendor_id` = "0")
AND (';
foreach ($user->shopper_groups as $groups) {
$q .= ' s.`virtuemart_shoppergroup_id`= "' . (int)$groups . '" OR';
}
$q .= ' (s.`virtuemart_shoppergroup_id`) IS NULL ) GROUP BY v.`virtuemart_' . $this->_psType . 'method_id` ORDER BY v.`ordering`';
$db->setQuery ($q);
$this->methods = $db->loadObjectList ();
$err = $db->getErrorMsg ();
if (!empty($err)) {
vmError ('Error reading getPluginMethods ' . $err);
}
if ($this->methods) {
foreach ($this->methods as $method) {
VmTable::bindParameterable ($method, $this->_xParams, $this->_varsToPushParam);
}
}
return count ($this->methods);
}
/**
* Get Method Data for a given Payment ID
*
* @author Valérie Isaksen
* @param int $virtuemart_order_id The order ID
* @return $methodData
*/
final protected function getDataByOrderId ($virtuemart_order_id) {
$db = JFactory::getDBO ();
$q = 'SELECT * FROM `' . $this->_tablename . '` '
. 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id;
$db->setQuery ($q);
$methodData = $db->loadObject ();
return $methodData;
}
/**
* Get Method Datas for a given Payment ID
*
* @author Valérie Isaksen
* @param int $virtuemart_order_id The order ID
* @return $methodData
*/
final protected function getDatasByOrderId ($virtuemart_order_id) {
$db = JFactory::getDBO ();
$q = 'SELECT * FROM `' . $this->_tablename . '` '
. 'WHERE `virtuemart_order_id` = ' . $virtuemart_order_id;
$db->setQuery ($q);
$methodData = $db->loadObjectList ();
return $methodData;
}
/**
* Get the total weight for the order, based on which the proper shipping rate
* can be selected.
*
* @param object $cart Cart object
* @return float Total weight for the order
* @author Oscar van Eijk
*/
protected function getOrderWeight (VirtueMartCart $cart, $to_weight_unit) {
static $weight = 0.0;
if(count($cart->products)>0 and empty($weight)){
foreach ($cart->products as $product) {
$weight += (ShopFunctions::convertWeightUnit ($product->product_weight, $product->product_weight_uom, $to_weight_unit) * $product->quantity);
}
}
return $weight;
}
/**
* getThisName
* Get the name of the method
*
* @param int $id The method ID
* @author Valérie Isaksen
* @return string Shipment name
*/
final protected function getThisName ($virtuemart_method_id) {
$db = JFactory::getDBO ();
$q = 'SELECT `' . $this->_psType . '_name` '
. 'FROM #__virtuemart_' . $this->_psType . 'methods '
. 'WHERE ' . $this->_idName . ' = "' . $virtuemart_method_id . '" ';
$db->setQuery ($q);
return $db->loadResult (); // TODO Error check
}
/**
* Extends the standard function in vmplugin. Extendst the input data by virtuemart_order_id
* Calls the parent to execute the write operation
*
* @author Max Milbers
* @param array $_values
* @param string $_table
*/
protected function storePSPluginInternalData ($values, $primaryKey = 0, $preload = FALSE) {
if (!class_exists ('VirtueMartModelOrders')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'models' . DS . 'orders.php');
}
if (!isset($values['virtuemart_order_id'])) {
$values['virtuemart_order_id'] = VirtueMartModelOrders::getOrderIdByOrderNumber ($values['order_number']);
}
return $this->storePluginInternalData ($values, $primaryKey, 0, $preload);
}
/**
* Something went wrong, Send notification to all administrators
*
* @param string subject of the mail
* @param string message
*/
protected function sendEmailToVendorAndAdmins ($subject = NULL, $message = NULL) {
// recipient is vendor and admin
$vendorId = 1;
$vendorModel = VmModel::getModel('vendor');
$vendor = $vendorModel->getVendor($vendorId);
$vendorEmail = $vendorModel->getVendorEmail($vendorId);
$vendorName = $vendorModel->getVendorName($vendorId);
VmConfig::loadJLang('com_virtuemart');
if ($subject == NULL) {
$subject = JText::sprintf('COM_VIRTUEMART_ERROR_SUBJECT', $this->_name, $vendor->vendor_store_name);
}
if ($message == NULL) {
$link=juri::root().'administrator/index.php?option=com_virtuemart&view=log&task=edit&logfile='.$this->getLogFilename().VmConfig::LOGFILEEXT;
//$logFileLink=''.$this->getLogFilename().VmConfig::LOGFILEEXT.'';
$message = JText::sprintf('COM_VIRTUEMART_ERROR_BODY', $subject, $link);
}
JUtility::sendMail($vendorEmail, $vendorName, $vendorEmail, $subject, $message);
if (JVM_VERSION === 1) {
//get all super administrator
$query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE LOWER( usertype ) = "super administrator"';
} else {
$query = 'SELECT name, email, sendEmail' . ' FROM #__users' . ' WHERE sendEmail=1';
}
$db = JFactory::getDBO();
$db->setQuery($query);
$rows = $db->loadObjectList();
$subject = html_entity_decode($subject, ENT_QUOTES);
// get superadministrators id
foreach ($rows as $row) {
if ($row->sendEmail) {
$message = html_entity_decode($message, ENT_QUOTES);
JUtility::sendMail($vendorEmail, $vendorName, $row->email, $subject, $message);
}
}
}
/**
* displays the logos of a VirtueMart plugin
*
* @author Valerie Isaksen
* @author Max Milbers
* @param array $logo_list
* @return html with logos
*/
protected function displayLogos ($logo_list) {
$img = "";
if (!(empty($logo_list))) {
$url = JURI::root () . 'images/stories/virtuemart/' . $this->_psType . '/';
if (!is_array ($logo_list)) {
$logo_list = (array)$logo_list;
}
foreach ($logo_list as $logo) {
$alt_text = substr ($logo, 0, strpos ($logo, '.'));
$img .= ' ';
}
}
return $img;
}
/**
* @param $plugin plugin
*/
protected function renderPluginName ($plugin) {
$return = '';
$plugin_name = $this->_psType . '_name';
$plugin_desc = $this->_psType . '_desc';
$description = '';
// $params = new JParameter($plugin->$plugin_params);
// $logo = $params->get($this->_psType . '_logos');
$logosFieldName = $this->_psType . '_logos';
$logos = $plugin->$logosFieldName;
if (!empty($logos)) {
$return = $this->displayLogos ($logos) . ' ';
}
if (!empty($plugin->$plugin_desc)) {
$description = '' . $plugin->$plugin_desc . '';
}
$pluginName = $return . '' . $plugin->$plugin_name . '' . $description;
return $pluginName;
}
protected function getPluginHtml ($plugin, $selectedPlugin, $pluginSalesPrice) {
$pluginmethod_id = $this->_idName;
$pluginName = $this->_psType . '_name';
if ($selectedPlugin == $plugin->$pluginmethod_id) {
$checked = 'checked="checked"';
} else {
$checked = '';
}
if (!class_exists ('CurrencyDisplay')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
}
$currency = CurrencyDisplay::getInstance ();
$costDisplay = "";
if ($pluginSalesPrice) {
$costDisplay = $currency->priceDisplay ($pluginSalesPrice);
$costDisplay = ' (' . JText::_ ('COM_VIRTUEMART_PLUGIN_COST_DISPLAY') . $costDisplay . ")";
}
$html = '\n"
. '\n";
return $html;
}
/**
*
*/
protected function getHtmlHeaderBE () {
$class = "class='key'";
$html = ' ' . "\n"
. '