/** * @return Product */ public function getProduct() { if (is_null($this->_product)) { $this->_product = Product::findOne($this->product_id); } return $this->_product; }
/** * @param $node * @return string * @throws NotFoundHttpException */ public function actionList($node) { /** @var Order $order */ $order = Order::findOne($node); if (!$order) { throw new NotFoundHttpException(); } $newProduct = new AddProductForm(); if ($newProduct->load(\Yii::$app->request->post()) && $newProduct->validate()) { /** @var OrderData $existingLine */ $existingLine = OrderData::find()->where(['product_id' => $newProduct->product_id, 'order_id' => $order->id])->one(); if ($existingLine) { $existingLine->quantity += $newProduct->quantity; $existingLine->save(); } else { /** @var Product $product */ $product = Product::findOne($newProduct->product_id); if ($product) { $line = new OrderData(['product_id' => $product->id, 'quantity' => $newProduct->quantity, 'price' => $product->price]); $order->link('orderLines', $line); } } } return $this->render('list', ['order' => $order, 'newProduct' => $newProduct]); }
public function process() { if ($this->validate()) { if (!is_null($this->importFile)) { $imported = 0; $errors = 0; if (($handle = fopen($this->importFile->tempName, "r")) !== FALSE) { $keys = fgetcsv($handle); while (($row = fgetcsv($handle)) !== FALSE) { $data = []; for ($c = 0; $c < count($row); $c++) { $data[$keys[$c]] = $row[$c]; } /** @var Product $product */ $product = array_key_exists('id', $data) && $data['id'] ? Product::findOne($data['id']) : new Product(); if ($product->from_array($data)) { $imported++; } else { $errors++; } } fclose($handle); } return "Imported: {$imported}, Errors: {$errors}"; } else { return "File not found"; } } else { return "Invalid File"; } }
public function actionAjaxAdd() { Yii::$app->response->format = Response::FORMAT_JSON; $request = Yii::$app->request; $id = $request->get('id'); $color = $request->get('color'); $size = $request->get('size'); $number = $request->get('num'); $model = Product::findOne($id); if (!Yii::$app->session->isActive) { Yii::$app->session->open(); } $cart = new Cart(); $cart->session_id = Yii::$app->session->id; $cart->user_id = Yii::$app->user->isGuest ? 0 : Yii::$app->user->id; $cart->product_id = $id; $cart->name = $model->name; $cart->color = $color; $cart->size = $size; $cart->number = $number; $cart->price = $model->price; if ($cart->save()) { return ['status' => 1, 'productId' => $id, 'size' => $size, 'color' => $color]; } else { return ['status' => -2, 'productId' => $id, 'size' => $size, 'color' => $color]; } }
/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Product::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Продукт с номером ID ' . $id . ' не обнаружен.'); } }
/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Product::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionUpdate($itemId, $quantity) { $product = Product::findOne($itemId); if ($product) { \Yii::$app->cart->update($product, $quantity); $this->redirect(['cart/list']); } }
public function actionUpdate($id, $quantity) { $product = Product::findOne($id); if ($product) { $this->_cart->update($product, $quantity); $this->redirect(['cart/list']); } }
/** * @param $id * @return \yii\web\Response * @throws NotFoundHttpException * @throws \Exception */ public function actionDelete($id) { /** @var Product $model */ $model = Product::findOne($id); if (!$model) { throw new NotFoundHttpException(); } $model->delete(); return $this->redirect(['list', 'node' => $model->category_id]); }
/** * Ajaxified version of ProductController actionEdit * @return partial */ public function actionEditProduct($id) { $model = Product::findOne($id); if (Yii::$app->request->isAjax || Yii::$app->request->isPjax) { if ($model->load(Yii::$app->request->post()) && $model->save()) { $model = new Product(); } return $this->renderPartial('_product_edit', ['model' => $model]); } }
public function findModel($id) { $search = new Product(); $search->scenario = Product::SCENARIO_READ; if (($model = $search->findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionAddToCart($id) { $cart = new ShoppingCart(); $model = Product::findOne($id); if ($model) { $cart->put($model, 1); return $this->redirect(['cart-view']); } throw new NotFoundHttpException(); }
public function actionProduct() { $request = Yii::$app->request; $product = null; if ($code = $request->get('code')) { $product = Product::find()->where(['url_code' => $code])->one(); } if (is_null($product) && ($id = $request->get('id'))) { $product = Product::findOne($id); } if (!is_null($product)) { return $this->render('product', ['model' => $product]); } else { return $this->goHome(); } }
public function exportRestaurantMenuToCsv($id) { $restaurantName = Restaurant::findOne(['restaurant_id' => $id])->name; Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/web/upload/'; $string = "name, description, price \n"; $product = null; foreach (Warehouse::find()->where(['restaurant_id' => $id])->batch(1) as $warehouse) { try { $product = Product::findOne(['product_id' => $warehouse[0]->product_id]); $string .= '"' . $product->name . '","' . $product->description . '","' . $warehouse[0]->price . '"'; $string .= "\n"; } catch (Exception $e) { } } $path = $this->saveStringToCsvFile($string, $restaurantName); $this->giveUserFile($path); }
/** * Validates product */ public function validateProduct() { if (!Product::findOne($this->product_id)) { $this->addError('product_id', \Yii::t('app', 'Product does not exist.')); } }
public function actionLoadCart() { $return = []; $total = 0; if (isset(Yii::$app->user->id)) { $cart = Cart::findOne(['user_id' => Yii::$app->user->id, 'status' => 'CREATED']); if ($cart) { foreach ($cart->productscarts as $k => $productCart) { $aux = []; $aux['name'] = $productCart->product->name; $aux['value'] = $productCart->quantity; $aux['won'] = $productCart->won; $return[$productCart->product->id] = $aux; $total += $productCart->product->price * $productCart->quantity; } $return['total'] = $total; } } else { $cart = Yii::$app->session['cart']; if ($cart) { foreach ($cart as $k => $ca) { $aux = []; $product = Product::findOne($k); $aux['name'] = $product->name; $aux['value'] = $ca; $aux['won'] = 'NO'; $return[$product->id] = $aux; $total += $product->price * $ca; } $return['total'] = $total; } } echo json_encode($return); }
<?php /** @var $ids [] */ /** @var $template string */ /** @var Product[] $list */ use app\models\Product; $list = []; if (isset($ids) && is_array($ids)) { foreach ($ids as $id) { $p = Product::findOne($id); if (!is_null($p)) { $list[] = $p; } } } $cellClass = 'col-xs-6'; if (isset($columns)) { if ($columns == 3) { $cellClass = 'col-sm-4 col-xs-6'; } if ($columns == 4) { $cellClass = 'col-sm-3 col-xs-6'; } } ?> <div class="row"> <?php foreach ($list as $model) { ?> <div class="<?php echo $cellClass;
</div> </div> <!-- <a href="#" class="flecha-r"><img src="<?php echo URL::base(); ?> /images/flecha-seccR.svg" alt="flecha"/></a> --> </section> <?php } ?> </section> <!-- --> <?php if (Yii::$app->getRequest()->getCookies()->has('product')) { $product_id = Yii::$app->getRequest()->getCookies()->getValue('product'); $product_i = Product::findOne($product_id); ?> <section class="cont-servicios" style="background-image:url('<?php echo URL::base(); ?> /images/productos-interna/<?php echo $product_i->background1; ?> ')"> <div class="txt-secc"> <span id="linea-s"><?php echo $product_i->title; ?> </span> <!-- <span id="linea-s">línea</span> <span id="linea-c">Caressa</span> -->
/** * Updates an existing Product model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { if (Yii::$app->user->isGuest || Yii::$app->user->identity->user_role != 4) { return $this->goHome(); } else { if (Yii::$app->request->isAjax) { return $this->updateAjax(); } else { $model = Product::findOne(['product_id' => $id]); $model->scenario = Product::SCENARIO_UPDATE; return $this->render('update', ['model' => $model]); } } }
public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); $oldImages = $this->imagesWithoutPlaceholder; $newImages = $this->pictures; // Detach old images foreach ($oldImages as $img) { if (!in_array($img->filePath, $newImages)) { $this->removeImage($img); } else { $newImages = array_diff($newImages, [$img->filePath]); } } // Attach new images foreach ($newImages as $path) { $this->attachImage($path); } // Set main image $mainImage = $this->findImageByPath($this->mainPicture); if ($mainImage) { $this->setMainImage($mainImage); } // Link and unlink products $oldProducts = ArrayHelper::map($this->linkedProducts, 'id', 'id'); $newProducts = $this->products; $addProducts = array_diff($newProducts, $oldProducts); $removeProducts = array_diff($oldProducts, $newProducts); foreach ($addProducts as $pid) { $this->link('linkedProducts', Product::findOne($pid)); } foreach ($removeProducts as $pid) { $this->unlink('linkedProducts', Product::findOne($pid), true); } }
public function actionGetProductDetail($productID) { $product = Product::findOne($productID); echo Json::encode($product); }
/** * @param $shopCart ShoppingCart */ public function restoreUserShopCart($shopCart) { $jsonData = $this->getProperty(self::USER_SHOPCART, null); if (!empty($jsonData) && !empty($data = json_decode($jsonData, true))) { foreach ($data as $item) { /** @var Product $product */ $product = Product::findOne($item['product_id']); if (!is_null($product)) { $shopCart->addProduct($product, $item['quantity'], $item['product_data']); } } } }
/** * [getProductPrice description] * @return Float product price */ public function getProductPrice() { $product = Product::findOne($this->item_id); // debug var_dump($product); return $product->getPrice(); }
<?php use app\models\Comment; use app\models\Product; use app\modules\user\models\User; use app\widgets\BackLink; use app\widgets\EntityDropDown; use app\widgets\Rating; use yii\bootstrap\ActiveForm; use yii\bootstrap\Html; use yii\bootstrap\Nav; use yii\helpers\Url; /** @var Comment $model */ $this->title = Yii::t('app', 'Update a comment: ' . $model->id . ' (' . Product::findOne($model->product_id)->name) . ' - ' . User::findOne($model->user_id)->name . ')'; echo Nav::widget(['encodeLabels' => false, 'items' => [['label' => BackLink::widget(['title' => Yii::t('app', 'Comments'), 'textOnly' => true]), 'url' => Url::to(['/admin/comment/list']), 'active' => true]], 'options' => ['class' => 'nav-pills']]); ?> <div class="comment-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'product_id')->hiddenInput()->label(false); ?> <?php echo $form->field($model, 'user_id')->hiddenInput()->label(false); ?> <?php
public function actionAddProduct($id) { /** @var Product $model */ $model = Product::findOne($id); $qty = isset($_REQUEST['quantity']) && is_numeric($_REQUEST['quantity']) && $_REQUEST['quantity'] > 0 ? $_REQUEST['quantity'] : 1; $data = isset($_REQUEST['data']) && !empty($_REQUEST['data']) ? $_REQUEST['data'] : ''; $this->getShoppingCart()->addProduct($model, $qty, $data); if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; $message = Yii::t('app', '<span class="glyphicon glyphicon-ok"></span> Product <strong>{pname}</strong> added to Shopping Cart', ['pname' => $model->getName(Yii::$app->language)]); return ['result' => 'ok', 'message' => $message]; } else { return $this->redirect(['index']); } }
public function actionAddproductname() { $data = json_decode(file_get_contents("php://input")); if (@$data->sn) { $model = Product::findOne($data->sn); $model->sn = $data->sn; } else { $model = new Product(); } if (@$data->pid) { $model->ProductID = $data->pid; } else { $pd = strtotime(date("Y-m-d H:i:s")); $model->ProductID = $pd; } $model->ProductName = $data->productname; $model->CategoryID = $data->cname; if ($model->save()) { $arr = array('msg' => "Product Name Added Successfully !!!", 'error' => ''); $jsn = json_encode($arr); print_r($jsn); } }
/** * Finds the Product model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Product the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $provider = $this->getProvider(); if (($model = Product::findOne($id)) !== null && $model->provider_id == $provider->id) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use app\models\Product; use app\modules\admin\models\CommentSearch; use app\modules\user\models\User; use app\widgets\EntityDropDown; use app\widgets\Rating; use yii\bootstrap\Html; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; use yii\web\View; /** * @var CommentSearch $searchModel * @var ActiveDataProvider $dataProvider * @var View $this */ $this->title = Yii::t('app', 'Comments'); ?> <?php echo \yii\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['attribute' => 'product_id', 'filter' => false, 'format' => 'text'], ['label' => Yii::t('app', 'Product name'), 'filter' => false, 'format' => 'html', 'value' => function ($comment) { /** @var Product $product */ $product = Product::findOne($comment->product_id); return Html::a($product->name, ['/admin/product/update', 'id' => $product->id]); }], ['attribute' => 'user_id', 'format' => 'html', 'filter' => EntityDropDown::widget(['model' => $searchModel, 'attribute' => 'user_id', 'items' => ArrayHelper::map(User::find()->all(), 'id', 'name')]), 'value' => function ($comment) { return User::findOne($comment->user_id)->name; }], ['attribute' => 'body', 'format' => 'text', 'value' => function ($comment) { return \yii\helpers\StringHelper::truncateWords($comment->body, 10); }], 'created_at:datetime', ['attribute' => 'rating', 'format' => 'raw', 'filter' => false, 'value' => function ($comment) { return Rating::widget(['readonly' => true, 'name' => "rating[{$comment->id}]", 'value' => $comment->rating]); }], ['attribute' => 'status', 'format' => 'html', 'filter' => EntityDropDown::widget(['model' => $searchModel, 'attribute' => 'user_id', 'items' => [Yii::t('app', 'Inactive'), Yii::t('app', 'Active')]]), 'value' => function ($comment) { return $comment->status == Comment::STATUS_ACTIVE ? Yii::t('app', 'Active') : Yii::t('app', 'Inactive'); }], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]);
public function actionIndex() { $product = Product::findOne(6); $line = Line::findOne(3); return $this->render('index', ['product' => $product, 'line' => $line]); }
?> ">See all products</a> <h3>Top Sellers</h3> <table class="table"> <thead> <tr> <th>Name</th> <th>Provider</th> <th style="text-align: right">Sales</th> </tr> </thead> <tbody> <?php foreach ($products as $row) { /** @var Product $product */ $product = Product::findOne($row['product_id']); $sales = $row['cant']; ?> <tr> <td><?php echo $product->getName(); ?> </td> <td><?php echo !is_null($product->provider) ? $product->provider->name : ''; ?> </td> <td style="text-align: right"><?php echo $sales; ?> </td>