Пример #1
0
 public static function SaveProduct($productXML)
 {
     $product_id = (int) $productXML->product_id;
     $product = Products::findOne($product_id);
     if (is_null($product)) {
         // создаем запись
         $product = new Products();
         $product->product_id = (int) $productXML->product_id;
         $product->catalog_id = (int) $productXML->catalog_id;
         $product->gallery_id = (int) $productXML->gallery_id;
         $product->name = (string) $productXML->name;
         $product->precontent = (string) $productXML->precontent;
         $product->content = (string) $productXML->content;
         $product->popular = (int) $productXML->popular;
         $product->price = (int) $productXML->price;
         //          $product->count = (int) $productXML->count;
         $product->save(false);
     } else {
         // обновляем запись
         $product->product_id = (int) $productXML->product_id;
         $product->catalog_id = (int) $productXML->catalog_id;
         $product->gallery_id = (int) $productXML->gallery_id;
         $product->name = (string) $productXML->name;
         $product->precontent = (string) $productXML->precontent;
         $product->content = (string) $productXML->content;
         $product->popular = (int) $productXML->popular;
         $product->price = (int) $productXML->price;
         //            $product->count = (int) $productXML->count;
         $product->save(false);
     }
 }
Пример #2
0
 public function actionIndex()
 {
     $countOrders = Orders::find()->count();
     $countCatalogs = Catalogs::find()->where(['not', ['name' => 'ROOT']])->count();
     $countProducts = Products::find()->count();
     return $this->render('index', ['countOrders' => $countOrders, 'countCatalogs' => $countCatalogs, 'countProducts' => $countProducts]);
 }
Пример #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param Catalogs $catalog
  *
  * @return ActiveDataProvider
  */
 public function search($params, $catalog)
 {
     $viewList = CookieController::getViewList();
     $productsID = [];
     $productsID = array_merge($productsID, $catalog->getProducts()->select('product_id')->asArray()->all());
     foreach ($catalog->children()->all() as $child) {
         $productsID = array_merge($productsID, $child->getProducts()->select('product_id')->asArray()->all());
     }
     $query = Products::find()->where(['product_id' => $productsID]);
     $price_min = $query->min('price');
     $price_max = $query->max('price');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $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->andFilterWhere(['like', 'name', $this->name]);
     // print_r($this->price_min);
     $query->andFilterWhere(['>=', 'price', $this->price_min]);
     $query->andFilterWhere(['<=', 'price', $this->price_max]);
     //print_r($params['ProductsCatalogSearch']);
     if ($params['ProductsCatalogSearch']['count'] == self::ALL) {
         // echo "всееее";
         // $query->andWhere('a > :a', ['a' => 'a'])
     } elseif ($params['ProductsCatalogSearch']['count'] == self::AVAILABLE) {
         // echo "в наличиbbи";
         $query->andWhere('count > 0');
     } elseif ($params['ProductsCatalogSearch']['count'] == self::NOT_AVAILABLE) {
         // echo "нетууу";
         $query->andWhere('count <= 0');
     }
     return ['dataProvider' => $dataProvider, 'price_min' => $price_min, 'price_max' => $price_max];
 }
Пример #4
0
 public function actionView($product_id)
 {
     $model = Products::findOne($product_id);
     if ($model === null) {
         throw new NotFoundHttpException();
     }
     return $this->render('view', ['model' => $model]);
 }
Пример #5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Products::find()->select('products.product_id as product_id, products.name as name, catalogs.name as name_catalog')->leftJoin('catalogs as catalogs', 'Products.id_catalog = catalogs.id');
     $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->andFilterWhere(['product_id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'catalogs.name', $this->name_catalog]);
     return $dataProvider;
 }
Пример #6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $products
  *
  * @return ActiveDataProvider
  */
 public function search($products)
 {
     $productsID = [];
     foreach ($products as $product) {
         $productsID[] = $product->product_id;
     }
     $query = Products::find()->where(['product_id' => $productsID]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     return $dataProvider;
 }
Пример #7
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $viewList = CookieController::getViewList();
     $query = Products::find()->select(['product_id', 'name', 'price', 'gallery_id', "IF (LENGTH(precontent) > 200,\n                CONCAT(LEFT(TRIM(TRAILING '.' FROM precontent),150),'...'),\n                LEFT(TRIM(TRAILING '.' FROM precontent),150))\n             as precontent"])->where(['popular' => true]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $viewList == 'panel' ? 6 : 5]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         return $dataProvider;
     }
     if (isset($params['ProductsPopularSearch']['count'])) {
         if ($params['ProductsPopularSearch']['count'] == Products::AVAILABLE) {
             // echo "в наличии";
             $query->andWhere('count > 0');
         } elseif ($params['ProductsPopularSearch']['count'] == Products::NOT_AVAILABLE) {
             // echo "нетууу";
             $query->andWhere('count <= 0');
         }
     }
     return $dataProvider;
 }
