Vendor emails are not sent

Please post your issues and questions about One Page Checkout for Virtuemart 2 to this forum.

Vendor emails are not sent

Postby admin » Tue Jul 01, 2014 1:35 pm

hello friends, in some cases when your database got modified due to any reason, and for some reason the emails are not sent to the vendor (never) you may want to update a code within the vendor classes

\administrator\components\com_virtuemart\models\vendor.php


locate this function:
Code: Select all
/**
    * Find the user id given a vendor id
    *
    * @author Max Milbers
    * @param int $virtuemart_vendor_id
    * @return int $virtuemart_user_id
    */
   static function getUserIdByVendorId ($vendorId) {

      //this function is used static, needs its own db

      if (empty($vendorId)) {
         return;
      } else {
         $db = JFactory::getDBO ();
         $query = 'SELECT `virtuemart_user_id` FROM `#__virtuemart_vmusers` WHERE `virtuemart_vendor_id`=' . (int)$vendorId;
         $db->setQuery ($query);
         $result = $db->loadResult ();
         $err = $db->getErrorMsg ();
         if (!empty($err)) {
            vmError ('getUserIdByVendorId ' . $err, 'Failed to retrieve user id by vendor');
         }
         return (isset($result) ? $result : 0);
      }
   }



and update it to this:
Code: Select all
/**
    * Find the user id given a vendor id
    *
    * @author Max Milbers
    * @param int $virtuemart_vendor_id
    * @return int $virtuemart_user_id
    */
   static function getUserIdByVendorId ($vendorId) {

      //this function is used static, needs its own db

      if (empty($vendorId)) {
         return;
      } else {
         $db = JFactory::getDBO ();
         
                  $query = 'SELECT * FROM `#__virtuemart_vmusers`';
                  $db->setQuery($query);
                  $res = $db->loadAssocList();
                  //var_dump($res); die();
                  
         $query = 'SELECT `virtuemart_user_id` FROM `#__virtuemart_vmusers` as vmu, `#__users` as ju WHERE `virtuemart_vendor_id`=' . (int)$vendorId.' and ju.id = vmu.virtuemart_user_id and vmu.user_is_vendor = 1 limit 0,1';
         $db->setQuery ($query);
         $result = $db->loadResult ();
         $err = $db->getErrorMsg ();
         if (!empty($err)) {
            vmError ('getUserIdByVendorId ' . $err, 'Failed to retrieve user id by vendor');
         }
         
         
         return (isset($result) ? $result : 0);
      }
   }



The new query will:
- make sure that the user also exists in joomla (#__users)
- will be faster as it's using limit clause on non indexed column and thus full table search is not necessary
- double checks if the user is really vendor

best regards, stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Return to One Page Checkout for Virtuemart 2

cron