Exemplo n.º 1
0
 /**
  * Get Unique order number
  *
  */
 public function getOrdernumber()
 {
     $order_functions = new order_functions();
     $trackid_time = $this->getOrdernumberTrack();
     if ($trackid_time != "") {
         $to_time = strtotime(date('Y-m-d H:i:s'));
         $from_time = strtotime($trackid_time);
         $total_minutes = round(abs($to_time - $from_time) / 60, 2);
         if ($total_minutes > 1) {
             $this->deleteOrdernumberTrack();
             $trackid_time = "";
         }
     }
     if ($trackid_time == "") {
         $this->insertOrdernumberTrack();
         $order_number = $order_functions->generateOrderNumber();
         return $order_number;
     } else {
         return $this->getOrdernumber();
     }
 }
Exemplo n.º 2
0
 public function save($apply = 0)
 {
     $post = JRequest::get('post');
     $adminproducthelper = new adminproducthelper();
     $order_functions = new order_functions();
     $shippinghelper = new shipping();
     $option = JRequest::getVar('option', '', 'request', 'string');
     $cid = JRequest::getVar('cid', array(0), 'post', 'array');
     $post['order_id'] = $cid[0];
     $model = $this->getModel('addorder_detail');
     $post['order_number'] = $order_number = $order_functions->generateOrderNumber();
     $orderItem = $adminproducthelper->redesignProductItem($post);
     $post['order_item'] = $orderItem;
     // Check product Quantity
     $stocknote = '';
     if (USE_STOCKROOM == 1) {
         $stockroomhelper = new rsstockroomhelper();
         $producthelper = new producthelper();
         for ($i = 0; $i < count($orderItem); $i++) {
             $quantity = $orderItem[$i]->quantity;
             $productData = $producthelper->getProductById($orderItem[$i]->product_id);
             if ($productData->min_order_product_quantity > 0 && $productData->min_order_product_quantity > $quantity) {
                 $msg = $productData->product_name . " " . JText::_('WARNING_MSG_MINIMUM_QUANTITY');
                 $stocknote .= sprintf($msg, $productData->min_order_product_quantity) . "<br/>";
                 $quantity = $productData->min_order_product_quantity;
             }
             $currentStock = $stockroomhelper->getStockroomTotalAmount($orderItem[$i]->product_id);
             $finalquantity = $currentStock >= $quantity ? (int) $quantity : (int) $currentStock;
             if ($finalquantity > 0) {
                 if ($productData->max_order_product_quantity > 0 && $productData->max_order_product_quantity < $finalquantity) {
                     $msg = $productData->product_name . " " . JText::_('WARNING_MSG_MAXIMUM_QUANTITY') . "<br/>";
                     $stocknote .= sprintf($msg, $productData->max_order_product_quantity);
                     $finalquantity = $productData->max_order_product_quantity;
                 }
                 $orderItem[$i]->quantity = $finalquantity;
             } else {
                 $stocknote .= $productData->product_name . " " . JText::_('PRODUCT_OUT_OF_STOCK') . "<br/>";
                 unset($orderItem[$i]);
             }
         }
         $orderItem = array_merge(array(), $orderItem);
         if (count($orderItem) <= 0) {
             $msg = JText::_('PRODUCT_OUT_OF_STOCK');
             $this->setRedirect('index.php?option=' . $option . '&view=addorder_detail&user_id=' . $post['user_id'] . '&shipping_users_info_id=' . $post['shipp_users_info_id'], $msg);
             return;
         }
     }
     $order_total = $post['order_total'];
     $order_shipping = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $post['shipping_rate_id'])));
     if (count($order_shipping) > 4) {
         $post['order_shipping'] = $order_shipping[3];
         $order_total = $order_total + $order_shipping[3];
         $post['order_shipping_tax'] = $order_shipping[6];
     }
     $tmporder_total = $order_total;
     if (array_key_exists("issplit", $post) && $post['issplit']) {
         $tmporder_total = $order_total / 2;
     }
     $paymentmethod = $order_functions->getPaymentMethodInfo($post['payment_method_class']);
     $paymentmethod = $paymentmethod[0];
     $paymentparams = new JRegistry($paymentmethod->params);
     $paymentinfo = new stdclass();
     $post['economic_payment_terms_id'] = $paymentparams->get('economic_payment_terms_id');
     $post['economic_design_layout'] = $paymentparams->get('economic_design_layout');
     $paymentinfo->payment_price = $paymentparams->get('payment_price', '');
     $paymentinfo->is_creditcard = $post['economic_is_creditcard'] = $paymentparams->get('is_creditcard', '');
     $paymentinfo->payment_oprand = $paymentparams->get('payment_oprand', '');
     $paymentinfo->accepted_credict_card = $paymentparams->get("accepted_credict_card");
     $paymentinfo->payment_discount_is_percent = $paymentparams->get('payment_discount_is_percent', '');
     $cartHelper = new rsCartHelper();
     $subtotal = $post['order_subtotal'];
     $update_discount = 0;
     if ($post['update_discount'] > 0) {
         $update_discount = $post['update_discount'];
         if ($update_discount > $subtotal) {
             $update_discount = $subtotal;
         }
         if ($update_discount != 0) {
             $order_total = $order_total - $update_discount;
         }
     }
     $special_discount = $post['special_discount'];
     $subtotal_excl_vat = 0;
     for ($i = 0; $i < count($orderItem); $i++) {
         $subtotal_excl_vat = $subtotal_excl_vat + $orderItem[$i]->prdexclprice * $orderItem[$i]->quantity;
     }
     if (APPLY_VAT_ON_DISCOUNT) {
         $amt = $subtotal;
     } else {
         $amt = $subtotal_excl_vat;
     }
     $discount_price = $amt * $special_discount / 100;
     $post['special_discount'] = $special_discount;
     $post['special_discount_amount'] = $discount_price;
     $order_total = $order_total - $discount_price;
     if (PAYMENT_CALCULATION_ON == 'subtotal') {
         $paymentAmount = $subtotal;
     } else {
         $paymentAmount = $order_total;
     }
     $paymentMethod = $cartHelper->calculatePayment($paymentAmount, $paymentinfo, $order_total);
     $post['ship_method_id'] = urldecode(urldecode($post['shipping_rate_id']));
     $order_total = $paymentMethod[0];
     $post['user_info_id'] = $post['users_info_id'];
     $post['payment_discount'] = $paymentMethod[1];
     $post['payment_oprand'] = $paymentinfo->payment_oprand;
     $post['order_discount'] = $update_discount;
     $post['order_total'] = $order_total;
     $post['order_payment_amount'] = $tmporder_total;
     $post['order_payment_name'] = $paymentmethod->name;
     if ($apply == 1) {
         $post['order_payment_status'] = 'Unpaid';
         $post['order_status'] = 'P';
     }
     if ($row = $model->store($post)) {
         $msg = JText::_('COM_REDSHOP_ORDER_DETAIL_SAVED');
     } else {
         $msg = JText::_('COM_REDSHOP_ERROR_SAVING_ORDER_DETAIL');
     }
     if ($apply == 1) {
         $objorder = new order_functions();
         $objorder->getpaymentinformation($row, $post);
     } else {
         $this->setRedirect('index.php?option=' . $option . '&view=order', $msg . $stocknote);
     }
 }
Exemplo n.º 3
0
 public function Orders_insert()
 {
     $producthelper = new producthelper();
     $order_functions = new order_functions();
     $query = "SELECT rui.users_info_id AS rui_users_info_id, vmo . * , rdo.vm_order_number AS rdo_order_number\r\n\t\t\t\tFROM (\r\n\t\t\t\t(\r\n\t\t\t\t#__vm_orders AS vmo\r\n\t\t\t\tLEFT JOIN " . $this->_table_prefix . "orders AS rdo ON rdo.vm_order_number = vmo.order_number\r\n\t\t\t\t)\r\n\t\t\t\tLEFT JOIN `" . $this->_table_prefix . "users_info` AS rui ON rui.user_id = vmo.user_id AND rui.address_type ='BT'\r\n\t\t\t\t)\r\n\t\t\t\tORDER BY vmo.order_id ASC";
     $this->_db->setQuery($query);
     $data = $this->_db->loadObjectList();
     $k = 0;
     for ($i = 0; $i <= count($data) - 1; $i++) {
         if ($data[$i]->rdo_order_number == null) {
             $order_number = $order_functions->generateOrderNumber();
             $reduser = $this->getTable('order_detail');
             $reduser->set('order_id', 0);
             $reduser->set('user_id', $data[$i]->user_id);
             $reduser->set('order_number', $order_number);
             $reduser->set('user_info_id', $data[$i]->rui_users_info_id);
             $reduser->set('order_total', $data[$i]->order_total);
             $reduser->set('order_subtotal', $data[$i]->order_subtotal);
             $reduser->set('order_tax', $data[$i]->order_tax);
             $reduser->set('order_tax_details', $data[$i]->order_tax_details);
             $reduser->set('order_shipping', $data[$i]->order_shipping);
             $reduser->set('order_shipping_tax', $data[$i]->order_shipping_tax);
             $reduser->set('coupon_discount', $data[$i]->coupon_discount);
             $reduser->set('order_discount', $data[$i]->order_discount);
             $reduser->set('order_status', $data[$i]->order_status);
             $reduser->set('order_payment_status', '');
             $reduser->set('cdate', $data[$i]->cdate);
             $reduser->set('mdate', $data[$i]->mdate);
             $reduser->set('ship_method_id', $data[$i]->ship_method_id);
             $reduser->set('customer_note', $data[$i]->customer_note);
             $reduser->set('ip_address', $data[$i]->ip_address);
             $reduser->set('vm_order_number', $data[$i]->order_number);
             if (!$reduser->store()) {
                 $this->setError($this->_db->getErrorMsg());
             } else {
                 $k++;
             }
             $last_insert = $reduser->order_id;
             // Copying VM Order_item Data To Redshop
             $order_item = "SELECT vmoi.*,rdoi.order_id AS rdoi_order_id " . ",rdp.product_id AS rdp_product_id " . "FROM `#__vm_order_item` AS vmoi " . "LEFT JOIN " . $this->_table_prefix . "order_item AS rdoi ON rdoi.order_id = '" . $last_insert . "' " . "LEFT JOIN " . $this->_table_prefix . "product AS rdp ON rdp.product_number = vmoi.order_item_sku " . "WHERE vmoi.order_id='" . $data[$i]->order_id . "' ";
             $this->_db->setQuery($order_item);
             $order_item = $this->_db->loadObjectList();
             for ($j = 0; $j <= count($order_item) - 1; $j++) {
                 $reduser = $this->getTable('order_item_detail');
                 $reduser->set('order_item_id', 0);
                 $reduser->set('order_id', $last_insert);
                 $reduser->set('user_info_id', $data[$i]->rui_users_info_id);
                 $reduser->set('product_id', $order_item[$j]->rdp_product_id);
                 $reduser->set('order_item_sku', $order_item[$j]->order_item_sku);
                 $reduser->set('order_item_name', $order_item[$j]->order_item_name);
                 $reduser->set('product_quantity', $order_item[$j]->product_quantity);
                 $reduser->set('product_item_price', $order_item[$j]->product_item_price);
                 $reduser->set('product_final_price', $order_item[$j]->product_final_price);
                 $reduser->set('order_item_currency', $order_item[$j]->order_item_currency);
                 $reduser->set('order_status', $order_item[$j]->order_status);
                 $reduser->set('cdate', $order_item[$j]->cdate);
                 $reduser->set('mdate', $order_item[$j]->mdate);
                 $reduser->set('product_attribute', $order_item[$j]->product_attribute);
                 if (!$reduser->store()) {
                     $this->setError($this->_db->getErrorMsg());
                 }
             }
             // Starting Copying VM order_payment Data to Redshop
             $order_item = "SELECT vmop.*,rdop.payment_order_id FROM `#__vm_order_payment` AS vmop " . "LEFT JOIN " . $this->_table_prefix . "order_payment AS rdop ON rdop.order_id = '" . $last_insert . "' " . "WHERE vmop.order_id = '" . $data[$i]->order_id . "' ";
             $this->_db->setQuery($order_item);
             $order_payment = $this->_db->loadObjectList();
             for ($l = 0; $l <= count($order_payment) - 1; $l++) {
                 if ($order_payment[$l]->payment_order_id == null) {
                     $reduser = $this->getTable('order_payment');
                     $reduser->set('payment_order_id', 0);
                     $reduser->set('order_id', $last_insert);
                     $reduser->set('payment_method_id', $order_payment[$l]->payment_method_id);
                     $reduser->set('order_payment_code', $order_user_info[$m]->order_payment_code);
                     $reduser->set('order_payment_number', $order_user_info[$m]->order_payment_number);
                     $reduser->set('order_payment_amount', $order_user_info[$m]->order_total);
                     $reduser->set('order_payment_expire', $order_user_info[$m]->order_payment_expire);
                     $reduser->set('order_payment_name', $order_payment[$l]->order_payment_name);
                     $reduser->set('order_payment_trans_id', $order_payment[$l]->order_payment_trans_id);
                     if (!$reduser->store()) {
                         $this->setError($this->_db->getErrorMsg());
                     }
                 }
             }
             // Starting Copying VM order_user_info to Redshop
             $order_item = "SELECT vmoui.*,rdoui.order_id as rdoui_order_id,rdui.users_info_id FROM (`#__vm_order_user_info` AS vmoui LEFT JOIN " . $this->_table_prefix . "users_info AS rdui ON rdui.user_id = vmoui.user_id) " . "LEFT JOIN " . $this->_table_prefix . "order_users_info as rdoui on rdoui.order_id = '" . $last_insert . "' " . "WHERE vmoui.order_id='" . $data[$i]->order_id . "' ";
             $this->_db->setQuery($order_item);
             $order_user_info = $this->_db->loadObjectList();
             for ($m = 0; $m <= count($order_user_info) - 1; $m++) {
                 if ($order_user_info[$m]->rdoui_order_id == null) {
                     $order_user_info[$m]->company == null ? $company = 0 : ($company = 1);
                     $reduser = $this->getTable('order_user_detail');
                     $reduser->set('order_info_id', 0);
                     $reduser->set('users_info_id', $order_user_info[$m]->users_info_id);
                     $reduser->set('order_id', $last_insert);
                     $reduser->set('user_id', $order_user_info[$m]->user_id);
                     $reduser->set('firstname', $order_user_info[$m]->first_name);
                     $reduser->set('lastname', $order_user_info[$m]->middle_name);
                     $reduser->set('address_type', $order_user_info[$m]->address_type);
                     $reduser->set('vat_number', '');
                     $reduser->set('tax_exempt', '');
                     $reduser->set('shopper_group_id', '');
                     $reduser->set('country_code', $order_user_info[$m]->country);
                     $reduser->set('state_code', $order_user_info[$m]->state);
                     $reduser->set('zipcode', $order_user_info[$m]->zip);
                     $reduser->set('tax_exempt_approved', '');
                     $reduser->set('approved', '');
                     $reduser->set('is_company', $company);
                     $reduser->set('phone', $order_user_info[$m]->phone_1);
                     $reduser->set('address', $order_user_info[$m]->address_1);
                     $reduser->set('city', $order_user_info[$m]->city);
                     $reduser->set('user_email', $order_user_info[$m]->user_email);
                     $reduser->set('company_name', $order_user_info[$m]->company);
                     if (!$reduser->store()) {
                         $this->setError($this->_db->getErrorMsg());
                     }
                 }
             }
         }
     }
     return $k;
 }