本文整理汇总了PHP中common\models\Product类的典型用法代码示例。如果您正苦于以下问题:PHP Product类的具体用法?PHP Product怎么用?PHP Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: actionView
public function actionView($slug)
{
$productModel = new Product();
$productData = $productModel->findOne(['slug' => $slug]);
$relatedProduct = $productModel->find()->where(['category_id' => $productData->category_id])->andWhere(['<>', 'id', $productData->id])->limit(9)->orderBy(['id' => SORT_ASC])->all();
return $this->render('view', ['node' => $productData, 'relateNodes' => $relatedProduct]);
}
开发者ID:nguyentuansieu,项目名称:phutungoto,代码行数:7,代码来源:ProductController.php
示例2: actionCreate
public function actionCreate()
{
$model = new Product();
if ($model->load(\Yii::$app->request->post())) {
if ($model->validate() && $model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('form', ['model' => $model]);
}
开发者ID:afernandes465,项目名称:fafediesel,代码行数:10,代码来源:ProductController.php
示例3: run
public function run()
{
parent::run();
// TODO: Change the autogenerated stub
$nodes = Product::find()->where(['status' => 10])->limit(3)->all();
return $this->render('ProductBottomTopWidget', ['nodes' => $nodes]);
}
开发者ID:nguyentuansieu,项目名称:BioMedia,代码行数:7,代码来源:ProductBottomTopWidget.php
示例4: actionProductpic
/**
* 上传商品图片
*/
public function actionProductpic()
{
$user_id = \Yii::$app->user->getId();
$p_params = Yii::$app->request->get();
$product = Product::findOne($p_params['id']);
if (!$product) {
throw new NotFoundHttpException(Yii::t('app', 'Page not found'));
}
$picture = new UploadForm();
$picture->file = UploadedFile::getInstance($product, 'product_s_img');
if ($picture->file !== null && $picture->validate()) {
Yii::$app->response->getHeaders()->set('Vary', 'Accept');
Yii::$app->response->format = Response::FORMAT_JSON;
$response = [];
if ($picture->productSave()) {
$response['files'][] = ['name' => $picture->file->name, 'type' => $picture->file->type, 'size' => $picture->file->size, 'url' => '/' . $picture->getImageUrl(), 'thumbnailUrl' => '/' . $picture->getOImageUrl(), 'deleteUrl' => Url::to(['/uploadfile/deletepropic', 'id' => $picture->getID()]), 'deleteType' => 'POST'];
} else {
$response[] = ['error' => Yii::t('app', '上传错误')];
}
@unlink($picture->file->tempName);
} else {
if ($picture->hasErrors()) {
$response[] = ['error' => '上传错误'];
} else {
throw new HttpException(500, Yii::t('app', '上传错误'));
}
}
return $response;
}
开发者ID:uqiauto,项目名称:wxzuan,代码行数:32,代码来源:UploadfileController.php
示例5: generateTrans
/**
* @brief 根据用户的输入产生交易记录
*
* @return public function
* @retval
* @see
* @note
* @author 吕宝贵
* @date 2015/12/19 20:39:07
**/
public function generateTrans()
{
$product = Product::findOne(['pid' => $this->booking->pid]);
$buyerAccount = Yii::$app->account->getUserAccount(Yii::$app->user->identity['uid']);
//根据booking_id生成交易记录
$trans = new Trans();
$trans->pay_mode = Trans::PAY_MODE_VOUCHPAY;
$trans->trans_type_id = Trans::TRANS_TYPE_TRADE;
$trans->currency = 1;
$trans->total_money = $this->booking->price_final;
$trans->profit = $this->booking->price_for_platform;
$trans->money = $trans->total_money - $trans->profit;
//保证金,目前还没有上
//$trans->earnest_money = $this->booking->earnest_money;
$trans->trans_id_ext = $this->booking_id;
$trans->from_uid = $buyerAccount->uid;
$trans->to_uid = $this->booking->hug_uid;
$trans->status = Trans::PAY_STATUS_WAITPAY;
//1为等待支付状态
if ($trans->save()) {
return $trans;
} else {
$this->addErrors($trans->getErrors());
return false;
}
}
开发者ID:lubaogui,项目名称:yii2-account,代码行数:36,代码来源:PayForm.php
示例6: actionCheckout
public function actionCheckout()
{
session_start();
$prod_ids = $_SESSION['cart-item'];
$products = Product::find()->where(['prod_id' => $prod_ids])->all();
return $this->render('checkout', ['products' => $products]);
}
开发者ID:syedmaaz,项目名称:marxmall-,代码行数:7,代码来源:HomeController.php
示例7: actionView
public function actionView($id)
{
if ($id <= 0) {
$this->goHome();
}
$allCategory = Category::find()->asArray()->all();
$arrayCategoryIdName = ArrayHelper::map($allCategory, 'id', 'name');
$arrSubCat = Category::getArraySubCatalogId($id, $allCategory);
/****** 价格筛选 ****/
$result = (new Query())->select('min(price) as min, max(price) as max')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->one();
$min = $result['min'];
$max = $result['max'];
if ($max > $min && $max > 0) {
// 计算跨度
$priceGrade = 0.0001;
for ($i = -2; $i < log10($max); $i++) {
$priceGrade *= 10;
}
$span = ceil(($max - $min) / 5 / $priceGrade) * $priceGrade;
if ($span == 0) {
$span = $priceGrade;
}
// 计算价格的起点和终点
for ($i = 1; $min > $span * $i; $i++) {
}
for ($j = 1; $min > $span * ($i - 1) + $priceGrade * $j; $j++) {
}
$priceFilter['start'] = $span * ($i - 1) + $priceGrade * ($j - 1);
for (; $max >= $span * $i; $i++) {
}
$priceFilter['end'] = $span * $i + $priceGrade * ($j - 1);
$priceFilter['span'] = $span;
}
/****** 价格筛选 end ****/
/****** 品牌筛选 start ****/
$result = (new Query())->select('distinct(brand_id)')->from('product')->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE])->all();
$ids = ArrayHelper::map($result, 'brand_id', 'brand_id');
$brandFilter = Brand::find()->where(['id' => $ids])->orderBy(['name' => SORT_ASC])->all();
/****** 品牌筛选 end ****/
$query = Product::find()->where(['category_id' => $arrSubCat, 'status' => Status::STATUS_ACTIVE]);
// 如果选择了价格区间
if (Yii::$app->request->get('max')) {
$min = intval(Yii::$app->request->get('min'));
$max = intval(Yii::$app->request->get('max'));
if ($min >= 0 && $max) {
$query->andWhere(['and', ['>', 'price', $min], ['<=', 'price', $max]]);
}
}
// 如果选择了品牌
if (Yii::$app->request->get('brand_id')) {
$brandId = intval(Yii::$app->request->get('brand_id'));
if ($brandId >= 0) {
$query->andWhere(['brand_id' => $brandId]);
}
}
// 侧边热销商品
$sameCategoryProducts = Product::find()->where(['category_id' => $id])->orderBy(['sales' => SORT_DESC])->limit(5)->all();
$dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['defaultPageSize' => Yii::$app->params['defaultPageSizeProduct']], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
return $this->render('view', ['model' => $this->findModel($id), 'allCategory' => $allCategory, 'arrayCategoryIdName' => $arrayCategoryIdName, 'products' => $dataProvider->getModels(), 'pagination' => $dataProvider->pagination, 'priceFilter' => isset($priceFilter) ? $priceFilter : null, 'brandFilter' => $brandFilter, 'sameCategoryProducts' => $sameCategoryProducts]);
}
开发者ID:CTaiDeng,项目名称:funshop,代码行数:60,代码来源:CategoryController.php
示例8: actionIndex
public function actionIndex($c_url, $sc_url, $r_url, $product_ui)
{
if (!($product = Product::find()->withProperties()->select(['{{product}}.*', 'IF(round(sum(product_review.rating) / count(product.reviews_count)) IS NULL, 0, rating) as rating'])->joinWith('productReviews')->groupBy('{{product}}.id')->with(['photos', 'videos', 'photos360'])->byUi($product_ui)->one())) {
throw new NotFoundHttpException();
}
Yii::$app->recently->add($product);
return $this->render('index', ['model' => $product]);
}
开发者ID:ninetor,项目名称:yii-classifield,代码行数:8,代码来源:ItemController.php
示例9: actionUpdate
public function actionUpdate($id, $quantity)
{
$product = Product::findOne($id);
if ($product) {
\Yii::$app->cart->update($product, $quantity);
$this->redirect(['cart/list']);
}
}
开发者ID:ibrarturi,项目名称:yii2-shop,代码行数:8,代码来源:CartController.php
示例10: actionIndex
public function actionIndex()
{
$hotProducts = Product::getHots();
$bestProducts = Product::getBests();
$newProducts = Product::getNews();
$randomProducts = Product::getRandoms();
return $this->render('index', compact('hotProducts', 'bestProducts', 'newProducts', 'randomProducts'));
}
开发者ID:su-xiaolin,项目名称:ICShop-Yii,代码行数:8,代码来源:HomeController.php
示例11: getProduct
public function getProduct()
{
/**
* 第一个参数为要关联的字表模型类名称,
* 第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
*/
return $this->hasOne(Product::className(), ['product_id' => 'product_id']);
}
开发者ID:uqiauto,项目名称:wxzuan,代码行数:8,代码来源:ProductOrder.php
示例12: actionIndex
/**
* Displays homepage.
*
* @return mixed
*/
public function actionIndex()
{
$Prod = new Product();
$Number_Of_Products = $Prod->getNumberOfProducts();
$max = $Number_Of_Products[0]["COUNT('product_id')"];
$Rand_Prod = array();
$numbers = range(1, $max);
shuffle($numbers);
if ($max >= 9) {
foreach (range(0, 8) as $number) {
array_push($Rand_Prod, $product = Product::find()->where(['product_id' => $numbers[$number]])->one());
}
} else {
throw new \yii\base\UserException("Add At Lease 9 Products to Database" . "\n" . "Products in Database : " . $max);
}
return $this->render('index', ['Rand' => $Rand_Prod]);
}
开发者ID:keszfeayym,项目名称:Nzi_Project,代码行数:22,代码来源:SiteController.php
示例13: findById
public function findById($id)
{
if (($model = Product::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('请求页面不存在');
}
}
开发者ID:xiaomige,项目名称:giishop,代码行数:8,代码来源:ProductServiceImpl.php
示例14: findModel
/**
* 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.');
}
}
开发者ID:phpsong,项目名称:ExtJS5-Yii2,代码行数:15,代码来源:ProductController.php
示例15: findModel
/**
* Finds the Product model based on its slug.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param string $slug
* @return Product the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($slug)
{
if (($model = Product::findOne(['slug' => $slug])) !== null) {
return $model;
} else {
throw new NotFoundHttpException(Yii::t('frontend', 'The requested page does not exist.'));
}
}
开发者ID:cyanofresh,项目名称:yii2shop,代码行数:15,代码来源:CatalogController.php
示例16: actionIndex
/**
* Lists all Image models.
* @param int $id product id
* @return mixed
*
* @throws NotFoundHttpException
*/
public function actionIndex($id)
{
$form = new MultipleUploadForm();
if (!Product::find()->where(['id' => $id])->exists()) {
throw new NotFoundHttpException();
}
$searchModel = new ImageSearch();
$searchModel->product_id = $id;
$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) {
//
// UPLOADING THE IMAGE:
//
$image = new Image();
$image->product_id = $id;
if ($image->save()) {
// Save an original image;
$path = $image->getPath();
$file->saveAs($path);
// Original size:
$size = getimagesize($path);
$height = $size[1];
$width = $size[0];
// IMAGINE
ImagineImage::$driver = [ImagineImage::DRIVER_GD2];
$imagine = new Imagine();
$picture = $imagine->open($path);
//---------------------------
// $size = new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT);
// $center = new Center($size);
//---------------------------
// $picture->crop(new Point(0, 0),
// new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path);
/**
* If the image's height is bigger than needed, it must be cut.
* Otherwise it must be resized.
*/
if ($height >= self::IMAGE_HEIGHT) {
$picture->thumbnail(new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path, ['quality' => 100]);
// re-save cropped image;
} else {
$picture->resize(new Box(self::IMAGE_WIDTH, self::IMAGE_HEIGHT))->save($path);
}
sleep(1);
// $background = new Color('#FFF');
// $topLeft = new Point(0, 0);
// $canvas = $imagine->create(new Box(450, 450), $background);
// $canvas->paste($picture, $topLeft)->save($path);
}
}
}
}
return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'uploadForm' => $form]);
}
开发者ID:Krinnerion,项目名称:shop,代码行数:64,代码来源:ImageController.php
示例17: save
/**
* 保存商品
*/
public function save()
{
#获得用户的地区信息用来提供浏览者的显示信息
$userinfo = \Yii::$app->user->getIdentity();
$newProduct = new Product();
$newProduct->product_country = 0;
if (!empty($userinfo->province)) {
$newProduct->product_province = $userinfo->province;
}
if (!empty($userinfo->city)) {
$newProduct->product_city = $userinfo->city;
}
if (!empty($userinfo->area)) {
$newProduct->product_area = $userinfo->area;
}
$newProduct->setAttributes($this->attributes);
return $newProduct->save();
}
开发者ID:wxzuan,项目名称:wxzuan,代码行数:21,代码来源:AddProductForm.php
示例18: actionOrganization
public function actionOrganization($id)
{
// Все кроме текущей
$orgList = Organization::loadList('*', "id != {$id}");
// Продукты организации
$productList = Product::loadList('*', ['organization_id' => $id]);
$model = $this->findModel($id);
return $this->render('organization', ['model' => $model, 'orgList' => $orgList, 'productList' => $productList]);
}
开发者ID:kibercoder,项目名称:bilious-octo-fibula,代码行数:9,代码来源:DefaultController.php
示例19: getModel
public function getModel($id)
{
$product = Product::findOne($id);
if (!$product) {
throw new NotFoundHttpException(Yii::t('app', 'specify product could not be found.'));
} else {
return $product;
}
}
开发者ID:su-xiaolin,项目名称:ICShop-Yii,代码行数:9,代码来源:ProductController.php
示例20: actionRemove
/**
* Remove a product from the cart.
* @param $id
* @throws NotFoundHttpException
*/
public function actionRemove($id)
{
$model = Product::findOne($id);
if ($model) {
\Yii::$app->cart->remove($model);
$this->redirect(['index']);
}
throw new NotFoundHttpException();
}
开发者ID:Krinnerion,项目名称:shop,代码行数:14,代码来源:CartController.php
注:本文中的common\models\Product类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论