Ejemplo n.º 1
0
 /**
  * Если нет будет создан
  *
  * @return ShopFuser
  */
 public function getShopFuser()
 {
     if ($this->_shopFuser instanceof ShopFuser) {
         return $this->_shopFuser;
     }
     //Если пользователь гость
     if (\Yii::$app->user->isGuest) {
         //Проверка сессии
         if (\Yii::$app->getSession()->offsetExists($this->sessionFuserName)) {
             $fuserId = \Yii::$app->getSession()->get($this->sessionFuserName);
             $shopFuser = ShopFuser::find()->where(['id' => $fuserId])->one();
             //Поиск юзера
             if ($shopFuser) {
                 $this->_shopFuser = $shopFuser;
             }
         }
         if (!$this->_shopFuser) {
             $shopFuser = new ShopFuser();
             $shopFuser->save();
             \Yii::$app->getSession()->set($this->sessionFuserName, $shopFuser->id);
             $this->_shopFuser = $shopFuser;
         }
     } else {
         $this->_shopFuser = ShopFuser::find()->where(['user_id' => \Yii::$app->user->identity->id])->one();
         //Если у авторизовнного пользоывателя уже есть пользователь корзины
         if ($this->_shopFuser) {
             //Проверка сессии, а было ли чего то в корзине
             if (\Yii::$app->getSession()->offsetExists($this->sessionFuserName)) {
                 $fuserId = \Yii::$app->getSession()->get($this->sessionFuserName);
                 $shopFuser = ShopFuser::find()->where(['id' => $fuserId])->one();
                 /**
                  * @var $shopFuser ShopFuser
                  */
                 if ($shopFuser) {
                     $this->_shopFuser->addBaskets($shopFuser->shopBaskets);
                     $shopFuser->delete();
                 }
                 //Эти данные в сессии больше не нужны
                 \Yii::$app->getSession()->remove($this->sessionFuserName);
             }
         } else {
             //Проверка сессии, а было ли чего то в корзине
             if (\Yii::$app->getSession()->offsetExists($this->sessionFuserName)) {
                 $fuserId = \Yii::$app->getSession()->get($this->sessionFuserName);
                 $shopFuser = ShopFuser::find()->where(['id' => $fuserId])->one();
                 //Поиск юзера
                 /**
                  * @var $shopFuser ShopFuser
                  */
                 if ($shopFuser) {
                     $shopFuser->user_id = \Yii::$app->user->identity->id;
                     $shopFuser->save();
                 }
                 $this->_shopFuser = $shopFuser;
                 \Yii::$app->getSession()->remove($this->sessionFuserName);
             } else {
                 $shopFuser = new ShopFuser(['user_id' => \Yii::$app->user->identity->id]);
                 $shopFuser->save();
                 $this->_shopFuser = $shopFuser;
             }
         }
     }
     return $this->_shopFuser;
 }
Ejemplo n.º 2
0
    <?php 
echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id])]), 'columns' => ['id', ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'status_code', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopOrder $order) {
    return Html::label($order->status->name, null, ['style' => "background: {$order->status->color}", 'class' => "label"]) . "<br />" . Html::tag("small", \Yii::$app->formatter->asDatetime($order->status_at) . " (" . \Yii::$app->formatter->asRelativeTime($order->status_at) . ")");
}], ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => 'payed', 'format' => 'raw'], ['class' => \skeeks\cms\grid\BooleanColumn::className(), 'attribute' => 'canceled', 'format' => 'raw'], ['class' => \yii\grid\DataColumn::className(), 'format' => 'raw', 'attribute' => 'price', 'label' => \skeeks\cms\shop\Module::t('app', 'Sum'), 'value' => function (\skeeks\cms\shop\models\ShopOrder $model) {
    return \Yii::$app->money->intlFormatter()->format($model->money);
}], ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'site_id', 'format' => 'raw', 'label' => \skeeks\cms\shop\Module::t('app', 'Site'), 'value' => function (\skeeks\cms\shop\models\ShopOrder $model) {
    return $model->site->name . " [{$model->site->code}]";
}], ['class' => \skeeks\cms\grid\CreatedAtColumn::className()]]]);
echo $form->fieldSetEnd();
?>



<?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']]]);
?>