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); } }
public function actionRemove() { $id = $_POST['id']; $product = Products::findOne($id); Yii::$app->cart->remove($product); $arr = ['cart_quantity' => Yii::$app->cart->getCount(), 'cart_cost' => number_format(Yii::$app->cart->getCost(), 0, '.', ' '), 'cartContent' => self::getCartContent()]; echo Json::Encode($arr); }
public function actionView($product_id) { $model = Products::findOne($product_id); if ($model === null) { throw new NotFoundHttpException(); } return $this->render('view', ['model' => $model]); }
\$('#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();
/** * 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.'); } }