  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: order.php 443 2006-02-19 23:01:01Z hpdl $ |
| |
| 3 | + | $Id: order.php 554 2006-04-29 16:26:53Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2005 osCommerce |
| |
| 8 | + | Copyright (c) 2006 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
  |
13 | | - | class order { |
| |
| 13 | + | class osC_Order { |
|
14 | 14 | | var $info, $totals, $products, $customer, $delivery, $content_type; |
| |
15 | 15 | | |
| |
16 | 16 | | /* Private variables */ |
| |
|
|
 |
… |
|
19 | 19 | | |
| |
20 | 20 | | /* Class constructor */ |
| |
21 | 21 | | |
  |
22 | | - | function order($order_id = '') { |
| |
| 22 | + | function osC_Order($order_id = '') { |
|
23 | 23 | | if (is_numeric($order_id)) { |
| |
24 | 24 | | $this->_id = $order_id; |
| |
25 | 25 | | } |
| |
|
|
 |
… |
|
39 | 39 | | |
| |
40 | 40 | | /* Public methods */ |
| |
41 | 41 | | |
  |
| 42 | + | function getStatusID($id) { |
| |
| 43 | + | global $osC_Database; |
| |
| 44 | + | |
| |
| 45 | + | $Qorder = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id'); |
| |
| 46 | + | $Qorder->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 47 | + | $Qorder->bindInt(':orders_id', $id); |
| |
| 48 | + | $Qorder->execute(); |
| |
| 49 | + | |
| |
| 50 | + | if ($Qorder->numberOfRows()) { |
| |
| 51 | + | return $Qorder->valueInt('orders_status'); |
| |
| 52 | + | } |
| |
| 53 | + | |
| |
| 54 | + | return false; |
| |
| 55 | + | } |
| |
| 56 | + | |
| |
| 57 | + | function remove($id) { |
| |
| 58 | + | global $osC_Database; |
| |
| 59 | + | |
| |
| 60 | + | $Qcheck = $osC_Database->query('select orders_status from :table_orders where orders_id = :orders_id'); |
| |
| 61 | + | $Qcheck->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 62 | + | $Qcheck->bindInt(':orders_id', $id); |
| |
| 63 | + | $Qcheck->execute(); |
| |
| 64 | + | |
| |
| 65 | + | if ($Qcheck->valueInt('orders_status') === 4) { |
| |
| 66 | + | $Qdel = $osC_Database->query('delete from :table_orders_products_download where orders_id = :orders_id'); |
| |
| 67 | + | $Qdel->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD); |
| |
| 68 | + | $Qdel->bindInt(':orders_id', $id); |
| |
| 69 | + | $Qdel->execute(); |
| |
| 70 | + | |
| |
| 71 | + | $Qdel = $osC_Database->query('delete from :table_orders_products_attributes where orders_id = :orders_id'); |
| |
| 72 | + | $Qdel->bindTable(':table_orders_products_aattributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES); |
| |
| 73 | + | $Qdel->bindInt(':orders_id', $id); |
| |
| 74 | + | $Qdel->execute(); |
| |
| 75 | + | |
| |
| 76 | + | $Qdel = $osC_Database->query('delete from :table_orders_products where orders_id = :orders_id'); |
| |
| 77 | + | $Qdel->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); |
| |
| 78 | + | $Qdel->bindInt(':orders_id', $id); |
| |
| 79 | + | $Qdel->execute(); |
| |
| 80 | + | |
| |
| 81 | + | $Qdel = $osC_Database->query('delete from :table_orders_status_history where orders_id = :orders_id'); |
| |
| 82 | + | $Qdel->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY); |
| |
| 83 | + | $Qdel->bindInt(':orders_id', $id); |
| |
| 84 | + | $Qdel->execute(); |
| |
| 85 | + | |
| |
| 86 | + | $Qdel = $osC_Database->query('delete from :table_orders_total where orders_id = :orders_id'); |
| |
| 87 | + | $Qdel->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL); |
| |
| 88 | + | $Qdel->bindInt(':orders_id', $id); |
| |
| 89 | + | $Qdel->execute(); |
| |
| 90 | + | |
| |
| 91 | + | $Qdel = $osC_Database->query('delete from :table_orders where orders_id = :orders_id'); |
| |
| 92 | + | $Qdel->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 93 | + | $Qdel->bindInt(':orders_id', $id); |
| |
| 94 | + | $Qdel->execute(); |
| |
| 95 | + | } |
| |
| 96 | + | |
| |
| 97 | + | if (isset($_SESSION['prepOrderID'])) { |
| |
| 98 | + | unset($_SESSION['prepOrderID']); |
| |
| 99 | + | } |
| |
| 100 | + | } |
| |
| 101 | + | |
| |
| 102 | + | function insert() { |
| |
| 103 | + | global $osC_Database, $osC_Customer, $osC_Language, $osC_Currencies, $osC_ShoppingCart; |
| |
| 104 | + | |
| |
| 105 | + | if (isset($_SESSION['prepOrderID'])) { |
| |
| 106 | + | $_prep = explode('-', $_SESSION['prepOrderID']); |
| |
| 107 | + | |
| |
| 108 | + | if ($_prep[0] == $osC_ShoppingCart->getCartID()) { |
| |
| 109 | + | return $_prep[1]; // order_id |
| |
| 110 | + | } else { |
| |
| 111 | + | if (osC_Order::getStatusID($_prep[1]) === 4) { |
| |
| 112 | + | osC_Order::remove($_prep[1]); |
| |
| 113 | + | } |
| |
| 114 | + | } |
| |
| 115 | + | } |
| |
| 116 | + | |
| |
| 117 | + | $Qorder = $osC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_country, customers_telephone, customers_email_address, customers_address_format_id, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_country, delivery_address_format_id, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_country, billing_address_format_id, payment_method, payment_module, cc_type, cc_owner, cc_number, cc_expires, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_country, :customers_telephone, :customers_email_address, :customers_address_format_id, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_country, :delivery_address_format_id, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_country, :billing_address_format_id, :payment_method, :payment_module, :cc_type, :cc_owner, :cc_number, :cc_expires, now(), :orders_status, :currency, :currency_value)'); |
| |
| 118 | + | $Qorder->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 119 | + | $Qorder->bindInt(':customers_id', $osC_Customer->getID()); |
| |
| 120 | + | $Qorder->bindValue(':customers_name', $osC_Customer->getName()); |
| |
| 121 | + | $Qorder->bindValue(':customers_company', '' /*$order->customer['company']*/); |
| |
| 122 | + | $Qorder->bindValue(':customers_street_address', '' /*$order->customer['street_address']*/); |
| |
| 123 | + | $Qorder->bindValue(':customers_suburb', '' /*$order->customer['suburb']*/); |
| |
| 124 | + | $Qorder->bindValue(':customers_city', '' /*$order->customer['city']*/); |
| |
| 125 | + | $Qorder->bindValue(':customers_postcode', '' /*$order->customer['postcode']*/); |
| |
| 126 | + | $Qorder->bindValue(':customers_state', '' /*$order->customer['state']*/); |
| |
| 127 | + | $Qorder->bindValue(':customers_country', '' /*$order->customer['country']['title']*/); |
| |
| 128 | + | $Qorder->bindValue(':customers_telephone', '' /*$order->customer['telephone']*/); |
| |
| 129 | + | $Qorder->bindValue(':customers_email_address', $osC_Customer->getEmailAddress()); |
| |
| 130 | + | $Qorder->bindInt(':customers_address_format_id', $osC_Customer->getDefaultAddressID()); |
| |
| 131 | + | $Qorder->bindValue(':customers_ip_address', tep_get_ip_address()); |
| |
| 132 | + | $Qorder->bindValue(':delivery_name', $osC_ShoppingCart->getShippingAddress('firstname') . ' ' . $osC_ShoppingCart->getShippingAddress('lastname')); |
| |
| 133 | + | $Qorder->bindValue(':delivery_company', $osC_ShoppingCart->getShippingAddress('company')); |
| |
| 134 | + | $Qorder->bindValue(':delivery_street_address', $osC_ShoppingCart->getShippingAddress('street_address')); |
| |
| 135 | + | $Qorder->bindValue(':delivery_suburb', $osC_ShoppingCart->getShippingAddress('suburb')); |
| |
| 136 | + | $Qorder->bindValue(':delivery_city', $osC_ShoppingCart->getShippingAddress('city')); |
| |
| 137 | + | $Qorder->bindValue(':delivery_postcode', $osC_ShoppingCart->getShippingAddress('postcode')); |
| |
| 138 | + | $Qorder->bindValue(':delivery_state', $osC_ShoppingCart->getShippingAddress('state')); |
| |
| 139 | + | $Qorder->bindValue(':delivery_country', $osC_ShoppingCart->getShippingAddress('country_title')); |
| |
| 140 | + | $Qorder->bindInt(':delivery_address_format_id', $osC_ShoppingCart->getShippingAddress('format_id')); |
| |
| 141 | + | $Qorder->bindValue(':billing_name', $osC_ShoppingCart->getBillingAddress('firstname') . ' ' . $osC_ShoppingCart->getBillingAddress('lastname')); |
| |
| 142 | + | $Qorder->bindValue(':billing_company', $osC_ShoppingCart->getBillingAddress('company')); |
| |
| 143 | + | $Qorder->bindValue(':billing_street_address', $osC_ShoppingCart->getBillingAddress('street_address')); |
| |
| 144 | + | $Qorder->bindValue(':billing_suburb', $osC_ShoppingCart->getBillingAddress('suburb')); |
| |
| 145 | + | $Qorder->bindValue(':billing_city', $osC_ShoppingCart->getBillingAddress('city')); |
| |
| 146 | + | $Qorder->bindValue(':billing_postcode', $osC_ShoppingCart->getBillingAddress('postcode')); |
| |
| 147 | + | $Qorder->bindValue(':billing_state', $osC_ShoppingCart->getBillingAddress('state')); |
| |
| 148 | + | $Qorder->bindValue(':billing_country', $osC_ShoppingCart->getBillingAddress('country_title')); |
| |
| 149 | + | $Qorder->bindInt(':billing_address_format_id', $osC_ShoppingCart->getBillingAddress('format_id')); |
| |
| 150 | + | $Qorder->bindValue(':payment_method', $osC_ShoppingCart->getBillingMethod('title')); |
| |
| 151 | + | $Qorder->bindValue(':payment_module', $GLOBALS['osC_Payment_' . $osC_ShoppingCart->getBillingMethod('id')]->getCode()); |
| |
| 152 | + | $Qorder->bindValue(':cc_type', '' /*$order->info['cc_type']*/); |
| |
| 153 | + | $Qorder->bindValue(':cc_owner', '' /*$order->info['cc_owner']*/); |
| |
| 154 | + | $Qorder->bindValue(':cc_number', '' /*$order->info['cc_number']*/); |
| |
| 155 | + | $Qorder->bindValue(':cc_expires', '' /*$order->info['cc_expires']*/); |
| |
| 156 | + | $Qorder->bindInt(':orders_status', 4); |
| |
| 157 | + | $Qorder->bindValue(':currency', $osC_Currencies->getCode()); |
| |
| 158 | + | $Qorder->bindValue(':currency_value', $osC_Currencies->value($osC_Currencies->getCode())); |
| |
| 159 | + | $Qorder->execute(); |
| |
| 160 | + | |
| |
| 161 | + | $insert_id = $osC_Database->nextID(); |
| |
| 162 | + | |
| |
| 163 | + | foreach ($osC_ShoppingCart->getOrderTotals() as $module) { |
| |
| 164 | + | $Qtotals = $osC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)'); |
| |
| 165 | + | $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL); |
| |
| 166 | + | $Qtotals->bindInt(':orders_id', $insert_id); |
| |
| 167 | + | $Qtotals->bindValue(':title', $module['title']); |
| |
| 168 | + | $Qtotals->bindValue(':text', $module['text']); |
| |
| 169 | + | $Qtotals->bindValue(':value', $module['value']); |
| |
| 170 | + | $Qtotals->bindValue(':class', $module['code']); |
| |
| 171 | + | $Qtotals->bindInt(':sort_order', $module['sort_order']); |
| |
| 172 | + | $Qtotals->execute(); |
| |
| 173 | + | } |
| |
| 174 | + | |
| |
| 175 | + | $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)'); |
| |
| 176 | + | $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY); |
| |
| 177 | + | $Qstatus->bindInt(':orders_id', $insert_id); |
| |
| 178 | + | $Qstatus->bindInt(':orders_status_id', 4); |
| |
| 179 | + | $Qstatus->bindInt(':customer_notified', '0'); |
| |
| 180 | + | $Qstatus->bindValue(':comments', (isset($_SESSION['comments']) ? $_SESSION['comments'] : '')); |
| |
| 181 | + | $Qstatus->execute(); |
| |
| 182 | + | |
| |
| 183 | + | foreach ($osC_ShoppingCart->getProducts() as $products) { |
| |
| 184 | + | $Qproducts = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_name, products_price, final_price, products_tax, products_quantity) values (:orders_id, :products_id, :products_model, :products_name, :products_price, :final_price, :products_tax, :products_quantity)'); |
| |
| 185 | + | $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); |
| |
| 186 | + | $Qproducts->bindInt(':orders_id', $insert_id); |
| |
| 187 | + | $Qproducts->bindInt(':products_id', tep_get_prid($products['id'])); |
| |
| 188 | + | $Qproducts->bindValue(':products_model', '' /*$products['model']*/); |
| |
| 189 | + | $Qproducts->bindValue(':products_name', $products['name']); |
| |
| 190 | + | $Qproducts->bindValue(':products_price', $products['price']); |
| |
| 191 | + | $Qproducts->bindValue(':final_price', $products['final_price']); |
| |
| 192 | + | $Qproducts->bindValue(':products_tax', '' /*$products['tax']*/); |
| |
| 193 | + | $Qproducts->bindInt(':products_quantity', $products['quantity']); |
| |
| 194 | + | $Qproducts->execute(); |
| |
| 195 | + | |
| |
| 196 | + | $order_products_id = $osC_Database->nextID(); |
| |
| 197 | + | |
| |
| 198 | + | if ($osC_ShoppingCart->hasAttributes($products['id'])) { |
| |
| 199 | + | foreach ($osC_ShoppingCart->getAttributes($products['id']) as $attributes) { |
| |
| 200 | + | if (DOWNLOAD_ENABLED == '1') { |
| |
| 201 | + | $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id'); |
| |
| 202 | + | $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS); |
| |
| 203 | + | $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES); |
| |
| 204 | + | $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
| 205 | + | $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD); |
| |
| 206 | + | $Qattributes->bindInt(':products_id', $products['id']); |
| |
| 207 | + | $Qattributes->bindInt(':options_id', $attributes['options_id']); |
| |
| 208 | + | $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']); |
| |
| 209 | + | $Qattributes->bindInt(':popt_language_id', $osC_Language->getID()); |
| |
| 210 | + | $Qattributes->bindInt(':poval_language_id', $osC_Language->getID()); |
| |
| 211 | + | } else { |
| |
| 212 | + | $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id'); |
| |
| 213 | + | $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS); |
| |
| 214 | + | $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES); |
| |
| 215 | + | $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
| 216 | + | $Qattributes->bindInt(':products_id', $products['id']); |
| |
| 217 | + | $Qattributes->bindInt(':options_id', $attributes['options_id']); |
| |
| 218 | + | $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']); |
| |
| 219 | + | $Qattributes->bindInt(':popt_language_id', $osC_Language->getID()); |
| |
| 220 | + | $Qattributes->bindInt(':poval_language_id', $osC_Language->getID()); |
| |
| 221 | + | } |
| |
| 222 | + | $Qattributes->execute(); |
| |
| 223 | + | |
| |
| 224 | + | $Qopa = $osC_Database->query('insert into :table_orders_products_attributes (orders_id, orders_products_id, products_options, products_options_values, options_values_price, price_prefix) values (:orders_id, :orders_products_id, :products_options, :products_options_values, :options_values_price, :price_prefix)'); |
| |
| 225 | + | $Qopa->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES); |
| |
| 226 | + | $Qopa->bindInt(':orders_id', $insert_id); |
| |
| 227 | + | $Qopa->bindInt(':orders_products_id', $order_products_id); |
| |
| 228 | + | $Qopa->bindValue(':products_options', $Qattributes->value('products_options_name')); |
| |
| 229 | + | $Qopa->bindValue(':products_options_values', $Qattributes->value('products_options_values_name')); |
| |
| 230 | + | $Qopa->bindValue(':options_values_price', $Qattributes->value('options_values_price')); |
| |
| 231 | + | $Qopa->bindValue(':price_prefix', $Qattributes->value('price_prefix')); |
| |
| 232 | + | $Qopa->execute(); |
| |
| 233 | + | |
| |
| 234 | + | if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) { |
| |
| 235 | + | $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)'); |
| |
| 236 | + | $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD); |
| |
| 237 | + | $Qopd->bindInt(':orders_id', $insert_id); |
| |
| 238 | + | $Qopd->bindInt(':orders_products_id', $order_products_id); |
| |
| 239 | + | $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename')); |
| |
| 240 | + | $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays')); |
| |
| 241 | + | $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount')); |
| |
| 242 | + | $Qopd->execute(); |
| |
| 243 | + | } |
| |
| 244 | + | } |
| |
| 245 | + | } |
| |
| 246 | + | } |
| |
| 247 | + | |
| |
| 248 | + | $_SESSION['prepOrderID'] = $osC_ShoppingCart->getCartID() . '-' . $insert_id; |
| |
| 249 | + | |
| |
| 250 | + | return $insert_id; |
| |
| 251 | + | } |
| |
| 252 | + | |
| |
| 253 | + | function process($order_id, $status_id = '') { |
| |
| 254 | + | global $osC_Database; |
| |
| 255 | + | |
| |
| 256 | + | if (empty($status_id) || (is_numeric($status_id) === false)) { |
| |
| 257 | + | $status_id = DEFAULT_ORDERS_STATUS_ID; |
| |
| 258 | + | } |
| |
| 259 | + | |
| |
| 260 | + | $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)'); |
| |
| 261 | + | $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY); |
| |
| 262 | + | $Qstatus->bindInt(':orders_id', $order_id); |
| |
| 263 | + | $Qstatus->bindInt(':orders_status_id', $status_id); |
| |
| 264 | + | $Qstatus->bindInt(':customer_notified', (SEND_EMAILS == '1') ? '1' : '0'); |
| |
| 265 | + | $Qstatus->bindValue(':comments', ''); |
| |
| 266 | + | $Qstatus->execute(); |
| |
| 267 | + | |
| |
| 268 | + | $Qupdate = $osC_Database->query('update :table_orders set orders_status = :orders_status where orders_id = :orders_id'); |
| |
| 269 | + | $Qupdate->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 270 | + | $Qupdate->bindInt(':orders_status', $status_id); |
| |
| 271 | + | $Qupdate->bindInt(':orders_id', $order_id); |
| |
| 272 | + | $Qupdate->execute(); |
| |
| 273 | + | |
| |
| 274 | + | $Qproducts = $osC_Database->query('select products_id, products_quantity from :table_orders_products where orders_id = :orders_id'); |
| |
| 275 | + | $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); |
| |
| 276 | + | $Qproducts->bindInt(':orders_id', $order_id); |
| |
| 277 | + | $Qproducts->execute(); |
| |
| 278 | + | |
| |
| 279 | + | while ($Qproducts->next()) { |
| |
| 280 | + | if (STOCK_LIMITED == '1') { |
| |
| 281 | + | |
| |
| 282 | + | /********** HPDL ; still uses logic from the shopping cart class |
| |
| 283 | + | if (DOWNLOAD_ENABLED == '1') { |
| |
| 284 | + | $Qstock = $osC_Database->query('select products_quantity, pad.products_attributes_filename from :table_products p left join :table_products_attributes pa on (p.products_id = pa.products_id) left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where p.products_id = :products_id'); |
| |
| 285 | + | $Qstock->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 286 | + | $Qstock->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
| 287 | + | $Qstock->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD); |
| |
| 288 | + | $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id')); |
| |
| 289 | + | |
| |
| 290 | + | // Will work with only one option for downloadable products otherwise, we have to build the query dynamically with a loop |
| |
| 291 | + | if ($osC_ShoppingCart->hasAttributes($products['id'])) { |
| |
| 292 | + | $products_attributes = $osC_ShoppingCart->getAttributes($products['id']); |
| |
| 293 | + | $products_attributes = array_shift($products_attributes); |
| |
| 294 | + | |
| |
| 295 | + | $Qstock->appendQuery('and pa.options_id = :options_id and pa.options_values_id = :options_values_id'); |
| |
| 296 | + | $Qstock->bindInt(':options_id', $products_attributes['options_id']); |
| |
| 297 | + | $Qstock->bindInt(':options_values_id', $products_attributes['options_values_id']); |
| |
| 298 | + | } |
| |
| 299 | + | } else { |
| |
| 300 | + | ************/ |
| |
| 301 | + | $Qstock = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id'); |
| |
| 302 | + | $Qstock->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 303 | + | $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id')); |
| |
| 304 | + | // HPDL } |
| |
| 305 | + | |
| |
| 306 | + | $Qstock->execute(); |
| |
| 307 | + | |
| |
| 308 | + | if ($Qstock->numberOfRows() > 0) { |
| |
| 309 | + | $stock_left = $Qstock->valueInt('products_quantity'); |
| |
| 310 | + | |
| |
| 311 | + | // do not decrement quantities if products_attributes_filename exists |
| |
| 312 | + | // HPDL if ((DOWNLOAD_ENABLED == '-1') || ((DOWNLOAD_ENABLED == '1') && (strlen($Qstock->value('products_attributes_filename')) < 1))) { |
| |
| 313 | + | $stock_left = $stock_left - $Qproducts->valueInt('products_quantity'); |
| |
| 314 | + | |
| |
| 315 | + | $Qupdate = $osC_Database->query('update :table_products set products_quantity = :products_quantity where products_id = :products_id'); |
| |
| 316 | + | $Qupdate->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 317 | + | $Qupdate->bindInt(':products_quantity', $stock_left); |
| |
| 318 | + | $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id')); |
| |
| 319 | + | $Qupdate->execute(); |
| |
| 320 | + | // HPDL } |
| |
| 321 | + | |
| |
| 322 | + | if ((STOCK_ALLOW_CHECKOUT == '-1') && ($stock_left < 1)) { |
| |
| 323 | + | $Qupdate = $osC_Database->query('update :table_products set products_status = 0 where products_id = :products_id'); |
| |
| 324 | + | $Qupdate->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 325 | + | $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id')); |
| |
| 326 | + | $Qupdate->execute(); |
| |
| 327 | + | } |
| |
| 328 | + | } |
| |
| 329 | + | } |
| |
| 330 | + | |
| |
| 331 | + | // Update products_ordered (for bestsellers list) |
| |
| 332 | + | $Qupdate = $osC_Database->query('update :table_products set products_ordered = products_ordered + :products_ordered where products_id = :products_id'); |
| |
| 333 | + | $Qupdate->bindTable(':table_products', TABLE_PRODUCTS); |
| |
| 334 | + | $Qupdate->bindInt(':products_ordered', $Qproducts->valueInt('products_quantity')); |
| |
| 335 | + | $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id')); |
| |
| 336 | + | $Qupdate->execute(); |
| |
| 337 | + | } |
| |
| 338 | + | |
| |
| 339 | + | osC_Order::sendEmail($order_id); |
| |
| 340 | + | |
| |
| 341 | + | unset($_SESSION['prepOrderID']); |
| |
| 342 | + | } |
| |
| 343 | + | |
| |
| 344 | + | function sendEmail($id) { |
| |
| 345 | + | global $osC_Database, $osC_Language, $osC_Currencies; |
| |
| 346 | + | |
| |
| 347 | + | $Qorder = $osC_Database->query('select * from :table_orders where orders_id = :orders_id limit 1'); |
| |
| 348 | + | $Qorder->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 349 | + | $Qorder->bindInt(':orders_id', $id); |
| |
| 350 | + | $Qorder->execute(); |
| |
| 351 | + | |
| |
| 352 | + | if ($Qorder->numberOfRows() === 1) { |
| |
| 353 | + | $email_order = STORE_NAME . "\n" . |
| |
| 354 | + | $osC_Language->get('email_order_separator') . "\n" . |
| |
| 355 | + | sprintf($osC_Language->get('email_order_order_number'), $id) . "\n" . |
| |
| 356 | + | sprintf($osC_Language->get('email_order_invoice_url'), tep_href_link(FILENAME_ACCOUNT, 'orders=' . $id, 'SSL', false, true, true)) . "\n" . |
| |
| 357 | + | sprintf($osC_Language->get('email_order_date_ordered'), osC_DateTime::getLong()) . "\n\n" . |
| |
| 358 | + | $osC_Language->get('email_order_products') . "\n" . |
| |
| 359 | + | $osC_Language->get('email_order_separator') . "\n"; |
| |
| 360 | + | |
| |
| 361 | + | $Qproducts = $osC_Database->query('select orders_products_id, products_model, products_name, final_price, products_tax, products_quantity from :table_orders_products where orders_id = :orders_id order by orders_products_id'); |
| |
| 362 | + | $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); |
| |
| 363 | + | $Qproducts->bindInt(':orders_id', $id); |
| |
| 364 | + | $Qproducts->execute(); |
| |
| 365 | + | |
| |
| 366 | + | while ($Qproducts->next()) { |
| |
| 367 | + | $email_order .= $Qproducts->valueInt('products_quantity') . ' x ' . $Qproducts->value('products_name') . ' (' . $Qproducts->value('products_model') . ') = ' . $osC_Currencies->displayPriceWithTaxRate($Qproducts->value('final_price'), $Qproducts->value('products_tax'), $Qproducts->valueInt('products_quantity'), $Qorder->value('currency'), $Qorder->value('currency_value')) . "\n"; |
| |
| 368 | + | |
| |
| 369 | + | $Qattributes = $osC_Database->query('select products_options, products_options_values from :table_orders_products_attributes where orders_id = :orders_id and orders_products_id = :orders_products_id order by orders_products_attributes_id'); |
| |
| 370 | + | $Qattributes->bindTable(':table_orders_products_attributes', TABLE_ORDERS_PRODUCTS_ATTRIBUTES); |
| |
| 371 | + | $Qattributes->bindInt(':orders_id', $id); |
| |
| 372 | + | $Qattributes->bindInt(':orders_products_id', $Qproducts->valueInt('orders_products_id')); |
| |
| 373 | + | $Qattributes->execute(); |
| |
| 374 | + | |
| |
| 375 | + | while ($Qattributes->next()) { |
| |
| 376 | + | $email_order .= "\t" . $Qattributes->value('products_options') . ': ' . $Qattributes->value('products_options_values') . "\n"; |
| |
| 377 | + | } |
| |
| 378 | + | } |
| |
| 379 | + | |
| |
| 380 | + | unset($Qproducts); |
| |
| 381 | + | unset($Qattributes); |
| |
| 382 | + | |
| |
| 383 | + | $email_order .= $osC_Language->get('email_order_separator') . "\n"; |
| |
| 384 | + | |
| |
| 385 | + | $Qtotals = $osC_Database->query('select title, text from :table_orders_total where orders_id = :orders_id order by sort_order'); |
| |
| 386 | + | $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL); |
| |
| 387 | + | $Qtotals->bindInt(':orders_id', $id); |
| |
| 388 | + | $Qtotals->execute(); |
| |
| 389 | + | |
| |
| 390 | + | while ($Qtotals->next()) { |
| |
| 391 | + | $email_order .= strip_tags($Qtotals->value('title') . ' ' . $Qtotals->value('text')) . "\n"; |
| |
| 392 | + | } |
| |
| 393 | + | |
| |
| 394 | + | unset($Qtotals); |
| |
| 395 | + | |
| |
| 396 | + | if ( (osc_empty($Qorder->value('delivery_name') === false)) && (osc_empty($Qorder->value('street_address') === false)) ) { |
| |
| 397 | + | $address = array('name' => $Qorder->value('delivery_name'), |
| |
| 398 | + | 'company' => $Qorder->value('delivery_company'), |
| |
| 399 | + | 'street_address' => $Qorder->value('delivery_street_address'), |
| |
| 400 | + | 'suburb' => $Qorder->value('delivery_suburb'), |
| |
| 401 | + | 'city' => $Qorder->value('delivery_city'), |
| |
| 402 | + | 'state' => $Qorder->value('delivery_state'), |
| |
| 403 | + | 'country' => $Qorder->value('delivery_country'), |
| |
| 404 | + | 'postcode' => $Qorder->value('delivery_postcode')); |
| |
| 405 | + | |
| |
| 406 | + | $email_order .= "\n" . $osC_Language->get('email_order_delivery_address') . "\n" . |
| |
| 407 | + | $osC_Language->get('email_order_separator') . "\n" . |
| |
| 408 | + | tep_address_format($Qorder->valueInt('delivery_address_format_id'), $address, false, '', "\n") . "\n"; |
| |
| 409 | + | |
| |
| 410 | + | unset($address); |
| |
| 411 | + | } |
| |
| 412 | + | |
| |
| 413 | + | $address = array('name' => $Qorder->value('billing_name'), |
| |
| 414 | + | 'company' => $Qorder->value('billing_company'), |
| |
| 415 | + | 'street_address' => $Qorder->value('billing_street_address'), |
| |
| 416 | + | 'suburb' => $Qorder->value('billing_suburb'), |
| |
| 417 | + | 'city' => $Qorder->value('billing_city'), |
| |
| 418 | + | 'state' => $Qorder->value('billing_state'), |
| |
| 419 | + | 'country' => $Qorder->value('billing_country'), |
| |
| 420 | + | 'postcode' => $Qorder->value('billing_postcode')); |
| |
| 421 | + | |
| |
| 422 | + | $email_order .= "\n" . $osC_Language->get('email_order_billing_address') . "\n" . |
| |
| 423 | + | $osC_Language->get('email_order_separator') . "\n" . |
| |
| 424 | + | tep_address_format($Qorder->valueInt('billing_address_format_id'), $address, false, '', "\n") . "\n\n"; |
| |
| 425 | + | |
| |
| 426 | + | unset($address); |
| |
| 427 | + | |
| |
| 428 | + | $Qstatus = $osC_Database->query('select orders_status_name from :table_orders_status where orders_status_id = :orders_status_id and language_id = :language_id'); |
| |
| 429 | + | $Qstatus->bindTable(':table_orders_status', TABLE_ORDERS_STATUS); |
| |
| 430 | + | $Qstatus->bindInt(':orders_status_id', $Qorder->valueInt('orders_status')); |
| |
| 431 | + | $Qstatus->bindInt(':language_id', $osC_Language->getID()); |
| |
| 432 | + | $Qstatus->execute(); |
| |
| 433 | + | |
| |
| 434 | + | $email_order .= sprintf($osC_Language->get('email_order_status'), $Qstatus->value('orders_status_name')) . "\n" . |
| |
| 435 | + | $osC_Language->get('email_order_separator') . "\n"; |
| |
| 436 | + | |
| |
| 437 | + | unset($Qstatus); |
| |
| 438 | + | |
| |
| 439 | + | $Qstatuses = $osC_Database->query('select date_added, comments from :table_orders_status_history where orders_id = :orders_id and comments != "" order by orders_status_history_id'); |
| |
| 440 | + | $Qstatuses->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY); |
| |
| 441 | + | $Qstatuses->bindInt(':orders_id', $id); |
| |
| 442 | + | $Qstatuses->execute(); |
| |
| 443 | + | |
| |
| 444 | + | while ($Qstatuses->next()) { |
| |
| 445 | + | $email_order .= osC_DateTime::getLong($Qstatuses->value('date_added')) . "\n\t" . wordwrap(str_replace("\n", "\n\t", $Qstatuses->value('comments')), 60, "\n\t", 1) . "\n\n"; |
| |
| 446 | + | } |
| |
| 447 | + | |
| |
| 448 | + | unset($Qstatuses); |
| |
| 449 | + | |
| |
| 450 | + | // if (is_object($GLOBALS[$payment])) { |
| |
| 451 | + | // $email_order .= $osC_Language->get('email_order_payment_method') . "\n" . |
| |
| 452 | + | // $osC_Language->get('email_order_separator') . "\n"; |
| |
| 453 | + | |
| |
| 454 | + | // $email_order .= $osC_ShoppingCart->getBillingMethod('title') . "\n\n"; |
| |
| 455 | + | // if (isset($GLOBALS[$payment]->email_footer)) { |
| |
| 456 | + | // $email_order .= $GLOBALS[$payment]->email_footer . "\n\n"; |
| |
| 457 | + | // } |
| |
| 458 | + | // } |
| |
| 459 | + | |
| |
| 460 | + | tep_mail($Qorder->value('customers_name'), $Qorder->value('customers_email_address'), $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); |
| |
| 461 | + | |
| |
| 462 | + | // send emails to other people |
| |
| 463 | + | if (SEND_EXTRA_ORDER_EMAILS_TO != '') { |
| |
| 464 | + | tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, $osC_Language->get('email_order_subject'), $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS); |
| |
| 465 | + | } |
| |
| 466 | + | } |
| |
| 467 | + | |
| |
| 468 | + | unset($Qorder); |
| |
| 469 | + | } |
| |
| 470 | + | |
|
42 | 471 | | function &getListing($limit = null, $page_keyword = 'page') { |
| |
43 | 472 | | global $osC_Database, $osC_Customer, $osC_Language; |
| |
44 | 473 | | |
| |
|
|
 |
… |
|
124 | 553 | | return $Qproducts->valueInt('total'); |
| |
125 | 554 | | } |
| |
126 | 555 | | |
  |