Пример #8
0
                              \$('#cart_order').html('');
                              \$('.cart-message').html("Ваша корзина пуста");
\t\t\t\t\t}
\t\t\t\t\t});

\t\t\t\t}
\t\t\t\t);

\t\t\t
  
JS;
$this->registerJs($jsCartClear, \yii\web\View::POS_READY);
echo GridView::widget(['dataProvider' => $dataProvider, 'layout' => "{items}", 'options' => ['style' => 'margin-left:-1px;margin-right:-2px;'], 'showFooter' => true, 'rowOptions' => function ($model, $key, $index, $grid) {
    return ['id' => "product_" . $model->product_id];
}, 'tableOptions' => ['class' => 'table table-bordered', 'id' => 'cart_table', 'style' => 'border:0;margin-bottom:0px;'], 'columns' => [['class' => 'yii\\grid\\SerialColumn', 'header' => '№', 'headerOptions' => ['style' => 'border-left:none;border-top:1px solid #ddd;'], 'contentOptions' => ['style' => 'border-left:none;'], 'footerOptions' => ['style' => 'border-left:none;border-bottom:1px solid #ddd;']], ['class' => 'yii\\grid\\DataColumn', 'label' => 'Наименование', 'headerOptions' => ['style' => 'border-right:none;border-top:1px solid #ddd;'], 'footerOptions' => ['class' => 'text-right', 'style' => 'border-bottom:1px solid #ddd;'], 'format' => 'html', 'value' => function ($model) {
    $product = Products::findOne($model->product_id);
    $mainPhoto = $model->getMainPhoto();
    //			print_r($mainPhoto);
    //			return Html::img($mainPhoto->url,['class'=>'img-responsive','style'=>'width:80px;']);
    return Html::a(Html::img($mainPhoto->getUrl('original'), ['class' => 'img-responsive', 'style' => 'height:50px;']), ['products/view', 'product_id' => $model->product_id], ['style' => 'display:block;']);
    //			echo Html::a(
    //				Html::img($mainPhoto->getUrl('original'), [ 'class' => 'img-responsive', 'style' => 'max-height:120px;' ]),
    //				[ 'products/view', 'product_id' => $model->product_id ], [ 'style' => 'display:block;' ]);
}], ['class' => 'yii\\grid\\DataColumn', 'label' => '', 'headerOptions' => ['style' => 'border-left:none;border-top:1px solid #ddd;'], 'footerOptions' => ['class' => 'text-right', 'style' => 'border-bottom:1px solid #ddd;'], 'format' => 'raw', 'value' => function ($model) {
    return Html::a($model->name, ['products/view', 'product_id' => $model->product_id], ['style' => 'display:block;']);
}], ['class' => 'yii\\grid\\DataColumn', 'label' => 'Цена', 'format' => 'html', 'headerOptions' => ['style' => 'border-top:1px solid #ddd;border-right:0;'], 'contentOptions' => ['style' => 'border-right:0;'], 'footer' => '<span style="font-size: 22px;">Итого</span>', 'footerOptions' => ['class' => 'text-right', 'style' => 'border-right:none;border-bottom:1px solid #ddd;'], 'value' => function ($model) {
    return '<span style="font-size: 16px;">' . number_format($model->price, 0, '.', ' ') . '</span>';
}], ['class' => 'yii\\grid\\DataColumn', 'label' => '', 'format' => 'html', 'headerOptions' => ['style' => 'border-top:1px solid #ddd;border-left:0;'], 'contentOptions' => ['style' => 'border-left:0;padding-top: 10px;'], 'footerOptions' => ['style' => 'border-left:none;border-bottom:1px solid #ddd;'], 'value' => function ($model) {
    return '<i class="glyphicon-cart glyphicon-ruble" style="margin-left:20px;font-size: 14px;"></i>';
}], ['class' => 'yii\\grid\\DataColumn', 'label' => 'Количество', 'headerOptions' => ['style' => 'border-top:1px solid #ddd;'], 'contentOptions' => ['style' => 'max-width:100px!important;'], 'footer' => '<span id="cart_quantity" style="font-size: 22px;">' . Yii::$app->cart->getCount() . '</span>', 'footerOptions' => ['style' => 'border-bottom:1px solid #ddd;'], 'format' => 'raw', 'value' => function ($model) {
    // return Yii::$app->cart->getPositionById($model->id)->getQuantity();
Пример #9
0
 public function getProducts()
 {
     return $this->hasMany(Products::className(), ['catalog_id' => 'catalog_id']);
 }
Пример #10
0
 /**
  * Finds the Products model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $product_id
  *
  * @return Products the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($product_id)
 {
     if (($model = Products::findOne($product_id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Пример #11
0
 public function actionClear()
 {
     Yii::$app->cart->removeAll();
     $arr = ['cart_quantity' => Yii::$app->cart->getCount(), 'cart_cost' => number_format(Yii::$app->cart->getCost(), 0, '.', ' '), 'cartContent' => Products::getCartContent()];
     echo Json::Encode($arr);
 }