public function listProductByCate($domain, $slug, $tagId, Request $request) { $productService = new productService(); $tagService = new tagService(); $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0; try { $tag = $request->input('tagId'); $page = $request->input('page', 1); $tag = $tag != "" ? $tag : $tagId; $sort = $request->input('sort'); $options = ['tagId' => $tag, 'sort' => $sort, 'product_tag_type_id' => TAG_RELATION_TYPE_MENU]; $limit = KACANA_PRODUCT_ITEM_PER_TAG; $data['items'] = $productService->getProductByTagId($tagId, $limit, $userId, $page, $options); $tags = $tagService->getTagById($tagId, false); $tags->allChilds = $tagService->getAllChildTagHaveProduct($tagId); $tagIdRelated = []; $tags->tagKeyword = $tagService->formatMetaKeyword($tags->allChilds, $tagIdRelated); $data['tag'] = $tags; $data['options'] = $options; } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e->getMessage()]); } } return view('client.product.listproduct', $data); }
/** * edit product * * @param $domain * @param $id * @param Request $request * @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function editProduct($domain, $id, Request $request) { $productService = new productService(); $addressService = new addressService(); $productGalleryModel = new productGalleryModel(); $tagService = new tagService(); $results = []; try { if ($request->isMethod('post')) { $productService->updateProduct($request->all(), $id); return redirect('/product/editProduct/' . $id)->with('success', 'Cập nhật sản phẩm thành công!'); } $results['product'] = $productService->getProductById($id, 0, false); $results['tagColor'] = $tagService->getColorTag(); $results['groupTag'] = $tagService->getTagGroup(); $results['tagSize'] = $tagService->getSizeTag(); $results['tagStyle'] = $tagService->getStyleTag(); $results['countries'] = $addressService->getListCountry(); $results['images'] = $productGalleryModel->getImagesProductByProductId($id); return view('admin.product.edit-product', $results); } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e->getMessage()]); } } }
/** * Bootstrap any application services. * * @return void */ public function boot() { //menu on header View::composer('layouts.client.header', function ($view) { $tagService = new tagService(); $params = false; if (Route::current()) { $params = Route::current()->parameters(); } $view->with('menu_items', $tagService->getTagForClientMenu())->with('id_active', isset($params['id']) ? $params['id'] : 0); }); //menu on footer View::composer('layouts.client.footer', function ($view) { $tagService = new tagService(); $view->with('menu_items', $tagService->getTagForClientMenu()); }); }
public function sitemapTags(Request $request) { $tagService = new tagService(); // create sitemap $sitemap_tags = \App::make("sitemap"); $mainTags = $tagService->getRootTag(); $tagIdCheck = []; foreach ($mainTags as $tag) { $sitemap_tags->add(urlTag($tag), $tag->updated, '0.9', 'weekly'); $tagChilds = $tagService->getAllChildTagHaveProduct($tag->id); array_push($tagIdCheck, $tag->id); foreach ($tagChilds as $tagChild) { if (!in_array($tagChild->id, $tagIdCheck)) { array_push($tagIdCheck, $tagChild->id); $sitemap_tags->add(urlTag($tagChild), $tagChild->updated, '0.8', 'weekly'); } } } return $sitemap_tags->render('xml'); }
/** * Show the application welcome screen to the user. * * @param Request $request * @return \BladeView|bool|\Illuminate\View\View */ public function index(Request $request) { $productService = new productService(); $tagService = new tagService(); $limit = KACANA_HOMEPAGE_ITEM_PER_TAG; $mainTags = $tagService->getRootTag(); $data = array(); foreach ($mainTags as $tag) { $result['tag'] = $tag->name; $result['short_desc'] = $tag->short_desc; $result['slug'] = str_slug($tag->name . '-'); $result['tag_id'] = $tag->child_id; $result['tag_url'] = ''; $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0; $result['products'] = $productService->getProductByTagId($tag->id, $limit, $userId, 1, ['product_tag_type_id' => TAG_RELATION_TYPE_MENU]); $data[] = $result; } $newestProduct = $productService->getNewestProduct($userId); $discountProduct = $productService->getDiscountProduct($userId); return view('client.index.index', array('items' => $data, 'newest' => $newestProduct, 'discount' => $discountProduct)); }
public function changeTagStatusRelation(Request $request) { $tagService = new tagService(); $tagId = $request->input('tagId'); $typeId = $request->input('typeId'); $parentId = $request->input('parentId'); $return['ok'] = 0; try { if ($tagService->toggleStatusRelation($tagId, $typeId, $parentId)) { $return['ok'] = 1; } } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['error'] = $e->getMessage(); $return['errorMsg'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return response()->json($return); }
/** * @param $productId * @param $colorId * @param $sizeId * @param $quantity * @param $tagId * @return \Gloudemans\Shoppingcart\Gloudemans\Shoppingcart\CartCollection * @throws \Exception */ public function addProductToCart($productId, $colorId, $sizeId, $quantity, $tagId) { $productService = new productService(); $tagService = new tagService(); if (!$productId) { throw new \Exception('có lỗi xảy ra trong quá trình đặt hàng!'); } $product = $productService->getProductById($productId); if (!$product) { throw new \Exception('sản phẩm không tồn tại!'); } $productName = $product->name; $productDiscount = 0; if (intval($product->discount)) { $productDiscount = $product->discount; $productPrice = $product->sell_price - $product->discount; } if (intval($product->mainDiscount)) { $productDiscount = $product->mainDiscount; $productPrice = $product->sell_price - $product->mainDiscount; } else { $productPrice = $product->sell_price; } $cartId = $this->generateCartId($productId, $colorId, $sizeId); $productImage = $product->image; $properties = $product->properties; $options = []; $options['url'] = urlProductDetail($product) . $tagId; $options['priceShow'] = formatMoney($productPrice); $options['productId'] = $productId; // check properties of product if (count($properties)) { if (!isset($properties[$colorId])) { throw new \Exception('sản phẩm không tồn tại colorId: ' . $colorId . '!'); } else { $colorTag = $tagService->getTagById($colorId, TAG_RELATION_TYPE_COLOR); $property = $properties[$colorId]; $sizeIds = $property->sizeIds; if ($colorTag) { $options['colorId'] = $colorId; $options['colorName'] = $colorTag->name; if ($property->product_gallery_id) { $galleries = $product->galleries; if ($galleries && count($galleries)) { foreach ($galleries as $gallery) { if ($gallery->id == $property->product_gallery_id) { $productImage = $gallery->image; } } } } if (count($sizeIds) && !in_array($sizeId, $sizeIds)) { throw new \Exception('sản phẩm không tồn tại colorId: ' . $colorId . ' với sizeId: ' . $sizeId . '!'); } else { if (count($sizeIds) && in_array($sizeId, $sizeIds)) { $sizeTag = $tagService->getTagById($sizeId, TAG_RELATION_TYPE_SIZE); if ($sizeTag) { $options['sizeId'] = $sizeId; $options['sizeName'] = $sizeTag->name; } else { throw new \Exception('sizeId: ' . $sizeId . ' không tồn tại trong hệ thống hoặc bị tắt!'); } } } } else { throw new \Exception('colorId: ' . $colorId . ' không tồn tại trong hệ thống hoặc bị tắt!'); } } } $options['image'] = $productImage; $options['discount'] = $productDiscount; $options['discountShow'] = formatMoney($productDiscount); $options['origin_price'] = $product->sell_price; $options['origin_price_show'] = formatMoney($product->sell_price); $order = Cart::add(array('id' => $cartId, 'name' => $productName, 'qty' => $quantity, 'price' => $productPrice, 'options' => $options)); return Cart::get(Cart::search(['id' => $cartId])[0]); }
/** * @param $tagId * @param $typeId * @param $productId * @return array */ public function getProductTreeMenu($tagId, $typeId, $productId) { $tagService = new tagService(); $productModel = new productModel(); $tags = $tagService->getSubTagsWithAdminData($tagId, $typeId); $tagOfProducts = $productModel->getProductById($productId, false)->tag; $tagProductArray = []; foreach ($tagOfProducts as $tagOfProduct) { if ($tagOfProduct->pivot->type == KACANA_PRODUCT_TAG_TYPE_MENU) { array_push($tagProductArray, $tagOfProduct->id); } } $tagActive = array(); foreach ($tags as $tag) { if ($tag->relation_status) { if (in_array($tag->child_id, $tagProductArray)) { $tag->checked = true; } array_push($tagActive, $tag); } } return $tagActive; }
public function updateImage(Request $request) { $return['ok'] = 0; $id = $request->input('tagId'); $imageName = $request->input('name'); try { $tagService = new tagService(); $return['data'] = $tagService->updateImage($id, $imageName); $return['ok'] = 1; } catch (Exception $e) { // @codeCoverageIgnoreStart $return['error'] = TR::l('EDITOR/MESSAGE/ERROR/SHARE_BIN'); $return['errorMsg'] = $e->getMessage(); Binumi_Util::logErr($e->getMessage()); // @codeCoverageIgnoreEnd } return response()->json($return); }