public function init()
 {
     $this->name = \Yii::t('skeeks/shop/app', 'Types of prices');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopTypePrice::className();
     parent::init();
 }
 public function init()
 {
     $this->name = \skeeks\cms\shop\Module::t('app', 'Types of prices');
     $this->modelShowAttribute = "name";
     $this->modelClassName = ShopTypePrice::className();
     parent::init();
 }
 public function run()
 {
     /**
      * @var $contentElement CmsContentElement
      */
     $contentElement = $this->controller->model;
     $model = ShopProduct::find()->where(['id' => $contentElement->id])->one();
     $productPrices = [];
     if (!$model) {
         $model = new ShopProduct(['id' => $contentElement->id]);
     } else {
         if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) {
             foreach ($typePrices as $typePrice) {
                 $productPrice = ShopProductPrice::find()->where(['product_id' => $model->id, 'type_price_id' => $typePrice->id])->one();
                 if (!$productPrice) {
                     $productPrice = new ShopProductPrice(['product_id' => $model->id, 'type_price_id' => $typePrice->id]);
                 }
                 if ($post = \Yii::$app->request->post()) {
                     $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id);
                     $productPrice->load($data, "");
                 }
                 $productPrices[] = $productPrice;
             }
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         return $rr->ajaxValidateForm($model);
     }
     if ($rr->isRequestPjaxPost()) {
         /**
          * @var $productPrice ShopProductPrice
          */
         foreach ($productPrices as $productPrice) {
             if ($productPrice->save()) {
             } else {
                 \Yii::$app->getSession()->setFlash('error', \skeeks\cms\shop\Module::t('app', 'Check the correctness of the prices'));
             }
         }
         if ($model->load(\Yii::$app->request->post()) && $model->save()) {
             \Yii::$app->getSession()->setFlash('success', 'Saved');
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->controller->redirect($this->controller->indexUrl);
             }
             $model->refresh();
         } else {
             \Yii::$app->getSession()->setFlash('error', \skeeks\cms\shop\Module::t('app', 'Failed to save'));
         }
     }
     $this->viewParams = ['model' => $model, 'productPrices' => $productPrices];
     return parent::run();
 }
Exemple #4
0
 /**
  * Все типы цен магазина
  * @return ShopTypePrice[]
  */
 public function getShopTypePrices()
 {
     return ShopTypePrice::find()->all();
 }
Exemple #5
0
echo $form->fieldSet(\skeeks\cms\shop\Module::t('app', 'Currency amount paid orders and discounts'));
?>
    <?php 
echo $form->fieldSelect($model, 'currency_code', \yii\helpers\ArrayHelper::map(\skeeks\modules\cms\money\models\Currency::find()->active()->all(), 'code', 'code'));
?>

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

<?php 
echo $form->fieldSet(\skeeks\cms\shop\Module::t('app', 'Limitations'));
?>

    <?php 
echo $form->field($model, 'typePrices')->checkboxList(\yii\helpers\ArrayHelper::map(\skeeks\cms\shop\models\ShopTypePrice::find()->all(), 'id', 'name'))->hint(\skeeks\cms\shop\Module::t('app', 'if nothing is selected, it means all'));
?>


     <?php 
\yii\bootstrap\Alert::begin(['options' => ['class' => 'alert-warning']]);
?>

       <?php 
echo \skeeks\cms\shop\Module::t('app', '<b> Warning! </b> Permissions are stored in real time. Thus, these settings are independent of site or user.');
?>

        <?php 
\yii\bootstrap\Alert::end();
?>
 /**
  * @return ShopTypePrice
  */
 public function getTypePrice()
 {
     if (!$this->type_price_id) {
         return null;
     }
     return ShopTypePrice::find()->where(['id' => $this->type_price_id])->one();
 }
Exemple #7
0
    <?php 
echo $form->field($model, 'searchModelAttributes')->dropDownList(['image' => \Yii::t('skeeks/shop/app', 'Filter by photo'), 'hasQuantity' => \Yii::t('skeeks/shop/app', 'Filter by availability')], ['multiple' => true, 'size' => 4]);
?>

    <? if ($model->cmsContent) : ?>
        <?php 
echo $form->fieldSelectMulti($model, 'realatedProperties', \yii\helpers\ArrayHelper::map($model->cmsContent->cmsContentProperties, 'code', 'name'));
?>

        <? if ($model->shopContent && $model->shopContent->offerContent) : ?>
            <?php 
