當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::with方法代碼示例

本文整理匯總了PHP中Product::with方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::with方法的具體用法?PHP Product::with怎麽用?PHP Product::with使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Product的用法示例。


在下文中一共展示了Product::with方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionIndex

 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.');
     }
 }
開發者ID:septembermd,項目名稱:n1,代碼行數:53,代碼來源:SearchController.php

示例2: find

 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);
 }
開發者ID:jimmyhien,項目名稱:dailyhuuhoc,代碼行數:26,代碼來源:ProductsController.php

示例3: index

 /**
  * 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;
 }
開發者ID:abrahammontas,項目名稱:Supplements-online-store,代碼行數:12,代碼來源:ProductsController.php

示例4: productAlmostOutOfStock

 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;
 }
開發者ID:sliekasirdis79,項目名稱:POS,代碼行數:29,代碼來源:AlertController.php

示例5: getView

    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 ) );
    }
開發者ID:alur86,項目名稱:PHP_Code_Samples,代碼行數:8,代碼來源:ProductController.php

示例6: getList

 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);
 }
開發者ID:huanghua581,項目名稱:erp,代碼行數:8,代碼來源:GoodsController.php

示例7: indexAction

 public function indexAction()
 {
     $query = Product::with(["category"]);
     $category = Input::get("category");
     if ($category) {
         $query->where("category_id", $category);
     }
     return $query->get();
 }
開發者ID:gitter-badger,項目名稱:tutorial-laravel-4-e-commerce,代碼行數:9,代碼來源:ProductController.php

示例8: _name

 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;
 }
開發者ID:sliekasirdis79,項目名稱:POS,代碼行數:10,代碼來源:ProductController.php

示例9: index

 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));
 }
開發者ID:basuritas-laravel,項目名稱:laravel-seo,代碼行數:12,代碼來源:SeoController.php

示例10: view

 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'));
 }
開發者ID:fbf,項目名稱:laravel-food,代碼行數:12,代碼來源:ProductsController.php

示例11: listProduct

 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);
 }
開發者ID:qnck,項目名稱:qingnianchuangke,代碼行數:17,代碼來源:OfficeProductController.php

示例12: index

 /**
  * 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'));
 }
開發者ID:hiten1986,項目名稱:LaravelWebshopAdmin,代碼行數:23,代碼來源:AdminProductsController.php

示例13: getProduct

 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);
 }
開發者ID:qnck,項目名稱:qingnianchuangke,代碼行數:41,代碼來源:ProductController.php

示例14: ajaxCollection

 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]);
 }
開發者ID:Fash1,項目名稱:Fash1,代碼行數:38,代碼來源:ProductController.php

示例15: get_index

 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);
 }
開發者ID:TahsinGokalp,項目名稱:L3-Eticaret,代碼行數:36,代碼來源:product.php


注:本文中的Product::with方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。