/** * function mame: productDetail * * @param Request $request * @return \Symfony\Component\HttpFoundation\Response */ public function addProductToCart(Request $request) { $cartService = new cartService(); $productService = new productService(); $result = array(); $result['ok'] = false; try { if ($request->isMethod('post')) { $productId = $request->get('productId', 0); $tagId = $request->get('tagId', 1); $colorId = $request->get('colorId', 0); $sizeId = $request->get('sizeId', 0); $quantity = $request->get('quantity', 1); $result['ok'] = true; $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0; $result['item'] = $cartService->addProductToCart($productId, $colorId, $sizeId, $quantity, $tagId); $result['products'] = $productService->getProductRelated($tagId, 3, $userId, ['product_tag_type_id' => false]); $result['cart'] = $cartService->cartInformation(); } } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e]); } } return response()->json($result); }
public function searchProduct($domain, $searchString, Request $request) { $productService = new productService(); $trackingService = new trackingService(); $result['ok'] = 0; $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0; $page = $request->input('page', 1); $limit = $request->input('limit', KACANA_PRODUCT_ITEM_PER_TAG); $sort = $request->input('sort'); $options = ['sort' => $sort]; $products = $productService->searchProduct($searchString, $limit, $page, $options, $userId); $trackingService->createTrackingSearch($searchString, $userId, $request->ip(), 'sub'); $result['ok'] = 1; $result['products'] = $products; $result['search'] = $searchString; return view('client.index.search', $result); }
public function sitemapProducts() { $productService = new productService(); // create sitemap $sitemap_products = \App::make("sitemap"); // set cache $sitemap_products->setCache('__sitemap_products__', 3600); $products = $productService->getAllProductAvailable(); foreach ($products as $product) { $images = [['url' => 'http:' . $product->image, 'title' => $product->name, 'caption' => $product->name]]; if (count($product->galleries)) { foreach ($product->galleries as $gallery) { $image = ['url' => 'http:' . $gallery->image, 'title' => $product->name, 'caption' => $product->name]; array_push($images, $image); } } $sitemap_products->add(urlProductDetail($product), $product->updated, '0.9', 'daily', $images); } return $sitemap_products->render('xml'); }
public function productSupperBoot(Request $request) { $productIds = $request->input('productIds', 0); $productService = new productService(); $saleRule = '<br><br>🛫 Giao hàng toàn quốc<br>💵 Thanh toán khi nhận hàng<br>🏍 Miễn phí vận chuyển với đơn hàng trên 500k<br>📱 Mua hàng:' . $this->_user->phone; $return['ok'] = 0; try { $return['data'] = $productService->getProductsToBoot($productIds, $this->_user->id); $return['saleRule'] = $saleRule; $return['ok'] = 1; } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e->getMessage()]); } } return response()->json($return); }
public function addProductToOrder(Request $request) { $productService = new productService(); $orderService = new orderService(); $orderId = $request->input('orderId'); $productId = $request->input('productId'); try { $order = $orderService->getOrderById($orderId); $total = $order->total; $discount = $order->discount; $originTotal = $order->origin_total; $quantity = $order->quantity; $product = $productService->getProductById($productId); $productDiscount = 0; if ($product->mainDiscount) { $productDiscount = $product->mainDiscount; } elseif ($product->discount) { $productDiscount = $product->discount; } $orderDetailData = new \stdClass(); $orderDetailData->order_id = $orderId; $orderDetailData->name = $product->name; $orderDetailData->price = $product->sell_price; $orderDetailData->discount = $product->discount; $orderDetailData->quantity = 1; $orderDetailData->product_id = $product->id; $orderDetailData->product_url = urlProductDetail($product); $orderDetailData->image = $product->image; $orderDetailData->subtotal = $product->sell_price - $productDiscount; $orderService->createOrderDetailAdmin($orderDetailData); $total += $product->sell_price - $productDiscount; $discount += $productDiscount; $originTotal += $product->sell_price; $quantity += 1; $dataOrder = ['total' => $total, 'origin_total' => $originTotal, 'quantity' => $quantity, 'discount' => $discount]; $orderService->updateOrder($orderId, $dataOrder); return redirect('/order/edit/' . $order->order_code); } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e]); } } }
/** * @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]); }
public function trackUserProductView(Request $request) { $productService = new productService(); $productId = $request->input('productId'); $userId = \Kacana\Util::isLoggedIn() ? $this->_user->id : 0; $result['ok'] = 0; try { $productService->trackUserProductView($productId, $userId, $request->ip()); $result['ok'] = 1; } catch (\Exception $e) { if ($request->ajax()) { $result['error'] = $e->getMessage(); return $result; } else { return view('errors.404', ['error_message' => $e->getMessage()]); } } return response()->json($result); }
public function reportDetailTableProductView(Request $request) { $params = $request->all(); $productService = new productService(); try { $return = $productService->reportDetailTableProductView($params); } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['error'] = $e->getMessage(); $return['errorMsg'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return response()->json($return); }
public function createCSVForRemarketing() { $productService = new productService(); $return['ok'] = 0; try { $return['data'] = $productService->createCsvBD(); $return['ok'] = 1; } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['error'] = $e->getMessage(); $return['errorMsg'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return response()->json($return); }
public function formatMetaKeyword(&$tags, &$tagIdRelated) { $productService = new productService(); $tagNameArray = []; $tagCache = '__count_product_by_tag_id__'; $tagIdRelatedArray = []; if (count($tags)) { foreach ($tags as &$tag) { array_push($tagNameArray, $tag->name); $countProduct = Cache::tags($tagCache)->get($tag->id); if (!$countProduct) { $countProduct = $productService->countProductByTagId($tag->id); } $tagIdRelated[$tag->id] = $countProduct; $tag->countProduct = $countProduct; } } asort($tagIdRelated); return $tagNameArray; }