Example #1
0
 /**
  * @inheritdoc
  */
 public function markAsRead(Message &$dialog)
 {
     $result = Message::updateAll(['read' => Message::STATUS_READ], ArrayHelper::merge($dialog->getAttributes(['from', 'to']), ['read' => Message::STATUS_UNREAD]));
     if ($result) {
         $dialog->read = Message::STATUS_READ;
     }
 }
 public function init()
 {
     parent::init();
     $geo = new \jisoft\sypexgeo\Sypexgeo();
     $res = $geo->get();
     $request = \Yii::$app->request->getQueryParams();
     $category = Category::find()->byUrl(ArrayHelper::getValue($request, Category::URL_PARAM_CATEGORY))->one();
     $subcategory = Category::find()->byUrl(ArrayHelper::getValue($request, Category::URL_PARAM_SUBCATEGORY))->one();
     $rubric = Category::find()->byUrl(ArrayHelper::getValue($request, Category::URL_PARAM_RUBRIC))->one();
     $this->view->params = ['bundle' => AppAsset::register($this->view), 'categories' => Category::getMain(), 'countryEn' => $res['country']['name_en'], 'category' => $category, 'subcategory' => $subcategory, 'rubric' => $rubric];
 }
Example #3
0
 public static function loadProperties(array $groupPost, array $postProperties, $update = false)
 {
     $data = $postProperties ? ArrayHelper::combine($groupPost, $postProperties) : $groupPost;
     if ($update) {
         $result = [];
         if ($groupPost) {
             foreach ($groupPost as $key => $group) {
                 $groupModel = ($model = GroupProperty::findOne(['id' => ArrayHelper::getValue($group, 'id')])) ? $model : new GroupProperty();
                 if ($groupModel->load($group, '')) {
                     //foreach properties
                     $properties = [];
                     foreach ($data[$key] as $property) {
                         $propertyModel = ($model = Property::findOne(['id' => ArrayHelper::getValue($property, 'id')])) ? $model : new Property();
                         if (!$propertyModel->load($property, '')) {
                             return [];
                         }
                         $properties[] = $propertyModel;
                     }
                     $result[] = ['group' => $groupModel, 'properties' => $properties];
                 }
             }
         }
     } else {
         $result = [];
         foreach ($data as $key => $items) {
             $properties = [];
             if ($postProperties) {
                 array_walk($items, function ($entry) use(&$properties) {
                     $properties[] = new Property($entry);
                 });
             }
             $result[] = ['group' => new GroupProperty($groupPost[$key]), 'properties' => $properties];
         }
     }
     return $result;
 }
 public function watchedSearch($params)
 {
     $query = Yii::$app->user->identity->getRecentlyProducts()->select(['{{product}}.*', 'IF(round(sum(product_review.rating) / count(product.reviews_count)) IS NULL, 0, rating) as rating'])->joinWith(['productReviews', 'recentProducts'])->groupBy('{{product}}.id');
     $sort = new Sort(['defaultOrder' => ['recent' => SORT_ASC], 'attributes' => ArrayHelper::merge(['recent' => ['asc' => ['recent_product.created_at' => SORT_DESC], 'label' => 'Recently', 'defaultOrder' => SORT_ASC], 'old' => ['asc' => ['recent_product.created_at' => SORT_ASC], 'label' => 'Old', 'defaultOrder' => SORT_ASC]], Product::getSortAttributes())]);
     $viewSort = new Sort(['sortParam' => 'view', 'attributes' => [Product::VIEW_SORT_LIST, Product::VIEW_SORT_BLOCK]]);
     $this->load($params);
     $sortParam = Yii::$app->request->getQueryParam('view');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => $sort, 'pagination' => ['pageSizeParam' => false, 'pageSize' => $sortParam === Product::VIEW_SORT_BLOCK ? self::FAVORITES_PAGINATION_SIZE_BLOCK : self::FAVORITES_PAGINATION_SIZE_LIST]]);
     Yii::$app->controller->view->params['viewSort'] = $viewSort;
     Yii::$app->controller->view->params['sort'] = $sort;
     Yii::$app->controller->view->params['searchModel'] = $this;
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'active' => $this->active, 'reviews_count' => $this->reviews_count, 'brand_id' => $this->brand_id, 'comment_count' => $this->comment_count, 'category_id' => $this->category_id, 'UI' => $this->ui]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'full_description', $this->full_description])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'ui', $this->ui]);
     return $dataProvider;
 }
Example #5
0
use common\components\ArrayHelper;
use frontend\helpers\String;
/* @var $this yii\web\View */
/* @var $products \common\models\Product[] */
/* @var $pagination \yii\data\Pagination */
/* @var $widget \frontend\widgets\ProductsList */
?>

<div class="catalog-list">
    <?php 
