public function init()
 {
     $this->name = \Yii::t('skeeks/shop/app', 'Buyers');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopBuyer::className();
     parent::init();
 }
示例#2
0
 public function init()
 {
     $this->name = \skeeks\cms\shop\Module::t('app', 'Buyers');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopBuyer::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);
    }
 /**
  * @inheritdoc
  */
 public function actions()
 {
     return ArrayHelper::merge(parent::actions(), ['index' => ["dataProviderCallback" => function (ActiveDataProvider $dataProvider) {
         $query = $dataProvider->query;
         /**
          * @var \yii\db\ActiveQuery $query
          */
         //$query->select(['app_company.*', 'count(`app_company_officer_user`.`id`) as countOfficer']);
         $query->groupBy([CmsUser::tableName() . '.id']);
         $query->innerJoin(ShopBuyer::tableName(), '`shop_buyer`.`cms_user_id` = `cms_user`.`id`');
     }, "columns" => [['class' => UserColumnData::className(), 'attribute' => 'id', 'label' => \skeeks\cms\shop\Module::t('app', 'Buyer')], 'email', 'phone', ['class' => DateTimeColumnData::className(), 'attribute' => 'created_at', 'label' => \skeeks\cms\shop\Module::t('app', 'Date of registration')], ['class' => DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'Date of last order'), 'value' => function (CmsUser $model) {
         if ($order = ShopOrder::find()->where(['user_id' => $model->id])->orderBy(['created_at' => SORT_DESC])->one()) {
             return \Yii::$app->formatter->asDatetime($order->created_at);
         }
         return null;
     }], ['class' => DataColumn::className(), 'label' => \skeeks\cms\shop\Module::t('app', 'The amount paid orders'), 'value' => function (CmsUser $model) {
         return ShopOrder::find()->where(['user_id' => $model->id, 'payed' => Cms::BOOL_Y])->count();
     }]]]]);
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopBuyers()
 {
     return $this->hasMany(ShopBuyer::className(), ['shop_person_type_id' => 'id']);
 }
