maxkart Posted December 20, 2012 Share Posted December 20, 2012 Ciao A tutti e buone feste in anticipo! Ho un problemino che chi sa solo un pò di PHP penso possa risolvere con facilità. Uso uno script che avevo trovato tempo fa in questo magnifico forum da cui posso modificare ordini già effettuati dai clienti. Da questo però non è possibile modificare il tipo di corriere scelto dal cliente. Cosi, ogni volta, vado nel DB nella tabella orders e modifico manualmente la voce id_carrier assegnando l'ID corriere da me scelto. LA mia domanda era, sempre se non esiste un metodo più semplice, se ci fosse qualche anima pia che riuscisse a compilarmi la pagina php che mi va a creare la pagina di modifica ordine. Ho già inserito il campo ID corriere, viene visualizzato correttamente, ma non sò come dire al programmino di fare l'update nel database del valore modificato. Grazie in anticipo a tutti quelli che mi sapranno aiutare! Ecco il codice: <?php //if ( $_SESSION['token'] != 'password') die('Access Denied'); require("../config/settings.inc.php"); if ($_GET['id_order']) $_POST['id_order']=$_GET['id_order']; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Prestashop Order Modify</title> <style type="text/css"> <!-- .Stile1 { font-size: large; font-weight: bold; } .Stile2 {font-size: small} --> </style> </head> <body> <form name="order" method="post" action="order_edit.php"> <label>Ordine n. <input name="id_order" type="text" value="<?php echo $_POST['id_order'] ?>" size="10" maxlength="10" /> </label> <input name="send" type="submit" value="invia" /> <br /> </form> <?php if ($_POST['id_order']) { if ($_GET['action']=='add_product') { $query=" select p.*,pl.name,t.rate as tax_rate,tl.name as tax_name from ". _DB_PREFIX_."product p join ". _DB_PREFIX_."product_lang pl on p.id_product=pl.id_product "; $query.=" left join ". _DB_PREFIX_."tax t on t.id_tax=p.id_tax"; $query.=" left join ". _DB_PREFIX_."tax_lang tl on t.id_tax=tl.id_tax"; $query.=" where p.id_product=".$_GET['id_product']. " and pl.id_lang=".$_GET['id_lang']; // echo $query."<br/>"; $res=dbquery($query); $products=mysql_fetch_array($res); if (is_null($products['tax_rate'])) $products['tax_rate']=0; $query="insert into ". _DB_PREFIX_."order_detail (id_order ,product_id ,product_name ,product_quantity ,product_quantity_in_stock ,product_price ,product_ean13 ,product_reference ,product_supplier_reference ,product_weight ,tax_name ,tax_rate ) values "; $query.="(".$_GET['id_order'].",".$products['id_product'].",'".addslashes($products['name'])."',1,1,"; $query.=$products['price'].",'".$products['ean13']."','".addslashes($products['reference'])."','".addslashes($products['supplier_reference'])."',".$products['weight'].",'".addslashes($products['tax_name'])."',".$products['tax_rate'].")"; // echo $query; dbquery($query); update_total($_GET['id_order']); } if ($_POST['order_total']) { $total=price($_POST['total_products']*(1+$_POST['tax_rate']/100) )+price($_POST['total_shipping'])+price($_POST['total_wrapping'])-price($_POST['total_discounts']); $query="update ". _DB_PREFIX_."orders set "; $query.=" total_discounts=".price($_POST['total_discounts']); $query.=" ,total_wrapping=".price($_POST['total_wrapping']); $query.=" ,total_shipping=".price($_POST['total_shipping']); $query.=" ,total_paid_real=".$total; $query.=" ,total_paid=".$total; $query.=" where id_order=".$_POST['id_order']; $query.=" limit 1"; dbquery("update ". _DB_PREFIX_."orders set id_carrier=".$_POST['id_carrier'][$id_order].", where id_order=".$id_order); dbquery($query); echo "<br/><b> MODIFICA ORDINE </b><br/>"; } if ($_POST['Apply']) { //delete product if ($_POST['product_delete']) { foreach ($_POST['product_delete'] as $id_order_detail=>$value) { dbquery("delete from ". _DB_PREFIX_."order_detail where id_order_detail=".$id_order_detail); } } if ($_POST['product_price']) { foreach ($_POST['product_price'] as $id_order_detail=>$price_product) { $qty_difference=$_POST['product_quantity_old'][$id_order_detail]-$_POST['product_quantity'][$id_order_detail]; $stock=max(0,$_POST['product_stock'][$id_order_detail]+$qty_difference); $name=addslashes(utf8_decode($_POST['product_name'][$id_order_detail])); dbquery("update ". _DB_PREFIX_."order_detail set product_price=".$price_product." where id_order_detail=".$id_order_detail); dbquery("update ". _DB_PREFIX_."order_detail set product_quantity=".$_POST['product_quantity'][$id_order_detail].", product_quantity_in_stock=".$_POST['product_quantity'][$id_order_detail]." where id_order_detail=".$id_order_detail); dbquery("update ". _DB_PREFIX_."order_detail set product_name='".$name."' where id_order_detail=".$id_order_detail); //servirebbe ad aggiornare lo stock, ma si dovrebbe vincolare ad uno stato. Attualmete lo disabilito dbquery("update ". _DB_PREFIX_."product set quantity=".$stock." where id_product=".$_POST['product_id'][$id_order_detail]); $total_products+=$_POST['product_quantity'][$id_order_detail]*price($price_product); } $total_products=$total_products*(1+$_POST['tax_rate']/100); dbquery("update ". _DB_PREFIX_."orders set total_products=".$total_products." where id_order=".$_POST['id_order']); update_total($_POST['id_order']); } } if ($_POST['id_order']) { $query="select distinct o.*,a.*,p.tax_rate from ". _DB_PREFIX_."orders o,". _DB_PREFIX_."address a,". _DB_PREFIX_."order_detail p where a.id_address=o.id_address_delivery and o.id_order=p.id_order and o.id_order=".$_POST['id_order']; $res=dbquery($query); if (mysql_num_rows($res)>0) { $order=mysql_fetch_array($res); $id_customer=$order['id_customer']; $id_lang=$order['id_lang']; $id_cart=$order['id_cart']; $payment=$order['payment']; $module=$order['module']; $tax_rate=$order['tax_rate']; $invoice_number=$order['invoice_number']; $id_carrier=$order['id_carrier']; $delivery_number=$order['delivery_number']; $total_paid_real=$order['total_paid_real']; $total_products=$order['total_products']; $total_discounts=$order['total_discounts']; $total_shipping=$order['total_shipping']; $id_carrier=$order['id_carrier']; $total_wrapping=$order['total_wrapping']; $firstname=$order['firstname']; $lastname=$order['lastname']; $company=$order['company']; } } // echo "alert('Are you sure you want to give us the deed to your house?')" ?> <p> ID cliente: <?php echo $id_customer ?><br /> Nome cliente: <?php echo utf8_encode($firstname)." ".utf8_encode($lastname). " ".utf8_encode($company) ?><br /></p> <table border="1"> <tr><td> <b>TOTALI DOCUMENTO</b> <form name="order_total" method="post" action="order_edit.php"> <label><br /> Sconto <input name="total_discounts" type="text" value="<?php echo $total_discounts ?>" /> <br /> Imballo <input name="total_wrapping" type="text" value="<?php echo $total_wrapping ?>" /> <br /> Spedizione <input name="total_shipping" type="text" value="<?php echo $total_shipping ?>" /> <br /> ID corriere <input name="id_carrier" type="text" value="<?php echo $id_carrier ?>" /> <br /> Data invio <input name="delivery_number" type="text" value="<?php echo $delivery_number ?>" /> <br /> <br /> Totale prodotti: <?php echo $total_products ?> <input name="total_products" type="hidden" value="<?php echo $total_products ?>" /> <input name="tax_rate" type="hidden" value="<?php echo $tax_rate ?>" /> <br /> Totale ordine : <?php echo $total_paid_real ?> <input name="total" type="hidden" id="total_paid_real" value="<?php echo $total_paid_real ?>" /> <input name="id_order" type="hidden" value="<?php echo $_POST['id_order'] ?>" /> <br /> <br /> </label> <label> <input type="submit" name="order_total" value="modifica" /> </label> </form> </td></tr> </table> <p align="center" class="Stile1"><a href="add_product.php?id_order=<?php echo $_POST['id_order'] ?>&id_lang=<?php echo $id_lang ?>" target="_self">AGGIUNGI PRODOTTO</a></p> <form name="products" method="post" action="order_edit.php"> <table width="100%" border="1" bgcolor="#FFCCCC"> <tr> <td>ID</td> <td>Codice articolo</td> <td>Nome articolo</td> <td>Prezzo netto</td> <td>IVA</td> <td>Prezzo lordo</td> <td>Quantita'</td> <td>Totale I.E.</td> <td>Totale I.I.</td> <td>Peso</td> <td>Cancella</td> </tr> <?php $query="select o.*,p.quantity as stock from ". _DB_PREFIX_."order_detail o left join ". _DB_PREFIX_."product p on o.product_id=p.id_product"; $query.=" where id_order=".$_POST['id_order']; $query.=" order by id_order_detail asc"; $res1=dbquery($query); if (mysql_num_rows($res1)>0) { while ($products=mysql_fetch_array($res1)) { $tax_rate=$products['tax_rate']; echo '<tr>'; echo ' <td>'.$products['product_id'].'</td>'; echo ' <td>'.utf8_encode($products['product_reference']).'</td>'; echo ' <td><input name="product_name['.$products['id_order_detail'].']" type="text" value="'.utf8_encode($products['product_name']).'" /></td>'; echo ' <td><input name="product_price['.$products['id_order_detail'].']" type="text" value="'.number_format($products['product_price'], 4, ',', '').'" /></td>'; echo ' <td>'.$products['tax_rate'].'%</td>'; echo ' <td>'.number_format($products['product_price']*(1+$products['tax_rate']/100),3, ',', '').'</td>'; echo ' <td><input name="product_quantity['.$products['id_order_detail'].']" type="text" value="'.$products['product_quantity'].'" /></td>'; echo ' <td>'.number_format($products['product_price']*$products['product_quantity'],2, ',', '').'</td>'; echo ' <td>'.number_format($products['product_price']*$products['product_quantity']*(1+$products['tax_rate']/100),2, ',', '').'</td>'; echo ' <td>'.number_format($products['product_weight'],2, ',', '').'</td>'; echo ' <td><input name="product_delete['.$products['id_order_detail'].']" type="checkbox" /></td>'; echo '</tr> '; echo ' <input name="product_quantity_old['.$products['id_order_detail'].']" type="hidden" value="'.$products['product_quantity'].'" />'; echo ' <input name="product_id['.$products['id_order_detail'].']" type="hidden" value="'.$products['product_id'].'" />'; echo ' <input name="product_stock['.$products['id_order_detail'].']" type="hidden" value="'.$products['stock'].'" />'; ?> <?php } } ?> </table> <p align="center"> <input name="Apply" type="submit" value="modifica" /> <input name="id_order" type="hidden" value="<?php echo $_POST['id_order'] ?>" /> <input name="tax_rate" type="hidden" value="<?php echo $tax_rate ?>" /> <input name="id_lang" type="hidden" value="<?php echo $id_lang ?>" /> </p> </form> <hr/> <p align="center" class="Stile2">Script realizzato da Luca Lo Bascio. Visita <a href="http://www.atomicshop.it">www.atomicshop.it</a> per comprare Hardware, Console, CD and DVDs Vergini, Monitor, TV e molto altro.<br /> <br/> <strong>Se sei interessato al DROPSHIPPING</strong>, abbiamo realizzato uno script che inserisce ed aggiorna automaticamente categorie, prodotti e marche di www.AtomicShop.it nel tuo e-commerce basato su PrestaShop, e anche per il modulo e-commerce VirtuaMart di Joomla o anche il modulo e-commerce di Wordpress. <strong><em>Tu vendi, noi spediamo!</em></strong> Il guadagno è assicurato! Attualmente le spedizioni sono effettuate solo ai clienti Italiani</p> <p align="center" class="Stile2">Per informazioni invia una e-mail a <a href="mailto:[email protected]?subject=prestashop_ordermodify">[email protected]</a></p> <hr/> <p align="center" class="Stile2">Script by Luca Lo Bascio. Visit <a href="http://www.atomicshop.it">www.atomicshop.it</a> to shop Hardware, Console, CD and DVDs Recordable, Monitor, TV and more.<br /> <br/> <strong>If you are interested at DROPSHIPPING</strong>, we created a script that inserts and updates categories, brands and products of www.AtomicShop.it in your PrestaShop e-commerce, Joomla VirtuaMart or Wordpress. <strong><em>You sell, we ship!</em></strong> The gain is assured! Acctually only for shipping in Italy</p> <p align="center" class="Stile2">For information send email to <a href="mailto:[email protected]?subject=prestashop_ordermodify">[email protected]</a></p> </body> </html> <?php } function dbquery($query) { $conn = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_) or die ("Connessione non avvenuta"); mysql_select_db(_DB_NAME_, $conn) or die ("Selezione del db non avvenuta"); $res = @mysql_query($query, $conn); //or die ("Query non eseguita"); mysql_close($conn); return $res; } function connessione() { $conn = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_) or die ("Connessione non avvenuta"); mysql_select_db(_DB_NAME_, $conn) or die ("Selezione del db non avvenuta"); } function price($price) { $price=str_replace(",",".",$price); return $price; } function update_total($id_order) { $query="select sum(product_price*product_quantity*(1+tax_rate/100)) as total_products,sum(product_price*product_quantity) as total_products_notax from ". _DB_PREFIX_."order_detail where id_order=".$id_order; $res2=dbquery($query); $products=mysql_fetch_array($res2); $query="select * from ". _DB_PREFIX_."orders where id_order=".$id_order; $res3=dbquery($query); $order=mysql_fetch_array($res3); $total=price($products['total_products'])+price($order['total_shipping'])+price($order['total_wrapping'])-price($order['total_discounts']); $query="update ". _DB_PREFIX_."orders set "; $query.=" total_discounts=".$order['total_discounts']; $query.=" ,total_wrapping=".$order['total_wrapping']; $query.=" ,total_shipping=".$order['total_shipping']; $query.=" ,id_carrier=".$order['id_carrier']; $query.=" ,total_products=".$products['total_products_notax']; $query.=" ,total_paid_real=".$total; $query.=" ,total_paid=".$total; $query.=" where id_order=".$id_order; $query.=" limit 1"; dbquery($query); } ?> Link to comment Share on other sites More sharing options...
maxkart Posted December 23, 2012 Author Share Posted December 23, 2012 Vabbè, visto che nessuno mi sa aiutare a modificare il file per modificare gli ordini, ho fatto prima, a casua delle mie scarse conoscenze di php, a crearmi una paginetta per modificare il corriere di un ordine già eseguito. A me risulta molto utile perchè in fase d'ordine, ad esempio, il cliente si trova fra gli spedizionieri, la voce generica di corriere espresso. Se seleziona quello, non potrei inviargli il link per la tracciatura, non sapendo in partenza se userò sda, brt, spedireweb o altro. Quindi, solo nel momento della spedizione, andrò a modificare il corriere generico con quello specifico a me più conveniente. Il cliente riceverà cosi il link corretto per la tracciatura e nel suo front office potrà visualizzare le info corrette. Il file va inserito nella cartella admin (sicuramente rinominata) e si apre come una normale pagina php editando il relativo indirizzo web. Io utilizzo P.S. 1.2.5 e non so se funziona anche con altre versioni. Buon Natale a tutti. corriere.php Link to comment Share on other sites More sharing options...
rancla Posted February 26, 2013 Share Posted February 26, 2013 Ciao io ho provato ad usare questo script con ps 1.5.3 però nel numero ordine vanno solo 4 caratteri. Che tu sappia che numero si mette in quella casella? grazie mille Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now