public function actionIndex($style = null, $order = null, $manufacturer = null, $attribute = null) { if (isset($_GET['q'])) { $with = array(); $category = array(); $criteria = new CDbCriteria(); $criteria->condition = "name like :search or description like :search"; $criteria->params = array(':search' => "%{$_GET['q']}%"); if (isset($_GET['category']) && $_GET['category'] > 0) { $category = Category::model()->findByPk($_GET['category']); $criteria->addCondition("category_id = {$category->id}"); } $template = "type/_grid"; if ($style == "list") { $template = 'type/_' . $style; } switch ($order) { case "price": $criteria->order = "price"; break; case "created": $criteria->order = "created DESC"; break; default: $criteria->order = "name"; break; } if ($manufacturer) { $criteria->addInCondition("manufacturer_id", explode(',', trim($manufacturer))); } if ($attribute) { $crtr = new CDbCriteria(); $crtr->addInCondition("id", explode(',', trim($attribute))); $opt = EntityAttributeOption::model()->findAll($crtr); $attrs = CHtml::listData($opt, 'id', 'option'); $criteria->addInCondition("entityAttributeOptions.option", $attrs); $with = array('entityAttributeOptions' => array('together' => true)); } $products = new Product(); $total = $products->with($with)->count($criteria); $pages = new Pagination($total); $pages->pageSize = 4; $pages->applyLimit($criteria); $list = $products->with($with)->findAll($criteria); if (Yii::app()->request->isAjaxRequest) { $this->widget("ProductList", array('pages' => $pages, 'products' => $list, 'template' => $template)); Yii::app()->end(); } $this->render('index', array('models' => $list, 'pages' => $pages, 'q' => $_GET['q'], 'template' => $template, 'category' => $category)); } else { throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.'); } }
public function find($id) { $product = Product::with(["unit", "orderItems.order.business", "orders"])->whereId($id)->get(); foreach ($product as $p) { $inStock = 0; $outStock = 0; foreach ($p->orderItems as $orderItem) { $raw = $orderItem->price * $orderItem->quantity; $discountValue = $raw * $orderItem->discount / 100; $taxValue = $raw * $orderItem->tax / 100; $total = $raw + $taxValue - $discountValue; if ($orderItem->order->business->name == "Nhập hàng") { $inStock += $orderItem->quantity; } if ($orderItem->order->business->name == "Xuất hàng") { $outStock += $orderItem->quantity; } array_add($orderItem, 'total', $total); } $stock = $inStock - $outStock; array_add($p, 'in_stock', $inStock); array_add($p, 'out_stock', $outStock); array_add($p, 'stock', $stock); } return Response::json($product); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $products = Product::with('Type')->with('Brand')->get(); View::share('selected_option', 'Ver Productos'); $view = View::make('product.list')->with('products', $products); return $view; }
public static function productAlmostOutOfStock($type) { $almost_out_of_stock = Product::with(array('brand' => function ($query) { $query->select('id', 'name'); }, 'categories' => function ($query) { $query->select('id', 'name'); }))->select('id', 'name', 'quantity', 'productcat_id', 'brand_id', 'almost_finished', 'published')->orderBy('quantity', 'asc')->get()->toArray(); //tt(count($almost_out_of_stock), true); $counter = 0; // Counter for count alert if ($type === 'list' || $type === 'all') { } if (!empty($almost_out_of_stock)) { foreach ($almost_out_of_stock as $key) { if ($key['published'] != 0 && $key['quantity'] <= $key['almost_finished']) { //We'll take record is we're requesting for listing the items if ($type === 'list' || $type === 'all') { $key['linktoproduct'] = User::permitted('role.stock manager') ? URL::route('adminShowProduct', array(slug($key['brand']['name']), slug($key['categories']['name']))) : ''; //tt($key); $data['products'][] = $key; } $counter++; } } } $data['count'] = $counter; //tt(count($data['products'])); return $data; }
public function getView( $slug ) { $product = Product::where( 'slug', '=', $slug )->first(); $related_products = Product::with( 'categories', 'images' )->paginate( 40 ); return View::make( 'products.view', array( 'product' => $product, 'related_products' => $related_products ) ); }
public function getList($GoodId) { $admin_warehouse = '0'; if (Auth::user()->grade == 6) { $admin_warehouse = Warehouse::getUserWarehouseId(Auth::user()->id); } return View::make('goods.list')->with('good', Good::find($GoodId))->with('products', Product::with('warehouse')->where('good_id', $GoodId)->orderBy('production_date', 'desc')->paginate())->with('count', Product::where('good_id', $GoodId)->count())->with('admin_warehouse', $admin_warehouse); }
public function indexAction() { $query = Product::with(["category"]); $category = Input::get("category"); if ($category) { $query->where("category_id", $category); } return $query->get(); }
private function _name($q, $mode, $ql) { //tt($mode); $products = Product::with(array('brand' => function ($query) { $query->select('id', 'name'); }, 'categories' => function ($query) { $query->select('id', 'name', 'type'); }))->whereRaw("name LIKE '%" . $q . "%'")->where($mode . '_price', '>', 0)->where('published', '=', 1)->select('id', 'name', 'barcodeid', 'costprice', 'productcat_id', 'brand_id', 'quantity', $mode . '_price as price', $mode . '_discount as discount', $mode . '_discountedprice as discounted_price', 'published')->take($ql)->orderBy('quantity', 'DESC')->get(); return $products; }
public function index() { switch ($this->type) { case 'categories': $list = Category::with('seo')->get(array('id', 'name')); break; default: $list = Product::with('seo')->get(array('id', 'name')); break; } $this->layout->content = View::make('admin.seo.list', array('type' => $this->type, 'list' => $list)); }
public function view($productCategorySlug, $productSlug) { $product = Product::with(array('stockists', 'productCategory' => function ($query) use($productCategorySlug) { $query->where('slug', '=', $productCategorySlug); }, 'recipes' => function ($query) { $query->orderBy(\DB::raw('RAND()'))->take(3); }))->where('slug', '=', $productSlug)->live()->first(); if (!$product) { \App::abort(404); } return \View::make(\Config::get('laravel-food::views.products.view'))->with(compact('product')); }
public function listProduct() { $per_page = Input::get('per_page', 30); try { $query = Product::with(['booth', 'quantity', 'user']); $list = $query->paginate($per_page); $data['rows'] = []; foreach ($list as $key => $product) { $data['rows'][] = $product->showInList(); } $data['total'] = $list->getTotal(); $re = Tools::reTrue('获取产品列表成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取产品列表失败:' . $e->getMessage()); } return Response::json($re); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $products = Product::with(['sizes' => function ($query) { return $query->order(); }, 'images', 'category', 'brand', 'department']); if (Input::has('f')) { if (Input::get('f') == 'num') { $products = $products->whereBetween(DB::raw('LEFT(name, 1)'), [0, 9]); } else { $products = $products->where('name', 'like', Input::get('f') . '%'); } } if (Input::has('s')) { $products = $products->where('name', 'like', '%' . Input::get('s') . '%'); } $products = $products->paginate($this->perPage); return View::make('admin::products.index', compact('products')); }
public function getProduct($id) { $u_id = Input::get('u_id'); try { $product = Product::with(['user', 'booth' => function ($q) { $q->with(['school']); }, 'quantity', 'promo', 'replies' => function ($q) { $q->with(['user'])->take(3)->orderBy('created_at', 'DESC'); }, 'favorites' => function ($q) { $q->where('favorites.u_id', '=', $this->u_id); }, 'praises' => function ($q) { $q->where('praises.u_id', '=', $this->u_id); }])->find($id); if (empty($product->p_id)) { throw new Exception("无法找到请求的产品", 7001); } $data = $product->showDetail(); // delete this after several upgrade if (!empty($data['user']['mobile'])) { $data['user']['mobile'] = $data['mobile']; } if (empty($data['booth']['school'])) { $data['school'] = []; } else { $data['school'] = $data['booth']['school']; unset($data['booth']); } $data['is_praised'] = 0; $data['is_favorited'] = 0; if (count($product->praises) > 0) { $data['is_praised'] = 1; } if (count($product->favorites) > 0) { $data['is_favorited'] = 1; } $re = Tools::reTrue('获取产品成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取产品失败:' . $e->getMessage()); } return Response::json($re); }
public function ajaxCollection() { $sizes = Input::get('sizes'); // Get the products and required relationships. $products = Product::with('product_media.media', 'stock'); // Search. if (Input::get('search') !== '') { $products = $products->where('name', 'LIKE', '%' . Input::get('search') . '%'); } // Sorting options. if (Input::get('sort') == 'low-high') { $products = $products->orderBy('price', 'ASC'); } else { if (Input::get('sort') == 'high-low') { $products = $products->orderBy('price', 'DESC'); } } $products = $products->get(); $end_products = []; foreach ($products as $key => $product) { $display = false; foreach ($product->stock as $key => $stock) { if (Input::has('sizes')) { if (in_array($stock->size_id, $sizes) && $stock->quantity > 0) { $display = true; } } else { if ($stock->quantity > 0) { $display = true; } } } if ($display) { $end_products[] = $product; } } return View::make('brochure.product.ajax', ['products' => $end_products, 'selected_sizes' => $sizes]); }
public function get_index($cat = '', $alias = '') { //Filtering the Attribute groups for product specific if (empty($alias)) { } $prod = Product::with(array('getCategory', 'getCategory.getDescriptions'))->where('alias', '=', $cat)->first(); $cat = $prod->getCategory[0]->getDescriptions->alias; $alias = $prod->alias; $category_id = CategoryDescription::with('getCategory')->where('alias', '=', $cat)->only('id'); $result = Category::with(array("getDescriptions", "getTopCat", "getTopCat.getDescriptions", "getProducts" => function ($query) use($alias) { $query->where('alias', '=', $alias); }, "getProducts.getBrand", "getProducts.getImages", "getProducts.getDetail", "getProducts.getTax", "getProducts.getDiscount", "getProducts.getAttributes", "getProducts.getShipment", "getAttributeListing", "getAttributeListing.getTopGroup"))->where('id', '=', $category_id)->first(); Title::put($result->getProducts[0]->getDetail->name); /*Get attributes*/ $topGroups = array(); foreach ($result->getAttributeListing as $item) { array_push($topGroups, $item->getTopGroup->id); } $topGroups = array_unique($topGroups); $groups = array(); foreach ($result->getAttributeListing as $item) { array_push($groups, $item->id); } $groups = array_unique($groups); $belongedGroups = array(); foreach ($result->getProducts[0]->getAttributes as $item) { array_push($belongedGroups, $item->id); } $attrs = AttributeGroup::with(array('getParentGroup' => function ($query) use($groups) { $query->order_by('sort_order', 'desc'); $query->where_in('id', $groups); }, 'getParentGroup.getAttributes' => function ($query) use($belongedGroups) { $query->where_in('id', $belongedGroups); }))->where_in('id', $topGroups)->get(); return View::make('products.index')->with('product', $result)->with('attrs', $attrs); }
public function getProduct($id) { try { $product = Product::with(['quantity', 'promo', 'replies' => function ($q) { $q->with(['user', 'children' => function ($qq) { $qq->where('r_status', '=', 1)->orderBy('created_at', 'DESC'); }])->where('to_r_id', '=', 0)->where('r_status', '=', 1)->where('to_u_id', '=', 0)->orderBy('created_at', 'DESC'); }])->find($id); if (!empty($product->promo)) { $product->promo->load('praises'); } if (empty($product->p_id)) { throw new Exception("无法找到请求的产品", 7001); } $data = $product->showDetail(); $re = Tools::reTrue('获取产品成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取产品失败:' . $e->getMessage()); } return Response::json($re); }
public function listFlea() { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $per_page = Input::get('per_page', 30); try { $user = User::chkUserByToken($token, $u_id); $query = Product::with(['booth' => function ($q) { $q->with(['user', 'school']); }, 'quantity', 'praises' => function ($q) { $q->where('praises.u_id', '=', $this->u_id); }])->where('u_id', '=', $u_id)->where('p_type', '=', 2); $list = $query->orderBy('created_at', 'DESC')->paginate($per_page); $data = []; foreach ($list as $key => $product) { $tmp = $product->showInList(); if (count($product->praises) > 0) { $tmp['is_praised'] = 1; } else { $tmp['is_praised'] = 0; } $data[] = $tmp; } $re = Tools::reTrue('获取我发布的产品成功', $data); } catch (Exception $e) { $re = Tools::reFalse($e->getCode(), '获取我发布的产品失败:' . $e->getMessage()); } return Response::json($re); }
public function editProduct($productId) { try { $product = Product::with('images')->with('categories')->with('optionGroups')->with('options')->with('priceBreaks')->with('sizeLists')->findorFail($productId); } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) { return App::abort(404); } $product = $product->toArray(); foreach (['option_groups', 'options'] as $value) { $tmpData = []; if (!empty($product[$value])) { foreach ($product[$value] as $v) { $tmpData[] = $v['id']; } } $product[$value] = $tmpData; unset($tmpData); } $product['sell_price'] = number_format($product['sell_price'], 2); $arrCategories = []; if (!empty($product['categories'])) { foreach ($product['categories'] as $category) { $arrCategories[] = $category['id']; } } $this->layout->title = 'Edit Product'; $this->layout->content = View::make('admin.products-one')->with(['product' => $product, 'arrCategories' => ProductCategory::getSource(false, 0, true), 'arrChosenCategories' => $arrCategories, 'types' => ProductType::getSource(), 'option_groups' => ProductOptionGroup::getSource(false, true), 'layouts' => array()]); }
public function getProducts() { $token = Input::get('token', ''); $u_id = Input::get('u_id', 0); $b_id = Input::get('b_id'); $per_page = Input::get('per_page', 30); try { $user = User::chkUserByToken($token, $u_id); $products = Product::with(['quantity', 'promo'])->where('u_id', '=', $u_id)->where('b_id', '=', $b_id)->where('p_status', '=', 1)->orderBy('sort', 'DESC')->orderBy('created_at', 'DESC')->paginate($per_page); $pagination = ['total_record' => $products->getTotal(), 'total_page' => $products->getLastPage(), 'per_page' => $products->getPerPage(), 'current_page' => $products->getCurrentPage()]; $data = []; foreach ($products as $key => $product) { $data[] = $product->showInList(); } $re = ['result' => 2000, 'data' => $data, 'info' => '获取商品成功', 'pagination' => $pagination]; } catch (Exception $e) { $code = 7001; if ($e->getCode() > 2000) { $code = $e->getCode(); } $re = ['result' => $code, 'data' => [], 'info' => '获取商品失败:' . $e->getMessage()]; } return Response::json($re); }
public function getProductColours($id) { // Get the product. $product = Product::with('colours')->findOrFail($id); // Render the view. return View::make('admin.products.colours', ['product' => $product]); }
/** * Display a listing of products * * @return Response */ public function index() { $products = Product::with('inventories')->get(); return View::make('products.index', compact('products')); }
public function index($image_id) { $arrReturn = array(); $arrImage = array(); $imageObj = VIImage::select('images.id', 'images.name', 'images.short_name', 'images.description', 'images.keywords', 'images.artist', 'images.author_id', 'image_details.path', 'image_details.width', 'image_details.height', 'image_details.ratio')->join('image_details', 'image_details.image_id', '=', 'images.id')->where('images.id', $image_id)->first(); if (is_object($imageObj)) { if ($imageObj->ratio > 1) { $width = 450; $height = $width / $imageObj->ratio; } else { $height = 450; $width = $height * $imageObj->ratio; } $arrImage = ['image_id' => $imageObj->id, 'name' => $imageObj->name, 'short_name' => $imageObj->short_name, 'description' => $imageObj->description, 'keywords' => $imageObj->keywords, 'artist' => $imageObj->artist, 'author_id' => $imageObj->author_id, 'width' => $width, 'height' => $height, 'path' => '/pic/with-logo/' . $imageObj->short_name . '-' . $imageObj->id . '.jpg', 'path_thumb' => '/pic/thumb/' . $imageObj->short_name . '-' . $imageObj->id . '.jpg']; $htmlChooseDownload = $this->loadChooseDownload($imageObj->id); $product = Product::with(['type', 'sizeLists', 'optionGroups' => function ($query) { $query->select('option_groups.id', 'name', 'key'); }, 'options' => function ($query) { $query->select('options.id', 'name', 'key', 'option_group_id'); }]); $product = $product->where('active', 1)->get(); $arrProduct = array(); if (is_object($product)) { $arrProduct = $product->toArray(); } // echo '<pre>'; // print_r($arrProduct[0]['option_groups']); // echo '</pre>'; $htmlOrder = $this->loadOrder($arrImage, $arrProduct); $htmlSignin = View::make('frontend.account.signin')->with([])->render(); $arrKeywords = explode(',', $imageObj->keywords); $arrReturn['htmlKeywords'] = View::make('frontend.images.view-keywords')->with('arrKeywords', $arrKeywords)->render(); $action = Input::has('a') ? Input::get('a') : ''; $arrReturn['htmlMainImage'] = View::make('frontend.images.main-image')->with(['imageObj' => $arrImage, 'htmlChooseDownload' => $htmlChooseDownload, 'htmlOrder' => $htmlOrder, 'htmlSignin' => $htmlSignin, 'action' => $action, 'htmlKeywords' => $arrReturn['htmlKeywords']])->render(); $arrReturn['htmlSameArtist'] = $this->loadSameArtist($imageObj->author_id); $arrReturn['htmlSimilarImages'] = $this->getSimilarImage(array($imageObj->id)); $this->layout->metaTitle = $imageObj->name; //save to recently_view_images table //App::make('AccountController')->addToRecentlyViewImages($imageObj->id); if (Auth::user()->check()) { BackgroundProcess::actionSearch(['type' => 'recently-view', 'image_id' => $imageObj->id, 'user_id' => Auth::user()->get()->id]); } } else { return App::abort(404); } $arrReturn['imageObj'] = $arrImage; $categories = $this->layout->categories; $arrReturn['htmlCategories'] = View::make('frontend.account.view-categories')->with('categories', $categories)->render(); $lightboxes = array(); if (Auth::user()->check()) { $lightboxes = Lightbox::where('user_id', '=', Auth::user()->get()->id)->get()->toArray(); foreach ($lightboxes as $key => $lightbox) { $lightboxes[$key]['total'] = LightboxImages::where('lightbox_id', '=', $lightbox['id'])->count(); } } $arrReturn['lightboxes'] = $lightboxes; $arrReturn['mod_download'] = Configure::GetValueConfigByKey('mod_download'); $arrReturn['mod_order'] = Configure::GetValueConfigByKey('mod_order'); $arrReturn['arrProduct'] = $arrProduct; $this->layout->content = View::make('frontend.images.index')->with($arrReturn); }
public function updateProducts() { $inputs = Input::all(); $xe = strtolower($inputs['name']); $mode = $inputs['mode']; //products, brands, productcategories $product = Product::with(array('brand' => function ($query) { $query->select('id', 'name'); }, 'categories' => function ($query) { $query->select('id', 'name'); }))->find($inputs['pk']); $method = '_update_' . $xe; $ajax = $this->{$method}($product, $inputs); $ajax['id'] = $product->id; $product->save(); return Response::json($ajax); }
public function one($id) { $product = Product::with('crops')->where('crop_id', '=', $id)->get(); $categories = Category::with('crops')->get(); return View::make('main.all', compact('product'))->with('categories', $categories)->with('title', "Product Details"); }