E anche oggi ho risolto un bel problema.
Un cliente, da quanti ordini ha, (beato lui) non riesce più a gestirli e mi ha chiesto la seguente modifica:
- dall'elenco degli ordini gli serve un pulsante per stampare in blocco tutti gli ordini che non sono stati evasi finora. Per lui evasi voleva dire non stampati.
Si tratta di andare a modificare in maniera non troppo pesante un joomla 1.5 e un Virtuemart 1.1.3
Sostanzialmente, ho copiato il file order.order_printdetails.php presente nella cartella administrator/components/com_v
Almeno con la visualizzazione degli ordini.
Ah no, la prima cosa che ho fatto è stata quella di aggiungere nella tabella di virtuemart orders un nuovo campo per la gestione di un flag, chiamato flag_stampa e l'ho messo di default a 0, perchè alla creazione dell'ordine doveva restare così.
Poi ho fatto una query per portar tutta la tabella ad un valore di 1 del suddetto campo.
A mano poi ne ho modificati due o tre riportandoli a 0 giusto per provare.
Bene...
questo è il file che ho fatto...
<code>
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: order.order_printdetails.php 1408 2008-06-10 04:03:14Z soeren_nb $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gp
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_
*
*/
mm_showMyFileName( __FILE__ );
global $ps_order_status;
require_once(CLASSPATH.'ps_che
require_once(CLASSPATH.'ps_use
require_once(CLASSPATH.'ps_pro
$ps_product= new ps_product;
$registrationfields = ps_userfield::getUserFields('r
$shippingfields = ps_userfield::getUserFields('s
//$order_id = vmRequest::getInt('order_id', 0);
$dbc = new ps_DB;
?>
<script>
var xmlhttp
var myform
var testk
//funzione da richiamare se non devo fare niente prima
function Kload(url, miafunzione, send1)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.
}
if (xmlhttp!=null)
{
testk=miafunzione
xmlhttp.onreadysta
xmlhttp.open("
xmlhttp.setRequest
xmlhttp.send(send1
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}
function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
eval(testk+'(xmlhttp.res
}
else
{
alert("Proble
}
}
}
function load_page(url, mydiv2, callback)
{
mydiv=document.getElementById(
mydiv.innerHTML=mydiv.innerHTM
//var temp=url.split('?');
//temp=temp[1].split('=');
//temp=temp[1].split('&');
//temp=temp[0];
//temp=document.getElementById
//temp.className='row_3';
Kload(url, callback, null);
}
function load_page2(testo)
{
mydiv.innerHTML=testo;
}
function azzera_ordini(array)
{
load_page('index.php?pag
}
</script>
<br />
Quando si clicca questo pulsante si resettano gli ordini sottostanti.<br>
Quindi alla prossima stampa o al refresh di pagina dopo il click sull'icona non saranno piu' presenti!<br>
<span class="vmNoPrint">
<a href="javascript:void(0)&
<img src="http://www.pharmasi.
</a>
</span>
<div id="messaggio_di_ritorno&
<br />
<?php
$db = new ps_DB;
$q = "SELECT * FROM #__{vm}_orders WHERE flag_stampa='0'";
$db->query($q);
while ($db->next_record()){
$order_id =$db->f("order_id"
$id_dell_ordine[]=$db->f(&q
?>
<table width="100%" align="center"
<tr>
<td valign="top">
<h2><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<p><?php echo ps_vendor::formatted_store_add
</td>
<td valign="top" width="10%" align="right"><
</tr>
<!-- begin customer information -->
<tr class="sectiontableheader
<th align="left" colspan="2"><?
</tr>
<tr>
<td><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<td><?php printf("%08d", $db->f("order_id"
</tr>
<tr>
<td><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<td><?php echo vmFormatDate( $db->f("cdate"));
</tr>
<tr>
<td><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<td><?php echo $ps_order_status->getOrderS
</tr>
<?php
// Print the coupon code when available
if( $db->f("coupon_code&qu
<tr>
<td><strong>
<td><?php $db->p("coupon_code&qu
</tr>
<?php
}
?>
<!-- End Customer Information -->
<!-- Begin 2 column bill-ship to -->
<tr class="sectiontableheader
<th align="left" colspan="2"><?
</tr>
<tr valign="top">&nbs
<td width="50%"> <!-- Begin BillTo --><?php
// Get bill_to information
$dbbt = new ps_DB;
$q = "SELECT * FROM #__{vm}_order_user_info WHERE user_id='" . $db->f("user_id")
$dbbt->query($q);
$dbbt->next_record();
$user = $dbbt->record;
?>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td colspan="2"><s
</tr>
<?php
foreach( $registrationfields as $field ) {
if( $field->name == 'email') $field->name = 'user_email';
if($field->type == 'captcha') continue;
?>
<tr>
<td align="right"><
<td><?php
switch($field->name) {
case 'country':
require_once(CLASSPATH.'ps_cou
$country = new ps_country();
$dbc = $country->get_country_by_co
if( $dbc !== false ) echo $dbc->f('country_name');
break;
default:
echo $dbbt->f($field->name);
break;
}
?>
</td>
</tr>
<?php
}
?>
</table>
<!-- End BillTo --> </td>
<td width="50%"> <!-- Begin ShipTo --> <?php
// Get ship_to information
$dbbt->next_record();
$dbst =& $dbbt;
?>
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr>
<td colspan="2"><s
</tr>
<?php
foreach( $shippingfields as $field ) {
if( $field->name == 'email') $field->name = 'user_email';
?>
<tr>
<td width="35%" align="right">&am
<td width="65%"><?
switch($field->name) {
case 'country':
require_once(CLASSPATH.'ps_cou
$country = new ps_country();
$dbc = $country->get_country_by_co
if( $dbc !== false ) echo $dbc->f('country_name');
break;
default:
echo $dbst->f($field->name);
break;
}
?>
</td>
</tr>
<?php
}
?>
</table>
<!-- End ShipTo -->
<!-- End Customer Information -->
</td>
</tr>
<tr>
<td colspan="2">&
</tr>
<?php
if ($PSHOP_SHIPPING_MODULES[0] != "no_shipping" && $db->f("ship_method_id
$details = explode( "|", $db->f("ship_method_id
?>
<tr>
<td colspan="2"> 
<table width="100%" border="0" cellspacing="0" cellpadding="1">
<tr class="sectiontableheader
<th align="left"><
</tr>
<tr>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong>
<td><strong>
<td><strong>
</tr>
<tr>
<td><?php echo $details[1]; ?> </td&g
<td><?php echo $details[2]; ?></td>
<td><?php echo $CURRENCY_DISPLAY->getFullV
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr><?ph
}
?>
<tr>
<td colspan="2">&
</tr>
<!-- Begin Order Items Information -->
<tr class="sectiontableheader
<th align="left" colspan="2"><?
</tr>
<tr>
<td colspan="2"> 
<table width="100%" cellspacing="0" cellpadding="2" border="0">
<tr align="left">&nbs
<th><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<th><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<th><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<th><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<th align="right"><
</tr>
<?php
$dbcart = new ps_DB;
$q = "SELECT * FROM #__{vm}_order_item ";
$q .= "WHERE #__{vm}_order_item.order_id='$ord
$dbcart->query($q);&n
$subtotal = 0;
while ($dbcart->next_record()) {
?>
<tr align="left">&nbs
<td><?php $dbcart->p("product_qu
<td><?php $dbcart->p("order_item
<td><?php $dbcart->p("order_item
<td><?php /*
$price = $ps_product->get_price($dbc
$item_price = $price["product_price&quo
$item_price = $dbcart->f("product_it
echo $CURRENCY_DISPLAY->getFullV
?></td>
<td align="right"><
$subtotal += $total;
echo $CURRENCY_DISPLAY->getFullV
?> &
</tr><?php
}
?>
<tr>
<td colspan="4" align="right">&am
<td> <
</tr>
<tr>
<td colspan="4" align="right"><
<td align="right"><
</tr>
<?php
/* COUPON DISCOUNT */
$coupon_discount = $db->f("coupon_discoun
if( $coupon_discount > 0 ) {
$subtotal -= $coupon_discount;
?>
<tr>
<td colspan="4" align="right"><
</td>
<td align="right"><
echo "- ".$CURRENCY_DISPLAY->g
</td>
</tr>
<?php
}
if (($db->f("order_discou
&& (PAYMENT_DISCOUNT_BEFORE == '1')) { ?>
<tr>
<td colspan="4" align="right"><
if( $db->f("order_discount
echo $VM_LANG->_('PHPSHOP_PAYMEN
else
echo $VM_LANG->_('PHPSHOP_FEE');
?>:
</td>
<td align="right"><
if ($db->f("order_discoun
echo "- ".$CURRENCY_DISPLAY->g
elseif ($db->f("order_discoun
echo "+ ".$CURRENCY_DISPLAY->g
&
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="right"><
<td align="right"><
$shipping_total = $db->f("order_shipping
echo $CURRENCY_DISPLAY->getFullV
?>  
</tr>
<tr>
<td colspan="4" align="right"><
<td align="right"><
$tax_total = $db->f("order_tax"
echo $CURRENCY_DISPLAY->getFullV
?>  
</tr>
<tr>
<td colspan="4" align="right">
<?php if (PAYMENT_DISCOUNT_BEFORE == '1') { ?><strong><?php }
echo $VM_LANG->_('PHPSHOP_CART_T
<td align="right"><
if (PAYMENT_DISCOUNT_BEFORE == '1') { ?><strong><?php
$total = $db->f("order_total&qu
echo $CURRENCY_DISPLAY->getFullV
}
else {
//$total = $db->f("order_subtotal
$total = $db->f("order_total&qu
echo $CURRENCY_DISPLAY->getFullV
}
if (PAYMENT_DISCOUNT_BEFORE == '1') { ?></strong><?php } ?> &
</tr>
<?php
if ($db->f("order_discoun
<tr>
<td colspan="4" align="right"><
if( $db->f("order_discount
echo $VM_LANG->_('PHPSHOP_PAYMEN
else
echo $VM_LANG->_('PHPSHOP_FEE');
?>:
</td>
<td align="right"><
if ($db->f("order_discoun
echo "- ".$CURRENCY_DISPLAY->g
elseif ($db->f("order_discoun
echo "+ ".$CURRENCY_DISPLAY->g
?> &
</td>
</tr>
<tr>
<td colspan="4" align="right"><
<td align="right"><
</strong> 
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="4" align="right">&am
<td align="right"><
</strong> 
</td>
</tr>
</table>
</td>
</tr>
<!-- End Order Items Information -->
<!-- Begin Payment Information -->
<tr class="sectiontableheader
<th align="left" colspan="2"><?
</tr>
<?php
/** Retrieve Payment Info **/
$dbpm = new ps_DB;
$q = "SELECT * FROM #__{vm}_payment_method, #__{vm}_order_payment, #__{vm}_orders ";
$q .= "WHERE #__{vm}_order_payment.order_id='$
$q .= "AND #__{vm}_payment_method.payment_me
$q .= "AND #__{vm}_orders.user_id='" . $db->f("user_id")
$q .= "AND #__{vm}_orders.order_id='$order_i
$dbpm->query($q);
$dbpm->next_record();
<tr>
<td width="20%"><?
<td><?php $dbpm->p("payment_meth
</tr>
<?php
require_once(CLASSPATH.'
$ps_payment_method = new ps_payment_method;
$payment = $dbpm->f("payment_meth
if ($ps_payment_method->is_cre
// DECODE Account Number
$dbaccount = new ps_DB;
$q = 'SELECT '.VM_DECRYPT_FUNCTION.'(order_
FROM #__{vm}_order_payment WHERE order_id=\''.$order_id.'\'';
$dbaccount->query($q)
$dbaccount->next_reco
<tr>
<td width="10%"><?
<td><?php $dbpm->p("order_paymen
</tr>
<tr>
<td><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<td><?php echo ps_checkout::asterisk_pad($dba
?> </td>
</tr>
<tr>
<td><?php echo $VM_LANG->_('PHPSHOP_ORDER_
<td><?php echo vmFormatDate($dbpm->f("
</tr>
<?php } ?>
<!-- end payment information -->
<tr>
<td colspan="2"
<?php // }
/** Print out the customer note **/
if ( $db->f("customer_note&
?>
<table width="100%">
<tr>
<td colspan="2">&
</tr>
<tr class="sectiontableheader
<th align="left" colspan="2"><?
</tr>
<tr>
<td colspan="2">
<?php echo nl2br($db->f("customer
</td>
</tr>
</table>
<?php
}
?>
</td>
</tr>
</table>
<?php
}
// } /* End of security check */
if(is_array($id_dell_ordine)){
$id_per_funzione=i
}
?>
<input type="hidden" id="id_ordini" value="<?php echo $id_per_funzione ?>">
<script type="text/javascript&quo
//<!--
window.document.title="&l
//-->
</code>
l'ho nominato order.order_printdetails_nonev
In esso ci sono anche delle funzioni ajax dirette, in quanto dovevo fare in modo che al click dell'icona della stampante in automatico... si aprisse la gestione della stampante e gli ordini presenti nella pagina si flaggassero a 1 e quindi fossero stati evasi, o comunque stampati
Con questo stile:
style='page-break-after:always
E questo è il file che richiamo via ajax per gestire l'update dei flag a 1:
<code>
<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
/**
*
* @version $Id: order.order_printdetails.php 1408 2008-06-10 04:03:14Z soeren_nb $
* @package VirtueMart
* @subpackage html
* @copyright Copyright (C) 2004-2007 soeren - All rights reserved.
* @license http://www.gnu.org/copyleft/gp
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See /administrator/components/com_
*
*/
mm_showMyFileName( __FILE__ );
global $ps_order_status;
require_once(CLASSPATH.'ps_che
require_once(CLASSPATH.'ps_use
require_once(CLASSPATH.'ps_pro
if(isset($_GET['id_ordini'])) {
$ordini=explode("-",
$text_id=implode("' or order_id = '",$ordini);
$db = new ps_DB;
$q = "update #__{vm}_orders
SET flag_stampa='1'
WHERE order_id = '".$text_id."'"
$db->query($q);
echo "ordini azzerati!";
}
?>
</code>
' importante nominare questo file come order.order_printdetails_azzer
Per finire alla riga 76 del file order.order_list.php ho aggiunto il seguente codice:
<code>
<a href="javascript:void window.open('<?php $sess->purl($_SERVER['PHP_S
<img src="http://www.pharmasi.
</code>
che serve per creare un link nella lista degli ordini e poter eseguire il tutto.
Bon... ho finito
- Login o registrati per inviare commenti




