From 8200ccb7df3b36368847bedcf4aa90bb15785402 Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 20 Aug 2021 21:26:11 +0300 Subject: [PATCH] init --- Module.php | 39 +++- assets/js/product.view.configurations.js | 8 +- commands/SitemapController.php | 101 ++++++++++ components/BaseTestUrlRule.php | 90 --------- components/BaseUrlRule.php | 94 ---------- components/BaseUrlRule1.php | 93 ---------- components/CategoryUrlRule.php | 174 ------------------ components/CategoryUrlRuleBACKUP.php | 147 --------------- components/CategoryUrlRule_1.php | 85 --------- components/EavBehavior.php | 6 +- components/FilterController.php | 5 +- components/ImageBehavior.php | 47 ++++- .../BaseUrlRule.php} | 13 +- components/{ => rules}/BrandUrlRule.php | 2 +- .../CategoryUrlRule.php} | 22 ++- components/{ => rules}/SearchUrlRule.php | 2 +- composer.json | 1 - controllers/CatalogController.php | 15 +- controllers/ProductController.php | 2 +- controllers/SearchController.php | 19 +- controllers/admin/ProductController.php | 6 + models/Brand.php | 6 + models/Category.php | 2 + models/Product.php | 64 +++++-- models/query/ProductQuery.php | 41 +++-- models/search/ProductConfigureSearch.php | 7 +- views/admin/product/index.php | 10 +- views/admin/product/tabs/_configurations.php | 26 ++- views/admin/product/tabs/_variations.php | 2 +- widgets/filtersnew2/assets/js/filter.js | 9 + 30 files changed, 363 insertions(+), 775 deletions(-) create mode 100644 commands/SitemapController.php delete mode 100644 components/BaseTestUrlRule.php delete mode 100644 components/BaseUrlRule.php delete mode 100644 components/BaseUrlRule1.php delete mode 100644 components/CategoryUrlRule.php delete mode 100644 components/CategoryUrlRuleBACKUP.php delete mode 100644 components/CategoryUrlRule_1.php rename components/{BaseTest2UrlRule.php => rules/BaseUrlRule.php} (93%) rename components/{ => rules}/BrandUrlRule.php (98%) rename components/{CategoryUrlRuleNew.php => rules/CategoryUrlRule.php} (87%) rename components/{ => rules}/SearchUrlRule.php (97%) diff --git a/Module.php b/Module.php index 319cc94b..5ffd30a8 100644 --- a/Module.php +++ b/Module.php @@ -19,7 +19,8 @@ class Module extends WebModule implements BootstrapInterface public $mailPath = '@shop/mail'; public $searchAttribute = 'sku'; public $filterViewCurrent = '@shop/widgets/filtersnew/views/current'; - + public $reviewsCount = 0; + public $viewList = ['grid','list']; public function getImage($dirtyAlias) { //Get params @@ -126,16 +127,16 @@ public function bootstrap($app) if ($app->id != 'console') { - + $this->reviewsCount = ProductReviews::find()->where(['status' => ProductReviews::STATUS_WAIT])->count(); $rules[] = [ - 'class' => 'panix\mod\shop\components\SearchUrlRule', + 'class' => 'panix\mod\shop\components\rules\SearchUrlRule', //'pattern'=>'products/search', 'route' => 'shop/search/index', 'defaults' => ['q' => Yii::$app->request->get('q')] ]; $rules[] = [ - 'class' => 'panix\mod\shop\components\BrandUrlRule', + 'class' => 'panix\mod\shop\components\rules\BrandUrlRule', 'route' => 'shop/brand/view', 'index' => 'brand', 'pattern' => 'brand/' @@ -149,10 +150,12 @@ public function bootstrap($app) // 'pattern' => '' ];*/ + // $rules['sales/page//per-page/'] = 'shop/catalog/sales'; + foreach ($this->getAllPaths() as $path) { $rules[] = [ - 'class' => 'panix\mod\shop\components\CategoryUrlRuleNew', + 'class' => 'panix\mod\shop\components\rules\CategoryUrlRule', 'route' => 'shop/catalog/view', 'defaults' => ['slug' => $path], //'suffix'=>'.html', @@ -161,7 +164,7 @@ public function bootstrap($app) $rules[] = [ - 'class' => 'panix\mod\shop\components\CategoryUrlRuleNew', + 'class' => 'panix\mod\shop\components\rules\CategoryUrlRule', 'route' => 'shop/catalog/sales', 'defaults' => ['slug' => $path], 'index'=>'sales', @@ -172,16 +175,30 @@ public function bootstrap($app) } $rules[] = [ - 'class' => 'panix\mod\shop\components\BaseTest2UrlRule', + 'class' => 'panix\mod\shop\components\rules\BaseUrlRule', + 'route' => 'shop/catalog/sales', + 'index' => 'sales', + 'pattern' => 'sales/page//per-page/', + ]; + $rules['sales/page/'] = 'shop/catalog/sales'; + $rules[] = [ + 'class' => 'panix\mod\shop\components\rules\BaseUrlRule', 'route' => 'shop/catalog/sales', 'index' => 'sales', 'pattern' => 'sales', ]; + // $rules['sales'] = 'shop/catalog/sales'; + + + + + + $rules[] = [ - 'class' => 'panix\mod\shop\components\BaseTest2UrlRule', + 'class' => 'panix\mod\shop\components\rules\BaseUrlRule', 'route' => 'shop/catalog/new', 'index' => 'new', 'pattern' => 'new' @@ -216,6 +233,8 @@ public function bootstrap($app) 'currency' => ['class' => 'panix\mod\shop\components\CurrencyManager'], ]); + + } public function getAllPaths() @@ -280,7 +299,7 @@ public function getViewProducts($current_id = false) public function getAdminMenu() { - $reviewCount = ProductReviews::find()->where(['status' => ProductReviews::STATUS_WAIT])->count(); + return [ 'shop' => [ 'label' => Yii::t('shop/default', 'MODULE_NAME'), @@ -323,7 +342,7 @@ public function getAdminMenu() 'label' => Yii::t('shop/admin', 'REVIEWS'), "url" => ['/admin/shop/reviews'], 'icon' => 'comments', - 'badge' => ($reviewCount) ? $reviewCount : '', + 'badge' => ($this->reviewsCount) ? $this->reviewsCount : '', 'visible' => Yii::$app->user->can('/shop/admin/reviews/index') || Yii::$app->user->can('/shop/admin/reviews/*') ], [ diff --git a/assets/js/product.view.configurations.js b/assets/js/product.view.configurations.js index 45902bb3..1622d4d8 100644 --- a/assets/js/product.view.configurations.js +++ b/assets/js/product.view.configurations.js @@ -9,7 +9,7 @@ $('.eavData:not(:first)').attr('disabled', 'disabled'); $(document).on('change','.eavData',function () { $('#configurable_id').val(0); if ($(this).val() === '---' || $(this).val() === '0') { - recalculateProductPrice(); + recalculateProductPrice(this); // If selected empty - reset all next dropdowns $('.eavData').nextAllData(this).each(function () { $(this).find('option:first').attr('selected', 'selected'); @@ -64,7 +64,7 @@ $('.eavData:last').change(function () { $('#configurable_id').val(productId); } - recalculateProductPrice(); + recalculateProductPrice(this); }); @@ -111,7 +111,9 @@ function recalculateProductPrice2(el_clicked) { */ function recalculateProductPrice(el_clicked) { var id = $(el_clicked).data('product_id'); - var form = $('#form-add-cart-'+$(el_clicked).data('product_id')); + console.log(el_clicked); + var form = $(el_clicked).closest('form'); + //var form = $('#form-add-cart-'+$(el_clicked).data('product_id')); var priceInput = form.find('input[name="product_price"]'); var formData = form.serialize(); var data = getFormData(form); diff --git a/commands/SitemapController.php b/commands/SitemapController.php new file mode 100644 index 00000000..f45240ff --- /dev/null +++ b/commands/SitemapController.php @@ -0,0 +1,101 @@ +rootDir.'/'.$this->sitemapFile); + + // $module = $this->module; + + //if (!$sitemapData = Yii::$app->cache->get('sitemap')) { + // $sitemapData = Yii::$app->getModule('sitemap')->buildSitemap(); + // } + + + // print_r($sitemapData);die; + + + $this->stdout("Generate sitemap file.".PHP_EOL, Console::FG_PURPLE); + $this->stdout("Rendering sitemap...".PHP_EOL, Console::FG_PURPLE); + $sitemap = Yii::$app->sitemap->render(); + + $this->stdout("Writing sitemap to $file".PHP_EOL, Console::FG_PURPLE); + file_put_contents($file, $sitemap[0]['xml']); + $sitemap_count = count($sitemap); + for ($i = 1; $i < $sitemap_count; $i++) { + $file = Yii::getAlias($this->rootDir.'/'.trim($sitemap[$i]['file'], '/')); + $this->stdout("Writing sitemap to $file".PHP_EOL, Console::FG_PURPLE); + file_put_contents($file, $sitemap[$i]['xml']); + } + $this->stdout("Done!".PHP_EOL, Console::FG_GREEN); + return ExitCode::OK; + } + + + + + public function actionTest() + { + + $file = Yii::getAlias($this->rootDir.'/'.$this->sitemapFileJson); + + + $this->stdout("Generate sitemap file.".PHP_EOL, Console::FG_PURPLE); + $this->stdout("Rendering sitemap...".PHP_EOL, Console::FG_PURPLE); + $sitemap = Yii::$app->sitemap->render(); + +//print_r($sitemap);die; + $xml = new \SimpleXMLElement($sitemap[0]['xml']); +//print_r($xml);die; + $this->stdout("Writing sitemap to $file".PHP_EOL, Console::FG_PURPLE); + file_put_contents($file, $sitemap[0]['xml']); + $sitemap_count = count($sitemap); + for ($i = 1; $i < $sitemap_count; $i++) { + $file = Yii::getAlias($this->rootDir.'/'.trim($sitemap[$i]['file'], '/')); + $this->stdout("Writing sitemap to $file".PHP_EOL, Console::FG_PURPLE); + file_put_contents($file, $sitemap[$i]['xml']); + } + $this->stdout("Done!".PHP_EOL, Console::FG_GREEN); + return ExitCode::OK; + } +} diff --git a/components/BaseTestUrlRule.php b/components/BaseTestUrlRule.php deleted file mode 100644 index 42578b02..00000000 --- a/components/BaseTestUrlRule.php +++ /dev/null @@ -1,90 +0,0 @@ -'; - public $cacheDuration = 0; - public $index = 'brand'; - public $alias = 'slug'; - public $query; - - /** - * @inheritdoc - */ - public function createUrl2($manager, $route, $params) - { - - if ($route === $this->route) { - if (isset($params['slug'])) { - $url = trim($params['slug'], '/'); - unset($params['slug']); - } else { - $url = ''; - } - $parts = []; - if (!empty($params)) { - foreach ($params as $key => $val) { - if (!is_array($val)) { - $parts[] = $key . '/' . $val; - } - } - if (!empty($url)) - $url .= '/' . implode('/', $parts); - } - - return $this->index . $url . $this->suffix; - // return $url . $this->suffix; - } - return false; - } - - - public function parseRequest($manager, $request) - { - - $params = []; - $pathInfo = $request->getPathInfo(); - - $basePathInfo = $pathInfo; - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - - $pathInfo = str_replace($this->index . '/', '', $pathInfo); - //$pathInfo = $pathInfo; - - - // $params['slug'] = ltrim($path[$this->alias]); - // $_GET['slug'] = $params['slug']; - - // $pathInfo = ltrim(substr($basePathInfo, strlen($this->index . '/' . $path[$this->alias])), '/'); - //$pathInfo = ltrim(substr($basePathInfo, strlen($path[$this->alias])), '/'); - - $parts = explode('/', $pathInfo); - $paramsList = array_chunk($parts, 2); - - foreach ($paramsList as $k => $p) { - if (isset($p[1]) && isset($p[0])) { - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } - } - - return [$this->route, $params]; - - - return false; - } - -} diff --git a/components/BaseUrlRule.php b/components/BaseUrlRule.php deleted file mode 100644 index 8a6f6cbc..00000000 --- a/components/BaseUrlRule.php +++ /dev/null @@ -1,94 +0,0 @@ -'; - public $cacheDuration = 0; - public $index = 'brand'; - public $alias = 'slug'; - public $query; - - /** - * @inheritdoc - */ - public function createUrl($manager, $route, $params) - { - - if ($route === $this->route) { - if (isset($params['slug'])) { - $url = trim($params['slug'], '/'); - unset($params['slug']); - } else { - $url = ''; - } - $parts = []; - if (!empty($params)) { - foreach ($params as $key => $val) { - if (!is_array($val)) { - $parts[] = $key . '/' . $val; - } - } - if (!empty($url)) - $url .= '/' . implode('/', $parts); - } - - return $this->index .'/'. $url . $this->suffix; - // return $url . $this->suffix; - } - return false; - } - - - public function parseRequest($manager, $request) - { - - $params = []; - $pathInfo = $request->getPathInfo(); - - $basePathInfo = $pathInfo; - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - if (method_exists($this, 'getAllPaths')) { - foreach ($this->getAllPaths() as $path) { - $pathInfo = str_replace($this->index . '/', '', $pathInfo); - //$pathInfo = $pathInfo; - if ($path[$this->alias] !== '' && strpos($pathInfo, $path[$this->alias]) === 0) { - - $params['slug'] = ltrim($path[$this->alias]); - $_GET['slug'] = $params['slug']; - - $pathInfo = ltrim(substr($basePathInfo, strlen($this->index . '/' . $path[$this->alias])), '/'); - //$pathInfo = ltrim(substr($basePathInfo, strlen($path[$this->alias])), '/'); - - $parts = explode('/', $pathInfo); - $paramsList = array_chunk($parts, 2); - - foreach ($paramsList as $k => $p) { - if (isset($p[1]) && isset($p[0])) { - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } - } - - return [$this->route, $params]; - } - } - } else { - return [$this->route, $params]; - } - return false; - } - -} diff --git a/components/BaseUrlRule1.php b/components/BaseUrlRule1.php deleted file mode 100644 index c26f43c4..00000000 --- a/components/BaseUrlRule1.php +++ /dev/null @@ -1,93 +0,0 @@ -'; - public $cacheDuration = 0; - public $index = 'brand'; - public $alias = 'slug'; - public $query; - - /** - * @inheritdoc - */ - public function createUrl($manager, $route, $params) - { - if ($route === $this->route) { - if (isset($params['slug'])) { - $url = trim($params['slug'], '/'); - unset($params['slug']); - } else { - $url = ''; - } - $parts = []; - if (!empty($params)) { - foreach ($params as $key => $val) { - //if(is_array($val)){ - // $val = implode(',',$val); - // } - $parts[] = $key . '/' . $val; - } - $url .= '/' . implode('/', $parts); - } - return $this->index . '/' . $url . $this->suffix; - } - return false; - } - - - public function parseRequest($manager, $request) - { - - $params = []; - $pathInfo = $request->getPathInfo(); - - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - foreach ($this->getAllPaths() as $path) { - $pathInfo = str_replace($this->index . '/', '', $pathInfo); - if ($path[$this->alias] !== '' && strpos($pathInfo, $path[$this->alias]) === 0) { - - $params['slug'] = ltrim($path[$this->alias]); - $_GET['slug'] = $params['slug']; - - $pathInfo = ltrim(substr($pathInfo, strlen($path[$this->alias])), '/'); - - - CMS::dump($params); - $parts = explode('/', $pathInfo); - $paramsList = array_chunk($parts, 2); - - CMS::dump($paramsList);die; - - unset($paramsList[0]); - - foreach ($paramsList as $k => $p) { - if (isset($p[1])) { - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } else { - - throw new HttpException(404, Yii::t('app/error', '404')); - } - } - return [$this->route, $params]; - } - } - - return false; - } - -} diff --git a/components/CategoryUrlRule.php b/components/CategoryUrlRule.php deleted file mode 100644 index b16ab636..00000000 --- a/components/CategoryUrlRule.php +++ /dev/null @@ -1,174 +0,0 @@ -route) { - - if (isset($params['slug'])) { - $url = trim($params['slug'], '/'); - unset($params['slug']); - } else { - $url = ''; - } - $parts = []; - if (!empty($params)) { - foreach ($params as $key => $val) { - $parts[] = $key . '/' . $val; - } - $url .= '/' . implode('/', $parts); - } - - return $url . $this->suffix; - } - - return false; - } - - public function parseRequest($manager, $request) - { - - $params = []; - $pathInfo = $request->getPathInfo(); - - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - - foreach ($this->getAllPaths() as $path) { - - if ($path['full_path'] !== '' && strpos($pathInfo, $path['full_path']) === 0) { - $_GET['slug'] = $path['full_path']; - $uri = str_replace($path['full_path'], '', $pathInfo); - $parts = explode('/', $uri); - unset($parts[0]); - //$pathInfo = implode($parts, '/'); - // print_r(array_chunk($parts, 2)); - $ss = array_chunk($parts, 2); - - foreach ($ss as $k => $p) { - // print_r($p); - if (isset($p[1])) { - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } - } - - $params['slug'] = ltrim($path['full_path']); - - - return [$this->route, $params]; - } - } - - return false; - }*/ - - protected function getAllPaths() - { - $allPaths = \Yii::$app->cache->get('CategoryUrlRule'); - if ($allPaths === false) { - $items = (new \yii\db\Query()) - ->select(['full_path']) - ->andWhere('id!=:id', [':id' => 1]) - ->from(Category::tableName()) - ->all(); - - $allPaths = []; - foreach ($items as $item) { - $allPaths[] = $item['full_path']; - } - - // Sort paths by length. - usort($allPaths, function ($a, $b) { - return strlen($b) - strlen($a); - // return strlen($b['full_path']) - strlen($a['full_path']); - }); - - - \Yii::$app->cache->set('CategoryUrlRule', $allPaths, 1); - } - - return $allPaths; - } - - - public function parseRequest($manager, $request) - { - - - $params = []; - $pathInfo = $request->getPathInfo(); - - - $isAdmin = strpos($pathInfo, 'admin'); - if ($isAdmin === false) { - - - $basePathInfo = $pathInfo; - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - //if ($this->host !== null) { - // $pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo); - //} - - foreach ($this->getAllPaths() as $path) { - $pathInfo = str_replace($this->index . '/', '', $pathInfo); - if ($path !== '' && strpos($pathInfo, $path) === 0) { - - $params['slug'] = ltrim($path); - $_GET['slug'] = $params['slug']; - - $pathInfo = ltrim(substr($basePathInfo, strlen($this->index . '/' . $path)), '/'); - // $pathInfo = trim(substr($basePathInfo, strlen($this->index . '/' . $path))); - - if (!empty($pathInfo)) { - $parts = explode('/', $pathInfo); - $paramsList = array_chunk($parts, 2); - foreach ($paramsList as $k => $p) { - - if (!isset($p[1])) { - - return false; - } - if (isset($p[1]) && isset($p[0])) { - - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } - - } - } - return [$this->route, $params]; - } - - } - } - return false; - } - -} diff --git a/components/CategoryUrlRuleBACKUP.php b/components/CategoryUrlRuleBACKUP.php deleted file mode 100644 index 79ae4db6..00000000 --- a/components/CategoryUrlRuleBACKUP.php +++ /dev/null @@ -1,147 +0,0 @@ -route) { - - if (isset($params['slug'])) { - $url = trim($params['slug'], '/'); - unset($params['slug']); - } else { - $url = ''; - } - $parts = []; - if (!empty($params)) { - foreach ($params as $key => $val) { - $parts[] = $key . '/' . $val; - } - $url .= '/' . implode('/', $parts); - } - - return $url . $this->suffix; - } - - return false; - } - - public function parseRequest($manager, $request) - { - - $params = []; - $pathInfo = $request->getPathInfo(); - - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - - foreach ($this->getAllPaths() as $path) { - - if ($path['full_path'] !== '' && strpos($pathInfo, $path['full_path']) === 0) { - $_GET['slug'] = $path['full_path']; - $uri = str_replace($path['full_path'], '', $pathInfo); - $parts = explode('/', $uri); - unset($parts[0]); - //$pathInfo = implode($parts, '/'); - // print_r(array_chunk($parts, 2)); - $ss = array_chunk($parts, 2); - - foreach ($ss as $k => $p) { - // print_r($p); - if (isset($p[1])) { - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } - } - - $params['slug'] = ltrim($path['full_path']); - - - return [$this->route, $params]; - } - } - - return false; - }*/ - - protected function getAllPaths() - { - $allPaths = \Yii::$app->cache->get('CategoryUrlRule'); - if ($allPaths === false) { - $allPaths = (new \yii\db\Query()) - ->select(['full_path']) - ->andWhere('id!=:id', [':id' => 1]) - ->from(Category::tableName()) - ->all(); - - - // Sort paths by length. - usort($allPaths, function ($a, $b) { - return strlen($b['full_path']) - strlen($a['full_path']); - }); - - \Yii::$app->cache->set('CategoryUrlRule', $allPaths, $this->cacheDuration); - } - - return $allPaths; - } - - - public function parseRequest($manager, $request) - { - - $params = []; - $pathInfo = $request->getPathInfo(); - - $basePathInfo= $pathInfo; - if (empty($pathInfo)) - return false; - - if ($this->suffix) - $pathInfo = strtr($pathInfo, [$this->suffix => '']); - - - foreach ($this->getAllPaths() as $path) { - $pathInfo = str_replace($this->index . '/', '', $pathInfo); - if ($path[$this->alias] !== '' && strpos($pathInfo, $path[$this->alias]) === 0) { - - $params['slug'] = ltrim($path[$this->alias]); - $_GET['slug'] = $params['slug']; - - $pathInfo = ltrim(substr($basePathInfo, strlen($this->index.'/'.$path[$this->alias])), '/'); - - $parts = explode('/', $pathInfo); - $paramsList = array_chunk($parts, 2); - - foreach ($paramsList as $k => $p) { - if (isset($p[1]) && isset($p[0])) { - $_GET[$p[0]] = $p[1]; - $params[$p[0]] = $p[1]; - } - } - - return [$this->route, $params]; - } - } - - return false; - } - -} diff --git a/components/CategoryUrlRule_1.php b/components/CategoryUrlRule_1.php deleted file mode 100644 index 2eab2206..00000000 --- a/components/CategoryUrlRule_1.php +++ /dev/null @@ -1,85 +0,0 @@ - $val){ - - $parts[] = $key . '/' . $val; - - } - $url .= '/' . implode('/', $parts); - } - - return $url . \Yii::$app->urlManager->suffix; - } - return false; - } - - public function parseRequest($manager, $request) { - - $params = []; - $pathInfo = $request->getPathInfo(); - if (empty($pathInfo)) - return false; - - if (\Yii::$app->urlManager->suffix) - $pathInfo = strtr($pathInfo, array(\Yii::$app->urlManager->suffix => '')); - //if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) { - foreach ($this->getAllPaths() as $path) { - if ($path['full_path'] !== '' && strpos($pathInfo, $path['full_path']) === 0) { - $_GET['slug'] = $path['full_path']; - - $params['slug'] = ltrim($path['full_path']); - // var_dump($params); - // die; - //// \Yii::$app->urlManager->parsePathInfo($params); - // \Yii::$app->urlManager->parseRequest($params); - return ['shop/category/view', $params]; - } - } - // check $matches[1] and $matches[3] to see - // if they match a brand and a model in the database. - // If so, set $params['brand'] and/or $params['model'] - // and return ['car/index', $params] - // } - return false; // this rule does not apply - } - - protected function getAllPaths() { - $allPaths = \Yii::$app->cache->get(__CLASS__); - if ($allPaths === false) { - $allPaths = (new \yii\db\Query()) - ->select(['full_path']) - ->andWhere('id!=:id', [':id' => 1]) - ->from('{{%shop__category}}') - ->all(); - - - // Sort paths by length. - usort($allPaths, function($a, $b) { - return strlen($b['full_path']) - strlen($a['full_path']); - }); - - \Yii::$app->cache->set(__CLASS__, $allPaths); - } - - return $allPaths; - } - -} diff --git a/components/EavBehavior.php b/components/EavBehavior.php index a54e13af..d1437019 100644 --- a/components/EavBehavior.php +++ b/components/EavBehavior.php @@ -8,6 +8,7 @@ use panix\mod\shop\models\ProductAttributesEav; use Yii; use yii\base\Exception; +use yii\caching\TagDependency; use yii\db\ActiveRecord; use yii\db\Query; @@ -292,6 +293,7 @@ public function afterFind() // Load attributes for model. if ($this->preload) { if ($owner->getPrimaryKey()) { + $this->loadEavAttributes($this->getSafeAttributesArray()); } } @@ -342,7 +344,9 @@ public function saveEavAttributes($attributes) */ public function loadEavAttributes($attributes) { - $data = $this->getLoadEavAttributesQuery($attributes)->all(); + $data = $this->getLoadEavAttributesQuery($attributes) + //->cache(Yii::$app->db->queryCacheDuration,new TagDependency(['tags' => "attributes-{$this->owner->primaryKey}"])) + ->all(); foreach ($data as $row) { $attribute = $this->stripPrefix($row[$this->attributeField]); $value = $row[$this->valueField]; diff --git a/components/FilterController.php b/components/FilterController.php index 633bf1ba..aaa83bbc 100644 --- a/components/FilterController.php +++ b/components/FilterController.php @@ -132,7 +132,7 @@ public function beforeAction($action) Url::remember(); if (Yii::$app->request->get('view')) { - if (in_array(Yii::$app->request->get('view'), ['list', 'grid'])) { + if (in_array(Yii::$app->request->get('view'), Yii::$app->getModule('shop')->viewList)) { $this->itemView = '_view_' . Yii::$app->request->get('view'); } } @@ -535,6 +535,7 @@ public function _render($view = '@shop/views/catalog/view',array $params=[]) if (Yii::$app->request->headers->has('filter-ajax')) { Yii::$app->response->format = Response::FORMAT_JSON; $url = ($this->dataModel) ? $this->dataModel->getUrl() : ['/' . Yii::$app->requestedRoute]; + return [ //'currentFilters' => $filterData, //'full_url' => Url::to($this->currentUrl), @@ -546,7 +547,7 @@ public function _render($view = '@shop/views/catalog/view',array $params=[]) 'currentFiltersData' => ($activeFilters) ? $this->renderPartial($this->module->filterViewCurrent, [ //'@shop/widgets/filtersnew/views/current', '@app/widgets/filters/current' 'dataModel' => $this->dataModel, 'active' => $activeFilters, - 'url' => $url + 'url' => $this->refreshUrl ]) : null ]; } else { diff --git a/components/ImageBehavior.php b/components/ImageBehavior.php index 5f4aa5f6..61fdcafd 100644 --- a/components/ImageBehavior.php +++ b/components/ImageBehavior.php @@ -2,9 +2,6 @@ namespace panix\mod\shop\components; -use panix\engine\CMS; -use panix\engine\components\ImageHandler; -use panix\mod\shop\models\ProductImage; use Yii; use yii\base\Exception; use yii\db\ActiveRecord; @@ -12,6 +9,9 @@ use yii\helpers\BaseFileHelper; use yii\helpers\FileHelper; use yii\httpclient\Client; +use panix\engine\CMS; +use panix\engine\components\ImageHandler; +use panix\mod\shop\models\ProductImage; class ImageBehavior extends \yii\base\Behavior { @@ -58,6 +58,43 @@ public function afterSave() } } + /** + * Remove all model images + */ + public function afterDelete() + { + $images = $this->owner->getImages(); + if ($images->count() < 1) { + return true; + } else { + foreach ($images->all() as $image) { + $this->removeImage($image); + } + + $path = Yii::getAlias($this->savePath) . DIRECTORY_SEPARATOR . $this->owner->primaryKey; + BaseFileHelper::removeDirectory($path); + } + } + + /** + * removes concrete model's image + * @param ProductImage $img + * @return bool + * @throws \Exception + */ + public function removeImage(ProductImage $img) + { + + $storePath = Yii::getAlias('@uploads/store'); + + $fileToRemove = Yii::getAlias($this->savePath); + if (preg_match('@\.@', $fileToRemove) and is_file($fileToRemove)) { + unlink($fileToRemove); + } + $img->delete(); + return true; + } + protected function updateMainImage() { $post = Yii::$app->request->post('AttachmentsMainId'); @@ -81,8 +118,8 @@ protected function updateMainImage() if ($currentMainId != $post) { $customer->is_main = 1; $customer->update(); - $this->owner->main_image = $customer->filename; - $this->owner->save(false); + //$this->owner->main_image = $customer->filename; + // $this->owner->save(false); } } } diff --git a/components/BaseTest2UrlRule.php b/components/rules/BaseUrlRule.php similarity index 93% rename from components/BaseTest2UrlRule.php rename to components/rules/BaseUrlRule.php index 2d39d638..caa6b0d9 100644 --- a/components/BaseTest2UrlRule.php +++ b/components/rules/BaseUrlRule.php @@ -1,6 +1,6 @@ '; @@ -31,6 +31,9 @@ public function createUrl($manager, $route, $params) } $parts = []; if (!empty($params)) { + if(Yii::$app->request->isPjax){ + unset($params['_pjax']); + } foreach ($params as $key => $val) { if (!is_array($val)) { $parts[] = $key . '/' . $val; @@ -78,12 +81,16 @@ public function parseRequest($manager, $request) //original end $params=[]; + $pathInfoParse = str_replace($this->index . '/', '', $pathInfo); $parts = explode('/', $pathInfoParse); if ($this->index == mb_substr($pathInfo, 0,strlen($this->index))) { $paramsList = array_chunk($parts, 2); - //CMS::dump($paramsList);die; + + + foreach ($paramsList as $k => $p) { + if (isset($p[1]) && isset($p[0])) { $_GET[$p[0]] = $p[1]; $params[$p[0]] = $p[1]; diff --git a/components/BrandUrlRule.php b/components/rules/BrandUrlRule.php similarity index 98% rename from components/BrandUrlRule.php rename to components/rules/BrandUrlRule.php index 8e3cf36c..0fdcd987 100644 --- a/components/BrandUrlRule.php +++ b/components/rules/BrandUrlRule.php @@ -1,6 +1,6 @@ mode === self::CREATION_ONLY) { return false; } @@ -49,22 +50,24 @@ public function parseRequest($manager, $request) } $params = $this->defaults; - if ($params['slug'] !== '' && strpos(str_replace($this->index.'/', '', $pathInfo), $params['slug']) === 0) { - $parts_slug = explode('/', $this->index.'/' . $params['slug']); + if ($params['slug'] !== '' && strpos(str_replace($this->index . '/', '', $pathInfo), $params['slug']) === 0) { + + $parts_slug = explode('/', $this->index . '/' . $params['slug']); $parts = explode('/', $pathInfo); $a = array_slice($parts, 0, count($parts_slug)); if (array_diff($parts_slug, $a)) { + return false; } - - $filterPathInfo = ltrim(substr($pathInfo, strlen($this->index.'/' . $params['slug'])), '/'); + $_GET['slug'] = $params['slug']; + $filterPathInfo = ltrim(substr($pathInfo, strlen($this->index . '/' . $params['slug'])), '/'); if (!empty($filterPathInfo)) { $parts = explode('/', $filterPathInfo); $paramsList = array_chunk($parts, 2); - foreach ($paramsList as $p) { + foreach ($paramsList as $p) { if (isset($p[1])) { $params[$p[0]] = $p[1]; $_GET[$p[0]] = $p[1]; @@ -94,7 +97,7 @@ public function createUrl($manager, $route, $params) if ($route === $this->route) { if (isset($params['slug'])) { - $url = '/'.trim($params['slug'], '/'); + $url = '/' . trim($params['slug'], '/'); unset($params['slug']); } else { $url = ''; @@ -102,6 +105,9 @@ public function createUrl($manager, $route, $params) //echo $url;die; $parts = []; if (!empty($params)) { + if(Yii::$app->request->isPjax){ + unset($params['_pjax']); + } foreach ($params as $key => $val) { if (!is_array($val)) { $parts[] = $key . '/' . $val; diff --git a/components/SearchUrlRule.php b/components/rules/SearchUrlRule.php similarity index 97% rename from components/SearchUrlRule.php rename to components/rules/SearchUrlRule.php index 29842ac8..908f7aa6 100644 --- a/components/SearchUrlRule.php +++ b/components/rules/SearchUrlRule.php @@ -1,6 +1,6 @@ view->registerJs("var current_url = '" . $this->currentUrl . "';", yii\web\View::POS_HEAD, 'current_url'); - $this->query = $productModel::find()->published(); - if ($config->label_expire_new) { + $this->query = $productModel::find()->published()->new(); + /*if ($config->label_expire_new) { $this->query->int2between(time(), time() - (86400 * $config->label_expire_new)); } else { $this->query->int2between(-1, -1); - } + }*/ $this->filter = new Filter($this->query, $productModel); @@ -344,8 +344,7 @@ public function actionSales() $this->query = Product::find()->published(); - $this->query->andWhere(['IS NOT', Product::tableName() . '.discount', null]) - ->andWhere(['!=', Product::tableName() . '.discount', '']); + $this->query->sales(); $brands = []; $categories = []; @@ -392,6 +391,10 @@ public function actionSales() foreach ($categoriesResult as $c){ $categoriesIds[]=$c['main_category_id']; } + + + // $categoriesResponse = Category::find()->dataTree(1, null, ['switch' => 1,'id'=>$categoriesIds],CMS::gen(100)); + // CMS::dump($categoriesResponse);die; $categoriesResponse = Category::find()->where(['id'=>$categoriesIds])->all(); if(Yii::$app->request->getQueryParam('slug')){ $category = $this->findModel(Yii::$app->request->getQueryParam('slug')); @@ -447,7 +450,7 @@ public function actionSales() // ), - return $this->_render('@shop/views/catalog/view',['categories'=>$categoriesResponse]); + return $this->_render('@shop/views/catalog/view',['categories'=>$categoriesResponse,'categoriesIds'=>$categoriesIds]); } diff --git a/controllers/ProductController.php b/controllers/ProductController.php index 3592fcc1..c0d5e6bd 100644 --- a/controllers/ProductController.php +++ b/controllers/ProductController.php @@ -74,7 +74,7 @@ public function actionView($slug, $id) { $this->dataModel = $this->findModel($slug, $id); - + $this->dataModel->preload=true; if (Yii::$app->settings->get('seo', 'google_tag_manager')) { $dataLayer['ecomm_pagetype'] = 'offerdetail'; $dataLayer['ecomm_totalvalue'] = (string) $this->dataModel->getFrontPrice(); diff --git a/controllers/SearchController.php b/controllers/SearchController.php index 9a2c9419..9484a195 100644 --- a/controllers/SearchController.php +++ b/controllers/SearchController.php @@ -2,6 +2,7 @@ namespace panix\mod\shop\controllers; +use panix\engine\CMS; use panix\engine\Html; use panix\mod\shop\components\Filter; use Yii; @@ -23,12 +24,12 @@ public function actionIndex() $productModel = Yii::$app->getModule('shop')->model('Product'); $this->query = $productModel::find(); //$this->query->attachBehaviors((new $productModel)->behaviors()); - +$q=Yii::$app->request->post('q'); //fix for POST send form if (!Yii::$app->request->isPjax || !Yii::$app->request->isAjax) { - if (Yii::$app->request->post('q')) + if ($q) return $this->redirect(['/shop/search/index', 'q' => Yii::$app->request->post('q')]); } @@ -38,7 +39,14 @@ public function actionIndex() $this->query->applyBrands($brands); } $this->query->groupBy(Product::tableName() . '.`id`'); - $this->query->applySearch(Yii::$app->request->get('q'))->published(); + + //если пусто, делаем фейк запрос для "не чего не найдено" + $queryGet = Yii::$app->request->get('q'); + if(empty($queryGet)){ + $queryGet = CMS::gen(10); + } + + $this->query->applySearch($queryGet)->published(); $this->filter = new Filter($this->query); @@ -63,8 +71,11 @@ public function actionIndex() 'pageSize' => $this->per_page, ] ]); + + $this->currentUrl = Url::to(['/shop/search/index', 'q' => Yii::$app->request->get('q')]); + $this->refreshUrl=$this->currentUrl; $this->view->canonical = Url::to(['/shop/search/index', 'q' => Yii::$app->request->get('q')], true); - $this->view->registerJs("var current_url = '" . Url::to(Yii::$app->request->getUrl()) . "';", yii\web\View::POS_HEAD, 'current_url'); + $this->view->registerJs("var current_url = '" . $this->currentUrl . "';", yii\web\View::POS_HEAD, 'current_url'); $this->pageName = Yii::t('shop/default', 'SEARCH_RESULT', [ 'query' => Html::encode(Yii::$app->request->get('q')), diff --git a/controllers/admin/ProductController.php b/controllers/admin/ProductController.php index 7f71b8f1..43c7946b 100644 --- a/controllers/admin/ProductController.php +++ b/controllers/admin/ProductController.php @@ -72,7 +72,13 @@ public function actionIndex() { $searchModel = new ProductSearch(); + + $searchModel->preload = false; $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams()); + //$searchModel->behaviors()['eav']['preload']=false; + + // $searchModel->attachBehavior('eav',ArrayHelper::merge($searchModel->behaviors()['eav'],['preload'=>false])); + // CMS::dump($searchModel->behaviors['eav']);die; $this->pageName = Yii::t('shop/admin', 'PRODUCTS'); if (Yii::$app->user->can("/{$this->module->id}/{$this->id}/*") || Yii::$app->user->can("/{$this->module->id}/{$this->id}/create")) { diff --git a/models/Brand.php b/models/Brand.php index 253451e9..d4895059 100644 --- a/models/Brand.php +++ b/models/Brand.php @@ -5,6 +5,7 @@ use panix\engine\Html; use panix\mod\shop\components\ExternalFinder; use Yii; +use yii\caching\TagDependency; use yii\helpers\ArrayHelper; use panix\engine\db\ActiveRecord; use panix\mod\shop\models\query\BrandQuery; @@ -177,4 +178,9 @@ public function afterDelete() } parent::afterDelete(); } + public function afterSave($insert, $changedAttributes) + { + TagDependency::invalidate(Yii::$app->cache, 'brand-'.$this->id); + parent::afterSave($insert, $changedAttributes); + } } diff --git a/models/Category.php b/models/Category.php index 3bdd8dda..d6de4b85 100644 --- a/models/Category.php +++ b/models/Category.php @@ -131,6 +131,8 @@ public function behaviors() }, 'dataClosure' => function ($model) { /** @var self $model */ + + return [ 'loc' => $model->getUrl(), 'lastmod' => $model->updated_at, diff --git a/models/Product.php b/models/Product.php index a89c2c2c..eccc49a9 100644 --- a/models/Product.php +++ b/models/Product.php @@ -11,6 +11,7 @@ use panix\engine\CMS; use panix\mod\shop\models\query\ProductQuery; use yii\caching\DbDependency; +use yii\caching\TagDependency; use yii\db\Exception; use yii\db\Query; use yii\helpers\ArrayHelper; @@ -168,7 +169,7 @@ public function buy($value, array $options) public function beginCartForm() { $html = ''; - $html .= Html::beginForm(['/cart/add'], 'post'); + $html .= Html::beginForm(['/cart/add'], 'post', ['csrf' => false]); $html .= Html::hiddenInput('product_id', $this->id); //$html .= Html::hiddenInput('product_price', $this->price); //$html .= Html::hiddenInput('use_configurations', $this->use_configurations, ['id' => 'use_configurations-' . $this->id]); @@ -275,13 +276,13 @@ public function afterFind() $sum = $this->discount; if ('%' === substr($sum, -1, 1)) { $sum = $this->price * ((double)$sum) / 100; - // $this->discountParcent = round((($sum - $this->price) / $sum) * 100);11 + // $this->discountParcent = round((($sum - $this->price) / $sum) * 100);11 } else { } $this->discountSum = $this->discount; $this->discountPrice = $this->price - $sum; - $this->discountPercent = round( ($this->price-$this->discountPrice)/$this->price * 100); + $this->discountPercent = round(($this->price - $this->discountPrice) / $this->price * 100); $this->originalPrice = $this->price; $this->hasDiscount = $this->discount; } @@ -403,7 +404,7 @@ public function rules() // $rules[] = [['image'], 'image']; $rules[] = [['name', 'slug'], 'trim']; - $rules[] = [['full_description', 'length', 'width', 'height', 'weight', 'main_image'], 'string']; + $rules[] = [['full_description', 'length', 'width', 'height', 'weight'], 'string']; $rules[] = ['use_configurations', 'boolean', 'on' => self::SCENARIO_INSERT]; $rules[] = ['enable_comments', 'boolean']; $rules[] = [['unit'], 'default', 'value' => 1]; @@ -515,7 +516,7 @@ public function getReviewsCount() */ public function getBrand() { - return $this->hasOne(Brand::class, ['id' => 'brand_id']); + return $this->hasOne(Brand::class, ['id' => 'brand_id'])->cache(self::getDb()->queryCacheDuration,new TagDependency(['tags' => 'brand-'.$this->brand_id])); } /** @@ -560,7 +561,6 @@ public function getImages() } - /** * @return \yii\db\ActiveQuery */ @@ -1127,6 +1127,23 @@ public function getConfigurable_attributes() return $this->_configurable_attributes; } + public function getEav($attribute) + { + if ($this->getIsNewRecord()) + return null; + + //$attribute = substr($name, 4); + /** @var \panix\mod\shop\components\EavBehavior $this */ + $eavData = $this->getEavAttributes(); + + if (isset($eavData[$attribute])) + $value = $eavData[$attribute]; + else + return null; + + return $value; + } + /** * @inheritdoc */ @@ -1140,29 +1157,43 @@ public function __get($name) $dependency->sql = "SELECT MAX(updated_at) FROM {$table}"; - if ($this->getIsNewRecord()) + $value = $this->getEav($attribute = substr($name, 4)); + /*if ($this->getIsNewRecord()) return null; $attribute = substr($name, 4); - /** @var \panix\mod\shop\components\EavBehavior $this */ + $eavData = $this->getEavAttributes(); if (isset($eavData[$attribute])) $value = $eavData[$attribute]; else - return null; + return null;*/ - $attributeModel = Attribute::getDb()->cache(function ($db) use ($attribute) { - $q = Attribute::find()->where(['name' => $attribute]); + //$attributeModel = Attribute::getDb()->cache(function ($db) use ($attribute) { + // $q = Attribute::find()->where(['name' => $attribute]); - $result = $q->one(); - return $result; - }); + // $attributeModel = $q->one(); + // return $result; + //}); + + + /*$query = new \yii\db\Query(); + + $query->from(\panix\mod\shop\models\AttributeOption::tableName()) + ->where(['id' =>$value]); + // ->cache(Yii::$app->db->queryCacheDuration); + $option = $query->one();*/ + // return $attributeModel['value']; + $q = AttributeOption::find()->where(['id' => $value]); + $q->orderBy = false; + $o = $q->cache(self::getDb()->queryCacheDuration)->one(); //$attributeModel = Attribute::find()->where(['name' => $attribute])->cache(3600 * 24, $dependency)->one(); - return (object)['name' => $attributeModel->title, 'value' => $attributeModel->renderValue($value)]; + //return (object)['name' => $attributeModel->title, 'value' => $attributeModel->renderValue($value)]; + return $o; //return $attributeModel->renderValue($value); } return parent::__get($name); @@ -1204,7 +1235,8 @@ public function behaviors() ]; $a['eav'] = [ 'class' => '\panix\mod\shop\components\EavBehavior', - 'tableName' => ProductAttributesEav::tableName() + 'tableName' => ProductAttributesEav::tableName(), + 'preload'=>true ]; $a['translate'] = [ 'class' => '\panix\mod\shop\components\TranslateBehavior', diff --git a/models/query/ProductQuery.php b/models/query/ProductQuery.php index 61d061ef..53818f8c 100644 --- a/models/query/ProductQuery.php +++ b/models/query/ProductQuery.php @@ -27,10 +27,23 @@ public function category() return $this; } - public function getSales(){ - $this->published(); - $this->andWhere(['IS NOT', Product::tableName() . '.discount', null]) - ->andWhere(['!=', Product::tableName() . '.discount', '']); + public function sales() + { + + $this->andWhere(['IS NOT', Product::tableName() . '.discount', null]); + //->andWhere(['!=', Product::tableName() . '.discount', '']); + return $this; + } + + public function new() + { + $config = Yii::$app->settings->get('shop'); + if ($config->label_expire_new) { + $this->int2between(time(), time() - (86400 * $config->label_expire_new)); + } else { + $this->int2between(-1, -1); + } + $this->orderBy(['created_at'=>SORT_DESC]); return $this; } @@ -40,7 +53,7 @@ public function getSales(){ * @param $whereType string * @return $this */ - public function applyBrands($brands,$whereType = 'andWhere') + public function applyBrands($brands, $whereType = 'andWhere') { if (!is_array($brands)) $brands = [$brands]; @@ -115,20 +128,20 @@ public function applySearch($q = null) if ($q) { $modelClass = $this->modelClass; $tableName = $modelClass::tableName(); - $this->andWhere(['LIKE', $tableName . '.'.Yii::$app->getModule('shop')->searchAttribute, $q]); + $this->andWhere(['LIKE', $tableName . '.' . Yii::$app->getModule('shop')->searchAttribute, $q]); $this->orWhere(['LIKE', $tableName . '.name_' . $language, $q]); } return $this; } - - public function new($start, $end) - { - $modelClass = $this->modelClass; - $tableName = $modelClass::tableName(); - $this->between($start, $end, 'created_at'); - return $this; - } + /* + public function new($start, $end) + { + $modelClass = $this->modelClass; + $tableName = $modelClass::tableName(); + $this->between($start, $end, 'created_at'); + return $this; + }*/ /** diff --git a/models/search/ProductConfigureSearch.php b/models/search/ProductConfigureSearch.php index 9f47d380..b2a5b57b 100644 --- a/models/search/ProductConfigureSearch.php +++ b/models/search/ProductConfigureSearch.php @@ -53,7 +53,7 @@ public function search($params, $configure = []) $query = Product::find(); $query->sort(); - $query->joinWith(['categorization categories']); //, 'commentsCount' + //$query->joinWith(['categorization categories']); //, 'commentsCount' $dataProvider = new ActiveDataProvider([ 'query' => $query, @@ -122,8 +122,9 @@ public function search($params, $configure = []) $query->andFilterWhere(['brand_id' => $this->brand_id]); - if ($this->eavAttributes) - $query->withEavAttributes($this->eavAttributes); + $eav = $this->eavAttributes; + if ($eav) + $query->withEavAttributes($eav); return $dataProvider; diff --git a/views/admin/product/index.php b/views/admin/product/index.php index 523687b3..966b5590 100644 --- a/views/admin/product/index.php +++ b/views/admin/product/index.php @@ -27,6 +27,8 @@ } CMS::dump($matches);die; */ +ProductIndex::register($this); +Pjax::begin(['id'=>'pjax-grid-product']); ?>
@@ -53,8 +55,7 @@ render('_grid_filter', ['model' => $searchModel]); -ProductIndex::register($this); -Pjax::begin(['id'=>'pjax-grid-product']); + echo GridView::widget([ 'id' => 'grid-product', @@ -71,11 +72,12 @@ 'showFooter' => true, 'pager'=>['options'=>['class'=>'pagination ml-auto mr-auto mr-lg-0 ml-lg-auto']] ]); -Pjax::end(); + ?>
- + 1]); //use yii\widgets\Pjax; use panix\mod\shop\models\search\ProductConfigureSearch; @@ -77,11 +77,11 @@ 'contentOptions' => ['class' => 'text-center'], 'filter' => ArrayHelper::map(Brand::find() ->addOrderBy(['name_' . Yii::$app->language => SORT_ASC]) - // ->cache(3200, new DbDependency(['sql' => 'SELECT MAX(`updated_at`) FROM ' . Brand::tableName()])) + ->cache(Yii::$app->db->queryCacheDuration, new \yii\caching\DbDependency(['sql' => 'SELECT MAX(`updated_at`) FROM ' . Brand::tableName()])) ->all(), 'id', 'name_' . Yii::$app->language), 'filterInputOptions' => ['class' => 'form-control', 'prompt' => html_entity_decode('— выберите бренд —')], 'value' => function ($model) { - return ($model->brand) ? $model->brand->name : NULL; + return ($model->brand_id) ? $model->brand->name : NULL; } ]; $columns[] = [ @@ -130,26 +130,36 @@ $columns[] = [ - 'attribute' => 'eav_' . $attribute->name . '.value', + // 'attribute' => 'eav_' . $attribute->name . '.value', 'header' => $attribute->title, 'contentOptions' => ['class' => 'eav text-center'], - 'filter' => Html::dropDownList('eav[' . $attribute->name . ']', $selected, ArrayHelper::map($attribute->getOptions()->cache(86400), 'id', 'value'), [ + 'filter' => Html::dropDownList('eav[' . $attribute->name . ']', $selected, ArrayHelper::map($attribute->getOptions()->cache(Yii::$app->db->queryCacheDuration)->all(), 'id', 'value'), [ 'prompt' => html_entity_decode($product::t('SELECT_ATTRIBUTE')), 'class' => 'custom-select w-auto' - ]) + ]), + 'value' => function ($model) use ($attribute) { + //print_r($model);die; + $query = new \yii\db\Query(); + + $query->from(\panix\mod\shop\models\AttributeOption::tableName()) + ->where(['id' => $model->getEav($attribute->name)]) + ->cache(Yii::$app->db->queryCacheDuration); + $item = $query->one(); + return $item['value']; + } ]; } } $searchModel = new ProductConfigureSearch(); $searchModel->exclude[] = $product->id; -$searchModel->eavAttributes = $eavAttributes; +//$searchModel->eavAttributes = $eavAttributes; //print_r($product->getConfigurations()); $configure = []; -$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams(), ['attribute_id' => $attribute_id,'confs'=>$product->getConfigurations()]); +$dataProvider = $searchModel->search(Yii::$app->request->getQueryParams(), ['attribute_id' => $attribute_id, 'confs' => $product->getConfigurations()]); Pjax::begin([ 'id' => 'pjax-ConfigurationsProductGrid', 'enablePushState' => false, diff --git a/views/admin/product/tabs/_variations.php b/views/admin/product/tabs/_variations.php index 4554c73c..4a7fa05e 100644 --- a/views/admin/product/tabs/_variations.php +++ b/views/admin/product/tabs/_variations.php @@ -41,4 +41,4 @@ } ?>
- \ No newline at end of file + diff --git a/widgets/filtersnew2/assets/js/filter.js b/widgets/filtersnew2/assets/js/filter.js index 0db7c55b..ab9a5db5 100644 --- a/widgets/filtersnew2/assets/js/filter.js +++ b/widgets/filtersnew2/assets/js/filter.js @@ -201,8 +201,17 @@ function filter_ajax(e, objects) { console.debug('ias plugin > reinitialize:', ias); ias.reinitialize(); } + }else{ + // pjax.state = data.currentUrl; + if ($.pjax) { + console.log('dsa'); + // $.pjax({url: url, container: '#pjax-catalog', timeout: false, state: data.currentUrl}); + // $.pjax.reload('#pjax-sales', {url: url,timeout:false,state:data.currentUrl}) + } } + + }, beforeSend: function () { ajaxSelector.toggleClass('loading');