Exemplo n.º 1
0
 public function init()
 {
     $this->name = \skeeks\cms\shop\Module::t('app', 'Baskets');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopFuser::className();
     parent::init();
 }
Exemplo n.º 2
0
 public function init()
 {
     $this->name = \Yii::t('skeeks/shop/app', 'Baskets');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopFuser::className();
     parent::init();
 }
    public function run()
    {
        $rr = new RequestResponse();
        $errors = [];
        if ($post = \Yii::$app->request->post()) {
            $this->shopFuser->load($post);
            $this->shopFuser->save();
        }
        $this->shopBuyer = $this->shopFuser->personType->createModelShopBuyer();
        $shopBuyer = $this->shopBuyer;
        if ($shopBuyer) {
            if ($post = \Yii::$app->request->post()) {
                $this->shopBuyer->load($post);
                $this->shopBuyer->relatedPropertiesModel->load($post);
            }
        }
        if ($rr->isRequestPjaxPost()) {
            if (!\Yii::$app->request->post($this->notSubmitParam)) {
                if ($this->shopFuser->validate() && $this->shopBuyer->validate() && $this->shopBuyer->relatedPropertiesModel->validate()) {
                    if ($this->shopBuyer->isNewRecord) {
                        if (!$this->shopBuyer->save()) {
                            throw new Exception('Not save buyer');
                        }
                    }
                    if (!$this->shopBuyer->relatedPropertiesModel->save()) {
                        throw new Exception('Not save buyer data');
                    }
                    $this->shopFuser->buyer_id = $this->shopBuyer->id;
                    $newOrder = ShopOrder::createOrderByFuser($this->shopFuser);
                    $orderUrl = $newOrder->publicUrl;
                    $this->view->registerJs(<<<JS
location.href='{$orderUrl}';
JS
);
                } else {
                    /*print_r($this->shopFuser->firstErrors);
                      print_r($this->shopBuyer->firstErrors);
                      print_r($this->shopBuyer->relatedPropertiesModel->firstErrors);*/
                }
            }
        }
        return $this->render($this->viewFile);
    }
Exemplo n.º 4
0
    /**
     * Просмотр созданных бекапов баз данных
     */
    public function actionDeleteEmptyCarts()
    {
        $deleted = ShopFuser::deleteAll(['and', ['shop_fuser.user_id' => null], ['shop_fuser.person_type_id' => null], ['shop_fuser.pay_system_id' => null], ['shop_fuser.delivery_id' => null], ['shop_fuser.buyer_id' => null], new Expression(<<<SQL
            (SELECT count(id) as count FROM shop_basket WHERE shop_basket.fuser_id = shop_fuser.id) = 0
SQL
)]);
        /*
                $query = ShopFuser::find()
                            ->andWhere(['shop_fuser.user_id' => null])
                            ->andWhere(['shop_fuser.person_type_id' => null])
                            ->andWhere(['shop_fuser.pay_system_id' => null])
                            ->andWhere(['shop_fuser.delivery_id' => null])
                            ->andWhere(['shop_fuser.buyer_id' => null])
        
                            ->andWhere(new Expression(<<<SQL
                            (SELECT count(id) as count FROM shop_basket WHERE shop_basket.fuser_id = shop_fuser.id) = 0
        SQL
                            ))
                            ;
        
                echo $query->createCommand()->sql;*/
        /*
                $counter = 0;
                $models = $query->all();
                $allCount = count($models);
                Console::startProgress(0, $allCount);
        
                foreach ($query->each() as $model)
                {
                    // $users is indexed by the "username" column
                    $counter ++;
                    $model->delete();
                    Console::updateProgress($counter, $allCount);
                }
        
                Console::endProgress();*/
        $this->stdout("Removed empty baskets: " . $deleted . "\n");
        \Yii::info("Removed empty baskets: " . $deleted);
    }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopFuser()
 {
     return $this->hasOne(ShopFuser::className(), ['id' => 'shop_fuser_id']);
 }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
0
 public function createOrder()
 {
     $cmsUser = null;
     if ($userId = \Yii::$app->request->get('cmsUserId')) {
         $cmsUser = CmsUser::findOne($userId);
     }
     if ($cmsUser) {
         /**
          * @var $shopFuser ShopFuser
          */
         $shopFuser = ShopFuser::getInstanceByUser($cmsUser);
         $model = $shopFuser;
         $rr = new RequestResponse();
         if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
             $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER;
             return $rr->ajaxValidateForm($model);
         }
         if ($rr->isRequestPjaxPost()) {
             try {
                 if ($model->load(\Yii::$app->request->post()) && $model->save()) {
                     $model->scenario = ShopFuser::SCENARIO_CREATE_ORDER;
                     if ($model->validate()) {
                         $order = ShopOrder::createOrderByFuser($model);
                         if (!$order->isNewRecord) {
                             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'The order #{order_id} created successfully', ['order_id' => $order->id]));
                             if (\Yii::$app->request->post('submit-btn') == 'apply') {
                                 return $this->redirect(UrlHelper::constructCurrent()->setCurrentRef()->enableAdmin()->setRoute($this->modelDefaultAction)->normalizeCurrentRoute()->addData([$this->requestPkParamName => $order->id])->toString());
                             } else {
                                 return $this->redirect($this->indexUrl);
                             }
                         } else {
                             throw new Exception(\Yii::t('skeeks/shop/app', 'Incorrect data of the new order') . ": " . array_shift($order->getFirstErrors()));
                         }
                     } else {
                         throw new Exception(\Yii::t('skeeks/shop/app', 'Not enogh data for ordering') . ": " . array_shift($model->getFirstErrors()));
                     }
                 } else {
                     throw new Exception(\Yii::t('skeeks/shop/app', 'Could not save'));
                 }
             } catch (\Exception $e) {
                 \Yii::$app->getSession()->setFlash('error', $e->getMessage());
             }
         }
         return $this->render($this->action->id, ['cmsUser' => $cmsUser, 'shopFuser' => $model]);
     } else {
         return $this->render($this->action->id . "-select-user");
     }
 }
Exemplo n.º 8
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']]]);
?>