private function getOrderDetails($id) { if ($id != "") { $this->orderModel = $this->orderModel->fetchOrderById($id); if ($this->orderModel != null) { $orderProdModel = new OrderProdsModel(); $orderProds = $orderProdModel->fetchByOrderid($this->orderModel->getOrderid()); if ($orderProds != null) { // fetch order and template ids foreach ($orderProds as $k => $op) { $tid = $op->getTid(); $pid = $op->getPid(); if ($tid > 0) { $tids[] = $tid; $pids[] = $pid; } else { $product_ids[] = $pid; } $data['orderdetail'][$tid]['op'] = $op; } // fetch ordered template details if (is_array($tids) && count($tids) > 0) { $prodModel = new ProductModel(); $templModel = new UsertemplateModel(); $products = $prodModel->fetchProductsfromIds(implode(",", $pids)); $templates = $templModel->fetchTemplatesfromIds(implode(",", $tids)); if (is_array($templates) && count($templates) > 0) { foreach ($templates as $templ) { foreach ($products as $prod) { if ($templ->getProductid() == $prod->getProductId()) { $data['orderdetail'][$templ->getTemplateid()]['t'] = $templ; $data['orderdetail'][$templ->getTemplateid()]['p'] = $prod; } } } } } // fetch ordered product details if (is_array($product_ids) && count($product_ids) > 0) { $prodModel = new ProductModel(); $products = $prodModel->fetchProductsfromIds(implode(",", $product_ids)); if (is_array($products) && count($products) > 0) { foreach ($products as $prod) { $data['orderdetail']['-' . $prod->getProductId()]['t'] = null; $data['orderdetail']['-' . $prod->getProductId()]['p'] = $prod; } } } } } $data['order'] = $this->orderModel; return $data; } return null; }
private function saveOrder($jsonArray = null) { if (is_array($jsonArray) && isset($jsonArray['usr']) && isset($jsonArray['cart'])) { $order = new OrderModel(); $usr = $jsonArray['usr']; $cart = $jsonArray['cart']; // echo '<pre>';print_R($cart);die; // add checks here before saving order $order->setBfname($usr['fname']); $order->setBlname($usr['lname']); $order->setBemail($usr['email']); $order->setBaddressl1($usr['addr1']); $order->setBaddressl2($usr['addr2']); $order->setBaddressl3($usr['addr3']); $order->setBcity($usr['city']); $order->setBcountry($usr['country']); $order->setBstate($usr['state']); $order->setBzipcode($usr['zipcode']); $order->setInserttime(date("Y-m-d H:i:s")); $order->setSfname($usr['sfname']); $order->setSlname($usr['slname']); $order->setSemail($usr['semail']); $order->setSaddressl1($usr['saddr1']); $order->setSaddressl2($usr['saddr2']); $order->setSaddressl3($usr['saddr3']); $order->setScity($usr['scity']); $order->setScountry($usr['scountry']); $order->setSstate($usr['sstate']); $order->setStatus("pending"); $order->setSubtotal($cart['subTotal']); $order->setSzipcode($usr['szipcode']); $order->setDiscount($cart['discount']); $order->setTotal($cart['total']); $order->setQty($cart['qty']); $order->setOrder_type(strtoupper($usr['ordertype'])); $order->setUserid(Session::getInstance()->getSess("userid")); $order->insert(); if ($order->isSuccess() == 1) { $oid = $order->getOrderid(); foreach ($cart['items'] as $k => $itm) { $item = new OrderProdsModel(); $item->setOid($oid); $item->setTid($itm['template']); $item->setPid($itm['product']); $item->setPrice($itm['price']); $item->setQty($itm['qty']); $item->setTotal($itm['total']); $item->insert(); $this->moveTemplate($itm['template']); // converts file urls from temp dir to final destination dir } if ($cart['disId'] != 0) { $du = new DiscountUserModel(); $du->setDiscountId($cart['disId']); $du->setUserId(Session::getInstance()->getSess("userid")); $du->insert(); if ($cart['discountFor'] == 1) { $dis = new DiscountModel(); $dis->setDiscountid($cart['disId']); $dis->setStatus(1); $dis->update_status(); } } if ($usr['ordertype'] == 'cod') { $this->cod_order($oid, $usr, $cart['total']); } $oc = new OrderController(); ob_start(); $oc->printinvoice($oid); $html = ob_get_clean(); if ($usr['ordertype'] != 'payment') { Session::getInstance()->setMessage("Order accepted.", "green"); Session::getInstance()->removeSess('cart'); } mail($usr['email'], "Order Confirmation", $html, "Content-type: text/html; charset=iso-8859-1 \r\nFrom: noreply@snooky.com\r\n"); echo $oid; } else { Session::getInstance()->setMessage("Problem in accepting order, please try again.", "red"); echo "failed"; } } }