Index: components/com_virtuemart/controllers/productdetails.php
===================================================================
--- components/com_virtuemart/controllers/productdetails.php (revision 7223)
+++ components/com_virtuemart/controllers/productdetails.php (working copy)
@@ -1,385 +1,386 @@
-registerTask ('recommend', 'MailForm');
- $this->registerTask ('askquestion', 'MailForm');
- }
-
- function display($cachable = false, $urlparams = false) {
-
- $format = JRequest::getWord ('format', 'html');
- if ($format == 'pdf') {
- $viewName = 'Pdf';
- } else {
- $viewName = 'Productdetails';
- }
-
- $view = $this->getView ($viewName, $format);
-
- $view->display ();
- }
-
- /**
- * Send the ask question email.
- *
- * @author Kohl Patrick, Christopher Roussel
- */
- public function mailAskquestion () {
-
- JRequest::checkToken () or jexit ('Invalid Token');
-
- $app = JFactory::getApplication ();
- if(!VmConfig::get('ask_question',false)){
- $app->redirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), 'Function disabled');
- }
-
- if(!VmConfig::get('recommend_unauth',false)){
- $user = JFactory::getUser();
- if($user->guest){
- $app->redirect(JRoute::_('index.php?option=com_virtuemart','JGLOBAL_YOU_MUST_LOGIN_FIRST'));
- }
- }
- $view = $this->getView ('askquestion', 'html');
- if (!class_exists ('shopFunctionsF')) {
- require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
- }
-
- $vars = array();
- $min = VmConfig::get ('asks_minimum_comment_length', 50) + 1;
- $max = VmConfig::get ('asks_maximum_comment_length', 2000) - 1;
- $commentSize = mb_strlen (JRequest::getString ('comment'));
- $validMail = filter_var (JRequest::getVar ('email'), FILTER_VALIDATE_EMAIL);
-
- if ($commentSize < $min or $commentSize > $max or !$validMail) {
- $errmsg = JText::_ ('COM_VIRTUEMART_COMMENT_NOT_VALID_JS');
- if ($commentSize < $min) {
- vmdebug ('mailAskquestion', $min, $commentSize);
- $errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_CS_MIN');
- ;
- } else {
- if ($commentSize > $max) {
- $errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_CS_MAX');
- ;
- } else {
- if (!$validMail) {
- $errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_INV_MAIL');
- ;
- }
- }
- }
-
- $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), $errmsg);
- return;
- }
-
- $virtuemart_product_idArray = JRequest::getInt ('virtuemart_product_id', 0);
- if (is_array ($virtuemart_product_idArray)) {
- $virtuemart_product_id = (int)$virtuemart_product_idArray[0];
- } else {
- $virtuemart_product_id = (int)$virtuemart_product_idArray;
- }
- $productModel = VmModel::getModel ('product');
-
- $vars['product'] = $productModel->getProduct ($virtuemart_product_id);
-
- $user = JFactory::getUser ();
- if (empty($user->id)) {
- $fromMail = JRequest::getVar ('email'); //is sanitized then
- $fromName = JRequest::getVar ('name', ''); //is sanitized then
- $fromMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromMail);
- $fromName = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromName);
- } else {
- $fromMail = $user->email;
- $fromName = $user->name;
- }
- $vars['user'] = array('name' => $fromName, 'email' => $fromMail);
-
- $vendorModel = VmModel::getModel ('vendor');
- $VendorEmail = $vendorModel->getVendorEmail ($vars['product']->virtuemart_vendor_id);
- $vars['vendor'] = array('vendor_store_name' => $fromName);
-
- if (shopFunctionsF::renderMail ('askquestion', $VendorEmail, $vars, 'productdetails')) {
- $string = 'COM_VIRTUEMART_MAIL_SEND_SUCCESSFULLY';
- } else {
- $string = 'COM_VIRTUEMART_MAIL_NOT_SEND_SUCCESSFULLY';
- }
- $app->enqueueMessage (JText::_ ($string));
-
-
- $view->setLayout ('mail_confirmed');
- $view->display ();
- }
-
- /**
- * Send the Recommend to a friend email.
- *
- * @author Kohl Patrick,
- */
- public function mailRecommend () {
-
- JRequest::checkToken () or jexit ('Invalid Token');
-
- $app = JFactory::getApplication ();
- if(!VmConfig::get('show_emailfriend',false)){
- $app->redirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), 'Function disabled');
- }
- if(!VmConfig::get('recommend_unauth',false)){
- $user = JFactory::getUser();
- if($user->guest){
- $app->redirect(JRoute::_('index.php?option=com_virtuemart','JGLOBAL_YOU_MUST_LOGIN_FIRST'));
- }
- }
- // Display it all
- $view = $this->getView ('recommend', 'html');
-
- if (!class_exists ('shopFunctionsF')) {
- require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
- }
- if(!class_exists('ShopFunctions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'shopfunctions.php');
-
- $mainframe = JFactory::getApplication ();
- $vars = array();
-
- $virtuemart_product_idArray = JRequest::getInt ('virtuemart_product_id', 0);
- if (is_array ($virtuemart_product_idArray)) {
- $virtuemart_product_id = (int)$virtuemart_product_idArray[0];
- } else {
- $virtuemart_product_id = (int)$virtuemart_product_idArray;
- }
- $productModel = VmModel::getModel ('product');
-
- $vars['product'] = $productModel->getProduct ($virtuemart_product_id);
-
- $user = JFactory::getUser ();
- $vars['user'] = array('name' => $user->name, 'email' => $user->email);
-
- $vars['vendorEmail'] = $user->email;
- $vendorModel = VmModel::getModel ('vendor');
- $vendor = $vendorModel->getVendor ($vars['product']->virtuemart_vendor_id);
- $vendorModel->addImages ($vars['vendor']);
- $vendor->vendorFields = $vendorModel->getVendorAddressFields();
- $vars['vendor'] = $vendor;
- $vars['vendorAddress']= shopFunctions::renderVendorAddress($vars['product']->virtuemart_vendor_id);
-
- $vars['vendorEmail']= $user->email;
- $vars['vendor']->vendor_name =$user->name;
-
-
- $toMail = JRequest::getVar ('email'); //is sanitized then
- $toMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $toMail);
-
- if (shopFunctionsF::renderMail ('recommend', $toMail, $vars, 'productdetails', TRUE)) {
- $string = 'COM_VIRTUEMART_MAIL_SEND_SUCCESSFULLY';
- } else {
- $string = 'COM_VIRTUEMART_MAIL_NOT_SEND_SUCCESSFULLY';
- }
- $mainframe->enqueueMessage (JText::_ ($string));
-
-// vmdebug('my email vars ',$vars,$TOMail);
-
-
- $view->setLayout ('mail_confirmed');
- $view->display ();
- }
-
- /**
- * Ask Question form
- * Recommend form for Mail
- */
- public function MailForm () {
-
- /*OSP 2012-03-14 ...Track #375; allowed by setting */
- if (VmConfig::get ('recommend_unauth', 0) == '0') {
- $user = JFactory::getUser ();
- if (empty($user->id)) {
- VmInfo (JText::_ ('JGLOBAL_YOU_MUST_LOGIN_FIRST'));
- return;
- }
- }
- if (JRequest::getCmd ('task') == 'recommend') {
- $view = $this->getView ('recommend', 'html');
- } else {
- $view = $this->getView ('askquestion', 'html');
- }
-
- /* Set the layout */
- $view->setLayout ('form');
-
- // Display it all
- $view->display ();
- }
-
- /**
- * Add or edit a review
- */
- public function review () {
-
- $data = JRequest::get ('post');
-
- $model = VmModel::getModel ('ratings');
- $model->saveRating ($data);
- $errors = $model->getErrors ();
- if (empty($errors)) {
- $msg = JText::sprintf ('COM_VIRTUEMART_STRING_SAVED', JText::_ ('COM_VIRTUEMART_REVIEW'));
- }
- foreach ($errors as $error) {
- $msg = ($error) . '
';
- }
-
- $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . (int)$data['virtuemart_product_id'], FALSE), $msg);
-
- }
-
- /**
- * Json task for recalculation of prices
- *
- * @author Max Milbers
- * @author Patrick Kohl
- *
- */
- public function recalculate () {
-
- //$post = JRequest::get('request');
-
-// echo '
'.print_r($post,1).'
';
- jimport ('joomla.utilities.arrayhelper');
- $virtuemart_product_idArray = JRequest::getVar ('virtuemart_product_id', array()); //is sanitized then
- if(is_array($virtuemart_product_idArray)){
- JArrayHelper::toInteger ($virtuemart_product_idArray);
- $virtuemart_product_id = $virtuemart_product_idArray[0];
- } else {
- $virtuemart_product_id = $virtuemart_product_idArray;
- }
-
- $customPrices = array();
- $customVariants = JRequest::getVar ('customPrice', array()); //is sanitized then
- //echo ''.print_r($customVariants,1).'
';
-
- //MarkerVarMods
- foreach ($customVariants as $customVariant) {
- //foreach ($customVariant as $selected => $priceVariant) {
- //In this case it is NOT $selected => $variant, because we get it that way from the form
- foreach ($customVariant as $priceVariant => $selected) {
- //Important! sanitize array to int
- $selected = (int)$selected;
- $customPrices[$selected] = $priceVariant;
- }
- }
-
- $quantityArray = JRequest::getVar ('quantity', array()); //is sanitized then
- JArrayHelper::toInteger ($quantityArray);
-
- $quantity = 1;
- if (!empty($quantityArray[0])) {
- $quantity = $quantityArray[0];
- }
-
- $product_model = VmModel::getModel ('product');
-
- //VmConfig::$echoDebug = TRUE;
- $prices = $product_model->getPrice ($virtuemart_product_id, $customPrices, $quantity);
-
- $priceFormated = array();
- if (!class_exists ('CurrencyDisplay')) {
- require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
- }
- $currency = CurrencyDisplay::getInstance ();
- foreach ($prices as $name => $product_price) {
-// echo 'Price is '.print_r($name,1).'
';
- if ($name != 'costPrice') {
- $priceFormated[$name] = $currency->createPriceDiv ($name, '', $prices, TRUE);
- }
- }
-
- // Get the document object.
- $document = JFactory::getDocument ();
- // stAn: setName works in JDocumentHTML and not JDocumentRAW
- if (method_exists($document, 'setName')){
- $document->setName ('recalculate');
- }
-
- JResponse::setHeader ('Cache-Control', 'no-cache, must-revalidate');
- JResponse::setHeader ('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
- // Set the MIME type for JSON output.
- $document->setMimeEncoding ('application/json');
- JResponse::setHeader ('Content-Disposition', 'attachment;filename="recalculate.json"', TRUE);
- JResponse::sendHeaders ();
- echo json_encode ($priceFormated);
- jexit ();
- }
-
- public function getJsonChild () {
-
- $view = $this->getView ('productdetails', 'json');
-
- $view->display (NULL);
- }
-
- /**
- * Notify customer
- *
- * @author Seyi Awofadeju
- *
- */
- public function notifycustomer () {
-
- $data = JRequest::get ('post');
-
- $model = VmModel::getModel ('waitinglist');
- if (!$model->adduser ($data)) {
- $errors = $model->getErrors ();
- foreach ($errors as $error) {
- $msg = ($error) . '
';
- }
- $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $data['virtuemart_product_id'], FALSE), $msg);
- } else {
- $msg = JText::sprintf ('COM_VIRTUEMART_STRING_SAVED', JText::_ ('COM_VIRTUEMART_CART_NOTIFY'));
- $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $data['virtuemart_product_id'], FALSE), $msg);
- }
-
- }
- /*
- * Send an email to all shoppers who bought a product
- */
-
- public function sentProductEmailToShoppers () {
-
- $model = VmModel::getModel ('product');
- $model->sentProductEmailToShoppers ();
-
- }
-
-}
-// pure php no closing tag
+registerTask ('recommend', 'MailForm');
+ $this->registerTask ('askquestion', 'MailForm');
+ }
+
+ function display($cachable = false, $urlparams = false) {
+
+ $format = JRequest::getWord ('format', 'html');
+ if ($format == 'pdf') {
+ $viewName = 'Pdf';
+ } else {
+ $viewName = 'Productdetails';
+ }
+
+ $view = $this->getView ($viewName, $format);
+
+ $view->display ();
+ }
+
+ /**
+ * Send the ask question email.
+ *
+ * @author Kohl Patrick, Christopher Roussel
+ */
+ public function mailAskquestion () {
+
+ JRequest::checkToken () or jexit ('Invalid Token');
+
+ $app = JFactory::getApplication ();
+ if(!VmConfig::get('ask_question',false)){
+ $app->redirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), 'Function disabled');
+ }
+
+ if(!VmConfig::get('recommend_unauth',false)){
+ $user = JFactory::getUser();
+ if($user->guest){
+ $app->redirect(JRoute::_('index.php?option=com_virtuemart','JGLOBAL_YOU_MUST_LOGIN_FIRST'));
+ }
+ }
+ $view = $this->getView ('askquestion', 'html');
+ if (!class_exists ('shopFunctionsF')) {
+ require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
+ }
+
+ $vars = array();
+ $min = VmConfig::get ('asks_minimum_comment_length', 50) + 1;
+ $max = VmConfig::get ('asks_maximum_comment_length', 2000) - 1;
+ $commentSize = mb_strlen (JRequest::getString ('comment'));
+ $validMail = filter_var (JRequest::getVar ('email'), FILTER_VALIDATE_EMAIL);
+
+ if ($commentSize < $min or $commentSize > $max or !$validMail) {
+ $errmsg = JText::_ ('COM_VIRTUEMART_COMMENT_NOT_VALID_JS');
+ if ($commentSize < $min) {
+ vmdebug ('mailAskquestion', $min, $commentSize);
+ $errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_CS_MIN');
+ ;
+ } else {
+ if ($commentSize > $max) {
+ $errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_CS_MAX');
+ ;
+ } else {
+ if (!$validMail) {
+ $errmsg = JText::_ ('COM_VIRTUEMART_ASKQU_INV_MAIL');
+ ;
+ }
+ }
+ }
+
+ $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), $errmsg);
+ return;
+ }
+
+ $virtuemart_product_idArray = JRequest::getInt ('virtuemart_product_id', 0);
+ if (is_array ($virtuemart_product_idArray)) {
+ $virtuemart_product_id = (int)$virtuemart_product_idArray[0];
+ } else {
+ $virtuemart_product_id = (int)$virtuemart_product_idArray;
+ }
+ $productModel = VmModel::getModel ('product');
+
+ $vars['product'] = $productModel->getProduct ($virtuemart_product_id);
+
+ $user = JFactory::getUser ();
+ if (empty($user->id)) {
+ $fromMail = JRequest::getVar ('email'); //is sanitized then
+ $fromName = JRequest::getVar ('name', ''); //is sanitized then
+ $fromMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromMail);
+ $fromName = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $fromName);
+ } else {
+ $fromMail = $user->email;
+ $fromName = $user->name;
+ }
+ $vars['user'] = array('name' => $fromName, 'email' => $fromMail);
+
+ $vendorModel = VmModel::getModel ('vendor');
+ $VendorEmail = $vendorModel->getVendorEmail ($vars['product']->virtuemart_vendor_id);
+ $vars['vendor'] = array('vendor_store_name' => $fromName);
+
+ if (shopFunctionsF::renderMail ('askquestion', $VendorEmail, $vars, 'productdetails')) {
+ $string = 'COM_VIRTUEMART_MAIL_SEND_SUCCESSFULLY';
+ } else {
+ $string = 'COM_VIRTUEMART_MAIL_NOT_SEND_SUCCESSFULLY';
+ }
+ $app->enqueueMessage (JText::_ ($string));
+
+
+ $view->setLayout ('mail_confirmed');
+ $view->display ();
+ }
+
+ /**
+ * Send the Recommend to a friend email.
+ *
+ * @author Kohl Patrick,
+ */
+ public function mailRecommend () {
+
+ JRequest::checkToken () or jexit ('Invalid Token');
+
+ $app = JFactory::getApplication ();
+ if(!VmConfig::get('show_emailfriend',false)){
+ $app->redirect (JRoute::_ ('index.php?option=com_virtuemart&tmpl=component&view=productdetails&task=askquestion&virtuemart_product_id=' . JRequest::getInt ('virtuemart_product_id', 0)), 'Function disabled');
+ }
+ if(!VmConfig::get('recommend_unauth',false)){
+ $user = JFactory::getUser();
+ if($user->guest){
+ $app->redirect(JRoute::_('index.php?option=com_virtuemart','JGLOBAL_YOU_MUST_LOGIN_FIRST'));
+ }
+ }
+ // Display it all
+ $view = $this->getView ('recommend', 'html');
+
+ if (!class_exists ('shopFunctionsF')) {
+ require(JPATH_VM_SITE . DS . 'helpers' . DS . 'shopfunctionsf.php');
+ }
+ if(!class_exists('ShopFunctions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'shopfunctions.php');
+
+ $mainframe = JFactory::getApplication ();
+ $vars = array();
+
+ $virtuemart_product_idArray = JRequest::getInt ('virtuemart_product_id', 0);
+ if (is_array ($virtuemart_product_idArray)) {
+ $virtuemart_product_id = (int)$virtuemart_product_idArray[0];
+ } else {
+ $virtuemart_product_id = (int)$virtuemart_product_idArray;
+ }
+ $productModel = VmModel::getModel ('product');
+
+ $vars['product'] = $productModel->getProduct ($virtuemart_product_id);
+
+ $user = JFactory::getUser ();
+ $vars['user'] = array('name' => $user->name, 'email' => $user->email);
+
+ $vars['vendorEmail'] = $user->email;
+ $vendorModel = VmModel::getModel ('vendor');
+ $vendor = $vendorModel->getVendor ($vars['product']->virtuemart_vendor_id);
+ $vendorModel->addImages ($vars['vendor']);
+ $vendor->vendorFields = $vendorModel->getVendorAddressFields();
+ $vars['vendor'] = $vendor;
+ $vars['vendorAddress']= shopFunctions::renderVendorAddress($vars['product']->virtuemart_vendor_id);
+
+ $vars['vendorEmail']= $user->email;
+ $vars['vendor']->vendor_name =$user->name;
+
+
+ $toMail = JRequest::getVar ('email'); //is sanitized then
+ $toMail = str_replace (array('\'', '"', ',', '%', '*', '/', '\\', '?', '^', '`', '{', '}', '|', '~'), array(''), $toMail);
+
+ if (shopFunctionsF::renderMail ('recommend', $toMail, $vars, 'productdetails', TRUE)) {
+ $string = 'COM_VIRTUEMART_MAIL_SEND_SUCCESSFULLY';
+ } else {
+ $string = 'COM_VIRTUEMART_MAIL_NOT_SEND_SUCCESSFULLY';
+ }
+ $mainframe->enqueueMessage (JText::_ ($string));
+
+// vmdebug('my email vars ',$vars,$TOMail);
+
+
+ $view->setLayout ('mail_confirmed');
+ $view->display ();
+ }
+
+ /**
+ * Ask Question form
+ * Recommend form for Mail
+ */
+ public function MailForm () {
+
+ /*OSP 2012-03-14 ...Track #375; allowed by setting */
+ if (VmConfig::get ('recommend_unauth', 0) == '0') {
+ $user = JFactory::getUser ();
+ if (empty($user->id)) {
+ VmInfo (JText::_ ('JGLOBAL_YOU_MUST_LOGIN_FIRST'));
+ return;
+ }
+ }
+ if (JRequest::getCmd ('task') == 'recommend') {
+ $view = $this->getView ('recommend', 'html');
+ } else {
+ $view = $this->getView ('askquestion', 'html');
+ }
+
+ /* Set the layout */
+ $view->setLayout ('form');
+
+ // Display it all
+ $view->display ();
+ }
+
+ /**
+ * Add or edit a review
+ */
+ public function review () {
+
+ $data = JRequest::get ('post');
+
+ $model = VmModel::getModel ('ratings');
+ $model->saveRating ($data);
+ $errors = $model->getErrors ();
+ if (empty($errors)) {
+ $msg = JText::sprintf ('COM_VIRTUEMART_STRING_SAVED', JText::_ ('COM_VIRTUEMART_REVIEW'));
+ }
+ foreach ($errors as $error) {
+ $msg = ($error) . '
';
+ }
+
+ $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . (int)$data['virtuemart_product_id'], FALSE), $msg);
+
+ }
+
+ /**
+ * Json task for recalculation of prices
+ *
+ * @author Max Milbers
+ * @author Patrick Kohl
+ *
+ */
+ public function recalculate () {
+
+ //$post = JRequest::get('request');
+ $priceFormated = array();
+// echo ''.print_r($post,1).'
';
+ jimport ('joomla.utilities.arrayhelper');
+ $virtuemart_product_idArray = JRequest::getVar ('virtuemart_product_id', array()); //is sanitized then
+ if(is_array($virtuemart_product_idArray)){
+ JArrayHelper::toInteger ($virtuemart_product_idArray);
+ $virtuemart_product_id = $virtuemart_product_idArray[0];
+ } else {
+ $virtuemart_product_id = $virtuemart_product_idArray;
+ }
+ //stAn for debugging purposes let's return the product's ids as well:
+ $priceFormated['products'] = $virtuemart_product_idArray;
+ $customPrices = array();
+ $customVariants = JRequest::getVar ('customPrice', array()); //is sanitized then
+ //echo ''.print_r($customVariants,1).'
';
+
+ //MarkerVarMods
+ foreach ($customVariants as $customVariant) {
+ //foreach ($customVariant as $selected => $priceVariant) {
+ //In this case it is NOT $selected => $variant, because we get it that way from the form
+ foreach ($customVariant as $priceVariant => $selected) {
+ //Important! sanitize array to int
+ $selected = (int)$selected;
+ $customPrices[$selected] = $priceVariant;
+ }
+ }
+
+ $quantityArray = JRequest::getVar ('quantity', array()); //is sanitized then
+ JArrayHelper::toInteger ($quantityArray);
+
+ $quantity = 1;
+ if (!empty($quantityArray[0])) {
+ $quantity = $quantityArray[0];
+ }
+
+ $product_model = VmModel::getModel ('product');
+
+ //VmConfig::$echoDebug = TRUE;
+ $prices = $product_model->getPrice ($virtuemart_product_id, $customPrices, $quantity);
+
+
+ if (!class_exists ('CurrencyDisplay')) {
+ require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'currencydisplay.php');
+ }
+ $currency = CurrencyDisplay::getInstance ();
+ foreach ($prices as $name => $product_price) {
+// echo 'Price is '.print_r($name,1).'
';
+ if ($name != 'costPrice') {
+ $priceFormated[$name] = $currency->createPriceDiv ($name, '', $prices, TRUE);
+ }
+ }
+
+ // Get the document object.
+ $document = JFactory::getDocument ();
+ // stAn: setName works in JDocumentHTML and not JDocumentRAW
+ if (method_exists($document, 'setName')){
+ $document->setName ('recalculate');
+ }
+
+ JResponse::setHeader ('Cache-Control', 'no-cache, must-revalidate');
+ JResponse::setHeader ('Expires', 'Mon, 6 Jul 2000 10:00:00 GMT');
+ // Set the MIME type for JSON output.
+ $document->setMimeEncoding ('application/json');
+ JResponse::setHeader ('Content-Disposition', 'attachment;filename="recalculate.json"', TRUE);
+ JResponse::sendHeaders ();
+ echo json_encode ($priceFormated);
+ jexit ();
+ }
+
+ public function getJsonChild () {
+
+ $view = $this->getView ('productdetails', 'json');
+
+ $view->display (NULL);
+ }
+
+ /**
+ * Notify customer
+ *
+ * @author Seyi Awofadeju
+ *
+ */
+ public function notifycustomer () {
+
+ $data = JRequest::get ('post');
+
+ $model = VmModel::getModel ('waitinglist');
+ if (!$model->adduser ($data)) {
+ $errors = $model->getErrors ();
+ foreach ($errors as $error) {
+ $msg = ($error) . '
';
+ }
+ $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&layout=notify&virtuemart_product_id=' . $data['virtuemart_product_id'], FALSE), $msg);
+ } else {
+ $msg = JText::sprintf ('COM_VIRTUEMART_STRING_SAVED', JText::_ ('COM_VIRTUEMART_CART_NOTIFY'));
+ $this->setRedirect (JRoute::_ ('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' . $data['virtuemart_product_id'], FALSE), $msg);
+ }
+
+ }
+ /*
+ * Send an email to all shoppers who bought a product
+ */
+
+ public function sentProductEmailToShoppers () {
+
+ $model = VmModel::getModel ('product');
+ $model->sentProductEmailToShoppers ();
+
+ }
+
+}
+// pure php no closing tag
Index: components/com_virtuemart/assets/js/vmprices.js
===================================================================
--- components/com_virtuemart/assets/js/vmprices.js (revision 7223)
+++ components/com_virtuemart/assets/js/vmprices.js (working copy)
@@ -3,15 +3,50 @@
var Virtuemart = {
setproducttype : function (form, id) {
form.view = null;
- var $ = jQuery, datas = form.serialize();
+ var $ = jQuery;
+ //orignal: datas = form.serialize();
+
+ var datas = form.serializeArray();
+
+ var query = '';
+ for (var i=0; i"+form.find(".pname").val()+"";
} else {
+ if (typeof vmCartError != 'undefined')
var txt = ""+vmCartError+"
"+datas.msg;
+ else
+ var txt = "Cart Error
"+datas.msg;
}
- if(usefancy){
+ if ((typeof usefancy != 'undefined') && (usefancy))
+ {
$.fancybox({
"titlePosition" : "inside",
"transitionIn" : "elastic",
@@ -85,16 +164,20 @@
}
);
} else {
- $.facebox.settings.closeImage = closeImage;
- $.facebox.settings.loadingImage = loadingImage;
- //$.facebox.settings.faceboxHtml = faceboxHtml;
- $.facebox({ text: txt }, 'my-groovy-style');
+ if (typeof $.facebox != 'undefined')
+ {
+ $.facebox.settings.closeImage = closeImage;
+ $.facebox.settings.loadingImage = loadingImage;
+ //$.facebox.settings.faceboxHtml = faceboxHtml;
+ $.facebox({ text: txt }, 'my-groovy-style');
+ }
}
if ($(".vmCartModule")[0]) {
Virtuemart.productUpdate($(".vmCartModule"));
}
- });
+ }
+ });
$.ajaxSetup({ cache: true });
},
@@ -145,6 +228,18 @@
});
});
+ },
+ log: function()
+ {
+ //stAn,maybe a global logging variable should be present
+ if ((typeof virtuemart_debug != 'undefined') && (virtuemart_debug == true))
+ if (typeof console != 'undefined')
+ if (typeof console.log != 'undefined')
+ if (console.log != null)
+ for (var i = 0; i < arguments.length; i++) {
+ console.log(arguments[i]);
+ }
+
}
};
jQuery.noConflict();
Index: administrator/components/com_virtuemart/plugins/vmpsplugin.php
===================================================================
--- administrator/components/com_virtuemart/plugins/vmpsplugin.php (revision 7223)
+++ administrator/components/com_virtuemart/plugins/vmpsplugin.php (working copy)
@@ -1023,7 +1023,8 @@
if($this->_psType=='payment'){
$cartTotalAmountOrig=$this->getCartAmount($cart_prices);
- $cartTotalAmount=($cartTotalAmountOrig+ $method->cost_per_transaction) / (1 -($method->cost_percent_total * 0.01));
+ $cartTotalAmount=($cartTotalAmountOrig+ $method->cost_per_transaction);
+ $cartTotalAmount += $cartTotalAmount * ($method->cost_percent_total * 0.01);
$cart_prices[$this->_psType . 'Value'] = $cartTotalAmount - $cartTotalAmountOrig;
}
Index: administrator/components/com_virtuemart/helpers/config.php
===================================================================
--- administrator/components/com_virtuemart/helpers/config.php (revision 7223)
+++ administrator/components/com_virtuemart/helpers/config.php (working copy)
@@ -1018,11 +1018,29 @@
* @param boolean load minified version
* @return nothing
*/
-
+ public static $loaded = array();
+
+ /* stAn, i would like to introduce overrides to VM js API so any of the javascript functions can be overriden from onAfterRoute by including the configuration file and registering a class and methods within $loaded_overrides
+ Example usage from a system plugin onAfterRoute:
+
+ if (!class_exists('VmConfig'))
+ require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
+
+ vmJsApi::$override_class = 'myClass';
+
+ class myClass {
+ public static js($namespace,$path=FALSE,$version='', $minified = NULL)
+ {
+ // code to override the default js scripts
+ }
+ }
+
+ */
+ public static $override_class = '';
public static function js($namespace,$path=FALSE,$version='', $minified = NULL)
{
- static $loaded = array();
+
// Only load once
// using of namespace assume same library have same namespace
// NEVER WRITE FULL NAME AS $namespace IN CASE OF REVISION NUMBER IF YOU WANT PREVENT MULTI LOAD !!!
@@ -1031,9 +1049,28 @@
// loading 2 time a JS file with this method simply return and do not load it the second time
- if (!empty($loaded[$namespace])) {
+ if (!empty(self::$loaded[$namespace])) {
return;
}
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ call_user_func($callable, $namespace,$path,$version, $minified);
+ return;
+ }
+
+ }
+
$file = vmJsApi::setPath($namespace,$path,$version, $minified , 'js');
$document = JFactory::getDocument();
$document->addScript( $file );
@@ -1052,7 +1089,7 @@
public static function css($namespace,$path = FALSE ,$version='', $minified = NULL)
{
- static $loaded = array();
+
// Only load once
// using of namespace assume same css have same namespace
@@ -1061,11 +1098,29 @@
if (!empty($loaded[$namespace])) {
return;
}
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ call_user_func($callable, $namespace,$path,$version, $minified);
+ return;
+ }
+
+ }
$file = vmJsApi::setPath( $namespace,$path, $version='', $minified , 'css');
$document = JFactory::getDocument();
$document->addStyleSheet($file);
- $loaded[$namespace] = TRUE;
+ self::$loaded[$namespace] = TRUE;
}
@@ -1117,6 +1172,25 @@
*/
static function jQuery($isSite=-1) {
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $isSite);
+
+ }
+
+ }
+
//Very important convention with other 3rd pary developers, must be kept
if (JFactory::getApplication ()->get ('jquery')) {
return FALSE;
@@ -1154,7 +1228,24 @@
// Virtuemart product and price script
static function jPrice()
{
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable);
+
+ }
+ }
if (!VmConfig::get ('jprice', TRUE) and JFactory::getApplication ()->isSite ()) {
return FALSE;
}
@@ -1214,17 +1305,52 @@
// Virtuemart Site Js script
static function jSite()
{
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable);
+
+ }
+ }
if (!VmConfig::get ('jsite', TRUE) and JFactory::getApplication ()->isSite ()) {
return FALSE;
}
vmJsApi::js('vmsite');
}
+
+ static function JcountryStateList($stateIds, $prefix='') {
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $stateIds, $prefix);
+
+ }
- static function JcountryStateList($stateIds, $prefix='') {
- static $JcountryStateList = array();
+ }
+
// If exist exit
- if (isset($JcountryStateList[$prefix]) or !VmConfig::get ('jsite', TRUE)) {
+ if (isset(self::$loaded['JcountryStateList'.$prefix]) or !VmConfig::get ('jsite', TRUE)) {
return;
}
$document = JFactory::getDocument();
@@ -1236,15 +1362,32 @@
});
//]]>
');
- $JcountryStateList[$prefix] = TRUE;
+ self::$loaded['JcountryStateList'.$prefix] = TRUE;
return;
}
static function chosenDropDowns(){
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $stateIds, $prefix);
+
+ }
- static $chosenDropDowns = false;
+ }
+
- if(!$chosenDropDowns){
+ if(empty(self::$loaded['chosenDropDowns'])){
if(VmConfig::get ('jchosen', 0)){
vmJsApi::js('chosen.jquery.min');
@@ -1262,18 +1405,34 @@
//]]>
');
}
- $chosenDropDowns = true;
+ self::$loaded['chosenDropDowns'] = true;
}
return;
}
static function JvalideForm($name='#adminForm')
{
- static $jvalideForm;
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $stateIds, $prefix);
+
+ }
+
+ }
// If exist exit
- if ($jvalideForm === $name) {
- return;
- }
+ if (!empty(self::$loaded['jvalideForm']) && (self::$loaded['jvalideForm']===$name)) return;
+
$document = JFactory::getDocument();
$document->addScriptDeclaration( "
//
" );
- if ($jvalideForm) {
+ if (!empty(self::$loaded['jvalidateForm'])) {
return;
}
vmJsApi::js( 'jquery.validationEngine');
@@ -1302,16 +1461,36 @@
vmJsApi::css ( 'validationEngine.template' );
vmJsApi::css ( 'validationEngine.jquery' );
- $jvalideForm = $name;
+
+ self::$loaded['jvalidateForm'] = $name;
+
+
}
// Virtuemart product and price script
static function jCreditCard()
{
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $stateIds, $prefix);
+
+ }
- static $jCreditCard;
+ }
+
// If exist exit
- if ($jCreditCard) {
+ if (!empty(self::$loaded['jCreditCard'])) {
return;
}
JFactory::getLanguage()->load('com_virtuemart');
@@ -1332,7 +1511,7 @@
$doc = JFactory::getDocument();
$doc->addScriptDeclaration($js);
- $jCreditCard = TRUE;
+ self::$loaded['jCreditCard'] = true;
return TRUE;
}
@@ -1343,12 +1522,29 @@
*/
static function cssSite() {
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $stateIds, $prefix);
+
+ }
+ }
if (!VmConfig::get ('css', TRUE)) {
return FALSE;
}
- static $cssSite;
- if ($cssSite) {
+
+ if (!empty(self::$loaded['cssSite'])) {
return;
}
// Get the Page direction for right to left support
@@ -1358,14 +1554,31 @@
// If exist exit
vmJsApi::css ( $cssFile ) ;
- $cssSite = TRUE;
+ self::$loaded['cssSite'] = true;
return TRUE;
}
// $yearRange format >> 1980:2010
// Virtuemart Datepicker script
static function jDate($date='',$name="date",$id=NULL,$resetBt = TRUE, $yearRange='') {
+ if (!empty(self::$override_class))
+ {
+
+ // override class name
+ $class_name = self::$override_class;
+ // current method name
+ $method_name = __FUNCTION__;
+ // check if the current method exists in the overrided function
+ $callable = "{$class_name}::{$method_name}";
+
+ if (@is_callable( $callable ) === true )
+ {
+
+ return call_user_func($callable, $date,$name,$id,$resetBt, $yearRange);
+
+ }
+ }
if ($yearRange) {
$yearRange = 'yearRange: "' . $yearRange . '",';
}
@@ -1375,7 +1588,7 @@
if (empty($id)) {
$id = $name;
}
- static $jDate;
+
$dateFormat = JText::_('COM_VIRTUEMART_DATE_FORMAT_INPUT_J16');//="m/d/y"
$search = array('m', 'd');
@@ -1400,12 +1613,13 @@
}
// If exist exit
- if ($jDate) {
+ if (!empty(self::$loaded['jDate'])) {
return $display;
}
$front = 'components/com_virtuemart/assets/';
$document = JFactory::getDocument();
+ // stAn: to update the below script for jQuery 1.9 compatiblity, change .live( to .on(
$document->addScriptDeclaration('
//