[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/classes/ -> order.php (source)

   1  <?php
   2  /**

   3   * File contains the order-processing class ("order")

   4   *

   5   * @package classes

   6   * @copyright Copyright 2003-2006 Zen Cart Development Team

   7   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   8   * @version $Id: order.php 6534 2007-06-26 01:01:00Z drbyte $

   9   */
  10  /**

  11   * order class

  12   *

  13   * Handles all order-processing functions

  14   *

  15   * @package classes

  16   */
  17  if (!defined('IS_ADMIN_FLAG')) {
  18    die('Illegal Access');
  19  }
  20  class order extends base {
  21    var $info, $totals, $products, $customer, $delivery, $content_type, $email_low_stock, $products_ordered_attributes,
  22    $products_ordered, $products_ordered_email;
  23  
  24    function order($order_id = '') {
  25      $this->info = array();
  26      $this->totals = array();
  27      $this->products = array();
  28      $this->customer = array();
  29      $this->delivery = array();
  30  
  31      if (zen_not_null($order_id)) {
  32        $this->query($order_id);
  33      } else {
  34        $this->cart();
  35      }
  36    }
  37  
  38    function query($order_id) {
  39      global $db;
  40  
  41      $order_id = zen_db_prepare_input($order_id);
  42  
  43      $order_query = "select customers_id, customers_name, customers_company,
  44                           customers_street_address, customers_suburb, customers_city,
  45                           customers_postcode, customers_state, customers_country,
  46                           customers_telephone, customers_email_address, customers_address_format_id,
  47                           delivery_name, delivery_company, delivery_street_address, delivery_suburb,
  48                           delivery_city, delivery_postcode, delivery_state, delivery_country,
  49                           delivery_address_format_id, billing_name, billing_company,
  50                           billing_street_address, billing_suburb, billing_city, billing_postcode,
  51                           billing_state, billing_country, billing_address_format_id,
  52                           payment_method, payment_module_code, shipping_method, shipping_module_code,
  53                           coupon_code, cc_type, cc_owner, cc_number, cc_expires, currency, currency_value,
  54                           date_purchased, orders_status, last_modified, order_total, order_tax, ip_address
  55                          from " . TABLE_ORDERS . "
  56                          where orders_id = '" . (int)$order_id . "'";
  57  
  58      $order = $db->Execute($order_query);
  59  
  60      $totals_query = "select title, text, class
  61                           from " . TABLE_ORDERS_TOTAL . "
  62                           where orders_id = '" . (int)$order_id . "'
  63                           order by sort_order";
  64  
  65      $totals = $db->Execute($totals_query);
  66  
  67      while (!$totals->EOF) {
  68        $this->totals[] = array('title' => $totals->fields['title'],
  69                                'text' => $totals->fields['text'],
  70                                'class' => $totals->fields['class']);
  71        $totals->MoveNext();
  72      }
  73  
  74      $order_total_query = "select text, value
  75                               from " . TABLE_ORDERS_TOTAL . "
  76                               where orders_id = '" . (int)$order_id . "'
  77                               and class = 'ot_total'";
  78  
  79  
  80      $order_total = $db->Execute($order_total_query);
  81  
  82  
  83      $shipping_method_query = "select title, value
  84                                  from " . TABLE_ORDERS_TOTAL . "
  85                                  where orders_id = '" . (int)$order_id . "'
  86                                  and class = 'ot_shipping'";
  87  
  88  
  89      $shipping_method = $db->Execute($shipping_method_query);
  90  
  91      $order_status_query = "select orders_status_name
  92                               from " . TABLE_ORDERS_STATUS . "
  93                               where orders_status_id = '" . $order->fields['orders_status'] . "'
  94                               and language_id = '" . (int)$_SESSION['languages_id'] . "'";
  95  
  96      $order_status = $db->Execute($order_status_query);
  97  
  98      $this->info = array('currency' => $order->fields['currency'],
  99                          'currency_value' => $order->fields['currency_value'],
 100                          'payment_method' => $order->fields['payment_method'],
 101                          'payment_module_code' => $order->fields['payment_module_code'],
 102                          'shipping_method' => $order->fields['shipping_method'],
 103                          'shipping_module_code' => $order->fields['shipping_module_code'],
 104                          'coupon_code' => $order->fields['coupon_code'],
 105                          'cc_type' => $order->fields['cc_type'],
 106                          'cc_owner' => $order->fields['cc_owner'],
 107                          'cc_number' => $order->fields['cc_number'],
 108                          'cc_expires' => $order->fields['cc_expires'],
 109                          'date_purchased' => $order->fields['date_purchased'],
 110                          'orders_status' => $order_status->fields['orders_status_name'],
 111                          'last_modified' => $order->fields['last_modified'],
 112                          'total' => $order->fields['order_total'],
 113                          'tax' => $order->fields['order_tax'],
 114                          'ip_address' => $order->fields['ip_address']
 115                          );
 116  
 117      $this->customer = array('id' => $order->fields['customers_id'],
 118                              'name' => $order->fields['customers_name'],
 119                              'company' => $order->fields['customers_company'],
 120                              'street_address' => $order->fields['customers_street_address'],
 121                              'suburb' => $order->fields['customers_suburb'],
 122                              'city' => $order->fields['customers_city'],
 123                              'postcode' => $order->fields['customers_postcode'],
 124                              'state' => $order->fields['customers_state'],
 125                              'country' => $order->fields['customers_country'],
 126                              'format_id' => $order->fields['customers_address_format_id'],
 127                              'telephone' => $order->fields['customers_telephone'],
 128                              'email_address' => $order->fields['customers_email_address']);
 129  
 130      $this->delivery = array('name' => $order->fields['delivery_name'],
 131                              'company' => $order->fields['delivery_company'],
 132                              'street_address' => $order->fields['delivery_street_address'],
 133                              'suburb' => $order->fields['delivery_suburb'],
 134                              'city' => $order->fields['delivery_city'],
 135                              'postcode' => $order->fields['delivery_postcode'],
 136                              'state' => $order->fields['delivery_state'],
 137                              'country' => $order->fields['delivery_country'],
 138                              'format_id' => $order->fields['delivery_address_format_id']);
 139  
 140      if (empty($this->delivery['name']) && empty($this->delivery['street_address'])) {
 141        $this->delivery = false;
 142      }
 143  
 144      $this->billing = array('name' => $order->fields['billing_name'],
 145                             'company' => $order->fields['billing_company'],
 146                             'street_address' => $order->fields['billing_street_address'],
 147                             'suburb' => $order->fields['billing_suburb'],
 148                             'city' => $order->fields['billing_city'],
 149                             'postcode' => $order->fields['billing_postcode'],
 150                             'state' => $order->fields['billing_state'],
 151                             'country' => $order->fields['billing_country'],
 152                             'format_id' => $order->fields['billing_address_format_id']);
 153  
 154      $index = 0;
 155      $orders_products_query = "select orders_products_id, products_id, products_name,
 156                                   products_model, products_price, products_tax,
 157                                   products_quantity, final_price,
 158                                   onetime_charges,
 159                                   products_priced_by_attribute, product_is_free, products_discount_type,
 160                                   products_discount_type_from
 161                                    from " . TABLE_ORDERS_PRODUCTS . "
 162                                    where orders_id = '" . (int)$order_id . "'";
 163  
 164      $orders_products = $db->Execute($orders_products_query);
 165  
 166      while (!$orders_products->EOF) {
 167        // convert quantity to proper decimals - account history

 168        if (QUANTITY_DECIMALS != 0) {
 169          $fix_qty = $orders_products->fields['products_quantity'];
 170          switch (true) {
 171            case (!strstr($fix_qty, '.')):
 172            $new_qty = $fix_qty;
 173            break;
 174            default:
 175            $new_qty = preg_replace('/[0]+$/', '', $orders_products->fields['products_quantity']);
 176            break;
 177          }
 178        } else {
 179          $new_qty = $orders_products->fields['products_quantity'];
 180        }
 181  
 182        $new_qty = round($new_qty, QUANTITY_DECIMALS);
 183  
 184        if ($new_qty == (int)$new_qty) {
 185          $new_qty = (int)$new_qty;
 186        }
 187  
 188        $this->products[$index] = array('qty' => $new_qty,
 189                                        'id' => $orders_products->fields['products_id'],
 190                                        'name' => $orders_products->fields['products_name'],
 191                                        'model' => $orders_products->fields['products_model'],
 192                                        'tax' => $orders_products->fields['products_tax'],
 193                                        'price' => $orders_products->fields['products_price'],
 194                                        'final_price' => $orders_products->fields['final_price'],
 195                                        'onetime_charges' => $orders_products->fields['onetime_charges'],
 196                                        'products_priced_by_attribute' => $orders_products->fields['products_priced_by_attribute'],
 197                                        'product_is_free' => $orders_products->fields['product_is_free'],
 198                                        'products_discount_type' => $orders_products->fields['products_discount_type'],
 199                                        'products_discount_type_from' => $orders_products->fields['products_discount_type_from']);
 200  
 201        $subindex = 0;
 202        $attributes_query = "select products_options_id, products_options_values_id, products_options, products_options_values,
 203                                options_values_price, price_prefix from " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . "
 204                                 where orders_id = '" . (int)$order_id . "'
 205                                 and orders_products_id = '" . (int)$orders_products->fields['orders_products_id'] . "'";
 206  
 207        $attributes = $db->Execute($attributes_query);
 208        if ($attributes->RecordCount()) {
 209          while (!$attributes->EOF) {
 210            $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options'],
 211                                                                     'value' => $attributes->fields['products_options_values'],
 212                                                                     'prefix' => $attributes->fields['price_prefix'],
 213                                                                     'price' => $attributes->fields['options_values_price']);
 214  
 215            $subindex++;
 216            $attributes->MoveNext();
 217          }
 218        }
 219  
 220        $this->info['tax_groups']["{$this->products[$index]['tax']}"] = '1';
 221  
 222        $index++;
 223        $orders_products->MoveNext();
 224      }
 225    }
 226  
 227    function cart() {
 228      global $db, $currencies;
 229  
 230      $this->content_type = $_SESSION['cart']->get_content_type();
 231  
 232      $customer_address_query = "select c.customers_firstname, c.customers_lastname, c.customers_telephone,
 233                                      c.customers_email_address, ab.entry_company, ab.entry_street_address,
 234                                      ab.entry_suburb, ab.entry_postcode, ab.entry_city, ab.entry_zone_id,
 235                                      z.zone_name, co.countries_id, co.countries_name,
 236                                      co.countries_iso_code_2, co.countries_iso_code_3,
 237                                      co.address_format_id, ab.entry_state
 238                                     from (" . TABLE_CUSTOMERS . " c, " . TABLE_ADDRESS_BOOK . " ab )
 239                                     left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 240                                     left join " . TABLE_COUNTRIES . " co on (ab.entry_country_id = co.countries_id)
 241                                     where c.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 242                                     and ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 243                                     and c.customers_default_address_id = ab.address_book_id";
 244  
 245      $customer_address = $db->Execute($customer_address_query);
 246  
 247      $shipping_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,
 248                                      ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,
 249                                      ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,
 250                                      c.countries_id, c.countries_name, c.countries_iso_code_2,
 251                                      c.countries_iso_code_3, c.address_format_id, ab.entry_state
 252                                     from " . TABLE_ADDRESS_BOOK . " ab
 253                                     left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 254                                     left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) 
 255                                     where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 256                                     and ab.address_book_id = '" . (int)$_SESSION['sendto'] . "'";
 257  
 258      $shipping_address = $db->Execute($shipping_address_query);
 259  
 260      $billing_address_query = "select ab.entry_firstname, ab.entry_lastname, ab.entry_company,
 261                                     ab.entry_street_address, ab.entry_suburb, ab.entry_postcode,
 262                                     ab.entry_city, ab.entry_zone_id, z.zone_name, ab.entry_country_id,
 263                                     c.countries_id, c.countries_name, c.countries_iso_code_2,
 264                                     c.countries_iso_code_3, c.address_format_id, ab.entry_state
 265                                    from " . TABLE_ADDRESS_BOOK . " ab
 266                                    left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 267                                    left join " . TABLE_COUNTRIES . " c on (ab.entry_country_id = c.countries_id) 
 268                                    where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 269                                    and ab.address_book_id = '" . (int)$_SESSION['billto'] . "'";
 270  
 271      $billing_address = $db->Execute($billing_address_query);
 272      //STORE_PRODUCT_TAX_BASIS

 273  
 274      switch (STORE_PRODUCT_TAX_BASIS) {
 275        case 'Shipping':
 276  
 277        $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
 278                                from " . TABLE_ADDRESS_BOOK . " ab
 279                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 280                                where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 281                                and ab.address_book_id = '" . (int)($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
 282        $tax_address = $db->Execute($tax_address_query);
 283        break;
 284        case 'Billing':
 285  
 286        $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
 287                                from " . TABLE_ADDRESS_BOOK . " ab
 288                                left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 289                                where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 290                                and ab.address_book_id = '" . (int)$_SESSION['billto'] . "'";
 291        $tax_address = $db->Execute($tax_address_query);
 292        break;
 293        case 'Store':
 294        if ($billing_address->fields['entry_zone_id'] == STORE_ZONE) {
 295  
 296          $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
 297                                  from " . TABLE_ADDRESS_BOOK . " ab
 298                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 299                                  where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 300                                  and ab.address_book_id = '" . (int)$_SESSION['billto'] . "'";
 301        } else {
 302          $tax_address_query = "select ab.entry_country_id, ab.entry_zone_id
 303                                  from " . TABLE_ADDRESS_BOOK . " ab
 304                                  left join " . TABLE_ZONES . " z on (ab.entry_zone_id = z.zone_id)
 305                                  where ab.customers_id = '" . (int)$_SESSION['customer_id'] . "'
 306                                  and ab.address_book_id = '" . (int)($this->content_type == 'virtual' ? $_SESSION['billto'] : $_SESSION['sendto']) . "'";
 307        }
 308        $tax_address = $db->Execute($tax_address_query);
 309      }
 310  
 311  
 312      $class =& $_SESSION['payment'];
 313  
 314      if (isset($_SESSION['cc_id'])) {
 315        $coupon_code_query = "select coupon_code
 316                                from " . TABLE_COUPONS . "
 317                                where coupon_id = '" . (int)$_SESSION['cc_id'] . "'";
 318  
 319        $coupon_code = $db->Execute($coupon_code_query);
 320  
 321  
 322      }
 323  
 324      $this->info = array('order_status' => DEFAULT_ORDERS_STATUS_ID,
 325                          'currency' => $_SESSION['currency'],
 326                          'currency_value' => $currencies->currencies[$_SESSION['currency']]['value'],
 327                          'payment_method' => $GLOBALS[$class]->title,
 328                          'payment_module_code' => $GLOBALS[$class]->code,
 329                          'coupon_code' => $coupon_code->fields['coupon_code'],
 330      //                          'cc_type' => (isset($GLOBALS['cc_type']) ? $GLOBALS['cc_type'] : ''),

 331      //                          'cc_owner' => (isset($GLOBALS['cc_owner']) ? $GLOBALS['cc_owner'] : ''),

 332      //                          'cc_number' => (isset($GLOBALS['cc_number']) ? $GLOBALS['cc_number'] : ''),

 333      //                          'cc_expires' => (isset($GLOBALS['cc_expires']) ? $GLOBALS['cc_expires'] : ''),

 334      //                          'cc_cvv' => (isset($GLOBALS['cc_cvv']) ? $GLOBALS['cc_cvv'] : ''),

 335                          'shipping_method' => $_SESSION['shipping']['title'],
 336                          'shipping_module_code' => $_SESSION['shipping']['id'],
 337                          'shipping_cost' => $_SESSION['shipping']['cost'],
 338                          'subtotal' => 0,
 339                          'tax' => 0,
 340                          'total' => 0,
 341                          'tax_groups' => array(),
 342                          'comments' => (isset($_SESSION['comments']) ? $_SESSION['comments'] : ''),
 343                          'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
 344                          );
 345  
 346      //print_r($GLOBALS[$class]);

 347      //echo $class;

 348      //print_r($GLOBALS);

 349      //echo $_SESSION['payment'];

 350      /*

 351      // this is set above to the module filename it should be set to the module title like Checks/Money Order rather than moneyorder

 352      if (isset($$_SESSION['payment']) && is_object($$_SESSION['payment'])) {

 353      $this->info['payment_method'] = $$_SESSION['payment']->title;

 354      }

 355      */
 356  
 357  /*

 358  // bof: move below calculations

 359      if ($this->info['total'] == 0) {

 360        if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {

 361          $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;

 362        } else {

 363          $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;

 364        }

 365      }

 366      if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {

 367        if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) {

 368          $this->info['order_status'] = $GLOBALS[$class]->order_status;

 369        }

 370      }

 371  // eof: move below calculations

 372  */
 373      $this->customer = array('firstname' => $customer_address->fields['customers_firstname'],
 374                              'lastname' => $customer_address->fields['customers_lastname'],
 375                              'company' => $customer_address->fields['entry_company'],
 376                              'street_address' => $customer_address->fields['entry_street_address'],
 377                              'suburb' => $customer_address->fields['entry_suburb'],
 378                              'city' => $customer_address->fields['entry_city'],
 379                              'postcode' => $customer_address->fields['entry_postcode'],
 380                              'state' => ((zen_not_null($customer_address->fields['entry_state'])) ? $customer_address->fields['entry_state'] : $customer_address->fields['zone_name']),
 381                              'zone_id' => $customer_address->fields['entry_zone_id'],
 382                              'country' => array('id' => $customer_address->fields['countries_id'], 'title' => $customer_address->fields['countries_name'], 'iso_code_2' => $customer_address->fields['countries_iso_code_2'], 'iso_code_3' => $customer_address->fields['countries_iso_code_3']),
 383                              'format_id' => $customer_address->fields['address_format_id'],
 384                              'telephone' => $customer_address->fields['customers_telephone'],
 385                              'email_address' => $customer_address->fields['customers_email_address']);
 386  
 387      $this->delivery = array('firstname' => $shipping_address->fields['entry_firstname'],
 388                              'lastname' => $shipping_address->fields['entry_lastname'],
 389                              'company' => $shipping_address->fields['entry_company'],
 390                              'street_address' => $shipping_address->fields['entry_street_address'],
 391                              'suburb' => $shipping_address->fields['entry_suburb'],
 392                              'city' => $shipping_address->fields['entry_city'],
 393                              'postcode' => $shipping_address->fields['entry_postcode'],
 394                              'state' => ((zen_not_null($shipping_address->fields['entry_state'])) ? $shipping_address->fields['entry_state'] : $shipping_address->fields['zone_name']),
 395                              'zone_id' => $shipping_address->fields['entry_zone_id'],
 396                              'country' => array('id' => $shipping_address->fields['countries_id'], 'title' => $shipping_address->fields['countries_name'], 'iso_code_2' => $shipping_address->fields['countries_iso_code_2'], 'iso_code_3' => $shipping_address->fields['countries_iso_code_3']),
 397                              'country_id' => $shipping_address->fields['entry_country_id'],
 398                              'format_id' => $shipping_address->fields['address_format_id']);
 399  
 400      $this->billing = array('firstname' => $billing_address->fields['entry_firstname'],
 401                             'lastname' => $billing_address->fields['entry_lastname'],
 402                             'company' => $billing_address->fields['entry_company'],
 403                             'street_address' => $billing_address->fields['entry_street_address'],
 404                             'suburb' => $billing_address->fields['entry_suburb'],
 405                             'city' => $billing_address->fields['entry_city'],
 406                             'postcode' => $billing_address->fields['entry_postcode'],
 407                             'state' => ((zen_not_null($billing_address->fields['entry_state'])) ? $billing_address->fields['entry_state'] : $billing_address->fields['zone_name']),
 408                             'zone_id' => $billing_address->fields['entry_zone_id'],
 409                             'country' => array('id' => $billing_address->fields['countries_id'], 'title' => $billing_address->fields['countries_name'], 'iso_code_2' => $billing_address->fields['countries_iso_code_2'], 'iso_code_3' => $billing_address->fields['countries_iso_code_3']),
 410                             'country_id' => $billing_address->fields['entry_country_id'],
 411                             'format_id' => $billing_address->fields['address_format_id']);
 412  
 413      $index = 0;
 414      $products = $_SESSION['cart']->get_products();
 415      for ($i=0, $n=sizeof($products); $i<$n; $i++) {
 416        if (($i/2) == floor($i/2)) {
 417          $rowClass="rowEven";
 418        } else {
 419          $rowClass="rowOdd";
 420        }
 421        $this->products[$index] = array('qty' => $products[$i]['quantity'],
 422                                        'name' => $products[$i]['name'],
 423                                        'model' => $products[$i]['model'],
 424                                        'tax' => zen_get_tax_rate($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']),
 425                                        'tax_description' => zen_get_tax_description($products[$i]['tax_class_id'], $tax_address->fields['entry_country_id'], $tax_address->fields['entry_zone_id']),
 426                                        'price' => $products[$i]['price'],
 427                                        'final_price' => $products[$i]['price'] + $_SESSION['cart']->attributes_price($products[$i]['id']),
 428                                        'onetime_charges' => $_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity']),
 429                                        'weight' => $products[$i]['weight'],
 430                                        'products_priced_by_attribute' => $products[$i]['products_priced_by_attribute'],
 431                                        'product_is_free' => $products[$i]['product_is_free'],
 432                                        'products_discount_type' => $products[$i]['products_discount_type'],
 433                                        'products_discount_type_from' => $products[$i]['products_discount_type_from'],
 434                                        'id' => $products[$i]['id'],
 435                                        'rowClass' => $rowClass);
 436  
 437        if ($products[$i]['attributes']) {
 438          $subindex = 0;
 439          reset($products[$i]['attributes']);
 440          while (list($option, $value) = each($products[$i]['attributes'])) {
 441            /*

 442            //clr 030714 Determine if attribute is a text attribute and change products array if it is.

 443            if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){

 444            $attr_value = $products[$i]['attributes_values'][$option];

 445            } else {

 446            $attr_value = $attributes->fields['products_options_values_name'];

 447            }

 448            */
 449  
 450            $attributes_query = "select popt.products_options_name, poval.products_options_values_name,
 451                                            pa.options_values_price, pa.price_prefix
 452                                     from " . TABLE_PRODUCTS_OPTIONS . " popt,
 453                                          " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval,
 454                                          " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 455                                     where pa.products_id = '" . (int)$products[$i]['id'] . "'
 456                                     and pa.options_id = '" . (int)$option . "'
 457                                     and pa.options_id = popt.products_options_id
 458                                     and pa.options_values_id = '" . (int)$value . "'
 459                                     and pa.options_values_id = poval.products_options_values_id
 460                                     and popt.language_id = '" . (int)$_SESSION['languages_id'] . "'
 461                                     and poval.language_id = '" . (int)$_SESSION['languages_id'] . "'";
 462  
 463            $attributes = $db->Execute($attributes_query);
 464  
 465            //clr 030714 Determine if attribute is a text attribute and change products array if it is.

 466            if ($value == PRODUCTS_OPTIONS_VALUES_TEXT_ID){
 467              $attr_value = $products[$i]['attributes_values'][$option];
 468            } else {
 469              $attr_value = $attributes->fields['products_options_values_name'];
 470            }
 471  
 472            $this->products[$index]['attributes'][$subindex] = array('option' => $attributes->fields['products_options_name'],
 473                                                                     'value' => $attr_value,
 474                                                                     'option_id' => $option,
 475                                                                     'value_id' => $value,
 476                                                                     'prefix' => $attributes->fields['price_prefix'],
 477                                                                     'price' => $attributes->fields['options_values_price']);
 478  
 479            $subindex++;
 480          }
 481        }
 482  
 483        // add onetime charges here

 484        //$_SESSION['cart']->attributes_price_onetime_charges($products[$i]['id'], $products[$i]['quantity'])

 485  
 486        /*********************************************

 487         * Calculate taxes for this product

 488         *********************************************/
 489        $shown_price = (zen_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'])
 490        + zen_add_tax($this->products[$index]['onetime_charges'], $this->products[$index]['tax']);
 491        $this->info['subtotal'] += $shown_price;
 492  
 493        // find product's tax rate and description

 494        $products_tax = $this->products[$index]['tax'];
 495        $products_tax_description = $this->products[$index]['tax_description'];
 496  
 497        // calculate the amount of tax "inc"luded in price (used if tax-in pricing is enabled)

 498        $current_row_tax_inc = $shown_price - ($shown_price / (($products_tax < 10) ? "1.0" . str_replace('.', '', $products_tax) : "1." . str_replace('.', '', $products_tax)));
 499  
 500        // calculate the amount of tax for this product (assuming tax is NOT included in the price)

 501        $current_row_tax_exc = zen_round(($products_tax / 100) * $shown_price, $currencies->currencies[$this->info['currency']]['decimal_places']);
 502  
 503        if (DISPLAY_PRICE_WITH_TAX == 'true') {
 504          $this->info['tax'] += $current_row_tax_inc;
 505          if (isset($this->info['tax_groups']["$products_tax_description"])) {
 506            $this->info['tax_groups']["$products_tax_description"] += $current_row_tax_inc;
 507          } else {
 508            $this->info['tax_groups']["$products_tax_description"] = $current_row_tax_inc;
 509          }
 510        } else {
 511          // this adds the tax rate for cases where tax is NOT included in the product

 512          $this->info['tax'] += $current_row_tax_exc;
 513          if (isset($this->info['tax_groups']["$products_tax_description"])) {
 514            $this->info['tax_groups']["$products_tax_description"] += $current_row_tax_exc;
 515          } else {
 516            $this->info['tax_groups']["$products_tax_description"] = $current_row_tax_exc;
 517          }
 518        }
 519        /*********************************************

 520         * END: Calculate taxes for this product

 521         *********************************************/
 522        $index++;
 523      }
 524  
 525      // Update the final total to include tax if not already tax-inc

 526      if (DISPLAY_PRICE_WITH_TAX == 'true') {
 527        $this->info['total'] = $this->info['subtotal'] + $this->info['shipping_cost'];
 528      } else {
 529        $this->info['total'] = $this->info['subtotal'] + $this->info['tax'] + $this->info['shipping_cost'];
 530      }
 531  
 532  /*

 533  // moved to function create

 534      if ($this->info['total'] == 0) {

 535        if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {

 536          $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;

 537        } else {

 538          $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;

 539        }

 540      }

 541  */
 542      if (isset($GLOBALS[$class]) && is_object($GLOBALS[$class])) {
 543        if ( isset($GLOBALS[$class]->order_status) && is_numeric($GLOBALS[$class]->order_status) && ($GLOBALS[$class]->order_status > 0) ) {
 544          $this->info['order_status'] = $GLOBALS[$class]->order_status;
 545        }
 546      }
 547  
 548    }
 549  
 550    function create($zf_ot_modules, $zf_mode = 2) {
 551      global $db;
 552  
 553      if ($this->info['total'] == 0) {
 554        if (DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID == 0) {
 555          $this->info['order_status'] = DEFAULT_ORDERS_STATUS_ID;
 556        } else {
 557          $this->info['order_status'] = DEFAULT_ZERO_BALANCE_ORDERS_STATUS_ID;
 558        }
 559      }
 560  
 561      if ($_SESSION['shipping'] == 'free_free') {
 562        $this->info['shipping_module_code'] = $_SESSION['shipping'];
 563      }
 564  
 565      $sql_data_array = array('customers_id' => $_SESSION['customer_id'],
 566                              'customers_name' => $this->customer['firstname'] . ' ' . $this->customer['lastname'],
 567                              'customers_company' => $this->customer['company'],
 568                              'customers_street_address' => $this->customer['street_address'],
 569                              'customers_suburb' => $this->customer['suburb'],
 570                              'customers_city' => $this->customer['city'],
 571                              'customers_postcode' => $this->customer['postcode'],
 572                              'customers_state' => $this->customer['state'],
 573                              'customers_country' => $this->customer['country']['title'],
 574                              'customers_telephone' => $this->customer['telephone'],
 575                              'customers_email_address' => $this->customer['email_address'],
 576                              'customers_address_format_id' => $this->customer['format_id'],
 577                              'delivery_name' => $this->delivery['firstname'] . ' ' . $this->delivery['lastname'],
 578                              'delivery_company' => $this->delivery['company'],
 579                              'delivery_street_address' => $this->delivery['street_address'],
 580                              'delivery_suburb' => $this->delivery['suburb'],
 581                              'delivery_city' => $this->delivery['city'],
 582                              'delivery_postcode' => $this->delivery['postcode'],
 583                              'delivery_state' => $this->delivery['state'],
 584                              'delivery_country' => $this->delivery['country']['title'],
 585                              'delivery_address_format_id' => $this->delivery['format_id'],
 586                              'billing_name' => $this->billing['firstname'] . ' ' . $this->billing['lastname'],
 587                              'billing_company' => $this->billing['company'],
 588                              'billing_street_address' => $this->billing['street_address'],
 589                              'billing_suburb' => $this->billing['suburb'],
 590                              'billing_city' => $this->billing['city'],
 591                              'billing_postcode' => $this->billing['postcode'],
 592                              'billing_state' => $this->billing['state'],
 593                              'billing_country' => $this->billing['country']['title'],
 594                              'billing_address_format_id' => $this->billing['format_id'],
 595                              'payment_method' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_METHOD_GV : $this->info['payment_method']),
 596                              'payment_module_code' => (($this->info['payment_module_code'] == '' and $this->info['payment_method'] == '') ? PAYMENT_MODULE_GV : $this->info['payment_module_code']),
 597                              'shipping_method' => $this->info['shipping_method'],
 598                              'shipping_module_code' => (strpos($this->info['shipping_module_code'], '_') > 0 ? substr($this->info['shipping_module_code'], 0, strpos($this->info['shipping_module_code'], '_')) : $this->info['shipping_module_code']),
 599                              'coupon_code' => $this->info['coupon_code'],
 600                              'cc_type' => $this->info['cc_type'],
 601                              'cc_owner' => $this->info['cc_owner'],
 602                              'cc_number' => $this->info['cc_number'],
 603                              'cc_expires' => $this->info['cc_expires'],
 604                              'date_purchased' => 'now()',
 605                              'orders_status' => $this->info['order_status'],
 606                              'order_total' => $this->info['total'],
 607                              'order_tax' => $this->info['tax'],
 608                              'currency' => $this->info['currency'],
 609                              'currency_value' => $this->info['currency_value'],
 610                              'ip_address' => $_SESSION['customers_ip_address'] . ' - ' . $_SERVER['REMOTE_ADDR']
 611                              );
 612  
 613  
 614      zen_db_perform(TABLE_ORDERS, $sql_data_array);
 615  
 616      $insert_id = $db->Insert_ID();
 617  
 618      for ($i=0, $n=sizeof($zf_ot_modules); $i<$n; $i++) {
 619        $sql_data_array = array('orders_id' => $insert_id,
 620                                'title' => $zf_ot_modules[$i]['title'],
 621                                'text' => $zf_ot_modules[$i]['text'],
 622                                'value' => $zf_ot_modules[$i]['value'],
 623                                'class' => $zf_ot_modules[$i]['code'],
 624                                'sort_order' => $zf_ot_modules[$i]['sort_order']);
 625  
 626        zen_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
 627      }
 628  
 629      $customer_notification = (SEND_EMAILS == 'true') ? '1' : '0';
 630      $sql_data_array = array('orders_id' => $insert_id,
 631                              'orders_status_id' => $this->info['order_status'],
 632                              'date_added' => 'now()',
 633                              'customer_notified' => $customer_notification,
 634                              'comments' => $this->info['comments']);
 635  
 636      zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 637  
 638      return($insert_id);
 639  
 640    }
 641  
 642  
 643    function  create_add_products($zf_insert_id, $zf_mode = false) {
 644      global $db, $currencies, $order_total_modules, $order_totals, $zco_notifier;
 645  
 646      // initialized for the email confirmation

 647  
 648      $this->products_ordered = '';
 649      $this->products_ordered_html = '';
 650      $this->subtotal = 0;
 651      $this->total_tax = 0;
 652  
 653      // lowstock email report

 654      $this->email_low_stock='';
 655  
 656      for ($i=0, $n=sizeof($this->products); $i<$n; $i++) {
 657        // Stock Update - Joao Correia

 658        if (STOCK_LIMITED == 'true') {
 659          if (DOWNLOAD_ENABLED == 'true') {
 660            $stock_query_raw = "select p.products_quantity, pad.products_attributes_filename, p.product_is_always_free_shipping
 661                                from " . TABLE_PRODUCTS . " p
 662                                left join " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 663                                 on p.products_id=pa.products_id
 664                                left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 665                                 on pa.products_attributes_id=pad.products_attributes_id
 666                                WHERE p.products_id = '" . zen_get_prid($this->products[$i]['id']) . "'";
 667  
 668            // Will work with only one option for downloadable products

 669            // otherwise, we have to build the query dynamically with a loop

 670            $products_attributes = $this->products[$i]['attributes'];
 671            if (is_array($products_attributes)) {
 672              $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
 673            }
 674            $stock_values = $db->Execute($stock_query_raw);
 675          } else {
 676            $stock_values = $db->Execute("select * from " . TABLE_PRODUCTS . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");
 677          }
 678  
 679          $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_BEGIN');
 680  
 681          if ($stock_values->RecordCount() > 0) {
 682            // do not decrement quantities if products_attributes_filename exists

 683            if ((DOWNLOAD_ENABLED != 'true') || $stock_values->fields['product_is_always_free_shipping'] == 2 || (!$stock_values->fields['products_attributes_filename']) ) {
 684              $stock_left = $stock_values->fields['products_quantity'] - $this->products[$i]['qty'];
 685              $this->products[$i]['stock_reduce'] = $this->products[$i]['qty'];
 686            } else {
 687              $stock_left = $stock_values->fields['products_quantity'];
 688            }
 689  
 690            //            $this->products[$i]['stock_value'] = $stock_values->fields['products_quantity'];

 691  
 692            $db->Execute("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");
 693            //        if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {

 694            if ($stock_left <= 0) {
 695              // only set status to off when not displaying sold out

 696              if (SHOW_PRODUCTS_SOLD_OUT == '0') {
 697                $db->Execute("update " . TABLE_PRODUCTS . " set products_status = 0 where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");
 698              }
 699            }
 700  
 701            // for low stock email

 702            if ( $stock_left <= STOCK_REORDER_LEVEL ) {
 703              // WebMakers.com Added: add to low stock email

 704              $this->email_low_stock .=  'ID# ' . zen_get_prid($this->products[$i]['id']) . "\t\t" . $this->products[$i]['model'] . "\t\t" . $this->products[$i]['name'] . "\t\t" . ' Qty Left: ' . $stock_left . "\n";
 705            }
 706          }
 707        }
 708  
 709        // Update products_ordered (for bestsellers list)

 710        //    $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . zen_get_prid($order->products[$i]['id']) . "'");

 711        $db->Execute("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%f', $this->products[$i]['qty']) . " where products_id = '" . zen_get_prid($this->products[$i]['id']) . "'");
 712  
 713        $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_STOCK_DECREMENT_END');
 714  
 715        $sql_data_array = array('orders_id' => $zf_insert_id,
 716                                'products_id' => zen_get_prid($this->products[$i]['id']),
 717                                'products_model' => $this->products[$i]['model'],
 718                                'products_name' => $this->products[$i]['name'],
 719                                'products_price' => $this->products[$i]['price'],
 720                                'final_price' => $this->products[$i]['final_price'],
 721                                'onetime_charges' => $this->products[$i]['onetime_charges'],
 722                                'products_tax' => $this->products[$i]['tax'],
 723                                'products_quantity' => $this->products[$i]['qty'],
 724                                'products_priced_by_attribute' => $this->products[$i]['products_priced_by_attribute'],
 725                                'product_is_free' => $this->products[$i]['product_is_free'],
 726                                'products_discount_type' => $this->products[$i]['products_discount_type'],
 727                                'products_discount_type_from' => $this->products[$i]['products_discount_type_from'],
 728                                'products_prid' => $this->products[$i]['id']);
 729        zen_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
 730  
 731        $order_products_id = $db->Insert_ID();
 732  
 733        $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_CREDIT_ACCOUNT_UPDATE_BEGIN');
 734        $order_total_modules->update_credit_account($i);//ICW ADDED FOR CREDIT CLASS SYSTEM

 735  
 736        $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_ATTRIBUTES_BEGIN');
 737  
 738        //------ bof: insert customer-chosen options to order--------

 739        $attributes_exist = '0';
 740        $this->products_ordered_attributes = '';
 741        if (isset($this->products[$i]['attributes'])) {
 742          $attributes_exist = '1';
 743          for ($j=0, $n2=sizeof($this->products[$i]['attributes']); $j<$n2; $j++) {
 744            if (DOWNLOAD_ENABLED == 'true') {
 745              $attributes_query = "select popt.products_options_name, poval.products_options_values_name,
 746                                   pa.options_values_price, pa.price_prefix,
 747                                   pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,
 748                                   pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,
 749                                   pa.attributes_price_factor, pa.attributes_price_factor_offset,
 750                                   pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,
 751                                   pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,
 752                                   pa.attributes_price_words, pa.attributes_price_words_free,
 753                                   pa.attributes_price_letters, pa.attributes_price_letters_free,
 754                                   pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename,
 755                                   pa.product_attribute_is_free, pa.attributes_discounted
 756                                   from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " .
 757              TABLE_PRODUCTS_ATTRIBUTES . " pa
 758                                    left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 759                                    on pa.products_attributes_id=pad.products_attributes_id
 760                                   where pa.products_id = '" . zen_db_input($this->products[$i]['id']) . "'
 761                                    and pa.options_id = '" . $this->products[$i]['attributes'][$j]['option_id'] . "'
 762                                    and pa.options_id = popt.products_options_id
 763                                    and pa.options_values_id = '" . $this->products[$i]['attributes'][$j]['value_id'] . "'
 764                                    and pa.options_values_id = poval.products_options_values_id
 765                                    and popt.language_id = '" . $_SESSION['languages_id'] . "'
 766                                    and poval.language_id = '" . $_SESSION['languages_id'] . "'";
 767  
 768              $attributes_values = $db->Execute($attributes_query);
 769            } else {
 770              $attributes_values = $db->Execute("select popt.products_options_name, poval.products_options_values_name,
 771                                   pa.options_values_price, pa.price_prefix,
 772                                   pa.product_attribute_is_free, pa.products_attributes_weight, pa.products_attributes_weight_prefix,
 773                                   pa.attributes_discounted, pa.attributes_price_base_included, pa.attributes_price_onetime,
 774                                   pa.attributes_price_factor, pa.attributes_price_factor_offset,
 775                                   pa.attributes_price_factor_onetime, pa.attributes_price_factor_onetime_offset,
 776                                   pa.attributes_qty_prices, pa.attributes_qty_prices_onetime,
 777                                   pa.attributes_price_words, pa.attributes_price_words_free,
 778                                   pa.attributes_price_letters, pa.attributes_price_letters_free
 779                                   from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 780                                   where pa.products_id = '" . $this->products[$i]['id'] . "' and pa.options_id = '" . (int)$this->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . (int)$this->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $_SESSION['languages_id'] . "' and poval.language_id = '" . $_SESSION['languages_id'] . "'");
 781            }
 782  
 783            //clr 030714 update insert query.  changing to use values form $order->products for products_options_values.

 784            $sql_data_array = array('orders_id' => $zf_insert_id,
 785                                    'orders_products_id' => $order_products_id,
 786                                    'products_options' => $attributes_values->fields['products_options_name'],
 787  
 788            //                                 'products_options_values' => $attributes_values->fields['products_options_values_name'],

 789                                    'products_options_values' => $this->products[$i]['attributes'][$j]['value'],
 790                                    'options_values_price' => $attributes_values->fields['options_values_price'],
 791                                    'price_prefix' => $attributes_values->fields['price_prefix'],
 792                                    'product_attribute_is_free' => $attributes_values->fields['product_attribute_is_free'],
 793                                    'products_attributes_weight' => $attributes_values->fields['products_attributes_weight'],
 794                                    'products_attributes_weight_prefix' => $attributes_values->fields['products_attributes_weight_prefix'],
 795                                    'attributes_discounted' => $attributes_values->fields['attributes_discounted'],
 796                                    'attributes_price_base_included' => $attributes_values->fields['attributes_price_base_included'],
 797                                    'attributes_price_onetime' => $attributes_values->fields['attributes_price_onetime'],
 798                                    'attributes_price_factor' => $attributes_values->fields['attributes_price_factor'],
 799                                    'attributes_price_factor_offset' => $attributes_values->fields['attributes_price_factor_offset'],
 800                                    'attributes_price_factor_onetime' => $attributes_values->fields['attributes_price_factor_onetime'],
 801                                    'attributes_price_factor_onetime_offset' => $attributes_values->fields['attributes_price_factor_onetime_offset'],
 802                                    'attributes_qty_prices' => $attributes_values->fields['attributes_qty_prices'],
 803                                    'attributes_qty_prices_onetime' => $attributes_values->fields['attributes_qty_prices_onetime'],
 804                                    'attributes_price_words' => $attributes_values->fields['attributes_price_words'],
 805                                    'attributes_price_words_free' => $attributes_values->fields['attributes_price_words_free'],
 806                                    'attributes_price_letters' => $attributes_values->fields['attributes_price_letters'],
 807                                    'attributes_price_letters_free' => $attributes_values->fields['attributes_price_letters_free'],
 808                                    'products_options_id' => (int)$this->products[$i]['attributes'][$j]['option_id'],
 809                                    'products_options_values_id' => (int)$this->products[$i]['attributes'][$j]['value_id'],
 810                                    'products_prid' => $this->products[$i]['id']
 811                                    );
 812  
 813  
 814            zen_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
 815  
 816            if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values->fields['products_attributes_filename']) && zen_not_null($attributes_values->fields['products_attributes_filename'])) {
 817              $sql_data_array = array('orders_id' => $zf_insert_id,
 818                                      'orders_products_id' => $order_products_id,
 819                                      'orders_products_filename' => $attributes_values->fields['products_attributes_filename'],
 820                                      'download_maxdays' => $attributes_values->fields['products_attributes_maxdays'],
 821                                      'download_count' => $attributes_values->fields['products_attributes_maxcount'],
 822                                      'products_prid' => $this->products[$i]['id']
 823                                      );
 824  
 825              zen_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
 826            }
 827            //clr 030714 changing to use values from $orders->products and adding call to zen_decode_specialchars()

 828            //        $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . $attributes_values->fields['products_options_values_name'];

 829            $this->products_ordered_attributes .= "\n\t" . $attributes_values->fields['products_options_name'] . ' ' . zen_decode_specialchars($this->products[$i]['attributes'][$j]['value']);
 830          }
 831        }
 832        //------eof: insert customer-chosen options ----

 833  
 834        // update totals counters

 835        $this->total_weight += ($this->products[$i]['qty'] * $this->products[$i]['weight']);
 836        $this->total_tax += zen_calculate_tax($total_products_price, $products_tax) * $this->products[$i]['qty'];
 837        $this->total_cost += $total_products_price;
 838  
 839        $zco_notifier->notify('NOTIFY_ORDER_PROCESSING_ONE_TIME_CHARGES_BEGIN');
 840  
 841        // build output for email notification

 842        $this->products_ordered .=  $this->products[$i]['qty'] . ' x ' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') . ' = ' .
 843        $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) .
 844        ($this->products[$i]['onetime_charges'] !=0 ? "\n" . TEXT_ONETIME_CHARGES_EMAIL . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') .
 845        $this->products_ordered_attributes . "\n";
 846        $this->products_ordered_html .=
 847        '<tr>' .
 848        '<td class="product-details" align="right" valign="top" width="30">' . $this->products[$i]['qty'] . '&nbsp;x</td>' .
 849        '<td class="product-details" valign="top">' . $this->products[$i]['name'] . ($this->products[$i]['model'] != '' ? ' (' . $this->products[$i]['model'] . ') ' : '') .
 850        '<nobr><small><em> '. $this->products_ordered_attributes .'</em></small></nobr></td>' .
 851        '<td class="product-details-num" valign="top" align="right">' .
 852        $currencies->display_price($this->products[$i]['final_price'], $this->products[$i]['tax'], $this->products[$i]['qty']) .
 853        ($this->products[$i]['onetime_charges'] !=0 ?
 854        '</td></tr><tr><td class="product-details">' . TEXT_ONETIME_CHARGES_EMAIL . '</td>' .
 855        '<td>' . $currencies->display_price($this->products[$i]['onetime_charges'], $this->products[$i]['tax'], 1) : '') .
 856        '</td></tr>';
 857      }
 858  
 859      $order_total_modules->apply_credit();//ICW ADDED FOR CREDIT CLASS SYSTEM

 860    }
 861  
 862  
 863    function send_order_email($zf_insert_id, $zf_mode) {
 864      global $currencies, $order_totals;
 865  
 866      //      print_r($this);

 867      //      die();

 868      if ($this->email_low_stock != '' and SEND_LOWSTOCK_EMAIL=='1') {
 869        // send an email

 870        $email_low_stock = SEND_EXTRA_LOW_STOCK_EMAIL_TITLE . "\n\n" . $this->email_low_stock;
 871        zen_mail('', SEND_EXTRA_LOW_STOCK_EMAILS_TO, EMAIL_TEXT_SUBJECT_LOWSTOCK, $email_low_stock, STORE_OWNER, EMAIL_FROM, array('EMAIL_MESSAGE_HTML' => nl2br($email_low_stock)),'low_stock');
 872      }
 873  
 874      // lets start with the email confirmation

 875      // make an array to store the html version

 876      $html_msg=array();
 877  
 878      //intro area

 879      $email_order = EMAIL_TEXT_HEADER . EMAIL_TEXT_FROM . STORE_NAME . "\n\n" .
 880      $this->customer['firstname'] . ' ' . $this->customer['lastname'] . "\n\n" .
 881      EMAIL_THANKS_FOR_SHOPPING . "\n" . EMAIL_DETAILS_FOLLOW . "\n" .
 882      EMAIL_SEPARATOR . "\n" .
 883      EMAIL_TEXT_ORDER_NUMBER . ' ' . $zf_insert_id . "\n" .
 884      EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n" .
 885      EMAIL_TEXT_INVOICE_URL . ' ' . zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL', false) . "\n\n";
 886      $html_msg['EMAIL_TEXT_HEADER']     = EMAIL_TEXT_HEADER;
 887      $html_msg['EMAIL_TEXT_FROM']       = EMAIL_TEXT_FROM;
 888      $html_msg['INTRO_STORE_NAME']      = STORE_NAME;
 889      $html_msg['EMAIL_THANKS_FOR_SHOPPING'] = EMAIL_THANKS_FOR_SHOPPING;
 890      $html_msg['EMAIL_DETAILS_FOLLOW']  = EMAIL_DETAILS_FOLLOW;
 891      $html_msg['INTRO_ORDER_NUM_TITLE'] = EMAIL_TEXT_ORDER_NUMBER;
 892      $html_msg['INTRO_ORDER_NUMBER']    = $zf_insert_id;
 893      $html_msg['INTRO_DATE_TITLE']      = EMAIL_TEXT_DATE_ORDERED;
 894      $html_msg['INTRO_DATE_ORDERED']    = strftime(DATE_FORMAT_LONG);
 895      $html_msg['INTRO_URL_TEXT']        = EMAIL_TEXT_INVOICE_URL_CLICK;
 896      $html_msg['INTRO_URL_VALUE']       = zen_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $zf_insert_id, 'SSL', false);
 897  
 898      //comments area

 899      if ($this->info['comments']) {
 900        $email_order .= zen_db_output($this->info['comments']) . "\n\n";
 901        $html_msg['ORDER_COMMENTS'] = nl2br(zen_db_output($this->info['comments']));
 902      } else {
 903        $html_msg['ORDER_COMMENTS'] = '';
 904      }
 905  
 906      //products area

 907      $email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
 908      EMAIL_SEPARATOR . "\n" .
 909      $this->products_ordered .
 910      EMAIL_SEPARATOR . "\n";
 911      $html_msg['PRODUCTS_TITLE'] = EMAIL_TEXT_PRODUCTS;
 912      $html_msg['PRODUCTS_DETAIL']='<table class="product-details" border="0" width="100%" cellspacing="0" cellpadding="2">' . $this->products_ordered_html . '</table>';
 913  
 914      //order totals area

 915      $html_ot .= '<td class="order-totals-text" align="right" width="100%">' . '&nbsp;' . '</td> ' . "\n" . '<td class="order-totals-num" align="right" nowrap="nowrap">' . '---------' .'</td> </tr>' . "\n" . '<tr>';
 916      for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 917        $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
 918        $html_ot .= '<td class="order-totals-text" align="right" width="100%">' . $order_totals[$i]['title'] . '</td> ' . "\n" . '<td class="order-totals-num" align="right" nowrap="nowrap">' .($order_totals[$i]['text']) .'</td> </tr>' . "\n" . '<tr>';
 919      }
 920      $html_msg['ORDER_TOTALS'] = '<table border="0" width="100%" cellspacing="0" cellpadding="2">' . $html_ot . '</table>';
 921  
 922      //addresses area: Delivery

 923      $html_msg['HEADING_ADDRESS_INFORMATION']= HEADING_ADDRESS_INFORMATION;
 924      $html_msg['ADDRESS_DELIVERY_TITLE']     = EMAIL_TEXT_DELIVERY_ADDRESS;
 925      $html_msg['ADDRESS_DELIVERY_DETAIL']    = ($this->content_type != 'virtual') ? zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], true, '', "<br />") : 'n/a';
 926      $html_msg['SHIPPING_METHOD_TITLE']      = HEADING_SHIPPING_METHOD;
 927      $html_msg['SHIPPING_METHOD_DETAIL']     = (zen_not_null($this->info['shipping_method'])) ? $this->info['shipping_method'] : 'n/a';
 928  
 929      if ($this->content_type != 'virtual') {
 930        $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
 931        EMAIL_SEPARATOR . "\n" .
 932        zen_address_label($_SESSION['customer_id'], $_SESSION['sendto'], 0, '', "\n") . "\n";
 933      }
 934  
 935      //addresses area: Billing

 936      $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
 937      EMAIL_SEPARATOR . "\n" .
 938      zen_address_label($_SESSION['customer_id'], $_SESSION['billto'], 0, '', "\n") . "\n\n";
 939      $html_msg['ADDRESS_BILLING_TITLE']   = EMAIL_TEXT_BILLING_ADDRESS;
 940      $html_msg['ADDRESS_BILLING_DETAIL']  = zen_address_label($_SESSION['customer_id'], $_SESSION['billto'], true, '', "<br />");
 941  
 942      if (is_object($GLOBALS[$_SESSION['payment']])) {
 943        $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
 944        EMAIL_SEPARATOR . "\n";
 945        $payment_class = $_SESSION['payment'];
 946        $email_order .= $GLOBALS[$payment_class]->title . "\n\n";
 947        $email_order .= (isset($this->info['cc_type']) && $this->info['cc_type'] != '') ? $this->info['cc_type'] . "\n\n" : '';
 948        $email_order .= ($GLOBALS[$payment_class]->email_footer) ? $GLOBALS[$payment_class]->email_footer . "\n\n" : '';
 949      } else {
 950        $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
 951        EMAIL_SEPARATOR . "\n";
 952        $email_order .= PAYMENT_METHOD_GV . "\n\n";
 953      }
 954      $html_msg['PAYMENT_METHOD_TITLE']  = EMAIL_TEXT_PAYMENT_METHOD;
 955      $html_msg['PAYMENT_METHOD_DETAIL'] = (is_object($GLOBALS[$_SESSION['payment']]) ? $GLOBALS[$payment_class]->title : PAYMENT_METHOD_GV );
 956      $html_msg['PAYMENT_METHOD_FOOTER'] = (is_object($GLOBALS[$_SESSION['payment']]) && $GLOBALS[$payment_class]->email_footer != '') ? nl2br($GLOBALS[$payment_class]->email_footer) : $this->info['cc_type'];
 957  
 958      // include disclaimer

 959      $email_order .= "\n-----\n" . sprintf(EMAIL_DISCLAIMER, STORE_OWNER_EMAIL_ADDRESS) . "\n\n";
 960      // include copyright

 961      $email_order .= "\n-----\n" . EMAIL_FOOTER_COPYRIGHT . "\n\n";
 962  
 963      while (strstr($email_order, '&nbsp;')) $email_order = str_replace('&nbsp;', ' ', $email_order);
 964  
 965      $html_msg['EMAIL_FIRST_NAME'] = $this->customer['firstname'];
 966      $html_msg['EMAIL_LAST_NAME'] = $this->customer['lastname'];
 967      //  $html_msg['EMAIL_TEXT_HEADER'] = EMAIL_TEXT_HEADER;

 968      $html_msg['EXTRA_INFO'] = '';
 969      zen_mail($this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id, $email_order, STORE_NAME, EMAIL_FROM, $html_msg, 'checkout');
 970  
 971      // send additional emails

 972      if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
 973        $extra_info=email_collect_extra_info('','', $this->customer['firstname'] . ' ' . $this->customer['lastname'], $this->customer['email_address'], $this->customer['telephone']);
 974        $html_msg['EXTRA_INFO'] = $extra_info['HTML'];
 975              
 976        if ($GLOBALS[$_SESSION['payment']]->auth_code || $GLOBALS[$_SESSION['payment']]->transaction_id) {
 977          $pmt_details = 'AuthCode: ' . $GLOBALS[$_SESSION['payment']]->auth_code . '  TransID: ' . $GLOBALS[$_SESSION['payment']]->transaction_id . "\n\n";
 978          $email_order = $pmt_details . $email_order;
 979          $html_msg['EMAIL_TEXT_HEADER'] = nl2br($pmt_details) . $html_msg['EMAIL_TEXT_HEADER'];
 980        }
 981  
 982        zen_mail('', SEND_EXTRA_ORDER_EMAILS_TO, SEND_EXTRA_NEW_ORDERS_EMAILS_TO_SUBJECT . ' ' . EMAIL_TEXT_SUBJECT . EMAIL_ORDER_NUMBER_SUBJECT . $zf_insert_id,
 983        $email_order . $extra_info['TEXT'], STORE_NAME, EMAIL_FROM, $html_msg, 'checkout_extra');
 984      }
 985    }
 986  
 987  }
 988  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics