public function display($tpl = null) { $app = JFactory::getApplication(); $order_functions = new order_functions(); // Extra_field; $extra_field = new extraField(); $task = JRequest::getCmd('task'); $user = JFactory::getUser(); $uri = JFactory::getURI(); // Preform security checks $session = JFactory::getSession(); $auth = $session->get('auth'); $params = $app->getParams('com_redshop'); $lists = array(); if ($user->id) { $billingaddresses = $order_functions->getBillingAddress($user->id); } elseif (isset($auth['users_info_id']) && $auth['users_info_id']) { $model = $this->getModel('account_shipto'); $billingaddresses = $model->_loadData($auth['users_info_id']); } else { $app->Redirect('index.php?option=com_redshop&view=login&Itemid=' . JRequest::getInt('Itemid')); exit; } if ($task == 'addshipping') { JHTML::Script('jquery-1.4.2.min.js', 'components/com_redshop/assets/js/', false); JHTML::Script('jquery.validate.js', 'components/com_redshop/assets/js/', false); JHTML::Script('common.js', 'components/com_redshop/assets/js/', false); JHTML::Script('registration.js', 'components/com_redshop/assets/js/', false); JHTML::Stylesheet('validation.css', 'components/com_redshop/assets/css/'); $shippingaddresses = $this->get('Data'); if ($shippingaddresses->users_info_id > 0 && $shippingaddresses->user_id != $billingaddresses->user_id) { echo JText::_('COM_REDSHOP_ALERTNOTAUTH'); return; } $lists['shipping_customer_field'] = $extra_field->list_all_field(14, $shippingaddresses->users_info_id); $lists['shipping_company_field'] = $extra_field->list_all_field(15, $shippingaddresses->users_info_id); $this->setLayout('form'); } else { $shippingaddresses = $order_functions->getShippingAddress($user->id); } $this->lists = $lists; $this->shippingaddresses = $shippingaddresses; $this->billingaddresses = $billingaddresses; $this->request_url = $uri->toString(); $this->params = $params; parent::display($tpl); }
public function store($postdata) { $redshopMail = new redshopMail(); $order_functions = new order_functions(); $helper = new redhelper(); $producthelper = new producthelper(); $rsCarthelper = new rsCarthelper(); $shippinghelper = new shipping(); $adminproducthelper = new adminproducthelper(); $stockroomhelper = new rsstockroomhelper(); // For barcode generation $barcode_code = $order_functions->barcode_randon_number(12, 0); $postdata['barcode'] = $barcode_code; $row = $this->getTable('order_detail'); if (!$row->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$row->store()) { $this->setError($this->_db->getErrorMsg()); return false; } $iscrm = $helper->isredCRM(); if ($iscrm) { $postdata['order_id'] = $row->order_id; $postdata['debitor_id'] = $postdata['user_info_id']; JTable::addIncludePath(REDCRM_ADMIN . '/tables'); $crmorder =& $this->getTable('crm_order'); if (!$crmorder->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } if (!$crmorder->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Update rma table entry if (ENABLE_RMA && isset($postdata['rmanotes'])) { $rmaInfo = $this->getTable('rma_orders'); $rmaInfo->rma_number = $postdata['rma_number']; $rmaInfo->original_order_id = $postdata['main_order_id']; $rmaInfo->credit_note_order_id = $row->order_id; $rmaInfo->rma_note = $postdata['rmanotes']; $rmaInfo->store(); } JTable::addIncludePath(REDSHOP_ADMIN . '/tables'); } $order_shipping = explode("|", $shippinghelper->decryptShipping(str_replace(" ", "+", $row->ship_method_id))); $rowOrderStatus =& $this->getTable('order_status_log'); $rowOrderStatus->order_id = $row->order_id; $rowOrderStatus->order_status = $row->order_status; $rowOrderStatus->date_changed = time(); $rowOrderStatus->customer_note = $row->customer_note; $rowOrderStatus->store(); $billingaddresses = $order_functions->getBillingAddress($row->user_id); if (isset($postdata['billisship']) && $postdata['billisship'] == 1) { $shippingaddresses = $billingaddresses; } else { $key = 0; $shippingaddresses = $order_functions->getShippingAddress($row->user_id); $shipp_users_info_id = isset($postdata['shipp_users_info_id']) && $postdata['shipp_users_info_id'] != 0 ? $postdata['shipp_users_info_id'] : 0; if ($shipp_users_info_id != 0) { for ($o = 0; $o < count($shippingaddresses); $o++) { if ($shippingaddresses[$o]->users_info_id == $shipp_users_info_id) { $key = $o; break; } } } $shippingaddresses = $shippingaddresses[$key]; } // ORDER DELIVERY TIME IS REMAINING $user_id = $row->user_id; $item = $postdata['order_item']; for ($i = 0; $i < count($item); $i++) { $product_id = $item[$i]->product_id; $quantity = $item[$i]->quantity; $product_excl_price = $item[$i]->prdexclprice; $product_price = $item[$i]->productprice; // Attribute price added $generateAttributeCart = $rsCarthelper->generateAttributeArray((array) $item[$i], $user_id); $retAttArr = $producthelper->makeAttributeCart($generateAttributeCart, $product_id, $user_id, 0, $quantity); $product_attribute = $retAttArr[0]; // Accessory price $generateAccessoryCart = $rsCarthelper->generateAccessoryArray((array) $item[$i], $user_id); $retAccArr = $producthelper->makeAccessoryCart($generateAccessoryCart, $product_id, $user_id); $product_accessory = $retAccArr[0]; $accessory_total_price = $retAccArr[1]; $accessory_vat_price = $retAccArr[2]; $wrapper_price = 0; $wrapper_vat = 0; if ($item[$i]->wrapper_data != 0 && $item[$i]->wrapper_data != '') { $wrapper = $producthelper->getWrapper($product_id, $item[$i]->wrapper_data); if (count($wrapper) > 0) { if ($wrapper[0]->wrapper_price > 0) { $wrapper_vat = $producthelper->getProducttax($product_id, $wrapper[0]->wrapper_price, $user_id); } $wrapper_price = $wrapper[0]->wrapper_price + $wrapper_vat; } } $product = $producthelper->getProductById($product_id); $rowitem =& $this->getTable('order_item_detail'); if (!$rowitem->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } // STOCKROOM update $updatestock = $stockroomhelper->updateStockroomQuantity($product_id, $quantity); $stockroom_id_list = $updatestock['stockroom_list']; $stockroom_quantity_list = $updatestock['stockroom_quantity_list']; $rowitem->stockroom_id = $stockroom_id_list; $rowitem->stockroom_quantity = $stockroom_quantity_list; $rowitem->order_item_id = 0; $rowitem->order_id = $row->order_id; $rowitem->user_info_id = $row->user_info_id; $rowitem->supplier_id = $product->manufacturer_id; $rowitem->product_id = $product_id; $rowitem->order_item_sku = $product->product_number; $rowitem->order_item_name = $product->product_name; $rowitem->product_quantity = $quantity; $rowitem->product_item_price = $product_price; $rowitem->product_item_price_excl_vat = $product_excl_price; $rowitem->product_final_price = $product_price * $quantity; $rowitem->order_item_currency = REDCURRENCY_SYMBOL; $rowitem->order_status = $row->order_status; $rowitem->cdate = $row->cdate; $rowitem->mdate = $row->cdate; $rowitem->product_attribute = $product_attribute; $rowitem->product_accessory = $product_accessory; $rowitem->wrapper_id = $item[$i]->wrapper_data; $rowitem->wrapper_price = $wrapper_price; $rowitem->is_giftcard = 0; // RedCRM product purchase price if ($iscrm) { $crmProductHelper = new crmProductHelper(); $crmproduct = $crmProductHelper->getProductById($product_id); $rowitem->product_purchase_price = $crmproduct->product_purchase_price > 0 ? $crmproduct->product_purchase_price : $crmproduct->product_price; } if ($producthelper->checkProductDownload($product_id)) { $medianame = $producthelper->getProductMediaName($product_id); for ($j = 0; $j < count($medianame); $j++) { $product_serial_number = $producthelper->getProdcutSerialNumber($product_id); $producthelper->insertProductDownload($product_id, $user_id, $rowitem->order_id, $medianame[$j]->media_name, $product_serial_number->serial_number); } } if (!$rowitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } /** my accessory save in table start */ if (count($generateAccessoryCart) > 0) { $attArr = $generateAccessoryCart; for ($a = 0; $a < count($attArr); $a++) { $accessory_vat_price = 0; $accessory_attribute = ""; $accessory_id = $attArr[$a]['accessory_id']; $accessory_name = $attArr[$a]['accessory_name']; $accessory_price = $attArr[$a]['accessory_price']; $accessory_org_price = $accessory_price; if ($accessory_price > 0) { $accessory_vat_price = $producthelper->getProductTax($product_id, $accessory_price, $user_id); } $attchildArr = $attArr[$a]['accessory_childs']; for ($j = 0; $j < count($attchildArr); $j++) { $attribute_id = $attchildArr[$j]['attribute_id']; $accessory_attribute .= urldecode($attchildArr[$j]['attribute_name']) . ":<br/>"; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $attribute_id; $rowattitem->section = "attribute"; $rowattitem->parent_section_id = $accessory_id; $rowattitem->section_name = $attchildArr[$j]['attribute_name']; $rowattitem->is_accessory_att = 1; if ($attribute_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $propArr = $attchildArr[$j]['attribute_childs']; for ($k = 0; $k < count($propArr); $k++) { $section_vat = 0; if ($propArr[$k]['property_price'] > 0) { $section_vat = $producthelper->getProducttax($product_id, $propArr[$k]['property_price'], $user_id); } $property_id = $propArr[$k]['property_id']; $accessory_attribute .= urldecode($propArr[$k]['property_name']) . " (" . $propArr[$k]['property_oprand'] . $producthelper->getProductFormattedPrice($propArr[$k]['property_price'] + $section_vat) . ")<br/>"; $subpropArr = $propArr[$k]['property_childs']; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $property_id; $rowattitem->section = "property"; $rowattitem->parent_section_id = $attribute_id; $rowattitem->section_name = $propArr[$k]['property_name']; $rowattitem->section_price = $propArr[$k]['property_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $propArr[$k]['property_oprand']; $rowattitem->is_accessory_att = 1; if ($property_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } for ($l = 0; $l < count($subpropArr); $l++) { $section_vat = 0; if ($subpropArr[$l]['subproperty_price'] > 0) { $section_vat = $producthelper->getProducttax($rowitem->product_id, $subpropArr[$l]['subproperty_price'], $user_id); } $subproperty_id = $subpropArr[$l]['subproperty_id']; $accessory_attribute .= urldecode($subpropArr[$l]['subproperty_name']) . " (" . $subpropArr[$l]['subproperty_oprand'] . $producthelper->getProductFormattedPrice($subpropArr[$l]['subproperty_price'] + $section_vat) . ")<br/>"; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $subproperty_id; $rowattitem->section = "subproperty"; $rowattitem->parent_section_id = $property_id; $rowattitem->section_name = $subpropArr[$l]['subproperty_name']; $rowattitem->section_price = $subpropArr[$l]['subproperty_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand']; $rowattitem->is_accessory_att = 1; if ($subproperty_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } } $accdata =& $this->getTable('accessory_detail'); if ($accessory_id > 0) { $accdata->load($accessory_id); } $accProductinfo = $producthelper->getProductById($accdata->child_product_id); $rowaccitem =& $this->getTable('order_acc_item'); $rowaccitem->order_item_acc_id = 0; $rowaccitem->order_item_id = $rowitem->order_item_id; $rowaccitem->product_id = $accessory_id; $rowaccitem->order_acc_item_sku = $accProductinfo->product_number; $rowaccitem->order_acc_item_name = $accessory_name; $rowaccitem->order_acc_price = $accessory_org_price; $rowaccitem->order_acc_vat = $accessory_vat_price; $rowaccitem->product_quantity = $quantity; $rowaccitem->product_acc_item_price = $accessory_price; $rowaccitem->product_acc_final_price = $accessory_price * $quantity; $rowaccitem->product_attribute = $accessory_attribute; if ($accessory_id > 0) { if (!$rowaccitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } /** my attribute save in table start */ if (count($generateAttributeCart) > 0) { $attArr = $generateAttributeCart; for ($j = 0; $j < count($attArr); $j++) { $attribute_id = $attArr[$j]['attribute_id']; $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $attribute_id; $rowattitem->section = "attribute"; $rowattitem->parent_section_id = $rowitem->product_id; $rowattitem->section_name = $attArr[$j]['attribute_name']; $rowattitem->is_accessory_att = 0; if ($attribute_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $propArr = $attArr[$j]['attribute_childs']; for ($k = 0; $k < count($propArr); $k++) { $section_vat = 0; if ($propArr[$k]['property_price'] > 0) { $section_vat = $producthelper->getProducttax($rowitem->product_id, $propArr[$k]['property_price'], $user_id); } $property_id = $propArr[$k]['property_id']; /** product property STOCKROOM update start */ $updatestock = $stockroomhelper->updateStockroomQuantity($property_id, $quantity, "property"); $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $property_id; $rowattitem->section = "property"; $rowattitem->parent_section_id = $attribute_id; $rowattitem->section_name = $propArr[$k]['property_name']; $rowattitem->section_price = $propArr[$k]['property_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $propArr[$k]['property_oprand']; $rowattitem->is_accessory_att = 0; if ($property_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } $subpropArr = $propArr[$k]['property_childs']; for ($l = 0; $l < count($subpropArr); $l++) { $section_vat = 0; if ($subpropArr[$l]['subproperty_price'] > 0) { $section_vat = $producthelper->getProducttax($product_id, $subpropArr[$l]['subproperty_price'], $user_id); } $subproperty_id = $subpropArr[$l]['subproperty_id']; /** product subproperty STOCKROOM update start */ $updatestock = $stockroomhelper->updateStockroomQuantity($subproperty_id, $quantity, "subproperty"); $rowattitem =& $this->getTable('order_attribute_item'); $rowattitem->order_att_item_id = 0; $rowattitem->order_item_id = $rowitem->order_item_id; $rowattitem->section_id = $subproperty_id; $rowattitem->section = "subproperty"; $rowattitem->parent_section_id = $property_id; $rowattitem->section_name = $subpropArr[$l]['subproperty_name']; $rowattitem->section_price = $subpropArr[$l]['subproperty_price']; $rowattitem->section_vat = $section_vat; $rowattitem->section_oprand = $subpropArr[$l]['subproperty_oprand']; $rowattitem->is_accessory_att = 0; if ($subproperty_id > 0) { if (!$rowattitem->store()) { $this->setError($this->_db->getErrorMsg()); return false; } } } } } } // $producthelper->insertProdcutUserfield($i,$item,$rowitem->order_item_id,12); if (USE_CONTAINER) { $producthelper->updateContainerStock($product_id, $quantity, $rowitem->container_id); } // Store userfields $userfields = $item[$i]->extrafieldname; $userfields_id = $item[$i]->extrafieldId; for ($ui = 0; $ui < count($userfields); $ui++) { $adminproducthelper->admin_insertProdcutUserfield($userfields_id[$ui], $rowitem->order_item_id, 12, $userfields[$ui]); } // redCRM RMA Transaction Entry if ($iscrm) { if (ENABLE_RMA && $rowitem->product_final_price < 0) { // RMA transation log if (isset($item[$i]->reason)) { $rmaTrans =& $this->getTable('rma_transaction'); $rmaTrans->rma_transaction_id = 0; $rmaTrans->rma_number = $postdata['rma_number']; $rmaTrans->order_item_return_id = $rowitem->order_item_id; $rmaTrans->order_item_return_reason = $item[$i]->reason; $rmaTrans->order_item_return_status = $item[$i]->deposition; $rmaTrans->order_item_return_action = $item[$i]->action; $rmaTrans->cdate = time(); $rmaTrans->store(); if (ENABLE_ITEM_TRACKING_SYSTEM) { // Manage supplier order stock $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $senddata['main_order_number'] = $postdata['main_order_number']; $senddata['order_status'] = $row->order_status; $senddata['product_id'] = $rowitem->product_id; $senddata['property_id'] = $property_id; $senddata['subproperty_id'] = $subproperty_id; $senddata['deposition'] = $item[$i]->deposition; $itemqty = $rowitem->product_quantity; for ($r = 0; $r < $itemqty; $r++) { $crmSupplierOrderHelper->manageStockAffectedRMA($senddata); } } } } } } $rowpayment =& $this->getTable('order_payment'); if (!$rowpayment->bind($postdata)) { $this->setError($this->_db->getErrorMsg()); return false; } $rowpayment->order_id = $row->order_id; $rowpayment->payment_method_id = $postdata['payment_method_class']; $rowpayment->order_payment_amount = $row->order_total; $rowpayment->order_payment_name = $postdata['order_payment_name']; $rowpayment->payment_method_class = $postdata['payment_method_class']; if (!$rowpayment->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Add billing Info $userrow =& $this->getTable('user_detail'); $userrow->load($billingaddresses->users_info_id); $orderuserrow =& $this->getTable('order_user_detail'); if (!$orderuserrow->bind($userrow)) { $this->setError($this->_db->getErrorMsg()); return false; } $orderuserrow->order_id = $row->order_id; $orderuserrow->address_type = 'BT'; if (!$orderuserrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } // Add shipping Info $userrow =& $this->getTable('user_detail'); if (isset($shippingaddresses->users_info_id)) { $userrow->load($shippingaddresses->users_info_id); } $orderuserrow =& $this->getTable('order_user_detail'); if (!$orderuserrow->bind($userrow)) { $this->setError($this->_db->getErrorMsg()); return false; } $orderuserrow->order_id = $row->order_id; $orderuserrow->address_type = 'ST'; if (!$orderuserrow->store()) { $this->setError($this->_db->getErrorMsg()); return false; } if ($row->order_status == CLICKATELL_ORDER_STATUS) { $helper->clickatellSMS($row->order_id); } // Maintan supplier order stck when item tracking system is enabled if ($helper->isredCRM()) { if (ENABLE_ITEM_TRACKING_SYSTEM) { // Supplier order helper object $crmSupplierOrderHelper = new crmSupplierOrderHelper(); $getStatus = array(); $getStatus['orderstatus'] = $row->order_status; $getStatus['paymentstatus'] = $row->order_payment_status; $crmSupplierOrderHelper->redSHOPOrderUpdate($row->order_id, $getStatus); unset($getStatus); } } $checkOrderStatus = 1; if ($postdata['payment_method_class'] == "rs_payment_banktransfer" || $postdata['payment_method_class'] == "rs_payment_banktransfer_discount" || $postdata['payment_method_class'] == "rs_payment_banktransfer2" || $postdata['payment_method_class'] == "rs_payment_banktransfer3" || $postdata['payment_method_class'] == "rs_payment_banktransfer4" || $postdata['payment_method_class'] == "rs_payment_banktransfer5") { $checkOrderStatus = 0; } // Economic Integration start for invoice generate and book current invoice if (ECONOMIC_INTEGRATION == 1 && ECONOMIC_INVOICE_DRAFT != 2) { $issplit = 0; $economic = new economic(); if (isset($postdata['issplit']) && $postdata['issplit'] == 1) { $issplit = 1; } $economicdata['split_payment'] = $issplit; $economicdata['economic_payment_terms_id'] = $postdata['economic_payment_terms_id']; $economicdata['economic_design_layout'] = $postdata['economic_design_layout']; $economicdata['economic_is_creditcard'] = $postdata['economic_is_creditcard']; $payment_name = $postdata['payment_method_class']; $paymentArr = explode("rs_payment_", $postdata['payment_method_class']); if (count($paymentArr) > 0) { $payment_name = $paymentArr[1]; } $economicdata['economic_payment_method'] = $payment_name; $invoiceHandle = $economic->createInvoiceInEconomic($row->order_id, $economicdata); if (ECONOMIC_INVOICE_DRAFT == 0) { $bookinvoicepdf = $economic->bookInvoiceInEconomic($row->order_id, $checkOrderStatus); if (is_file($bookinvoicepdf)) { $ret = $redshopMail->sendEconomicBookInvoiceMail($row->order_id, $bookinvoicepdf); } } } // ORDER MAIL SEND if ($postdata['task'] != "save_without_sendmail") { $redshopMail->sendOrderMail($row->order_id); } return $row; }
public function display($tpl = null) { $option = JRequest::getVar('option'); $extra_field = new extra_field(); $order_functions = new order_functions(); $Redconfiguration = new Redconfiguration(); $document = JFactory::getDocument(); $document->setTitle(JText::_('COM_REDSHOP_ORDER')); $document->addScript('components/' . $option . '/assets/js/select_sort.js'); $document->addStyleSheet('components/' . $option . '/assets/css/search.css'); $document->addScript('components/' . $option . '/assets/js/search.js'); $document->addScript('components/' . $option . '/assets/js/json.js'); $document->addScript('components/' . $option . '/assets/js/validation.js'); $document->addScript('components/' . $option . '/assets/js/order.js'); $document->addScript('components/' . $option . '/assets/js/common.js'); $uri = JFactory::getURI(); $lists = array(); $billing = array(); $shippinginfo = array(); $model = $this->getModel(); $detail = $this->get('data'); $redhelper = new redhelper(); $payment_lang_list = $redhelper->getPlugins("redshop_payment"); $language = JFactory::getLanguage(); $base_dir = JPATH_ADMINISTRATOR; $language_tag = $language->getTag(); for ($l = 0; $l < count($payment_lang_list); $l++) { $extension = 'plg_redshop_payment_' . $payment_lang_list[$l]->element; $language->load($extension, $base_dir, $language_tag, true); } $err = JRequest::getVar('err', ''); $shipping_rate_id = JRequest::getVar('shipping_rate_id'); $user_id = JRequest::getVar('user_id', 0); if ($user_id != 0) { $billing = $order_functions->getBillingAddress($user_id); $shippinginfo = $order_functions->getShippingAddress($user_id); } else { $billing = $model->setBilling(); } $shipping_country = 0; $shipping_state = 0; $key = 0; $shippingop = array(); $shippingop[0] = new stdClass(); $shippingop[0]->users_info_id = 0; $shippingop[0]->text = JText::_('COM_REDSHOP_SELECT'); if (count($shippinginfo) > 0) { $shipping_users_info_id = JRequest::getVar('shipping_users_info_id', 0); if ($shipping_users_info_id != 0) { for ($o = 0; $o < count($shippinginfo); $o++) { if ($shippinginfo[$o]->users_info_id == $shipping_users_info_id) { $key = $o; break; } } $shipping_country = $shippinginfo[$key]->country_code; $shipping_state = $shippinginfo[$key]->state_code; } $shippingop = array_merge($shippingop, $shippinginfo); $billisship = $shippinginfo[$key]->billisship = $shipping_users_info_id ? 0 : 1; } else { $shippinginfo[0] = $model->setShipping(); $shipping_users_info_id = $shippinginfo[0]->users_info_id = 0; $billisship = $shippinginfo[0]->billisship; } $shdisable = $billisship ? "disabled" : ""; $detail->user_id = $user_id; $lists['shippinginfo_list'] = JHTML::_('select.genericlist', $shippingop, 'shipp_users_info_id', 'class="inputbox" ' . $shdisable . ' onchange="getShippinginfo(this.value, ' . $billing->is_company . ');" ', 'users_info_id', 'text', $shipping_users_info_id); $payment_detail = $this->get('payment'); JToolBarHelper::title(JText::_('COM_REDSHOP_ORDER') . ': <small><small>[ ' . JText::_('COM_REDSHOP_NEW') . ' ]</small></small>', 'redshop_order48'); if ($err == "" && array_key_exists("users_info_id", $billing) && $billing->users_info_id) { JToolBarHelper::custom('savepay', 'save.png', 'save_f2.png', 'Save + Pay', false); JToolBarHelper::custom('save_without_sendmail', 'save.png', 'save_f2.png', JText::_('COM_REDSHOP_SAVE_WITHOUT_SEND_ORDERMAIL_LBL'), false); JToolBarHelper::save(); } JToolBarHelper::cancel(); $countryarray = $Redconfiguration->getCountryList((array) $billing, "country_code", "BT"); $billing->country_code = $countryarray['country_code']; $lists['country_code'] = $countryarray['country_dropdown']; $statearray = $Redconfiguration->getStateList((array) $billing, "state_code", "country_code", "BT", 1); $lists['state_code'] = $statearray['state_dropdown']; $shipping['country_code_ST'] = $shippinginfo[$key]->country_code; $countryarray = $Redconfiguration->getCountryList((array) $shipping, "country_code_ST", "ST"); $shipping['country_code_ST'] = $shippinginfo[$key]->country_code = $countryarray['country_code_ST']; $lists['country_code_ST'] = $countryarray['country_dropdown']; $statearray = $Redconfiguration->getStateList((array) $shipping, "state_code_ST", "country_code_ST", "ST", 1); $lists['state_code_ST'] = $statearray['state_dropdown']; $lists['is_company'] = JHTML::_('select.booleanlist', 'is_company', 'class="inputbox" onchange="showOfflineCompanyOrCustomer(this.value);" ', $billing->is_company, JText::_('COM_REDSHOP_USER_COMPANY'), JText::_('COM_REDSHOP_USER_CUSTOMER')); $lists['customer_field'] = $extra_field->list_all_field(7, $billing->users_info_id); $lists['company_field'] = $extra_field->list_all_field(8, $billing->users_info_id); $lists['shipping_customer_field'] = $extra_field->list_all_field(14, $shippinginfo[0]->users_info_id); $lists['shipping_company_field'] = $extra_field->list_all_field(15, $shippinginfo[0]->users_info_id); $this->lists = $lists; $this->detail = $detail; $this->billing = $billing; $this->shipping = $shippinginfo[$key]; $this->shipping_users_info_id = $shipping_users_info_id; $this->payment_detail = $payment_detail; $this->shipping_rate_id = $shipping_rate_id; $this->request_url = $uri->toString(); parent::display($tpl); }
public function getfreeshippingRate($shipping_rate_id = 0) { $userhelper = new rsUserhelper(); $session = JFactory::getSession(); $cart = $session->get('cart', null); $db = JFactory::getDbo(); $idx = 0; if (isset($cart['idx']) === true) { $idx = (int) $cart['idx']; } $order_subtotal = isset($cart['product_subtotal']) ? $cart['product_subtotal'] : null; $order_functions = new order_functions(); $user = JFactory::getUser(); $user_id = $user->id; if (!empty($idx)) { $text = JText::_('COM_REDSHOP_NO_SHIPPING_RATE_AVAILABLE'); } else { return JText::_('COM_REDSHOP_NO_SHIPPING_RATE_AVAILABLE_WHEN_NOPRODUCT_IN_CART'); } $users_info_id = JRequest::getVar('users_info_id'); // Try to load user information $userInfo = null; $country = null; $state = null; $is_company = null; $shoppergroup = null; $zip = null; if ($user_id) { if ($users_info_id) { $userInfo = $this->getShippingAddress($users_info_id); } elseif ($userInfo = $order_functions->getShippingAddress($user_id)) { $userInfo = $userInfo[0]; } } $where = ''; $wherestate = ''; $whereshopper = ''; if (!$is_company) { $where = " AND ( company_only = 2 or company_only = 0) "; } else { $where = " AND ( company_only = 1 or company_only = 0) "; } if ($userInfo) { $country = $userInfo->country_code; $state = $userInfo->state_code; $is_company = $userInfo->is_company; $shoppergroup = $userhelper->getShoppergroupData($userInfo->user_id); $zip = $userInfo->zipcode; } if (count($shoppergroup) > 0) { $shopper_group_id = $shoppergroup->shopper_group_id; $whereshopper = ' AND (FIND_IN_SET(' . (int) $shopper_group_id . ', shipping_rate_on_shopper_group ) OR shipping_rate_on_shopper_group="") '; } $shippingrate = array(); if ($country) { $wherecountry = 'AND (FIND_IN_SET(' . $db->quote($country) . ', shipping_rate_country ) OR shipping_rate_country="0" OR shipping_rate_country="" )'; } else { $wherecountry = 'AND (FIND_IN_SET(' . $db->quote(DEFAULT_SHIPPING_COUNTRY) . ', shipping_rate_country ) OR shipping_rate_country="0" OR shipping_rate_country="")'; } if ($state) { $wherestate = ' AND (FIND_IN_SET(' . $db->quote($state) . ', shipping_rate_state ) OR shipping_rate_state="0" OR shipping_rate_state="")'; } $zipCond = ""; $zip = trim($zip); if (preg_match('/^[0-9 ]+$/', $zip) && !empty($zip)) { $zipCond = ' AND ( ( shipping_rate_zip_start <= ' . $db->quote($zip) . ' AND shipping_rate_zip_end >= ' . $db->quote($zip) . ' ) OR (shipping_rate_zip_start = "0" AND shipping_rate_zip_end = "0") OR (shipping_rate_zip_start = "" AND shipping_rate_zip_end = "") ) '; } if ($shipping_rate_id) { $where .= ' AND sr.shipping_rate_id = ' . (int) $shipping_rate_id . ' '; } $sql = "SELECT * FROM " . $this->_table_prefix . "shipping_rate as sr\n\t\t\t\t\t\t\t\t LEFT JOIN #__extensions AS s\n\t\t\t\t\t\t\t\t ON\n\t\t\t\t\t\t\t\t sr.shipping_class = s.element\n\t\t\t\t\t\t\t\t WHERE (shipping_rate_value =0 OR shipping_rate_value ='0')\n\n\t\t\t\t{$wherecountry} {$wherestate} {$whereshopper} {$zipCond} {$where}\n\t\t\t\tORDER BY s.ordering,sr.shipping_rate_priority LIMIT 0,1"; $db->setQuery($sql); $shippingrate = $db->loadObject(); if ($shippingrate) { if ($shippingrate->shipping_rate_ordertotal_start > $order_subtotal) { $diff = $shippingrate->shipping_rate_ordertotal_start - $order_subtotal; $text = sprintf(JText::_('COM_REDSHOP_SHIPPING_TEXT_LBL'), $this->producthelper->getProductFormattedPrice($diff)); } elseif ($shippingrate->shipping_rate_ordertotal_start < $order_subtotal && $shippingrate->shipping_rate_ordertotal_end > $order_subtotal) { $text = JText::_('COM_REDSHOP_FREE_SHIPPING_RATE_IS_IN_USED'); } else { $text = JText::_('COM_REDSHOP_NO_SHIPPING_RATE_AVAILABLE'); } } return $text; }