Exemplo n.º 1
0
 function _updateStatus($id, $data)
 {
     global $osC_Database, $osC_Language, $orders_status_array;
     $error = false;
     $osC_Database->startTransaction();
     $orders_status = osC_OrdersStatus_Admin::getData($data['status_id']);
     if ($orders_status['downloads_flag'] == 1) {
         osC_Order::activeDownloadables($id);
     }
     if ($orders_status['gift_certificates_flag'] == 1) {
         osC_Order::activeGiftCertificates($id);
     }
     if ($data['status_id'] == ORDERS_STATUS_CANCELLED && $data['restock_products'] == true) {
         $Qproducts = $osC_Database->query('select orders_products_id, products_id, products_type, products_quantity from :table_orders_products where orders_id = :orders_id');
         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qproducts->bindInt(':orders_id', $id);
         $Qproducts->execute();
         while ($Qproducts->next()) {
             $result = osC_Product::restock($id, $Qproducts->valueInt('orders_products_id'), $Qproducts->valueInt('products_id'), $Qproducts->valueInt('products_quantity'));
             if ($result == false) {
                 $error = true;
                 break;
             }
         }
     }
     $Qupdate = $osC_Database->query('update :table_orders set orders_status = :orders_status, last_modified = now() where orders_id = :orders_id');
     $Qupdate->bindTable(':table_orders', TABLE_ORDERS);
     $Qupdate->bindInt(':orders_status', $data['status_id']);
     $Qupdate->bindInt(':orders_id', $id);
     $Qupdate->setLogging($_SESSION['module'], $id);
     $Qupdate->execute();
     if (!$osC_Database->isError()) {
         $Qupdate = $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)');
         $Qupdate->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
         $Qupdate->bindInt(':orders_id', $id);
         $Qupdate->bindInt(':orders_status_id', $data['status_id']);
         $Qupdate->bindInt(':customer_notified', $data['notify_customer'] === true ? '1' : '0');
         $Qupdate->bindValue(':comments', $data['comment']);
         $Qupdate->setLogging($_SESSION['module'], $id);
         $Qupdate->execute();
         if ($osC_Database->isError()) {
             $error = true;
         }
         if ($data['notify_customer'] === true) {
             $Qorder = $osC_Database->query('select o.customers_name, o.customers_email_address, s.orders_status_name, o.date_purchased from :table_orders o, :table_orders_status s where o.orders_status = s.orders_status_id and s.language_id = :language_id and o.orders_id = :orders_id');
             $Qorder->bindTable(':table_orders', TABLE_ORDERS);
             $Qorder->bindTable(':table_orders_status', TABLE_ORDERS_STATUS);
             $Qorder->bindInt(':language_id', $osC_Language->getID());
             $Qorder->bindInt(':orders_id', $id);
             $Qorder->execute();
             require_once '../includes/classes/email_template.php';
             $email_template = toC_Email_Template::getEmailTemplate('admin_order_status_updated');
             $email_template->setData($id, osc_href_link(FILENAME_ACCOUNT, 'orders=' . $id, 'SSL', false, true, true), osC_DateTime::getLong($Qorder->value('date_purchased')), $data['append_comment'], $data['comment'], $Qorder->value('orders_status_name'), $Qorder->value('customers_name'), $Qorder->value('customers_email_address'));
             $email_template->buildMessage();
             $email_template->sendEmail();
         }
     } else {
         $error = true;
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
 function deleteProduct($orders_products_id)
 {
     global $osC_Database;
     $error = false;
     $osC_Database->startTransaction();
     //find products_id_string
     $products_id_string = '';
     foreach ($this->_contents as $tmp_products_id_string => $tmp_product) {
         if ($orders_products_id == $this->_contents[$tmp_products_id_string]['orders_products_id']) {
             $products_id_string = $tmp_products_id_string;
         }
     }
     $products_id = osc_get_product_id($products_id_string);
     $osC_Product = new osC_Product($products_id, $this->getCustomer('customers_id'));
     $restock = osC_Product::restock($this->_order_id, $orders_products_id, osc_get_product_id($products_id_string), $this->_contents[$products_id_string]['quantity']);
     if ($restock === true) {
         $QdeleteVariants = $osC_Database->query('delete from :table_orders_products_variants where orders_products_id = :orders_products_id ');
         $QdeleteVariants->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS);
         $QdeleteVariants->bindInt(':orders_products_id', $orders_products_id);
         $QdeleteVariants->setLogging($_SESSION['module'], $this->_order_id);
         $QdeleteVariants->execute();
         if ($osC_Database->isError()) {
             $error = true;
         } else {
             $Qdelete = $osC_Database->query('delete from :table_orders_products where orders_products_id = :orders_products_id ');
             $Qdelete->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
             $Qdelete->bindInt(':orders_products_id', $orders_products_id);
             $Qdelete->setLogging($_SESSION['module'], $this->_order_id);
             $Qdelete->execute();
             if ($osC_Product->getProductType() == PRODUCT_TYPE_DOWNLOADABLE) {
                 $Qopd = $osC_Database->query('delete from :table_orders_products_download where orders_products_id = :orders_products_id');
                 $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
                 $Qopd->bindInt(':orders_products_id', $orders_products_id);
                 $Qopd->setLogging($_SESSION['module'], $this->_order_id);
                 $Qopd->execute();
             }
             if ($osC_Product->getProductType() == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                 $Qgc = $osC_Database->query('delete from :table_gift_certificates where orders_products_id = :orders_products_id');
                 $Qgc->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
                 $Qgc->bindInt(':orders_products_id', $orders_products_id);
                 $Qgc->setLogging($_SESSION['module'], $this->_order_id);
                 $Qgc->execute();
             }
             if ($osC_Database->isError()) {
                 $error = true;
             } else {
                 unset($this->_contents[$products_id_string]);
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         $this->_calculate(true);
         $this->updateOrderTotal();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }
Exemplo n.º 3
0
 function delete($id, $restock = false)
 {
     global $osC_Database;
     $error = false;
     $osC_Database->startTransaction();
     if ($restock === true) {
         $Qproducts = $osC_Database->query('select orders_products_id, products_id, products_type, products_quantity from :table_orders_products where orders_id = :orders_id');
         $Qproducts->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qproducts->bindInt(':orders_id', $id);
         $Qproducts->execute();
         while ($Qproducts->next()) {
             $result = osC_Product::restock($id, $Qproducts->valueInt('orders_products_id'), $Qproducts->valueInt('products_id'), $Qproducts->valueInt('products_quantity'));
             if ($result == false) {
                 $error = true;
                 break;
             }
         }
     }
     if ($error === false) {
         $Qproducts = $osC_Database->query('delete from :table_orders_refunds_products where orders_refunds_id = (select orders_refunds_id from :table_orders_refunds where orders_id = :orders_id) ');
         $Qproducts->bindTable(':table_orders_refunds_products', TABLE_ORDERS_REFUNDS_PRODUCTS);
         $Qproducts->bindTable(':table_orders_refunds', TABLE_ORDERS_REFUNDS);
         $Qproducts->bindInt(':orders_id', $id);
         $Qproducts->setLogging($_SESSION['module'], $id);
         $Qproducts->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qrefunds = $osC_Database->query('delete from :table_orders_refunds where orders_id = :orders_id');
         $Qrefunds->bindTable(':table_orders_refunds', TABLE_ORDERS_REFUNDS);
         $Qrefunds->bindInt(':orders_id', $id);
         $Qrefunds->setLogging($_SESSION['module'], $id);
         $Qrefunds->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qproducts = $osC_Database->query('delete from :table_orders_returns_products where orders_returns_id = (select orders_returns_id from :table_orders_returns where orders_id = :orders_id) ');
         $Qproducts->bindTable(':table_orders_returns_products', TABLE_ORDERS_RETURNS_PRODUCTS);
         $Qproducts->bindTable(':table_orders_returns', TABLE_ORDERS_RETURNS);
         $Qproducts->bindInt(':orders_id', $id);
         $Qproducts->setLogging($_SESSION['module'], $id);
         $Qproducts->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qreturns = $osC_Database->query('delete from :table_orders_returns where orders_id = :orders_id');
         $Qreturns->bindTable(':table_orders_returns', TABLE_ORDERS_RETURNS);
         $Qreturns->bindInt(':orders_id', $id);
         $Qreturns->setLogging($_SESSION['module'], $id);
         $Qreturns->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qopd = $osC_Database->query('delete from :table_orders_products_download where orders_id = :orders_id');
         $Qopd->bindTable(':table_orders_products_download', TABLE_ORDERS_PRODUCTS_DOWNLOAD);
         $Qopd->bindInt(':orders_id', $id);
         $Qopd->setLogging($_SESSION['module'], $id);
         $Qopd->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qgc = $osC_Database->query('delete from :table_gift_certificates where orders_id = :orders_id');
         $Qgc->bindTable(':table_gift_certificates', TABLE_GIFT_CERTIFICATES);
         $Qgc->bindInt(':orders_id', $id);
         $Qgc->setLogging($_SESSION['module'], $id);
         $Qgc->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qopa = $osC_Database->query('delete from :table_orders_products_variants where orders_id = :orders_id');
         $Qopa->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS);
         $Qopa->bindInt(':orders_id', $id);
         $Qopa->setLogging($_SESSION['module'], $id);
         $Qopa->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qop = $osC_Database->query('delete from :table_orders_products where orders_id = :orders_id');
         $Qop->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
         $Qop->bindInt(':orders_id', $id);
         $Qop->setLogging($_SESSION['module'], $id);
         $Qop->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qosh = $osC_Database->query('delete from :table_orders_transactions_history where orders_id = :orders_id');
         $Qosh->bindTable(':table_orders_transactions_history', TABLE_ORDERS_TRANSACTIONS_HISTORY);
         $Qosh->bindInt(':orders_id', $id);
         $Qosh->setLogging($_SESSION['module'], $id);
         $Qosh->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qosh = $osC_Database->query('delete from :table_orders_status_history where orders_id = :orders_id');
         $Qosh->bindTable(':table_orders_status_history', TABLE_ORDERS_STATUS_HISTORY);
         $Qosh->bindInt(':orders_id', $id);
         $Qosh->setLogging($_SESSION['module'], $id);
         $Qosh->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qot = $osC_Database->query('delete from :table_orders_total where orders_id = :orders_id');
         $Qot->bindTable(':table_orders_total', TABLE_ORDERS_TOTAL);
         $Qot->bindInt(':orders_id', $id);
         $Qot->setLogging($_SESSION['module'], $id);
         $Qot->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qo = $osC_Database->query('delete from :table_orders where orders_id = :orders_id');
         $Qo->bindTable(':table_orders', TABLE_ORDERS);
         $Qo->bindInt(':orders_id', $id);
         $Qo->setLogging($_SESSION['module'], $id);
         $Qo->execute();
         if ($osC_Database->isError() === true) {
             $error = true;
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         return true;
     } else {
         $osC_Database->rollbackTransaction();
         return false;
     }
 }
Exemplo n.º 4
0
 function createStoreCredit($data)
 {
     global $osC_Database, $osC_Language;
     $error = false;
     $osC_Database->startTransaction();
     //order refund
     $Qinsert = $osC_Database->query('insert into :table_orders_refunds (orders_refunds_type, orders_id, credit_slips_id, sub_total, shipping, handling, refund_total, comments, date_added) values (:orders_refunds_type, :orders_id, :credit_slips_id, :sub_total, :shipping, :handling, :refund_total, :comments, now())');
     $Qinsert->bindTable(':table_orders_refunds', TABLE_ORDERS_REFUNDS);
     $Qinsert->bindInt(':orders_refunds_type', ORDERS_RETURNS_TYPE_STORE_CREDIT);
     $Qinsert->bindInt(':orders_id', $data['orders_id']);
     $Qinsert->bindRaw(':credit_slips_id', 'null');
     $Qinsert->bindValue(':sub_total', $data['sub_total']);
     $Qinsert->bindValue(':shipping', $data['shipping_fee']);
     $Qinsert->bindValue(':handling', $data['handling']);
     $Qinsert->bindValue(':refund_total', $data['sub_total'] + $data['shipping_fee'] + $data['handling']);
     $Qinsert->bindValue(':comments', $data['comments']);
     $Qinsert->setLogging($_SESSION['module'], null);
     $Qinsert->execute();
     if ($osC_Database->isError()) {
         $error = true;
     } else {
         $orders_refunds_id = $osC_Database->nextID();
         //orders refunds products
         $return_products = explode(';', $data['return_quantity']);
         foreach ($return_products as $product) {
             list($orders_products_id, $quantity) = explode(':', $product);
             $Qproduct = $osC_Database->query('insert into :table_orders_refunds_products (orders_refunds_id, orders_products_id, products_quantity) values (:orders_refunds_id, :orders_products_id, :products_quantity)');
             $Qproduct->bindTable(':table_orders_refunds_products', TABLE_ORDERS_REFUNDS_PRODUCTS);
             $Qproduct->bindInt(':orders_refunds_id', $orders_refunds_id);
             $Qproduct->bindInt(':orders_products_id', $orders_products_id);
             $Qproduct->bindInt(':products_quantity', $quantity);
             $Qproduct->setLogging($_SESSION['module'], $orders_refunds_id);
             $Qproduct->execute();
             if ($osC_Database->isError()) {
                 $error = true;
                 break;
             }
             if ($error === false) {
                 $Qupdate = $osC_Database->query('update :table_orders_products set products_return_quantity = products_return_quantity + :products_return_quantity where orders_products_id = :orders_products_id');
                 $Qupdate->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
                 $Qupdate->bindInt(':products_return_quantity', $quantity);
                 $Qupdate->bindInt(':orders_products_id', $orders_products_id);
                 $Qupdate->setLogging($_SESSION['module'], $orders_refunds_id);
                 $Qupdate->execute();
                 if ($osC_Database->isError()) {
                     $error = true;
                     break;
                 }
             }
             if ($error === false && $data['restock_quantity'] === true) {
                 $Qcheck = $osC_Database->query('select products_id from :table_orders_products where orders_products_id = :orders_products_id and orders_id = :orders_id');
                 $Qcheck->bindTable(':table_orders_products', TABLE_ORDERS_PRODUCTS);
                 $Qcheck->bindInt(':orders_products_id', $orders_products_id);
                 $Qcheck->bindInt(':orders_id', $data['orders_id']);
                 $Qcheck->setLogging($_SESSION['module'], $orders_refunds_id);
                 $Qcheck->execute();
                 $products_id = $Qcheck->valueInt('products_id');
                 if (!osC_Product::restock($data['orders_id'], $orders_products_id, $products_id, $quantity)) {
                     $error = true;
                     break;
                 }
             }
         }
     }
     if ($error === false) {
         $Qreturn = $osC_Database->query('update :table_orders_returns set orders_returns_status_id = :orders_returns_status_id, admin_comments = :admin_comments, date_updated = now() where orders_returns_id = :id');
         $Qreturn->bindTable(':table_orders_returns', TABLE_ORDERS_RETURNS);
         $Qreturn->bindInt(':orders_returns_status_id', ORDERS_RETURNS_STATUS_REFUNDED_STORE_CREDIT);
         $Qreturn->bindValue(':admin_comments', $data['comment']);
         $Qreturn->bindInt(':id', $data['orders_returns_id']);
         $Qreturn->setLogging($_SESSION['module'], $data['orders_returns_id']);
         $Qreturn->execute();
         if ($osC_Database->isError()) {
             $error = true;
         }
     }
     if ($error === false) {
         $Qcustomer = $osC_Database->query('select customers_id from :table_orders where orders_id = :orders_id');
         $Qcustomer->bindTable(':table_orders', TABLE_ORDERS);
         $Qcustomer->bindInt(':orders_id', $data['orders_id']);
         $Qcustomer->execute();
         $customers_id = $Qcustomer->valueInt('customers_id');
         $Qhistory = $osC_Database->query('insert into :table_customers_credits_history (customers_id, action_type, date_added, amount, comments) values (:customers_id, :action_type, now(), :amount, :comments)');
         $Qhistory->bindTable(':table_customers_credits_history', TABLE_CUSTOMERS_CREDITS_HISTORY);
         $Qhistory->bindInt(':customers_id', $customers_id);
         $Qhistory->bindInt(':action_type', STORE_CREDIT_ACTION_TYPE_ORDER_REFUNDED);
         $Qhistory->bindValue(':amount', $data['sub_total'] + $data['shipping_fee'] + $data['handling']);
         $Qhistory->bindValue(':comments', sprintf($osC_Language->get('infomation_store_credit_from_order'), $data['orders_id']));
         $Qhistory->execute();
         if ($osC_Database->isError()) {
             $error = true;
         }
         if ($error === false) {
             $Qupdate = $osC_Database->query('update :table_customers set customers_credits = (customers_credits + :customers_credits) where customers_id = :customers_id');
             $Qupdate->bindTable(':table_customers', TABLE_CUSTOMERS);
             $Qupdate->bindRaw(':customers_credits', $data['sub_total'] + $data['shipping_fee'] + $data['handling']);
             $Qupdate->bindInt(':customers_id', $customers_id);
             $Qupdate->setLogging($_SESSION['module'], $data['$orders_refunds_id']);
             $Qupdate->execute();
             if ($osC_Database->isError()) {
                 $error = true;
             }
         }
     }
     if ($error === false) {
         $osC_Database->commitTransaction();
         $osC_Order = new osC_Order($data['orders_id']);
         $return_products_ids = array();
         $return_products_qty = array();
         $return_products = explode(';', $data['return_quantity']);
         foreach ($return_products as $product) {
             list($orders_products_id, $quantity) = explode(':', $product);
             $return_products_ids[] = $orders_products_id;
             $return_products_qty[$orders_products_id] = $quantity;
         }
         $products = array();
         foreach ($osC_Order->getProducts() as $product) {
             if (in_array($product['orders_products_id'], $return_products_ids)) {
                 $product_info = $return_products_qty[$product['orders_products_id']] . ' x ' . $product['name'];
                 if ($product['type'] == PRODUCT_TYPE_GIFT_CERTIFICATE) {
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_name') . ': ' . $product['senders_name'] . '</i></nobr>';
                     if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('senders_email') . ': ' . $product['senders_email'] . '</i></nobr>';
                     }
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_name') . ': ' . $product['recipients_name'] . '</i></nobr>';
                     if ($product['gift_certificates_type'] == GIFT_CERTIFICATE_TYPE_EMAIL) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('recipients_email') . ': ' . $product['recipients_email'] . '</i></nobr>';
                     }
                     $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $osC_Language->get('messages') . ': ' . $product['messages'] . '</i></nobr>';
                 }
                 if (isset($product['variants']) && is_array($product['variants']) && sizeof($product['variants']) > 0) {
                     foreach ($product['variants'] as $variants) {
                         $product_info .= '<br /><nobr>&nbsp;&nbsp;&nbsp;<i>' . $variants['groups_name'] . ': ' . $variants['values_name'] . '</i></nobr>';
                     }
                 }
                 $products[] = $product_info;
             }
         }
         $customers_name = $osC_Order->getCustomer('name');
         $customers_email_address = $osC_Order->getCustomer('email_address');
         require_once 'includes/classes/currencies.php';
         $osC_Currencies = new osC_Currencies_Admin();
         include '../includes/classes/email_template.php';
         $email_template = toC_Email_Template::getEmailTemplate('admin_create_order_store_credit');
         $email_template->setData($customers_name, $customers_email_address, implode('<br />', $products), $data['orders_id'], $osC_Currencies->format($data['sub_total'] + $data['shipping_fee'] + $data['handling']));
         $email_template->buildMessage();
         $email_template->sendEmail();
         return true;
     }
     $osC_Database->rollbackTransaction();
     return false;
 }