Ejemplo n.º 1
0
 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]);
     }
 }
Ejemplo n.º 2
0
 /**
  * function ::create ($data)
  */
 public static function create($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = new ProductTranslation();
     if ($model->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = "Create ProductTranslation";
             $log->created_at = $now;
             $log->type = 1;
             $log->is_success = 0;
             $log->save();
         }
         do {
             $path = FileUtils::generatePath($now);
         } while (file_exists(Yii::$app->params['images_folder'] . $path));
         $model->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $model->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $model->image_path;
         $model->description = FileUtils::copyContentImages(['content' => $model->description, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         $model->detail = FileUtils::copyContentImages(['content' => $model->detail, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         $model->shipping_detail = FileUtils::copyContentImages(['content' => $model->shipping_detail, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         if ($model->save()) {
             if ($log) {
                 $log->action .= ", id = {$model->id}";
                 $log->is_success = 1;
                 $log->save();
             }
             return $model;
         }
         $model->getErrors();
         return $model;
     }
     return false;
 }
Ejemplo n.º 3
0
 /**
  * @return ActiveQuery
  */
 public function getProductTranslations()
 {
     return $this->hasMany(ProductTranslation::className(), ['product_id' => 'id']);
 }