News:

Support the VirtueMart project and become a member

Main Menu

How to make the customer ID uppercase?

Started by kittmaster, August 25, 2012, 15:56:10 PM

Previous topic - Next topic

kittmaster

I know strtoupper is what I want to do, but I can't figure out how to incorporate it without crashing the page.  I want to do this to the customer ID and the order numbers (just need to get syntax right).

Can someone help me figure out how to uppercase the customer ID?

Thanks!


<td class="key">
<label for="customer_number">
<?php echo JText::_('COM_VIRTUEMART_USER_FORM_CUSTOMER_NUMBER'?>:
</label>
</td>
<td>
<?php if(Permissions::getInstance()->check('admin')) { ?>
<input type="text" class="inputbox" name="customer_number" id="customer_number" size="40" value="<?php echo $this->lists['custnumber'];
?>
" />
<?php } else {
echo $this->lists['custnumber'];
?>

</td>


ivus

Hi kittmaster,

If all you're wanting to do is display the CUSTOMER_NUMBER and ORDER_NUMBER (and maybe INVOICE_NUMBER too) in uppercase for no real reason except for styling you can just wrap your output code with strtoupper() like you mentioned. There's no real magic behind it as you can see in the PHP docs http://php.net/manual/en/function.strtoupper.php.



    <?php if(Permissions::getInstance()->check('admin')) { ?>
        <input type="text" class="inputbox" name="customer_number" id="customer_number" size="40" value="<?php echo strtoupper($this->lists['custnumber']); ?>" />
    <?php } else {
echo strtoupper($this->lists['custnumber']);
    } 
?>




Bare in mind that you will have to update every instance where these numbers appear in the templates (screen, print, email, pdf).  It's gonna be a tedious task.

ALAS!... the alternative solution is to make it all uppercase when the 3 numbers are generated, which means you'll only ever have to do it once and it'll cascade throughout your templates. Doesn't that sound like a far better solution?

You only need to update 2 files in the backend

To update the CUSTOMER_NUMBER
/administrator/components/com_virtuemart/models/user.php @ line 698, look for this function public function saveUserData(&$data,$trigger=true){}



if(empty($data['customer_number'])){
//if(!class_exists('vmUserPlugin')) require(JPATH_VM_SITE.DS.'helpers'.DS.'vmuserplugin.php');
///if(!$returnValues){
$data['customer_number'] = strtoupper( md5($data['username']) );
//}
} else {
if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'permissions.php');
if(!Permissions::getInstance()->check("admin,storeadmin")) {
unset($data['customer_number']);
}
}



To update the ORDER_NUMBER
/administrator/components/com_virtuemart/models/orders.php @ line 498, look for this function private function _createOrder($_cart, $_usr, $_prices){}



if(empty($_orderData->order_number)){
$_orderData->order_number = strtoupper( $this->generateOrderNumber($_usr->get('id'),4,$_orderData->virtuemart_vendor_id) );
}



To update the INVOICE_NUMBER
/administrator/components/com_virtuemart/models/orders.php @ line 995, look for this function function createInvoiceNumber($orderDetails, &$invoiceNumber){}


           
                if(empty($data['invoice_number'])) {
                    //$variable_fixed=sprintf("%05s",$num_rows);
                    $date = date("Y-m-d");
                    // $date = JFactory::getDate()->toMySQL();
                    $data['invoice_number'] = strtoupper( str_replace('-', '', substr($date,2,8)).substr(md5($orderDetails['order_number'].$orderDetails['order_status']),0,3).'0'.$count );
                }



PS: next time don't bump. If you had read this http://forum.virtuemart.net/index.php?topic=104795.0 and correctly posted your question, perhaps you would have gotten more responses.
BTW: this solution is for VM2.0.8e (I'd assume it rolls back a few versions too).

Good luck.