示例#1
0
 function process($order_id, $status_id = '', $comments = '')
 {
     global $osC_Database;
     if (empty($status_id) || is_numeric($status_id) === false) {
         $status_id = DEFAULT_ORDERS_STATUS_ID;
     }
     $Qstatus = $osC_Database->query('insert into :table_orders_status_history (orders_id, orders_status_id, date_added, customer_notified, comments) values (:orders_id, :orders_status_id, now(), :customer_notified, :comments)');
     $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', $comments);
     $Qstatus->execute();
     $Qupdate = $osC_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();
     $Qproducts = $osC_Database->query('select orders_products_id, 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()) {
         osC_Product::updateStock($order_id, $Qproducts->valueInt('orders_products_id'), $Qproducts->valueInt('products_id'), $Qproducts->valueInt('products_quantity'));
     }
     $order_status = self::getOrderStatusData($status_id);
     if ($order_status['downloads_flag'] == 1) {
         self::activeDownloadables($order_id);
     }
     if ($order_status['gift_certificates_flag'] == 1) {
         self::activeGiftCertificates($order_id);
     }
     osC_Order::sendEmail($order_id);
     unset($_SESSION['prepOrderID']);
 }
 /**
  * Add the products to this order.
  */
 function addProduct($products_id_string, $quantity, $gift_certificate_data = null)
 {
     global $osC_Database, $osC_Language, $osC_Tax;
     $error = false;
     $osC_Database->startTransaction();
     $products_id = osc_get_product_id($products_id_string);
     $variants = osc_parse_variants_from_id_string($products_id_string);
     $osC_Product = new osC_Product($products_id, $this->getCustomer('customers_id'));
     //If the products with the variants exists in the order, then increase the order quantity
     //Each gift certificate added to order will be considered as a new product
     //
     if (isset($this->_contents[$products_id_string])) {
         $orders_products_id = $this->_contents[$products_id_string]['orders_products_id'];
         $new_quantity = $this->_contents[$products_id_string]['quantity'] + $quantity;
         $Qupdate = $osC_Database->query('update :table_orders_products set products_quantity = :products_quantity, products_price = :products_price, final_price = :final_price, products_type = :products_type where orders_products_id = :orders_products_id ');
         $Qupdate->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qupdate->bindInt(':products_quantity', $new_quantity);
         $Qupdate->bindValue(':products_price', $osC_Product->getPrice($variants, $new_quantity));
         $Qupdate->bindValue(':final_price', $osC_Product->getPrice($variants, $new_quantity));
         $Qupdate->bindInt(':orders_products_id', $orders_products_id);
         $Qupdate->bindInt(':products_type', $osC_Product->getProductType());
         $Qupdate->setLogging($_SESSION['module'], $this->_order_id);
         $Qupdate->execute();
         if ($osC_Database->isError()) {
             $error = true;
         } else {
             $this->_contents[$products_id_string]['quantity'] = $new_quantity;
             $this->_contents[$products_id_string]['price'] = $osC_Product->getPrice($variants, $new_quantity);
             $this->_contents[$products_id_string]['final_price'] = $osC_Product->getPrice($variants, $new_quantity);
         }
     } else {
         $products_price = $osC_Product->getPrice($variants, $quantity);
         if ($osC_Product->isEmailGiftCertificate() && $osC_Product->isOpenAmountGiftCertificate()) {
             $products_price = $gift_certificate_data['price'];
         }
         $Qinsert = $osC_Database->query('insert into :table_orders_products (orders_id, products_id, products_sku, products_name, products_price, final_price, products_tax, products_quantity, products_type) values (:orders_id, :products_id, :products_sku, :products_name, :products_price, :final_price, :products_tax, :products_quantity, :products_type) ');
         $Qinsert->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qinsert->bindInt(':orders_id', $this->_order_id);
         $Qinsert->bindInt(':products_id', $osC_Product->getID());
         $Qinsert->bindValue(':products_sku', $osC_Product->getSKU());
         $Qinsert->bindValue(':products_name', $osC_Product->getTitle());
         $Qinsert->bindValue(':products_price', $products_price);
         $Qinsert->bindValue(':final_price', $products_price);
         $Qinsert->bindValue(':products_tax', $osC_Tax->getTaxRate($osC_Product->getTaxClassID(), $this->_shipping_address['country_id'], $this->_shipping_address['zone_id']));
         $Qinsert->bindInt(':products_quantity', $quantity);
         $Qinsert->bindInt(':products_type', $osC_Product->getProductType());
         $Qinsert->execute();
         if ($osC_Database->isError()) {
             $error = true;
         } else {
             $orders_products_id = $osC_Database->nextID();
             if (is_array($variants) && !empty($variants)) {
                 foreach ($variants as $groups_id => $values_id) {
                     $Qvariants = $osC_Database->query('select pvg.products_variants_groups_name, pvv.products_variants_values_name from :table_products_variants pv, :table_products_variants_entries pve, :table_products_variants_groups pvg, :table_products_variants_values pvv where pv.products_id = :products_id and pv.products_variants_id = pve.products_variants_id and pve.products_variants_groups_id = :groups_id and pve.products_variants_values_id = :variants_values_id and pve.products_variants_groups_id = pvg.products_variants_groups_id and pve.products_variants_values_id = pvv.products_variants_values_id and pvg.language_id = :language_id and pvv.language_id = :language_id');
                     $Qvariants->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                     $Qvariants->bindTable(':table_products_variants_entries', TABLE_PRODUCTS_VARIANTS_ENTRIES);
                     $Qvariants->bindTable(':table_products_variants_groups', TABLE_PRODUCTS_VARIANTS_GROUPS);
                     $Qvariants->bindTable(':table_products_variants_values', TABLE_PRODUCTS_VARIANTS_VALUES);
                     $Qvariants->bindInt(':products_id', $osC_Product->getID());
                     $Qvariants->bindInt(':groups_id', $groups_id);
                     $Qvariants->bindInt(':variants_values_id', $values_id);
                     $Qvariants->bindInt(':language_id', $osC_Language->getID());
                     $Qvariants->bindInt(':language_id', $osC_Language->getID());
                     $Qvariants->execute();
                     $Qinsert = $osC_Database->query('insert into :table_orders_products_variants (orders_id, orders_products_id, products_variants_groups_id, products_variants_groups, products_variants_values_id, products_variants_values) values (:orders_id, :orders_products_id, :products_variants_groups_id, :products_variants_groups, :products_variants_values_id, :products_variants_values) ');
                     $Qinsert->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS);
                     $Qinsert->bindInt(':orders_id', $this->_order_id);
                     $Qinsert->bindInt(':orders_products_id', $orders_products_id);
                     $Qinsert->bindInt(':products_variants_groups_id', $groups_id);
                     $Qinsert->bindValue(':products_variants_groups', $Qvariants->value('products_variants_groups_name'));
                     $Qinsert->bindInt(':products_variants_values_id', $values_id);
                     $Qinsert->bindValue(':products_variants_values', $Qvariants->value('products_variants_values_name'));
                     $Qinsert->setLogging($_SESSION['module'], $this->_order_id);
                     $Qinsert->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                         break;
                     }
                 }
             }
             if ($error === false) {
                 if ($osC_Product->getProductType() == PRODUCT_TYPE_DOWNLOADABLE) {
                     $Qdownloadable = $osC_Database->query('select * from :table_products_downloadables where products_id = :products_id');
                     $Qdownloadable->bindTable(':table_products_downloadables', TABLE_PRODUCTS_DOWNLOADABLES);
                     $Qdownloadable->bindInt(':products_id', $products_id);
                     $Qdownloadable->execute();
                     $Qopd = $osC_Database->query('insert into :table_orders_products_download (orders_id, orders_products_id, orders_products_filename, orders_products_cache_filename, download_maxdays, download_count) values (:orders_id, :orders_products_id, :orders_products_filename, :orders_products_cache_filename, :download_maxdays, :download_count)');
                     $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
                     $Qopd->bindInt(':orders_id', $_REQUEST['orders_id']);
                     $Qopd->bindInt(':orders_products_id', $orders_products_id);
                     $Qopd->bindValue(':orders_products_filename', $Qdownloadable->value('filename'));
                     $Qopd->bindValue(':orders_products_cache_filename', $Qdownloadable->value('cache_filename'));
                     $Qopd->bindValue(':download_maxdays', $Qdownloadable->valueInt('number_of_accessible_days'));
                     $Qopd->bindValue(':download_count', $Qdownloadable->valueInt('number_of_downloads'));
                     $Qopd->setLogging($_SESSION['module'], $this->_order_id);
                     $Qopd->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                     }
                 }
             }
             if ($error === false) {
                 if ($osC_Product->getProductType() == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     require_once '../includes/classes/gift_certificates.php';
                     $Qgc = $osC_Database->query('insert into :table_gift_certificates (orders_id, orders_products_id, gift_certificates_type, amount, gift_certificates_code, recipients_name, recipients_email, senders_name, senders_email, messages) values (:orders_id, :orders_products_id, :gift_certificates_type, :amount, :gift_certificates_code, :recipients_name, :recipients_email, :senders_name, :senders_email, :messages)');
                     $Qgc->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
                     $Qgc->bindInt(':orders_id', $_REQUEST['orders_id']);
                     $Qgc->bindInt(':gift_certificates_type', $gift_certificate_data['type']);
                     $Qgc->bindInt(':orders_products_id', $orders_products_id);
                     $Qgc->bindValue(':amount', $gift_certificate_data['price']);
                     $Qgc->bindValue(':gift_certificates_code', toC_Gift_Certificates::createGiftCertificateCode());
                     $Qgc->bindValue(':recipients_name', $gift_certificate_data['recipients_name']);
                     $Qgc->bindValue(':recipients_email', $gift_certificate_data['recipients_email']);
                     $Qgc->bindValue(':senders_name', $gift_certificate_data['senders_name']);
                     $Qgc->bindValue(':senders_email', $gift_certificate_data['senders_email']);
                     $Qgc->bindValue(':messages', $gift_certificate_data['message']);
                     $Qgc->setLogging($_SESSION['module'], $this->_order_id);
                     $Qgc->execute();
                     if ($osC_Database->isError()) {
                         $error = true;
                     }
                 }
             }
         }
         if ($error === false) {
             $this->_contents[$products_id_string] = array('id' => $products_id, 'orders_products_id' => $orders_products_id, 'quantity' => $quantity, 'name' => $osC_Product->getTitle(), 'sku' => $osC_Product->getSKU($variants_array), 'tax' => $osC_Tax->getTaxRate($osC_Product->getTaxClassID(), $this->_shipping_address['country_id'], $this->_shipping_address['zone_id']), 'price' => $product_price, 'final_price' => $products_price, 'weight' => $osC_Product->getWeight($variants), 'tax_class_id' => $osC_Product->getTaxClassID(), 'weight_class_id' => $osC_Product->getWeightClass());
         }
     }
     osC_Product::updateStock($this->_order_id, $orders_products_id, $products_id, $quantity);
     if ($error === false) {
         $osC_Database->commitTransaction();
         $this->_calculate();
         $this->updateOrderTotal();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }