Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
andrtechno committed Aug 20, 2021
1 parent 54e3e91 commit 8200ccb
Show file tree
Hide file tree
Showing 30 changed files with 363 additions and 775 deletions.
39 changes: 29 additions & 10 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/<slug:[0-9a-zA-Z_\-]+>'
Expand All @@ -149,10 +150,12 @@ public function bootstrap($app)
// 'pattern' => ''
];*/

// $rules['sales/page/<page:\d+>/per-page/<per-page:\d+>'] = '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',
Expand All @@ -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',
Expand All @@ -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/<page:\d+>/per-page/<per-page:\d+>',
];
$rules['sales/page/<page:\d+>'] = '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'
Expand Down Expand Up @@ -216,6 +233,8 @@ public function bootstrap($app)
'currency' => ['class' => 'panix\mod\shop\components\CurrencyManager'],
]);



}

public function getAllPaths()
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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/*')
],
[
Expand Down
8 changes: 5 additions & 3 deletions assets/js/product.view.configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -64,7 +64,7 @@ $('.eavData:last').change(function () {
$('#configurable_id').val(productId);
}

recalculateProductPrice();
recalculateProductPrice(this);
});


Expand Down Expand Up @@ -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);
Expand Down
101 changes: 101 additions & 0 deletions commands/SitemapController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace panix\mod\shop\commands;

use panix\engine\console\controllers\ConsoleController;
use Yii;
use yii\console\ExitCode;
use yii\helpers\Console;

/**
* Generate sitemap for shop
*
* @package panix\mod\shop\commands
*/
class SitemapController extends ConsoleController
{

/**
* @var string folder for sitemaps files
*/
public $rootDir = '@runtime';

/**
* @var string sitemap main file name
*/
public $sitemapFile = 'sitemap-shop.xml';
public $sitemapFileJson = 'sitemap.json';

/**
* @inheritdoc
*/
public function options($actionID)
{
return array_merge(parent::options($actionID), ['rootDir', 'sitemapFile']);
}

/**
* Generate sitemap.xml file
*
* @access public
* @return integer
*/
public function actionIndex()
{

$file = Yii::getAlias($this->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;
}
}
90 changes: 0 additions & 90 deletions components/BaseTestUrlRule.php

This file was deleted.

Loading

0 comments on commit 8200ccb

Please sign in to comment.