public function getListProductFeature($setting) { $data['products'] = array(); if (!$setting['limit']) { $setting['limit'] = 4; } if (!empty($setting['product'])) { $products = array_slice($setting['product'], 0, (int) $setting['limit']); foreach ($products as $product_id) { $product = new Product(); $product_info = $product->getProduct($product_id); $data['products'][] = array('product_id' => $product_info['product_id'], 'thumb' => 'assets/image/' . $product_info['image'], 'name' => $product_info['name'], 'description' => substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, (int) \Yii::$app->params['config_product_description_length']) . '..', 'price' => $product_info['price'], 'special' => $product_info['special'], 'rating' => $product_info['rating'], 'href' => 'product/product/' . 'product_id=' . $product_info['product_id']); } } return $data; }
public function getBestSellerProducts() { $product_data = array(); $order = new OrderProduct(); $data = $order->getAllBestSellerProducts(12); $product = new Product(); $count = 0; foreach ($data as $result) { $info = $product->getProduct($result['product_id']); $product_data[$count]['product_id'] = $result['product_id']; $product_data[$count]['thumb'] = 'assets/image/' . $info['image']; $product_data[$count]['name'] = $info['image']; $product_data[$count]['description'] = $info['description']; $product_data[$count]['price'] = $info['price']; $product_data[$count]['special'] = $info['special']; $product_data[$count]['rating'] = $info['rating']; $product_data[$count]['href'] = 'product/product/' . 'product_id=' . $info['product_id']; $count++; } return $product_data; }
public function actionRemoveFromCart() { $result = 0; $product_id = Yii::$app->request->post('product_id'); $quantity = Yii::$app->request->post('quantity', true); if ($product = Product::findOne(['id' => $product_id, 'is_active' => 1])) { Yii::$app->session->get('cart')->remove($product, $quantity); $result = Yii::$app->session->get('cart')->totalValue(); $result = I18n::currency($result); } return $result; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'pr_sum' => $this->pr_sum, 'pr_price' => $this->pr_price]); $query->andFilterWhere(['like', 'pr_name', $this->pr_name])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Product::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->joinWith('user'); $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'user.username', $this->user_id]); return $dataProvider; }
public function actionProductItems() { $this->layout = false; if ($q = Yii::$app->request->post('q')) { $offset = Yii::$app->session->get("controllers.search.index.{$q}.offset"); $offset += static::PRODUCTS_LIMIT; Yii::$app->session->set("controllers.search.index.{$q}.offset", $offset); $q_utf8 = StringUtils::utf8convert($q); $translations = ProductTranslation::find()->orFilterWhere(['like', 'name', $q])->orFilterWhere(['like', 'meta_title', $q])->orFilterWhere(['like', 'meta_description', $q])->orFilterWhere(['like', 'meta_keywords', $q])->orFilterWhere(['like', 'h1', $q])->orFilterWhere(['like', 'page_title', $q])->orFilterWhere(['like', 'description', $q])->orFilterWhere(['like', 'detail', $q])->orFilterWhere(['like', 'name', $q_utf8])->orFilterWhere(['like', 'meta_title', $q_utf8])->orFilterWhere(['like', 'meta_description', $q_utf8])->orFilterWhere(['like', 'meta_keywords', $q_utf8])->orFilterWhere(['like', 'h1', $q_utf8])->orFilterWhere(['like', 'page_title', $q_utf8])->orFilterWhere(['like', 'description', $q_utf8])->orFilterWhere(['like', 'detail', $q_utf8])->all(); $pids = ArrayHelper::getColumn($translations, 'product_id'); $products = Product::getProducts(['id_in' => $pids, 'orderBy' => Yii::$app->request->post('orderBy'), 'limit' => static::PRODUCTS_LIMIT, 'offset' => $offset]); $nextProductsNumber = count(Product::getProducts(['id_in' => $pids, 'limit' => static::PRODUCTS_LIMIT, 'offset' => $offset + static::PRODUCTS_LIMIT])); $productsHtml = $this->render('//product/items', ['products' => $products, 'offset' => $offset]); return json_encode(['productsHtml' => $productsHtml, 'nextProductsNumber' => $nextProductsNumber]); } }
public function actionPairingProducts() { if (Yii::$app->request->isAjax) { /* @var StoreProduct $storeProduct */ $storeProduct = new StoreProduct(); $storeProduct->store_id = $_POST['storeId']; $storeProduct->product_id = $_POST['productId']; $storeProduct->price = $_POST['price']; if ($storeProduct->save()) { return 'save :)'; } else { return 'not save :('; } } else { $dataProvider = new ActiveDataProvider(['query' => Product::find()]); return $this->render('pairing-products', ['dataProvider' => $dataProvider]); } }
public function actionDetail() { $slug = Yii::$app->request->get('slug'); if ($product = Product::findOne(['slug' => $slug, 'is_active' => 1])) { $this->link_canonical = $product->getLink(); if (!Redirect::compareUrl($this->link_canonical)) { $this->redirect($this->link_canonical); } $product_images = ProductImage::find()->where(['product_id' => $product->id])->all(); if ($this->is_mobile && !$this->is_tablet) { $product_image_suffix = ProductImage::$image_resizes['mobile']; } else { if ($this->is_tablet) { $product_image_suffix = ProductImage::$image_resizes['tablet']; } else { $product_image_suffix = ProductImage::$image_resizes['desktop']; } } return $this->render('detail', ['product' => $product, 'product_images' => $product_images, 'product_image_suffix' => $product_image_suffix]); } else { Redirect::go(); } }
public static function getProducts($params = []) { $query = Product::find()->where(['is_active' => 1])->andWhere(['<=', 'published_at', strtotime('now')]); if (isset($params['id_in']) && is_array($params['id_in'])) { $query->andWhere(['in', 'id', $params['id_in']]); } if (!empty($params['orderBy'])) { $query->orderBy($params['orderBy']); } if (!empty($params['limit'])) { $query->limit($params['limit']); } if (!empty($params['offset'])) { $query->offset($params['offset']); } $result = $query->all(); if (!is_array($result)) { return []; } return $result; }
public static function get_thumb_product_with_detail() { $options = []; $i = 0; $product_list_r = Product::find()->joinWith('cat_rel')->orderBy('product_category_rel.sort_order desc')->all(); foreach ($product_list_r as $key => $value) { $options[self::product_data($value->id)->slug]['id'] = self::product_data($value->id)->id; $options[self::product_data($value->id)->slug]['title'] = self::product_data($value->id)->title; $options[self::product_data($value->id)->slug]['slug'] = self::product_data($value->id)->slug; $options[self::product_data($value->id)->slug]['short_desc'] = self::product_data($value->id)->short_desc; $options[self::product_data($value->id)->slug]['desc'] = self::product_data($value->id)->desc; //$options[self::product_data($value->id)->slug]['status'] = self::product_data($value->id)->status; $options[self::product_data($value->id)->slug]['project_order'] = self::product_data($value->id)->sort_order; $options[self::product_data($value->id)->slug]['is_featured'] = self::product_data($value->id)->is_featured; if (!empty($value->specification)) { $k = 0; foreach ($value->specification as $spec) { $options[self::product_data($value->id)->slug]['specification'][$k] = $spec; $k++; } } if (!empty($value->image_all)) { $j = 0; foreach ($value->image_all as $banner) { $options[self::product_data($value->id)->slug]['images'][$j]['url'] = Yii::$app->urlManager->createAbsoluteUrl('/') . 'product_uploads/thumb/' . $banner->image; $options[self::product_data($value->id)->slug]['images'][$j]['url_full'] = Yii::$app->urlManager->createAbsoluteUrl('/') . 'product_uploads/' . $banner->image; $options[self::product_data($value->id)->slug]['images'][$j]['title'] = $banner->title; $options[self::product_data($value->id)->slug]['images'][$j]['desc'] = $banner->desc; $options[self::product_data($value->id)->slug]['images'][$j]['sort_order'] = $banner->sort_order; $options[self::product_data($value->id)->slug]['images'][$j]['is_banner'] = $banner->is_banner; $options[self::product_data($value->id)->slug]['images'][$j]['is_gallery'] = $banner->is_gallery; $options[self::product_data($value->id)->slug]['images'][$j]['is_hover'] = $banner->is_hover; $j++; } } if (!empty($value->post)) { $j = 0; foreach ($value->post as $post) { $options[self::product_data($value->id)->slug]['posts'][$j] = $post; $j++; } } $options[self::product_data($value->id)->slug]['type'] = $value->project_category_rel->category_name['cat_title']; $options[self::product_data($value->id)->slug]['category'] = $value->project_category_rel->project_category_category_self_rel['category_name']['cat_title']; $i++; } return $options; }
/** * @return \yii\db\ActiveQuery */ public function getProduct() { return $this->hasOne(Product::className(), ['id' => 'product_id']); }
public function getProduct() { //同样第一个参数指定关联的子表模型类名 return $this->hasOne(Product::className(), ['id' => 'productId']); }
public function actionTeadetailsrate() { $material = new Material(); $product = new Product(); $MaterialList = $material->findByProductId(GlobalArray::$productIdArray['0']); $ProductList = $product->findByProductId(GlobalArray::$productIdArray['0']); $pagination = new Pagination(['defaultPageSize' => 15, 'totalCount' => count((new Comment())->findByProductIdAll(GlobalArray::$commentTypeConstantArray['product'], GlobalArray::$productIdArray['0'], 0, 0))]); $commentList = (new Comment())->findByProductIdAll(GlobalArray::$commentTypeConstantArray['product'], GlobalArray::$productIdArray['0'], $pagination->offset, $pagination->limit); $product->UpdateByLookCount(GlobalArray::$productIdArray['0']); return $this->render(FVariable::$productTeadetailsrate_view, ['MaterialList' => $MaterialList, 'ProductList' => $ProductList, 'commentList' => $commentList, 'pagination' => $pagination]); }
function actionUpload() { $keys = $this->getKeys(); if (!$keys) { return false; } $key = $keys['file_key']; $t = time(); $img_dir = Yii::$app->params[$keys['params_key']]; $date = date($img_dir['date_fmt'], $t); if (Yii::$app->user->isGuest) { $id_user = Yii::$app->session->getHasSessionId(); } else { $id_user = Yii::$app->user->id; } if (!Yii::$app->user->isGuest) { if (empty($_POST['id_item']) && empty(Yii::$app->session[$keys['key_id_item']])) { $item = new Product(); $item->attributes = $_POST['Product']; $item->item_state = Product::STATE_ROUGH_COPY & Product::STATE_PUBLISH; $item->id_cat = Category::checkCategory($_POST['Product']['category']); $item->save(false); $id_item = $item->id; Yii::$app->session[$keys['key_id_item']] = $id_item; if (!empty($_POST['ProductInfo']['full_text'])) { $item_i = new ProductInfo(); $item_i->id = $id_item; $item_i->attributes = $_POST['ProductInfo']; $item_i->save(false); } } else { if (!empty(Yii::$app->session[$keys['key_id_item']])) { $id_item = Yii::$app->session[$keys['key_id_item']]; //$item = Product::model()->findByPk(Yii::$app->session[$keys['key_id_item']]); } else { if (!empty($_POST['id_item'])) { //$item = Product::model()->findByPk($_POST['id_item']); $id_item = $_POST['id_item']; } } } $mainImg = Yii::$app->db->createCommand('SELECT prod_images.id, prod_images.date_create, prod_images.img_url FROM {{%product}} product INNER JOIN {{%prod_images}} prod_images ON product.id_mainImg=prod_images.id WHERE product.id=:id')->bindParam(':id', $id_item)->queryOne(); $c_images = Yii::$app->db->createCommand('SELECT COUNT(id) FROM {{%prod_images}} WHERE id_prod=:prod')->bindParam(':prod', $id_item)->queryScalar(); } else { $mainImg = Yii::$app->db->createCommand('SELECT id, date_create, img_url FROM {{%prod_temp_images}} images WHERE id_session=:id AND is_main=1')->bindParam(':id', $id_user)->queryOne(); $c_images = Yii::$app->db->createCommand('SELECT COUNT(id) FROM {{%prod_temp_images}} WHERE id_session=:prod')->bindParam(':prod', $id_user)->queryScalar(); } foreach ($img_dir as $k => &$dir) { if ($k == 'date_fmt') { continue; } if (is_array($dir)) { foreach ($dir as &$path) { $path = strtr($path, array('{id_user}' => $id_user, '{id_item}' => $id_item)); CLib::createFolders($path); } } else { $dir = strtr($dir, array('{id_user}' => $id_user, '{id_item}' => $id_item)); CLib::createFolders($dir); } } $targetFolder = $img_dir['origin']; $bigFolder = $img_dir['big']; $tmpFolder = $img_dir['tmp']; $previewFolder = $img_dir['preview']; if (!count($_FILES[$key])) { return false; } $info = array(); $size = 1200; // px $max_files = Yii::$app->params['max_images']; $tempFile = $_FILES[$key]['tmp_name']; $fileName = md5($id_user . $_FILES[$key]['name'] . $t . rand(0, 1000)); $type = explode('/', $_FILES[$key]['type']); //$fileName.='.'.$type[1]; $fileName .= '.jpeg'; $newFile = $tmpFolder . $fileName; // перенести во временную папку move_uploaded_file($tempFile, $newFile); if (!file_exists($newFile)) { $vr['err'] = CLib::param('FILE_TO_BIG'); $vr['no_image'] = true; echo json_encode(array('files' => array($vr))); return; } $f_size = filesize($newFile); // TODO if ($max_files <= $c_images) { unlink($newFile); $vr['err'] = CLib::param('FILE_IMAGE_LIMIT'); $vr['err_limit'] = true; } else { if ($f_size > MAX_SIZE) { unlink($newFile); $vr['err'] = CLib::param('FILE_TO_BIG'); $vr['no_image'] = true; } else { $mime = explode('/', FileHelper::getMimeType($newFile)); if ($mime[1] != 'jpeg' && $mime[1] != 'jpg') { unlink($newFile); $vr['err'] = CLib::param('FILE_NO_IMAGE'); $vr['no_image'] = true; } else { $w_norm = $h_norm = $size; copy($newFile, $targetFolder . $fileName); CLib::resizeImgToSmall($w_norm, $h_norm, $targetFolder . $fileName, false, 80, false, true); // $size = 1200; $w_norm = $h_norm = $size; $t_start = microtime(true); unlink($newFile); $newFile = $targetFolder . $fileName; copy($newFile, $bigFolder . $fileName); CLib::resizeImgToSmall($w_norm, $h_norm, $bigFolder . $fileName, false, 80); // $t_end = microtime(true); $vr['time']['diff2'][] = $t_end - $t_start; foreach ($previewFolder as $size => $folder) { $w_norm = $h_norm = (int) $size; if (!file_exists($folder)) { mkdir($folder); } $img = $folder . $fileName; copy($newFile, $img); CLib::resizeImgToSmall($w_norm, $h_norm, $img, $size == 300 || $size == 100, 80); } //unlink($newFile); //$command->bindParam(':filename',$fileName)->execute(); //$id = Yii::$app->db->getLastInsertID(); if (!Yii::$app->user->isGuest) { $sql = 'INSERT INTO {{%prod_images}} SET id_prod=:prod, img_url=:url, date_create=:date'; Yii::$app->db->createCommand($sql)->bindParam(':prod', $id_item)->bindParam(':url', $fileName)->bindParam(':date', $t)->execute(); } else { $sql = 'INSERT INTO {{%prod_temp_images}} SET id_session=:id_user, img_url=:url, date_create=:date'; Yii::$app->db->createCommand($sql)->bindParam(':id_user', $id_user)->bindParam(':url', $fileName)->bindParam(':date', $t)->execute(); } /* $img_model = new ProdImages(); $img_model->id_prod = $id_item; $img_model->img_url = $fileName; $img_model->date_create = $t; $img_model->save(false); */ $id_img = Yii::$app->db->lastInsertID; if (!Yii::$app->user->isGuest) { if (empty($mainImg['date_create']) || !CLib::checkProdImg(Yii::$app->user->id, $id_item, $mainImg['img_url'])) { $mainImg['id'] = $id_img; Yii::$app->db->createCommand('UPDATE {{%product}} SET id_mainImg=:img WHERE id=:id')->bindParam(':id', $id_item)->bindParam(':img', $id_img)->execute(); /* $item->id_mainImg = $img_model->id; $item->save(false); */ } } else { if (!isset(Yii::$app->session['prod_images'])) { $arr = array(); } else { $arr = Yii::$app->session['prod_images']; } $arr[] = $id_img; Yii::$app->session['prod_images'] = $arr; if (empty($mainImg['date_create']) || !CLib::checkProdImg($id_user, $id_item, $mainImg['img_url'])) { $mainImg['id'] = $id_img; Yii::$app->db->createCommand('UPDATE {{%prod_temp_images}} SET is_main=1 WHERE id=:id')->bindParam(':id', $id_img)->execute(); } } $vr['thumbUrl'] = Url::to($previewFolder['100'] . $fileName, true); $vr['thumbUrl_100'] = Url::to($previewFolder['100'] . $fileName, true); $vr['thumbUrl_300'] = Url::to($previewFolder['300'] . $fileName, true); $vr['id'] = $id_img; $vr['id_main'] = $mainImg['id']; $vr['time']['start'] = $t_start; $vr['time']['end'] = $t_end; $vr['time']['diff'] = $t_end - $t_start; } } } $info[] = $vr; return json_encode(array('files' => $info)); }
public function actionInsertorderdata() { $userId = Yii::$app->session->get(FVariable::$session_userId_str); if (!$userId) { return $this->redirect(FVariable::$siteLogin_view); } $addressId = intval(Yii::$app->request->post("addressId")); $TotalPrice = floatval(Yii::$app->request->post("TotalPrice")); $order = new Order(); $cart = new Cart(); $cartList = $cart->findById($userId); if (!$cartList) { return $this->redirect(FVariable::$home_view); } $allMoney = ""; foreach ($cartList as $mk => $mv) { $allMoney += $mv['count'] * $mv['productPrice']; } if ($TotalPrice != $allMoney) { $TotalPrice = $allMoney; } $orderNo = Tool::getOrderNumber(); $connection = Yii::$app->getDb(); $transaction = $connection->beginTransaction(); try { $orderDetail = new OrderDetail(); $orderData = $order->insertOrder($orderNo, $TotalPrice, GlobalArray::$orderStateConstantArray['waitPay'], GlobalArray::$orderPayMethodConstantArray['alipay'], GlobalArray::$orderComeFromConstantArray['WEB'], $userId, $addressId); $orderId = Yii::$app->db->getLastInsertID(); $cartDetail = $cart->findByIdIs($userId); if (!$cartDetail) { return $this->redirect(FVariable::$home_view); } $detailArr = []; foreach ($cartDetail as $k => $v) { $new = []; $new[0] = $orderId; $new[1] = $v['productId']; $new[2] = $v['count']; $new[3] = $v['money']; $detailArr[$k] = $new; } $orderDetail->insertOrderDetail($detailArr); $product = new Product(); $orderDetailFind = $orderDetail->findByOrderIdProduct($orderId); foreach ($orderDetailFind as $k => $v) { $productSelect = $product->findByProductId($v['productId']); $productStock = $productSelect->productStock; $productSales = $productSelect->productSales; $detailArrCount = $productStock - $v['productCount']; $productSales = $productSales + $v['productCount']; $product->UpdateByStock($v['productId'], $detailArrCount, $productSales); } $cart->findByIdDelCartAll($userId); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); throw $e; } $this->redirect(Yii::$app->urlManager->createUrl([FVariable::$userOrderpayment_view, 'id' => $orderId])); }
public function getProducts($params = []) { $cate_ids = ArrayHelper::merge([$this->id], ArrayHelper::getColumn($this->getChildren(), 'id')); $id_in = ArrayHelper::getColumn(ProductCategoryToProduct::find()->where(['in', 'product_category_id', $cate_ids])->all(), 'product_id'); $result = Product::getProducts(['id_in' => $id_in, 'orderBy' => !empty($params['orderBy']) ? $params['orderBy'] : null, 'limit' => !empty($params['limit']) ? $params['limit'] : null, 'offset' => !empty($params['offset']) ? $params['offset'] : null]); return $result; }
/** * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::className(), ['user_id' => 'id']); }
public function getProducts($params = []) { $id_in = ArrayHelper::getColumn(ProductCollectionToProduct::find()->where(['product_collection_id' => $this->id])->all(), 'product_id'); $result = Product::getProducts(['id_in' => $id_in, 'orderBy' => !empty($params['orderBy']) ? $params['orderBy'] : null, 'limit' => !empty($params['limit']) ? $params['limit'] : null, 'offset' => !empty($params['offset']) ? $params['offset'] : null]); return $result; }
public function UpdateByLookCount($id) { $productUpdate = Product::find()->where(['id' => $id])->one(); $productUpdate->lookCount += 1; $productUpdate->update(); }
use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use frontend\models\Product; /* @var $this yii\web\View */ /* @var $model frontend\models\Order */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="order-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'productID')->dropDownList(ArrayHelper::map(Product::find()->all(), 'productID', 'name'), ['prompt' => 'Select product']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Buy' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div>
public function actionCreate_all_project_detail() { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $response = Product::get_all_product_with_detail(); $resp2 = Product::get_thumb_product_with_detail(); /*$response = []; $response['product_list'] = $product_all_list;*/ /*$data = ProductCategorySelfRel::getAllparentCat(); $category_data = []; $i=0; foreach ($data as $key) { $category_data[$i] = ProductCategory::getHierarchy_cat_with_slug($key['slug']); $i++; }*/ $fp = fopen('json/project_detail.json', 'w'); fwrite($fp, \yii\helpers\Json::encode($response)); fclose($fp); $fp2 = fopen('json/thumb_project_detail.json', 'w'); fwrite($fp2, \yii\helpers\Json::encode($resp2)); fclose($fp2); return $this->redirect(['/']); }
/** * 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.'); } }