public function actionUpdateBasket() { $rr = new RequestResponse(); if ($rr->isRequestAjaxPost()) { $basket_id = (int) \Yii::$app->request->post('basket_id'); $quantity = (int) \Yii::$app->request->post('quantity'); $shopBasket = ShopBasket::find()->where(['id' => $basket_id])->one(); if ($shopBasket) { if ($quantity > 0) { $shopBasket->quantity = $quantity; if ($shopBasket->recalculate()->save()) { $rr->success = true; $rr->message = \skeeks\cms\shop\Module::t('app', 'Postion successfully updated'); } } else { if ($shopBasket->delete()) { $rr->success = true; $rr->message = \skeeks\cms\shop\Module::t('app', 'Position successfully removed'); } } } \Yii::$app->shop->shopFuser->link('site', \Yii::$app->cms->site); $rr->data = \Yii::$app->shop->shopFuser->toArray([], \Yii::$app->shop->shopFuser->extraFields()); return (array) $rr; } else { return $this->goBack(); } }
/** * @return array */ public function actionUpdateOrderAddProduct() { $rr = new RequestResponse(); if ($this->model) { $model = $this->model; } if ($rr->isRequestAjaxPost()) { $product_id = \Yii::$app->request->post('product_id'); $quantity = \Yii::$app->request->post('quantity'); /** * @var ShopProduct $product */ $product = ShopProduct::find()->where(['id' => $product_id])->one(); if (!$product) { $rr->message = \Yii::t('skeeks/shop/app', 'This product is not found, it may be removed.'); return (array) $rr; } $shopBasket = ShopBasket::find()->where(['order_id' => $model->id, 'product_id' => $product_id, 'fuser_id' => null])->one(); if (!$shopBasket) { $shopBasket = new ShopBasket(['order_id' => $model->id, 'product_id' => $product->id, 'quantity' => 0]); } $shopBasket->quantity = $shopBasket->quantity + $quantity; if (!$shopBasket->recalculate()->save()) { $rr->success = false; $rr->message = \Yii::t('skeeks/shop/app', 'Failed to add item to cart'); } else { $rr->success = true; $rr->message = \Yii::t('skeeks/shop/app', 'Item added to cart'); } $rr->data = $model->toArray([], $model->extraFields()); return (array) $rr; } else { return $this->goBack(); } }
public function actionUpdateBasket() { $rr = new RequestResponse(); if ($rr->isRequestAjaxPost()) { $basket_id = (int) \Yii::$app->request->post('basket_id'); $quantity = (double) \Yii::$app->request->post('quantity'); /** * @var $shopBasket ShopBasket */ $shopBasket = ShopBasket::find()->where(['id' => $basket_id])->one(); if ($shopBasket) { if ($quantity > 0) { $product = $shopBasket->product; if ($product->measure_ratio > 1) { if ($quantity % $product->measure_ratio != 0) { $quantity = $product->measure_ratio; } } $shopBasket->quantity = $quantity; if ($shopBasket->recalculate()->save()) { $rr->success = true; $rr->message = \Yii::t('skeeks/shop/app', 'Postion successfully updated'); } } else { if ($shopBasket->delete()) { $rr->success = true; $rr->message = \Yii::t('skeeks/shop/app', 'Position successfully removed'); } } } \Yii::$app->shop->shopFuser->link('site', \Yii::$app->cms->site); $rr->data = \Yii::$app->shop->shopFuser->jsonSerialize(); return (array) $rr; } else { return $this->goBack(); } }
<?php $fuser = \skeeks\cms\shop\models\ShopFuser::find()->where(['user_id' => $model->id])->one(); ?> <?php echo $form->fieldSet(\skeeks\cms\shop\Module::t('app', 'Basket') . ' (' . \skeeks\cms\shop\models\ShopBasket::find()->where(['fuser_id' => $fuser->id])->count() . ")"); ?> <?php echo \skeeks\cms\modules\admin\widgets\BlockTitleWidget::widget(['content' => \skeeks\cms\shop\Module::t('app', 'At the moment the user in a basket')]); ?> <?php echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \skeeks\cms\shop\models\ShopBasket::find()->where(['fuser_id' => $fuser->id])]), 'columns' => [['class' => \skeeks\cms\grid\DateTimeColumnData::className(), 'attribute' => 'created_at'], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'name'], ['class' => \yii\grid\DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'Price'), 'value' => function (\skeeks\cms\shop\models\ShopBasket $shopBasket) { return \Yii::$app->money->intlFormatter()->format($shopBasket->money); }], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'quantity'], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'site_id']]]); ?> <?php echo $form->fieldSetEnd(); ?> <?php echo $form->fieldSet(\skeeks\cms\shop\Module::t('app', 'Viewed products') . " (" . \skeeks\cms\shop\models\ShopViewedProduct::find()->where(['shop_fuser_id' => $fuser->id])->count() . ")"); ?> <?php echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \skeeks\cms\shop\models\ShopViewedProduct::find()->where(['shop_fuser_id' => $fuser->id])]), 'columns' => [['class' => \skeeks\cms\grid\CreatedAtColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'Date views')], ['class' => \yii\grid\DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'Good'), 'value' => function (\skeeks\cms\shop\models\ShopViewedProduct $shopViewedProduct) {