public function productDetail($domain, $slug, $id, $tagId, Request $request) { $productService = new productService(); $tagService = new tagService(); $productGallery = new productGalleryModel(); $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0; try { $product = $productService->getProductById($id, $userId); $tagIdRelateds = []; $product->metaKeyword = $tagService->formatMetaKeyword($product->tag, $tagIdRelateds); $data['productRelated'] = []; $productRelationIds = []; foreach ($tagIdRelateds as $tagIdRelated => $numberProductByTagId) { $productRelations = $productService->getProductByTagId($tagIdRelated, 100); foreach ($productRelations as $productRelation) { if (!in_array($productRelation->id, $productRelationIds)) { array_push($data['productRelated'], $productRelation); array_push($productRelationIds, $productRelation->id); } if (count($data['productRelated']) > 8) { break; } } if (count($data['productRelated']) > 8) { break; } } $data['product'] = $product; $data['tag'] = $tagService->getTagById($tagId, false); $data['productSlide'] = $productGallery->getImagesProductByProductId($id, PRODUCT_IMAGE_TYPE_SLIDE); return view('client.product.detail', $data); } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e->getMessage()]); } } }
/** * @param $description * @param $id */ public function trimImageDesc($description, $id) { $productGallery = new productGalleryModel(); $productGalleryService = new productGalleryService(); $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->strictErrorChecking = false; preg_match_all('/src="(.*?)"/', $description, $items); $images = $items[1]; $productImageDesc = $productGallery->getImagesProductByProductId($id, PRODUCT_IMAGE_TYPE_DESC); foreach ($productImageDesc as $image) { if (!in_array($image->image, $images)) { $productGalleryService->deleteImage($image->id); } } }
/** * 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()]); } } }