foreach ($products as $product) {
    ?>
        <div class="catalog-item product">
            <div class="catalog-check"><label class="checkbox-style"><input type="checkbox"><i></i> In comparison</label></div>
            <?php 
    echo WishListIcon::widget(ArrayHelper::merge(['product' => $product], $widget->wishIconOptions));
    ?>
            <div class="catalog-img"><a href="<?php 
    echo $product->getRoute();
    ?>
"><?php 
    echo Html::img($product->getMainImagePath());
    ?>
</a></div>
            <div class="catalog-cont">
                <h3><a href="<?php 
    echo $product->getRoute();
    ?>
"><?php 
    echo $product->title;
    ?>
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  * @throws ErrorException
  * @throws Exception
  * @throws NotFoundHttpException
  * @throws \yii\base\Exception
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->scenario = $model::SCENARIO_UPDATE;
     $videos = $model->videos;
     Model::setScenarios($videos, ProductVideo::SCENARIO_PRODUCT_UPDATE);
     $properties = $model->productProperties;
     Model::setScenarios($properties, ProductProperty::SCENARIO_PRODUCT_UPDATE);
     if ($model->load($post = Yii::$app->request->post())) {
         $oldVideoIds = ArrayHelper::map($videos, 'id', 'id');
         $oldPropertyIds = ArrayHelper::map($properties, 'id', 'id');
         $videos = Model::createMultiple(ProductVideo::classname(), $videos);
         $properties = Model::createMultiple(ProductProperty::classname(), $properties);
         Model::setScenarios($videos, ProductVideo::SCENARIO_PRODUCT_UPDATE);
         Model::setScenarios($properties, ProductProperty::SCENARIO_PRODUCT_UPDATE);
         Model::loadMultiple($videos, Yii::$app->request->post());
         Model::loadMultiple($properties, Yii::$app->request->post());
         $deletedVideoIds = array_diff($oldVideoIds, array_filter(ArrayHelper::map($videos, 'id', 'id')));
         $deletedPropertyIds = array_diff($oldPropertyIds, array_filter(ArrayHelper::map($properties, 'id', 'id')));
         Model::validateDuplicates($properties, 'property_id');
         // ajax validation
         if (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ArrayHelper::merge(ActiveForm::validate($model), ActiveForm::validateMultiple($properties, false), ActiveForm::validateMultiple($videos));
         }
         if ($model->validate() && Model::validateMultiple($properties) && Model::validateMultiple($videos)) {
             $transaction = $model->getDb()->beginTransaction();
             $oldMainPhoto = $model->getOldAttribute('main_photo');
             $model->main_photo = UploadedFile::getInstance($model, 'main_photo');
             try {
                 if (!($category = Category::findOne(['id' => $model->category_id]))) {
                     throw new \yii\base\Exception();
                 }
                 if ($model->main_photo) {
                     if (!$model->save(false)) {
                         throw new ErrorException();
                     }
                     $model->removeMainPhotoFromFolder($oldMainPhoto);
                     if (!$model->upload()) {
                         throw new \yii\base\Exception();
                     }
                 } else {
                     $model->setAttribute('main_photo', $oldMainPhoto);
                     if (!$model->save(false)) {
                         throw new \yii\base\Exception();
                     }
                 }
                 ProductVideo::deleteAll(['id' => $deletedVideoIds]);
                 ProductProperty::deleteAll(['id' => $deletedPropertyIds]);
                 Model::linkAll($model, $properties, 'productProperties');
                 Model::unsetEmpty($videos, 'video');
                 Model::linkAll($model, $videos, 'videos');
                 $model->savePhotos();
                 $transaction->commit();
                 Yii::$app->session->setFlash('success', 'Product have been updated.');
                 return $this->redirect('index');
             } catch (Exception $e) {
                 Yii::$app->session->setFlash('error', 'Failed to update product.');
                 $transaction->rollBack();
                 return $this->redirect('index');
             }
         }
     }
     $model->clearTmpPhotos();
     return $this->render('update', ['model' => $model, 'videos' => empty($videos) ? [new ProductVideo()] : $videos, 'properties' => empty($properties) ? [new ProductProperty()] : $properties, 'category' => Category::findOne(['id' => $model->category_id])]);
 }
 /**
  * Updates an existing Category model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $groupProperties = [];
     foreach ($model->groupProperties as $group) {
         $groupProperties[] = ['group' => $group, 'properties' => $group->properties];
     }
     $request = Yii::$app->request;
     $post = $request->post();
     $groupPost = $request->post('GroupProperty');
     $propertyPost = $request->post('Property');
     $model->scenario = $model::SCENARIO_UPDATE;
     if ($model->load($post)) {
         $oldProperties = ArrayHelper::flatten(ArrayHelper::getColumn($groupProperties, 'properties'));
         $oldGroups = ArrayHelper::flatten(ArrayHelper::getColumn($groupProperties, 'group'));
         $groupProperties = Model::loadProperties($groupPost, $propertyPost, true);
         if (!$groupProperties) {
             Yii::$app->session->setFlash('error', 'Failed to update category.');
             return $this->redirect('index');
         }
         $oldPropertyIds = ArrayHelper::getColumn($oldProperties, 'id');
         $newPropertyIds = [];
         array_walk_recursive($propertyPost, function ($item, $key) use(&$newPropertyIds) {
             if ($key == 'id') {
                 $newPropertyIds[] = $item;
             }
         });
         $oldGroupIds = ArrayHelper::getColumn($oldGroups, 'id');
         $newGroupIds = [];
         array_walk_recursive($groupPost, function ($item, $key) use(&$newGroupIds) {
             if ($key == 'id') {
                 $newGroupIds[] = $item;
             }
         });
         $deletedPropertiesIds = array_diff($oldPropertyIds, $newPropertyIds);
         $deletedGroupsIds = array_diff($oldGroupIds, $newGroupIds);
         if ($model->validate() && Model::validateProperties($groupProperties)) {
             $transaction = $model::getDb()->beginTransaction();
             try {
                 $oldImage = $model->getOldAttribute('image');
                 $oldIcon = $model->getOldAttribute('icon');
                 $oldIconHover = $model->getOldAttribute('icon_hover');
                 $model->image = UploadedFile::getInstance($model, 'image');
                 $model->icon = UploadedFile::getInstance($model, 'icon');
                 $model->icon_hover = UploadedFile::getInstance($model, 'icon_hover');
                 if ($model->image || $model->icon || $model->icon_hover) {
                     if ($save = $model->save()) {
                         $model->removeImageFromFolder($oldImage);
                         $model->removeIconFromFolder($oldIcon);
                         $model->removeIconHoverFromFolder($oldIconHover);
                         if (!$model->upload()) {
                             throw new \yii\base\Exception();
                         }
                     }
                 } else {
                     $model->image = $oldImage;
                     $model->icon = $oldIcon;
                     $model->icon_hover = $oldIconHover;
                     $save = $model->save();
                 }
                 if ($save) {
                     if (!empty($deletedPropertiesIds)) {
                         Property::deleteAll(['id' => $deletedPropertiesIds]);
                     }
                     if (!empty($deletedGroupsIds)) {
                         GroupProperty::deleteAll(['id' => $deletedGroupsIds]);
                     }
                     Model::linkProperties($model, $groupProperties);
                 }
                 Yii::$app->session->setFlash('success', 'Category have been updated.');
                 $transaction->commit();
             } catch (\Exception $e) {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('error', 'Failed to update category.');
             }
         }
     } else {
         if (empty($groupProperties)) {
             $groupProperties[] = ['group' => new GroupProperty(), 'properties' => [new Property()]];
         }
         return $this->render('update', ['model' => $model, 'groupProperties' => $groupProperties]);
     }
     return $this->redirect('index');
 }
Example #8
0
    <h2>Photos 360</h2>

    <!-- Photos -->
    <div class="form-group photos">
        <?php 
echo \kartik\file\FileInput::widget(['id' => 'photo360-upload', 'name' => 'photo360[]', 'options' => ['multiple' => true], 'pluginOptions' => ArrayHelper::merge($model->getPhoto360Config(), ['overwriteInitial' => false, 'showRemove' => false, 'showUpload' => false, 'uploadAsync' => true, 'allowedFileTypes' => ['image'], 'maxFileSize' => 1024, 'uploadUrl' => Url::to(['product/upload-temp-photo360']), 'uploadExtraData' => ['product_id' => $model->isNewRecord ? $model->id : '']])]);
?>
    </div>

    <h2>Photos</h2>

    <!-- Photos -->
    <div class="form-group photos">
        <?php 
echo \kartik\file\FileInput::widget(['id' => 'photo-upload', 'name' => 'photo[]', 'options' => ['multiple' => true], 'pluginOptions' => ArrayHelper::merge($model->getPhotoConfig(), ['overwriteInitial' => false, 'showRemove' => false, 'showUpload' => false, 'allowedFileTypes' => ['image'], 'maxFileSize' => 1024, 'uploadUrl' => Url::to(['product/upload-temp-photo']), 'uploadExtraData' => ['product_id' => $model->isNewRecord ? $model->id : '']])]);
?>
    </div>

    <!-- Videos -->
    <?php 
\wbraganca\dynamicform\DynamicFormWidget::begin(['widgetContainer' => 'video_dynamicform_wrapper', 'widgetBody' => '.video-container', 'widgetItem' => '.video-panel-body', 'min' => 1, 'insertButton' => '.add-item', 'deleteButton' => '.video-button-remove ', 'model' => new ProductVideo(), 'formId' => 'product-form', 'formFields' => ['video']]);
?>

    <div class="container-items"><!-- widgetContainer -->
            <div class="video-item item panel panel-default"><!-- widgetBody -->
                <div class="panel-heading">
                    <h3 class="panel-title pull-left">Videos - please, insert <b>youtube</b> video <b>ID</b> (https://www.youtube.com/watch?v=<b>id_here</b>)</h3>
                    <div class="pull-right">
                        <button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
                    </div>