本文整理汇总了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.');
}
}
示例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);
}
示例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;
}
示例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;
}
示例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 ) );
}
示例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);
}
示例7: indexAction
public function indexAction()
{
$query = Product::with(["category"]);
$category = Input::get("category");
if ($category) {
$query->where("category_id", $category);
}
return $query->get();
}
示例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;
}
示例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));
}
示例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'));
}
示例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);
}
示例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'));
}
示例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);
}
示例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]);
}
示例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);
}