PageRenderTime 53ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_virtuemart/classes/ps_order_edit.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 1440 lines | 1049 code | 168 blank | 223 comment | 121 complexity | 1100881ceb22cb37b999197b7f500d23 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
  3. /**
  4. *
  5. * @version $Id: ps_order_edit.php 1132 2008-01-08 14:50:07Z soeren_nb $
  6. * @author nfischer
  7. * @copyright Copyright (C) 2006 Ingemar F�llman. All rights reserved.
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9. *
  10. */
  11. /****************************************************************************
  12. *
  13. * CLASS DESCRIPTION
  14. *
  15. * ps_order_edit
  16. *
  17. * The class acts as a plugin for the order_print page.
  18. # It adds a new tab for order edit handling.
  19. *
  20. *************************************************************************/
  21. class ps_order_edit {
  22. var $classname = "ps_order_edit";
  23. var $error;
  24. var $order_id;
  25. var $reload_from_db;
  26. var $product_added = false;
  27. /**************************************************************************
  28. * name: ps_order_edit (constructor)
  29. * created by: ingemar
  30. * description: constructor, setup initial variables
  31. * parameters: Order Id
  32. * returns:
  33. **************************************************************************/
  34. function ps_order_edit($order_id) {
  35. $this->order_id = $order_id;
  36. }
  37. /**************************************************************************
  38. * name: pane_content
  39. * created by: ingemar
  40. * description: Show pane content
  41. * parameters: Tab Object
  42. * returns:
  43. **************************************************************************/
  44. function pane_content($tab) {
  45. global $VM_LANG;
  46. if( vmGet( $_REQUEST, 'order_edit_page' ) == '1') {
  47. ?>
  48. <script type="text/javascript">
  49. var current = document.getElementById( "order_edit_page" );
  50. current.tabPage.select();
  51. </script>
  52. <?php
  53. }
  54. if( vmGet( $_REQUEST, 'delete_product' ) != '' )
  55. $this->delete_product();
  56. elseif( vmGet( $_REQUEST, 'add_product') != '' )
  57. $this->add_product();
  58. elseif( vmGet( $_REQUEST, 'update_quantity' ) != '' )
  59. $this->update_quantity();
  60. elseif( vmGet( $_REQUEST, 'update_coupon_discount' ) != '' )
  61. $this->update_coupon_discount();
  62. elseif( vmGet( $_REQUEST, 'update_discount' ) != '' )
  63. $this->update_discount();
  64. elseif( vmGet( $_REQUEST, 'update_standard_shipping' ) != '' )
  65. $this->update_standard_shipping();
  66. elseif( vmGet( $_REQUEST, 'update_shipping' ) != '' )
  67. $this->update_shipping();
  68. elseif( vmGet( $_REQUEST, 'update_bill_to' ) != '' )
  69. $this->update_bill_to();
  70. elseif( vmGet( $_REQUEST, 'update_ship_to' ) != '' )
  71. $this->update_ship_to();
  72. elseif( vmGet( $_REQUEST, 'update_shipping_tax' ) != '' )
  73. ?>
  74. <form method="post" name="editForm" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  75. <table class="adminlist">
  76. <tr>
  77. <th><?php echo($VM_LANG->_('VM_ORDER_EDIT_EDIT_ORDER')); ?></th>
  78. </tr>
  79. </table>
  80. <table class="adminlist">
  81. <tr>
  82. <th><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_SKU') ?></th>
  83. <th><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_NAME') ?></th>
  84. <th width="5%" align="left"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_QUANTITY') ?></th>
  85. <th width="5%" align="left" colspan="2"><?php echo $VM_LANG->_('VM_ORDER_EDIT_ACTIONS') ?></th>
  86. </tr>
  87. <?php
  88. $dbt = new ps_DB;
  89. $db = new ps_DB;
  90. $qt = "SELECT order_item_id, product_quantity,order_item_name,order_item_sku FROM `#__{vm}_order_item`".
  91. "WHERE #__{vm}_order_item.order_id='".$this->order_id."' ";
  92. $q = "SELECT * FROM #__{vm}_orders WHERE order_id='".$this->order_id."'";
  93. $dbt->query($qt);
  94. $db->query($q);
  95. $db->next_record();
  96. $i = 0;
  97. $rate_details = explode( "|", $db->f("ship_method_id") );
  98. while ($dbt->next_record()){
  99. if ($i++ % 2) {
  100. $bgcolor='row0';
  101. } else {
  102. $bgcolor='row1';
  103. }
  104. ?>
  105. <tr class="<?php echo $bgcolor; ?>" valign="top">
  106. <td><?php $dbt->p("order_item_sku") ?>&nbsp;</td>
  107. <td><?php $dbt->p("order_item_name") ?></td>
  108. <td>
  109. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  110. <input type="text" value="<?php $dbt->p("product_quantity") ?>" name="product_quantity" size="5" />
  111. </td>
  112. <td align="left">
  113. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  114. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  115. <input type="hidden" value="1" name="update_quantity" />
  116. <input type="hidden" name="order_edit_page" value="1" />
  117. <input type="hidden" name="page" value="order.order_print" />
  118. <input type="hidden" name="option" value="com_virtuemart" />
  119. <input type="hidden" name="func" value="" />
  120. <input type="hidden" name="order_item_id" value="<?php $dbt->p("order_item_id") ?>" />
  121. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  122. </form>
  123. </td>
  124. <td>
  125. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  126. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_DELETE') ?>" src="<?php echo IMAGEURL ?>ps_image/delete_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_DELETE') ?>" />
  127. <input type="hidden" value="1" name="delete_product" />
  128. <input type="hidden" name="order_edit_page" value="1" />
  129. <input type="hidden" name="page" value="order.order_print" />
  130. <input type="hidden" name="option" value="com_virtuemart" />
  131. <input type="hidden" name="func" value="" />
  132. <input type="hidden" name="order_item_id" value="<?php $dbt->p("order_item_id") ?>" />
  133. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  134. </form>
  135. </td>
  136. </tr>
  137. <?php
  138. }
  139. ?>
  140. </table>
  141. <table class="adminlist">
  142. <tr>
  143. <th><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_SHIPPING') . " &amp; " . $VM_LANG->_('PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT') ?></th>
  144. <th width="5%" align="left"> &nbsp; </th>
  145. <th width="5%" align="left" colspan="1"><?php echo $VM_LANG->_('VM_ORDER_EDIT_ACTIONS') ?></th>
  146. </tr>
  147. <?php
  148. if($db->f('ship_method_id') == "" OR preg_match('/^standard_shipping/', $db->f('ship_method_id'))) {
  149. ?>
  150. <tr>
  151. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_SHIPPING') ?>: &nbsp;</strong></td>
  152. <td>
  153. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  154. <?php
  155. $dbs = new ps_DB;
  156. $q = 'SELECT shipping_rate_id, shipping_rate_name, shipping_rate_weight_start, shipping_rate_weight_end, shipping_rate_value, shipping_rate_package_fee, tax_rate, currency_name
  157. FROM #__{vm}_shipping_rate, #__{vm}_currency, #__{vm}_tax_rate
  158. WHERE currency_id = shipping_rate_currency_id
  159. AND ( tax_rate_id = shipping_rate_vat_id OR shipping_rate_vat_id = 0 )
  160. ORDER BY shipping_rate_list_order';
  161. $dbs->query($q);
  162. while ($dbs->next_record()){
  163. $rates[$dbs->f('shipping_rate_id')] = $dbs->f('shipping_rate_name')
  164. ."; (".$dbs->f('shipping_rate_weight_start')." - ".$dbs->f('shipping_rate_weight_end')."); "
  165. . " ".(($dbs->f('shipping_rate_value') * (1+$dbs->f('tax_rate'))) + $dbs->f('shipping_rate_package_fee'))
  166. . " ".$dbs->f('currency_name');
  167. }
  168. ps_html::dropdown_display( 'shipping', $rate_details[4], $rates );
  169. ?>
  170. </select>
  171. </td>
  172. <td>
  173. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  174. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  175. <input type="hidden" value="1" name="update_standard_shipping" />
  176. <input type="hidden" name="order_edit_page" value="1" />
  177. <input type="hidden" name="page" value="order.order_print" />
  178. <input type="hidden" name="option" value="com_virtuemart" />
  179. <input type="hidden" name="func" value="" />
  180. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  181. </form>
  182. </td>
  183. </tr>
  184. <?php
  185. } else {
  186. ?>
  187. <tr>
  188. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_SHIPPING') ?>: </strong></td>
  189. <td>
  190. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  191. <input type="text" value="<?php $db->p("order_shipping") ?>" size="5" name="order_shipping" />
  192. </td>
  193. <td>
  194. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  195. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  196. <input type="hidden" value="1" name="update_shipping" />
  197. <input type="hidden" name="order_edit_page" value="1" />
  198. <input type="hidden" name="page" value="order.order_print" />
  199. <input type="hidden" name="option" value="com_virtuemart" />
  200. <input type="hidden" name="func" value="" />
  201. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  202. </form>
  203. </td>
  204. </tr>
  205. <tr>
  206. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_SHIPPING_TAX') ?>: </strong></td>
  207. <td>
  208. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  209. <input type="text" value="<?php $db->p("order_shipping_tax") ?>" name="order_shipping_tax" size="5" />
  210. </td>
  211. <td>
  212. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  213. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  214. <input type="hidden" value="1" name="update_shipping_tax" />
  215. <input type="hidden" name="order_edit_page" value="1" />
  216. <input type="hidden" name="page" value="order.order_print" />
  217. <input type="hidden" name="option" value="com_virtuemart" />
  218. <input type="hidden" name="func" value="" />
  219. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  220. </form>
  221. </td>
  222. </tr>
  223. <?php
  224. }
  225. ?>
  226. <tr>
  227. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_COUPON_DISCOUNT') ?>: </strong></td>
  228. <td>
  229. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  230. <input type="text" value="<?php $db->p("coupon_discount") ?>" size="5" name="coupon_discount" />
  231. </td>
  232. <td>
  233. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  234. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  235. <input type="hidden" value="1" name="update_coupon_discount" />
  236. <input type="hidden" name="order_edit_page" value="1" />
  237. <input type="hidden" name="page" value="order.order_print" />
  238. <input type="hidden" name="option" value="com_virtuemart" />
  239. <input type="hidden" name="func" value="" />
  240. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  241. </form>
  242. </td>
  243. </tr>
  244. <tr>
  245. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_PAYMENT_METHOD_LIST_DISCOUNT') ?>: </strong></td>
  246. <td>
  247. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  248. <input type="text" value="<?php $db->p("order_discount") ?>" size="5" name="order_discount" />
  249. </td>
  250. <td>
  251. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  252. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  253. <input type="hidden" value="1" name="update_discount" />
  254. <input type="hidden" name="order_edit_page" value="1" />
  255. <input type="hidden" name="page" value="order.order_print" />
  256. <input type="hidden" name="option" value="com_virtuemart" />
  257. <input type="hidden" name="func" value="" />
  258. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  259. </form>
  260. </td>
  261. </tr>
  262. </table>
  263. <table class="adminlist">
  264. <tr>
  265. <th><?php echo $VM_LANG->_('PHPSHOP_USER_FORM_BILLTO_LBL') . " & " . $VM_LANG->_('PHPSHOP_USER_FORM_SHIPTO_LBL') ?></th>
  266. <th width="5%" align="left"> &nbsp; </th>
  267. <th width="5%" align="left" colspan="1"><?php echo $VM_LANG->_('VM_ORDER_EDIT_ACTIONS') ?></th>
  268. </tr>
  269. <tr>
  270. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_BILL_TO_LBL') ?>: </strong></td>
  271. <td align="right">
  272. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  273. <select name="bill_to">
  274. <?php
  275. $dbs = new ps_DB;
  276. $q = "SELECT user_id, last_name, first_name FROM #__{vm}_user_info WHERE address_type = 'BT' ORDER BY last_name ASC";
  277. $dbs->query($q);
  278. while ($dbs->next_record()){
  279. if (!is_null( $dbs->f('last_name') )) {
  280. print '<option value="'.$dbs->f('user_id').'"';
  281. if($dbs->f('user_id') == $db->f("user_id")) print " selected ";
  282. print '>';
  283. print $dbs->f('last_name');
  284. print ", ".$dbs->f('first_name');
  285. print '</option>';
  286. }
  287. }
  288. ?>
  289. </select>
  290. </td>
  291. <td>
  292. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  293. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  294. <input type="hidden" value="1" name="update_bill_to" />
  295. <input type="hidden" name="order_edit_page" value="1" />
  296. <input type="hidden" name="page" value="order.order_print" />
  297. <input type="hidden" name="option" value="com_virtuemart" />
  298. <input type="hidden" name="func" value="" />
  299. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  300. </form>
  301. </td>
  302. </tr>
  303. <?php /* Change ship to form */ ?>
  304. <tr>
  305. <td align="right"><strong><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_SHIP_TO_LBL') ?>: </strong></td>
  306. <td align="right">
  307. <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  308. <select name="ship_to">
  309. <?php
  310. $dbs = new ps_DB;
  311. $q = "SELECT user_info_id, address_type_name FROM #__{vm}_user_info WHERE user_id = '" . $db->f("user_id") . "' ORDER BY address_type_name ASC";
  312. $dbs->query($q);
  313. while ($dbs->next_record()){
  314. if (!is_null( $dbs->f('user_info_id') )) {
  315. print '<option value="'.$dbs->f('user_info_id').'">';
  316. print $dbs->f('address_type_name');
  317. print '</option>';
  318. }
  319. }
  320. ?>
  321. </select>
  322. </td>
  323. <td>
  324. <input type="image" title="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>"
  325. src="<?php echo VM_THEMEURL ?>images/edit_f2.gif" border="0" alt="<?php echo $VM_LANG->_('PHPSHOP_UPDATE') ?>" />
  326. <input type="hidden" value="1" name="update_ship_to" />
  327. <input type="hidden" name="order_edit_page" value="1" />
  328. <input type="hidden" name="page" value="order.order_print" />
  329. <input type="hidden" name="option" value="com_virtuemart" />
  330. <input type="hidden" name="func" value="" />
  331. <input type="hidden" name="order_id" value="<?php echo $this->order_id ?>" />
  332. </form>
  333. </td>
  334. </tr>
  335. </table>
  336. <?php $this->display_form_add_product(); ?>
  337. <?php
  338. }
  339. /**************************************************************************
  340. * name: update_ship_to
  341. * created by: Kaltokri
  342. * description: Change ship to
  343. * parameters:
  344. * returns:
  345. **************************************************************************/
  346. function update_ship_to() {
  347. $ship_to = trim(vmGet( $_REQUEST, 'ship_to' ));
  348. $db = new ps_DB;
  349. // Delete ship to
  350. $q = "DELETE FROM #__{vm}_order_user_info ";
  351. $q .= "WHERE order_id = '" . $this->order_id . "' AND address_type = 'ST'";
  352. $db->query($q);
  353. $db->next_record();
  354. $q = "SELECT * FROM #__{vm}_user_info ";
  355. $q .= "WHERE user_info_id = '" . $ship_to . "'";
  356. $db->query($q);
  357. $db->next_record();
  358. if($db->f('address_type') == 'ST') {
  359. // Ship to Address if applicable (copied from ps_checkout.php and changed)
  360. $q = "INSERT INTO `#__{vm}_order_user_info` ";
  361. $q .= "SELECT '', '$this->order_id', '".$db->f('user_id')."', address_type, address_type_name, company, title, last_name, first_name, middle_name, phone_1, phone_2, fax, address_1, address_2, city, state, country, zip, user_email, extra_field_1, extra_field_2, extra_field_3, extra_field_4, extra_field_5,bank_account_nr,bank_name,bank_sort_code,bank_iban,bank_account_holder,bank_account_type FROM #__{vm}_user_info WHERE user_id='".$db->f('user_id')."' AND user_info_id='".$ship_to."' AND address_type='ST'";
  362. $db->query($q);
  363. $db->next_record();
  364. }
  365. $this->reload_from_db = 1;
  366. }
  367. /**************************************************************************
  368. * name: update_bill_to
  369. * created by: Kaltokri
  370. * description: Change bill to
  371. * parameters:
  372. * returns:
  373. **************************************************************************/
  374. function update_bill_to() {
  375. $db = new ps_DB;
  376. $db2 = new ps_DB;
  377. $bill_to = trim(vmGet( $_REQUEST, 'bill_to' ));
  378. $q = "SELECT * FROM #__{vm}_user_info WHERE user_id = '" . $bill_to . "'";
  379. $db->query($q);
  380. if(!$db->next_record()) {
  381. print "<h1>Invalid user id: $bill_to</h1>";
  382. return;
  383. }
  384. // Update order
  385. $q = "UPDATE #__{vm}_orders ";
  386. $q .= "SET user_id = '" .$bill_to."',";
  387. $q .= " user_info_id = '" .$db->f('user_info_id')."'";
  388. $q .= " WHERE order_id = '" . $this->order_id . "'";
  389. $db2->query($q);
  390. $db2->next_record();
  391. // Update order_user_info
  392. $q = "UPDATE #__{vm}_order_user_info ";
  393. $q .= "SET user_id = '" .$db->f('user_id')."', ";
  394. $q .= "address_type_name = '" .$db->f('address_type_name')."', ";
  395. $q .= "company = '" .$db->f('company')."', ";
  396. $q .= "title = '" .$db->f('title')."', ";
  397. $q .= "last_name = '" .$db->f('last_name')."', ";
  398. $q .= "first_name = '" .$db->f('first_name')."', ";
  399. $q .= "middle_name = '" .$db->f('middle_name')."', ";
  400. $q .= "phone_1 = '" .$db->f('phone_1')."', ";
  401. $q .= "phone_2 = '" .$db->f('phone_2')."', ";
  402. $q .= "fax = '" .$db->f('fax')."', ";
  403. $q .= "address_1 = '" .$db->f('address_1')."', ";
  404. $q .= "address_2 = '" .$db->f('address_2')."', ";
  405. $q .= "city = '" .$db->f('city')."', ";
  406. $q .= "state = '" .$db->f('state')."', ";
  407. $q .= "country = '" .$db->f('country')."', ";
  408. $q .= "zip = '" .$db->f('zip')."', ";
  409. $q .= "user_email = '" .$db->f('user_email')."', ";
  410. $q .= "extra_field_1 = '" .$db->f('extra_field_1')."', ";
  411. $q .= "extra_field_2 = '" .$db->f('extra_field_2')."', ";
  412. $q .= "extra_field_3 = '" .$db->f('extra_field_3')."', ";
  413. $q .= "extra_field_4 = '" .$db->f('extra_field_4')."', ";
  414. $q .= "extra_field_5 = '" .$db->f('extra_field_5')."', ";
  415. $q .= "bank_account_nr = '" .$db->f('bank_account_nr')."', ";
  416. $q .= "bank_name = '" .$db->f('bank_name')."', ";
  417. $q .= "bank_sort_code = '" .$db->f('bank_sort_code')."', ";
  418. $q .= "bank_iban = '" .$db->f('bank_iban')."', ";
  419. $q .= "bank_account_holder = '" .$db->f('bank_account_holder')."', ";
  420. $q .= "bank_account_type = '" .$db->f('bank_account_type')."' ";
  421. $q .= " WHERE order_id = '" . $this->order_id . "' AND address_type = 'BT'";
  422. $db2->query($q);
  423. $db2->next_record();
  424. // Delete ship to
  425. $q = "DELETE FROM #__{vm}_order_user_info ";
  426. $q .= "WHERE order_id = '" . $this->order_id . "' AND address_type = 'ST'";
  427. $db2->query($q);
  428. $db2->next_record();
  429. $this->reload_from_db = 1;
  430. }
  431. /**************************************************************************
  432. * name: update_shipping
  433. * created by: ingemar
  434. * description: Change order shipping rate
  435. * parameters:
  436. * returns:
  437. **************************************************************************/
  438. function update_shipping() {
  439. $db = new ps_DB;
  440. $shipping = trim(vmGet( $_REQUEST, 'order_shipping' ));
  441. if(!is_numeric($shipping)) {
  442. $shipping = 0;
  443. }
  444. // Update order
  445. $q = "UPDATE #__{vm}_orders ";
  446. $q .= "SET order_total = order_total - order_shipping +".$shipping.", ";
  447. $q .= "order_shipping = ".$shipping;
  448. $q .= " WHERE order_id = '" . $this->order_id . "'";
  449. $db->query($q);
  450. $db->next_record();
  451. $this->reload_from_db = 1;
  452. }
  453. /**************************************************************************
  454. * name: update_shipping_tax
  455. * created by: ingemar
  456. * description: Change order shipping tax
  457. * parameters:
  458. * returns:
  459. **************************************************************************/
  460. function update_shipping_tax() {
  461. $db = new ps_DB;
  462. $shipping_tax = trim(vmGet( $_REQUEST, 'order_shipping_tax' ));
  463. if(!is_numeric($shipping_tax)) {
  464. $shipping_tax = 0;
  465. }
  466. // Update orde
  467. $q = "UPDATE #__{vm}_orders ";
  468. $q .= "SET order_total = order_total - order_shipping_tax +".$shipping_tax.", ";
  469. $q .= "order_shipping_tax = ".$shipping_tax;
  470. $q .= " WHERE order_id = '" . $this->order_id . "'";
  471. $db->query($q);
  472. $db->next_record();
  473. $this->reload_from_db = 1;
  474. }
  475. /**************************************************************************
  476. * name: update_standard_shipping
  477. * created by: ingemar
  478. * description: Change order shipping rate
  479. * parameters:
  480. * returns:
  481. **************************************************************************/
  482. function update_standard_shipping() {
  483. $db = new ps_DB;
  484. $shipping = trim(vmGet( $_REQUEST, 'shipping' ));
  485. $q = "SELECT shipping_rate_name, shipping_carrier_name, shipping_rate_value, ((tax_rate + 1) *shipping_rate_value) AS shipping_total FROM #__{vm}_shipping_rate, #__{vm}_tax_rate, #__{vm}_shipping_carrier WHERE shipping_carrier_id = shipping_rate_carrier_id AND tax_rate_id = shipping_rate_vat_id and shipping_rate_id = '".addslashes($shipping)."'";
  486. $db->query($q);
  487. if(!$db->next_record()) {
  488. print "<h1>Invalid shipping id: $shipping</h1>";
  489. return;
  490. }
  491. $shipping_carrier = $db->f('shipping_carrier_name');
  492. $shipping_name = $db->f('shipping_rate_name');
  493. $shipping_rate = $db->f('shipping_rate_value');
  494. $shipping_tax = $db->f('shipping_total') - $db->f('shipping_rate_value');
  495. $shipping_total = $db->f('shipping_total');
  496. $shipping_method = "standard_shipping|$shipping_carrier|$shipping_name|".round($shipping_total,2)."|$shipping";
  497. // Update order
  498. $q = "UPDATE #__{vm}_orders ";
  499. $q .= "SET order_total = order_total - order_shipping - order_shipping_tax + ".$shipping_rate." + ".$shipping_tax.", ";
  500. $q .= "order_shipping = ".$shipping_rate.", ";
  501. $q .= "order_shipping_tax = ".$shipping_tax.", ";
  502. $q .= "ship_method_id = '".addslashes($shipping_method)."'";
  503. $q .= " WHERE order_id = '" . $this->order_id . "'";
  504. $db->query($q);
  505. $db->next_record();
  506. $this->reload_from_db = 1;
  507. }
  508. /**************************************************************************
  509. * name: update_coupon_discount
  510. * created by: ingemar
  511. * description: Change order coupon discount
  512. * parameters:
  513. * returns:
  514. **************************************************************************/
  515. function update_coupon_discount() {
  516. $db = new ps_DB;
  517. $discount = trim(vmGet( $_REQUEST, 'coupon_discount' ));
  518. if(!is_numeric($discount)) {
  519. print "<h1>Invalid discount: $discount</h1>";
  520. return;
  521. }
  522. $q = "SELECT SUM(product_quantity*product_final_price) - SUM(product_quantity*product_item_price) AS item_tax, ".
  523. $q .= "SUM(product_quantity*product_final_price) as final_price ";
  524. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "'";
  525. $db->query($q);
  526. $db->next_record();
  527. // Update order
  528. $q = "UPDATE #__{vm}_orders ";
  529. $q .= "SET order_tax = (order_total - order_shipping - order_shipping_tax + coupon_discount - ".$discount." ) * (".$db->f('item_tax')." / ".$db->f('final_price')." ), ";
  530. $q .= "order_total = order_total + coupon_discount - ".$discount.", ";
  531. $q .= "coupon_discount = '".$discount."' ";
  532. $q .= "WHERE order_id = '" . $this->order_id . "'";
  533. $db->query($q);
  534. $db->next_record();
  535. $this->reload_from_db = 1;
  536. }
  537. /**************************************************************************
  538. * name: update_discount
  539. * created by: ingemar
  540. * description: Change order discount
  541. * parameters:
  542. * returns:
  543. **************************************************************************/
  544. function update_discount() {
  545. $db = new ps_DB;
  546. $discount = trim(vmGet( $_REQUEST, 'order_discount' ));
  547. if(!is_numeric($discount)) {
  548. print "<h1>Invalid discount: $discount</h1>";
  549. return;
  550. }
  551. $q = "SELECT
  552. SUM(product_quantity*product_final_price) - SUM(product_quantity*product_item_price) AS item_tax,
  553. SUM(product_quantity*product_final_price) as final_price
  554. FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "'";
  555. $db->query($q);
  556. $db->next_record();
  557. // Update order
  558. $q = "UPDATE #__{vm}_orders ";
  559. $q .= "SET order_tax = (order_total - order_shipping - order_shipping_tax + order_discount - ".$discount." ) * (".$db->f('item_tax')." / ".$db->f('final_price')." ), ";
  560. $q .= "order_total = order_total + order_discount - ".$discount.", ";
  561. $q .= "order_discount = '".$discount."' ";
  562. $q .= "WHERE order_id = '" . $this->order_id . "'";
  563. $db->query($q);
  564. $db->next_record();
  565. $this->reload_from_db = 1;
  566. }
  567. /**************************************************************************
  568. * name: delete_product
  569. * created by: nfischer
  570. * description: Delete an item
  571. * parameters:
  572. * returns:
  573. **************************************************************************/
  574. function delete_product() {
  575. global $VM_LANG, $vmLogger;
  576. $order_item_id = vmGet( $_REQUEST, 'order_item_id' );
  577. $quantity = trim(vmGet( $_REQUEST, 'product_quantity' ));
  578. $db = new ps_DB;
  579. $q = "SELECT product_id, product_quantity, product_final_price, product_item_price, product_final_price - product_item_price AS item_tax ";
  580. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' ";
  581. $q .= "AND order_item_id = '".addslashes($order_item_id)."'";
  582. $db->query($q);
  583. $db->next_record();
  584. $product_id = $db->f('product_id');
  585. $diff = $quantity - $db->f('product_quantity');
  586. $net_price_change = $diff * $db->f('product_item_price');
  587. $tax_change = $diff * $db->f('item_tax');
  588. $price_change = $diff * $db->f('product_final_price');
  589. $timestamp = time() + ($mosConfig_offset*60*60);
  590. // Update order
  591. $q = "UPDATE #__{vm}_orders ";
  592. $q .= "SET order_tax = (order_tax + ".$tax_change." ), ";
  593. $q .= "order_total = (order_total + ".$price_change." ), ";
  594. $q .= "order_subtotal = (order_subtotal + ".$net_price_change.") ";
  595. $q .= "WHERE order_id = '" . $this->order_id . "'";
  596. $db->query($q);
  597. $db->next_record();
  598. $this->reload_from_db = 1;
  599. // On supprime le produit de la commande
  600. $q = "DELETE FROM #__{vm}_order_item ";
  601. $q .= "WHERE order_item_id = '".addslashes($order_item_id)."'";
  602. $db->query($q);
  603. $db->next_record();
  604. /* Update Stock Level and Product Sales */
  605. $q = "UPDATE #__{vm}_product ";
  606. $q .= "SET product_in_stock = product_in_stock - ".$diff;
  607. $q .= " WHERE product_id = '" . $product_id . "'";
  608. $db->query($q);
  609. $db->next_record();
  610. $q = "UPDATE #__{vm}_product ";
  611. $q .= "SET product_sales= product_sales + " .$diff;
  612. $q .= " WHERE product_id='". $product_id ."'";
  613. $db->query($q);
  614. $db->next_record();
  615. $vmLogger->info( $VM_LANG->_('VM_ORDER_EDIT_PRODUCT_DELETED',false) );
  616. }
  617. /**************************************************************************
  618. * name: update_quantity
  619. * created by: ingemar
  620. * description: Change order_item quantity
  621. * parameters:
  622. * returns:
  623. **************************************************************************/
  624. function update_quantity() {
  625. global $VM_LANG, $vmLogger, $mosConfig_offset;
  626. $order_item_id = vmGet( $_REQUEST, 'order_item_id' );
  627. $quantity = trim(vmGet( $_REQUEST, 'product_quantity' ));
  628. if(!is_numeric($quantity) || $quantity < 1) {
  629. $vmLogger->err( $VM_LANG->_('VM_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0',false) );
  630. return;
  631. }
  632. $db = new ps_DB;
  633. $q = "SELECT product_id, product_quantity, product_final_price, product_item_price, product_final_price - product_item_price AS item_tax ";
  634. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' ";
  635. $q .= "AND order_item_id = '".addslashes($order_item_id)."'";
  636. $db->query($q);
  637. $db->next_record();
  638. $product_id = $db->f('product_id');
  639. $diff = $quantity - $db->f('product_quantity');
  640. $net_price_change = $diff * $db->f('product_item_price');
  641. $tax_change = $diff * $db->f('item_tax');
  642. $price_change = $diff * $db->f('product_final_price');
  643. $timestamp = time() + ($mosConfig_offset*60*60);
  644. // Update order
  645. $q = "UPDATE #__{vm}_orders ";
  646. $q .= "SET order_tax = (order_tax + ".$tax_change." ), ";
  647. $q .= "order_total = (order_total + ".$price_change." ), ";
  648. $q .= "order_subtotal = (order_subtotal + ".$net_price_change.") ";
  649. $q .= "WHERE order_id = '" . $this->order_id . "'";
  650. $db->query($q);
  651. $db->next_record();
  652. $this->reload_from_db = 1;
  653. $q = "UPDATE #__{vm}_order_item ";
  654. $q .= "SET product_quantity = ".$quantity.", ";
  655. $q .= "mdate = ".$timestamp." ";
  656. $q .= "WHERE order_item_id = '".addslashes($order_item_id)."'";
  657. $db->query($q);
  658. $db->next_record();
  659. /* Update Stock Level and Product Sales */
  660. $q = "UPDATE #__{vm}_product ";
  661. $q .= "SET product_in_stock = product_in_stock - ".$diff;
  662. $q .= " WHERE product_id = '" . $product_id . "'";
  663. $db->query($q);
  664. $db->next_record();
  665. $q = "UPDATE #__{vm}_product ";
  666. $q .= "SET product_sales= product_sales + " .$diff;
  667. $q .= " WHERE product_id='". $product_id ."'";
  668. $db->query($q);
  669. $db->next_record();
  670. $vmLogger->info( $VM_LANG->_('VM_ORDER_EDIT_QUANTITY_UPDATED',false) );
  671. }
  672. /**************************************************************************
  673. * name: add_product
  674. * created by: nfischer
  675. * description: Add a new product to an existing order
  676. * parameters:
  677. * returns:
  678. **************************************************************************/
  679. function add_product() {
  680. global $VM_LANG, $vmLogger, $mosConfig_offset;
  681. require_once(CLASSPATH . 'ps_product_attribute.php');
  682. require_once(CLASSPATH . 'ps_product.php');
  683. $ps_product_attribute = new ps_product_attribute;
  684. $ps_product = new ps_product;
  685. $product_id = vmGet( $_REQUEST, 'product_id' );
  686. $order_item_id = vmGet( $_REQUEST, 'order_item_id' );
  687. $add_product_validate = vmGet( $_REQUEST, 'add_product_validate' );
  688. $d = $_REQUEST;
  689. // On peux ins�rer le produit � la commande
  690. if ($add_product_validate == 1) {
  691. $quantity = trim(vmGet( $_REQUEST, 'product_quantity' ));
  692. if(!is_numeric($quantity) || $quantity < 1) {
  693. $vmLogger->err( $VM_LANG->_('VM_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0',false) );
  694. $add_product_validate = 0;
  695. }
  696. }
  697. if(!isset($d['order_subtotal_withtax'] )) {
  698. $d['order_subtotal_withtax'] = 0;
  699. }
  700. if ($add_product_validate == 1) {
  701. $result_attributes = $ps_product_attribute->cartGetAttributes($d);
  702. $dbp = new ps_DB;
  703. $q = "SELECT vendor_id, product_in_stock,product_sales,product_parent_id, product_sku, product_name FROM #__{vm}_product WHERE product_id='$product_id'";
  704. $dbp->query($q);
  705. $dbp->next_record();
  706. $vendor_id = $dbp->f("vendor_id");
  707. $product_sku = $dbp->f("product_sku");
  708. $product_name = $dbp->f("product_name");
  709. $product_parent_id = $dbp->f("product_parent_id");
  710. // On r�cup�re le prix exact du produit
  711. $product_price_arr = $this->get_adjusted_attribute_price($product_id, $quantity , $d["description"], $result_attributes);
  712. $product_price = $product_price_arr["product_price"];
  713. $my_taxrate = $ps_product->get_product_taxrate($product_id);
  714. $description = $d["description"];
  715. $product_final_price = round( ($product_price *($my_taxrate+1)), 2 );
  716. $product_currency = $product_price_arr["product_currency"];
  717. $db = new ps_DB;
  718. $q = "SELECT * FROM #__{vm}_order_item ";
  719. $q .= " WHERE order_id=" . $this->order_id;
  720. $db->query($q);
  721. $db->next_record();
  722. $user_info_id = $db->f("user_info_id");
  723. $order_status = $db->f("order_status");
  724. $timestamp = time() + ($mosConfig_offset*60*60);
  725. $q = "INSERT INTO #__{vm}_order_item ";
  726. $q .= "(order_id, user_info_id, vendor_id, product_id, order_item_sku, order_item_name, ";
  727. $q .= "product_quantity, product_item_price, product_final_price, ";
  728. $q .= "order_item_currency, order_status, product_attribute, cdate, mdate) ";
  729. $q .= "VALUES ('";
  730. $q .= $this->order_id . "', '";
  731. $q .= $user_info_id . "', '";
  732. $q .= $vendor_id . "', '";
  733. $q .= $product_id . "', '";
  734. $q .= $product_sku . "', '";
  735. $q .= $product_name . "', '";
  736. $q .= $quantity . "', '";
  737. $q .= $product_price . "', '";
  738. $q .= $product_final_price . "', '";
  739. $q .= $product_currency . "', '";
  740. $q .= $order_status . "', '";
  741. // added for advanced attribute storage
  742. $q .= addslashes( $description ) . "', '";
  743. // END advanced attribute modifications
  744. $q .= $timestamp . "','";
  745. $q .= $timestamp . "'";
  746. $q .= ")";
  747. $db->query($q);
  748. $db->next_record();
  749. $q = "SELECT product_id, product_quantity, product_final_price, product_item_price, product_final_price - product_item_price AS item_tax ";
  750. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' ";
  751. $q .= "AND order_item_id = '".addslashes($order_item_id)."'";
  752. $db->query($q);
  753. $db->next_record();
  754. $net_price_change = $quantity * $product_price;
  755. $tax_change = $quantity * ($product_final_price - $product_price);
  756. $price_change = $quantity * $product_final_price;
  757. $order_subtotal = 0;
  758. if( $_SESSION["auth"]["show_price_including_tax"] == 1 ) {
  759. $product_price = round( ($product_price *($my_taxrate+1)), 2 );
  760. $product_price *= $quantity;
  761. $d['order_subtotal_withtax'] += $product_price;
  762. $product_price = $product_price /($my_taxrate+1);
  763. $order_subtotal += $product_price;
  764. }
  765. else {
  766. $order_subtotal += $product_price * $quantity;
  767. $product_price = round( ($product_price *($my_taxrate+1)), 2 );
  768. $product_price *= $quantity;
  769. $d['order_subtotal_withtax'] += $product_price;
  770. $product_price = $product_price /($my_taxrate+1);
  771. }
  772. // Update order
  773. $q = "UPDATE #__{vm}_orders ";
  774. $q .= "SET order_tax = (order_tax + ".$tax_change." ), ";
  775. $q .= "order_total = (order_total + ".$price_change." ), ";
  776. $q .= "order_subtotal = (order_subtotal + ".$net_price_change.") ";
  777. $q .= "WHERE order_id = '" . $this->order_id . "'";
  778. $db->query($q);
  779. $db->next_record();
  780. $this->reload_from_db = 1;
  781. // Update Stock Level and Product Sales
  782. $q = "UPDATE #__{vm}_product ";
  783. $q .= "SET product_in_stock = product_in_stock - ".$quantity;
  784. $q .= " WHERE product_id = '" . $product_id . "'";
  785. $db->query($q);
  786. $db->next_record();
  787. $q = "UPDATE #__{vm}_product ";
  788. $q .= "SET product_sales= product_sales + " .$quantity;
  789. $q .= " WHERE product_id='". $product_id ."'";
  790. $db->query($q);
  791. $db->next_record();
  792. $this->product_added = true;
  793. $vmLogger->info( $VM_LANG->_('VM_ORDER_EDIT_PRODUCT_ADDED',false) );
  794. }
  795. }
  796. /**************************************************************************
  797. * name: display_form_add_product
  798. * created by: nfischer
  799. * description: Display the add_product form
  800. * parameters:
  801. * returns:
  802. **************************************************************************/
  803. function display_form_add_product() {
  804. global $VM_LANG, $vmLogger;
  805. require_once(CLASSPATH . 'ps_product_attribute.php');
  806. //require_once(CLASSPATH . 'ps_product.php');
  807. $ps_product_attribute = new ps_product_attribute;
  808. //$ps_product = new ps_product;
  809. $order_item_id = vmGet( $_REQUEST, 'order_item_id' );
  810. // Affichage de l'en-t�te
  811. $html_entete = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">';
  812. $html_entete .= '<br /><br /><table class="adminlist"><tr><th>' . $VM_LANG->_('VM_ORDER_EDIT_ADD_PRODUCT') . '</th></tr></table>';
  813. $html_entete .= '<table class="adminlist"><tr>';
  814. $html_entete .= '<th>' . $VM_LANG->_('PHPSHOP_ORDER_PRINT_NAME') . '</th>';
  815. $html_pied = '<input type="hidden" name="add_product" value="1" />
  816. <input type="hidden" name="order_edit_page" value="1" />
  817. <input type="hidden" name="page" value="order.order_print" />
  818. <input type="hidden" name="option" value="com_virtuemart" />
  819. <input type="hidden" name="func" value="" />
  820. <input type="hidden" name="order_id" value="' . $this->order_id . '" /></form>';
  821. $html_return_parent = '<form method="post" action="' . $_SERVER['PHP_SELF'] . '">
  822. <input type="submit" value="' . $VM_LANG->_('VM_ORDER_EDIT_RETURN_PARENTS') . '" />
  823. <input type="hidden" name="product_id" value="-1" />
  824. <input type="hidden" name="add_product_validate" value="0" />
  825. <input type="hidden" name="add_product_item" value="0" />
  826. <input type="hidden" name="add_product" value="1" />
  827. <input type="hidden" name="order_edit_page" value="1" />
  828. <input type="hidden" name="page" value="order.order_print" />
  829. <input type="hidden" name="option" value="com_virtuemart" />
  830. <input type="hidden" name="func" value="" />
  831. <input type="hidden" name="order_id" value="' . $this->order_id . '" /></form>';
  832. $product_id = vmGet( $_REQUEST, 'product_id' );
  833. if ($this->product_added ==true) {
  834. $product_id = -1;
  835. }
  836. $d = $_REQUEST;
  837. $add_product_validate = vmGet( $_REQUEST, 'add_product_validate' );
  838. if ($product_id < 0 || $product_id == "") {
  839. $html_table = '<tr><td>' . $this->list_products($product_id) . '</td>';
  840. $html_entete .= '</tr>';
  841. $html_table .= '</tr></table><input type="hidden" name="add_product_validate" value="0" />';
  842. echo $html_entete . $html_table . $html_pied;
  843. return;
  844. }
  845. $db = new ps_DB;
  846. $q = "SELECT product_id FROM #__{vm}_product WHERE ";
  847. $q .= "product_parent_id = '".$product_id."'";
  848. $db->query($q);
  849. $item = false;
  850. // Elements fils s�lectionn�s
  851. if (vmGet( $_REQUEST, 'add_product_item' ) == 1) {
  852. $item = true;
  853. $html_table = '<tr><td>' . $this->list_attribute($product_id, false) . '<input type="hidden" name="add_product_item" value="1" /></td>';
  854. }
  855. // S'il y a des �l�ments fils
  856. else if ( $db->num_rows()) {
  857. $html_entete .= '</tr>';
  858. $html_table = '<tr><td>' . $this->list_attribute($product_id) . '<input type="hidden" name="add_product_validate" value="0" /><input type="hidden" name="add_product_item" value="1" /></td></tr></table>';
  859. echo $html_entete . $html_table . $html_pied . $html_return_parent;
  860. return;
  861. }
  862. else {
  863. $html_table = '<tr><td>' . $this->list_products($product_id) . '</td>';
  864. }
  865. $html_entete .= '<th>' . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_CUSTOM_ATTRIBUTE_LIST') . '</th>';
  866. $html_entete .= '<th>' . $VM_LANG->_('PHPSHOP_PRODUCT_FORM_ATTRIBUTE_LIST') . '</th>';
  867. $html_entete .= '<th align="left">' . $VM_LANG->_('PHPSHOP_ORDER_PRINT_QUANTITY') . '</th>';
  868. $html_entete .= '<th align="left">Action</th></tr>';
  869. $html_table .= '<td>' . $ps_product_attribute->list_advanced_attribute($product_id) . '</td>';
  870. $html_table .= '<td>' . $ps_product_attribute->list_custom_attribute($product_id) . '</td>';
  871. $html_table .= '<td><input type="text" value="1" name="product_quantity" size="5" /><input type="hidden" name="add_product_validate" value="1" /></td>';
  872. $html_table .= '<td><input type="submit" value="' . $VM_LANG->_('VM_ORDER_EDIT_ADD') . '" /></td></tr></table>';
  873. if ($item) {
  874. $html_pied .= $html_return_parent;
  875. }
  876. echo $html_entete . $html_table . $html_pied;
  877. return;
  878. }
  879. /**************************************************************************
  880. * name: list_products
  881. * created by: nfischer
  882. * description: Create a list of products
  883. * parameters: product_id
  884. * returns: html to display
  885. **************************************************************************/
  886. function list_products($product_id) {
  887. global $VM_LANG;
  888. $db = new ps_DB;
  889. $query_list_products = "SELECT DISTINCT `product_name`,`products_per_row`,`category_browsepage`,`category_flypage`";
  890. $query_list_products .= ",`#__{vm}_product`.`product_id`,`#__{vm}_category`.`category_id`,`product_full_image`,`product_thumb_image`";
  891. $query_list_products .= ",`product_s_desc`,`product_parent_id`,`product_publish`,`product_in_stock`,`product_sku`";
  892. $query_list_products .= " FROM (`#__{vm}_product`, `#__{vm}_category`, `#__{vm}_product_category_xref`";
  893. $query_list_products .= ",`#__{vm}_shopper_group`) LEFT JOIN `#__{vm}_product_price` ON";
  894. $query_list_products .= " `#__{vm}_product`.`product_id` = `#__{vm}_product_price`.`product_id`";
  895. $query_list_products .= " WHERE `#__{vm}_product_category_xref`.`category_id`=`#__{vm}_category`.`category_id`";
  896. $query_list_products .= " AND `#__{vm}_product`.`product_id`=`#__{vm}_product_category_xref`.`product_id`";
  897. $query_list_products .= " AND `#__{vm}_product`.`product_parent_id`='0'";
  898. $query_list_products .= " AND `product_publish`='Y'";
  899. $query_list_products .= " AND (( `#__{vm}_shopper_group`.`shopper_group_id`=`#__{vm}_product_price`.`shopper_group_id` )";
  900. $query_list_products .= " OR (`#__{vm}_product_price`.`product_id` IS NULL))";
  901. $query_list_products .= " GROUP BY `#__{vm}_product`.`product_sku` ORDER BY `#__{vm}_product`.`product_name`";
  902. $db->query($query_list_products);
  903. $display = '<select name="product_id" onChange="this.form.add_product_validate.value=0;this.form.submit();">';
  904. $display .= '<option value="-1">' . $VM_LANG->_('VM_ORDER_EDIT_CHOOSE_PRODUCT') . '</option>';
  905. while ($db->next_record()) {
  906. $display .= '<option value="' . $db->f("product_id") . '"';
  907. if ($product_id == $db->f("product_id")) {
  908. $display .= ' selected="yes"';
  909. }
  910. $display .= '>' . $db->f("product_name") . '</option>';
  911. }
  912. $display .= '</select>';
  913. return $display;
  914. }
  915. /**************************************************************************
  916. * name: get_price
  917. * created by: nfischer
  918. * description: Give the price of a product
  919. * parameters: $product_id, $quantity ,$check_multiple_prices=false, $result_attributes
  920. * returns: Price of the product
  921. **************************************************************************/
  922. function get_price($product_id, $quantity ,$check_multiple_prices=false, $result_attributes) {
  923. if($check_multiple_prices) {
  924. $db = new ps_DB;
  925. // Get the vendor id for this product.
  926. $q = "SELECT vendor_id FROM #__{vm}_product WHERE product_id='$product_id'";
  927. $db->setQuery($q); $db->query();
  928. $db->next_record();
  929. $vendor_id = $db->f("vendor_id");
  930. $q = "SELECT svx.shopper_group_id, sg.shopper_group_discount FROM #__{vm}_shopper_vendor_xref svx, #__{vm}_orders o, #__{vm}_shopper_group sg";
  931. $q .= " WHERE svx.user_id=o.user_id AND sg.shopper_group_id=svx.shopper_group_id AND o.order_id=" . $this->order_id;
  932. $db->query($q);
  933. $db->next_record();
  934. $shopper_group_id = $db->f("shopper_group_id");
  935. $shopper_group_discount = $db->f("shopper_group_discount");
  936. // Get the default shopper group id for this vendor
  937. $q = "SELECT shopper_group_id,shopper_group_discount FROM #__{vm}_shopper_group WHERE ";
  938. $q .= "vendor_id='$vendor_id' AND `default`='1'";
  939. $db->setQuery($q); $db->query();
  940. $db->next_record();
  941. $default_shopper_group_id = $db->f("shopper_group_id");
  942. $default_shopper_group_discount = $db->f("shopper_group_discount");
  943. // Get the product_parent_id for this product/item
  944. $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id='$product_id'";
  945. $db->setQuery($q); $db->query();
  946. $db->next_record();
  947. $product_parent_id = $db->f("product_parent_id");
  948. $price_info = Array();
  949. if( !$check_multiple_prices ) {
  950. /* Added for Volume based prices */
  951. // This is an important decision: we add up all product quantities with the same product_id,
  952. // regardless to attributes. This gives "real" volume based discount, because our simple attributes
  953. // depend on one and the same product_id
  954. $volume_quantity_sql = " AND (('$quantity' >= price_quantity_start AND '$quantity' <= price_quantity_end)
  955. OR (price_quantity_end='0') OR ('$quantity' > price_quantity_end)) ORDER BY price_quantity_end DESC";
  956. /* End Addition */
  957. }
  958. else {
  959. $volume_quantity_sql = " ORDER BY price_quantity_start";
  960. }
  961. // Getting prices
  962. //
  963. // If the shopper group has a price then show it, otherwise
  964. // show the default price.
  965. if( !empty($shopper_group_id) ) {
  966. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_id' AND ";
  967. $q .= "shopper_group_id='$shopper_group_id' $volume_quantity_sql";
  968. $db->setQuery($q); $db->query();
  969. if ($db->next_record()) {
  970. $price_info["product_price"]= $db->f("product_price");
  971. if( $check_multiple_prices ) {
  972. $price_info["product_base_price"]= $db->f("product_price");
  973. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1;
  974. }
  975. $price_info["product_price_id"]=$db->f("product_price_id");
  976. $price_info["product_currency"]=$db->f("product_currency");
  977. $price_info["item"]=true;
  978. $GLOBALS['product_info'][$product_id]['price'] = $price_info;
  979. return $GLOBALS['product_info'][$product_id]['price'];
  980. }
  981. }
  982. // Get default price
  983. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_id' AND ";
  984. $q .= "shopper_group_id='$default_shopper_group_id' $volume_quantity_sql";
  985. $db->setQuery($q); $db->query();
  986. if ($db->next_record()) {
  987. $price_info["product_price"]=$db->f("product_price") * ((100 - $shopper_group_discount)/100);
  988. if( $check_multiple_prices ) {
  989. $price_info["product_base_price"]= $price_info["product_price"];
  990. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1;
  991. }
  992. $price_info["product_price_id"]=$db->f("product_price_id");
  993. $price_info["product_currency"] = $db->f("product_currency");
  994. $price_info["item"] = true;
  995. $GLOBALS['product_info'][$product_id]['price'] = $price_info;
  996. return $GLOBALS['product_info'][$product_id]['price'];
  997. }
  998. // Maybe its an item with no price, check again with product_parent_id
  999. if( !empty($shopper_group_id) ) {
  1000. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_parent_id' AND ";
  1001. $q .= "shopper_group_id='$shopper_group_id' $volume_quantity_sql";
  1002. $db->setQuery($q); $db->query();
  1003. if ($db->next_record()) {
  1004. $price_info["product_price"]=$db->f("product_price");
  1005. if( $check_multiple_prices ) {
  1006. $price_info["product_base_price"]= $db->f("product_price");
  1007. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1;
  1008. }
  1009. $price_info["product_price_id"]=$db->f("product_price_id");
  1010. $price_info["product_currency"] = $db->f("product_currency");
  1011. $GLOBALS['product_info'][$product_id]['price'] = $price_info;
  1012. return $GLOBALS['product_info'][$product_id]['price'];
  1013. }
  1014. }
  1015. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_parent_id' AND ";
  1016. $q .= "shopper_group_id='$default_shopper_group_id' $volume_quantity_sql";
  1017. $db->setQuery($q); $db->query();
  1018. if ($db->next_record()) {
  1019. $price_info["product_price"]=$db->f("product_price") * ((100 - $shopper_group_discount)/100);
  1020. if( $check_multiple_prices ) {
  1021. $price_info["product_base_price"]= $price_info["product_price"];
  1022. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1;
  1023. }
  1024. $price_info["product_price_id"]=$db->f("product_price_id");
  1025. $price_info["product_currency"] = $db->f("product_currency");
  1026. $GLOBALS['product_info'][$product_id]['price'] = $price_info;
  1027. return $GLOBALS['product_info'][$product_id]['price'];
  1028. }
  1029. // No price found
  1030. $GLOBALS['product_info'][$product_id]['price'] = false;
  1031. return $GLOBALS['product_info'][$product_id]['price'];
  1032. }
  1033. else {
  1034. return $GLOBALS['product_info'][$product_id]['price'];
  1035. }
  1036. }
  1037. /**************************************************************************
  1038. * name: get_adjusted_attribute_price
  1039. * created by: nfischer
  1040. * description: Give the price of a product according…

Large files files are truncated, but you can click here to view the full file