Jump to content

Modifica corriere ad ordine effettuato


maxkart

Recommended Posts

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:

 


  1. <?php

  2. //if ( $_SESSION['token'] != 'password') die('Access Denied');

  3. require("../config/settings.inc.php");

  4. if ($_GET['id_order']) $_POST['id_order']=$_GET['id_order'];

  5. ?>

  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  7. <html xmlns="http://www.w3.org/1999/xhtml">

  8. <head>

  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  10. <title>Prestashop Order Modify</title>

  11. <style type="text/css">

  12. <!--

  13. .Stile1 {

  14. font-size: large;

  15. font-weight: bold;

  16. }

  17. .Stile2 {font-size: small}

  18. -->

  19. </style>

  20. </head>

  21. <body>

  22. <form name="order" method="post" action="order_edit.php">

  23. <label>Ordine n.

  24. <input name="id_order" type="text" value="<?php echo $_POST['id_order'] ?>" size="10" maxlength="10" />

  25. </label>

  26. <input name="send" type="submit" value="invia" />

  27. <br />

  28. </form>

  29. <?php

  30. if ($_POST['id_order']) {

  31. if ($_GET['action']=='add_product') {

  32. $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 ";

  33. $query.=" left join ". _DB_PREFIX_."tax t on t.id_tax=p.id_tax";

  34. $query.=" left join ". _DB_PREFIX_."tax_lang tl on t.id_tax=tl.id_tax";

  35. $query.=" where p.id_product=".$_GET['id_product']. " and pl.id_lang=".$_GET['id_lang'];

  36. // echo $query."<br/>";

  37. $res=dbquery($query);

  38. $products=mysql_fetch_array($res);

  39. if (is_null($products['tax_rate'])) $products['tax_rate']=0;

  40. $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 ";

  41. $query.="(".$_GET['id_order'].",".$products['id_product'].",'".addslashes($products['name'])."',1,1,";

  42. $query.=$products['price'].",'".$products['ean13']."','".addslashes($products['reference'])."','".addslashes($products['supplier_reference'])."',".$products['weight'].",'".addslashes($products['tax_name'])."',".$products['tax_rate'].")";

  43. // echo $query;

  44. dbquery($query);

  45. update_total($_GET['id_order']);

  46. }

  47. if ($_POST['order_total']) {

  48. $total=price($_POST['total_products']*(1+$_POST['tax_rate']/100) )+price($_POST['total_shipping'])+price($_POST['total_wrapping'])-price($_POST['total_discounts']);

  49. $query="update ". _DB_PREFIX_."orders set ";

  50. $query.=" total_discounts=".price($_POST['total_discounts']);

  51. $query.=" ,total_wrapping=".price($_POST['total_wrapping']);

  52. $query.=" ,total_shipping=".price($_POST['total_shipping']);

  53. $query.=" ,total_paid_real=".$total;

  54. $query.=" ,total_paid=".$total;

  55. $query.=" where id_order=".$_POST['id_order'];

  56. $query.=" limit 1";

  57. dbquery("update ". _DB_PREFIX_."orders set id_carrier=".$_POST['id_carrier'][$id_order].", where id_order=".$id_order);

  58. dbquery($query);

  59. echo "<br/><b> MODIFICA ORDINE </b><br/>";

  60. }

  61. if ($_POST['Apply']) {

  62. //delete product

  63. if ($_POST['product_delete']) {

  64. foreach ($_POST['product_delete'] as $id_order_detail=>$value) {

  65. dbquery("delete from ". _DB_PREFIX_."order_detail where id_order_detail=".$id_order_detail);

  66. }

  67. }

  68. if ($_POST['product_price']) {

  69. foreach ($_POST['product_price'] as $id_order_detail=>$price_product) {

  70. $qty_difference=$_POST['product_quantity_old'][$id_order_detail]-$_POST['product_quantity'][$id_order_detail];

  71. $stock=max(0,$_POST['product_stock'][$id_order_detail]+$qty_difference);

  72. $name=addslashes(utf8_decode($_POST['product_name'][$id_order_detail]));

  73. dbquery("update ". _DB_PREFIX_."order_detail set product_price=".$price_product." where id_order_detail=".$id_order_detail);

  74. 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);

  75. dbquery("update ". _DB_PREFIX_."order_detail set product_name='".$name."' where id_order_detail=".$id_order_detail);

  76. //servirebbe ad aggiornare lo stock, ma si dovrebbe vincolare ad uno stato. Attualmete lo disabilito

  77. dbquery("update ". _DB_PREFIX_."product set quantity=".$stock." where id_product=".$_POST['product_id'][$id_order_detail]);

  78. $total_products+=$_POST['product_quantity'][$id_order_detail]*price($price_product);

  79. }

  80. $total_products=$total_products*(1+$_POST['tax_rate']/100);

  81. dbquery("update ". _DB_PREFIX_."orders set total_products=".$total_products." where id_order=".$_POST['id_order']);

  82. update_total($_POST['id_order']);

  83. }

  84. }

  85. if ($_POST['id_order']) {

  86. $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'];

  87. $res=dbquery($query);

  88. if (mysql_num_rows($res)>0) {

  89. $order=mysql_fetch_array($res);

  90. $id_customer=$order['id_customer'];

  91. $id_lang=$order['id_lang'];

  92. $id_cart=$order['id_cart'];

  93. $payment=$order['payment'];

  94. $module=$order['module'];

  95. $tax_rate=$order['tax_rate'];

  96. $invoice_number=$order['invoice_number'];

  97. $id_carrier=$order['id_carrier'];

  98. $delivery_number=$order['delivery_number'];

  99. $total_paid_real=$order['total_paid_real'];

  100. $total_products=$order['total_products'];

  101. $total_discounts=$order['total_discounts'];

  102. $total_shipping=$order['total_shipping'];

  103. $id_carrier=$order['id_carrier'];

  104. $total_wrapping=$order['total_wrapping'];

  105. $firstname=$order['firstname'];

  106. $lastname=$order['lastname'];

  107. $company=$order['company'];

  108. }

  109. }

  110. // echo "alert('Are you sure you want to give us the deed to your house?')"

  111. ?>

  112. <p> ID cliente: <?php echo $id_customer ?><br />

  113. Nome cliente: <?php echo utf8_encode($firstname)." ".utf8_encode($lastname). " ".utf8_encode($company) ?><br /></p>

  114. <table border="1">

  115. <tr><td>

  116. <b>TOTALI DOCUMENTO</b>

  117. <form name="order_total" method="post" action="order_edit.php">

  118. <label><br />

  119. Sconto       

  120. <input name="total_discounts" type="text" value="<?php echo $total_discounts ?>" />

  121. <br />

  122. Imballo      

  123. <input name="total_wrapping" type="text" value="<?php echo $total_wrapping ?>" />

  124. <br />

  125. Spedizione

  126. <input name="total_shipping" type="text" value="<?php echo $total_shipping ?>" />

  127. <br />

  128. ID corriere

  129. <input name="id_carrier" type="text" value="<?php echo $id_carrier ?>" />

  130. <br />

  131. Data invio  

  132. <input name="delivery_number" type="text" value="<?php echo $delivery_number ?>" />

  133. <br />

  134. <br />

  135. Totale prodotti: <?php echo $total_products ?>

  136. <input name="total_products" type="hidden" value="<?php echo $total_products ?>" />

  137. <input name="tax_rate" type="hidden" value="<?php echo $tax_rate ?>" />

  138. <br />

  139. Totale ordine   : <?php echo $total_paid_real ?>

  140. <input name="total" type="hidden" id="total_paid_real" value="<?php echo $total_paid_real ?>" />

  141. <input name="id_order" type="hidden" value="<?php echo $_POST['id_order'] ?>" />

  142. <br />

  143. <br />

  144. </label>

  145. <label>

  146. <input type="submit" name="order_total" value="modifica" />

  147. </label>

  148. </form>

  149. </td></tr>

  150. </table>

  151. <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>

  152. <form name="products" method="post" action="order_edit.php">

  153. <table width="100%" border="1" bgcolor="#FFCCCC">

  154. <tr>

  155. <td>ID</td>

  156. <td>Codice articolo</td>

  157. <td>Nome articolo</td>

  158. <td>Prezzo netto</td>

  159. <td>IVA</td>

  160. <td>Prezzo lordo</td>

  161. <td>Quantita'</td>

  162. <td>Totale I.E.</td>

  163. <td>Totale I.I.</td>

  164. <td>Peso</td>

  165. <td>Cancella</td>

  166. </tr>

  167. <?php

  168. $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";

  169. $query.=" where id_order=".$_POST['id_order'];

  170. $query.=" order by id_order_detail asc";

  171. $res1=dbquery($query);

  172. if (mysql_num_rows($res1)>0) {

  173. while ($products=mysql_fetch_array($res1)) {

  174. $tax_rate=$products['tax_rate'];

  175. echo '<tr>';

  176. echo ' <td>'.$products['product_id'].'</td>';

  177. echo ' <td>'.utf8_encode($products['product_reference']).'</td>';

  178. echo ' <td><input name="product_name['.$products['id_order_detail'].']" type="text" value="'.utf8_encode($products['product_name']).'" /></td>';

  179. echo ' <td><input name="product_price['.$products['id_order_detail'].']" type="text" value="'.number_format($products['product_price'], 4, ',', '').'" /></td>';

  180. echo ' <td>'.$products['tax_rate'].'%</td>';

  181. echo ' <td>'.number_format($products['product_price']*(1+$products['tax_rate']/100),3, ',', '').'</td>';

  182. echo ' <td><input name="product_quantity['.$products['id_order_detail'].']" type="text" value="'.$products['product_quantity'].'" /></td>';

  183. echo ' <td>'.number_format($products['product_price']*$products['product_quantity'],2, ',', '').'</td>';

  184. echo ' <td>'.number_format($products['product_price']*$products['product_quantity']*(1+$products['tax_rate']/100),2, ',', '').'</td>';

  185. echo ' <td>'.number_format($products['product_weight'],2, ',', '').'</td>';

  186. echo ' <td><input name="product_delete['.$products['id_order_detail'].']" type="checkbox" /></td>';

  187. echo '</tr> ';

  188. echo ' <input name="product_quantity_old['.$products['id_order_detail'].']" type="hidden" value="'.$products['product_quantity'].'" />';

  189. echo ' <input name="product_id['.$products['id_order_detail'].']" type="hidden" value="'.$products['product_id'].'" />';

  190. echo ' <input name="product_stock['.$products['id_order_detail'].']" type="hidden" value="'.$products['stock'].'" />';

  191. ?>

  192. <?php

  193. }

  194. }

  195. ?>

  196. </table>

  197. <p align="center">

  198. <input name="Apply" type="submit" value="modifica" />

  199. <input name="id_order" type="hidden" value="<?php echo $_POST['id_order'] ?>" />

  200. <input name="tax_rate" type="hidden" value="<?php echo $tax_rate ?>" />

  201. <input name="id_lang" type="hidden" value="<?php echo $id_lang ?>" />

  202. </p>

  203. </form>

  204. <hr/>

  205. <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 />

  206. <br/>

  207. <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.

  208. <strong><em>Tu vendi, noi spediamo!</em></strong> Il guadagno è assicurato! Attualmente le spedizioni sono effettuate solo ai clienti Italiani</p>

  209. <p align="center" class="Stile2">Per informazioni invia una e-mail a <a href="mailto:[email protected]?subject=prestashop_ordermodify">[email protected]</a></p>

  210. <hr/>

  211. <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 />

  212. <br/>

  213. <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.

  214. <strong><em>You sell, we ship!</em></strong> The gain is assured! Acctually only for shipping in Italy</p>

  215. <p align="center" class="Stile2">For information send email to <a href="mailto:[email protected]?subject=prestashop_ordermodify">[email protected]</a></p>

  216. </body>

  217. </html>

  218. <?php

  219. }

  220. function dbquery($query) {

  221. $conn = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_) or die ("Connessione non avvenuta");

  222. mysql_select_db(_DB_NAME_, $conn) or die ("Selezione del db non avvenuta");

  223. $res = @mysql_query($query, $conn); //or die ("Query non eseguita");

  224. mysql_close($conn);

  225. return $res;

  226. }

  227. function connessione() {

  228. $conn = mysql_connect(_DB_SERVER_, _DB_USER_, _DB_PASSWD_) or die ("Connessione non avvenuta");

  229. mysql_select_db(_DB_NAME_, $conn) or die ("Selezione del db non avvenuta");

  230. }

  231. function price($price) {

  232. $price=str_replace(",",".",$price);

  233. return $price;

  234. }

  235. function update_total($id_order) {

  236. $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;

  237. $res2=dbquery($query);

  238. $products=mysql_fetch_array($res2);

  239. $query="select * from ". _DB_PREFIX_."orders where id_order=".$id_order;

  240. $res3=dbquery($query);

  241. $order=mysql_fetch_array($res3);

  242. $total=price($products['total_products'])+price($order['total_shipping'])+price($order['total_wrapping'])-price($order['total_discounts']);

  243. $query="update ". _DB_PREFIX_."orders set ";

  244. $query.=" total_discounts=".$order['total_discounts'];

  245. $query.=" ,total_wrapping=".$order['total_wrapping'];

  246. $query.=" ,total_shipping=".$order['total_shipping'];

  247. $query.=" ,id_carrier=".$order['id_carrier'];

  248. $query.=" ,total_products=".$products['total_products_notax'];

  249. $query.=" ,total_paid_real=".$total;

  250. $query.=" ,total_paid=".$total;

  251. $query.=" where id_order=".$id_order;

  252. $query.=" limit 1";

  253. dbquery($query);

  254. }

  255. ?>

Link to comment
Share on other sites

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

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...