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 moveTemplate($tid) { // converts file urls from temp dir to final destination dir and update user templates database records $file = new FileTransfer(); $templateModel = new UsertemplateModel(); $templates = $templateModel->fetchTemplatesfromIds($tid); $template = $templates[0]; if ($template) { $json_template_str = $template->getTemplate(); $json_template = json_decode($json_template_str, true); $images = ""; if (isset($json_template['objects'][0])) { foreach ($json_template['objects'] as $k => $v) { if ($v['type'] == "image" && strpos($v['src'], "/temp/") != false) { $new_url = $file->move($v['src']); if ($new_url != "") { $json_template_str = str_replace($v['src'], $new_url, $json_template_str); } } if ($v['type'] == "image") { $images = $images . "##" . $v['src']; } } } if ($json_template['overlayImage']['type'] == "image") { $new_url = $file->move($json_template['overlayImage']['src']); if ($new_url != "") { $json_template_str = str_replace($json_template['overlayImage']['src'], $new_url, $json_template_str); } } $template->setTemplate($json_template_str); $template->update(); } }
public static function getCartItems($cart_items_str) { $cart_items = null; $cart_items_details = null; if ($cart_items_str != "") { $cart_items = explode("#", $cart_items_str); foreach ($cart_items as $k => $cart_item) { $detail = explode("_", $cart_item); if ($detail[0] < 0) { $product_ids .= -1 * $detail[0] . ","; // products of type 1 (without template) added in cart } else { $template_ids .= $detail[0] . ","; // products(templates) of type 2(with template) added in cart } $cart_items_details[$detail[0]] = $detail; } //fetch templates and their product details on basis of items in cart i.e detials of cart items of type 2(with template) $userTemplateModel = new UsertemplateModel(); $templates = $userTemplateModel->fetchTemplatesfromIds(rtrim($template_ids, ",")); $cartitems = null; if (is_array($templates) && count($templates) > 0) { foreach ($templates as $k => $templ) { $prod_ids .= $templ->getProductid() . ","; } $prodModel = new ProductModel(); $prods = $prodModel->fetchProductsfromIds(rtrim($prod_ids, ",")); foreach ($templates as $t) { $tpid = $t->getProductid(); $tid = $t->getTemplateid(); $qty = $cart_items_details[$tid][1]; foreach ($prods as $p) { if ($tpid == $p->getProductId()) { $cartitems[$tid]['prod'] = $p; $cartitems[$tid]['template'] = $t; $cartitems[$tid]['qty'] = $qty; break; } } } } //fetch product details on basis of items in cart i.e detials of cart items of type 1(without template) $prodModel = new ProductModel(); $prods = $prodModel->fetchProductsfromIds(rtrim($product_ids, ",")); if (is_array($prods) && count($prods) > 0) { foreach ($prods as $p) { $pid = '-' . $p->getProductId(); $cartitems[$pid]['prod'] = $p; $cartitems[$pid]['template'] = null; $cartitems[$pid]['qty'] = $cart_items_details[$pid][1]; } } return $cartitems; } return null; }