public function getPrice($id) { foreach (Product::find('price')->where(['id' => $id])->all() as $product) { $productPrice = $product['price']; } return $productPrice; }
/** * Lists all Images models. * @return mixed */ public function actionIndex($itemId) { if (!Product::find()->where(['item_id' => $itemId])->exists()) { throw new NotFoundHttpException(); } $form = new MultipleUploadForm(); $searchModel = new ImagesSearch(); $searchModel->item_id = $itemId; $dataProvider = $searchModel->search(Yii::$app->request->queryParams); if (Yii::$app->request->isPost) { $form->files = UploadedFile::getInstances($form, 'files'); if ($form->files && $form->validate()) { foreach ($form->files as $file) { $images = new Images(); $images->item_id = $itemId; if ($images->save()) { // writes file name to images table $images->big_image = $images->getUrl(); } if ($images->save()) { // saves file to folder $file->saveAs($images->getPath()); } } } } return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'uploadForm' => $form]); }
public function actionView($slug = null) { $model = Product::find()->bySlug($slug)->one(); $productByCategory = Product::find()->byCategory($model->category_id)->limit(4)->all(); $productByProduce = Product::find()->byProducer($model->producer_id)->limit(4)->all(); return $this->render('view', ['model' => $model, 'productByCategory' => $productByCategory ? ['category' => $model->category, 'data' => $productByCategory] : null, 'productByProduce' => $productByProduce ? ['producer' => $model->producer, 'data' => $productByProduce] : null]); }
public function actionMenu($id) { $roots = Category::find()->all(); $categ = Category::find()->where(array('id' => $id))->all(); $prods = Product::find()->where(array('id_category' => $id))->all(); return $this->render('menu', ['roots' => $roots, 'prods' => $prods, 'categ' => $categ]); }
public function actionDanhsach() { $query = Product::find(); $pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $query->count()]); $products = $query->orderBy('product_name')->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('danhsach', ['product' => $products, 'pagination' => $pagination]); }
/** * Change the currency. * * @return Redirect */ public function show(Request $request, string $currency) { $request->session()->put('currency', $currency); $currency = Currency::where('currency', $currency)->first()->toArray(); $request->session()->put('currency_rate', $currency['rate']); // we need to update the basket $basket = $request->session()->get('basket'); foreach ($basket['items'] as $id => $item) { if (isset($item['parent_sku'])) { // its an option $product = Product::where('sku', $item['parent_sku'])->first(); $price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price; foreach ($product->option_values as $option) { if ($option['sku'] == $id) { $price = number_format($option['price'] * $request->session()->get('currency_rate'), 2, '.', ''); } } } else { $product = Product::find($id); $price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price; } $basket['items'][$id]['price'] = $price; } $request->session()->put('basket', $basket); return redirect()->back(); }
/** * Update the visibility of a product * * @param $id * @param $visible * @return mixed */ public function updateVisibility($id, $visible) { $product = Product::find($id); $product->visible = $visible; $product->save(); return $product; }
/** * Get Customers who requested for a respective Product * AJAX * * @param Request $request * @return Array */ public function updateProductStatus(Request $request) { if ($request->ajax()) { $product = Product::find($request->product_id); return $this->dashboard->updateStatus($request, $product); } }
public function __construct($attributes = array()) { if (isset($attributes['product_id']) && !Product::find($attributes['product_id'])) { throw new Exception("Item not found"); } parent::__construct($attributes); }
/** * Execute the command. * * @return void */ public function handle() { $user = User::find($this->userId)->first(); $product = Product::find($this->productId); // dd($user, $product); $user->products()->save($product, ['mod' => '1']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $this->scenario = ''; $query = Product::find()->where(['active' => 1]); $this->scenario = 'default'; $this->load($params, ''); $order_arr = !empty($this->order_by) ? explode(':', $this->order_by) : ['id', 'desc']; $orderField = count($order_arr) > 0 ? $order_arr[0] : 'id'; $orderSort = count($order_arr) > 1 && $order_arr[1] == 'desc' ? SORT_DESC : SORT_ASC; $this->order_by = $orderField . ':' . ($orderSort == SORT_DESC ? 'desc' : 'asc'); /** @var Category $category */ if (isset($params['code']) && !empty($params['code'])) { $this->_category = Category::find()->where(['url_code' => $params['code']])->one(); } if (is_null($this->_category) && isset($params['id']) && !empty($params['id'])) { $this->_category = Category::findOne($params['id']); } if (!is_null($this->_category)) { $arr_cats = $this->_category->fillSubCategoryArray(); $query->andFilterWhere(['in', 'category_id', $arr_cats]); } $per_page = isset($params['per-page']) ? $params['per-page'] : 12; $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $per_page], 'sort' => ['defaultOrder' => ['new' => SORT_DESC], 'attributes' => ['new' => ['desc' => ['id' => SORT_DESC], 'asc' => false, 'default' => SORT_DESC, 'label' => Yii::t('app', 'Newest Arrivals')], 'featured' => ['asc' => false, 'desc' => ['featured' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Featured')], 'price_asc' => ['desc' => false, 'asc' => ['price_custom' => SORT_ASC], 'default' => SORT_ASC, 'label' => Yii::t('app', 'Price: Low to High')], 'price_desc' => ['asc' => false, 'desc' => ['price_custom' => SORT_DESC], 'default' => SORT_DESC, 'label' => Yii::t('app', 'Price: High to Low')]]]]); return $dataProvider; }
public function postAddtocart() { $product = Product::find(Input::get('id')); $quantity = Input::get('quantity'); Cart::insert(['id' => $product->id, 'name' => $product->title, 'price' => $product->price, 'quantity' => $quantity, 'image' => $product->image]); return Redirect::to('store/cart'); }
public function product_view($id) { $product = Product::find($id); $product->images = json_decode($product->images); $data = ['product' => $product]; return view('order.product_view', compact('data')); }
function save(array $params) { $response = new ResponseEntity(); DB::transaction(function () use(&$response, $params) { $user = User::find(Auth::user()->id); $product = Product::find($params['product_id']); $cust = new Customer(); $cust->first_name = $params['customer']['first_name']; $cust->last_name = $params['customer']['last_name']; $cust->phone_number = $params['customer']['phone_number']; $custCreated = $cust->save(); if ($custCreated && $product && $user) { $sale = new Sale(); $sale->user_id = $user->id; $sale->sale_status_id = Config::get('constants.sale_status.sale'); $sale->product_id = $product->id; $sale->customer_id = $cust->id; $sale->date_sold = Carbon::createFromFormat('m/d/Y', $params['date_sold'])->toDateString(); $sale->remarks = isset($params['remarks']) ? $params['remarks'] : ''; $sale->order_number = $params['order_number']; $sale->ninety_days = isset($params['ninety_days']) ?: 0; $ok = $sale->save(); if ($ok) { $ok = $this->setIncentive($sale->user_id, $sale->date_sold); $response->setMessages($ok ? ['Sale successfully created!'] : ['Failed to create sale!']); $response->setSuccess($ok); } else { $response->setMessages(['Failed to create sale!']); } } else { $response->setMessages(['Entities not found']); } }); return $response; }
public function run() { // query $product = Product::find()->orderBy('RAND()')->limit(3)->all(); //render view return $this->render('random', ['product' => $product]); }
public function actionIndex() { $query1 = Product::find(); $pagination = new Pagination(['defaultPageSize' => 6, 'totalCount' => $query1->count()]); $products = $query1->orderBy('product_name')->offset($pagination->offset)->limit($pagination->limit)->all(); $category = Category::showCategory(); return $this->render('index', ['product' => $products, 'category' => $category, 'pagination' => $pagination]); }
public function index($pid) { $product = \App\Models\Product::find($pid) ?: $this->notFoundJson(); $query = $product->categories(); $count = $query->count(); $query->forPage(request('page', 1), request('limit', $this->pageLimit)); return ["count" => $count, "limit" => request('limit', $this->pageLimit), "page" => request()->input('page', 1), "items" => $query->get()]; }
public function actionIndex() { $cateCount = Category::find()->count(); $productCount = Product::find()->count(); $onlineCount = Session::find()->where(['status' => 1])->count(); $userCount = Session::find()->count(); return $this->render('index', ['cateCount' => $cateCount, 'productCount' => $productCount, 'onlineCount' => $onlineCount, 'userCount' => $userCount]); }
public function destroy($productId) { $product = Product::find($productId)->delete(); if (!$product) { return $this->responseNotFound(['Product Id not found']); } return $this->responseOk($product); }
public function postAdd() { $id = Input::get('id'); $qty = Input::get('qty'); $product = Product::find($id); Cart::associate('Product', 'App\\Models')->add($product->id, $product->name, $qty, $product->price()); $this->update_cart(); return Redirect::back(); }
public function addItem(Request $request) { $item = $request->only('id', 'quantity'); $product = \App\Models\Product::find($item['id']); $item["name"] = $product->name; $item["price"] = $product->price; \Cart::insert($item); return redirect('cart'); }
public function index() { // $categories = Category::paginate(Config('constants.paginateNo')); $prod = Product::find(18); $relatedProd = $prod->relatedproducts()->with('catalogimgs')->take(1)->get()->toArray(); $upsellProd = $prod->upsellproducts()->with('catalogimgs')->take(3)->get()->toArray(); // Session::get('loggedinUserId'); return view(Config('constants.frontendCategoryView') . '.category', compact('relatedProd', 'upsellProd')); }
/** * Adds an item to the cart * * @return Response */ public function add($product_id) { $product = Product::find($product_id); if (!$product) { abort(404); } Cart::associate('Product', 'App\\Models')->add($product_id, $product->name, 1, $product->price); return redirect()->route('cart.index'); }
public function actionIndex() { $query = Product::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 10]); $pages->pageSizeParam = false; $products = $query->offset($pages->offset)->limit($pages->limit)->orderBy(['id' => SORT_DESC])->all(); return $this->render('index', ['products' => $products, 'pages' => $pages]); }
public function update(ProductUpdateRequest $request, $id) { $input = $request->except('categories'); $input = $this->uploadPicture($input); $product = Product::find($id); $product->update($input); $product->categories()->sync($request->categories); return redirect('admin/products'); }
/** * @param int[] $products * * @return string */ public function actionCheck($products) { $query = Product::find(); $products = json_decode($products, true); $dataProvider = new ActiveDataProvider(['query' => $query]); foreach ($products as $id) { $query->orFilterWhere(['id' => $id]); } return $this->render('check', ['dataProvider' => $dataProvider]); }
public function actionList() { $arrProducts = []; $arrProductsObj = \app\models\Product::find()->all(); foreach ($arrProductsObj as $p) { $arrProducts[$p->productCode] = $p->toArray(); } echo json_encode($arrProducts); Yii::$app->end(); }
function isProductOwner($productId) { $u = Auth::user(); $p = \App\Models\Product::find($productId); // Check if they're a direct owner first if ($u->id == $p->user_id) { return true; } return false; }
/** * Adds a new product to the shopping cart. * * @return \Illuminate\Http\RedirectResponse */ public function addAjax($id) { // Get the product from the database if (!($product = Product::find($id))) { return json_encode(['error' => 'invalid product.']); } // Add the item to the cart $item = $this->addToWishlist($product); return $item->toArray(); }
public function search($params) { $query = Product::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); // load the seach form data and validate if (!($this->load($params) && $this->validate())) { return $dataProvider; } return $dataProvider; }