public function incrementCounter() { global $lC_Database, $lC_Language; $Qupdate = $lC_Database->query('update :table_products_description set products_viewed = products_viewed+1 where products_id = :products_id and language_id = :language_id'); $Qupdate->bindTable(':table_products_description', TABLE_PRODUCTS_DESCRIPTION); $Qupdate->bindInt(':products_id', lc_get_product_id($this->_data['id'])); $Qupdate->bindInt(':language_id', $lC_Language->getID()); $Qupdate->execute(); }
public function process($order_id, $status_id = '') { global $lC_Database, $lC_Customer, $lC_Language, $lC_Currencies, $lC_ShoppingCart, $lC_Coupons, $lC_Tax; if (empty($status_id) || is_numeric($status_id) === false) { $status_id = DEFAULT_ORDERS_STATUS_ID; } if (isset($_SESSION['cartSync']['orderCreated']) && $_SESSION['cartSync']['orderCreated'] === TRUE) { if (isset($_SESSION['cartSync']['orderID']) && $_SESSION['cartSync']['orderID'] != NULL) { $order_id = $_SESSION['cartSync']['orderID']; } // update the order info if ($lC_Customer->getDefaultAddressID() == '') { $lC_Customer->setCustomerData($lC_Customer->getID()); } $customer_address = lC_AddressBook::getEntry($lC_Customer->getDefaultAddressID())->toArray(); $Qupdate = $lC_Database->query('update :table_orders set customers_id = :customers_id, customers_name = :customers_name, customers_company = :customers_company, customers_street_address = :customers_street_address, customers_suburb = :customers_suburb, customers_city = :customers_city, customers_postcode = :customers_postcode, customers_state = :customers_state, customers_state_code = :customers_state_code, customers_country = :customers_country, customers_country_iso2 = :customers_country_iso2, customers_country_iso3 = :customers_country_iso3, customers_telephone = :customers_telephone, customers_email_address = :customers_email_address, customers_address_format = :customers_address_format, customers_ip_address = :customers_ip_address, delivery_name = :delivery_name, delivery_company = :delivery_company, delivery_street_address = :delivery_street_address, delivery_suburb = :delivery_suburb, delivery_city = :delivery_city, delivery_postcode = :delivery_postcode, delivery_state = :delivery_state, delivery_state_code = :delivery_state_code, delivery_country = :delivery_country, delivery_country_iso2 = :delivery_country_iso2, delivery_country_iso3 = :delivery_country_iso3, delivery_address_format = :delivery_address_format, billing_company = :billing_company, billing_street_address = :billing_street_address, billing_suburb = :billing_suburb, billing_city = :billing_city, billing_postcode = :billing_postcode, billing_state = :billing_state, billing_state_code = :billing_state_code, billing_country = :billing_country, billing_country_iso2 = :billing_country_iso2, billing_country_iso3 = :billing_country_iso3, billing_address_format = :billing_address_format, currency = :currency, currency_value = :currency_value, orders_status = :orders_status where orders_id = :orders_id'); $Qupdate->bindInt(':customers_id', $lC_Customer->getID()); $Qupdate->bindValue(':customers_name', $lC_Customer->getName()); $Qupdate->bindValue(':customers_company', $customer_address['entry_company']); $Qupdate->bindValue(':customers_street_address', $customer_address['entry_street_address']); $Qupdate->bindValue(':customers_suburb', $customer_address['entry_suburb']); $Qupdate->bindValue(':customers_city', $customer_address['entry_city']); $Qupdate->bindValue(':customers_postcode', $customer_address['entry_postcode']); $Qupdate->bindValue(':customers_state', $customer_address['entry_state']); $Qupdate->bindValue(':customers_state_code', lC_Address::getZoneCode($customer_address['entry_zone_id'])); $Qupdate->bindValue(':customers_country', lC_Address::getCountryName($customer_address['entry_country_id'])); $Qupdate->bindValue(':customers_country_iso2', lC_Address::getCountryIsoCode2($customer_address['entry_country_id'])); $Qupdate->bindValue(':customers_country_iso3', lC_Address::getCountryIsoCode3($customer_address['entry_country_id'])); $Qupdate->bindValue(':customers_telephone', $customer_address['entry_telephone']); $Qupdate->bindValue(':customers_email_address', $lC_Customer->getEmailAddress()); $Qupdate->bindValue(':customers_address_format', lC_Address::getFormat($customer_address['entry_country_id'])); $Qupdate->bindValue(':customers_ip_address', lc_get_ip_address()); $Qupdate->bindValue(':delivery_name', $lC_ShoppingCart->getShippingAddress('lastname') != NULL ? $lC_ShoppingCart->getShippingAddress('firstname') . ' ' . $lC_ShoppingCart->getShippingAddress('lastname') : $lC_Customer->getName()); $Qupdate->bindValue(':delivery_company', $lC_ShoppingCart->getShippingAddress('company')); $Qupdate->bindValue(':delivery_street_address', $lC_ShoppingCart->getShippingAddress('street_address')); $Qupdate->bindValue(':delivery_suburb', $lC_ShoppingCart->getShippingAddress('suburb')); $Qupdate->bindValue(':delivery_city', $lC_ShoppingCart->getShippingAddress('city')); $Qupdate->bindValue(':delivery_postcode', $lC_ShoppingCart->getShippingAddress('postcode')); $Qupdate->bindValue(':delivery_state', $lC_ShoppingCart->getShippingAddress('state')); $Qupdate->bindValue(':delivery_state_code', $lC_ShoppingCart->getShippingAddress('zone_code')); $Qupdate->bindValue(':delivery_country', $lC_ShoppingCart->getShippingAddress('country_title')); $Qupdate->bindValue(':delivery_country_iso2', $lC_ShoppingCart->getShippingAddress('country_iso_code_2')); $Qupdate->bindValue(':delivery_country_iso3', $lC_ShoppingCart->getShippingAddress('country_iso_code_3')); $Qupdate->bindValue(':delivery_address_format', $lC_ShoppingCart->getShippingAddress('format')); $Qupdate->bindValue(':billing_name', $lC_ShoppingCart->getBillingAddress('lastname') != NULL ? $lC_ShoppingCart->getBillingAddress('firstname') . ' ' . $lC_ShoppingCart->getBillingAddress('lastname') : $lC_Customer->getName()); $Qupdate->bindValue(':billing_company', $lC_ShoppingCart->getBillingAddress('company')); $Qupdate->bindValue(':billing_street_address', $lC_ShoppingCart->getBillingAddress('street_address')); $Qupdate->bindValue(':billing_suburb', $lC_ShoppingCart->getBillingAddress('suburb')); $Qupdate->bindValue(':billing_city', $lC_ShoppingCart->getBillingAddress('city')); $Qupdate->bindValue(':billing_postcode', $lC_ShoppingCart->getBillingAddress('postcode')); $Qupdate->bindValue(':billing_state', $lC_ShoppingCart->getBillingAddress('state')); $Qupdate->bindValue(':billing_state_code', $lC_ShoppingCart->getBillingAddress('zone_code')); $Qupdate->bindValue(':billing_country', $lC_ShoppingCart->getBillingAddress('country_title')); $Qupdate->bindValue(':billing_country_iso2', $lC_ShoppingCart->getBillingAddress('country_iso_code_2')); $Qupdate->bindValue(':billing_country_iso3', $lC_ShoppingCart->getBillingAddress('country_iso_code_3')); $Qupdate->bindValue(':billing_address_format', $lC_ShoppingCart->getBillingAddress('format')); $Qupdate->bindValue(':currency', $lC_Currencies->getCode()); $Qupdate->bindValue(':currency_value', $lC_Currencies->value($lC_Currencies->getCode())); $Qpt = $lC_Database->query('delete from :table_orders_total where orders_id = :orders_id'); $Qpt->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL); $Qpt->bindInt(':orders_id', $order_id); $Qpt->execute(); 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', $order_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); } } } $Qpd = $lC_Database->query('delete from :table_orders_products where orders_id = :orders_id'); $Qpd->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); $Qpd->bindInt(':orders_id', $order_id); $Qpd->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', $order_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) { $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(); } } } } else { $Qupdate = $lC_Database->query('update :table_orders set orders_status = :orders_status where orders_id = :orders_id'); } $Qupdate->bindTable(':table_orders', TABLE_ORDERS); $Qupdate->bindInt(':orders_status', $status_id); $Qupdate->bindInt(':orders_id', $order_id); $Qupdate->execute(); $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', $order_id); $Qstatus->bindInt(':orders_status_id', $status_id); $Qstatus->bindInt(':customer_notified', SEND_EMAILS == '1' ? '1' : '0'); $Qstatus->bindValue(':comments', isset($_SESSION['comments']) ? $_SESSION['comments'] : $_POST['comments']); $Qstatus->execute(); $lC_ShoppingCart->synchronizeWithDatabase(); $Qproducts = $lC_Database->query('select products_id, products_quantity from :table_orders_products where orders_id = :orders_id'); $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS); $Qproducts->bindInt(':orders_id', $order_id); $Qproducts->execute(); while ($Qproducts->next()) { if (STOCK_LIMITED == '1') { /**** still uses logic from the shopping cart class if (DOWNLOAD_ENABLED == '1') { $Qstock = $lC_Database->query('select products_quantity, pad.products_attributes_filename from :table_products p left join :table_products_attributes pa on (p.products_id = pa.products_id) left join :table_products_attributes_download pad on (pa.products_attributes_id = pad.products_attributes_id) where p.products_id = :products_id'); $Qstock->bindTable(':table_products', TABLE_PRODUCTS); $Qstock->bindTable(':table_products_attributes', TABLE_PRODUCTS_ATTRIBUTES); $Qstock->bindTable(':table_products_attributes_download', TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD); $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id')); // Will work with only one option for downloadable products otherwise, we have to build the query dynamically with a loop if ($lC_ShoppingCart->hasAttributes($products['id'])) { $products_attributes = $lC_ShoppingCart->getAttributes($products['id']); $products_attributes = array_shift($products_attributes); $Qstock->appendQuery('and pa.options_id = :options_id and pa.options_values_id = :options_values_id'); $Qstock->bindInt(':options_id', $products_attributes['options_id']); $Qstock->bindInt(':options_values_id', $products_attributes['options_values_id']); } } else { *****/ $Qstock = $lC_Database->query('select products_quantity from :table_products where products_id = :products_id'); $Qstock->bindTable(':table_products', TABLE_PRODUCTS); $Qstock->bindInt(':products_id', $Qproducts->valueInt('products_id')); // } $Qstock->execute(); if ($Qstock->numberOfRows() > 0) { $stock_left = $Qstock->valueInt('products_quantity'); // do not decrement quantities if products_attributes_filename exists // if ((DOWNLOAD_ENABLED == '-1') || ((DOWNLOAD_ENABLED == '1') && (strlen($Qstock->value('products_attributes_filename')) < 1))) { $stock_left = $stock_left - $Qproducts->valueInt('products_quantity'); $Qupdate = $lC_Database->query('update :table_products set products_quantity = :products_quantity where products_id = :products_id'); $Qupdate->bindTable(':table_products', TABLE_PRODUCTS); $Qupdate->bindInt(':products_quantity', $stock_left); $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id')); $Qupdate->execute(); // } if (AUTODISABLE_OUT_OF_STOCK_PRODUCT == '1' && $stock_left < 1) { $Qupdate = $lC_Database->query('update :table_products set products_status = 0 where products_id = :products_id'); $Qupdate->bindTable(':table_products', TABLE_PRODUCTS); $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id')); $Qupdate->execute(); } } } // Update products_ordered (for bestsellers list) $Qupdate = $lC_Database->query('update :table_products set products_ordered = products_ordered + :products_ordered where products_id = :products_id'); $Qupdate->bindTable(':table_products', TABLE_PRODUCTS); $Qupdate->bindInt(':products_ordered', $Qproducts->valueInt('products_quantity')); $Qupdate->bindInt(':products_id', $Qproducts->valueInt('products_id')); $Qupdate->execute(); } lC_Order::sendEmail($order_id); $_SESSION['savedOrderID'] = $order_id; unset($_SESSION['prepOrderID']); }