[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/includes/modules/payment/ -> chronopay.php (source)

   1  <?php
   2  /*
   3    $Id: chronopay.php 1782 2008-01-10 01:10:52Z user $
   4  
   5    osCMax Power E-Commerce
   6    http://oscdox.com
   7  
   8    Copyright 2008 osCMax
   9  
  10    Released under the GNU General Public License
  11  */
  12  
  13    class chronopay {
  14      var $code, $title, $description, $enabled;
  15  
  16  // class constructor
  17      function chronopay() {
  18        global $order;
  19  
  20        $this->signature = 'chronopay|chronopay|1.0|2.2';
  21  
  22        $this->code = 'chronopay';
  23        $this->title = MODULE_PAYMENT_CHRONOPAY_TEXT_TITLE;
  24        $this->public_title = MODULE_PAYMENT_CHRONOPAY_TEXT_PUBLIC_TITLE;
  25        $this->description = MODULE_PAYMENT_CHRONOPAY_TEXT_DESCRIPTION;
  26        $this->sort_order = MODULE_PAYMENT_CHRONOPAY_SORT_ORDER;
  27        $this->enabled = ((MODULE_PAYMENT_CHRONOPAY_STATUS == 'True') ? true : false);
  28  
  29        if ((int)MODULE_PAYMENT_CHRONOPAY_PREPARE_ORDER_STATUS_ID > 0) {
  30          $this->order_status = MODULE_PAYMENT_CHRONOPAY_PREPARE_ORDER_STATUS_ID;
  31        }
  32  
  33        if (is_object($order)) $this->update_status();
  34  
  35        $this->form_action_url = 'https://secure.chronopay.com/index_shop.cgi';
  36      }
  37  
  38  // class methods
  39      function update_status() {
  40        global $order;
  41  
  42        if ( ($this->enabled == true) && ((int)MODULE_PAYMENT_CHRONOPAY_ZONE > 0) ) {
  43          $check_flag = false;
  44          $check_query = tep_db_query("select zone_id from " . TABLE_ZONES_TO_GEO_ZONES . " where geo_zone_id = '" . MODULE_PAYMENT_CHRONOPAY_ZONE . "' and zone_country_id = '" . $order->billing['country']['id'] . "' order by zone_id");
  45          while ($check = tep_db_fetch_array($check_query)) {
  46            if ($check['zone_id'] < 1) {
  47              $check_flag = true;
  48              break;
  49            } elseif ($check['zone_id'] == $order->billing['zone_id']) {
  50              $check_flag = true;
  51              break;
  52            }
  53          }
  54  
  55          if ($check_flag == false) {
  56            $this->enabled = false;
  57          }
  58        }
  59      }
  60  
  61      function javascript_validation() {
  62        return false;
  63      }
  64  
  65      function selection() {
  66        global $cart_ChronoPay_ID;
  67  
  68        if (tep_session_is_registered('cart_ChronoPay_ID')) {
  69          $order_id = substr($cart_ChronoPay_ID, strpos($cart_ChronoPay_ID, '-')+1);
  70  
  71          $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');
  72  
  73          if (tep_db_num_rows($check_query) < 1) {
  74            tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
  75            tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
  76            tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
  77            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
  78            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
  79            tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
  80  
  81            tep_session_unregister('cart_ChronoPay_ID');
  82          }
  83        }
  84  
  85        return array('id' => $this->code,
  86                     'module' => $this->public_title);
  87      }
  88  
  89      function pre_confirmation_check() {
  90        global $cartID, $cart;
  91  
  92        if (empty($cart->cartID)) {
  93          $cartID = $cart->cartID = $cart->generate_cart_id();
  94        }
  95  
  96        if (!tep_session_is_registered('cartID')) {
  97          tep_session_register('cartID');
  98        }
  99      }
 100  
 101      function confirmation() {
 102        global $cartID, $cart_ChronoPay_ID, $customer_id, $languages_id, $order, $order_total_modules;
 103  
 104        if (tep_session_is_registered('cartID')) {
 105          $insert_order = false;
 106  
 107          if (tep_session_is_registered('cart_ChronoPay_ID')) {
 108            $order_id = substr($cart_ChronoPay_ID, strpos($cart_ChronoPay_ID, '-')+1);
 109  
 110            $curr_check = tep_db_query("select currency from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 111            $curr = tep_db_fetch_array($curr_check);
 112  
 113            if ( ($curr['currency'] != $order->info['currency']) || ($cartID != substr($cart_ChronoPay_ID, 0, strlen($cartID))) ) {
 114              $check_query = tep_db_query('select orders_id from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '" limit 1');
 115  
 116              if (tep_db_num_rows($check_query) < 1) {
 117                tep_db_query('delete from ' . TABLE_ORDERS . ' where orders_id = "' . (int)$order_id . '"');
 118                tep_db_query('delete from ' . TABLE_ORDERS_TOTAL . ' where orders_id = "' . (int)$order_id . '"');
 119                tep_db_query('delete from ' . TABLE_ORDERS_STATUS_HISTORY . ' where orders_id = "' . (int)$order_id . '"');
 120                tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS . ' where orders_id = "' . (int)$order_id . '"');
 121                tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . ' where orders_id = "' . (int)$order_id . '"');
 122                tep_db_query('delete from ' . TABLE_ORDERS_PRODUCTS_DOWNLOAD . ' where orders_id = "' . (int)$order_id . '"');
 123              }
 124  
 125              $insert_order = true;
 126            }
 127          } else {
 128            $insert_order = true;
 129          }
 130  
 131          if ($insert_order == true) {
 132            $order_totals = array();
 133            if (is_array($order_total_modules->modules)) {
 134              reset($order_total_modules->modules);
 135              while (list(, $value) = each($order_total_modules->modules)) {
 136                $class = substr($value, 0, strrpos($value, '.'));
 137                if ($GLOBALS[$class]->enabled) {
 138                  for ($i=0, $n=sizeof($GLOBALS[$class]->output); $i<$n; $i++) {
 139                    if (tep_not_null($GLOBALS[$class]->output[$i]['title']) && tep_not_null($GLOBALS[$class]->output[$i]['text'])) {
 140                      $order_totals[] = array('code' => $GLOBALS[$class]->code,
 141                                              'title' => $GLOBALS[$class]->output[$i]['title'],
 142                                              'text' => $GLOBALS[$class]->output[$i]['text'],
 143                                              'value' => $GLOBALS[$class]->output[$i]['value'],
 144                                              'sort_order' => $GLOBALS[$class]->sort_order);
 145                    }
 146                  }
 147                }
 148              }
 149            }
 150  
 151            $sql_data_array = array('customers_id' => $customer_id,
 152                                    'customers_name' => $order->customer['firstname'] . ' ' . $order->customer['lastname'],
 153                                    'customers_company' => $order->customer['company'],
 154                                    'customers_street_address' => $order->customer['street_address'],
 155                                    'customers_suburb' => $order->customer['suburb'],
 156                                    'customers_city' => $order->customer['city'],
 157                                    'customers_postcode' => $order->customer['postcode'],
 158                                    'customers_state' => $order->customer['state'],
 159                                    'customers_country' => $order->customer['country']['title'],
 160                                    'customers_telephone' => $order->customer['telephone'],
 161                                    'customers_email_address' => $order->customer['email_address'],
 162                                    'customers_address_format_id' => $order->customer['format_id'],
 163                                    'delivery_name' => $order->delivery['firstname'] . ' ' . $order->delivery['lastname'],
 164                                    'delivery_company' => $order->delivery['company'],
 165                                    'delivery_street_address' => $order->delivery['street_address'],
 166                                    'delivery_suburb' => $order->delivery['suburb'],
 167                                    'delivery_city' => $order->delivery['city'],
 168                                    'delivery_postcode' => $order->delivery['postcode'],
 169                                    'delivery_state' => $order->delivery['state'],
 170                                    'delivery_country' => $order->delivery['country']['title'],
 171                                    'delivery_address_format_id' => $order->delivery['format_id'],
 172                                    'billing_name' => $order->billing['firstname'] . ' ' . $order->billing['lastname'],
 173                                    'billing_company' => $order->billing['company'],
 174                                    'billing_street_address' => $order->billing['street_address'],
 175                                    'billing_suburb' => $order->billing['suburb'],
 176                                    'billing_city' => $order->billing['city'],
 177                                    'billing_postcode' => $order->billing['postcode'],
 178                                    'billing_state' => $order->billing['state'],
 179                                    'billing_country' => $order->billing['country']['title'],
 180                                    'billing_address_format_id' => $order->billing['format_id'],
 181                                    'payment_method' => $order->info['payment_method'],
 182                                    'cc_type' => $order->info['cc_type'],
 183                                    'cc_owner' => $order->info['cc_owner'],
 184                                    'cc_number' => $order->info['cc_number'],
 185                                    'cc_expires' => $order->info['cc_expires'],
 186                                    'date_purchased' => 'now()',
 187                                    'orders_status' => $order->info['order_status'],
 188                                    'currency' => $order->info['currency'],
 189                                    'currency_value' => $order->info['currency_value']);
 190  
 191            tep_db_perform(TABLE_ORDERS, $sql_data_array);
 192  
 193            $insert_id = tep_db_insert_id();
 194  
 195            for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 196              $sql_data_array = array('orders_id' => $insert_id,
 197                                      'title' => $order_totals[$i]['title'],
 198                                      'text' => $order_totals[$i]['text'],
 199                                      'value' => $order_totals[$i]['value'],
 200                                      'class' => $order_totals[$i]['code'],
 201                                      'sort_order' => $order_totals[$i]['sort_order']);
 202  
 203              tep_db_perform(TABLE_ORDERS_TOTAL, $sql_data_array);
 204            }
 205  
 206            for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 207              $sql_data_array = array('orders_id' => $insert_id,
 208                                      'products_id' => tep_get_prid($order->products[$i]['id']),
 209                                      'products_model' => $order->products[$i]['model'],
 210                                      'products_name' => $order->products[$i]['name'],
 211                                      'products_price' => $order->products[$i]['price'],
 212                                      'final_price' => $order->products[$i]['final_price'],
 213                                      'products_tax' => $order->products[$i]['tax'],
 214                                      'products_quantity' => $order->products[$i]['qty']);
 215  
 216              tep_db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
 217  
 218              $order_products_id = tep_db_insert_id();
 219  
 220              $attributes_exist = '0';
 221              if (isset($order->products[$i]['attributes'])) {
 222                $attributes_exist = '1';
 223                for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
 224                  if (DOWNLOAD_ENABLED == 'true') {
 225                    $attributes_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
 226                                         from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 227                                         left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 228                                         on pa.products_attributes_id=pad.products_attributes_id
 229                                         where pa.products_id = '" . $order->products[$i]['id'] . "'
 230                                         and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
 231                                         and pa.options_id = popt.products_options_id
 232                                         and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
 233                                         and pa.options_values_id = poval.products_options_values_id
 234                                         and popt.language_id = '" . $languages_id . "'
 235                                         and poval.language_id = '" . $languages_id . "'";
 236                    $attributes = tep_db_query($attributes_query);
 237                  } else {
 238                    $attributes = tep_db_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 = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
 239                  }
 240                  $attributes_values = tep_db_fetch_array($attributes);
 241  
 242                  $sql_data_array = array('orders_id' => $insert_id,
 243                                          'orders_products_id' => $order_products_id,
 244                                          'products_options' => $attributes_values['products_options_name'],
 245                                          'products_options_values' => $attributes_values['products_options_values_name'],
 246                                          'options_values_price' => $attributes_values['options_values_price'],
 247                                          'price_prefix' => $attributes_values['price_prefix']);
 248  
 249                  tep_db_perform(TABLE_ORDERS_PRODUCTS_ATTRIBUTES, $sql_data_array);
 250  
 251                  if ((DOWNLOAD_ENABLED == 'true') && isset($attributes_values['products_attributes_filename']) && tep_not_null($attributes_values['products_attributes_filename'])) {
 252                    $sql_data_array = array('orders_id' => $insert_id,
 253                                            'orders_products_id' => $order_products_id,
 254                                            'orders_products_filename' => $attributes_values['products_attributes_filename'],
 255                                            'download_maxdays' => $attributes_values['products_attributes_maxdays'],
 256                                            'download_count' => $attributes_values['products_attributes_maxcount']);
 257  
 258                    tep_db_perform(TABLE_ORDERS_PRODUCTS_DOWNLOAD, $sql_data_array);
 259                  }
 260                }
 261              }
 262            }
 263  
 264            $cart_ChronoPay_ID = $cartID . '-' . $insert_id;
 265            tep_session_register('cart_ChronoPay_ID');
 266          }
 267        }
 268  
 269        return false;
 270      }
 271  
 272      function process_button() {
 273        global $customer_id, $order, $currencies, $currency, $languages_id, $cart_ChronoPay_ID;
 274  
 275        switch ($order->billing['country']['iso_code_3']) {
 276          case 'USA':
 277          case 'CAN':
 278            $zone_query = tep_db_query("select zone_code from " . TABLE_ZONES . " where zone_id = '" . (int)$order->billing['zone_id'] . "'");
 279            $zone = tep_db_fetch_array($zone_query);
 280  
 281            $state_code = $zone['zone_code'];
 282            break;
 283  
 284          default:
 285            $state_code = 'XX';
 286            break;
 287        }
 288  
 289        $lang_query = tep_db_query("select code from " . TABLE_LANGUAGES . " where languages_id = '" . (int)$languages_id . "'");
 290        $lang = tep_db_fetch_array($lang_query);
 291  
 292        switch (strtoupper($lang['code'])) {
 293          case 'EN':
 294          case 'RU':
 295          case 'NL':
 296          case 'ES':
 297            $language_code = strtoupper($lang['code']);
 298            break;
 299  
 300          default:
 301            $language_code = strtoupper(DEFAULT_LANGUAGE);
 302        }
 303  
 304        $total_price = number_format($order->info['total'] * $currencies->get_value('USD'), $currencies->currencies['USD']['decimal_places'], '.', '');
 305        $order_id = substr($cart_ChronoPay_ID, strpos($cart_ChronoPay_ID, '-')+1);
 306  
 307        $process_button_string = tep_draw_hidden_field('product_id', MODULE_PAYMENT_CHRONOPAY_PRODUCT_ID) .
 308                                 tep_draw_hidden_field('product_name', STORE_NAME) .
 309                                 tep_draw_hidden_field('product_price', $total_price) .
 310                                 tep_draw_hidden_field('product_price_currency', $currency) .
 311                                 tep_draw_hidden_field('cb_url', urlencode(tep_href_link('ext/modules/payment/chronopay/callback.php', '' , 'SSL', true, true, true))) .
 312                                 tep_draw_hidden_field('cb_type', 'P') .
 313                                 tep_draw_hidden_field('decline_url', urlencode(tep_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL'))) .
 314                                 tep_draw_hidden_field('language', $language_code) .
 315                                 tep_draw_hidden_field('f_name', $order->billing['firstname']) .
 316                                 tep_draw_hidden_field('s_name', $order->billing['lastname']) .
 317                                 tep_draw_hidden_field('street', $order->billing['street_address']) .
 318                                 tep_draw_hidden_field('city', $order->billing['city']) .
 319                                 tep_draw_hidden_field('state', $state_code) .
 320                                 tep_draw_hidden_field('zip', $order->billing['postcode']) .
 321                                 tep_draw_hidden_field('country', $order->billing['country']['iso_code_3']) .
 322                                 tep_draw_hidden_field('phone', $order->customer['telephone']) .
 323                                 tep_draw_hidden_field('email', $order->customer['email_address']) .
 324                                 tep_draw_hidden_field('cs1', $customer_id) .
 325                                 tep_draw_hidden_field('cs2', $order_id) .
 326                                 tep_draw_hidden_field('cs3', md5(MODULE_PAYMENT_CHRONOPAY_PRODUCT_ID . $order_id . $customer_id . $total_price . MODULE_PAYMENT_CHRONOPAY_MD5_HASH));
 327  
 328        return $process_button_string;
 329      }
 330  
 331      function before_process() {
 332        global $customer_id, $order, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_ChronoPay_ID;
 333        global $$payment;
 334  
 335        $order_id = substr($cart_ChronoPay_ID, strpos($cart_ChronoPay_ID, '-')+1);
 336  
 337        $check_query = tep_db_query("select orders_status from " . TABLE_ORDERS . " where orders_id = '" . (int)$order_id . "'");
 338        if (tep_db_num_rows($check_query)) {
 339          $check = tep_db_fetch_array($check_query);
 340  
 341          if ($check['orders_status'] == MODULE_PAYMENT_CHRONOPAY_PREPARE_ORDER_STATUS_ID) {
 342            $sql_data_array = array('orders_id' => $order_id,
 343                                    'orders_status_id' => MODULE_PAYMENT_CHRONOPAY_PREPARE_ORDER_STATUS_ID,
 344                                    'date_added' => 'now()',
 345                                    'customer_notified' => '0',
 346                                    'comments' => '');
 347  
 348            tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 349          }
 350        }
 351  
 352        tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . (MODULE_PAYMENT_CHRONOPAY_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_CHRONOPAY_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID) . "', last_modified = now() where orders_id = '" . (int)$order_id . "'");
 353  
 354        $sql_data_array = array('orders_id' => $order_id,
 355                                'orders_status_id' => (MODULE_PAYMENT_CHRONOPAY_ORDER_STATUS_ID > 0 ? (int)MODULE_PAYMENT_CHRONOPAY_ORDER_STATUS_ID : (int)DEFAULT_ORDERS_STATUS_ID),
 356                                'date_added' => 'now()',
 357                                'customer_notified' => (SEND_EMAILS == 'true') ? '1' : '0',
 358                                'comments' => $order->info['comments']);
 359  
 360        tep_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);
 361  
 362  // initialized for the email confirmation
 363        $products_ordered = '';
 364        $subtotal = 0;
 365        $total_tax = 0;
 366  
 367        for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
 368  // Stock Update - Joao Correia
 369          if (STOCK_LIMITED == 'true') {
 370            if (DOWNLOAD_ENABLED == 'true') {
 371              $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename
 372                                  FROM " . TABLE_PRODUCTS . " p
 373                                  LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 374                                  ON p.products_id=pa.products_id
 375                                  LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 376                                  ON pa.products_attributes_id=pad.products_attributes_id
 377                                  WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
 378  // Will work with only one option for downloadable products
 379  // otherwise, we have to build the query dynamically with a loop
 380              $products_attributes = $order->products[$i]['attributes'];
 381              if (is_array($products_attributes)) {
 382                $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $products_attributes[0]['value_id'] . "'";
 383              }
 384              $stock_query = tep_db_query($stock_query_raw);
 385            } else {
 386              $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 387            }
 388            if (tep_db_num_rows($stock_query) > 0) {
 389              $stock_values = tep_db_fetch_array($stock_query);
 390  // do not decrement quantities if products_attributes_filename exists
 391              if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
 392                $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
 393              } else {
 394                $stock_left = $stock_values['products_quantity'];
 395              }
 396              tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 397              if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
 398                tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 399              }
 400            }
 401          }
 402  
 403  // Update products_ordered (for bestsellers list)
 404          tep_db_query("update " . TABLE_PRODUCTS . " set products_ordered = products_ordered + " . sprintf('%d', $order->products[$i]['qty']) . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
 405  
 406  //------insert customer choosen option to order--------
 407          $attributes_exist = '0';
 408          $products_ordered_attributes = '';
 409          if (isset($order->products[$i]['attributes'])) {
 410            $attributes_exist = '1';
 411            for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
 412              if (DOWNLOAD_ENABLED == 'true') {
 413                $attributes_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
 414                                     from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_OPTIONS_VALUES . " poval, " . TABLE_PRODUCTS_ATTRIBUTES . " pa
 415                                     left join " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
 416                                     on pa.products_attributes_id=pad.products_attributes_id
 417                                     where pa.products_id = '" . $order->products[$i]['id'] . "'
 418                                     and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "'
 419                                     and pa.options_id = popt.products_options_id
 420                                     and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "'
 421                                     and pa.options_values_id = poval.products_options_values_id
 422                                     and popt.language_id = '" . $languages_id . "'
 423                                     and poval.language_id = '" . $languages_id . "'";
 424                $attributes = tep_db_query($attributes_query);
 425              } else {
 426                $attributes = tep_db_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 = '" . $order->products[$i]['id'] . "' and pa.options_id = '" . $order->products[$i]['attributes'][$j]['option_id'] . "' and pa.options_id = popt.products_options_id and pa.options_values_id = '" . $order->products[$i]['attributes'][$j]['value_id'] . "' and pa.options_values_id = poval.products_options_values_id and popt.language_id = '" . $languages_id . "' and poval.language_id = '" . $languages_id . "'");
 427              }
 428              $attributes_values = tep_db_fetch_array($attributes);
 429  
 430              $products_ordered_attributes .= "\n\t" . $attributes_values['products_options_name'] . ' ' . $attributes_values['products_options_values_name'];
 431            }
 432          }
 433  //------insert customer choosen option eof ----
 434          $total_weight += ($order->products[$i]['qty'] * $order->products[$i]['weight']);
 435          $total_tax += tep_calculate_tax($total_products_price, $products_tax) * $order->products[$i]['qty'];
 436          $total_cost += $total_products_price;
 437  
 438          $products_ordered .= $order->products[$i]['qty'] . ' x ' . $order->products[$i]['name'] . ' (' . $order->products[$i]['model'] . ') = ' . $currencies->display_price($order->products[$i]['final_price'], $order->products[$i]['tax'], $order->products[$i]['qty']) . $products_ordered_attributes . "\n";
 439        }
 440  
 441  // lets start with the email confirmation
 442        $email_order = STORE_NAME . "\n" .
 443                       EMAIL_SEPARATOR . "\n" .
 444                       EMAIL_TEXT_ORDER_NUMBER . ' ' . $order_id . "\n" .
 445                       EMAIL_TEXT_INVOICE_URL . ' ' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO, 'order_id=' . $order_id, 'SSL', false) . "\n" .
 446                       EMAIL_TEXT_DATE_ORDERED . ' ' . strftime(DATE_FORMAT_LONG) . "\n\n";
 447        if ($order->info['comments']) {
 448          $email_order .= tep_db_output($order->info['comments']) . "\n\n";
 449        }
 450        $email_order .= EMAIL_TEXT_PRODUCTS . "\n" .
 451                        EMAIL_SEPARATOR . "\n" .
 452                        $products_ordered .
 453                        EMAIL_SEPARATOR . "\n";
 454  
 455        for ($i=0, $n=sizeof($order_totals); $i<$n; $i++) {
 456          $email_order .= strip_tags($order_totals[$i]['title']) . ' ' . strip_tags($order_totals[$i]['text']) . "\n";
 457        }
 458  
 459        if ($order->content_type != 'virtual') {
 460          $email_order .= "\n" . EMAIL_TEXT_DELIVERY_ADDRESS . "\n" .
 461                          EMAIL_SEPARATOR . "\n" .
 462                          tep_address_label($customer_id, $sendto, 0, '', "\n") . "\n";
 463        }
 464  
 465        $email_order .= "\n" . EMAIL_TEXT_BILLING_ADDRESS . "\n" .
 466                        EMAIL_SEPARATOR . "\n" .
 467                        tep_address_label($customer_id, $billto, 0, '', "\n") . "\n\n";
 468  
 469        if (is_object($$payment)) {
 470          $email_order .= EMAIL_TEXT_PAYMENT_METHOD . "\n" .
 471                          EMAIL_SEPARATOR . "\n";
 472          $payment_class = $$payment;
 473          $email_order .= $payment_class->title . "\n\n";
 474          if ($payment_class->email_footer) {
 475            $email_order .= $payment_class->email_footer . "\n\n";
 476          }
 477        }
 478  
 479        tep_mail($order->customer['firstname'] . ' ' . $order->customer['lastname'], $order->customer['email_address'], EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 480  
 481  // send emails to other people
 482        if (SEND_EXTRA_ORDER_EMAILS_TO != '') {
 483          tep_mail('', SEND_EXTRA_ORDER_EMAILS_TO, EMAIL_TEXT_SUBJECT, $email_order, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 484        }
 485  
 486  // load the after_process function from the payment modules
 487        $this->after_process();
 488  
 489        $cart->reset(true);
 490  
 491  // unregister session variables used during checkout
 492        tep_session_unregister('sendto');
 493        tep_session_unregister('billto');
 494        tep_session_unregister('shipping');
 495        tep_session_unregister('payment');
 496        tep_session_unregister('comments');
 497  
 498        tep_session_unregister('cart_ChronoPay_ID');
 499  
 500        tep_redirect(tep_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL'));
 501      }
 502  
 503      function after_process() {
 504        return false;
 505      }
 506  
 507      function output_error() {
 508        return false;
 509      }
 510  
 511      function check() {
 512        if (!isset($this->_check)) {
 513          $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_CHRONOPAY_STATUS'");
 514          $this->_check = tep_db_num_rows($check_query);
 515        }
 516        return $this->_check;
 517      }
 518  
 519      function install() {
 520        $check_query = tep_db_query("select orders_status_id from " . TABLE_ORDERS_STATUS . " where orders_status_name = 'Preparing [ChronoPay]' limit 1");
 521  
 522        if (tep_db_num_rows($check_query) < 1) {
 523          $status_query = tep_db_query("select max(orders_status_id) as status_id from " . TABLE_ORDERS_STATUS);
 524          $status = tep_db_fetch_array($status_query);
 525  
 526          $status_id = $status['status_id']+1;
 527  
 528          $languages = tep_get_languages();
 529  
 530          for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
 531            tep_db_query("insert into " . TABLE_ORDERS_STATUS . " (orders_status_id, language_id, orders_status_name) values ('" . $status_id . "', '" . $languages[$i]['id'] . "', 'Preparing [ChronoPay]')");
 532          }
 533  
 534          $flags_query = tep_db_query("describe " . TABLE_ORDERS_STATUS . " public_flag");
 535          if (tep_db_num_rows($flags_query) == 1) {
 536            tep_db_query("update " . TABLE_ORDERS_STATUS . " set public_flag = 0 and downloads_flag = 0 where orders_status_id = '" . $status_id . "'");
 537          }
 538        } else {
 539          $check = tep_db_fetch_array($check_query);
 540  
 541          $status_id = $check['orders_status_id'];
 542        }
 543  
 544        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Enable ChronoPay', 'MODULE_PAYMENT_CHRONOPAY_STATUS', 'False', 'Do you want to accept ChronoPay payments?', '6', '3', 'tep_cfg_select_option(array(\'True\', \'False\'), ', now())");
 545        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('ChronoPay Product ID', 'MODULE_PAYMENT_CHRONOPAY_PRODUCT_ID', '', 'The product ID to assign transactions to.', '6', '4', now())");
 546        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('MD5 Hash Signature', 'MODULE_PAYMENT_CHRONOPAY_MD5_HASH', '', 'Use this value to verify transactions with.', '6', '4', now())");
 547        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Payment Zone', 'MODULE_PAYMENT_CHRONOPAY_ZONE', '0', 'If a zone is selected, only enable this payment method for that zone.', '6', '2', 'tep_get_zone_class_title', 'tep_cfg_pull_down_zone_classes(', now())");
 548        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set Preparing Order Status', 'MODULE_PAYMENT_CHRONOPAY_PREPARE_ORDER_STATUS_ID', '" . $status_id . "', 'Set the status of prepared orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
 549        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, use_function, date_added) values ('Set ChronoPay Acknowledged Order Status', 'MODULE_PAYMENT_CHRONOPAY_ORDER_STATUS_ID', '0', 'Set the status of orders made with this payment module to this value', '6', '0', 'tep_cfg_pull_down_order_statuses(', 'tep_get_order_status_name', now())");
 550        tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort order of display.', 'MODULE_PAYMENT_CHRONOPAY_SORT_ORDER', '0', 'Sort order of display. Lowest is displayed first.', '6', '0', now())");
 551      }
 552  
 553      function remove() {
 554        tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys()) . "')");
 555      }
 556  
 557      function keys() {
 558        return array('MODULE_PAYMENT_CHRONOPAY_STATUS', 'MODULE_PAYMENT_CHRONOPAY_PRODUCT_ID', 'MODULE_PAYMENT_CHRONOPAY_MD5_HASH', 'MODULE_PAYMENT_CHRONOPAY_ZONE', 'MODULE_PAYMENT_CHRONOPAY_PREPARE_ORDER_STATUS_ID', 'MODULE_PAYMENT_CHRONOPAY_ORDER_STATUS_ID', 'MODULE_PAYMENT_CHRONOPAY_SORT_ORDER');
 559      }
 560    }
 561  ?>


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7