| 556 | + | function exists($id, $customer_id = null) { |
| |
| 557 | + | global $osC_Database; |
|
127 | 558 | | |
  |
| 559 | + | $Qorder = $osC_Database->query('select orders_id from :table_orders where orders_id = :orders_id'); |
|
128 | 560 | | |
  |
| 561 | + | if (isset($customer_id) && is_numeric($customer_id)) { |
| |
| 562 | + | $Qorder->appendQuery('and customers_id = :customers_id'); |
| |
| 563 | + | $Qorder->bindInt(':customers_id', $customer_id); |
| |
| 564 | + | } |
| |
| 565 | + | |
| |
| 566 | + | $Qorder->appendQuery('limit 1'); |
| |
| 567 | + | $Qorder->bindTable(':table_orders', TABLE_ORDERS); |
| |
| 568 | + | $Qorder->bindInt(':orders_id', $id); |
| |
| 569 | + | $Qorder->execute(); |
| |
| 570 | + | |
| |
| 571 | + | return ($Qorder->numberOfRows() === 1); |
| |
| 572 | + | } |
| |
| 573 | + | |
|
129 | 574 | | function query($order_id) { |
| |
130 | 575 | | global $osC_Database, $osC_Language; |
| |
131 | 576 | | |
| |
|
|
 |
… |
|
255 | 700 | | $index++; |
| |
256 | 701 | | } |
| |
257 | 702 | | } |
  |
258 | | - | |
| |
259 | | - | function cart() { |
| |
260 | | - | global $osC_Database, $osC_ShoppingCart, $osC_Customer, $osC_Tax, $osC_Currencies, $osC_Language; |
| |
261 | | - | |
| |
262 | | - | $this->content_type = $osC_ShoppingCart->getContentType(); |
| |
263 | | - | |
| |
264 | | - | $shipping =& $_SESSION['shipping']; |
| |
265 | | - | $payment =& $_SESSION['payment']; |
| |
266 | | - | |
| |
267 | | - | $Qcustomer = $osC_Database->query('select c.customers_firstname, c.customers_lastname, c.customers_telephone, c.customers_email_address, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, co.countries_id, co.countries_name, co.countries_iso_code_2, co.countries_iso_code_3, co.address_format_id, ab.entry_state from :table_customers c, :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries co on (ab.entry_country_id = co.countries_id) where c.customers_id = :customers_id and ab.customers_id = :customers_id and c.customers_default_address_id = ab.address_book_id'); |
| |
268 | | - | $Qcustomer->bindTable(':table_customers', TABLE_CUSTOMERS); |
| |
269 | | - | $Qcustomer->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
270 | | - | $Qcustomer->bindTable(':table_zones', TABLE_ZONES); |
| |
271 | | - | $Qcustomer->bindTable(':table_countries', TABLE_COUNTRIES); |
| |
272 | | - | $Qcustomer->bindInt(':customers_id', $osC_Customer->getID()); |
| |
273 | | - | $Qcustomer->bindInt(':customers_id', $osC_Customer->getID()); |
| |
274 | | - | $Qcustomer->execute(); |
| |
275 | | - | |
| |
276 | | - | $Qshipping = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id'); |
| |
277 | | - | $Qshipping->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
278 | | - | $Qshipping->bindTable(':table_zones', TABLE_ZONES); |
| |
279 | | - | $Qshipping->bindTable(':table_countries', TABLE_COUNTRIES); |
| |
280 | | - | $Qshipping->bindInt(':customers_id', $osC_Customer->getID()); |
| |
281 | | - | $Qshipping->bindInt(':address_book_id', $_SESSION['sendto']); |
| |
282 | | - | $Qshipping->execute(); |
| |
283 | | - | |
| |
284 | | - | $Qbilling = $osC_Database->query('select ab.entry_firstname, ab.entry_lastname, ab.entry_company, ab.entry_street_address, ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id, c.countries_id, c.countries_name, c.countries_iso_code_2, c.countries_iso_code_3, c.address_format_id, ab.entry_state from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) left join :table_countries c on (ab.entry_country_id = c.countries_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id'); |
| |
285 | | - | $Qbilling->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
286 | | - | $Qbilling->bindTable(':table_zones', TABLE_ZONES); |
| |
287 | | - | $Qbilling->bindTable(':table_countries', TABLE_COUNTRIES); |
| |
288 | | - | $Qbilling->bindInt(':customers_id', $osC_Customer->getID()); |
| |
289 | | - | $Qbilling->bindInt(':address_book_id', $_SESSION['billto']); |
| |
290 | | - | $Qbilling->execute(); |
| |
291 | | - | |
| |
292 | | - | $Qtax = $osC_Database->query('select ab.entry_country_id, ab.entry_zone_id from :table_address_book ab left join :table_zones z on (ab.entry_zone_id = z.zone_id) where ab.customers_id = :customers_id and ab.address_book_id = :address_book_id'); |
| |
293 | | - | $Qtax->bindTable(':table_address_book', TABLE_ADDRESS_BOOK); |
| |
294 | | - | $Qtax->bindTable(':table_zones', TABLE_ZONES); |
| |
295 | | - | $Qtax->bindInt(':customers_id', $osC_Customer->getID()); |
| |
296 | | - | $Qtax->bindInt(':address_book_id', ($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto'])); |
| |
297 | | - | $Qtax->execute(); |
| |
298 | | - | |
| |
299 | | - | $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID, |
| |
300 | | - | 'currency' => $_SESSION['currency'], |
| |
301 | | - | 'currency_value' => $osC_Currencies->currencies[$_SESSION['currency']]['value'], |
| |
302 | | - | 'payment_method' => $payment, |
| |
303 | | - | 'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''), |
| |
304 | | - | 'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''), |
| |
305 | | - | 'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''), |
| |
306 | | - | 'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''), |
| |
307 | | - | 'shipping_method' => $shipping['title'], |
| |
308 | | - | 'shipping_cost' => $shipping['cost'], |
| |
309 | | - | 'subtotal' => 0, |
| |
310 | | - | 'tax' => 0, |
| |
311 | | - | 'tax_groups' => array(), |
| |
312 | | - | 'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : '')); |
| |
313 | | - | |
| |
314 | | - | if (isset($GLOBALS[$payment]) && is_object($GLOBALS[$payment])) { |
| |
315 | | - | $this->info['payment_method'] = $GLOBALS[$payment]->title; |
| |
316 | | - | |
| |
317 | | - | if ( isset($GLOBALS[$payment]->order_status) && is_numeric($GLOBALS[$payment]->order_status) && ($GLOBALS[$payment]->order_status > 0) ) { |
| |
318 | | - | $this->info['order_status'] = $GLOBALS[$payment]->order_status; |
| |
319 | | - | } |
| |
320 | | - | } |
| |
321 | | - | |
| |
322 | | - | $this->customer = array('firstname' => $Qcustomer->valueProtected('customers_firstname'), |
| |
323 | | - | 'lastname' => $Qcustomer->valueProtected('customers_lastname'), |
| |
324 | | - | 'company' => $Qcustomer->valueProtected('entry_company'), |
| |
325 | | - | 'street_address' => $Qcustomer->valueProtected('entry_street_address'), |
| |
326 | | - | 'suburb' => $Qcustomer->valueProtected('entry_suburb'), |
| |
327 | | - | 'city' => $Qcustomer->valueProtected('entry_city'), |
| |
328 | | - | 'postcode' => $Qcustomer->valueProtected('entry_postcode'), |
| |
329 | | - | 'state' => (tep_not_null($Qcustomer->valueProtected('entry_state')) ? $Qcustomer->valueProtected('entry_state') : $Qcustomer->valueProtected('zone_name')), |
| |
330 | | - | 'zone_id' => $Qcustomer->valueInt('entry_zone_id'), |
| |
331 | | - | 'country' => array('id' => $Qcustomer->valueInt('countries_id'), 'title' => $Qcustomer->value('countries_name'), 'iso_code_2' => $Qcustomer->value('countries_iso_code_2'), 'iso_code_3' => $Qcustomer->value('countries_iso_code_3')), |
| |
332 | | - | 'format_id' => $Qcustomer->valueInt('address_format_id'), |
| |
333 | | - | 'telephone' => $Qcustomer->valueProtected('customers_telephone'), |
| |
334 | | - | 'email_address' => $Qcustomer->valueProtected('customers_email_address')); |
| |
335 | | - | |
| |
336 | | - | $this->delivery = array('firstname' => $Qshipping->valueProtected('entry_firstname'), |
| |
337 | | - | 'lastname' => $Qshipping->valueProtected('entry_lastname'), |
| |
338 | | - | 'company' => $Qshipping->valueProtected('entry_company'), |
| |
339 | | - | 'street_address' => $Qshipping->valueProtected('entry_street_address'), |
| |
340 | | - | 'suburb' => $Qshipping->valueProtected('entry_suburb'), |
| |
341 | | - | 'city' => $Qshipping->valueProtected('entry_city'), |
| |
342 | | - | 'postcode' => $Qshipping->valueProtected('entry_postcode'), |
| |
343 | | - | 'state' => (tep_not_null($Qshipping->valueProtected('entry_state')) ? $Qshipping->valueProtected('entry_state') : $Qshipping->valueProtected('zone_name')), |
| |
344 | | - | 'zone_id' => $Qshipping->valueInt('entry_zone_id'), |
| |
345 | | - | 'country' => array('id' => $Qshipping->valueInt('countries_id'), 'title' => $Qshipping->value('countries_name'), 'iso_code_2' => $Qshipping->value('countries_iso_code_2'), 'iso_code_3' => $Qshipping->value('countries_iso_code_3')), |
| |
346 | | - | 'country_id' => $Qshipping->valueInt('entry_country_id'), |
| |
347 | | - | 'format_id' => $Qshipping->valueInt('address_format_id')); |
| |
348 | | - | |
| |
349 | | - | $this->billing = array('firstname' => $Qbilling->valueProtected('entry_firstname'), |
| |
350 | | - | 'lastname' => $Qbilling->valueProtected('entry_lastname'), |
| |
351 | | - | 'company' => $Qbilling->valueProtected('entry_company'), |
| |
352 | | - | 'street_address' => $Qbilling->valueProtected('entry_street_address'), |
| |
353 | | - | 'suburb' => $Qbilling->valueProtected('entry_suburb'), |
| |
354 | | - | 'city' => $Qbilling->valueProtected('entry_city'), |
| |
355 | | - | 'postcode' => $Qbilling->valueProtected('entry_postcode'), |
| |
356 | | - | 'state' => (tep_not_null($Qbilling->valueProtected('entry_state')) ? $Qbilling->valueProtected('entry_state') : $Qbilling->valueProtected('zone_name')), |
| |
357 | | - | 'zone_id' => $Qbilling->valueInt('entry_zone_id'), |
| |
358 | | - | 'country' => array('id' => $Qbilling->valueInt('countries_id'), 'title' => $Qbilling->value('countries_name'), 'iso_code_2' => $Qbilling->value('countries_iso_code_2'), 'iso_code_3' => $Qbilling->value('countries_iso_code_3')), |
| |
359 | | - | 'country_id' => $Qbilling->valueInt('entry_country_id'), |
| |
360 | | - | 'format_id' => $Qbilling->valueInt('address_format_id')); |
| |
361 | | - | |
| |
362 | | - | $index = 0; |
| |
363 | | - | $products = $osC_ShoppingCart->getProducts(); |
| |
364 | | - | for ($i=0, $n=sizeof($products); $i<$n; $i++) { |
| |
365 | | - | $this->products[$index] = array('qty' => $products[$i]['quantity'], |
| |
366 | | - | 'name' => $products[$i]['name'], |
| |
367 | | - | 'model' => $products[$i]['model'], |
| |
368 | | - | 'tax' => $osC_Tax->getTaxRate($products[$i]['tax_class_id'], $Qtax->valueInt('entry_country_id'), $Qtax->valueInt('entry_zone_id')), |
| |
369 | | - | 'tax_description' => $osC_Tax->getTaxRateDescription($products[$i]['tax_class_id'], $Qtax->valueInt('entry_country_id'), $Qtax->valueInt('entry_zone_id')), |
| |
370 | | - | 'tax_class_id' => $products[$i]['tax_class_id'], |
| |
371 | | - | 'price' => $products[$i]['price'], |
| |
372 | | - | 'final_price' => $products[$i]['price'] + $osC_ShoppingCart->getProductAttributesPriceTotal($products[$i]['id']), |
| |
373 | | - | 'weight' => $products[$i]['weight'], |
| |
374 | | - | 'id' => $products[$i]['id']); |
| |
375 | | - | |
| |
376 | | - | if ($products[$i]['attributes']) { |
| |
377 | | - | $subindex = 0; |
| |
378 | | - | reset($products[$i]['attributes']); |
| |
379 | | - | while (list($option, $value) = each($products[$i]['attributes'])) { |
| |
380 | | - | $Qattributes = $osC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :language_id and poval.language_id = :language_id'); |
| |
381 | | - | $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS); |
| |
382 | | - | $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES); |
| |
383 | | - | $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); |
| |
384 | | - | $Qattributes->bindInt(':products_id', $products[$i]['id']); |
| |
385 | | - | $Qattributes->bindInt(':options_id', $option); |
| |
386 | | - | $Qattributes->bindInt(':options_values_id', $value['value_id']); |
| |
387 | | - | $Qattributes->bindInt(':language_id', $osC_Language->getID()); |
| |
388 | | - | $Qattributes->bindInt(':language_id', $osC_Language->getID()); |
| |
389 | | - | $Qattributes->execute(); |
| |
390 | | - | |
| |
391 | | - | $this->products[$index]['attributes'][$subindex] = array('option' => $Qattributes->value('products_options_name'), |
| |
392 | | - | 'value' => $Qattributes->value('products_options_values_name'), |
| |
393 | | - | 'option_id' => $option, |
| |
394 | | - | 'value_id' => $value['value_id'], |
| |
395 | | - | 'prefix' => $Qattributes->value('price_prefix'), |
| |
396 | | - | 'price' => $Qattributes->value('options_values_price')); |
| |
397 | | - | |
| |
398 | | - | $subindex++; |
| |
399 | | - | } |
| |
400 | | - | } |
| |
401 | | - | |
| |
402 | | - | $shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']; |
| |
403 | | - | $this->info['subtotal'] += $shown_price; |
| |
404 | | - | |
| |
405 | | - | $products_tax = $this->products[$index]['tax']; |
| |
406 | | - | $products_tax_description = $this->products[$index]['tax_description']; |
| |
407 | | - | if (DISPLAY_PRICE_WITH_TAX == 'true') { |
| |
408 | | - | $this->info['tax'] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); |
| |
409 | | - | if (isset($this->info['tax_groups']["$products_tax_description"])) { |
| |
410 | | - | $this->info['tax_groups']["$products_tax_description"] += $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); |
| |
411 | | - | } else { |
| |
412 | | - | $this->info['tax_groups']["$products_tax_description"] = $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax))); |
| |
413 | | - | } |
| |
414 | | - | } else { |
| |
415 | | - | $this->info['tax'] += ($products_tax / 100) * $shown_price; |
| |
416 | | - | if (isset($this->info['tax_groups']["$products_tax_description"])) { |
| |
417 | | - | $this->info['tax_groups']["$products_tax_description"] += ($products_tax / 100) * $shown_price; |
| |
418 | | - | } else { |
| |
419 | | - | $this->info['tax_groups']["$products_tax_description"] = ($products_tax / 100) * $shown_price; |
| |
420 | | - | } |
| |
421 | | - | } |
| |
422 | | - | |
| |
423 | | - | $index++; |
| |
424 | | - | } |
| |
425 | | - | |
| |
426 | | - | if (DISPLAY_PRICE_WITH_TAX == 'true') { |
| |
427 | | - | $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost']; |
| |
428 | | - | } else { |
| |
429 | | - | $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost']; |
| |
430 | | - | } |
| |
431 | | - | } |
  |
432 | 703 | | } |
| |
433 | 704 | | ?> |