本文整理汇总了PHP中common\models\Product类的典型用法代码示例。如果您正苦于以下问题:PHP Product类的具体用法?PHP Product怎么用?PHP Product使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Product类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]);
}
示例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]);
}
示例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]);
}
示例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;
}
示例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;
}
}
示例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]);
}
示例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]);
}
示例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]);
}
示例9: actionUpdate
public function actionUpdate($id, $quantity)
{
$product = Product::findOne($id);
if ($product) {
\Yii::$app->cart->update($product, $quantity);
$this->redirect(['cart/list']);
}
}
示例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'));
}
示例11: getProduct
public function getProduct()
{
/**
* 第一个参数为要关联的字表模型类名称,
* 第二个参数指定 通过子表的 customer_id 去关联主表的 id 字段
*/
return $this->hasOne(Product::className(), ['product_id' => 'product_id']);
}
示例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]);
}
示例13: findById
public function findById($id)
{
if (($model = Product::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('请求页面不存在');
}
}
示例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.');
}
}
示例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.'));
}
}