Example #1
0
 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');
 }
Example #2
0
 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]);
         }
     }
 }
Example #3
0
 /**
  * @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]);
 }
Example #4
0
 /**
  * @param $results
  * @return mixed
  */
 public function formatProductDataForAjax($results)
 {
     foreach ($results as &$item) {
         $item->urlProductDetail = urlProductDetail($item);
         $item->sell_price_show = formatMoney($item->sell_price);
         $item->discount_show = formatMoney($item->discount);
         $item->price_after_discount_show = formatMoney($item->sell_price - $item->discount);
         $item->style = $item->style->toArray();
         $item->is_loggin = \Auth::check() ? 1 : 0;
         if (count($item->properties)) {
             $item->properties_js = $item->properties;
         } else {
             $item->properties_js = 0;
         }
     }
     return $results->toArray();
 }