public static function getCartRelativeProducts() { $arrCart = Session::get('cart'); $relativeProducts = array(); if (!empty($arrCart)) { $arrProductId = array_keys($arrCart); $productCls = new ProductModel(); $arrProducts = $productCls->getProductList(array('products.id' => $arrProductId), array(), array()); $arrCategoryId = array(); foreach ($arrProducts as $key => $val) { $arrCategoryId[] = $val['product_category']; } $whereArr = array('product_category' => $arrCategoryId, 'id NOT IN' => implode(',', $arrProductId)); $limitArr = array(0, 10); $relativeProducts = $productCls->getProductList($whereArr, $limitArr, array()); if (count($relativeProducts) < 10) { $productAdding = 10 - count($relativeProducts); $parrentCategory = DB::table('categories')->whereIn('id', $arrCategoryId)->lists('category_parent'); if ($parrentCategory) { $whereArr['product_category'] = $parrentCategory; $limitArr = array(0, $productAdding); $relativeProducts2 = $productCls->getProductList($whereArr, $limitArr, array()); if ($relativeProducts2) { $relativeProducts = $relativeProducts + $relativeProducts2; } } } } if (!empty($relativeProducts)) { return view('Frontend.relative_products', compact('relativeProducts')); } }
public static function getIndex() { $categoryCls = new CategoryModel(); $productCls = new ProductModel(); $customersModel = new CustomersModel(); // check if user login later register if (Session::has('register_flag')) { $data = $customersModel->getUserByEmail(Session::get('customer_email')); Mail::send('Frontend.email.register', $data, function ($message) use($data) { $message->to($data['customer_email'], $data['customer_name'])->subject('Cường thuỷ - Xác nhận đăng kí!'); }); Session::forget('register_flag'); } $arrParentList = $categoryCls->getParentList(); $arrChirdList = $categoryCls->getChildList(); foreach ($arrParentList as $key => $val) { $whereArr = array('OR' => array('categories.id' => $key, 'categories.category_parent' => $key)); $joinsArr = array(array('table' => 'categories', 'type' => 'INNER', 'conditions' => 'products.product_category = categories.id')); $limitArr = array(self::$PRODUCT_MAX); $arrProductList[$key] = $productCls->getProductList($whereArr, $limitArr, $joinsArr); } $arrProductNew = $productCls->getProductNew(array(), array(self::$PRODUCT_MAX)); BaseController::$title = 'Uy tín, chất lượng, giá rẻ cho mọi nhà '; return view('Frontend.index', ['arrParentList' => $arrParentList, 'arrChirdList' => $arrChirdList, 'arrProductList' => $arrProductList, 'arrProductNew' => $arrProductNew]); }
public static function getIndex() { $productCls = new ProductModel(); $categoryCls = new CategoryModel(); $whereArr = array(); $joinsArr = array(); $categoryId = ''; if (Input::has('category_id')) { $categoryId = Input::get('category_id'); $joinsArr = array(array('table' => 'categories', 'type' => 'RIGHT', 'conditions' => 'products.product_category = categories.id')); if ($categoryId > 0) { $whereArr['OR'] = array('categories.id' => $categoryId, 'categories.category_parent' => $categoryId); } else { $whereArr['OR'] = array('categories.id' => $categoryId); } } else { $whereArr['product_sell_status LIKE'] = "%1%"; } $searchKey = ''; $searchValue = ''; if (Input::has('search_key')) { $searchKey = Input::get('search_key'); switch ($searchKey) { case 'newer': $whereArr['product_sell_status LIKE'] = "%1%"; break; case 'hot': $whereArr['product_sell_status LIKE'] = "%3%"; break; case 'sell': $whereArr['product_sell_status LIKE'] = "%2%"; break; default: if (Input::has('search_value')) { $searchValue = Input::get('search_value'); $whereArr[$searchKey . ' LIKE'] = "%" . $searchValue . "%"; } break; } } if (Input::has('page')) { $page = Input::get('page'); } else { $page = 1; } $totalRecord = $productCls->getCountResult($whereArr, $joinsArr); $maxRec = self::$PRODUCT_MAX; $offset = ($page - 1) * $maxRec; $lastPage = ceil($totalRecord / $maxRec); $currentPage = $page; $previousPage = $page > 1 ? $page - 1 : 1; $nextPage = $page < $lastPage ? $page + 1 : $lastPage; $limitArr = array($offset, $maxRec); $arrProductList = $productCls->getProductList($whereArr, $limitArr, $joinsArr); // get category name $categories = $categoryCls->getCategoryNamebyId($categoryId); BaseController::$title = 'Danh sách sản phẩm'; return view('Frontend.list', ['arrProductList' => $arrProductList, 'currentPage' => $currentPage, 'lastPage' => $lastPage, 'previousPage' => $previousPage, 'nextPage' => $nextPage, 'categoryId' => $categoryId, 'categories' => $categories, 'search_key' => $searchKey, 'search_value' => $searchValue]); }