Exemple #1
0
 public function insert($status = 1)
 {
     global $lC_Database, $lC_Customer, $lC_Language, $lC_Currencies, $lC_ShoppingCart, $lC_Coupons, $lC_Tax;
     if (isset($_SESSION['prepOrderID'])) {
         $_prep = explode('-', $_SESSION['prepOrderID']);
         if ($_prep[0] == $lC_ShoppingCart->getCartID()) {
             return $_prep[1];
             // order_id
         } else {
             if (lC_Order::getStatusID($_prep[1]) === $status) {
                 lC_Order::remove($_prep[1]);
             }
         }
     }
     if ($lC_Customer->getID() == 0) {
         $customerName = 'New Customer';
     } else {
         if (isset($_SESSION['cartSync']['orderCreated']) && $_SESSION['cartSync']['orderCreated'] === TRUE) {
             return end(explode('-', $_SESSION['cartSync']['prepOrderID']));
             // order id
         }
         $customerName = $lC_Customer->getName();
     }
     $customer_address = lC_AddressBook::getEntry($lC_Customer->getDefaultAddressID())->toArray();
     // ppec inject
     if ($lC_ShoppingCart->getBillingMethod('id') != NULL && $_GET['ppec'] != 'process') {
         $payment_method = $GLOBALS['lC_Payment_' . $lC_ShoppingCart->getBillingMethod('id')]->getCode();
     } else {
         if (isset($_SESSION['cartSync']['paymentMethod']) && $_SESSION['cartSync']['paymentMethod'] != NULL) {
             $payment_method = $_SESSION['cartSync']['paymentMethod'];
         }
     }
     $Qorder = $lC_Database->query('insert into :table_orders (customers_id, customers_name, customers_company, customers_street_address, customers_suburb, customers_city, customers_postcode, customers_state, customers_state_code, customers_country, customers_country_iso2, customers_country_iso3, customers_telephone, customers_email_address, customers_address_format, customers_ip_address, delivery_name, delivery_company, delivery_street_address, delivery_suburb, delivery_city, delivery_postcode, delivery_state, delivery_state_code, delivery_country, delivery_country_iso2, delivery_country_iso3, delivery_address_format, billing_name, billing_company, billing_street_address, billing_suburb, billing_city, billing_postcode, billing_state, billing_state_code, billing_country, billing_country_iso2, billing_country_iso3, billing_address_format, payment_method, payment_module, date_purchased, orders_status, currency, currency_value) values (:customers_id, :customers_name, :customers_company, :customers_street_address, :customers_suburb, :customers_city, :customers_postcode, :customers_state, :customers_state_code, :customers_country, :customers_country_iso2, :customers_country_iso3, :customers_telephone, :customers_email_address, :customers_address_format, :customers_ip_address, :delivery_name, :delivery_company, :delivery_street_address, :delivery_suburb, :delivery_city, :delivery_postcode, :delivery_state, :delivery_state_code, :delivery_country, :delivery_country_iso2, :delivery_country_iso3, :delivery_address_format, :billing_name, :billing_company, :billing_street_address, :billing_suburb, :billing_city, :billing_postcode, :billing_state, :billing_state_code, :billing_country, :billing_country_iso2, :billing_country_iso3, :billing_address_format, :payment_method, :payment_module, now(), :orders_status, :currency, :currency_value)');
     $Qorder->bindTable(':table_orders', TABLE_ORDERS);
     $Qorder->bindInt(':customers_id', $lC_Customer->getID());
     $Qorder->bindValue(':customers_name', $customerName);
     $Qorder->bindValue(':customers_company', $customer_address['entry_company']);
     $Qorder->bindValue(':customers_street_address', $customer_address['entry_street_address']);
     $Qorder->bindValue(':customers_suburb', $customer_address['entry_suburb']);
     $Qorder->bindValue(':customers_city', $customer_address['entry_city']);
     $Qorder->bindValue(':customers_postcode', $customer_address['entry_postcode']);
     $Qorder->bindValue(':customers_state', !$customer_address['entry_state'] ? lC_Address::getZoneName($customer_address['entry_zone_id']) : $customer_address['entry_state']);
     $Qorder->bindValue(':customers_state_code', lC_Address::getZoneCode($customer_address['entry_zone_id']));
     $Qorder->bindValue(':customers_country', lC_Address::getCountryName($customer_address['entry_country_id']));
     $Qorder->bindValue(':customers_country_iso2', lC_Address::getCountryIsoCode2($customer_address['entry_country_id']));
     $Qorder->bindValue(':customers_country_iso3', lC_Address::getCountryIsoCode3($customer_address['entry_country_id']));
     $Qorder->bindValue(':customers_telephone', $customer_address['entry_telephone']);
     $Qorder->bindValue(':customers_email_address', $lC_Customer->getEmailAddress());
     $Qorder->bindValue(':customers_address_format', lC_Address::getFormat($customer_address['entry_country_id']));
     $Qorder->bindValue(':customers_ip_address', lc_get_ip_address());
     $Qorder->bindValue(':delivery_name', $lC_ShoppingCart->getShippingAddress('firstname') . ' ' . $lC_ShoppingCart->getShippingAddress('lastname'));
     $Qorder->bindValue(':delivery_company', $lC_ShoppingCart->getShippingAddress('company'));
     $Qorder->bindValue(':delivery_street_address', $lC_ShoppingCart->getShippingAddress('street_address'));
     $Qorder->bindValue(':delivery_suburb', $lC_ShoppingCart->getShippingAddress('suburb'));
     $Qorder->bindValue(':delivery_city', $lC_ShoppingCart->getShippingAddress('city'));
     $Qorder->bindValue(':delivery_postcode', $lC_ShoppingCart->getShippingAddress('postcode'));
     $Qorder->bindValue(':delivery_state', $lC_ShoppingCart->getShippingAddress('state'));
     $Qorder->bindValue(':delivery_state_code', $lC_ShoppingCart->getShippingAddress('zone_code'));
     $Qorder->bindValue(':delivery_country', $lC_ShoppingCart->getShippingAddress('country_title'));
     $Qorder->bindValue(':delivery_country_iso2', $lC_ShoppingCart->getShippingAddress('country_iso_code_2'));
     $Qorder->bindValue(':delivery_country_iso3', $lC_ShoppingCart->getShippingAddress('country_iso_code_3'));
     $Qorder->bindValue(':delivery_address_format', $lC_ShoppingCart->getShippingAddress('format'));
     $Qorder->bindValue(':billing_name', $lC_ShoppingCart->getBillingAddress('firstname') . ' ' . $lC_ShoppingCart->getBillingAddress('lastname'));
     $Qorder->bindValue(':billing_company', $lC_ShoppingCart->getBillingAddress('company'));
     $Qorder->bindValue(':billing_street_address', $lC_ShoppingCart->getBillingAddress('street_address'));
     $Qorder->bindValue(':billing_suburb', $lC_ShoppingCart->getBillingAddress('suburb'));
     $Qorder->bindValue(':billing_city', $lC_ShoppingCart->getBillingAddress('city'));
     $Qorder->bindValue(':billing_postcode', $lC_ShoppingCart->getBillingAddress('postcode'));
     $Qorder->bindValue(':billing_state', $lC_ShoppingCart->getBillingAddress('state'));
     $Qorder->bindValue(':billing_state_code', $lC_ShoppingCart->getBillingAddress('zone_code'));
     $Qorder->bindValue(':billing_country', $lC_ShoppingCart->getBillingAddress('country_title'));
     $Qorder->bindValue(':billing_country_iso2', $lC_ShoppingCart->getBillingAddress('country_iso_code_2'));
     $Qorder->bindValue(':billing_country_iso3', $lC_ShoppingCart->getBillingAddress('country_iso_code_3'));
     $Qorder->bindValue(':billing_address_format', $lC_ShoppingCart->getBillingAddress('format'));
     $Qorder->bindValue(':payment_method', $lC_ShoppingCart->getBillingMethod('title'));
     $Qorder->bindValue(':payment_module', $payment_method);
     $Qorder->bindInt(':orders_status', $status);
     $Qorder->bindValue(':currency', $lC_Currencies->getCode());
     $Qorder->bindValue(':currency_value', $lC_Currencies->value($lC_Currencies->getCode()));
     $Qorder->execute();
     $insert_id = $lC_Database->nextID();
     if (isset($_SESSION['cartSync']['orderCreated']) && $_SESSION['cartSync']['orderCreated'] === TRUE) {
         $_SESSION['cartSync']['orderID'] = $insert_id;
     }
     foreach ($lC_ShoppingCart->getOrderTotals() as $module) {
         $Qtotals = $lC_Database->query('insert into :table_orders_total (orders_id, title, text, value, class, sort_order) values (:orders_id, :title, :text, :value, :class, :sort_order)');
         $Qtotals->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
         $Qtotals->bindInt(':orders_id', $insert_id);
         $Qtotals->bindValue(':title', $module['title']);
         $Qtotals->bindValue(':text', strip_tags(str_replace(' ', '', $module['text'])));
         $Qtotals->bindValue(':value', $module['value']);
         $Qtotals->bindValue(':class', $module['code']);
         $Qtotals->bindInt(':sort_order', $module['sort_order']);
         $Qtotals->execute();
         if (defined('MODULE_SERVICES_INSTALLED') && in_array('coupons', explode(';', MODULE_SERVICES_INSTALLED)) && isset($lC_Coupons)) {
             if ($lC_Coupons->is_enabled) {
                 preg_match('#\\((.*?)\\)#', $module['title'], $match);
                 $lC_Coupons->redeem($match[1], $order_id);
             }
         }
     }
     $Qstatus = $lC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
     $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
     $Qstatus->bindInt(':orders_id', $insert_id);
     $Qstatus->bindInt(':orders_status_id', 1);
     $Qstatus->bindInt(':customer_notified', '0');
     $Qstatus->bindValue(':comments', '');
     $Qstatus->execute();
     // check for file upload and add to comments
     if (isset($_SESSION['file_upload'])) {
         $comments = '';
         if (is_array($_SESSION['file_upload']['name']) && empty($_SESSION['file_upload']['name']) === false) {
             foreach ($_SESSION['file_upload']['name'] as $file) {
                 if ($file == '') {
                     continue;
                 }
                 $comments .= '<div class="margin-left margin-bottom"><span class="icon-newspaper icon-size2 margin-right"></span><a target="_blank" href="' . DIR_WS_CATALOG . 'pub/' . $file . '">' . $file . '</a></div>';
             }
         } else {
             $comments = '<div class="margin-left margin-bottom"><span class="icon-newspaper icon-size2 margin-right"></span><a target="_blank" href="' . DIR_WS_CATALOG . 'pub/' . $_SESSION['file_upload']['name'] . '">' . $_SESSION['file_upload']['name'] . '</a></div>';
         }
         $Qstatus = $lC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
         $Qstatus->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
         $Qstatus->bindInt(':orders_id', $insert_id);
         $Qstatus->bindInt(':orders_status_id', 98);
         // file upload
         $Qstatus->bindInt(':customer_notified', '0');
         $Qstatus->bindValue(':comments', $comments);
         $Qstatus->execute();
     }
     foreach ($lC_ShoppingCart->getProducts() as $products) {
         $Qproducts = $lC_Database->query('insert into :table_orders_products (orders_id, products_id, products_model, products_sku, products_name, products_price, products_tax, products_quantity, products_simple_options_meta_data) values (:orders_id, :products_id, :products_model, :products_sku, :products_name, :products_price, :products_tax, :products_quantity, :products_simple_options_meta_data)');
         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qproducts->bindInt(':orders_id', $insert_id);
         $Qproducts->bindInt(':products_id', lc_get_product_id($products['id']));
         $Qproducts->bindValue(':products_model', $products['model']);
         $Qproducts->bindValue(':products_sku', $products['sku']);
         $Qproducts->bindValue(':products_name', $products['name']);
         $Qproducts->bindValue(':products_price', $products['price']);
         $Qproducts->bindValue(':products_tax', $lC_Tax->getTaxRate($products['tax_class_id']));
         $Qproducts->bindInt(':products_quantity', $products['quantity']);
         $Qproducts->bindValue(':products_simple_options_meta_data', serialize($products['simple_options']));
         $Qproducts->execute();
         $order_products_id = $lC_Database->nextID();
         if ($lC_ShoppingCart->isVariant($products['item_id'])) {
             foreach ($lC_ShoppingCart->getVariant($products['item_id']) as $variant) {
                 /* 
                 if (DOWNLOAD_ENABLED == '1') {
                   $Qattributes = $lC_Database->query('select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix, pad.products_attributes_maxdays, pad.products_attributes_maxcount, pad.products_attributes_filename from :table_products_options popt, :table_products_options_values poval, :table_products_attributes pa left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where pa.products_id = :products_id and pa.options_id = :options_id and pa.options_id = popt.products_options_id and pa.options_values_id = :options_values_id and pa.options_values_id = poval.products_options_values_id and popt.language_id = :popt_language_id and poval.language_id = :poval_language_id');
                   $Qattributes->bindTable(':table_products_options', TABLE_PRODUCTS_OPTIONS);
                   $Qattributes->bindTable(':table_products_options_values', TABLE_PRODUCTS_OPTIONS_VALUES);
                   $Qattributes->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES);
                   $Qattributes->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD);
                   $Qattributes->bindInt(':products_id', $products['id']);
                   $Qattributes->bindInt(':options_id', $attributes['options_id']);
                   $Qattributes->bindInt(':options_values_id', $attributes['options_values_id']);
                   $Qattributes->bindInt(':popt_language_id', $lC_Language->getID());
                   $Qattributes->bindInt(':poval_language_id', $lC_Language->getID());
                   $Qattributes->execute();
                 }
                 */
                 $Qvariant = $lC_Database->query('insert into :table_orders_products_variants (orders_id, orders_products_id, group_title, value_title) values (:orders_id, :orders_products_id, :group_title, :value_title)');
                 $Qvariant->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS);
                 $Qvariant->bindInt(':orders_id', $insert_id);
                 $Qvariant->bindInt(':orders_products_id', $order_products_id);
                 $Qvariant->bindValue(':group_title', $variant['group_title']);
                 $Qvariant->bindValue(':value_title', $variant['value_title']);
                 $Qvariant->execute();
                 /*
                 if ((DOWNLOAD_ENABLED == '1') && (strlen($Qattributes->value('products_attributes_filename')) > 0)) {
                   $Qopd = $lC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :download_maxdays, :download_count)');
                   $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
                   $Qopd->bindInt(':orders_id', $insert_id);
                   $Qopd->bindInt(':orders_products_id', $order_products_id);
                   $Qopd->bindValue(':orders_products_filename', $Qattributes->value('products_attributes_filename'));
                   $Qopd->bindValue(':download_maxdays', $Qattributes->value('products_attributes_maxdays'));
                   $Qopd->bindValue(':download_count', $Qattributes->value('products_attributes_maxcount'));
                   $Qopd->execute();
                 }
                 */
             }
         }
     }
     $_SESSION['prepOrderID'] = $lC_ShoppingCart->getCartID() . '-' . $insert_id;
     return $insert_id;
 }