/** * This function palce the order * @return * 0 = Unable to insert order * -1 = Email is already Registered.Please Login * -2 = session expire (cart empty- if someone on ckout page in one tab and logged out from other tab) * */ function store() { $user = JFactory::getUser(); $buildadsession = JFactory::getSession(); $jinput = JFactory::getApplication()->input; $data = $jinput->post; $orderId = $data->get('order_id', '', "RAW"); // while placing order if (empty($orderId)) { $data = $this->recalculateData($data); //session expire if ($data === -2) { return -2; } } // GET BILLING AND SHIPPING ADDRESS $bill = $data->get('bill', array(), "ARRAY"); $ship = $data->get('ship', array(), "ARRAY"); $qtc_guest_regis = $data->get('qtc_guest_regis', '', "STRING"); if (!$user->id) { $user->id = 0; //Register a new User if Checkout Method is Register if (!empty($qtc_guest_regis) && $qtc_guest_regis != "guest") { $regdata['user_name'] = $bill['email1']; $regdata['user_email'] = $bill['email1']; JLoader::import('registration', JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'models'); $Quick2cartModelregistration = new Quick2cartModelregistration(); $mesage = $Quick2cartModelregistration->store($regdata); if ($mesage) { $user = JFactory::getUser(); $userid = $user->id; } else { return -1; } } } $row = new stdClass(); $params = JComponentHelper::getParams('com_quick2cart'); $isAllowedZeroPriceOrder = $params->get('orderWithZeroPrice', 0); // Edit from 1page ckout if (empty($orderId)) { if (empty($isAllowedZeroPriceOrder)) { // if FINAL orderPRICE <=0 THEN DONT ALLOW FOR ORDER //if ($data->get('final_amt_pay_inputbox') <= 0 || $data->get('total_amt_inputbox') <= 0 || !isset($data->get('gateways'))) if ($data->get('final_amt_pay_inputbox') <= 0) { return 0; } } } // Place order $timestamp = date("Y-m-d H:i:s"); // Get the IP Address if (!empty($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = 'unknown'; } $row->payee_id = $user->id; $row->user_info_id = $user->id; $row->name = $bill['fnam']; $row->email = $bill['email1']; if (empty($orderId)) { //vm:DONT UPDATE THESE THING WHILE UPDATING ORDER (1-PAGE-CKOUT) $row->amount = $data->get('final_amt_pay_inputbox'); $row->original_amount = $data->get('total_amt_inputbox'); $row->order_tax = $data->get('orderTax', 0); $order_tax_details = $data->get('order_tax_details', ''); $row->order_tax_details = isset($order_tax_details) ? $order_tax_details : json_encode(array()); $row->order_shipping = $data->get('qtcOrderShipcharges', '', "STRING"); $order_shipping_details = $data->get('order_shipping_details', '', "STRING"); // order level : Save shipping msg for order level shipping method $row->order_shipping_details = isset($order_shipping_details) ? $order_shipping_details : json_encode(array()); $row->coupon_code = $data->get('cop'); } // $row->coupon_discount = $dis_totalamt;//$cdiscount; $comment = $data->get('comment', '', 'RAW'); $row->customer_note = $comment ? nl2br($comment) : ''; $updateOrderstatus = 0; $gtway = $data->get('gateways'); // if ZERO ORDER (first time) or on edit if (empty($row->amount)) { // if ZERO ORDER and EDIT MODE (FOUND $data['order_id']) THEN DONT CHANGE GATEWAY $row->status = 'P'; // ORDER IS NOT PLACED if (empty($orderId)) { // FIRST TIME AND AMOUT =0 THEN USE FREE CKOUT PAYMENT METHOD $updateOrderstatus = 1; $row->processor = 'FreeCheckout'; //$data['gateways']; // vm:what should be place here? } else { // Order is placed and buyer editing something. Now fetch order price from D. // FETCH ORDER PRICE FRM db $orderFinalAMt = (int) $this->getFinalOrderPrice($orderId); } } else { $row->status = 'P'; // not free product and no geteway then return false /* if (!isset($gtway)) { return 0; } $row->processor = $gtway;*/ } $row->cdate = $timestamp; $row->mdate = $timestamp; $row->ip_address = $ip; $comquick2cartHelper = new comquick2cartHelper(); $row->currency = $comquick2cartHelper->getCurrencySession(); //$row->discount_type = $this->discount_type; @TODO coupon related??? $row->id = ''; if (!empty($orderId)) { //EDIT ORDER $row->id = $insert_order_id = $orderId; if (!$this->_db->updateObject('#__kart_orders', $row, 'id')) { echo $this->_db->stderr(); return 0; } } else { if (!$this->_db->insertObject('#__kart_orders', $row, 'id')) { echo $this->_db->stderr(); return 0; } $insert_order_id = $this->_db->insertid(); } // Code to pad zero's to $insert_order_id and append to prefix and update JLoader::import('payment', JPATH_SITE . DS . 'components' . DS . 'com_quick2cart' . DS . 'models'); $Quick2cartModelpayment = new Quick2cartModelpayment(); $prefix = $Quick2cartModelpayment->generate_prefix($insert_order_id); $row1 = new stdClass(); $row1->prefix = $prefix; $row1->id = $insert_order_id; if (!$this->_db->updateObject('#__kart_orders', $row1, 'id')) { echo $this->_db->stderr(); return 0; } // Get Cart item detail$taxdataf $Quick2cartModelcart = new Quick2cartModelcart(); $cart_id = $Quick2cartModelcart->getCartId(); $cart_itemsdata = $Quick2cartModelcart->getCartitems(); if (empty($orderId)) { $this->addSaveOrderItems($insert_order_id, $cart_itemsdata, $data, $updateOrderstatus); } // Store billing and shipping detail. $this->billingaddr($user->id, $data, $insert_order_id); //START Q2C Sample development $order_obj = array(); $order_obj['order'] = $row; $order_obj['items'] = $cart_itemsdata; $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin("system"); $result = $dispatcher->trigger("OnAfterq2cOrder", array($order_obj, $data)); //END Q2C Sample development /* $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('system'); $plgresult = $dispatcher->trigger('qtcAfterCheckoutDetailSave',array($row->id, $data)); */ @$comquick2cartHelper->sendordermail($row->id); return $insert_order_id; }