本文整理汇总了PHP中common\models\Product::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::findOne方法的具体用法?PHP Product::findOne怎么用?PHP Product::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Product
的用法示例。
在下文中一共展示了Product::findOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
}
示例2: 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;
}
示例3: 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]);
}
示例4: 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.');
}
}
示例5: actionUpdate
public function actionUpdate($id, $quantity)
{
$product = Product::findOne($id);
if ($product) {
\Yii::$app->cart->update($product, $quantity);
$this->redirect(['cart/list']);
}
}
示例6: findById
public function findById($id)
{
if (($model = Product::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('请求页面不存在');
}
}
示例7: 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.'));
}
}
示例8: 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();
}
示例9: 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;
}
}
示例10: actionDetail
public function actionDetail($id)
{
$product = Product::findOne(['prod_id' => $id]);
// echo '<pre>';
// print_r(Product::getMetaByName('color'));exit;
//echo '<pre>';
// print_r($product->getProductImg('color')); exit;
return $this->render('detail', ['prod' => $product]);
}
示例11: actionUpdate
public function actionUpdate($id)
{
$model = Product::findOne($id);
if ($model->load(\Yii::$app->request->post())) {
if ($model->validate() && $model->save()) {
return $this->redirect(['index']);
}
}
return $this->render('form', ['model' => $model]);
}
示例12: actionToggle
public function actionToggle()
{
$id = Yii::$app->request->post('id');
if (($product = Product::findOne(['id' => $id])) && !$this->user->hasWish($id)) {
$this->user->addWish($product);
return ['status' => 'added'];
} else {
$this->user->removeWish($product);
return ['status' => 'removed'];
}
}
示例13: actionProduct
public function actionProduct($id)
{
if ($id) {
$product = Product::findOne(['id' => $id]);
if ($product === NULL) {
throw new NotFoundHttpException("Товар № {$id} не найден");
}
$this->getView()->title = "Mexanika 74 - Каталог техники: " . $product->name;
return $this->render('product_item', ['product' => $product]);
}
}
示例14: actionDelete
/**
* @param $id
* @return array
* @throws NotFoundHttpException
* @throws InvalidParamException
*/
public function actionDelete($id)
{
$image = Image::findOne($id);
$filePath = $image->getPathToOrigin();
if (!$image) {
throw new NotFoundHttpException('Image not found');
}
$product = Product::findOne($image->itemId);
if (!$product) {
throw new NotFoundHttpException('Product not found');
}
$product->removeImage($image);
if (file_exists($filePath)) {
return ['error' => 'Ошибка удаления файла'];
} else {
Yii::$app->getResponse()->setStatusCode(204);
}
}
示例15: actionDeleteAvatar
/**
* @return string
*/
public function actionDeleteAvatar()
{
$imageData = Json::decode(Yii::$app->request->post('imageData'));
$modelImageForm = new ImageForm();
$modelImageForm->deleteImage();
if (Yii::$app->session->get('error')) {
echo $error = Yii::$app->session->get('error');
} else {
$error = false;
}
/* @var $model \common\models\Profile */
if ($imageData['modelName'] == 'Carousel') {
$model = Carousel::findOne($imageData['object_id']);
} elseif ($imageData['modelName'] == 'Product') {
$model = Product::findOne($imageData['object_id']);
}
$imagesObject = $model->imagesOfObjects;
return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imageSmallWidth' => $imageData['imageSmallWidth'], 'imageSmallHeight' => $imageData['imageSmallHeight'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]);
}