PageRenderTime 57ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/administrator/components/com_virtuemart/classes/ps_order_change.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 1115 lines | 728 code | 169 blank | 218 comment | 106 complexity | 28de70a65aaae609aa58ce97a8c91f61 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. if( ! defined( '_VALID_MOS' ) && ! defined( '_JEXEC' ) )
  3. die( 'Direct Access to ' . basename( __FILE__ ) . ' is not allowed.' ) ;
  4. /**
  5. *
  6. * @version $Id$
  7. * @author nfischer & kaltokri
  8. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
  9. *
  10. */
  11. /****************************************************************************
  12. * ps_order_edit
  13. * The class acts as a plugin for the order_print page.
  14. *************************************************************************/
  15. class ps_order_change {
  16. var $order_id ;
  17. var $reload_from_db ;
  18. /**************************************************************************
  19. * name: ps_order_change (constructor)
  20. * created by: kaltokri
  21. * description: constructor, setup initial variables
  22. * parameters: Order Id
  23. * returns: none
  24. **************************************************************************/
  25. function ps_order_change( $order_id ) {
  26. $this->order_id = $order_id ;
  27. }
  28. /**************************************************************************
  29. * name: recalc_order
  30. * created by: kaltokri
  31. * description: Recalc the order (copied & modified from ps_checkout.php)
  32. * parameters: $order_id
  33. * returns: nothing
  34. **************************************************************************/
  35. function recalc_order( $order_id ) {
  36. //global $VM_LANG, $vmLogger;
  37. $debug_output = False ;
  38. // Read all items from db
  39. $db = new ps_DB( ) ;
  40. $q = "SELECT * FROM #__{vm}_order_item WHERE order_id = '" . $order_id . "'" ;
  41. $db->query( $q ) ;
  42. $order_tax_details = array() ;
  43. while( $db->next_record() ) {
  44. $product_final_price = $db->f( "product_final_price" ) ;
  45. $product_item_price = $db->f( "product_item_price" ) ;
  46. $product_quantity = $db->f( "product_quantity" ) ;
  47. if ($product_item_price > 0) {
  48. $my_taxrate = strval(round(($product_final_price / $product_item_price) - 1,2)."00");
  49. } else {
  50. $my_taxrate = 0;
  51. }
  52. $order_tax += ($product_final_price - $product_item_price) * $product_quantity ;
  53. $order_subtotal += $product_item_price * $product_quantity ;
  54. if( MULTIPLE_TAXRATES_ENABLE ) {
  55. // Calculate the amounts for each tax rate
  56. if( ! isset( $order_tax_details[$my_taxrate] ) ) {
  57. $order_tax_details[$my_taxrate] = 0 ;
  58. }
  59. $order_tax_details[$my_taxrate] += ($product_final_price - $product_item_price) * $product_quantity ;
  60. }
  61. }
  62. $db = new ps_DB( ) ;
  63. $q = "SELECT * FROM #__{vm}_orders WHERE order_id = '" . $order_id . "'" ;
  64. $db->query( $q ) ;
  65. // Read fix data from db
  66. $order_shipping = $db->f( "order_shipping" ) ;
  67. $order_shipping_tax = $db->f( "order_shipping_tax" ) ;
  68. $coupon_discount = $db->f( "coupon_discount" ) ;
  69. $order_discount = $db->f( "order_discount" ) ;
  70. $order_total = $order_subtotal + round( $order_tax, 2 ) + $order_shipping + $order_shipping_tax - $coupon_discount - $order_discount ;
  71. If( PAYMENT_DISCOUNT_BEFORE == 1 ) {
  72. // Calculate the taxes after discounts are subtracted
  73. $my_total_taxrate = round( (($order_subtotal + $order_tax) / $order_subtotal) - 1, 4 ) ;
  74. $temp_order_subtotal = $order_subtotal - $coupon_discount - $order_discount ;
  75. $order_tax = $temp_order_subtotal * $my_total_taxrate ;
  76. // Recalculate the order_total
  77. $order_total = $temp_order_subtotal + round( $order_tax, 2 ) + $order_shipping + $order_shipping_tax ;
  78. // If multiple taxes are used, they must be corrected
  79. $discount_factor = ($coupon_discount + $order_discount) / $order_subtotal ;
  80. if( MULTIPLE_TAXRATES_ENABLE ) {
  81. foreach( $order_tax_details as $rate => $value ) {
  82. $order_tax_details[$rate] = $value * (1 - $discount_factor) ;
  83. }
  84. }
  85. // Debug information
  86. if( $debug_output ) {
  87. $vmLogger->info( "\n" . '$order_subtotal=' . $order_subtotal . "\n" . '$order_discount=' . $order_discount * - 1 . "\n" . '$coupon_discount=' . $coupon_discount * - 1 . "\n" . '$temp_order_subtotal=' . $temp_order_subtotal . "\n" . '$order_tax=' . $order_tax . "\n" . '$order_shipping=' . $order_shipping . "\n" . '$order_shipping_tax=' . $order_shipping_tax . "\n" . '$order_total=' . $order_total . "\n" . '$order_tax_details=' . serialize( $order_tax_details ) ) ;
  88. }
  89. } else {
  90. if( $debug_output ) {
  91. // Debug information
  92. $vmLogger->info( "\n" . '$order_subtotal=' . $order_subtotal . "\n" . '$order_tax=' . $order_tax . "\n" . '$order_discount=' . $order_discount * - 1 . "\n" . '$coupon_discount=' . $coupon_discount * - 1 . "\n" . '$order_shipping=' . $order_shipping . "\n" . '$order_shipping_tax=' . $order_shipping_tax . "\n" . '$order_total=' . $order_total . "\n" . '$order_tax_details=' . serialize( $order_tax_details ) ) ;
  93. }
  94. }
  95. // Write data to database
  96. $q = "UPDATE #__{vm}_orders SET " ;
  97. $q .= "order_subtotal = " . $order_subtotal . ", " ;
  98. $q .= "order_tax = " . $order_tax . ", " ;
  99. $q .= "order_total = " . $order_total . ", " ;
  100. $q .= "order_tax_details = '" . serialize( $order_tax_details ) . "' " ;
  101. $q .= " WHERE order_id = '" . $order_id . "'" ;
  102. $db->query( $q ) ;
  103. $db->next_record() ;
  104. }
  105. /**************************************************************************
  106. * name: change_bill_to (constructor)
  107. * created by: kaltokri
  108. * description: Change bill to
  109. * parameters: none
  110. * returns: none
  111. **************************************************************************/
  112. function change_bill_to() {
  113. global $VM_LANG, $vmLogger ;
  114. $db = new ps_DB( ) ;
  115. $db2 = new ps_DB( ) ;
  116. $bill_to = trim( vmGet( $_REQUEST, 'bill_to' ) ) ;
  117. $q = "SELECT * FROM #__{vm}_user_info WHERE user_id = '" . $bill_to . "'" ;
  118. $db->query( $q ) ;
  119. if( ! $db->next_record() ) {
  120. print "<h1>Invalid user id: $bill_to</h1>" ;
  121. return ;
  122. }
  123. // Update order
  124. $q = "UPDATE #__{vm}_orders " ;
  125. $q .= "SET user_id = '" . $bill_to . "'," ;
  126. $q .= " user_info_id = '" . $db->f( 'user_info_id' ) . "'" ;
  127. $q .= " WHERE order_id = '" . $this->order_id . "'" ;
  128. $db2->query( $q ) ;
  129. $db2->next_record() ;
  130. // Update order_user_info
  131. $q = "UPDATE #__{vm}_order_user_info " ;
  132. $q .= "SET user_id = '" . $db->f( 'user_id' ) . "', " ;
  133. $q .= "address_type_name = '" . $db->f( 'address_type_name' ) . "', " ;
  134. $q .= "company = '" . $db->f( 'company' ) . "', " ;
  135. $q .= "title = '" . $db->f( 'title' ) . "', " ;
  136. $q .= "last_name = '" . $db->f( 'last_name' ) . "', " ;
  137. $q .= "first_name = '" . $db->f( 'first_name' ) . "', " ;
  138. $q .= "middle_name = '" . $db->f( 'middle_name' ) . "', " ;
  139. $q .= "phone_1 = '" . $db->f( 'phone_1' ) . "', " ;
  140. $q .= "phone_2 = '" . $db->f( 'phone_2' ) . "', " ;
  141. $q .= "fax = '" . $db->f( 'fax' ) . "', " ;
  142. $q .= "address_1 = '" . $db->f( 'address_1' ) . "', " ;
  143. $q .= "address_2 = '" . $db->f( 'address_2' ) . "', " ;
  144. $q .= "city = '" . $db->f( 'city' ) . "', " ;
  145. $q .= "state = '" . $db->f( 'state' ) . "', " ;
  146. $q .= "country = '" . $db->f( 'country' ) . "', " ;
  147. $q .= "zip = '" . $db->f( 'zip' ) . "', " ;
  148. $q .= "user_email = '" . $db->f( 'user_email' ) . "', " ;
  149. $q .= "extra_field_1 = '" . $db->f( 'extra_field_1' ) . "', " ;
  150. $q .= "extra_field_2 = '" . $db->f( 'extra_field_2' ) . "', " ;
  151. $q .= "extra_field_3 = '" . $db->f( 'extra_field_3' ) . "', " ;
  152. $q .= "extra_field_4 = '" . $db->f( 'extra_field_4' ) . "', " ;
  153. $q .= "extra_field_5 = '" . $db->f( 'extra_field_5' ) . "', " ;
  154. $q .= "bank_account_nr = '" . $db->f( 'bank_account_nr' ) . "', " ;
  155. $q .= "bank_name = '" . $db->f( 'bank_name' ) . "', " ;
  156. $q .= "bank_sort_code = '" . $db->f( 'bank_sort_code' ) . "', " ;
  157. $q .= "bank_iban = '" . $db->f( 'bank_iban' ) . "', " ;
  158. $q .= "bank_account_holder = '" . $db->f( 'bank_account_holder' ) . "', " ;
  159. $q .= "bank_account_type = '" . $db->f( 'bank_account_type' ) . "' " ;
  160. $q .= " WHERE order_id = '" . $this->order_id . "' AND address_type = 'BT'" ;
  161. $db2->query( $q ) ;
  162. $db2->next_record() ;
  163. // Delete ship to
  164. $q = "DELETE FROM #__{vm}_order_user_info " ;
  165. $q .= "WHERE order_id = '" . $this->order_id . "' AND address_type = 'ST'" ;
  166. $db2->query( $q ) ;
  167. $db2->next_record() ;
  168. $this->reload_from_db = 1 ;
  169. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_PRINT_BILL_TO_LBL' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  170. }
  171. /**************************************************************************
  172. * name: change_ship_to
  173. * created by: Kaltokri
  174. * description: Change ship to
  175. * parameters: none
  176. * returns: none
  177. **************************************************************************/
  178. function change_ship_to() {
  179. global $VM_LANG, $vmLogger ;
  180. $ship_to = trim( vmGet( $_REQUEST, 'ship_to' ) ) ;
  181. $db = new ps_DB( ) ;
  182. // Delete ship to
  183. $q = "DELETE FROM #__{vm}_order_user_info " ;
  184. $q .= "WHERE order_id = '" . $this->order_id . "' AND address_type = 'ST'" ;
  185. $db->query( $q ) ;
  186. $db->next_record() ;
  187. $q = "SELECT * FROM #__{vm}_user_info " ;
  188. $q .= "WHERE user_info_id = '" . $ship_to . "'" ;
  189. $db->query( $q ) ;
  190. $db->next_record() ;
  191. if( $db->f( 'address_type' ) == 'ST' ) {
  192. // Ship to Address if applicable (copied from ps_checkout.php and changed)
  193. $q = "INSERT INTO `#__{vm}_order_user_info` " ;
  194. $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'" ;
  195. $db->query( $q ) ;
  196. $db->next_record() ;
  197. }
  198. $this->reload_from_db = 1 ;
  199. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_PRINT_SHIP_TO_LBL' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  200. }
  201. /**************************************************************************
  202. * name: change_customer_note
  203. * created by: kaltokri
  204. * description: Change order customer_note
  205. * parameters: none
  206. * returns: none
  207. **************************************************************************/
  208. function change_customer_note() {
  209. global $VM_LANG, $vmLogger ;
  210. $db = new ps_DB( ) ;
  211. $customer_note = trim( vmGet( $_REQUEST, 'customer_note' ) ) ;
  212. // Update order
  213. $q = "UPDATE #__{vm}_orders " ;
  214. $q .= "SET customer_note = '" . $customer_note . "' " ;
  215. $q .= "WHERE order_id = '" . $this->order_id . "'" ;
  216. $db->query( $q ) ;
  217. $db->next_record() ;
  218. $this->reload_from_db = 1 ;
  219. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_PRINT_CUSTOMER_NOTE' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  220. $this->recalc_order( $this->order_id ) ;
  221. }
  222. /**************************************************************************
  223. * name: change_standard_shipping
  224. * created by: ingemar
  225. * description: Change order shipping rate
  226. * parameters: none
  227. * returns: none
  228. **************************************************************************/
  229. function change_standard_shipping() {
  230. global $VM_LANG, $vmLogger ;
  231. $db = new ps_DB( ) ;
  232. $shipping = trim( vmGet( $_REQUEST, 'shipping' ) ) ;
  233. $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 ) . "'" ;
  234. $db->query( $q ) ;
  235. if( ! $db->next_record() ) {
  236. print "<h1>Invalid shipping id: $shipping</h1>" ;
  237. return ;
  238. }
  239. $shipping_carrier = $db->f( 'shipping_carrier_name' ) ;
  240. $shipping_name = $db->f( 'shipping_rate_name' ) ;
  241. $shipping_rate = $db->f( 'shipping_rate_value' ) ;
  242. $shipping_tax = $db->f( 'shipping_total' ) - $db->f( 'shipping_rate_value' ) ;
  243. $shipping_total = $db->f( 'shipping_total' ) ;
  244. $shipping_method = "standard_shipping|$shipping_carrier|$shipping_name|" . round( $shipping_total, 2 ) . "|$shipping" ;
  245. // Update order
  246. $q = "UPDATE #__{vm}_orders " ;
  247. $q .= "SET order_total = order_total - order_shipping - order_shipping_tax + " . $shipping_rate . " + " . $shipping_tax . ", " ;
  248. $q .= "order_shipping = " . $shipping_rate . ", " ;
  249. $q .= "order_shipping_tax = " . $shipping_tax . ", " ;
  250. $q .= "ship_method_id = '" . addslashes( $shipping_method ) . "'" ;
  251. $q .= " WHERE order_id = '" . $this->order_id . "'" ;
  252. $db->query( $q ) ;
  253. $db->next_record() ;
  254. $this->reload_from_db = 1 ;
  255. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_PRINT_SHIPPING_MODE_LBL' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  256. }
  257. /**************************************************************************
  258. * name: change_shipping
  259. * created by: Greg
  260. * description: Change order shipping
  261. * parameters:
  262. * returns:
  263. **************************************************************************/
  264. function change_shipping( $order_id, $shipping ) {
  265. if( ! is_numeric( $shipping ) ) {
  266. return - 1 ;
  267. }
  268. $db = new ps_DB( ) ;
  269. $q = "UPDATE #__{vm}_orders SET " ;
  270. $q .= "order_shipping = '" . $shipping . "' " ;
  271. $q .= "WHERE order_id = '" . $order_id . "'" ;
  272. $db->query( $q ) ;
  273. $db->next_record() ;
  274. $this->recalc_order( $order_id ) ;
  275. $this->reload_from_db = 1 ;
  276. }
  277. /**************************************************************************
  278. * name: change_shipping_tax
  279. * created by: Greg
  280. * description: Change order shipping tax
  281. * parameters:
  282. * returns:
  283. **************************************************************************/
  284. function change_shipping_tax( $order_id, $shipping_tax ) {
  285. if( ! is_numeric( $shipping_tax ) ) {
  286. return - 1 ;
  287. }
  288. $db = new ps_DB( ) ;
  289. $q = "UPDATE #__{vm}_orders SET " ;
  290. $q .= "order_shipping_tax = '" . $shipping_tax . "' " ;
  291. $q .= "WHERE order_id = '" . $order_id . "'" ;
  292. $db->query( $q ) ;
  293. $db->next_record() ;
  294. $this->recalc_order( $order_id ) ;
  295. $this->reload_from_db = 1 ;
  296. }
  297. /**************************************************************************
  298. * name: change_discount
  299. * created by: ingemar
  300. * description: Change order discount
  301. * parameters:
  302. * returns:
  303. **************************************************************************/
  304. function change_discount( $order_id, $discount ) {
  305. if( ! is_numeric( $discount ) ) {
  306. return - 1 ;
  307. }
  308. $db = new ps_DB( ) ;
  309. $q = "UPDATE #__{vm}_orders SET " ;
  310. $q .= "order_discount = '" . $discount . "' " ;
  311. $q .= "WHERE order_id = '" . $order_id . "'" ;
  312. $db->query( $q ) ;
  313. $db->next_record() ;
  314. $this->recalc_order( $order_id ) ;
  315. $this->reload_from_db = 1 ;
  316. }
  317. /**************************************************************************
  318. * name: change_coupon_discount
  319. * created by: ingemar
  320. * description: Change order coupon discount
  321. * parameters:
  322. * returns:
  323. **************************************************************************/
  324. function change_coupon_discount( $order_id, $discount ) {
  325. if( ! is_numeric( $discount ) ) {
  326. return - 1 ;
  327. }
  328. // Update order
  329. $db = new ps_DB( ) ;
  330. $q = "UPDATE #__{vm}_orders SET " ;
  331. $q .= "coupon_discount = '" . $discount . "' " ;
  332. $q .= "WHERE order_id = '" . $order_id . "'" ;
  333. $db->query( $q ) ;
  334. $db->next_record() ;
  335. $this->recalc_order( $order_id ) ;
  336. $this->reload_from_db = 1 ;
  337. }
  338. /**************************************************************************
  339. * name: change_delete_item
  340. * created by: nfischer
  341. * description: Delete an item
  342. * parameters:
  343. * returns:
  344. **************************************************************************/
  345. function change_delete_item( $order_id, $order_item_id ) {
  346. global $VM_LANG, $vmLogger ;
  347. if( ! is_numeric( $order_item_id ) ) {
  348. return - 1 ;
  349. }
  350. $db = new ps_DB( ) ;
  351. $q = "SELECT product_id, product_quantity " ;
  352. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $order_id . "' " ;
  353. $q .= "AND order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  354. $db->query( $q ) ;
  355. $db->next_record() ;
  356. $product_id = $db->f( 'product_id' ) ;
  357. $diff = 0 - $db->f( 'product_quantity' ) ;
  358. // Delete item
  359. $q = "DELETE FROM #__{vm}_order_item " ;
  360. $q .= "WHERE order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  361. $db->query( $q ) ;
  362. $db->next_record() ;
  363. // Update Stock Level and Product Sales
  364. $q = "UPDATE #__{vm}_product " ;
  365. $q .= "SET product_in_stock = product_in_stock - " . $diff ;
  366. $q .= " WHERE product_id = '" . $product_id . "'" ;
  367. $db->query( $q ) ;
  368. $db->next_record() ;
  369. // Update amount of saled items of this products
  370. $q = "UPDATE #__{vm}_product " ;
  371. $q .= "SET product_sales = product_sales + " . $diff ;
  372. $q .= " WHERE product_id='" . $product_id . "'" ;
  373. $db->query( $q ) ;
  374. $db->next_record() ;
  375. $this->recalc_order( $order_id ) ;
  376. $this->reload_from_db = 1 ;
  377. }
  378. /**************************************************************************
  379. * name: change_item_quantity
  380. * created by: nfischer
  381. * description: Delete an item
  382. * parameters:
  383. * returns:
  384. **************************************************************************/
  385. function change_item_quantity( $order_id, $order_item_id, $quantity ) {
  386. if( ! is_numeric( $quantity ) || $quantity < 1 ) {
  387. return - 1 ;
  388. }
  389. $db = new ps_DB( ) ;
  390. $q = "SELECT product_id, product_quantity " ;
  391. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $order_id . "' " ;
  392. $q .= "AND order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  393. $db->query( $q ) ;
  394. $db->next_record() ;
  395. $product_id = $db->f( 'product_id' ) ;
  396. $diff = $quantity - $db->f( 'product_quantity' ) ;
  397. $timestamp = time() + ($mosConfig_offset * 60 * 60) ;
  398. // Update quantity of item
  399. $q = "UPDATE #__{vm}_order_item " ;
  400. $q .= "SET product_quantity = " . $quantity . ", " ;
  401. $q .= "mdate = " . $timestamp . " " ;
  402. $q .= "WHERE order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  403. $db->query( $q ) ;
  404. $db->next_record() ;
  405. // Update Stock Level and Product Sales
  406. $q = "UPDATE #__{vm}_product " ;
  407. $q .= "SET product_in_stock = product_in_stock - " . $diff ;
  408. $q .= " WHERE product_id = '" . $product_id . "'" ;
  409. $db->query( $q ) ;
  410. $db->next_record() ;
  411. $q = "UPDATE #__{vm}_product " ;
  412. $q .= "SET product_sales= product_sales + " . $diff ;
  413. $q .= " WHERE product_id='" . $product_id . "'" ;
  414. $db->query( $q ) ;
  415. $db->next_record() ;
  416. $this->recalc_order( $order_id ) ;
  417. $this->reload_from_db = 1 ;
  418. }
  419. /**************************************************************************
  420. * name: add_product
  421. * created by: nfischer
  422. * description: Add a new product to an existing order
  423. * parameters:
  424. * returns:
  425. **************************************************************************/
  426. function add_product() {
  427. global $VM_LANG, $vmLogger ;
  428. require_once (CLASSPATH . 'ps_product_attribute.php') ;
  429. require_once (CLASSPATH . 'ps_product.php') ;
  430. $ps_product_attribute = new ps_product_attribute( ) ;
  431. $ps_product = new ps_product( ) ;
  432. $product_id = vmGet( $_REQUEST, 'product_id' ) ;
  433. $order_item_id = vmGet( $_REQUEST, 'order_item_id' ) ;
  434. $add_product_validate = vmGet( $_REQUEST, 'add_product_validate' ) ;
  435. $d = $_REQUEST ;
  436. // Check if quantity is a numeric value
  437. if( $add_product_validate == 1 ) {
  438. $quantity = trim( vmGet( $_REQUEST, 'product_quantity' ) ) ;
  439. if( ! is_numeric( $quantity ) || $quantity < 1 ) {
  440. $vmLogger->err( $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0' ) ) ;
  441. $add_product_validate = 0 ;
  442. }
  443. }
  444. if( $add_product_validate == 1 ) {
  445. $result_attributes = $ps_product_attribute->cartGetAttributes( $d ) ;
  446. $dbp = new ps_DB( ) ;
  447. $q = "SELECT vendor_id, product_in_stock,product_sales,product_parent_id, product_sku, product_name FROM #__{vm}_product WHERE product_id='$product_id'" ;
  448. $dbp->query( $q ) ;
  449. $dbp->next_record() ;
  450. $vendor_id = $dbp->f( "vendor_id" ) ;
  451. $product_sku = $dbp->f( "product_sku" ) ;
  452. $product_name = $dbp->f( "product_name" ) ;
  453. $product_parent_id = $dbp->f( "product_parent_id" ) ;
  454. // On r�cup�re le prix exact du produit
  455. $product_price_arr = $this->get_adjusted_attribute_price( $product_id, $quantity, $d["description"], $result_attributes ) ;
  456. $product_price = $product_price_arr["product_price"] ;
  457. $my_taxrate = $ps_product->get_product_taxrate( $product_id ) ;
  458. $description = $d["description"] ;
  459. $product_final_price = round( ($product_price * ($my_taxrate + 1)), 2 ) ;
  460. $product_currency = $product_price_arr["product_currency"] ;
  461. $db = new ps_DB( ) ;
  462. if( $product_parent_id > 0 ) {
  463. $q = "SELECT attribute_name, attribute_value, product_id " ;
  464. $q .= "FROM #__{vm}_product_attribute WHERE " ;
  465. $q .= "product_id='" . $product_id . "'" ;
  466. $db->setQuery( $q ) ;
  467. $db->query() ;
  468. while( $db->next_record() ) {
  469. $description .= $db->f( "attribute_name" ) . ": " . $db->f( "attribute_value" ) . "; " ;
  470. }
  471. }
  472. $q = "SELECT * FROM #__{vm}_order_item " ;
  473. $q .= " WHERE order_id=" . $this->order_id ;
  474. $db->query( $q ) ;
  475. $db->next_record() ;
  476. $user_info_id = $db->f( "user_info_id" ) ;
  477. $order_status = $db->f( "order_status" ) ;
  478. $timestamp = time() + ($mosConfig_offset * 60 * 60) ;
  479. $q = "INSERT INTO #__{vm}_order_item " ;
  480. $q .= "(order_id, user_info_id, vendor_id, product_id, order_item_sku, order_item_name, " ;
  481. $q .= "product_quantity, product_item_price, product_final_price, " ;
  482. $q .= "order_item_currency, order_status, product_attribute, cdate, mdate) " ;
  483. $q .= "VALUES ('" ;
  484. $q .= $this->order_id . "', '" ;
  485. $q .= $user_info_id . "', '" ;
  486. $q .= $vendor_id . "', '" ;
  487. $q .= $product_id . "', '" ;
  488. $q .= $product_sku . "', '" ;
  489. $q .= $product_name . "', '" ;
  490. $q .= $quantity . "', '" ;
  491. $q .= $product_price . "', '" ;
  492. $q .= $product_final_price . "', '" ;
  493. $q .= $product_currency . "', '" ;
  494. $q .= $order_status . "', '" ;
  495. // added for advanced attribute storage
  496. $q .= addslashes( $description ) . "', '" ;
  497. // END advanced attribute modifications
  498. $q .= $timestamp . "','" ;
  499. $q .= $timestamp . "'" ;
  500. $q .= ")" ;
  501. $db->query( $q ) ;
  502. $db->next_record() ;
  503. $q = "SELECT product_id " ;
  504. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' " ;
  505. $q .= "AND order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  506. $db->query( $q ) ;
  507. $db->next_record() ;
  508. // Update Stock Level and Product Sales
  509. $q = "UPDATE #__{vm}_product " ;
  510. $q .= "SET product_in_stock = product_in_stock - " . $quantity ;
  511. $q .= " WHERE product_id = '" . $product_id . "'" ;
  512. $db->query( $q ) ;
  513. $db->next_record() ;
  514. $q = "UPDATE #__{vm}_product " ;
  515. $q .= "SET product_sales= product_sales + " . $quantity ;
  516. $q .= " WHERE product_id='" . $product_id . "'" ;
  517. $db->query( $q ) ;
  518. $db->next_record() ;
  519. $this->recalc_order( $this->order_id ) ;
  520. $this->reload_from_db = 1 ;
  521. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_PRODUCT_ADDED' ) ) ;
  522. }
  523. }
  524. /**************************************************************************
  525. * name: get_price
  526. * created by: nfischer
  527. * description: Give the price of a product
  528. * parameters: $product_id, $quantity ,$check_multiple_prices=false, $result_attributes
  529. * returns: Price of the product
  530. **************************************************************************/
  531. function get_price( $product_id, $quantity, $check_multiple_prices = false, $result_attributes ) {
  532. if( $check_multiple_prices ) {
  533. $db = new ps_DB( ) ;
  534. // Get the vendor id for this product.
  535. $q = "SELECT vendor_id FROM #__{vm}_product WHERE product_id='$product_id'" ;
  536. $db->setQuery( $q ) ;
  537. $db->query() ;
  538. $db->next_record() ;
  539. $vendor_id = $db->f( "vendor_id" ) ;
  540. $q = "SELECT svx.shopper_group_id, sg.shopper_group_discount FROM #__{vm}_shopper_vendor_xref svx, #__{vm}_orders o, #__{vm}_shopper_group sg" ;
  541. $q .= " WHERE svx.user_id=o.user_id AND sg.shopper_group_id=svx.shopper_group_id AND o.order_id=" . $this->order_id ;
  542. $db->query( $q ) ;
  543. $db->next_record() ;
  544. $shopper_group_id = $db->f( "shopper_group_id" ) ;
  545. $shopper_group_discount = $db->f( "shopper_group_discount" ) ;
  546. // Get the default shopper group id for this vendor
  547. $q = "SELECT shopper_group_id,shopper_group_discount FROM #__{vm}_shopper_group WHERE " ;
  548. $q .= "vendor_id='$vendor_id' AND `default`='1'" ;
  549. $db->setQuery( $q ) ;
  550. $db->query() ;
  551. $db->next_record() ;
  552. $default_shopper_group_id = $db->f( "shopper_group_id" ) ;
  553. $default_shopper_group_discount = $db->f( "shopper_group_discount" ) ;
  554. // Get the product_parent_id for this product/item
  555. $q = "SELECT product_parent_id FROM #__{vm}_product WHERE product_id='$product_id'" ;
  556. $db->setQuery( $q ) ;
  557. $db->query() ;
  558. $db->next_record() ;
  559. $product_parent_id = $db->f( "product_parent_id" ) ;
  560. $price_info = Array() ;
  561. if( ! $check_multiple_prices ) {
  562. /* Added for Volume based prices */
  563. // This is an important decision: we add up all product quantities with the same product_id,
  564. // regardless to attributes. This gives "real" volume based discount, because our simple attributes
  565. // depend on one and the same product_id
  566. $volume_quantity_sql = " AND (('$quantity' >= price_quantity_start AND '$quantity' <= price_quantity_end)
  567. OR (price_quantity_end='0') OR ('$quantity' > price_quantity_end)) ORDER BY price_quantity_end DESC" ;
  568. /* End Addition */
  569. } else {
  570. $volume_quantity_sql = " ORDER BY price_quantity_start" ;
  571. }
  572. // Getting prices
  573. //
  574. // If the shopper group has a price then show it, otherwise
  575. // show the default price.
  576. if( ! empty( $shopper_group_id ) ) {
  577. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_id' AND " ;
  578. $q .= "shopper_group_id='$shopper_group_id' $volume_quantity_sql" ;
  579. $db->setQuery( $q ) ;
  580. $db->query() ;
  581. if( $db->next_record() ) {
  582. $price_info["product_price"] = $db->f( "product_price" ) ;
  583. if( $check_multiple_prices ) {
  584. $price_info["product_base_price"] = $db->f( "product_price" ) ;
  585. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1 ;
  586. }
  587. $price_info["product_price_id"] = $db->f( "product_price_id" ) ;
  588. $price_info["product_currency"] = $db->f( "product_currency" ) ;
  589. $price_info["item"] = true ;
  590. $GLOBALS['product_info'][$product_id]['price'] = $price_info ;
  591. return $GLOBALS['product_info'][$product_id]['price'] ;
  592. }
  593. }
  594. // Get default price
  595. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_id' AND " ;
  596. $q .= "shopper_group_id='$default_shopper_group_id' $volume_quantity_sql" ;
  597. $db->setQuery( $q ) ;
  598. $db->query() ;
  599. if( $db->next_record() ) {
  600. $price_info["product_price"] = $db->f( "product_price" ) * ((100 - $shopper_group_discount) / 100) ;
  601. if( $check_multiple_prices ) {
  602. $price_info["product_base_price"] = $price_info["product_price"] ;
  603. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1 ;
  604. }
  605. $price_info["product_price_id"] = $db->f( "product_price_id" ) ;
  606. $price_info["product_currency"] = $db->f( "product_currency" ) ;
  607. $price_info["item"] = true ;
  608. $GLOBALS['product_info'][$product_id]['price'] = $price_info ;
  609. return $GLOBALS['product_info'][$product_id]['price'] ;
  610. }
  611. // Maybe its an item with no price, check again with product_parent_id
  612. if( ! empty( $shopper_group_id ) ) {
  613. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_parent_id' AND " ;
  614. $q .= "shopper_group_id='$shopper_group_id' $volume_quantity_sql" ;
  615. $db->setQuery( $q ) ;
  616. $db->query() ;
  617. if( $db->next_record() ) {
  618. $price_info["product_price"] = $db->f( "product_price" ) ;
  619. if( $check_multiple_prices ) {
  620. $price_info["product_base_price"] = $db->f( "product_price" ) ;
  621. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1 ;
  622. }
  623. $price_info["product_price_id"] = $db->f( "product_price_id" ) ;
  624. $price_info["product_currency"] = $db->f( "product_currency" ) ;
  625. $GLOBALS['product_info'][$product_id]['price'] = $price_info ;
  626. return $GLOBALS['product_info'][$product_id]['price'] ;
  627. }
  628. }
  629. $q = "SELECT product_price, product_price_id, product_currency FROM #__{vm}_product_price WHERE product_id='$product_parent_id' AND " ;
  630. $q .= "shopper_group_id='$default_shopper_group_id' $volume_quantity_sql" ;
  631. $db->setQuery( $q ) ;
  632. $db->query() ;
  633. if( $db->next_record() ) {
  634. $price_info["product_price"] = $db->f( "product_price" ) * ((100 - $shopper_group_discount) / 100) ;
  635. if( $check_multiple_prices ) {
  636. $price_info["product_base_price"] = $price_info["product_price"] ;
  637. $price_info["product_has_multiple_prices"] = $db->num_rows() > 1 ;
  638. }
  639. $price_info["product_price_id"] = $db->f( "product_price_id" ) ;
  640. $price_info["product_currency"] = $db->f( "product_currency" ) ;
  641. $GLOBALS['product_info'][$product_id]['price'] = $price_info ;
  642. return $GLOBALS['product_info'][$product_id]['price'] ;
  643. }
  644. // No price found
  645. $GLOBALS['product_info'][$product_id]['price'] = false ;
  646. return $GLOBALS['product_info'][$product_id]['price'] ;
  647. } else {
  648. return $GLOBALS['product_info'][$product_id]['price'] ;
  649. }
  650. }
  651. /**************************************************************************
  652. * name: get_adjusted_attribute_price
  653. * created by: nfischer
  654. * description: Give the price of a product according to the attributes
  655. * parameters: $product_id, $quantity ,$description='', $result_attributes
  656. * returns: Price of the product
  657. **************************************************************************/
  658. function get_adjusted_attribute_price( $product_id, $quantity, $description = '', $result_attributes ) {
  659. global $mosConfig_secret ;
  660. $auth = $_SESSION['auth'] ;
  661. $price = $this->get_price( $product_id, $quantity, true, $result_attributes ) ;
  662. $base_price = $price["product_price"] ;
  663. $setprice = 0 ;
  664. $set_price = false ;
  665. $adjustment = 0 ;
  666. // We must care for custom attribute fields! Their value can be freely given
  667. // by the customer, so we mustn't include them into the price calculation
  668. // Thanks to AryGroup@ua.fm for the good advice
  669. //***********************
  670. //***********************
  671. //***********************
  672. //***********************
  673. // A VOIR
  674. //***********************
  675. //***********************
  676. //***********************
  677. //***********************
  678. if( empty( $_REQUEST["custom_attribute_fields"] ) ) {
  679. if( ! empty( $_SESSION["custom_attribute_fields"] ) ) {
  680. $custom_attribute_fields = vmGet( $_SESSION, "custom_attribute_fields", Array() ) ;
  681. $custom_attribute_fields_check = vmGet( $_SESSION, "custom_attribute_fields_check", Array() ) ;
  682. } else
  683. $custom_attribute_fields = $custom_attribute_fields_check = Array() ;
  684. } else {
  685. $custom_attribute_fields = $_SESSION["custom_attribute_fields"] = vmGet( $_REQUEST, "custom_attribute_fields", Array() ) ;
  686. $custom_attribute_fields_check = $_SESSION["custom_attribute_fields_check"] = vmGet( $_REQUEST, "custom_attribute_fields_check", Array() ) ;
  687. }
  688. //***********************
  689. //***********************
  690. //***********************
  691. //***********************
  692. // A VOIR
  693. //***********************
  694. //***********************
  695. //***********************
  696. //***********************
  697. // if we've been given a description to deal with, get the adjusted price
  698. if( $description != '' ) { // description is safe to use at this point cause it's set to ''
  699. $attribute_keys = explode( ";", $description ) ;
  700. foreach( $attribute_keys as $temp_desc ) {
  701. $temp_desc = trim( $temp_desc ) ;
  702. // Get the key name (e.g. "Color" )
  703. $this_key = substr( $temp_desc, 0, strpos( $temp_desc, ":" ) ) ;
  704. if( in_array( $this_key, $custom_attribute_fields ) ) {
  705. if( @$custom_attribute_fields_check[$this_key] == md5( $mosConfig_secret . $this_key ) ) {
  706. // the passed value is valid, don't use it for calculating prices
  707. continue ;
  708. }
  709. }
  710. $i = 0 ;
  711. $start = strpos( $temp_desc, "[" ) ;
  712. $finish = strpos( $temp_desc, "]", $start ) ;
  713. $o = substr_count( $temp_desc, "[" ) ;
  714. $c = substr_count( $temp_desc, "]" ) ;
  715. //echo "open: $o<br>close: $c<br>\n";
  716. // check to see if we have a bracket
  717. if( True == is_int( $finish ) ) {
  718. $length = $finish - $start ;
  719. // We found a pair of brackets (price modifier?)
  720. if( $length > 1 ) {
  721. $my_mod = substr( $temp_desc, $start + 1, $length - 1 ) ;
  722. //echo "before: ".$my_mod."<br>\n";
  723. if( $o != $c ) { // skip the tests if we don't have to process the string
  724. if( $o < $c ) {
  725. $char = "]" ;
  726. $offset = $start ;
  727. } else {
  728. $char = "[" ;
  729. $offset = $finish ;
  730. }
  731. $s = substr_count( $my_mod, $char ) ;
  732. for( $r = 1 ; $r < $s ; $r ++ ) {
  733. $pos = strrpos( $my_mod, $char ) ;
  734. $my_mod = substr( $my_mod, $pos + 1 ) ;
  735. }
  736. }
  737. $oper = substr( $my_mod, 0, 1 ) ;
  738. $my_mod = substr( $my_mod, 1 ) ;
  739. // if we have a number, allow the adjustment
  740. if( true == is_numeric( $my_mod ) ) {
  741. // Now add or sub the modifier on
  742. if( $oper == "+" ) {
  743. $adjustment += $my_mod ;
  744. } else if( $oper == "-" ) {
  745. $adjustment -= $my_mod ;
  746. } else if( $oper == '=' ) {
  747. // NOTE: the +=, so if we have 2 sets they get added
  748. // this could be moded to say, if we have a set_price, then
  749. // calc the diff from the base price and start from there if we encounter
  750. // another set price... just a thought.
  751. $setprice += $my_mod ;
  752. $set_price = true ;
  753. }
  754. }
  755. $temp_desc = substr( $temp_desc, $finish + 1 ) ;
  756. $start = strpos( $temp_desc, "[" ) ;
  757. $finish = strpos( $temp_desc, "]" ) ;
  758. }
  759. }
  760. $i ++ ; // not necessary, but perhaps interesting? ;)
  761. }
  762. }
  763. // no set price was set from the attribs
  764. if( $set_price == false ) {
  765. $price["product_price"] = $base_price + $adjustment ;
  766. } else {
  767. // otherwise, set the price
  768. // add the base price to the price set in the attributes
  769. // then subtract the adjustment amount
  770. // we could also just add the set_price to the adjustment... not sure on that one.
  771. // $setprice += $adjustment;
  772. $setprice *= 1 - ($auth["shopper_group_discount"] / 100) ;
  773. $price["product_price"] = $setprice ;
  774. }
  775. // don't let negative prices get by, set to 0
  776. if( $price["product_price"] < 0 ) {
  777. $price["product_price"] = 0 ;
  778. }
  779. // Get the DISCOUNT AMOUNT
  780. $ps_product = new ps_product( ) ;
  781. $discount_info = $ps_product->get_discount( $product_id ) ;
  782. $my_taxrate = $ps_product->get_product_taxrate( $product_id ) ;
  783. if( ! empty( $discount_info["amount"] ) ) {
  784. if( $auth["show_price_including_tax"] == 1 ) {
  785. switch( $discount_info["is_percent"]) {
  786. case 0 :
  787. $price["product_price"] = (($price["product_price"] * ($my_taxrate + 1)) - $discount_info["amount"]) / ($my_taxrate + 1) ;
  788. break ;
  789. //case 1: $price["product_price"] = ($price["product_price"]*($my_taxrate+1) - $discount_info["amount"]/100*$price["product_price"])/($my_taxrate+1); break;
  790. case 1 :
  791. $price["product_price"] = ($price["product_price"] - $discount_info["amount"] / 100 * $price["product_price"]) ;
  792. break ;
  793. }
  794. } else {
  795. switch( $discount_info["is_percent"]) {
  796. case 0 :
  797. $price["product_price"] = (($price["product_price"]) - $discount_info["amount"]) ;
  798. break ;
  799. case 1 :
  800. $price["product_price"] = ($price["product_price"] - ($discount_info["amount"] / 100) * $price["product_price"]) ;
  801. break ;
  802. }
  803. }
  804. }
  805. return $price ;
  806. }
  807. /**************************************************************************
  808. * name: change_product_item_price
  809. * created by: kaltokri
  810. * description: change product item price
  811. * parameters: none
  812. * returns: none
  813. **************************************************************************/
  814. function change_product_item_price() {
  815. require_once (CLASSPATH . 'ps_product.php') ;
  816. global $VM_LANG, $vmLogger ;
  817. $ps_product = new ps_product( ) ;
  818. $order_item_id = vmGet( $_REQUEST, 'order_item_id' ) ;
  819. $product_item_price_new = trim( vmGet( $_REQUEST, 'product_item_price' ) ) ;
  820. $product_final_price_new = trim( vmGet( $_REQUEST, 'product_final_price' ) ) ;
  821. $db = new ps_DB( ) ;
  822. $q = "SELECT product_id, product_quantity, product_final_price, product_item_price, product_final_price - product_item_price AS item_tax " ;
  823. $q .= "FROM #__{vm}_order_item WHERE order_id = '" . $this->order_id . "' " ;
  824. $q .= "AND order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  825. $db->query( $q ) ;
  826. $db->next_record() ;
  827. $product_id = $db->f( 'product_id' ) ;
  828. $timestamp = time() + ($mosConfig_offset * 60 * 60) ;
  829. $my_taxrate = $ps_product->get_product_taxrate( $product_id ) ;
  830. $product_item_price = $db->f( 'product_item_price' ) ;
  831. $product_final_price = $db->f( 'product_final_price' ) ;
  832. $quantity = $db->f( 'product_quantity' ) ;
  833. if( is_numeric( $product_item_price_new ) ) {
  834. $product_final_price_new = round( ($product_item_price_new * ($my_taxrate + 1)), 2 ) ;
  835. }
  836. $product_item_price_new = ($product_final_price_new / ($my_taxrate + 1)) ;
  837. $q = "UPDATE #__{vm}_order_item " ;
  838. $q .= "SET product_item_price = " . $product_item_price_new . ", " ;
  839. $q .= "product_final_price = " . $product_final_price_new . ", " ;
  840. $q .= "mdate = " . $timestamp . " " ;
  841. $q .= "WHERE order_item_id = '" . addslashes( $order_item_id ) . "'" ;
  842. $db->query( $q ) ;
  843. $db->next_record() ;
  844. $this->recalc_order( $this->order_id ) ;
  845. $this->reload_from_db = 1 ;
  846. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_PRINT_PRICE' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  847. }
  848. /**************************************************************************
  849. * name: change_payment
  850. * created by: kaltokri
  851. * description: Change payment
  852. **************************************************************************/
  853. function change_payment( $order_id, $new_payment_method_id ) {
  854. $db = new ps_DB( ) ;
  855. // Get the old payment_method_id to get payment_discount in next step
  856. $q = "SELECT * FROM #__{vm}_order_payment" ;
  857. $q .= " WHERE order_id = '" . $order_id . "'" ;
  858. $db->query( $q ) ;
  859. $old_payment_method_id = $db->f( 'payment_method_id' ) ;
  860. // Get the old payment_discount
  861. $q = "SELECT * FROM #__{vm}_payment_method" ;
  862. $q .= " WHERE payment_method_id = '" . $old_payment_method_id . "'" ;
  863. $db->query( $q ) ;
  864. $old_payment_discount = $db->f( 'payment_method_discount' ) ;
  865. // Get the new payment_dicount
  866. $q = "SELECT * FROM #__{vm}_payment_method" ;
  867. $q .= " WHERE payment_method_id = '" . $new_payment_method_id . "'" ;
  868. $db->query( $q ) ;
  869. $new_payment_discount = $db->f( 'payment_method_discount' ) ;
  870. // Update order_payment
  871. $q = "UPDATE #__{vm}_order_payment " ;
  872. $q .= "SET payment_method_id = '" . $new_payment_method_id . "'" ;
  873. $q .= "WHERE order_id = '" . $order_id . "'" ;
  874. $db->query( $q ) ;
  875. $db->next_record() ;
  876. // Get the old order_discount
  877. $q = "SELECT * FROM #__{vm}_orders" ;
  878. $q .= " WHERE order_id = '" . $order_id . "'" ;
  879. $db->query( $q ) ;
  880. $old_order_discount = $db->f( 'order_discount' ) ;
  881. // Update order
  882. $q = "UPDATE #__{vm}_orders SET " ;
  883. $q .= "order_discount = order_discount + " . $new_payment_discount . " - " . $old_payment_discount ;
  884. $q .= " WHERE order_id = '" . $order_id . "'" ;
  885. $db->query( $q ) ;
  886. $db->next_record() ;
  887. $this->recalc_order( $order_id ) ;
  888. $this->reload_from_db = 1 ;
  889. }
  890. }
  891. if( vmGet( $_REQUEST, 'page' ) == 'order.order_print' ) {
  892. $ps_order_change = new ps_order_change( $order_id ) ;
  893. if( vmGet( $_REQUEST, 'change_bill_to' ) != '' )
  894. $ps_order_change->change_bill_to() ;
  895. elseif( vmGet( $_REQUEST, 'change_ship_to' ) != '' )
  896. $ps_order_change->change_ship_to() ;
  897. elseif( vmGet( $_REQUEST, 'change_customer_note' ) != '' )
  898. $ps_order_change->change_customer_note() ;
  899. elseif( vmGet( $_REQUEST, 'change_standard_shipping' ) != '' )
  900. $ps_order_change->change_standard_shipping() ;
  901. elseif( vmGet( $_REQUEST, 'change_shipping' ) != '' )
  902. $ps_order_change->change_shipping( $order_id, vmRequest::getFloat( 'order_shipping' ) );
  903. elseif( vmGet( $_REQUEST, 'change_shipping_tax' ) != '' )
  904. $ps_order_change->change_shipping_tax( $order_id, vmRequest::getFloat( 'order_shipping_tax' ) );
  905. elseif( vmGet( $_REQUEST, 'change_discount' ) != '' )
  906. if( $ps_order_change->change_discount( $order_id, trim( vmGet( $_REQUEST, 'order_discount' ) ) ) ) {
  907. $vmLogger->err( "Invalid Order Item ID!" ) ;
  908. } else {
  909. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_COUPON_DISCOUNT' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  910. }
  911. elseif( vmGet( $_REQUEST, 'change_coupon_discount' ) != '' )
  912. if( $ps_order_change->change_coupon_discount( $order_id, trim( vmGet( $_REQUEST, 'coupon_discount' ) ) ) ) {
  913. $vmLogger->err( "Discount is not a number!" ) ;
  914. } else {
  915. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_COUPON_DISCOUNT' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  916. }
  917. elseif( vmGet( $_REQUEST, 'change_delete_item' ) != '' )
  918. if( $ps_order_change->change_delete_item( $order_id, vmGet( $_REQUEST, 'order_item_id' ) ) ) {
  919. $vmLogger->err( "Discount is not a number!" ) ;
  920. } else {
  921. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_PRODUCT_DELETED' ) ) ;
  922. }
  923. elseif( vmGet( $_REQUEST, 'change_item_quantity' ) != '' )
  924. if( $ps_order_change->change_item_quantity( $order_id, vmGet( $_REQUEST, 'order_item_id' ), trim( vmGet( $_REQUEST, 'product_quantity' ) ) ) ) {
  925. $vmLogger->err( $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_ERROR_QUANTITY_MUST_BE_HIGHER_THAN_0' ) ) ;
  926. } else {
  927. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_QUANTITY_UPDATED' ) ) ;
  928. }
  929. elseif( vmGet( $_REQUEST, 'add_product' ) != '' )
  930. $ps_order_change->add_product() ;
  931. elseif( vmGet( $_REQUEST, 'change_product_item_price' ) != '' )
  932. $ps_order_change->change_product_item_price() ;
  933. elseif( vmGet( $_REQUEST, 'change_product_final_price' ) != '' )
  934. $ps_order_change->change_product_item_price() ;
  935. elseif( vmGet( $_REQUEST, 'change_payment' ) != '' )
  936. if( $ps_order_change->change_payment( $order_id, vmGet( $_REQUEST, 'new_payment_id' ) ) ) {
  937. } else {
  938. $vmLogger->info( $VM_LANG->_( 'PHPSHOP_PAYMENT' ) . $VM_LANG->_( 'PHPSHOP_ORDER_EDIT_SOMETHING_HAS_CHANGED' ) ) ;
  939. }
  940. if( $ps_order_change->reload_from_db ) {
  941. $q = "SELECT * FROM #__{vm}_orders WHERE order_id='$order_id'" ;
  942. $db->query( $q ) ;
  943. $db->next_record() ;
  944. }
  945. }
  946. ?>