Commit 8a7e6ecfc649172519d975876d4b5c4da0135b89
1 parent
0ea99bc1
Namespaces
Showing
58 changed files
with
2086 additions
and
121 deletions
Show diff stats
1 | +<?php | ||
2 | + namespace artweb\artbox\ecommerce\behaviors; | ||
3 | + | ||
4 | + use artweb\artbox\language\models\Language; | ||
5 | + use artweb\artbox\ecommerce\models\ProductVariantLang; | ||
6 | + use yii\base\Behavior; | ||
7 | + use artweb\artbox\ecommerce\models\Product; | ||
8 | + use artweb\artbox\ecommerce\models\ProductVariant; | ||
9 | + use artweb\artbox\ecommerce\models\ProductUnit; | ||
10 | + use artweb\artbox\ecommerce\models\ProductStock; | ||
11 | + use artweb\artbox\ecommerce\models\Stock; | ||
12 | + | ||
13 | + /** | ||
14 | + * Class DefaultVariantBehavior | ||
15 | + * | ||
16 | + * @package common/behaviors | ||
17 | + * @property Product $owner | ||
18 | + * @see ProductVariant | ||
19 | + */ | ||
20 | + class DefaultVariantBehavior extends Behavior | ||
21 | + { | ||
22 | + | ||
23 | + /** | ||
24 | + * @todo add default variant image also | ||
25 | + */ | ||
26 | + | ||
27 | + /** | ||
28 | + * Catches product's insert event | ||
29 | + * | ||
30 | + * @return array | ||
31 | + */ | ||
32 | + public function events() | ||
33 | + { | ||
34 | + return [ | ||
35 | + Product::EVENT_AFTER_INSERT => 'addDefaultVariant', | ||
36 | + ]; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * Creates new default product's variant and sets it's to stock | ||
41 | + * marked as default and sets to it unit also marked as default | ||
42 | + */ | ||
43 | + public function addDefaultVariant() | ||
44 | + { | ||
45 | + /** | ||
46 | + * @var Stock $stock | ||
47 | + * @var ProductUnit $defaultUnit | ||
48 | + */ | ||
49 | + $defaultVariant = new ProductVariant(); | ||
50 | + $defaultVariant->product_id = $this->owner->id; | ||
51 | + | ||
52 | + /** | ||
53 | + * Gets default unit for variant | ||
54 | + */ | ||
55 | + $defaultUnit = ProductUnit::find() | ||
56 | + ->where( | ||
57 | + [ | ||
58 | + 'is_default' => true, | ||
59 | + ] | ||
60 | + ) | ||
61 | + ->one(); | ||
62 | + $defaultVariant->product_unit_id = $defaultUnit->id; | ||
63 | + $defaultVariant->stock = 1; | ||
64 | + | ||
65 | + $defaultVariant->sku = 'default'; | ||
66 | + $defaultVariant->remote_id = time(); | ||
67 | + $defaultVariant->save(); | ||
68 | + | ||
69 | + /** | ||
70 | + * Saving languages | ||
71 | + */ | ||
72 | + $activeLanguageIds = Language::find() | ||
73 | + ->select('id') | ||
74 | + ->where( | ||
75 | + [ | ||
76 | + 'status' => true, | ||
77 | + ] | ||
78 | + ) | ||
79 | + ->asArray() | ||
80 | + ->column(); | ||
81 | + foreach ($activeLanguageIds as $languageId) { | ||
82 | + $variantLanguage = new ProductVariantLang(); | ||
83 | + $variantLanguage->language_id = $languageId; | ||
84 | + $variantLanguage->product_variant_id = $defaultVariant->id; | ||
85 | + $variantLanguage->title = 'default_' . $languageId; | ||
86 | + $variantLanguage->save(); | ||
87 | + } | ||
88 | + /** | ||
89 | + * Gets default stock | ||
90 | + */ | ||
91 | + $stock = Stock::find() | ||
92 | + ->one(); | ||
93 | + | ||
94 | + // $image = ProductImage::find() | ||
95 | + // ->where( | ||
96 | + // [ | ||
97 | + // 'product_id' => $this->owner->product_id, | ||
98 | + // ] | ||
99 | + // ) | ||
100 | + // ->one(); | ||
101 | + // $image->product_variant_id = $defaultVariant->product_variant_id; | ||
102 | + // $image->save(); | ||
103 | + | ||
104 | + /** | ||
105 | + * Add a new stock record | ||
106 | + */ | ||
107 | + $defaultStock = new ProductStock(); | ||
108 | + $defaultStock->product_variant_id = $defaultVariant->id; | ||
109 | + $defaultStock->stock_id = $stock->id; | ||
110 | + $defaultStock->quantity = $defaultVariant->stock; | ||
111 | + $defaultStock->save(); | ||
112 | + } | ||
113 | + | ||
114 | + } | ||
115 | + | ||
0 | \ No newline at end of file | 116 | \ No newline at end of file |
behaviors/FilterBehavior.php
@@ -12,7 +12,6 @@ | @@ -12,7 +12,6 @@ | ||
12 | 12 | ||
13 | public function getFilters() | 13 | public function getFilters() |
14 | { | 14 | { |
15 | - | ||
16 | /** | 15 | /** |
17 | * @var ActiveRecord $owner | 16 | * @var ActiveRecord $owner |
18 | */ | 17 | */ |
@@ -23,4 +22,5 @@ | @@ -23,4 +22,5 @@ | ||
23 | ->all(); | 22 | ->all(); |
24 | } | 23 | } |
25 | 24 | ||
26 | - } | ||
27 | \ No newline at end of file | 25 | \ No newline at end of file |
26 | + } | ||
27 | + | ||
28 | \ No newline at end of file | 28 | \ No newline at end of file |
composer.json
@@ -5,7 +5,12 @@ | @@ -5,7 +5,12 @@ | ||
5 | "require": { | 5 | "require": { |
6 | "php": ">=7.0", | 6 | "php": ">=7.0", |
7 | "yiisoft/yii2": "*", | 7 | "yiisoft/yii2": "*", |
8 | - "developeruz/yii2-db-rbac": "*" | 8 | + "developeruz/yii2-db-rbac": "*", |
9 | + "artweb/artbox": "dev-master", | ||
10 | + "artweb/artbox/language": "dev-master", | ||
11 | + "yiisoft/yii2-faker": "*", | ||
12 | + "artweb/artbox/seo": "dev-master", | ||
13 | + "wbraganca/yii2-dynamicform": "dev-master" | ||
9 | }, | 14 | }, |
10 | "autoload": { | 15 | "autoload": { |
11 | "psr-4": { | 16 | "psr-4": { |
1 | +<?php | ||
2 | + | ||
3 | + namespace console\controllers; | ||
4 | + | ||
5 | + use artweb\artbox\ecommerce\models\Brand; | ||
6 | + use artweb\artbox\ecommerce\models\Category; | ||
7 | + use artweb\artbox\ecommerce\models\Product; | ||
8 | + use artweb\artbox\ecommerce\models\ProductVariant; | ||
9 | + use artweb\artbox\ecommerce\models\TaxGroup; | ||
10 | + use artweb\artbox\ecommerce\models\TaxOption; | ||
11 | + use Faker\Factory; | ||
12 | + use Faker\Generator; | ||
13 | + use yii\console\Controller; | ||
14 | + use yii\helpers\Console; | ||
15 | + | ||
16 | + /** | ||
17 | + * Class GenerateController to generate ArtBox fake data | ||
18 | + * | ||
19 | + * @package console\controllers | ||
20 | + */ | ||
21 | + class GenerateController extends Controller | ||
22 | + { | ||
23 | + /** | ||
24 | + * Faker Generator locales | ||
25 | + * | ||
26 | + * @var array | ||
27 | + */ | ||
28 | + private $locales = [ | ||
29 | + 2 => 'ru_RU', | ||
30 | + 3 => 'uk_UA', | ||
31 | + ]; | ||
32 | + | ||
33 | + /** | ||
34 | + * Faker Generators instances | ||
35 | + * | ||
36 | + * @var Generator[] $fakers | ||
37 | + */ | ||
38 | + private $fakers = []; | ||
39 | + | ||
40 | + /** | ||
41 | + * Create faker Generators for all $locales | ||
42 | + * | ||
43 | + * @param \yii\base\Action $action | ||
44 | + * | ||
45 | + * @return bool | ||
46 | + */ | ||
47 | + public function beforeAction($action) | ||
48 | + { | ||
49 | + $parent = parent::beforeAction($action); | ||
50 | + $fakers = []; | ||
51 | + foreach ($this->locales as $locale_id => $locale) { | ||
52 | + $fakers[ $locale_id ] = Factory::create($locale); | ||
53 | + } | ||
54 | + $this->fakers = $fakers; | ||
55 | + return $parent; | ||
56 | + } | ||
57 | + | ||
58 | + /** | ||
59 | + * Generate fake Brands | ||
60 | + * | ||
61 | + * @param int $count Brands count | ||
62 | + * | ||
63 | + * @return int | ||
64 | + */ | ||
65 | + public function actionBrand(int $count = 10): int | ||
66 | + { | ||
67 | + /** | ||
68 | + * @var Brand[] $models | ||
69 | + */ | ||
70 | + $models = []; | ||
71 | + $fakers = $this->fakers; | ||
72 | + for ($i = 0; $i < $count; $i++) { | ||
73 | + $models[ $i ] = \Yii::createObject(Brand::className()); | ||
74 | + $models[ $i ]->generateLangs(); | ||
75 | + foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { | ||
76 | + $modelLang->title = $fakers[ $language_id ]->company; | ||
77 | + } | ||
78 | + if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { | ||
79 | + $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); | ||
80 | + $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); | ||
81 | + echo "Brand '$title' inserted under $id ID.\n"; | ||
82 | + }; | ||
83 | + } | ||
84 | + return 0; | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * Generate fake categories | ||
89 | + * | ||
90 | + * @param int $count Category count | ||
91 | + * | ||
92 | + * @return int | ||
93 | + */ | ||
94 | + public function actionCategory(int $count = 10):int | ||
95 | + { | ||
96 | + /** | ||
97 | + * @var Category[] $models | ||
98 | + */ | ||
99 | + $models = []; | ||
100 | + $fakers = $this->fakers; | ||
101 | + for ($i = 0; $i < $count; $i++) { | ||
102 | + $models[ $i ] = \Yii::createObject( | ||
103 | + [ | ||
104 | + 'class' => Category::className(), | ||
105 | + 'depth' => 0, | ||
106 | + 'parent_id' => 0, | ||
107 | + ] | ||
108 | + ); | ||
109 | + $models[ $i ]->generateLangs(); | ||
110 | + foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { | ||
111 | + $modelLang->title = ucfirst($fakers[ $language_id ]->word); | ||
112 | + } | ||
113 | + if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { | ||
114 | + $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); | ||
115 | + $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); | ||
116 | + echo "Category '$title' inserted under $id ID.\n"; | ||
117 | + }; | ||
118 | + } | ||
119 | + return 0; | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Generate fake products with variants, categories and tax options | ||
124 | + * | ||
125 | + * @param int $count Product count | ||
126 | + * | ||
127 | + * @return int | ||
128 | + */ | ||
129 | + public function actionProduct(int $count = 10):int | ||
130 | + { | ||
131 | + /** | ||
132 | + * @var Product[] $models | ||
133 | + */ | ||
134 | + $models = []; | ||
135 | + $fakers = $this->fakers; | ||
136 | + $brands = Brand::find() | ||
137 | + ->limit(20) | ||
138 | + ->asArray() | ||
139 | + ->column(); | ||
140 | + $categories = Category::find() | ||
141 | + ->limit(100) | ||
142 | + ->asArray() | ||
143 | + ->column(); | ||
144 | + $product_options = TaxOption::find() | ||
145 | + ->joinWith('taxGroup') | ||
146 | + ->where([ 'tax_group.level' => TaxGroup::GROUP_PRODUCT ]) | ||
147 | + ->limit(50) | ||
148 | + ->asArray() | ||
149 | + ->column(); | ||
150 | + $variant_options = TaxOption::find() | ||
151 | + ->joinWith('taxGroup') | ||
152 | + ->where([ 'tax_group.level' => TaxGroup::GROUP_VARIANT ]) | ||
153 | + ->limit(50) | ||
154 | + ->asArray() | ||
155 | + ->column(); | ||
156 | + for ($i = 0; $i < $count; $i++) { | ||
157 | + $models[ $i ] = \Yii::createObject( | ||
158 | + [ | ||
159 | + 'class' => Product::className(), | ||
160 | + 'brand_id' => $fakers[ 2 ]->randomElement($brands), | ||
161 | + ] | ||
162 | + ); | ||
163 | + $models[ $i ]->setCategories( | ||
164 | + $fakers[ 2 ]->randomElements($categories, $fakers[ 2 ]->randomDigitNotNull) | ||
165 | + ); | ||
166 | + $models[ $i ]->setOptions( | ||
167 | + $fakers[ 2 ]->randomElements($product_options, $fakers[ 2 ]->randomDigitNotNull) | ||
168 | + ); | ||
169 | + $models[ $i ]->generateLangs(); | ||
170 | + foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { | ||
171 | + $modelLang->title = ucfirst($fakers[ $language_id ]->word); | ||
172 | + } | ||
173 | + if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { | ||
174 | + $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); | ||
175 | + $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); | ||
176 | + echo "Product '$title' inserted under $id ID.\n"; | ||
177 | + $variant_count = $fakers[ 2 ]->numberBetween(4, 10); | ||
178 | + for ($j = 0; $j < $variant_count; $j++) { | ||
179 | + /** | ||
180 | + * @var ProductVariant $variant | ||
181 | + */ | ||
182 | + $variant = \Yii::createObject( | ||
183 | + [ | ||
184 | + 'class' => ProductVariant::className(), | ||
185 | + 'product_id' => $models[ $i ]->id, | ||
186 | + 'sku' => $fakers[ 2 ]->uuid, | ||
187 | + 'price' => $fakers[ 2 ]->randomFloat(2, 100, 10000), | ||
188 | + 'stock' => 10, | ||
189 | + 'product_unit_id' => 1, | ||
190 | + ] | ||
191 | + ); | ||
192 | + $variant->setOptions( | ||
193 | + $fakers[ 2 ]->randomElements($variant_options, $fakers[ 2 ]->randomDigitNotNull) | ||
194 | + ); | ||
195 | + $variant->generateLangs(); | ||
196 | + foreach ($variant->modelLangs as $variant_language_id => $variantLang) { | ||
197 | + $variantLang->title = ucfirst($fakers[ $variant_language_id ]->word); | ||
198 | + } | ||
199 | + if ($variant->save() && $variant->transactionStatus) { | ||
200 | + $variant_title = $this->ansiFormat($variant->modelLangs[ 2 ]->title, Console::FG_YELLOW); | ||
201 | + $variant_id = $this->ansiFormat($variant->id, Console::FG_YELLOW); | ||
202 | + echo "Variant '$variant_title' inserted under $variant_id ID for product $title.\n"; | ||
203 | + } | ||
204 | + } | ||
205 | + }; | ||
206 | + } | ||
207 | + return 0; | ||
208 | + } | ||
209 | + | ||
210 | + /** | ||
211 | + * Generate fake tax groups with tax options. | ||
212 | + * | ||
213 | + * @param int $count_product Tax Groups for Product | ||
214 | + * @param int $count_variant Tax Groups for ProductVariant | ||
215 | + * | ||
216 | + * @return int | ||
217 | + */ | ||
218 | + public function actionTax(int $count_product = 10, int $count_variant = 10):int | ||
219 | + { | ||
220 | + $categories = Category::find() | ||
221 | + ->asArray() | ||
222 | + ->column(); | ||
223 | + $this->generateTax(TaxGroup::GROUP_PRODUCT, $count_product, $categories); | ||
224 | + $this->generateTax(TaxGroup::GROUP_VARIANT, $count_variant, $categories); | ||
225 | + return 0; | ||
226 | + } | ||
227 | + | ||
228 | + /** | ||
229 | + * Generates tax groups amd tax options for actionTax | ||
230 | + * | ||
231 | + * @param int $level Tax Group for Product or ProductVariant | ||
232 | + * @param int $count Tax Group count | ||
233 | + * @param array $categories Categories for Tax Groups | ||
234 | + * | ||
235 | + * @see GenerateController::actionTax() | ||
236 | + */ | ||
237 | + private function generateTax(int $level, int $count, array $categories = []) | ||
238 | + { | ||
239 | + $count_option = 10; | ||
240 | + $fakers = $this->fakers; | ||
241 | + /** | ||
242 | + * @var TaxGroup[] $models | ||
243 | + */ | ||
244 | + $models = []; | ||
245 | + for ($i = 0; $i < $count; $i++) { | ||
246 | + $models[ $i ] = \Yii::createObject( | ||
247 | + [ | ||
248 | + 'class' => TaxGroup::className(), | ||
249 | + 'is_filter' => true, | ||
250 | + 'display' => true, | ||
251 | + ] | ||
252 | + ); | ||
253 | + $models[ $i ]->level = $level; | ||
254 | + $models[ $i ]->setCategories($categories); | ||
255 | + $models[ $i ]->generateLangs(); | ||
256 | + foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) { | ||
257 | + $modelLang->title = ucfirst($fakers[ $language_id ]->word); | ||
258 | + } | ||
259 | + if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) { | ||
260 | + for ($j = 0; $j < $count_option; $j++) { | ||
261 | + /** | ||
262 | + * @var TaxOption $option | ||
263 | + */ | ||
264 | + $option = \Yii::createObject( | ||
265 | + TaxOption::className() | ||
266 | + ); | ||
267 | + $option->tax_group_id = $models[ $i ]->id; | ||
268 | + $option->generateLangs(); | ||
269 | + foreach ($option->modelLangs as $option_language_id => $taxOptionLang) { | ||
270 | + $taxOptionLang->value = ucfirst($fakers[ $option_language_id ]->word); | ||
271 | + } | ||
272 | + $option->save(); | ||
273 | + } | ||
274 | + $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW); | ||
275 | + $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW); | ||
276 | + $element = $this->ansiFormat( | ||
277 | + ( $level === TaxGroup::GROUP_PRODUCT ) ? 'Product' : 'Variant', | ||
278 | + Console::FG_RED | ||
279 | + ); | ||
280 | + echo "Category '$title' inserted for $element under $id ID.\n"; | ||
281 | + }; | ||
282 | + } | ||
283 | + } | ||
284 | + } | ||
285 | + | ||
0 | \ No newline at end of file | 286 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | +namespace console\controllers; | ||
4 | + | ||
5 | +use artweb\artbox\ecommerce\models\Import; | ||
6 | +use Yii; | ||
7 | +use yii\console\Controller; | ||
8 | + | ||
9 | +/** | ||
10 | + * Class ImportController | ||
11 | + * | ||
12 | + * @todo Refactor | ||
13 | + * | ||
14 | + * @package console\controllers | ||
15 | + */ | ||
16 | +class ImportController extends Controller { | ||
17 | + public $errors = []; | ||
18 | + | ||
19 | + | ||
20 | + private function getProductsFile($file_type = 'uploadFileProducts') { | ||
21 | + $filename = Yii::getAlias('@uploadDir') .'/'. Yii::getAlias('@'. $file_type); | ||
22 | + if (!is_file($filename)) { | ||
23 | + $this->stderr('Task already executed'); | ||
24 | + return Controller::EXIT_CODE_ERROR; | ||
25 | + } | ||
26 | + return fopen ($filename, 'r'); | ||
27 | + } | ||
28 | + | ||
29 | + public function actionProducts() { | ||
30 | +// if (file_exists(Yii::getAlias('@uploadDir/goProducts.lock'))) { | ||
31 | +// $this->errors[] = 'Task already executed'; | ||
32 | +// return Controller::EXIT_CODE_ERROR; | ||
33 | +// } | ||
34 | +// $ff = fopen(Yii::getAlias('@uploadDir/goProducts.lock'), 'w+'); | ||
35 | +// fclose($ff); | ||
36 | + $model = new Import(); | ||
37 | + $model->goProducts(0, null); | ||
38 | +// unlink(Yii::getAlias('@uploadDir/goProducts.lock')); | ||
39 | + return Controller::EXIT_CODE_NORMAL; | ||
40 | + } | ||
41 | + | ||
42 | + public function actionPrices() { | ||
43 | + if (file_exists(Yii::getAlias('@uploadDir/goPrices.lock'))) { | ||
44 | + $this->stderr('Task already executed'); | ||
45 | + return Controller::EXIT_CODE_ERROR; | ||
46 | + } | ||
47 | + $ff = fopen(Yii::getAlias('@uploadDir/goPrices.lock'), 'w+'); | ||
48 | + fclose($ff); | ||
49 | + $model = new Import(); | ||
50 | + $data = $model->goPrices(0, null); | ||
51 | + unlink(Yii::getAlias('@uploadDir/goPrices.lock')); | ||
52 | + return Controller::EXIT_CODE_NORMAL; | ||
53 | + } | ||
54 | + | ||
55 | + private function saveNotFoundRecord (array $line, $filename) | ||
56 | + { | ||
57 | + $str = implode (';', $line)."\n"; | ||
58 | + $str = iconv ("UTF-8//TRANSLIT//IGNORE", "windows-1251", $str); | ||
59 | + | ||
60 | + $fg = fopen (Yii::getAlias('@uploadDir') .'/'. $filename, 'a+'); | ||
61 | + fputs ($fg, $str); | ||
62 | + fclose ($fg); | ||
63 | + } | ||
64 | +} | ||
0 | \ No newline at end of file | 65 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + namespace console\controllers; | ||
4 | + | ||
5 | + use artweb\artbox\seo\models\Seo; | ||
6 | + use artweb\artbox\ecommerce\models\Category; | ||
7 | + use artweb\artbox\ecommerce\models\Product; | ||
8 | + use artweb\artbox\ecommerce\models\ProductFrontendSearch; | ||
9 | + use Yii; | ||
10 | + use artweb\artbox\models\Page; | ||
11 | + use yii\helpers\ArrayHelper; | ||
12 | + use yii\helpers\Url; | ||
13 | + use yii\console\Controller; | ||
14 | + | ||
15 | + /** | ||
16 | + * PageController implements the CRUD actions for Page model. | ||
17 | + */ | ||
18 | + class SiteMapController extends Controller | ||
19 | + { | ||
20 | + | ||
21 | + private $urlList = [ 'http://www.rukzachok.com.ua/' ]; | ||
22 | + private $count = 1; | ||
23 | + | ||
24 | + public function checkFilter($category, $filter) | ||
25 | + { | ||
26 | + $productModel = new ProductFrontendSearch(); | ||
27 | + $productProvider = $productModel->search($category, $filter); | ||
28 | + if (!empty( $productProvider->models )) { | ||
29 | + return true; | ||
30 | + } else { | ||
31 | + return false; | ||
32 | + } | ||
33 | + } | ||
34 | + | ||
35 | + public function getAddStatic() | ||
36 | + { | ||
37 | + return [ | ||
38 | + 'http://www.rukzachok.com.ua', | ||
39 | + 'http://www.rukzachok.com.ua/catalog', | ||
40 | + ]; | ||
41 | + } | ||
42 | + | ||
43 | + public function getProducts() | ||
44 | + { | ||
45 | + return Product::find() | ||
46 | + ->all(); | ||
47 | + | ||
48 | + } | ||
49 | + | ||
50 | + public function getSeoLinks() | ||
51 | + { | ||
52 | + return Seo::find() | ||
53 | + ->where([ 'meta' => '' ]) | ||
54 | + ->all(); | ||
55 | + | ||
56 | + } | ||
57 | + | ||
58 | + public function getStaticPages() | ||
59 | + { | ||
60 | + return Page::find() | ||
61 | + ->all(); | ||
62 | + } | ||
63 | + | ||
64 | + public function getCategories() | ||
65 | + { | ||
66 | + return Category::find() | ||
67 | + ->all(); | ||
68 | + } | ||
69 | + | ||
70 | + public function getBrands($category) | ||
71 | + { | ||
72 | + | ||
73 | + return $category->brands; | ||
74 | + } | ||
75 | + | ||
76 | + /** | ||
77 | + * @param $category Category; | ||
78 | + * | ||
79 | + * @return mixed | ||
80 | + */ | ||
81 | + | ||
82 | + public function getFilters($category) | ||
83 | + { | ||
84 | + | ||
85 | + return $category->getActiveFilters() | ||
86 | + ->all(); | ||
87 | + | ||
88 | + } | ||
89 | + | ||
90 | + public function checkUrl($url) | ||
91 | + { | ||
92 | + if (!in_array($url, $this->urlList)) { | ||
93 | + $this->urlList[] = $url; | ||
94 | + return true; | ||
95 | + } else { | ||
96 | + return false; | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + public function createRow($url, $priority, &$content) | ||
101 | + { | ||
102 | + if ($this->checkUrl($url)) { | ||
103 | + print $this->count++ . "\n"; | ||
104 | + $content .= '<url>' . '<loc>' . $url . '</loc>' . '<lastmod>' . date( | ||
105 | + 'Y-m-d' | ||
106 | + ) . '</lastmod>' . '<changefreq>Daily</changefreq>' . '<priority>' . $priority . '</priority>' . '</url>'; | ||
107 | + } | ||
108 | + } | ||
109 | + | ||
110 | + public function actionProcess() | ||
111 | + { | ||
112 | + | ||
113 | + $config = ArrayHelper::merge( | ||
114 | + require( \Yii::getAlias('@frontend/config/') . 'main.php' ), | ||
115 | + require( \Yii::getAlias('@common/config/') . 'main.php' ) | ||
116 | + ); | ||
117 | + | ||
118 | + Yii::$app->urlManager->addRules($config[ 'components' ][ 'urlManager' ][ 'rules' ]); | ||
119 | + | ||
120 | + $dirName = Yii::getAlias('@frontend') . '/web'; | ||
121 | + | ||
122 | + $filename = 'sitemap.xml'; | ||
123 | + | ||
124 | + setlocale(LC_ALL, 'ru_RU.CP1251'); | ||
125 | + $handle = fopen($dirName . '/' . $filename, "w"); | ||
126 | + | ||
127 | + $content = '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'; | ||
128 | + | ||
129 | + foreach ($this->getAddStatic() as $page) { | ||
130 | + $this->createRow($page, 1, $content); | ||
131 | + } | ||
132 | + | ||
133 | + foreach ($this->getStaticPages() as $page) { | ||
134 | + $url = Url::to( | ||
135 | + [ | ||
136 | + 'text/index', | ||
137 | + 'translit' => $page->translit, | ||
138 | + ] | ||
139 | + ); | ||
140 | + $this->createRow($url, 1, $content); | ||
141 | + } | ||
142 | + | ||
143 | + foreach ($this->getCategories() as $category) { | ||
144 | + $url = Url::to( | ||
145 | + [ | ||
146 | + 'catalog/category', | ||
147 | + 'category' => $category, | ||
148 | + ] | ||
149 | + ); | ||
150 | + $this->createRow($url, 1, $content); | ||
151 | + } | ||
152 | + | ||
153 | + foreach ($this->getProducts() as $product) { | ||
154 | + | ||
155 | + $url = Url::to( | ||
156 | + [ | ||
157 | + 'catalog/product', | ||
158 | + 'product' => $product, | ||
159 | + ] | ||
160 | + ); | ||
161 | + $this->createRow($url, 0.9, $content); | ||
162 | + } | ||
163 | + | ||
164 | + // foreach ($this->getArticles() as $article) { | ||
165 | + // | ||
166 | + // $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]); | ||
167 | + // $this->createRow($url , 0.8,$content); | ||
168 | + // | ||
169 | + // } | ||
170 | + | ||
171 | + foreach ($this->getCategories() as $category) { | ||
172 | + foreach ($this->getBrands($category) as $brand) { | ||
173 | + if ($this->checkFilter($category, [ 'brands' => [ $brand->id ] ])) { | ||
174 | + $url = Url::to( | ||
175 | + [ | ||
176 | + 'catalog/category', | ||
177 | + 'category' => $category, | ||
178 | + 'filters' => [ 'brands' => [ $brand->alias ] ], | ||
179 | + ] | ||
180 | + ); | ||
181 | + $this->createRow($url, 0.8, $content); | ||
182 | + } | ||
183 | + } | ||
184 | + } | ||
185 | + | ||
186 | + foreach ($this->getCategories() as $category) { | ||
187 | + foreach ($this->getFilters($category) as $filter) { | ||
188 | + if ($this->checkFilter($category, [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ])) { | ||
189 | + $url = Url::to( | ||
190 | + [ | ||
191 | + 'catalog/category', | ||
192 | + 'category' => $category, | ||
193 | + 'filters' => [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ], | ||
194 | + ] | ||
195 | + ); | ||
196 | + $this->createRow($url, 0.8, $content); | ||
197 | + } | ||
198 | + | ||
199 | + } | ||
200 | + } | ||
201 | + | ||
202 | + foreach ($this->getSeoLinks() as $link) { | ||
203 | + $url = Yii::$app->urlManager->baseUrl . $link->url; | ||
204 | + $this->createRow($url, 0.7, $content); | ||
205 | + | ||
206 | + } | ||
207 | + | ||
208 | + // foreach($this->getCategories() as $category){ | ||
209 | + // foreach ($this->getFilters($category) as $filter1) { | ||
210 | + // foreach ($this->getFilters($category) as $filter2) { | ||
211 | + // if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){ | ||
212 | + // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]); | ||
213 | + // $this->createRow($url , 0.7, $content); | ||
214 | + // } | ||
215 | + // | ||
216 | + // } | ||
217 | + // | ||
218 | + // foreach ($this->getBrands($category) as $brand) { | ||
219 | + // if($this->checkFilter($category, ['brands' => [$brand->id], $filter1['group_alias'] => [$filter1['option_alias']]] )){ | ||
220 | + // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]); | ||
221 | + // $this->createRow($url , 0.7,$content); | ||
222 | + // } | ||
223 | + // | ||
224 | + // } | ||
225 | + // } | ||
226 | + // } | ||
227 | + | ||
228 | + $content .= '</urlset>'; | ||
229 | + | ||
230 | + fwrite($handle, $content); | ||
231 | + fclose($handle); | ||
232 | + | ||
233 | + print $dirName . '/' . $filename; | ||
234 | + } | ||
235 | + | ||
236 | + } |
controllers/ManageController.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\controllers; | 3 | namespace artweb\artbox\ecommerce\controllers; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use artweb\artbox\ecommerce\models\Export; | 6 | use artweb\artbox\ecommerce\models\Export; |
7 | use artweb\artbox\ecommerce\models\Import; | 7 | use artweb\artbox\ecommerce\models\Import; |
8 | use artweb\artbox\ecommerce\models\ProductImage; | 8 | use artweb\artbox\ecommerce\models\ProductImage; |
controllers/TaxGroupController.php
@@ -5,7 +5,6 @@ | @@ -5,7 +5,6 @@ | ||
5 | use artweb\artbox\ecommerce\models\TaxGroupSearch; | 5 | use artweb\artbox\ecommerce\models\TaxGroupSearch; |
6 | use Yii; | 6 | use Yii; |
7 | use artweb\artbox\ecommerce\models\TaxGroup; | 7 | use artweb\artbox\ecommerce\models\TaxGroup; |
8 | - use yii\data\ActiveDataProvider; | ||
9 | use yii\db\ActiveQuery; | 8 | use yii\db\ActiveQuery; |
10 | use yii\web\Controller; | 9 | use yii\web\Controller; |
11 | use yii\web\NotFoundHttpException; | 10 | use yii\web\NotFoundHttpException; |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | + use yii\base\Component; | ||
6 | + use yii\web\NotFoundHttpException; | ||
7 | + | ||
8 | + /** | ||
9 | + * Class Basket to work with basket | ||
10 | + * | ||
11 | + * @package artweb\artbox\ecommerce\models | ||
12 | + */ | ||
13 | + class Basket extends Component | ||
14 | + { | ||
15 | + /** | ||
16 | + * Session object | ||
17 | + * | ||
18 | + * @var \yii\web\Session | ||
19 | + */ | ||
20 | + public $session; | ||
21 | + | ||
22 | + /** | ||
23 | + * Basket constructor. | ||
24 | + * Check for basket variable in session and set it to empty array if not exist. | ||
25 | + * | ||
26 | + * @param array $config | ||
27 | + */ | ||
28 | + public function __construct(array $config = []) | ||
29 | + { | ||
30 | + $this->session = \Yii::$app->session; | ||
31 | + if (!$this->session->has('basket')) { | ||
32 | + $this->session->set('basket', []); | ||
33 | + } | ||
34 | + parent::__construct($config); | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Increment product variant with $product_variant_id count by 1 | ||
39 | + * | ||
40 | + * @param int $product_variant_id | ||
41 | + */ | ||
42 | + public function add(int $product_variant_id) | ||
43 | + { | ||
44 | + $data = $this->getData(); | ||
45 | + if (array_key_exists($product_variant_id, $data)) { | ||
46 | + if ($data[ $product_variant_id ][ 'count' ] <= 0) { | ||
47 | + $data[ $product_variant_id ] = 1; | ||
48 | + } else { | ||
49 | + $data[ $product_variant_id ][ 'count' ] += 1; | ||
50 | + } | ||
51 | + } else { | ||
52 | + if ($this->findModel($product_variant_id)) { | ||
53 | + $data[ $product_variant_id ] = [ | ||
54 | + 'count' => 1, | ||
55 | + ]; | ||
56 | + } | ||
57 | + } | ||
58 | + $this->setData($data); | ||
59 | + } | ||
60 | + | ||
61 | + /** | ||
62 | + * Set product variant with $product_variant_id to $count | ||
63 | + * | ||
64 | + * @param int $product_variant_id | ||
65 | + * @param int $count | ||
66 | + */ | ||
67 | + private function set(int $product_variant_id, int $count) | ||
68 | + { | ||
69 | + $data = $this->getData(); | ||
70 | + if (array_key_exists($product_variant_id, $data)) { | ||
71 | + $data[ $product_variant_id ][ 'count' ] = $count; | ||
72 | + if ($data[ $product_variant_id ][ 'count' ] <= 0) { | ||
73 | + unset( $data[ $product_variant_id ] ); | ||
74 | + } | ||
75 | + } elseif ($count > 0) { | ||
76 | + if ($this->findModel($product_variant_id)) { | ||
77 | + $data[ $product_variant_id ] = [ | ||
78 | + 'count' => $count, | ||
79 | + ]; | ||
80 | + } | ||
81 | + } | ||
82 | + $this->setData($data); | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Delete product variant with $product_variant_id from basket | ||
87 | + * | ||
88 | + * @param int $product_variant_id | ||
89 | + */ | ||
90 | + public function delete(int $product_variant_id) | ||
91 | + { | ||
92 | + $this->set($product_variant_id, 0); | ||
93 | + } | ||
94 | + | ||
95 | + /** | ||
96 | + * Get basket data | ||
97 | + * | ||
98 | + * @return array | ||
99 | + */ | ||
100 | + public function getData(): array | ||
101 | + { | ||
102 | + return $this->session->get('basket'); | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * Get basket item with $product_variant_id. Returns false if item not in basket. | ||
107 | + * | ||
108 | + * @param int $product_variant_id | ||
109 | + * | ||
110 | + * @return bool|array | ||
111 | + */ | ||
112 | + public function getItem(int $product_variant_id) | ||
113 | + { | ||
114 | + $data = $this->getData(); | ||
115 | + if (!empty( $data[ $product_variant_id ] )) { | ||
116 | + return $data[ $product_variant_id ]; | ||
117 | + } else { | ||
118 | + return false; | ||
119 | + } | ||
120 | + } | ||
121 | + | ||
122 | + /** | ||
123 | + * Set basket data | ||
124 | + * | ||
125 | + * @param array $data | ||
126 | + */ | ||
127 | + public function setData(array $data) | ||
128 | + { | ||
129 | + $this->session->set('basket', $data); | ||
130 | + } | ||
131 | + | ||
132 | + /** | ||
133 | + * Get count of product variants in basket | ||
134 | + * | ||
135 | + * @return int | ||
136 | + */ | ||
137 | + public function getCount(): int | ||
138 | + { | ||
139 | + $data = $this->getData(); | ||
140 | + return count($data); | ||
141 | + } | ||
142 | + | ||
143 | + /** | ||
144 | + * Find Product Variant by $product_variant_id | ||
145 | + * | ||
146 | + * @param int $product_variant_id | ||
147 | + * | ||
148 | + * @return \artweb\artbox\ecommerce\models\ProductVariant | ||
149 | + * @throws \yii\web\NotFoundHttpException | ||
150 | + */ | ||
151 | + public function findModel(int $product_variant_id): ProductVariant | ||
152 | + { | ||
153 | + /** | ||
154 | + * @var ProductVariant $model | ||
155 | + */ | ||
156 | + $model = ProductVariant::find() | ||
157 | + ->where([ 'product_variant.id' => $product_variant_id ]) | ||
158 | + ->joinWith('lang', true, 'INNER JOIN') | ||
159 | + ->one(); | ||
160 | + if (empty( $model )) { | ||
161 | + throw new NotFoundHttpException(\Yii::t('app', 'Product not found')); | ||
162 | + } else { | ||
163 | + return $model; | ||
164 | + } | ||
165 | + } | ||
166 | + | ||
167 | + /** | ||
168 | + * Find all Product Variants filtered by $product_variant_ids | ||
169 | + * | ||
170 | + * @param array $product_variant_ids | ||
171 | + * | ||
172 | + * @return ProductVariant[] | ||
173 | + */ | ||
174 | + public function findModels(array $product_variant_ids) | ||
175 | + { | ||
176 | + return ProductVariant::find() | ||
177 | + ->where([ 'product_variant.id' => $product_variant_ids ]) | ||
178 | + ->joinWith('lang', true, 'INNER JOIN') | ||
179 | + ->with( | ||
180 | + [ | ||
181 | + 'product', | ||
182 | + 'image', | ||
183 | + ] | ||
184 | + ) | ||
185 | + ->all(); | ||
186 | + } | ||
187 | + | ||
188 | + /** | ||
189 | + * Clear basket | ||
190 | + */ | ||
191 | + public function clear() | ||
192 | + { | ||
193 | + $this->setData([]); | ||
194 | + } | ||
195 | + | ||
196 | + } | ||
197 | + | ||
0 | \ No newline at end of file | 198 | \ No newline at end of file |
models/Brand.php
@@ -2,8 +2,8 @@ | @@ -2,8 +2,8 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\behaviors\SaveImgBehavior; | ||
6 | - use common\modules\language\behaviors\LanguageBehavior; | 5 | + use artweb\artbox\behaviors\SaveImgBehavior; |
6 | + use artweb\artbox\language\behaviors\LanguageBehavior; | ||
7 | use Yii; | 7 | use Yii; |
8 | use yii\db\ActiveQuery; | 8 | use yii\db\ActiveQuery; |
9 | use yii\db\ActiveRecord; | 9 | use yii\db\ActiveRecord; |
models/BrandLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 | ||
@@ -43,7 +43,7 @@ | @@ -43,7 +43,7 @@ | ||
43 | { | 43 | { |
44 | return [ | 44 | return [ |
45 | 'slug' => [ | 45 | 'slug' => [ |
46 | - 'class' => 'common\behaviors\Slug', | 46 | + 'class' => 'artweb\artbox\ecommerce\behaviors\Slug', |
47 | ], | 47 | ], |
48 | ]; | 48 | ]; |
49 | } | 49 | } |
models/Category.php
@@ -2,11 +2,10 @@ | @@ -2,11 +2,10 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\behaviors\SaveImgBehavior; | ||
6 | - use common\components\artboxtree\ArtboxTreeBehavior; | ||
7 | - use common\modules\language\behaviors\LanguageBehavior; | ||
8 | - use common\modules\language\models\Language; | ||
9 | - use artweb\artbox\ecommerce\models\TaxGroup; | 5 | + use artweb\artbox\behaviors\SaveImgBehavior; |
6 | + use artweb\artbox\components\artboxtree\ArtboxTreeBehavior; | ||
7 | + use artweb\artbox\language\behaviors\LanguageBehavior; | ||
8 | + use artweb\artbox\language\models\Language; | ||
10 | use Yii; | 9 | use Yii; |
11 | use yii\base\InvalidParamException; | 10 | use yii\base\InvalidParamException; |
12 | use yii\db\ActiveQuery; | 11 | use yii\db\ActiveQuery; |
models/CategoryLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 | ||
@@ -42,7 +42,7 @@ | @@ -42,7 +42,7 @@ | ||
42 | { | 42 | { |
43 | return [ | 43 | return [ |
44 | 'slug' => [ | 44 | 'slug' => [ |
45 | - 'class' => 'common\behaviors\Slug', | 45 | + 'class' => 'artweb\artbox\ecommerce\behaviors\Slug', |
46 | ], | 46 | ], |
47 | ]; | 47 | ]; |
48 | } | 48 | } |
models/CategoryQuery.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\components\artboxtree\ArtboxTreeQueryTrait; | 5 | + use artweb\artbox\components\artboxtree\ArtboxTreeQueryTrait; |
6 | use yii\db\ActiveQuery; | 6 | use yii\db\ActiveQuery; |
7 | 7 | ||
8 | /** | 8 | /** |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | + use artweb\artbox\language\behaviors\LanguageBehavior; | ||
6 | + use yii\db\ActiveQuery; | ||
7 | + use yii\db\ActiveRecord; | ||
8 | + use yii\web\Request; | ||
9 | + | ||
10 | + /** | ||
11 | + * Class Delivery | ||
12 | + * | ||
13 | + * @property int $id | ||
14 | + * @property int $parent_id | ||
15 | + * @property int $value | ||
16 | + * @property int $sort | ||
17 | + * @property Delivery|null $parent | ||
18 | + * * From language behavior * | ||
19 | + * @property OrderDeliveryLang $lang | ||
20 | + * @property OrderDeliveryLang[] $langs | ||
21 | + * @property OrderDeliveryLang $objectLang | ||
22 | + * @property string $ownerKey | ||
23 | + * @property string $langKey | ||
24 | + * @property OrderDeliveryLang[] $modelLangs | ||
25 | + * @property bool $transactionStatus | ||
26 | + * @method string getOwnerKey() | ||
27 | + * @method void setOwnerKey( string $value ) | ||
28 | + * @method string getLangKey() | ||
29 | + * @method void setLangKey( string $value ) | ||
30 | + * @method ActiveQuery getLangs() | ||
31 | + * @method ActiveQuery getLang( integer $language_id ) | ||
32 | + * @method OrderDeliveryLang[] generateLangs() | ||
33 | + * @method void loadLangs( Request $request ) | ||
34 | + * @method bool linkLangs() | ||
35 | + * @method bool saveLangs() | ||
36 | + * @method bool getTransactionStatus() | ||
37 | + * * End language behavior * | ||
38 | + */ | ||
39 | + class Delivery extends ActiveRecord | ||
40 | + { | ||
41 | + | ||
42 | + public function behaviors() | ||
43 | + { | ||
44 | + return [ | ||
45 | + 'language' => [ | ||
46 | + 'class' => LanguageBehavior::className(), | ||
47 | + 'objectLang' => OrderDeliveryLang::className(), | ||
48 | + 'ownerKey' => 'id', | ||
49 | + 'langKey' => 'order_delivery_id', | ||
50 | + ], | ||
51 | + ]; | ||
52 | + } | ||
53 | + | ||
54 | + public static function tableName() | ||
55 | + { | ||
56 | + return 'order_delivery'; | ||
57 | + } | ||
58 | + | ||
59 | + public function rules() | ||
60 | + { | ||
61 | + return [ | ||
62 | + [ | ||
63 | + [ | ||
64 | + 'value', | ||
65 | + 'parent_id', | ||
66 | + 'sort', | ||
67 | + ], | ||
68 | + 'integer', | ||
69 | + ], | ||
70 | + ]; | ||
71 | + } | ||
72 | + | ||
73 | + /** | ||
74 | + * @return \yii\db\ActiveQuery | ||
75 | + */ | ||
76 | + public function getParent() | ||
77 | + { | ||
78 | + return $this->hasOne(self::className(), [ 'id' => 'parent_id' ]); | ||
79 | + } | ||
80 | + } | ||
0 | \ No newline at end of file | 81 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * DeliverySearch represents the model behind the search form about `artweb\artbox\ecommerce\models\Delivery`. | ||
10 | + */ | ||
11 | + class DeliverySearch extends Delivery | ||
12 | + { | ||
13 | + | ||
14 | + /** | ||
15 | + * @var string | ||
16 | + */ | ||
17 | + public $title; | ||
18 | + | ||
19 | + /** | ||
20 | + * @var string | ||
21 | + */ | ||
22 | + public $parentTitle; | ||
23 | + | ||
24 | + /** | ||
25 | + * @inheritdoc | ||
26 | + */ | ||
27 | + public function rules() | ||
28 | + { | ||
29 | + return [ | ||
30 | + [ | ||
31 | + [ | ||
32 | + 'id', | ||
33 | + 'parent_id', | ||
34 | + 'value', | ||
35 | + 'sort', | ||
36 | + ], | ||
37 | + 'integer', | ||
38 | + ], | ||
39 | + [ | ||
40 | + [ 'title' ], | ||
41 | + 'safe', | ||
42 | + ], | ||
43 | + ]; | ||
44 | + } | ||
45 | + | ||
46 | + /** | ||
47 | + * @inheritdoc | ||
48 | + */ | ||
49 | + public function scenarios() | ||
50 | + { | ||
51 | + // bypass scenarios() implementation in the parent class | ||
52 | + return Model::scenarios(); | ||
53 | + } | ||
54 | + | ||
55 | + /** | ||
56 | + * Creates data provider instance with search query applied | ||
57 | + * | ||
58 | + * @param array $params | ||
59 | + * | ||
60 | + * @return ActiveDataProvider | ||
61 | + */ | ||
62 | + public function search($params) | ||
63 | + { | ||
64 | + $query = Delivery::find() | ||
65 | + ->joinWith('lang') | ||
66 | + ->joinWith([ 'parent as parent' ]); | ||
67 | + | ||
68 | + // add conditions that should always apply here | ||
69 | + | ||
70 | + $dataProvider = new ActiveDataProvider( | ||
71 | + [ | ||
72 | + 'query' => $query, | ||
73 | + 'sort' => [ | ||
74 | + 'attributes' => [ | ||
75 | + 'id', | ||
76 | + 'value', | ||
77 | + 'title' => [ | ||
78 | + 'asc' => [ 'order_delivery_lang.title' => SORT_ASC ], | ||
79 | + 'desc' => [ 'order_delivery_lang.title' => SORT_DESC ], | ||
80 | + ], | ||
81 | + ], | ||
82 | + ], | ||
83 | + ] | ||
84 | + ); | ||
85 | + | ||
86 | + $this->load($params); | ||
87 | + | ||
88 | + if (!$this->validate()) { | ||
89 | + // uncomment the following line if you do not want to return any records when validation fails | ||
90 | + // $query->where('0=1'); | ||
91 | + return $dataProvider; | ||
92 | + } | ||
93 | + | ||
94 | + // grid filtering conditions | ||
95 | + $query->andFilterWhere( | ||
96 | + [ | ||
97 | + 'id' => $this->id, | ||
98 | + 'value' => $this->value, | ||
99 | + 'sort' => $this->sort, | ||
100 | + ] | ||
101 | + ) | ||
102 | + ->andFilterWhere( | ||
103 | + [ | ||
104 | + 'like', | ||
105 | + 'order_delivery_lang.title', | ||
106 | + $this->title, | ||
107 | + ] | ||
108 | + ); | ||
109 | + | ||
110 | + return $dataProvider; | ||
111 | + } | ||
112 | + } |
models/Export.php
@@ -2,8 +2,7 @@ | @@ -2,8 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | ||
6 | - use artweb\artbox\ecommerce\models\TaxOption; | 5 | + use artweb\artbox\language\models\Language; |
7 | use yii\base\Model; | 6 | use yii\base\Model; |
8 | 7 | ||
9 | class Export extends Model | 8 | class Export extends Model |
models/Import.php
@@ -2,9 +2,7 @@ | @@ -2,9 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | ||
6 | - use artweb\artbox\ecommerce\models\TaxGroup; | ||
7 | - use artweb\artbox\ecommerce\models\TaxOption; | 5 | + use artweb\artbox\language\models\Language; |
8 | use Yii; | 6 | use Yii; |
9 | use yii\base\Model; | 7 | use yii\base\Model; |
10 | use yii\helpers\ArrayHelper; | 8 | use yii\helpers\ArrayHelper; |
1 | +<?php | ||
2 | + namespace artweb\artbox\ecommerce\models; | ||
3 | + | ||
4 | + use artweb\artbox\models\Customer; | ||
5 | + use Yii; | ||
6 | + use yii\db\ActiveRecord; | ||
7 | + use yii\db\Expression; | ||
8 | + use yii\web\Session; | ||
9 | + | ||
10 | + /** | ||
11 | + * Class Order | ||
12 | + * | ||
13 | + * @todo Write docs and refactor | ||
14 | + * @package artweb\artbox\ecommerce\models | ||
15 | + * @property int $id | ||
16 | + * @property int $user_id | ||
17 | + * @property string $name | ||
18 | + * @property string $phone | ||
19 | + * @property string $phone2 | ||
20 | + * @property string $email | ||
21 | + * @property string $adress | ||
22 | + * @property string $body | ||
23 | + * @property double $total | ||
24 | + * @property string $date_time | ||
25 | + * @property string $date_dedline | ||
26 | + * @property string $reserve | ||
27 | + * @property string $status | ||
28 | + * @property string $comment | ||
29 | + * @property int $label | ||
30 | + * @property int $pay | ||
31 | + * @property int $numbercard | ||
32 | + * @property int $delivery | ||
33 | + * @property string $declaration | ||
34 | + * @property string $stock | ||
35 | + * @property string $consignment | ||
36 | + * @property string $payment | ||
37 | + * @property string $insurance | ||
38 | + * @property double $amount_imposed | ||
39 | + * @property string $shipping_by | ||
40 | + * @property string $city | ||
41 | + */ | ||
42 | + class Order extends ActiveRecord | ||
43 | + { | ||
44 | + | ||
45 | + const SCENARIO_QUICK = 'quick'; | ||
46 | + | ||
47 | + private $data; | ||
48 | + | ||
49 | + public static function tableName() | ||
50 | + { | ||
51 | + return 'order'; | ||
52 | + } | ||
53 | + | ||
54 | + public function scenarios() | ||
55 | + { | ||
56 | + $scenarios = array_merge( | ||
57 | + parent::scenarios(), | ||
58 | + [ | ||
59 | + self::SCENARIO_QUICK => [ 'phone' ], | ||
60 | + ] | ||
61 | + ); | ||
62 | + return $scenarios; | ||
63 | + } | ||
64 | + | ||
65 | + public function rules() | ||
66 | + { | ||
67 | + return [ | ||
68 | + [ | ||
69 | + [ | ||
70 | + 'phone', | ||
71 | + ], | ||
72 | + 'required', | ||
73 | + ], | ||
74 | + [ | ||
75 | + [ 'comment' ], | ||
76 | + 'safe', | ||
77 | + ], | ||
78 | + [ | ||
79 | + [ 'email' ], | ||
80 | + 'email', | ||
81 | + ], | ||
82 | + [ | ||
83 | + [ 'phone' ], | ||
84 | + 'match', | ||
85 | + 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/', | ||
86 | + 'on' => self::SCENARIO_QUICK, | ||
87 | + ], | ||
88 | + [ | ||
89 | + [ | ||
90 | + 'name', | ||
91 | + 'phone2', | ||
92 | + 'numbercard', | ||
93 | + 'body', | ||
94 | + 'declaration', | ||
95 | + 'stock', | ||
96 | + 'consignment', | ||
97 | + 'payment', | ||
98 | + 'insurance', | ||
99 | + 'amount_imposed', | ||
100 | + 'shipping_by', | ||
101 | + 'city', | ||
102 | + 'adress', | ||
103 | + 'total', | ||
104 | + 'status', | ||
105 | + ], | ||
106 | + 'string', | ||
107 | + 'max' => 255, | ||
108 | + ], | ||
109 | + ]; | ||
110 | + } | ||
111 | + | ||
112 | + public function attributeLabels() | ||
113 | + { | ||
114 | + return [ | ||
115 | + 'name' => Yii::t('app', 'order_name'), | ||
116 | + 'phone' => Yii::t('app', 'order_phone'), | ||
117 | + 'email' => Yii::t('app', 'order_email'), | ||
118 | + 'comment' => Yii::t('app', 'order_comment'), | ||
119 | + ]; | ||
120 | + } | ||
121 | + | ||
122 | + public function beforeSave($insert) | ||
123 | + { | ||
124 | + $this->user_id = Yii::$app->user->id; | ||
125 | + $this->date_time = new Expression('NOW()'); | ||
126 | + return parent::beforeSave($insert); | ||
127 | + } | ||
128 | + | ||
129 | + public function beforeDelete() | ||
130 | + { | ||
131 | + return parent::beforeDelete(); | ||
132 | + } | ||
133 | + | ||
134 | + public function addBasket($product_variant_id, $count) | ||
135 | + { | ||
136 | + $session = new Session; | ||
137 | + $session->open(); | ||
138 | + $data = $session[ 'basket' ]; | ||
139 | + $i = 0; | ||
140 | + if (isset( $session[ 'basket' ] )) { | ||
141 | + foreach ($session[ 'basket' ] as $key => $basket) { | ||
142 | + if ($product_variant_id == $basket[ 'id' ]) { | ||
143 | + $data[ $key ][ 'count' ] += $count; | ||
144 | + $session[ 'basket' ] = $data; | ||
145 | + $i++; | ||
146 | + } | ||
147 | + } | ||
148 | + } | ||
149 | + if ($i == 0) { | ||
150 | + $data[] = [ | ||
151 | + 'id' => $product_variant_id, | ||
152 | + 'count' => $count, | ||
153 | + ]; | ||
154 | + $session[ 'basket' ] = $data; | ||
155 | + } | ||
156 | + } | ||
157 | + | ||
158 | + public function rowBasket() | ||
159 | + { | ||
160 | + $session = new Session; | ||
161 | + $session->open(); | ||
162 | + $cost = 0; | ||
163 | + $count = 0; | ||
164 | + if (isset( $session[ 'basket' ] ) && count($session[ 'basket' ])) { | ||
165 | + foreach ($session[ 'basket' ] as $product) { | ||
166 | + $count += $product[ 'count' ]; | ||
167 | + } | ||
168 | + } | ||
169 | + | ||
170 | + return (object) [ | ||
171 | + 'cost' => $cost, | ||
172 | + 'count' => $count, | ||
173 | + ]; | ||
174 | + } | ||
175 | + | ||
176 | + public function deleteBasketMod($id) | ||
177 | + { | ||
178 | + $session = new Session; | ||
179 | + $session->open(); | ||
180 | + $basket = $session[ 'basket' ]; | ||
181 | + foreach ($basket as $key => $product) { | ||
182 | + if ($id == $product[ 'id' ]) { | ||
183 | + unset( $basket[ $key ] ); | ||
184 | + } | ||
185 | + } | ||
186 | + $session[ 'basket' ] = $basket; | ||
187 | + } | ||
188 | + | ||
189 | + public function updateBasket($row) | ||
190 | + { | ||
191 | + $session = new Session; | ||
192 | + $session->open(); | ||
193 | + //$data = array(); | ||
194 | + if ($row[ 'count' ] > 0) { | ||
195 | + $this->data[] = [ | ||
196 | + 'id' => $row[ 'id' ], | ||
197 | + 'count' => $row[ 'count' ], | ||
198 | + ]; | ||
199 | + } | ||
200 | + $session[ 'basket' ] = $this->data; | ||
201 | + } | ||
202 | + | ||
203 | + public function getBasketMods() | ||
204 | + { | ||
205 | + $session = new Session; | ||
206 | + $session->open(); | ||
207 | + $products = []; | ||
208 | + if (empty( $session[ 'basket' ] )) { | ||
209 | + return []; | ||
210 | + } | ||
211 | + foreach ($session[ 'basket' ] as $product) { | ||
212 | + $row = ProductVariant::find() | ||
213 | + ->select( | ||
214 | + [ | ||
215 | + 'product_variant.*', | ||
216 | + 'product.name as productName', | ||
217 | + 'product.alias', | ||
218 | + ] | ||
219 | + ) | ||
220 | + ->where([ 'product_variant.id' => $product[ 'id' ] ]) | ||
221 | + ->leftJoin('product', 'product.id = product_variant.product_id') | ||
222 | + ->one(); | ||
223 | + $row->count = $product[ 'count' ]; | ||
224 | + $row->sum_cost = $product[ 'count' ] * $row->price; | ||
225 | + $products[] = $row; | ||
226 | + } | ||
227 | + | ||
228 | + return $products; | ||
229 | + } | ||
230 | + | ||
231 | + public function getSumCost() | ||
232 | + { | ||
233 | + $session = new Session; | ||
234 | + $session->open(); | ||
235 | + $cost = 0; | ||
236 | + if (empty( $session[ 'basket' ] )) { | ||
237 | + return false; | ||
238 | + } | ||
239 | + foreach ($session[ 'basket' ] as $product) { | ||
240 | + $cost += ( $this->getModCost($product[ 'id' ]) * $product[ 'count' ] ); | ||
241 | + } | ||
242 | + | ||
243 | + return $cost; | ||
244 | + } | ||
245 | + | ||
246 | + private function getModCost($product_variant_id) | ||
247 | + { | ||
248 | + /** | ||
249 | + * @var ProductVariant $mod | ||
250 | + */ | ||
251 | + $mod = ProductVariant::find() | ||
252 | + ->where([ 'id' => $product_variant_id ]) | ||
253 | + ->one(); | ||
254 | + | ||
255 | + return $mod->price; | ||
256 | + } | ||
257 | + | ||
258 | + public function clearBasket() | ||
259 | + { | ||
260 | + $session = new Session; | ||
261 | + $session->open(); | ||
262 | + $session[ 'basket' ] = null; | ||
263 | + } | ||
264 | + | ||
265 | + public function getUser() | ||
266 | + { | ||
267 | + return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]); | ||
268 | + } | ||
269 | + | ||
270 | + public function getProducts() | ||
271 | + { | ||
272 | + return $this->hasMany(OrderProduct::className(), [ 'order_id' => 'id' ]); | ||
273 | + } | ||
274 | + } | ||
0 | \ No newline at end of file | 275 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | + use artweb\artbox\language\models\Language; | ||
6 | + use Yii; | ||
7 | + use yii\db\ActiveRecord; | ||
8 | + | ||
9 | + /** | ||
10 | + * This is the model class for table "order_delivery_lang". | ||
11 | + * | ||
12 | + * @property integer $order_delivery_id | ||
13 | + * @property integer $language_id | ||
14 | + * @property string $title | ||
15 | + * @property string $text | ||
16 | + * @property Language $language | ||
17 | + * @property Delivery $delivery | ||
18 | + */ | ||
19 | + class OrderDeliveryLang extends ActiveRecord | ||
20 | + { | ||
21 | + | ||
22 | + /** | ||
23 | + * @inheritdoc | ||
24 | + */ | ||
25 | + public static function primaryKey() | ||
26 | + { | ||
27 | + return [ | ||
28 | + 'order_delivery_id', | ||
29 | + 'language_id', | ||
30 | + ]; | ||
31 | + } | ||
32 | + | ||
33 | + /** | ||
34 | + * @inheritdoc | ||
35 | + */ | ||
36 | + public static function tableName() | ||
37 | + { | ||
38 | + return 'order_delivery_lang'; | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * @inheritdoc | ||
43 | + */ | ||
44 | + public function rules() | ||
45 | + { | ||
46 | + return [ | ||
47 | + [ | ||
48 | + [ | ||
49 | + 'title', | ||
50 | + 'text', | ||
51 | + ], | ||
52 | + 'required', | ||
53 | + ], | ||
54 | + [ | ||
55 | + [ 'text' ], | ||
56 | + 'string', | ||
57 | + ], | ||
58 | + [ | ||
59 | + [ 'title' ], | ||
60 | + 'string', | ||
61 | + 'max' => 255, | ||
62 | + ], | ||
63 | + [ | ||
64 | + [ | ||
65 | + 'order_delivery_id', | ||
66 | + 'language_id', | ||
67 | + ], | ||
68 | + 'unique', | ||
69 | + 'targetAttribute' => [ | ||
70 | + 'order_delivery_id', | ||
71 | + 'language_id', | ||
72 | + ], | ||
73 | + 'message' => 'The combination of order Delivery ID and Language ID has already been taken.', | ||
74 | + ], | ||
75 | + [ | ||
76 | + [ 'language_id' ], | ||
77 | + 'exist', | ||
78 | + 'skipOnError' => true, | ||
79 | + 'targetClass' => Language::className(), | ||
80 | + 'targetAttribute' => [ 'language_id' => 'id' ], | ||
81 | + ], | ||
82 | + [ | ||
83 | + [ 'order_delivery_id' ], | ||
84 | + 'exist', | ||
85 | + 'skipOnError' => true, | ||
86 | + 'targetClass' => Delivery::className(), | ||
87 | + 'targetAttribute' => [ 'order_delivery_id' => 'id' ], | ||
88 | + ], | ||
89 | + ]; | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * @inheritdoc | ||
94 | + */ | ||
95 | + public function attributeLabels() | ||
96 | + { | ||
97 | + return [ | ||
98 | + 'order_delivery_id' => Yii::t('app', 'order_delivery_id'), | ||
99 | + 'language_id' => Yii::t('app', 'language_id'), | ||
100 | + 'title' => Yii::t('app', 'title'), | ||
101 | + 'text' => Yii::t('app', 'text'), | ||
102 | + ]; | ||
103 | + } | ||
104 | + | ||
105 | + /** | ||
106 | + * @return \yii\db\ActiveQuery | ||
107 | + */ | ||
108 | + public function getLanguage() | ||
109 | + { | ||
110 | + return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]); | ||
111 | + } | ||
112 | + | ||
113 | + /** | ||
114 | + * @return \yii\db\ActiveQuery | ||
115 | + */ | ||
116 | + public function getDelivery() | ||
117 | + { | ||
118 | + return $this->hasOne(Delivery::className(), [ 'id' => 'order_delivery_id' ]); | ||
119 | + } | ||
120 | + } |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | + use Yii; | ||
6 | + use yii\db\ActiveRecord; | ||
7 | + | ||
8 | + /** | ||
9 | + * Class OrderProduct | ||
10 | + * | ||
11 | + * @property int $id | ||
12 | + * @property int $order_id | ||
13 | + * @property int $product_variant_id | ||
14 | + * @property string $product_name | ||
15 | + * @property string $name | ||
16 | + * @property string $sku | ||
17 | + * @property double $price | ||
18 | + * @property int $count | ||
19 | + * @property double $sum_cost | ||
20 | + * @property Order $order | ||
21 | + * @property ProductVariant $productVariant | ||
22 | + * @package artweb\artbox\ecommerce\models | ||
23 | + */ | ||
24 | + class OrderProduct extends ActiveRecord | ||
25 | + { | ||
26 | + | ||
27 | + public static function tableName() | ||
28 | + { | ||
29 | + return 'order_product'; | ||
30 | + } | ||
31 | + | ||
32 | + public function rules() | ||
33 | + { | ||
34 | + return [ | ||
35 | + [ | ||
36 | + [ 'order_id' ], | ||
37 | + 'required', | ||
38 | + ], | ||
39 | + //['email', 'email'], | ||
40 | + [ | ||
41 | + [ | ||
42 | + 'product_name', | ||
43 | + 'name', | ||
44 | + 'price', | ||
45 | + 'count', | ||
46 | + 'sum_cost', | ||
47 | + 'product_variant_id', | ||
48 | + 'sku', | ||
49 | + ], | ||
50 | + 'safe', | ||
51 | + ], | ||
52 | + ]; | ||
53 | + } | ||
54 | + | ||
55 | + public function attributeLabels() | ||
56 | + { | ||
57 | + return [ | ||
58 | + 'product_name' => Yii::t('app', 'product_name'), | ||
59 | + 'name' => Yii::t('app', 'op_name'), | ||
60 | + 'art' => Yii::t('app', 'art'), | ||
61 | + 'cost' => Yii::t('app', 'cost'), | ||
62 | + 'count' => Yii::t('app', 'count'), | ||
63 | + 'sum_cost' => Yii::t('app', 'sum_cost'), | ||
64 | + ]; | ||
65 | + } | ||
66 | + | ||
67 | + public function getOrder() | ||
68 | + { | ||
69 | + return $this->hasOne(Order::className(), [ 'id' => 'order_id' ]); | ||
70 | + } | ||
71 | + | ||
72 | + /** | ||
73 | + * @return \yii\db\ActiveQuery | ||
74 | + */ | ||
75 | + public function getProductVariant() | ||
76 | + { | ||
77 | + return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]); | ||
78 | + } | ||
79 | + } | ||
0 | \ No newline at end of file | 80 | \ No newline at end of file |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\models; | ||
4 | + | ||
5 | + use yii\base\Model; | ||
6 | + use yii\data\ActiveDataProvider; | ||
7 | + | ||
8 | + /** | ||
9 | + * OrderSearch represents the model behind the search form about `\artweb\artbox\ecommerce\models\Order`. | ||
10 | + */ | ||
11 | + class OrderSearch extends Order | ||
12 | + { | ||
13 | + | ||
14 | + /** | ||
15 | + * @inheritdoc | ||
16 | + */ | ||
17 | + public function rules() | ||
18 | + { | ||
19 | + return [ | ||
20 | + [ | ||
21 | + [ | ||
22 | + 'id', | ||
23 | + 'user_id', | ||
24 | + 'delivery', | ||
25 | + 'payment', | ||
26 | + 'status', | ||
27 | + ], | ||
28 | + 'integer', | ||
29 | + ], | ||
30 | + [ | ||
31 | + [ | ||
32 | + 'name', | ||
33 | + 'email', | ||
34 | + 'phone', | ||
35 | + ], | ||
36 | + 'safe', | ||
37 | + ], | ||
38 | + ]; | ||
39 | + } | ||
40 | + | ||
41 | + /** | ||
42 | + * @inheritdoc | ||
43 | + */ | ||
44 | + public function scenarios() | ||
45 | + { | ||
46 | + // bypass scenarios() implementation in the parent class | ||
47 | + return Model::scenarios(); | ||
48 | + } | ||
49 | + | ||
50 | + /** | ||
51 | + * Creates data provider instance with search query applied | ||
52 | + * | ||
53 | + * @param array $params | ||
54 | + * | ||
55 | + * @return ActiveDataProvider | ||
56 | + */ | ||
57 | + public function search($params) | ||
58 | + { | ||
59 | + $query = Order::find(); | ||
60 | + | ||
61 | + // add conditions that should always apply here | ||
62 | + | ||
63 | + $dataProvider = new ActiveDataProvider( | ||
64 | + [ | ||
65 | + 'query' => $query, | ||
66 | + ] | ||
67 | + ); | ||
68 | + | ||
69 | + $this->load($params); | ||
70 | + | ||
71 | + if (!$this->validate()) { | ||
72 | + // uncomment the following line if you do not want to return any records when validation fails | ||
73 | + // $query->where('0=1'); | ||
74 | + return $dataProvider; | ||
75 | + } | ||
76 | + | ||
77 | + // grid filtering conditions | ||
78 | + $query->andFilterWhere( | ||
79 | + [ | ||
80 | + 'id' => $this->id, | ||
81 | + 'user_id' => $this->user_id, | ||
82 | + 'delivery' => $this->delivery, | ||
83 | + 'payment' => $this->payment, | ||
84 | + 'status' => $this->status, | ||
85 | + ] | ||
86 | + ); | ||
87 | + | ||
88 | + $query->andFilterWhere( | ||
89 | + [ | ||
90 | + 'like', | ||
91 | + 'name', | ||
92 | + $this->name, | ||
93 | + ] | ||
94 | + ) | ||
95 | + ->andFilterWhere( | ||
96 | + [ | ||
97 | + 'like', | ||
98 | + 'email', | ||
99 | + $this->email, | ||
100 | + ] | ||
101 | + ) | ||
102 | + ->andFilterWhere( | ||
103 | + [ | ||
104 | + 'like', | ||
105 | + 'phone', | ||
106 | + $this->phone, | ||
107 | + ] | ||
108 | + ); | ||
109 | + | ||
110 | + return $dataProvider; | ||
111 | + } | ||
112 | + } |
models/Product.php
@@ -2,15 +2,11 @@ | @@ -2,15 +2,11 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\behaviors\DefaultVariantBehavior; | ||
6 | - use common\behaviors\MultipleImgBehavior; | ||
7 | - use common\behaviors\SaveMultipleFileBehavior; | ||
8 | - use common\models\ProductToRating; | ||
9 | - use common\modules\comment\models\CommentModel; | ||
10 | - use common\modules\language\behaviors\LanguageBehavior; | ||
11 | - use artweb\artbox\ecommerce\models\TaxGroup; | ||
12 | - use artweb\artbox\ecommerce\models\TaxGroupToCategory; | ||
13 | - use artweb\artbox\ecommerce\models\TaxOption; | 5 | + use artweb\artbox\ecommerce\behaviors\DefaultVariantBehavior; |
6 | + use artweb\artbox\behaviors\MultipleImgBehavior; | ||
7 | + use artweb\artbox\behaviors\SaveMultipleFileBehavior; | ||
8 | +// use artweb\artbox\comment\models\CommentModel; | ||
9 | + use artweb\artbox\language\behaviors\LanguageBehavior; | ||
14 | use Yii; | 10 | use Yii; |
15 | use yii\base\InvalidParamException; | 11 | use yii\base\InvalidParamException; |
16 | use yii\db\ActiveQuery; | 12 | use yii\db\ActiveQuery; |
@@ -33,7 +29,6 @@ | @@ -33,7 +29,6 @@ | ||
33 | * @property boolean $is_top | 29 | * @property boolean $is_top |
34 | * @property boolean $is_new | 30 | * @property boolean $is_new |
35 | * @property boolean $is_discount | 31 | * @property boolean $is_discount |
36 | - * @property ProductToRating $averageRating | ||
37 | * @property TaxGroup[] $properties | 32 | * @property TaxGroup[] $properties |
38 | * @property ProductVariant $enabledVariant | 33 | * @property ProductVariant $enabledVariant |
39 | * @property ProductVariant[] $enabledVariants | 34 | * @property ProductVariant[] $enabledVariants |
@@ -500,35 +495,35 @@ | @@ -500,35 +495,35 @@ | ||
500 | * @todo Rewrite with behavior | 495 | * @todo Rewrite with behavior |
501 | * @return bool | 496 | * @return bool |
502 | */ | 497 | */ |
503 | - public function recalculateRating():bool | ||
504 | - { | ||
505 | - /** | ||
506 | - * @var ProductToRating $averageRating | ||
507 | - */ | ||
508 | - $average = $this->getComments() | ||
509 | - ->joinWith('rating') | ||
510 | - ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ]) | ||
511 | - ->scalar(); | ||
512 | - if (!$average) { | ||
513 | - $average = 0; | ||
514 | - } | ||
515 | - $averageRating = $this->averageRating; | ||
516 | - if (!empty( $averageRating )) { | ||
517 | - $averageRating->value = $average; | ||
518 | - } else { | ||
519 | - $averageRating = new ProductToRating( | ||
520 | - [ | ||
521 | - 'product_id' => $this->id, | ||
522 | - 'value' => $average, | ||
523 | - ] | ||
524 | - ); | ||
525 | - } | ||
526 | - if ($averageRating->save()) { | ||
527 | - return true; | ||
528 | - } else { | ||
529 | - return false; | ||
530 | - } | ||
531 | - } | 498 | +// public function recalculateRating():bool |
499 | +// { | ||
500 | +// /** | ||
501 | +// * @var ProductToRating $averageRating | ||
502 | +// */ | ||
503 | +// $average = $this->getComments() | ||
504 | +// ->joinWith('rating') | ||
505 | +// ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ]) | ||
506 | +// ->scalar(); | ||
507 | +// if (!$average) { | ||
508 | +// $average = 0; | ||
509 | +// } | ||
510 | +// $averageRating = $this->averageRating; | ||
511 | +// if (!empty( $averageRating )) { | ||
512 | +// $averageRating->value = $average; | ||
513 | +// } else { | ||
514 | +// $averageRating = new ProductToRating( | ||
515 | +// [ | ||
516 | +// 'product_id' => $this->id, | ||
517 | +// 'value' => $average, | ||
518 | +// ] | ||
519 | +// ); | ||
520 | +// } | ||
521 | +// if ($averageRating->save()) { | ||
522 | +// return true; | ||
523 | +// } else { | ||
524 | +// return false; | ||
525 | +// } | ||
526 | +// } | ||
532 | 527 | ||
533 | /** | 528 | /** |
534 | * Get CommmentModel query for artboxcomment module | 529 | * Get CommmentModel query for artboxcomment module |
@@ -536,27 +531,27 @@ | @@ -536,27 +531,27 @@ | ||
536 | * @todo Rewrite with behavior | 531 | * @todo Rewrite with behavior |
537 | * @return ActiveQuery | 532 | * @return ActiveQuery |
538 | */ | 533 | */ |
539 | - public function getComments() | ||
540 | - { | ||
541 | - return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ]) | ||
542 | - ->where( | ||
543 | - [ | ||
544 | - 'artbox_comment.entity' => self::className(), | ||
545 | - 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, | ||
546 | - 'artbox_comment.artbox_comment_pid' => null, | ||
547 | - ] | ||
548 | - ); | ||
549 | - } | 534 | +// public function getComments() |
535 | +// { | ||
536 | +// return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ]) | ||
537 | +// ->where( | ||
538 | +// [ | ||
539 | +// 'artbox_comment.entity' => self::className(), | ||
540 | +// 'artbox_comment.status' => CommentModel::STATUS_ACTIVE, | ||
541 | +// 'artbox_comment.artbox_comment_pid' => null, | ||
542 | +// ] | ||
543 | +// ); | ||
544 | +// } | ||
550 | 545 | ||
551 | /** | 546 | /** |
552 | * Get ProductToRating query in order to get average rating for current Product | 547 | * Get ProductToRating query in order to get average rating for current Product |
553 | * | 548 | * |
554 | * @return \yii\db\ActiveQuery | 549 | * @return \yii\db\ActiveQuery |
555 | */ | 550 | */ |
556 | - public function getAverageRating() | ||
557 | - { | ||
558 | - return $this->hasOne(ProductToRating::className(), [ 'product_id' => 'id' ]); | ||
559 | - } | 551 | +// public function getAverageRating() |
552 | +// { | ||
553 | +// return $this->hasOne(ProductToRating::className(), [ 'product_id' => 'id' ]); | ||
554 | +// } | ||
560 | 555 | ||
561 | /** | 556 | /** |
562 | * Get TaxGroupToCategories query via product_category table | 557 | * Get TaxGroupToCategories query via product_category table |
1 | +<?php | ||
2 | + | ||
3 | +namespace frontend\models; | ||
4 | + | ||
5 | +use artweb\artbox\ecommerce\helpers\FilterHelper; | ||
6 | +use artweb\artbox\ecommerce\models\Category; | ||
7 | +use yii\base\Model; | ||
8 | +use yii\data\ActiveDataProvider; | ||
9 | +use yii\data\ArrayDataProvider; | ||
10 | +use yii\db\ActiveQuery; | ||
11 | + | ||
12 | +use artweb\artbox\ecommerce\models\Product; | ||
13 | +use artweb\artbox\ecommerce\models\ProductVariant; | ||
14 | + | ||
15 | +class ProductFrontendSearch extends Product { | ||
16 | + | ||
17 | + | ||
18 | + public $price_interval; | ||
19 | + public $brands; | ||
20 | + | ||
21 | + public function behaviors() | ||
22 | + { | ||
23 | + $behaviors = parent::behaviors(); | ||
24 | + | ||
25 | + if (isset($behaviors['language'])) | ||
26 | + { | ||
27 | + unset($behaviors['language']); | ||
28 | + } | ||
29 | + return $behaviors; | ||
30 | + } | ||
31 | + | ||
32 | + /** | ||
33 | + * @inheritdoc | ||
34 | + */ | ||
35 | + public function rules() | ||
36 | + { | ||
37 | + return [ | ||
38 | + [['price_interval', 'brands'], 'safe'], | ||
39 | + ]; | ||
40 | + } | ||
41 | + | ||
42 | + /** | ||
43 | + * @inheritdoc | ||
44 | + */ | ||
45 | + public function scenarios() | ||
46 | + { | ||
47 | + // bypass scenarios() implementation in the parent class | ||
48 | + return Model::scenarios(); | ||
49 | + } | ||
50 | + | ||
51 | + /** | ||
52 | + * Creates data provider instance with search query applied for frontend | ||
53 | + * | ||
54 | + * @param array $params | ||
55 | + * | ||
56 | + * @return ActiveDataProvider | ||
57 | + */ | ||
58 | + public function search($category = null, $params = [], $in_stock = true) { | ||
59 | + | ||
60 | + | ||
61 | + $dataProvider = new ArrayDataProvider([ | ||
62 | + 'allModels' => $this->getSearchQuery($category, $params, $in_stock)->with([ | ||
63 | + 'images', | ||
64 | +// 'events', | ||
65 | + 'variant', | ||
66 | + 'variant.image', | ||
67 | + 'comments', | ||
68 | +// 'averageRating', | ||
69 | + ])->all(), | ||
70 | + 'pagination' => [ | ||
71 | + 'pageSize' => 15, | ||
72 | + ], | ||
73 | + 'sort' => [ | ||
74 | + 'attributes' => [ | ||
75 | + 'name' => [ | ||
76 | + 'asc' => ['name' => SORT_ASC], | ||
77 | + 'desc' => ['name' => SORT_DESC], | ||
78 | + 'default' => SORT_DESC, | ||
79 | + 'label' => 'имени', | ||
80 | + ], | ||
81 | + 'price' => [ | ||
82 | + 'asc' => ['price' => SORT_ASC], | ||
83 | + 'desc' => ['price' => SORT_DESC], | ||
84 | + 'default' => SORT_DESC, | ||
85 | + 'label' => 'по цене', | ||
86 | + ], | ||
87 | + ], | ||
88 | + ] | ||
89 | + ]); | ||
90 | + | ||
91 | + | ||
92 | + | ||
93 | + | ||
94 | + | ||
95 | + return $dataProvider; | ||
96 | + } | ||
97 | + | ||
98 | + public function getSearchQuery($category = null, $params = [], $in_stock = true) { | ||
99 | + | ||
100 | + if (!empty($category)) { | ||
101 | + /** @var ActiveQuery $query */ | ||
102 | + /**@var Category $category **/ | ||
103 | + $query = $category->getProducts(); | ||
104 | + | ||
105 | + } else { | ||
106 | + $query = Product::find(); | ||
107 | + } | ||
108 | + | ||
109 | + $query->select(['product.*']); | ||
110 | + $query->joinWith(['enabledVariants','brand','options', 'category']); | ||
111 | + | ||
112 | + $query->groupBy(['product.id', 'product_variant.price']); | ||
113 | + | ||
114 | + FilterHelper::setQueryParams($query, $params); | ||
115 | + if($in_stock){ | ||
116 | + $query->andWhere(['>=', ProductVariant::tableName() .'.stock', 1]); | ||
117 | + } | ||
118 | + | ||
119 | + | ||
120 | + return $query; | ||
121 | + } | ||
122 | + | ||
123 | + | ||
124 | + /** | ||
125 | + * @param Category|null $category | ||
126 | + * @return array | ||
127 | + */ | ||
128 | + | ||
129 | + public function priceLimits($category = null) { | ||
130 | + if (!empty($category)) { | ||
131 | + /** @var ActiveQuery $query */ | ||
132 | + $query = $category->getProducts(); | ||
133 | + } else { | ||
134 | + $query = Product::find(); | ||
135 | + } | ||
136 | + $query->joinWith('variant'); | ||
137 | + | ||
138 | + return [ | ||
139 | + 'min' => $query->min(ProductVariant::tableName() .'.price'), | ||
140 | + 'max' => $query->max(ProductVariant::tableName() .'.price'), | ||
141 | + ]; | ||
142 | + } | ||
143 | +} | ||
0 | \ No newline at end of file | 144 | \ No newline at end of file |
models/ProductImage.php
models/ProductLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 | ||
@@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
39 | { | 39 | { |
40 | return [ | 40 | return [ |
41 | 'slug' => [ | 41 | 'slug' => [ |
42 | - 'class' => 'common\behaviors\Slug', | 42 | + 'class' => 'artweb\artbox\ecommerce\behaviors\Slug', |
43 | ], | 43 | ], |
44 | ]; | 44 | ]; |
45 | } | 45 | } |
models/ProductOption.php
models/ProductUnit.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\behaviors\LanguageBehavior; | 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveQuery; | 7 | use yii\db\ActiveQuery; |
8 | use yii\db\ActiveRecord; | 8 | use yii\db\ActiveRecord; |
models/ProductUnitLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 |
models/ProductVariant.php
@@ -2,11 +2,9 @@ | @@ -2,11 +2,9 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\behaviors\MultipleImgBehavior; | ||
6 | - use common\behaviors\SaveMultipleFileBehavior; | ||
7 | - use common\modules\language\behaviors\LanguageBehavior; | ||
8 | - use artweb\artbox\ecommerce\models\TaxGroup; | ||
9 | - use artweb\artbox\ecommerce\models\TaxOption; | 5 | + use artweb\artbox\behaviors\MultipleImgBehavior; |
6 | + use artweb\artbox\behaviors\SaveMultipleFileBehavior; | ||
7 | + use artweb\artbox\language\behaviors\LanguageBehavior; | ||
10 | use Yii; | 8 | use Yii; |
11 | use yii\base\InvalidParamException; | 9 | use yii\base\InvalidParamException; |
12 | use yii\db\ActiveQuery; | 10 | use yii\db\ActiveQuery; |
models/ProductVariantLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 |
models/ProductVariantOption.php
models/Stock.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\behaviors\LanguageBehavior; | 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveQuery; | 7 | use yii\db\ActiveQuery; |
8 | use yii\db\ActiveRecord; | 8 | use yii\db\ActiveRecord; |
models/StockLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 |
models/TaxGroup.php
@@ -2,9 +2,8 @@ | @@ -2,9 +2,8 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\behaviors\LanguageBehavior; | ||
6 | - use common\modules\language\models\Language; | ||
7 | - use artweb\artbox\ecommerce\models\Category; | 5 | + use artweb\artbox\language\behaviors\LanguageBehavior; |
6 | + use artweb\artbox\language\models\Language; | ||
8 | use yii\base\InvalidValueException; | 7 | use yii\base\InvalidValueException; |
9 | use yii\db\ActiveQuery; | 8 | use yii\db\ActiveQuery; |
10 | use yii\db\ActiveRecord; | 9 | use yii\db\ActiveRecord; |
models/TaxGroupLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 | ||
@@ -40,7 +40,7 @@ | @@ -40,7 +40,7 @@ | ||
40 | { | 40 | { |
41 | return [ | 41 | return [ |
42 | 'slug' => [ | 42 | 'slug' => [ |
43 | - 'class' => 'common\behaviors\Slug', | 43 | + 'class' => 'artweb\artbox\ecommerce\behaviors\Slug', |
44 | ], | 44 | ], |
45 | ]; | 45 | ]; |
46 | } | 46 | } |
models/TaxGroupToCategory.php
models/TaxOption.php
@@ -2,10 +2,8 @@ | @@ -2,10 +2,8 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\behaviors\SaveImgBehavior; | ||
6 | - use common\modules\language\behaviors\LanguageBehavior; | ||
7 | - use artweb\artbox\ecommerce\models\Product; | ||
8 | - use artweb\artbox\ecommerce\models\ProductVariant; | 5 | + use artweb\artbox\behaviors\SaveImgBehavior; |
6 | + use artweb\artbox\language\behaviors\LanguageBehavior; | ||
9 | use Yii; | 7 | use Yii; |
10 | use yii\db\ActiveQuery; | 8 | use yii\db\ActiveQuery; |
11 | use yii\db\ActiveRecord; | 9 | use yii\db\ActiveRecord; |
models/TaxOptionLang.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | 2 | ||
3 | namespace artweb\artbox\ecommerce\models; | 3 | namespace artweb\artbox\ecommerce\models; |
4 | 4 | ||
5 | - use common\modules\language\models\Language; | 5 | + use artweb\artbox\language\models\Language; |
6 | use Yii; | 6 | use Yii; |
7 | use yii\db\ActiveRecord; | 7 | use yii\db\ActiveRecord; |
8 | 8 | ||
@@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
39 | { | 39 | { |
40 | return [ | 40 | return [ |
41 | 'slug' => [ | 41 | 'slug' => [ |
42 | - 'class' => 'common\behaviors\Slug', | 42 | + 'class' => 'artweb\artbox\ecommerce\behaviors\Slug', |
43 | 'inAttribute' => 'value', | 43 | 'inAttribute' => 'value', |
44 | ], | 44 | ], |
45 | ]; | 45 | ]; |
views/manage/_form.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | - use common\modules\language\widgets\LanguageForm; | 3 | + use artweb\artbox\language\widgets\LanguageForm; |
4 | use artweb\artbox\ecommerce\models\Brand; | 4 | use artweb\artbox\ecommerce\models\Brand; |
5 | use artweb\artbox\ecommerce\models\ProductLang; | 5 | use artweb\artbox\ecommerce\models\ProductLang; |
6 | use artweb\artbox\ecommerce\models\TaxGroup; | 6 | use artweb\artbox\ecommerce\models\TaxGroup; |
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | use yii\helpers\Html; | 8 | use yii\helpers\Html; |
9 | use yii\widgets\ActiveForm; | 9 | use yii\widgets\ActiveForm; |
10 | use yii\helpers\ArrayHelper; | 10 | use yii\helpers\ArrayHelper; |
11 | - use common\components\artboxtree\ArtboxTreeHelper; | 11 | + use artweb\artbox\ecommerce\components\artboxtree\ArtboxTreeHelper; |
12 | use artweb\artbox\ecommerce\helpers\ProductHelper; | 12 | use artweb\artbox\ecommerce\helpers\ProductHelper; |
13 | use kartik\select2\Select2; | 13 | use kartik\select2\Select2; |
14 | 14 |
views/manage/_form_language.php
1 | <?php | 1 | <?php |
2 | - use common\modules\language\models\Language; | 2 | + use artweb\artbox\language\models\Language; |
3 | use artweb\artbox\ecommerce\models\ProductLang; | 3 | use artweb\artbox\ecommerce\models\ProductLang; |
4 | use mihaildev\ckeditor\CKEditor; | 4 | use mihaildev\ckeditor\CKEditor; |
5 | use mihaildev\elfinder\ElFinder; | 5 | use mihaildev\elfinder\ElFinder; |
views/manage/export.php
views/manage/index.php
@@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
8 | use yii\helpers\Html; | 8 | use yii\helpers\Html; |
9 | use yii\grid\GridView; | 9 | use yii\grid\GridView; |
10 | use kartik\select2\Select2; | 10 | use kartik\select2\Select2; |
11 | - use common\components\artboxtree\ArtboxTreeHelper; | 11 | + use artweb\artbox\ecommerce\components\artboxtree\ArtboxTreeHelper; |
12 | use artweb\artbox\ecommerce\helpers\ProductHelper; | 12 | use artweb\artbox\ecommerce\helpers\ProductHelper; |
13 | use yii\web\View; | 13 | use yii\web\View; |
14 | 14 |
views/product-unit/_form.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | - use common\modules\language\widgets\LanguageForm; | 3 | + use artweb\artbox\language\widgets\LanguageForm; |
4 | use artweb\artbox\ecommerce\models\ProductUnit; | 4 | use artweb\artbox\ecommerce\models\ProductUnit; |
5 | use artweb\artbox\ecommerce\models\ProductUnitLang; | 5 | use artweb\artbox\ecommerce\models\ProductUnitLang; |
6 | use yii\helpers\Html; | 6 | use yii\helpers\Html; |
views/product-unit/_form_language.php
1 | <?php | 1 | <?php |
2 | - use common\modules\language\models\Language; | 2 | + use artweb\artbox\language\models\Language; |
3 | use artweb\artbox\ecommerce\models\ProductUnitLang; | 3 | use artweb\artbox\ecommerce\models\ProductUnitLang; |
4 | use yii\web\View; | 4 | use yii\web\View; |
5 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
views/tax-group/_form.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | - use common\modules\language\widgets\LanguageForm; | 3 | + use artweb\artbox\language\widgets\LanguageForm; |
4 | use artweb\artbox\ecommerce\models\TaxGroup; | 4 | use artweb\artbox\ecommerce\models\TaxGroup; |
5 | use artweb\artbox\ecommerce\models\TaxGroupLang; | 5 | use artweb\artbox\ecommerce\models\TaxGroupLang; |
6 | use yii\helpers\Html; | 6 | use yii\helpers\Html; |
7 | use yii\web\View; | 7 | use yii\web\View; |
8 | use yii\widgets\ActiveForm; | 8 | use yii\widgets\ActiveForm; |
9 | use artweb\artbox\ecommerce\helpers\ProductHelper; | 9 | use artweb\artbox\ecommerce\helpers\ProductHelper; |
10 | - use common\components\artboxtree\ArtboxTreeHelper; | 10 | + use artweb\artbox\ecommerce\components\artboxtree\ArtboxTreeHelper; |
11 | 11 | ||
12 | /** | 12 | /** |
13 | * @var View $this | 13 | * @var View $this |
views/tax-group/_form_language.php
1 | <?php | 1 | <?php |
2 | - use common\modules\language\models\Language; | 2 | + use artweb\artbox\language\models\Language; |
3 | use artweb\artbox\ecommerce\models\TaxGroupLang; | 3 | use artweb\artbox\ecommerce\models\TaxGroupLang; |
4 | use yii\web\View; | 4 | use yii\web\View; |
5 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
views/tax-option/_form.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | - use common\modules\language\widgets\LanguageForm; | 3 | + use artweb\artbox\language\widgets\LanguageForm; |
4 | use artweb\artbox\ecommerce\models\TaxGroup; | 4 | use artweb\artbox\ecommerce\models\TaxGroup; |
5 | use artweb\artbox\ecommerce\models\TaxOptionLang; | 5 | use artweb\artbox\ecommerce\models\TaxOptionLang; |
6 | use yii\helpers\ArrayHelper; | 6 | use yii\helpers\ArrayHelper; |
@@ -54,7 +54,7 @@ | @@ -54,7 +54,7 @@ | ||
54 | 'gif', | 54 | 'gif', |
55 | 'png', | 55 | 'png', |
56 | ], | 56 | ], |
57 | - 'initialPreview' => !empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage( | 57 | + 'initialPreview' => !empty( $model->imageUrl ) ? \artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper::getImage( |
58 | $model->imageUrl, | 58 | $model->imageUrl, |
59 | 'list' | 59 | 'list' |
60 | ) : '', | 60 | ) : '', |
views/tax-option/_form_language.php
1 | <?php | 1 | <?php |
2 | - use common\modules\language\models\Language; | 2 | + use artweb\artbox\language\models\Language; |
3 | use artweb\artbox\ecommerce\models\TaxOptionLang; | 3 | use artweb\artbox\ecommerce\models\TaxOptionLang; |
4 | use yii\web\View; | 4 | use yii\web\View; |
5 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
views/variant/_form.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | - use common\modules\language\widgets\LanguageForm; | 3 | + use artweb\artbox\language\widgets\LanguageForm; |
4 | use artweb\artbox\ecommerce\models\Product; | 4 | use artweb\artbox\ecommerce\models\Product; |
5 | use artweb\artbox\ecommerce\models\ProductStock; | 5 | use artweb\artbox\ecommerce\models\ProductStock; |
6 | use artweb\artbox\ecommerce\models\ProductUnit; | 6 | use artweb\artbox\ecommerce\models\ProductUnit; |
views/variant/_form_language.php
1 | <?php | 1 | <?php |
2 | - use common\modules\language\models\Language; | 2 | + use artweb\artbox\language\models\Language; |
3 | use artweb\artbox\ecommerce\models\ProductVariantLang; | 3 | use artweb\artbox\ecommerce\models\ProductVariantLang; |
4 | use yii\web\View; | 4 | use yii\web\View; |
5 | use yii\widgets\ActiveForm; | 5 | use yii\widgets\ActiveForm; |
1 | +<?php | ||
2 | + | ||
3 | + namespace artweb\artbox\ecommerce\widgets; | ||
4 | + | ||
5 | + use artweb\artbox\ecommerce\models\ProductVariant; | ||
6 | + use yii\base\Widget; | ||
7 | + | ||
8 | + class BasketHead extends Widget | ||
9 | + { | ||
10 | + | ||
11 | + public function init() | ||
12 | + { | ||
13 | + | ||
14 | + parent::init(); | ||
15 | + | ||
16 | + } | ||
17 | + | ||
18 | + public function run() | ||
19 | + { | ||
20 | + $sessionData = \Yii::$app->session->get('order'); | ||
21 | + unset( $sessionData[ 'order_id' ] ); | ||
22 | + $count = count($sessionData); | ||
23 | + $price = 0; | ||
24 | + if (is_array($sessionData) && !empty( $sessionData )) { | ||
25 | + | ||
26 | + $variant = ProductVariant::find() | ||
27 | + ->where([ 'product_variant_id' => array_keys($sessionData) ]) | ||
28 | + ->indexBy('product_variant_id') | ||
29 | + ->all(); | ||
30 | + | ||
31 | + foreach ($sessionData as $k => $item) { | ||
32 | + $sessionData[ $k ][ 'item' ] = $variant[ $k ]; | ||
33 | + $price += $variant[ $k ]->price * $sessionData[ $k ][ 'num' ]; | ||
34 | + } | ||
35 | + | ||
36 | + return $this->render( | ||
37 | + 'basket_head', | ||
38 | + [ | ||
39 | + 'items' => $sessionData, | ||
40 | + 'count' => $count, | ||
41 | + 'price' => $price, | ||
42 | + ] | ||
43 | + ); | ||
44 | + | ||
45 | + } | ||
46 | + | ||
47 | + } | ||
48 | + } | ||
49 | + | ||
0 | \ No newline at end of file | 50 | \ No newline at end of file |
1 | +<?php | ||
2 | + namespace artweb\artbox\ecommerce\widgets; | ||
3 | + | ||
4 | + use artweb\artbox\ecommerce\models\ProductVariant; | ||
5 | + use yii\base\Widget; | ||
6 | + | ||
7 | + class BasketModal extends Widget | ||
8 | + { | ||
9 | + | ||
10 | + public function init() | ||
11 | + { | ||
12 | + | ||
13 | + parent::init(); | ||
14 | + | ||
15 | + } | ||
16 | + | ||
17 | + public function run() | ||
18 | + { | ||
19 | + $sessionData = \Yii::$app->session->get('order'); | ||
20 | + unset( $sessionData[ 'order_id' ] ); | ||
21 | + $count = count($sessionData); | ||
22 | + $price = 0; | ||
23 | + if (is_array($sessionData) && !empty( $sessionData )) { | ||
24 | + | ||
25 | + $variant = ProductVariant::find() | ||
26 | + ->where([ 'product_variant_id' => array_keys($sessionData) ]) | ||
27 | + ->indexBy('product_variant_id') | ||
28 | + ->all(); | ||
29 | + | ||
30 | + foreach ($sessionData as $k => $item) { | ||
31 | + $sessionData[ $k ][ 'item' ] = $variant[ $k ]; | ||
32 | + $price += $variant[ $k ]->price * $sessionData[ $k ][ 'num' ]; | ||
33 | + } | ||
34 | + | ||
35 | + return $this->render( | ||
36 | + 'basket_modal', | ||
37 | + [ | ||
38 | + 'items' => $sessionData, | ||
39 | + 'count' => $count, | ||
40 | + 'price' => $price, | ||
41 | + ] | ||
42 | + ); | ||
43 | + | ||
44 | + } | ||
45 | + | ||
46 | + } | ||
47 | + | ||
48 | + } | ||
49 | + | ||
0 | \ No newline at end of file | 50 | \ No newline at end of file |
1 | +<?php | ||
2 | +use yii\bootstrap\Html; | ||
3 | +?> | ||
4 | +<div class="basket_head"> | ||
5 | + <img src="/images/ico_basket.png" class="bh_cell img"> | ||
6 | + <div class="bh_cell text"> | ||
7 | + <div class="basket_head_title"><?= Yii::t('app','basket');?> <?= $count? Html::tag('span',$count,['class'=>'head_basket_count']) :'' ?></div> | ||
8 | + </div> | ||
9 | + <i class="head-down bh_cell"></i> | ||
10 | +</div> |
1 | +<?php | ||
2 | +/** | ||
3 | + * @var $items array data from session | ||
4 | + * @var $count integer count items in basket | ||
5 | + */ | ||
6 | +use yii\helpers\Html; | ||
7 | + | ||
8 | +?> | ||
9 | +<div class="order_list"> | ||
10 | + <ul> | ||
11 | + <?php foreach($items as $item){ | ||
12 | + | ||
13 | + ?> | ||
14 | + | ||
15 | + <li> | ||
16 | + <div class="order_list_li" data-id="<?= $item['item']->product_variant_id?>"> | ||
17 | + <div class="delete_item_btn"><i class="fa fa-times"></i></div> | ||
18 | + <div class="little_img"> | ||
19 | + <?php if (empty($item['item']->product->image)) :?> | ||
20 | + <img src="/images/no_photo.png"> | ||
21 | + <?php else :?> | ||
22 | + <img src="/images/<?= $item['item']->product->image->image?>" alt="<?= $item['item']->product->image->alt ? $item['item']->product->image->alt : $item['item']->product->name?>"> | ||
23 | + <?php endif?> | ||
24 | + </div> | ||
25 | + <div class="name_and_code"> | ||
26 | + <span class="name"><?=$item['item']->product->name.' '.$item['item']->name?></span> | ||
27 | + <span class="code"><?= Yii::t('app', 'code', '45885-01016049')?></span> | ||
28 | + </div> | ||
29 | + <div class="count_block_wrap"> | ||
30 | + <div class="count_block"> | ||
31 | + <input type="text" name="" class="form-control buy_one_item" value="<?= $item['num']?>"> | ||
32 | + <div class="count_buttons"> | ||
33 | + <div class="button_plus">+</div> | ||
34 | + <div class="button_minus">-</div> | ||
35 | + </div> | ||
36 | + </div> | ||
37 | + <div class="price"><span class="price_val" data-price="<?= $item['item']->price ?>"><?= $item['item']->price * $item['num'] ?></span><span class="price_text">грн.</span></div> | ||
38 | + </div> | ||
39 | + </div> | ||
40 | + </li> | ||
41 | + <?php } ?> | ||
42 | + | ||
43 | + </ul> | ||
44 | + <hr> | ||
45 | + <div class="all_price"> | ||
46 | + <p><?= Yii::t('app','articles')?>: <span class="all_count"><?= $count ?></span></p> | ||
47 | + <p><?= Yii::t('app','sum')?>: <span class="all_price all_price_span"><?= $price ?></span> грн.</p> | ||
48 | + </div> | ||
49 | + <div class="busket_bottom_btn"> | ||
50 | + <?= Html::a(Yii::t('app','continue_shopping'),'#', ['class'=> 'close']) ?> | ||
51 | + <?= Html::a(Yii::t('app','checkout'), ['orders/first'], ['class'=> 'button']);?> | ||
52 | + </div> | ||
53 | +</div> |
widgets/views/brandsCarousel.php
@@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
2 | /** | 2 | /** |
3 | * @var Brand[] $brands | 3 | * @var Brand[] $brands |
4 | */ | 4 | */ |
5 | - use common\components\artboximage\ArtboxImageHelper; | 5 | + use artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper; |
6 | use artweb\artbox\ecommerce\models\Brand; | 6 | use artweb\artbox\ecommerce\models\Brand; |
7 | 7 | ||
8 | ?> | 8 | ?> |
widgets/views/product_smart.php
@@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
29 | 'product' => $product->lang->alias, | 29 | 'product' => $product->lang->alias, |
30 | ] | 30 | ] |
31 | ) ?>"> | 31 | ) ?>"> |
32 | - <?= \common\components\artboximage\ArtboxImageHelper::getImage( | 32 | + <?= \artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper::getImage( |
33 | $product->enabledVariants[ 0 ]->imageUrl, | 33 | $product->enabledVariants[ 0 ]->imageUrl, |
34 | 'list', | 34 | 'list', |
35 | [ | 35 | [ |
widgets/views/submenu.php
@@ -28,7 +28,7 @@ | @@ -28,7 +28,7 @@ | ||
28 | <?php if(empty( $_item[ 'item' ]->image )) : ?> | 28 | <?php if(empty( $_item[ 'item' ]->image )) : ?> |
29 | <img src="/images/no_photo.png"> | 29 | <img src="/images/no_photo.png"> |
30 | <?php else : ?> | 30 | <?php else : ?> |
31 | - <?= $_item[ 'item' ]->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($_item[ 'item' ]->imageUrl, 'mainmenu') : '' ?> | 31 | + <?= $_item[ 'item' ]->imageUrl ? \artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper::getImage($_item[ 'item' ]->imageUrl, 'mainmenu') : '' ?> |
32 | <?php endif ?> | 32 | <?php endif ?> |
33 | </div> | 33 | </div> |
34 | <div class="title"><?= $_item[ 'item' ]->title ?></div> | 34 | <div class="title"><?= $_item[ 'item' ]->title ?></div> |