echo $form->fieldSelectMulti($model, 'offerRelatedProperties', \yii\helpers\ArrayHelper::map($model->shopContent->offerContent->cmsContentProperties, 'code', 'name'));
?>
        <? endif ; ?>

    <? else: ?>
        Дополнительные свойства появятся после сохранения настроек
    <? endif; ?>


    <?php 
echo $form->fieldSelect($model, 'type_price_id', \yii\helpers\ArrayHelper::map(\skeeks\cms\shop\models\ShopTypePrice::find()->all(), 'id', 'name'), ['allowDeselect' => true]);
?>

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



 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTypePrice()
 {
     return $this->hasOne(ShopTypePrice::className(), ['id' => 'type_price_id']);
 }
Exemple #9
0
 /**
  * @return $this
  */
 public function getTypePrices()
 {
     return $this->hasMany(ShopTypePrice::className(), ['id' => 'type_price_id'])->viaTable('{{%shop_discount2type_price}}', ['discount_id' => 'id']);
 }
 public function update(AdminAction $adminAction)
 {
     /**
      * @var $model CmsContentElement
      */
     $model = $this->model;
     $relatedModel = $model->relatedPropertiesModel;
     $shopProduct = ShopProduct::find()->where(['id' => $model->id])->one();
     $productPrices = [];
     if (!$shopProduct) {
         $shopProduct = new ShopProduct(['id' => $model->id]);
         $shopProduct->save();
     } else {
         if ($typePrices = ShopTypePrice::find()->where(['!=', 'def', Cms::BOOL_Y])->all()) {
             foreach ($typePrices as $typePrice) {
                 $productPrice = ShopProductPrice::find()->where(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id])->one();
                 if (!$productPrice) {
                     $productPrice = new ShopProductPrice(['product_id' => $shopProduct->id, 'type_price_id' => $typePrice->id]);
                 }
                 if ($post = \Yii::$app->request->post()) {
                     $data = ArrayHelper::getValue($post, 'prices.' . $typePrice->id);
                     $productPrice->load($data, "");
                 }
                 $productPrices[] = $productPrice;
             }
         }
     }
     $rr = new RequestResponse();
     if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $shopProduct->load(\Yii::$app->request->post());
         return \yii\widgets\ActiveForm::validateMultiple([$model, $relatedModel, $shopProduct]);
     }
     if ($rr->isRequestPjaxPost()) {
         $model->load(\Yii::$app->request->post());
         $relatedModel->load(\Yii::$app->request->post());
         $shopProduct->load(\Yii::$app->request->post());
         /**
          * @var $productPrice ShopProductPrice
          */
         foreach ($productPrices as $productPrice) {
             if ($productPrice->save()) {
             } else {
                 \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Check the correctness of the prices'));
             }
         }
         if ($model->save() && $relatedModel->save() && $shopProduct->save()) {
             \Yii::$app->getSession()->setFlash('success', \Yii::t('skeeks/shop/app', 'Saved'));
             if (\Yii::$app->request->post('submit-btn') == 'apply') {
             } else {
                 return $this->redirect($this->indexUrl);
             }
             $model->refresh();
         } else {
             $errors = [];
             if ($model->getErrors()) {
                 foreach ($model->getErrors() as $error) {
                     $errors[] = implode(', ', $error);
                 }
             }
             \Yii::$app->getSession()->setFlash('error', \Yii::t('skeeks/shop/app', 'Could not save') . $errors);
         }
     }
     if (!$shopProduct->baseProductPrice) {
         $baseProductPrice = new ShopProductPrice(['type_price_id' => \Yii::$app->shop->baseTypePrice->id, 'currency_code' => \Yii::$app->money->currencyCode, 'product_id' => $model->id]);
         $baseProductPrice->save();
     }
     return $this->render('_form', ['model' => $model, 'relatedModel' => $relatedModel, 'shopProduct' => $shopProduct, 'productPrices' => $productPrices, 'baseProductPrice' => $shopProduct->getBaseProductPrice()->one()]);
 }
Exemple #11
0
 /**
  * Все типы цен магазина
  * @return ShopTypePrice[]
  */
 public function getShopTypePrices()
 {
     if (!$this->_shopTypePrices) {
         $this->_shopTypePrices = ShopTypePrice::find()->all();
     }
     return $this->_shopTypePrices;
 }