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