示例#6
0
 /**
  * Процесс отправки формы
  * @return array
  */
 public function actionShopPersonTypeSubmit()
 {
     $rr = new RequestResponse();
     try {
         if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
             if (\Yii::$app->request->post('shop_person_type_id')) {
                 $shop_person_type_id = \Yii::$app->request->post('shop_person_type_id');
                 $shop_buyer_id = \Yii::$app->request->post('shop_buyer_id');
                 /**
                  * @var $shopPersonType ShopPersonType
                  */
                 $modelBuyer = ShopBuyer::findOne($shop_buyer_id);
                 $shopPersonType = ShopPersonType::find()->active()->andWhere(['id' => $shop_person_type_id])->one();
                 if (!$shopPersonType) {
                     throw new Exception(\skeeks\cms\shop\Module::t('app', 'This payer is disabled or deleted. Refresh the page.'));
                 }
                 if (!$modelBuyer) {
                     $modelBuyer = $shopPersonType->createModelShopBuyer();
                 }
                 $validateModel = $modelBuyer->relatedPropertiesModel;
                 if ($validateModel->load(\Yii::$app->request->post()) && $validateModel->validate()) {
                     $modelBuyerName = [];
                     //Проверка свойств
                     foreach ($validateModel->attributeValues() as $code => $value) {
                         /**
                          * @var $property ShopPersonTypeProperty
                          */
                         $property = $validateModel->getRelatedProperty($code);
                         if ($property->is_buyer_name == Cms::BOOL_Y) {
                             $modelBuyerName[] = $value;
                         }
                         if ($property->is_user_email == Cms::BOOL_Y) {
                             $userEmail = $value;
                         }
                         if ($property->is_user_name == Cms::BOOL_Y) {
                             $userName = $value;
                         }
                         if ($property->is_user_username == Cms::BOOL_Y) {
                             $userUsername = $value;
                         }
                         if ($property->is_user_phone == Cms::BOOL_Y) {
                             $userPhone = $value;
                         }
                     }
                     //Нужно создать польозвателя
                     if (\Yii::$app->user->isGuest) {
                         if (!$userEmail) {
                             throw new Exception(\skeeks\cms\shop\Module::t('app', 'Unknown email address user'));
                         }
                         $newUser = new SignupForm();
                         $newUser->scenario = SignupForm::SCENARION_ONLYEMAIL;
                         $newUser->email = $userEmail;
                         if (!($user = $newUser->signup())) {
                             throw new Exception(\skeeks\cms\shop\Module::t('app', 'Do not create a user profile.'));
                         }
                         //Авторизация пользователя
                         \Yii::$app->user->login($user, 0);
                     }
                     $modelBuyer->name = $modelBuyerName ? implode(", ", $modelBuyerName) : $shopPersonType->name . " от (" . \Yii::$app->formatter->asDate(time(), 'medium') . ")";
                     $modelBuyer->cms_user_id = \Yii::$app->user->identity->id;
                     $modelBuyer->shop_person_type_id = $shopPersonType->id;
                     if (!$modelBuyer->save()) {
                         throw new Exception(\skeeks\cms\shop\Module::t('app', 'The data for the buyer are not saved.'));
                     }
                     $validateModel->save();
                     \Yii::$app->shop->shopFuser->buyer_id = $modelBuyer->id;
                     \Yii::$app->shop->shopFuser->person_type_id = $modelBuyer->shopPersonType->id;
                     \Yii::$app->shop->shopFuser->save();
                     $rr->success = true;
                     $rr->message = \skeeks\cms\shop\Module::t('app', 'Successfully sent');
                 } else {
                     throw new Exception(\skeeks\cms\shop\Module::t('app', 'Check the correctness of filling the form fields'));
                 }
             }
         }
     } catch (\Exception $e) {
         $rr->success = false;
         $rr->message = $e->getMessage();
     }
     return (array) $rr;
 }
示例#7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBuyer()
 {
     return $this->hasOne(ShopBuyer::className(), ['id' => 'buyer_id']);
 }
示例#8
0
 /**
  *
  * @return ActiveQuery
  */
 public function getShopBuyers()
 {
     return $this->hasMany(ShopBuyer::className(), ['cms_user_id' => 'id'])->via('user');
 }
示例#9
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getElement()
 {
     return $this->hasOne(ShopBuyer::className(), ['id' => 'element_id']);
 }
示例#10
0

<?php 
echo $form->fieldSetEnd();
?>

<?php 
echo $form->fieldSet("Профили покупателя");
?>

    <?php 
echo \skeeks\cms\modules\admin\widgets\BlockTitleWidget::widget(['content' => 'Все профили покупателя']);
?>

        <?php 
echo \skeeks\cms\modules\admin\widgets\GridView::widget(['dataProvider' => new \yii\data\ActiveDataProvider(['query' => \skeeks\cms\shop\models\ShopBuyer::find()->where(['cms_user_id' => $model->id])]), 'columns' => ['id', 'name', ['class' => \yii\grid\DataColumn::className(), 'attribute' => 'shop_person_type_id', 'format' => 'raw', 'value' => function (\skeeks\cms\shop\models\ShopBuyer $model) {
    return $model->shopPersonType->name;
}], ['class' => \skeeks\cms\grid\DateTimeColumnData::className(), 'attribute' => 'created_at']]]);
?>

<?php 
echo $form->fieldSetEnd();
?>


<?php 
echo $form->fieldSet("Заказы (" . \skeeks\cms\shop\models\ShopOrder::find()->where(['user_id' => $model->id])->count() . ")");
?>

    <?php 
echo \skeeks\cms\modules\admin\widgets\BlockTitleWidget::widget(['content' => 'Последние заказы']);