diff --git a/behaviors/DefaultVariantBehavior.php b/behaviors/DefaultVariantBehavior.php
new file mode 100644
index 0000000..c52d641
--- /dev/null
+++ b/behaviors/DefaultVariantBehavior.php
@@ -0,0 +1,115 @@
+ 'addDefaultVariant',
+ ];
+ }
+
+ /**
+ * Creates new default product's variant and sets it's to stock
+ * marked as default and sets to it unit also marked as default
+ */
+ public function addDefaultVariant()
+ {
+ /**
+ * @var Stock $stock
+ * @var ProductUnit $defaultUnit
+ */
+ $defaultVariant = new ProductVariant();
+ $defaultVariant->product_id = $this->owner->id;
+
+ /**
+ * Gets default unit for variant
+ */
+ $defaultUnit = ProductUnit::find()
+ ->where(
+ [
+ 'is_default' => true,
+ ]
+ )
+ ->one();
+ $defaultVariant->product_unit_id = $defaultUnit->id;
+ $defaultVariant->stock = 1;
+
+ $defaultVariant->sku = 'default';
+ $defaultVariant->remote_id = time();
+ $defaultVariant->save();
+
+ /**
+ * Saving languages
+ */
+ $activeLanguageIds = Language::find()
+ ->select('id')
+ ->where(
+ [
+ 'status' => true,
+ ]
+ )
+ ->asArray()
+ ->column();
+ foreach ($activeLanguageIds as $languageId) {
+ $variantLanguage = new ProductVariantLang();
+ $variantLanguage->language_id = $languageId;
+ $variantLanguage->product_variant_id = $defaultVariant->id;
+ $variantLanguage->title = 'default_' . $languageId;
+ $variantLanguage->save();
+ }
+ /**
+ * Gets default stock
+ */
+ $stock = Stock::find()
+ ->one();
+
+ // $image = ProductImage::find()
+ // ->where(
+ // [
+ // 'product_id' => $this->owner->product_id,
+ // ]
+ // )
+ // ->one();
+ // $image->product_variant_id = $defaultVariant->product_variant_id;
+ // $image->save();
+
+ /**
+ * Add a new stock record
+ */
+ $defaultStock = new ProductStock();
+ $defaultStock->product_variant_id = $defaultVariant->id;
+ $defaultStock->stock_id = $stock->id;
+ $defaultStock->quantity = $defaultVariant->stock;
+ $defaultStock->save();
+ }
+
+ }
+
\ No newline at end of file
diff --git a/behaviors/FilterBehavior.php b/behaviors/FilterBehavior.php
index 6bd7aed..83ccf96 100755
--- a/behaviors/FilterBehavior.php
+++ b/behaviors/FilterBehavior.php
@@ -12,7 +12,6 @@
public function getFilters()
{
-
/**
* @var ActiveRecord $owner
*/
@@ -23,4 +22,5 @@
->all();
}
- }
\ No newline at end of file
+ }
+
\ No newline at end of file
diff --git a/composer.json b/composer.json
index a5453b2..6735bf4 100644
--- a/composer.json
+++ b/composer.json
@@ -5,7 +5,12 @@
"require": {
"php": ">=7.0",
"yiisoft/yii2": "*",
- "developeruz/yii2-db-rbac": "*"
+ "developeruz/yii2-db-rbac": "*",
+ "artweb/artbox": "dev-master",
+ "artweb/artbox/language": "dev-master",
+ "yiisoft/yii2-faker": "*",
+ "artweb/artbox/seo": "dev-master",
+ "wbraganca/yii2-dynamicform": "dev-master"
},
"autoload": {
"psr-4": {
diff --git a/console/GenerateController.php b/console/GenerateController.php
new file mode 100644
index 0000000..ed0b4c9
--- /dev/null
+++ b/console/GenerateController.php
@@ -0,0 +1,285 @@
+ 'ru_RU',
+ 3 => 'uk_UA',
+ ];
+
+ /**
+ * Faker Generators instances
+ *
+ * @var Generator[] $fakers
+ */
+ private $fakers = [];
+
+ /**
+ * Create faker Generators for all $locales
+ *
+ * @param \yii\base\Action $action
+ *
+ * @return bool
+ */
+ public function beforeAction($action)
+ {
+ $parent = parent::beforeAction($action);
+ $fakers = [];
+ foreach ($this->locales as $locale_id => $locale) {
+ $fakers[ $locale_id ] = Factory::create($locale);
+ }
+ $this->fakers = $fakers;
+ return $parent;
+ }
+
+ /**
+ * Generate fake Brands
+ *
+ * @param int $count Brands count
+ *
+ * @return int
+ */
+ public function actionBrand(int $count = 10): int
+ {
+ /**
+ * @var Brand[] $models
+ */
+ $models = [];
+ $fakers = $this->fakers;
+ for ($i = 0; $i < $count; $i++) {
+ $models[ $i ] = \Yii::createObject(Brand::className());
+ $models[ $i ]->generateLangs();
+ foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) {
+ $modelLang->title = $fakers[ $language_id ]->company;
+ }
+ if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) {
+ $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW);
+ $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW);
+ echo "Brand '$title' inserted under $id ID.\n";
+ };
+ }
+ return 0;
+ }
+
+ /**
+ * Generate fake categories
+ *
+ * @param int $count Category count
+ *
+ * @return int
+ */
+ public function actionCategory(int $count = 10):int
+ {
+ /**
+ * @var Category[] $models
+ */
+ $models = [];
+ $fakers = $this->fakers;
+ for ($i = 0; $i < $count; $i++) {
+ $models[ $i ] = \Yii::createObject(
+ [
+ 'class' => Category::className(),
+ 'depth' => 0,
+ 'parent_id' => 0,
+ ]
+ );
+ $models[ $i ]->generateLangs();
+ foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) {
+ $modelLang->title = ucfirst($fakers[ $language_id ]->word);
+ }
+ if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) {
+ $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW);
+ $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW);
+ echo "Category '$title' inserted under $id ID.\n";
+ };
+ }
+ return 0;
+ }
+
+ /**
+ * Generate fake products with variants, categories and tax options
+ *
+ * @param int $count Product count
+ *
+ * @return int
+ */
+ public function actionProduct(int $count = 10):int
+ {
+ /**
+ * @var Product[] $models
+ */
+ $models = [];
+ $fakers = $this->fakers;
+ $brands = Brand::find()
+ ->limit(20)
+ ->asArray()
+ ->column();
+ $categories = Category::find()
+ ->limit(100)
+ ->asArray()
+ ->column();
+ $product_options = TaxOption::find()
+ ->joinWith('taxGroup')
+ ->where([ 'tax_group.level' => TaxGroup::GROUP_PRODUCT ])
+ ->limit(50)
+ ->asArray()
+ ->column();
+ $variant_options = TaxOption::find()
+ ->joinWith('taxGroup')
+ ->where([ 'tax_group.level' => TaxGroup::GROUP_VARIANT ])
+ ->limit(50)
+ ->asArray()
+ ->column();
+ for ($i = 0; $i < $count; $i++) {
+ $models[ $i ] = \Yii::createObject(
+ [
+ 'class' => Product::className(),
+ 'brand_id' => $fakers[ 2 ]->randomElement($brands),
+ ]
+ );
+ $models[ $i ]->setCategories(
+ $fakers[ 2 ]->randomElements($categories, $fakers[ 2 ]->randomDigitNotNull)
+ );
+ $models[ $i ]->setOptions(
+ $fakers[ 2 ]->randomElements($product_options, $fakers[ 2 ]->randomDigitNotNull)
+ );
+ $models[ $i ]->generateLangs();
+ foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) {
+ $modelLang->title = ucfirst($fakers[ $language_id ]->word);
+ }
+ if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) {
+ $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW);
+ $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW);
+ echo "Product '$title' inserted under $id ID.\n";
+ $variant_count = $fakers[ 2 ]->numberBetween(4, 10);
+ for ($j = 0; $j < $variant_count; $j++) {
+ /**
+ * @var ProductVariant $variant
+ */
+ $variant = \Yii::createObject(
+ [
+ 'class' => ProductVariant::className(),
+ 'product_id' => $models[ $i ]->id,
+ 'sku' => $fakers[ 2 ]->uuid,
+ 'price' => $fakers[ 2 ]->randomFloat(2, 100, 10000),
+ 'stock' => 10,
+ 'product_unit_id' => 1,
+ ]
+ );
+ $variant->setOptions(
+ $fakers[ 2 ]->randomElements($variant_options, $fakers[ 2 ]->randomDigitNotNull)
+ );
+ $variant->generateLangs();
+ foreach ($variant->modelLangs as $variant_language_id => $variantLang) {
+ $variantLang->title = ucfirst($fakers[ $variant_language_id ]->word);
+ }
+ if ($variant->save() && $variant->transactionStatus) {
+ $variant_title = $this->ansiFormat($variant->modelLangs[ 2 ]->title, Console::FG_YELLOW);
+ $variant_id = $this->ansiFormat($variant->id, Console::FG_YELLOW);
+ echo "Variant '$variant_title' inserted under $variant_id ID for product $title.\n";
+ }
+ }
+ };
+ }
+ return 0;
+ }
+
+ /**
+ * Generate fake tax groups with tax options.
+ *
+ * @param int $count_product Tax Groups for Product
+ * @param int $count_variant Tax Groups for ProductVariant
+ *
+ * @return int
+ */
+ public function actionTax(int $count_product = 10, int $count_variant = 10):int
+ {
+ $categories = Category::find()
+ ->asArray()
+ ->column();
+ $this->generateTax(TaxGroup::GROUP_PRODUCT, $count_product, $categories);
+ $this->generateTax(TaxGroup::GROUP_VARIANT, $count_variant, $categories);
+ return 0;
+ }
+
+ /**
+ * Generates tax groups amd tax options for actionTax
+ *
+ * @param int $level Tax Group for Product or ProductVariant
+ * @param int $count Tax Group count
+ * @param array $categories Categories for Tax Groups
+ *
+ * @see GenerateController::actionTax()
+ */
+ private function generateTax(int $level, int $count, array $categories = [])
+ {
+ $count_option = 10;
+ $fakers = $this->fakers;
+ /**
+ * @var TaxGroup[] $models
+ */
+ $models = [];
+ for ($i = 0; $i < $count; $i++) {
+ $models[ $i ] = \Yii::createObject(
+ [
+ 'class' => TaxGroup::className(),
+ 'is_filter' => true,
+ 'display' => true,
+ ]
+ );
+ $models[ $i ]->level = $level;
+ $models[ $i ]->setCategories($categories);
+ $models[ $i ]->generateLangs();
+ foreach ($models[ $i ]->modelLangs as $language_id => $modelLang) {
+ $modelLang->title = ucfirst($fakers[ $language_id ]->word);
+ }
+ if ($models[ $i ]->save() && $models[ $i ]->transactionStatus) {
+ for ($j = 0; $j < $count_option; $j++) {
+ /**
+ * @var TaxOption $option
+ */
+ $option = \Yii::createObject(
+ TaxOption::className()
+ );
+ $option->tax_group_id = $models[ $i ]->id;
+ $option->generateLangs();
+ foreach ($option->modelLangs as $option_language_id => $taxOptionLang) {
+ $taxOptionLang->value = ucfirst($fakers[ $option_language_id ]->word);
+ }
+ $option->save();
+ }
+ $title = $this->ansiFormat($models[ $i ]->modelLangs[ 2 ]->title, Console::FG_YELLOW);
+ $id = $this->ansiFormat($models[ $i ]->id, Console::FG_YELLOW);
+ $element = $this->ansiFormat(
+ ( $level === TaxGroup::GROUP_PRODUCT ) ? 'Product' : 'Variant',
+ Console::FG_RED
+ );
+ echo "Category '$title' inserted for $element under $id ID.\n";
+ };
+ }
+ }
+ }
+
\ No newline at end of file
diff --git a/console/ImportController.php b/console/ImportController.php
new file mode 100755
index 0000000..ab1b346
--- /dev/null
+++ b/console/ImportController.php
@@ -0,0 +1,64 @@
+stderr('Task already executed');
+ return Controller::EXIT_CODE_ERROR;
+ }
+ return fopen ($filename, 'r');
+ }
+
+ public function actionProducts() {
+// if (file_exists(Yii::getAlias('@uploadDir/goProducts.lock'))) {
+// $this->errors[] = 'Task already executed';
+// return Controller::EXIT_CODE_ERROR;
+// }
+// $ff = fopen(Yii::getAlias('@uploadDir/goProducts.lock'), 'w+');
+// fclose($ff);
+ $model = new Import();
+ $model->goProducts(0, null);
+// unlink(Yii::getAlias('@uploadDir/goProducts.lock'));
+ return Controller::EXIT_CODE_NORMAL;
+ }
+
+ public function actionPrices() {
+ if (file_exists(Yii::getAlias('@uploadDir/goPrices.lock'))) {
+ $this->stderr('Task already executed');
+ return Controller::EXIT_CODE_ERROR;
+ }
+ $ff = fopen(Yii::getAlias('@uploadDir/goPrices.lock'), 'w+');
+ fclose($ff);
+ $model = new Import();
+ $data = $model->goPrices(0, null);
+ unlink(Yii::getAlias('@uploadDir/goPrices.lock'));
+ return Controller::EXIT_CODE_NORMAL;
+ }
+
+ private function saveNotFoundRecord (array $line, $filename)
+ {
+ $str = implode (';', $line)."\n";
+ $str = iconv ("UTF-8//TRANSLIT//IGNORE", "windows-1251", $str);
+
+ $fg = fopen (Yii::getAlias('@uploadDir') .'/'. $filename, 'a+');
+ fputs ($fg, $str);
+ fclose ($fg);
+ }
+}
\ No newline at end of file
diff --git a/console/SiteMapController.php b/console/SiteMapController.php
new file mode 100755
index 0000000..2e86e9a
--- /dev/null
+++ b/console/SiteMapController.php
@@ -0,0 +1,236 @@
+search($category, $filter);
+ if (!empty( $productProvider->models )) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function getAddStatic()
+ {
+ return [
+ 'http://www.rukzachok.com.ua',
+ 'http://www.rukzachok.com.ua/catalog',
+ ];
+ }
+
+ public function getProducts()
+ {
+ return Product::find()
+ ->all();
+
+ }
+
+ public function getSeoLinks()
+ {
+ return Seo::find()
+ ->where([ 'meta' => '' ])
+ ->all();
+
+ }
+
+ public function getStaticPages()
+ {
+ return Page::find()
+ ->all();
+ }
+
+ public function getCategories()
+ {
+ return Category::find()
+ ->all();
+ }
+
+ public function getBrands($category)
+ {
+
+ return $category->brands;
+ }
+
+ /**
+ * @param $category Category;
+ *
+ * @return mixed
+ */
+
+ public function getFilters($category)
+ {
+
+ return $category->getActiveFilters()
+ ->all();
+
+ }
+
+ public function checkUrl($url)
+ {
+ if (!in_array($url, $this->urlList)) {
+ $this->urlList[] = $url;
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ public function createRow($url, $priority, &$content)
+ {
+ if ($this->checkUrl($url)) {
+ print $this->count++ . "\n";
+ $content .= '' . '' . $url . '' . '' . date(
+ 'Y-m-d'
+ ) . '' . 'Daily' . '' . $priority . '' . '';
+ }
+ }
+
+ public function actionProcess()
+ {
+
+ $config = ArrayHelper::merge(
+ require( \Yii::getAlias('@frontend/config/') . 'main.php' ),
+ require( \Yii::getAlias('@common/config/') . 'main.php' )
+ );
+
+ Yii::$app->urlManager->addRules($config[ 'components' ][ 'urlManager' ][ 'rules' ]);
+
+ $dirName = Yii::getAlias('@frontend') . '/web';
+
+ $filename = 'sitemap.xml';
+
+ setlocale(LC_ALL, 'ru_RU.CP1251');
+ $handle = fopen($dirName . '/' . $filename, "w");
+
+ $content = '';
+
+ foreach ($this->getAddStatic() as $page) {
+ $this->createRow($page, 1, $content);
+ }
+
+ foreach ($this->getStaticPages() as $page) {
+ $url = Url::to(
+ [
+ 'text/index',
+ 'translit' => $page->translit,
+ ]
+ );
+ $this->createRow($url, 1, $content);
+ }
+
+ foreach ($this->getCategories() as $category) {
+ $url = Url::to(
+ [
+ 'catalog/category',
+ 'category' => $category,
+ ]
+ );
+ $this->createRow($url, 1, $content);
+ }
+
+ foreach ($this->getProducts() as $product) {
+
+ $url = Url::to(
+ [
+ 'catalog/product',
+ 'product' => $product,
+ ]
+ );
+ $this->createRow($url, 0.9, $content);
+ }
+
+ // foreach ($this->getArticles() as $article) {
+ //
+ // $url = Url::to(['articles/show', 'translit' => $article->translit, 'id' => $article->id,]);
+ // $this->createRow($url , 0.8,$content);
+ //
+ // }
+
+ foreach ($this->getCategories() as $category) {
+ foreach ($this->getBrands($category) as $brand) {
+ if ($this->checkFilter($category, [ 'brands' => [ $brand->id ] ])) {
+ $url = Url::to(
+ [
+ 'catalog/category',
+ 'category' => $category,
+ 'filters' => [ 'brands' => [ $brand->alias ] ],
+ ]
+ );
+ $this->createRow($url, 0.8, $content);
+ }
+ }
+ }
+
+ foreach ($this->getCategories() as $category) {
+ foreach ($this->getFilters($category) as $filter) {
+ if ($this->checkFilter($category, [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ])) {
+ $url = Url::to(
+ [
+ 'catalog/category',
+ 'category' => $category,
+ 'filters' => [ $filter[ 'group_alias' ] => [ $filter[ 'option_alias' ] ] ],
+ ]
+ );
+ $this->createRow($url, 0.8, $content);
+ }
+
+ }
+ }
+
+ foreach ($this->getSeoLinks() as $link) {
+ $url = Yii::$app->urlManager->baseUrl . $link->url;
+ $this->createRow($url, 0.7, $content);
+
+ }
+
+ // foreach($this->getCategories() as $category){
+ // foreach ($this->getFilters($category) as $filter1) {
+ // foreach ($this->getFilters($category) as $filter2) {
+ // if($this->checkFilter($category, [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] )){
+ // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => [$filter1['group_alias'] => [$filter1['option_alias']],$filter2['group_alias'] => [$filter2['option_alias']]] ]);
+ // $this->createRow($url , 0.7, $content);
+ // }
+ //
+ // }
+ //
+ // foreach ($this->getBrands($category) as $brand) {
+ // if($this->checkFilter($category, ['brands' => [$brand->id], $filter1['group_alias'] => [$filter1['option_alias']]] )){
+ // $url = Url::to(['catalog/category', 'category' => $category, 'filters' => ['brands' => [$brand->alias],$filter1['group_alias'] => [$filter1['option_alias']]]]);
+ // $this->createRow($url , 0.7,$content);
+ // }
+ //
+ // }
+ // }
+ // }
+
+ $content .= '';
+
+ fwrite($handle, $content);
+ fclose($handle);
+
+ print $dirName . '/' . $filename;
+ }
+
+ }
diff --git a/controllers/ManageController.php b/controllers/ManageController.php
index 22637d0..c66381f 100755
--- a/controllers/ManageController.php
+++ b/controllers/ManageController.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\controllers;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use artweb\artbox\ecommerce\models\Export;
use artweb\artbox\ecommerce\models\Import;
use artweb\artbox\ecommerce\models\ProductImage;
diff --git a/controllers/TaxGroupController.php b/controllers/TaxGroupController.php
index 58ec043..b06b045 100755
--- a/controllers/TaxGroupController.php
+++ b/controllers/TaxGroupController.php
@@ -5,7 +5,6 @@
use artweb\artbox\ecommerce\models\TaxGroupSearch;
use Yii;
use artweb\artbox\ecommerce\models\TaxGroup;
- use yii\data\ActiveDataProvider;
use yii\db\ActiveQuery;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
diff --git a/models/Basket.php b/models/Basket.php
new file mode 100755
index 0000000..a03b01e
--- /dev/null
+++ b/models/Basket.php
@@ -0,0 +1,197 @@
+session = \Yii::$app->session;
+ if (!$this->session->has('basket')) {
+ $this->session->set('basket', []);
+ }
+ parent::__construct($config);
+ }
+
+ /**
+ * Increment product variant with $product_variant_id count by 1
+ *
+ * @param int $product_variant_id
+ */
+ public function add(int $product_variant_id)
+ {
+ $data = $this->getData();
+ if (array_key_exists($product_variant_id, $data)) {
+ if ($data[ $product_variant_id ][ 'count' ] <= 0) {
+ $data[ $product_variant_id ] = 1;
+ } else {
+ $data[ $product_variant_id ][ 'count' ] += 1;
+ }
+ } else {
+ if ($this->findModel($product_variant_id)) {
+ $data[ $product_variant_id ] = [
+ 'count' => 1,
+ ];
+ }
+ }
+ $this->setData($data);
+ }
+
+ /**
+ * Set product variant with $product_variant_id to $count
+ *
+ * @param int $product_variant_id
+ * @param int $count
+ */
+ private function set(int $product_variant_id, int $count)
+ {
+ $data = $this->getData();
+ if (array_key_exists($product_variant_id, $data)) {
+ $data[ $product_variant_id ][ 'count' ] = $count;
+ if ($data[ $product_variant_id ][ 'count' ] <= 0) {
+ unset( $data[ $product_variant_id ] );
+ }
+ } elseif ($count > 0) {
+ if ($this->findModel($product_variant_id)) {
+ $data[ $product_variant_id ] = [
+ 'count' => $count,
+ ];
+ }
+ }
+ $this->setData($data);
+ }
+
+ /**
+ * Delete product variant with $product_variant_id from basket
+ *
+ * @param int $product_variant_id
+ */
+ public function delete(int $product_variant_id)
+ {
+ $this->set($product_variant_id, 0);
+ }
+
+ /**
+ * Get basket data
+ *
+ * @return array
+ */
+ public function getData(): array
+ {
+ return $this->session->get('basket');
+ }
+
+ /**
+ * Get basket item with $product_variant_id. Returns false if item not in basket.
+ *
+ * @param int $product_variant_id
+ *
+ * @return bool|array
+ */
+ public function getItem(int $product_variant_id)
+ {
+ $data = $this->getData();
+ if (!empty( $data[ $product_variant_id ] )) {
+ return $data[ $product_variant_id ];
+ } else {
+ return false;
+ }
+ }
+
+ /**
+ * Set basket data
+ *
+ * @param array $data
+ */
+ public function setData(array $data)
+ {
+ $this->session->set('basket', $data);
+ }
+
+ /**
+ * Get count of product variants in basket
+ *
+ * @return int
+ */
+ public function getCount(): int
+ {
+ $data = $this->getData();
+ return count($data);
+ }
+
+ /**
+ * Find Product Variant by $product_variant_id
+ *
+ * @param int $product_variant_id
+ *
+ * @return \artweb\artbox\ecommerce\models\ProductVariant
+ * @throws \yii\web\NotFoundHttpException
+ */
+ public function findModel(int $product_variant_id): ProductVariant
+ {
+ /**
+ * @var ProductVariant $model
+ */
+ $model = ProductVariant::find()
+ ->where([ 'product_variant.id' => $product_variant_id ])
+ ->joinWith('lang', true, 'INNER JOIN')
+ ->one();
+ if (empty( $model )) {
+ throw new NotFoundHttpException(\Yii::t('app', 'Product not found'));
+ } else {
+ return $model;
+ }
+ }
+
+ /**
+ * Find all Product Variants filtered by $product_variant_ids
+ *
+ * @param array $product_variant_ids
+ *
+ * @return ProductVariant[]
+ */
+ public function findModels(array $product_variant_ids)
+ {
+ return ProductVariant::find()
+ ->where([ 'product_variant.id' => $product_variant_ids ])
+ ->joinWith('lang', true, 'INNER JOIN')
+ ->with(
+ [
+ 'product',
+ 'image',
+ ]
+ )
+ ->all();
+ }
+
+ /**
+ * Clear basket
+ */
+ public function clear()
+ {
+ $this->setData([]);
+ }
+
+ }
+
\ No newline at end of file
diff --git a/models/Brand.php b/models/Brand.php
index bd4d78c..0c088f5 100755
--- a/models/Brand.php
+++ b/models/Brand.php
@@ -2,8 +2,8 @@
namespace artweb\artbox\ecommerce\models;
- use common\behaviors\SaveImgBehavior;
- use common\modules\language\behaviors\LanguageBehavior;
+ use artweb\artbox\behaviors\SaveImgBehavior;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
diff --git a/models/BrandLang.php b/models/BrandLang.php
index 36fcdff..6cbb07f 100755
--- a/models/BrandLang.php
+++ b/models/BrandLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
@@ -43,7 +43,7 @@
{
return [
'slug' => [
- 'class' => 'common\behaviors\Slug',
+ 'class' => 'artweb\artbox\ecommerce\behaviors\Slug',
],
];
}
diff --git a/models/Category.php b/models/Category.php
index c4eb1cc..b1e4208 100755
--- a/models/Category.php
+++ b/models/Category.php
@@ -2,11 +2,10 @@
namespace artweb\artbox\ecommerce\models;
- use common\behaviors\SaveImgBehavior;
- use common\components\artboxtree\ArtboxTreeBehavior;
- use common\modules\language\behaviors\LanguageBehavior;
- use common\modules\language\models\Language;
- use artweb\artbox\ecommerce\models\TaxGroup;
+ use artweb\artbox\behaviors\SaveImgBehavior;
+ use artweb\artbox\components\artboxtree\ArtboxTreeBehavior;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\base\InvalidParamException;
use yii\db\ActiveQuery;
diff --git a/models/CategoryLang.php b/models/CategoryLang.php
index 3a10105..0cbb513 100755
--- a/models/CategoryLang.php
+++ b/models/CategoryLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
@@ -42,7 +42,7 @@
{
return [
'slug' => [
- 'class' => 'common\behaviors\Slug',
+ 'class' => 'artweb\artbox\ecommerce\behaviors\Slug',
],
];
}
diff --git a/models/CategoryQuery.php b/models/CategoryQuery.php
index ed0b7d4..105210c 100755
--- a/models/CategoryQuery.php
+++ b/models/CategoryQuery.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\components\artboxtree\ArtboxTreeQueryTrait;
+ use artweb\artbox\components\artboxtree\ArtboxTreeQueryTrait;
use yii\db\ActiveQuery;
/**
diff --git a/models/Delivery.php b/models/Delivery.php
new file mode 100755
index 0000000..36287d6
--- /dev/null
+++ b/models/Delivery.php
@@ -0,0 +1,80 @@
+ [
+ 'class' => LanguageBehavior::className(),
+ 'objectLang' => OrderDeliveryLang::className(),
+ 'ownerKey' => 'id',
+ 'langKey' => 'order_delivery_id',
+ ],
+ ];
+ }
+
+ public static function tableName()
+ {
+ return 'order_delivery';
+ }
+
+ public function rules()
+ {
+ return [
+ [
+ [
+ 'value',
+ 'parent_id',
+ 'sort',
+ ],
+ 'integer',
+ ],
+ ];
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getParent()
+ {
+ return $this->hasOne(self::className(), [ 'id' => 'parent_id' ]);
+ }
+ }
\ No newline at end of file
diff --git a/models/DeliverySearch.php b/models/DeliverySearch.php
new file mode 100755
index 0000000..36db3ad
--- /dev/null
+++ b/models/DeliverySearch.php
@@ -0,0 +1,112 @@
+joinWith('lang')
+ ->joinWith([ 'parent as parent' ]);
+
+ // add conditions that should always apply here
+
+ $dataProvider = new ActiveDataProvider(
+ [
+ 'query' => $query,
+ 'sort' => [
+ 'attributes' => [
+ 'id',
+ 'value',
+ 'title' => [
+ 'asc' => [ 'order_delivery_lang.title' => SORT_ASC ],
+ 'desc' => [ 'order_delivery_lang.title' => SORT_DESC ],
+ ],
+ ],
+ ],
+ ]
+ );
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ // grid filtering conditions
+ $query->andFilterWhere(
+ [
+ 'id' => $this->id,
+ 'value' => $this->value,
+ 'sort' => $this->sort,
+ ]
+ )
+ ->andFilterWhere(
+ [
+ 'like',
+ 'order_delivery_lang.title',
+ $this->title,
+ ]
+ );
+
+ return $dataProvider;
+ }
+ }
diff --git a/models/Export.php b/models/Export.php
index 2aa0dd4..d1f2db4 100755
--- a/models/Export.php
+++ b/models/Export.php
@@ -2,8 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
- use artweb\artbox\ecommerce\models\TaxOption;
+ use artweb\artbox\language\models\Language;
use yii\base\Model;
class Export extends Model
diff --git a/models/Import.php b/models/Import.php
index 7662973..a0581b1 100755
--- a/models/Import.php
+++ b/models/Import.php
@@ -2,9 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
- use artweb\artbox\ecommerce\models\TaxGroup;
- use artweb\artbox\ecommerce\models\TaxOption;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\base\Model;
use yii\helpers\ArrayHelper;
diff --git a/models/Order.php b/models/Order.php
new file mode 100755
index 0000000..80b586a
--- /dev/null
+++ b/models/Order.php
@@ -0,0 +1,274 @@
+ [ 'phone' ],
+ ]
+ );
+ return $scenarios;
+ }
+
+ public function rules()
+ {
+ return [
+ [
+ [
+ 'phone',
+ ],
+ 'required',
+ ],
+ [
+ [ 'comment' ],
+ 'safe',
+ ],
+ [
+ [ 'email' ],
+ 'email',
+ ],
+ [
+ [ 'phone' ],
+ 'match',
+ 'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/',
+ 'on' => self::SCENARIO_QUICK,
+ ],
+ [
+ [
+ 'name',
+ 'phone2',
+ 'numbercard',
+ 'body',
+ 'declaration',
+ 'stock',
+ 'consignment',
+ 'payment',
+ 'insurance',
+ 'amount_imposed',
+ 'shipping_by',
+ 'city',
+ 'adress',
+ 'total',
+ 'status',
+ ],
+ 'string',
+ 'max' => 255,
+ ],
+ ];
+ }
+
+ public function attributeLabels()
+ {
+ return [
+ 'name' => Yii::t('app', 'order_name'),
+ 'phone' => Yii::t('app', 'order_phone'),
+ 'email' => Yii::t('app', 'order_email'),
+ 'comment' => Yii::t('app', 'order_comment'),
+ ];
+ }
+
+ public function beforeSave($insert)
+ {
+ $this->user_id = Yii::$app->user->id;
+ $this->date_time = new Expression('NOW()');
+ return parent::beforeSave($insert);
+ }
+
+ public function beforeDelete()
+ {
+ return parent::beforeDelete();
+ }
+
+ public function addBasket($product_variant_id, $count)
+ {
+ $session = new Session;
+ $session->open();
+ $data = $session[ 'basket' ];
+ $i = 0;
+ if (isset( $session[ 'basket' ] )) {
+ foreach ($session[ 'basket' ] as $key => $basket) {
+ if ($product_variant_id == $basket[ 'id' ]) {
+ $data[ $key ][ 'count' ] += $count;
+ $session[ 'basket' ] = $data;
+ $i++;
+ }
+ }
+ }
+ if ($i == 0) {
+ $data[] = [
+ 'id' => $product_variant_id,
+ 'count' => $count,
+ ];
+ $session[ 'basket' ] = $data;
+ }
+ }
+
+ public function rowBasket()
+ {
+ $session = new Session;
+ $session->open();
+ $cost = 0;
+ $count = 0;
+ if (isset( $session[ 'basket' ] ) && count($session[ 'basket' ])) {
+ foreach ($session[ 'basket' ] as $product) {
+ $count += $product[ 'count' ];
+ }
+ }
+
+ return (object) [
+ 'cost' => $cost,
+ 'count' => $count,
+ ];
+ }
+
+ public function deleteBasketMod($id)
+ {
+ $session = new Session;
+ $session->open();
+ $basket = $session[ 'basket' ];
+ foreach ($basket as $key => $product) {
+ if ($id == $product[ 'id' ]) {
+ unset( $basket[ $key ] );
+ }
+ }
+ $session[ 'basket' ] = $basket;
+ }
+
+ public function updateBasket($row)
+ {
+ $session = new Session;
+ $session->open();
+ //$data = array();
+ if ($row[ 'count' ] > 0) {
+ $this->data[] = [
+ 'id' => $row[ 'id' ],
+ 'count' => $row[ 'count' ],
+ ];
+ }
+ $session[ 'basket' ] = $this->data;
+ }
+
+ public function getBasketMods()
+ {
+ $session = new Session;
+ $session->open();
+ $products = [];
+ if (empty( $session[ 'basket' ] )) {
+ return [];
+ }
+ foreach ($session[ 'basket' ] as $product) {
+ $row = ProductVariant::find()
+ ->select(
+ [
+ 'product_variant.*',
+ 'product.name as productName',
+ 'product.alias',
+ ]
+ )
+ ->where([ 'product_variant.id' => $product[ 'id' ] ])
+ ->leftJoin('product', 'product.id = product_variant.product_id')
+ ->one();
+ $row->count = $product[ 'count' ];
+ $row->sum_cost = $product[ 'count' ] * $row->price;
+ $products[] = $row;
+ }
+
+ return $products;
+ }
+
+ public function getSumCost()
+ {
+ $session = new Session;
+ $session->open();
+ $cost = 0;
+ if (empty( $session[ 'basket' ] )) {
+ return false;
+ }
+ foreach ($session[ 'basket' ] as $product) {
+ $cost += ( $this->getModCost($product[ 'id' ]) * $product[ 'count' ] );
+ }
+
+ return $cost;
+ }
+
+ private function getModCost($product_variant_id)
+ {
+ /**
+ * @var ProductVariant $mod
+ */
+ $mod = ProductVariant::find()
+ ->where([ 'id' => $product_variant_id ])
+ ->one();
+
+ return $mod->price;
+ }
+
+ public function clearBasket()
+ {
+ $session = new Session;
+ $session->open();
+ $session[ 'basket' ] = null;
+ }
+
+ public function getUser()
+ {
+ return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]);
+ }
+
+ public function getProducts()
+ {
+ return $this->hasMany(OrderProduct::className(), [ 'order_id' => 'id' ]);
+ }
+ }
\ No newline at end of file
diff --git a/models/OrderDeliveryLang.php b/models/OrderDeliveryLang.php
new file mode 100755
index 0000000..70d6a6e
--- /dev/null
+++ b/models/OrderDeliveryLang.php
@@ -0,0 +1,120 @@
+ 255,
+ ],
+ [
+ [
+ 'order_delivery_id',
+ 'language_id',
+ ],
+ 'unique',
+ 'targetAttribute' => [
+ 'order_delivery_id',
+ 'language_id',
+ ],
+ 'message' => 'The combination of order Delivery ID and Language ID has already been taken.',
+ ],
+ [
+ [ 'language_id' ],
+ 'exist',
+ 'skipOnError' => true,
+ 'targetClass' => Language::className(),
+ 'targetAttribute' => [ 'language_id' => 'id' ],
+ ],
+ [
+ [ 'order_delivery_id' ],
+ 'exist',
+ 'skipOnError' => true,
+ 'targetClass' => Delivery::className(),
+ 'targetAttribute' => [ 'order_delivery_id' => 'id' ],
+ ],
+ ];
+ }
+
+ /**
+ * @inheritdoc
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'order_delivery_id' => Yii::t('app', 'order_delivery_id'),
+ 'language_id' => Yii::t('app', 'language_id'),
+ 'title' => Yii::t('app', 'title'),
+ 'text' => Yii::t('app', 'text'),
+ ];
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getLanguage()
+ {
+ return $this->hasOne(Language::className(), [ 'id' => 'language_id' ]);
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getDelivery()
+ {
+ return $this->hasOne(Delivery::className(), [ 'id' => 'order_delivery_id' ]);
+ }
+ }
diff --git a/models/OrderProduct.php b/models/OrderProduct.php
new file mode 100755
index 0000000..ce36314
--- /dev/null
+++ b/models/OrderProduct.php
@@ -0,0 +1,79 @@
+ Yii::t('app', 'product_name'),
+ 'name' => Yii::t('app', 'op_name'),
+ 'art' => Yii::t('app', 'art'),
+ 'cost' => Yii::t('app', 'cost'),
+ 'count' => Yii::t('app', 'count'),
+ 'sum_cost' => Yii::t('app', 'sum_cost'),
+ ];
+ }
+
+ public function getOrder()
+ {
+ return $this->hasOne(Order::className(), [ 'id' => 'order_id' ]);
+ }
+
+ /**
+ * @return \yii\db\ActiveQuery
+ */
+ public function getProductVariant()
+ {
+ return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]);
+ }
+ }
\ No newline at end of file
diff --git a/models/OrderSearch.php b/models/OrderSearch.php
new file mode 100755
index 0000000..3d9bb9f
--- /dev/null
+++ b/models/OrderSearch.php
@@ -0,0 +1,112 @@
+ $query,
+ ]
+ );
+
+ $this->load($params);
+
+ if (!$this->validate()) {
+ // uncomment the following line if you do not want to return any records when validation fails
+ // $query->where('0=1');
+ return $dataProvider;
+ }
+
+ // grid filtering conditions
+ $query->andFilterWhere(
+ [
+ 'id' => $this->id,
+ 'user_id' => $this->user_id,
+ 'delivery' => $this->delivery,
+ 'payment' => $this->payment,
+ 'status' => $this->status,
+ ]
+ );
+
+ $query->andFilterWhere(
+ [
+ 'like',
+ 'name',
+ $this->name,
+ ]
+ )
+ ->andFilterWhere(
+ [
+ 'like',
+ 'email',
+ $this->email,
+ ]
+ )
+ ->andFilterWhere(
+ [
+ 'like',
+ 'phone',
+ $this->phone,
+ ]
+ );
+
+ return $dataProvider;
+ }
+ }
diff --git a/models/Product.php b/models/Product.php
index bae90fe..980b0d3 100755
--- a/models/Product.php
+++ b/models/Product.php
@@ -2,15 +2,11 @@
namespace artweb\artbox\ecommerce\models;
- use common\behaviors\DefaultVariantBehavior;
- use common\behaviors\MultipleImgBehavior;
- use common\behaviors\SaveMultipleFileBehavior;
- use common\models\ProductToRating;
- use common\modules\comment\models\CommentModel;
- use common\modules\language\behaviors\LanguageBehavior;
- use artweb\artbox\ecommerce\models\TaxGroup;
- use artweb\artbox\ecommerce\models\TaxGroupToCategory;
- use artweb\artbox\ecommerce\models\TaxOption;
+ use artweb\artbox\ecommerce\behaviors\DefaultVariantBehavior;
+ use artweb\artbox\behaviors\MultipleImgBehavior;
+ use artweb\artbox\behaviors\SaveMultipleFileBehavior;
+// use artweb\artbox\comment\models\CommentModel;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
use Yii;
use yii\base\InvalidParamException;
use yii\db\ActiveQuery;
@@ -33,7 +29,6 @@
* @property boolean $is_top
* @property boolean $is_new
* @property boolean $is_discount
- * @property ProductToRating $averageRating
* @property TaxGroup[] $properties
* @property ProductVariant $enabledVariant
* @property ProductVariant[] $enabledVariants
@@ -500,35 +495,35 @@
* @todo Rewrite with behavior
* @return bool
*/
- public function recalculateRating():bool
- {
- /**
- * @var ProductToRating $averageRating
- */
- $average = $this->getComments()
- ->joinWith('rating')
- ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ])
- ->scalar();
- if (!$average) {
- $average = 0;
- }
- $averageRating = $this->averageRating;
- if (!empty( $averageRating )) {
- $averageRating->value = $average;
- } else {
- $averageRating = new ProductToRating(
- [
- 'product_id' => $this->id,
- 'value' => $average,
- ]
- );
- }
- if ($averageRating->save()) {
- return true;
- } else {
- return false;
- }
- }
+// public function recalculateRating():bool
+// {
+// /**
+// * @var ProductToRating $averageRating
+// */
+// $average = $this->getComments()
+// ->joinWith('rating')
+// ->select([ 'average' => 'avg(artbox_comment_rating.value)::float' ])
+// ->scalar();
+// if (!$average) {
+// $average = 0;
+// }
+// $averageRating = $this->averageRating;
+// if (!empty( $averageRating )) {
+// $averageRating->value = $average;
+// } else {
+// $averageRating = new ProductToRating(
+// [
+// 'product_id' => $this->id,
+// 'value' => $average,
+// ]
+// );
+// }
+// if ($averageRating->save()) {
+// return true;
+// } else {
+// return false;
+// }
+// }
/**
* Get CommmentModel query for artboxcomment module
@@ -536,27 +531,27 @@
* @todo Rewrite with behavior
* @return ActiveQuery
*/
- public function getComments()
- {
- return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ])
- ->where(
- [
- 'artbox_comment.entity' => self::className(),
- 'artbox_comment.status' => CommentModel::STATUS_ACTIVE,
- 'artbox_comment.artbox_comment_pid' => null,
- ]
- );
- }
+// public function getComments()
+// {
+// return $this->hasMany(CommentModel::className(), [ 'entity_id' => 'id' ])
+// ->where(
+// [
+// 'artbox_comment.entity' => self::className(),
+// 'artbox_comment.status' => CommentModel::STATUS_ACTIVE,
+// 'artbox_comment.artbox_comment_pid' => null,
+// ]
+// );
+// }
/**
* Get ProductToRating query in order to get average rating for current Product
*
* @return \yii\db\ActiveQuery
*/
- public function getAverageRating()
- {
- return $this->hasOne(ProductToRating::className(), [ 'product_id' => 'id' ]);
- }
+// public function getAverageRating()
+// {
+// return $this->hasOne(ProductToRating::className(), [ 'product_id' => 'id' ]);
+// }
/**
* Get TaxGroupToCategories query via product_category table
diff --git a/models/ProductFrontendSearch.php b/models/ProductFrontendSearch.php
new file mode 100644
index 0000000..97fa735
--- /dev/null
+++ b/models/ProductFrontendSearch.php
@@ -0,0 +1,143 @@
+ $this->getSearchQuery($category, $params, $in_stock)->with([
+ 'images',
+// 'events',
+ 'variant',
+ 'variant.image',
+ 'comments',
+// 'averageRating',
+ ])->all(),
+ 'pagination' => [
+ 'pageSize' => 15,
+ ],
+ 'sort' => [
+ 'attributes' => [
+ 'name' => [
+ 'asc' => ['name' => SORT_ASC],
+ 'desc' => ['name' => SORT_DESC],
+ 'default' => SORT_DESC,
+ 'label' => 'имени',
+ ],
+ 'price' => [
+ 'asc' => ['price' => SORT_ASC],
+ 'desc' => ['price' => SORT_DESC],
+ 'default' => SORT_DESC,
+ 'label' => 'по цене',
+ ],
+ ],
+ ]
+ ]);
+
+
+
+
+
+ return $dataProvider;
+ }
+
+ public function getSearchQuery($category = null, $params = [], $in_stock = true) {
+
+ if (!empty($category)) {
+ /** @var ActiveQuery $query */
+ /**@var Category $category **/
+ $query = $category->getProducts();
+
+ } else {
+ $query = Product::find();
+ }
+
+ $query->select(['product.*']);
+ $query->joinWith(['enabledVariants','brand','options', 'category']);
+
+ $query->groupBy(['product.id', 'product_variant.price']);
+
+ FilterHelper::setQueryParams($query, $params);
+ if($in_stock){
+ $query->andWhere(['>=', ProductVariant::tableName() .'.stock', 1]);
+ }
+
+
+ return $query;
+ }
+
+
+ /**
+ * @param Category|null $category
+ * @return array
+ */
+
+ public function priceLimits($category = null) {
+ if (!empty($category)) {
+ /** @var ActiveQuery $query */
+ $query = $category->getProducts();
+ } else {
+ $query = Product::find();
+ }
+ $query->joinWith('variant');
+
+ return [
+ 'min' => $query->min(ProductVariant::tableName() .'.price'),
+ 'max' => $query->max(ProductVariant::tableName() .'.price'),
+ ];
+ }
+}
\ No newline at end of file
diff --git a/models/ProductImage.php b/models/ProductImage.php
index 7adc9ed..1c3a26d 100755
--- a/models/ProductImage.php
+++ b/models/ProductImage.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\behaviors\ImageBehavior;
+ use artweb\artbox\behaviors\ImageBehavior;
use Yii;
use yii\db\ActiveRecord;
diff --git a/models/ProductLang.php b/models/ProductLang.php
index 6792271..5a86be0 100755
--- a/models/ProductLang.php
+++ b/models/ProductLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
@@ -39,7 +39,7 @@
{
return [
'slug' => [
- 'class' => 'common\behaviors\Slug',
+ 'class' => 'artweb\artbox\ecommerce\behaviors\Slug',
],
];
}
diff --git a/models/ProductOption.php b/models/ProductOption.php
index bb54b21..030306f 100755
--- a/models/ProductOption.php
+++ b/models/ProductOption.php
@@ -2,7 +2,6 @@
namespace artweb\artbox\ecommerce\models;
- use artweb\artbox\ecommerce\models\TaxOption;
use Yii;
use yii\db\ActiveRecord;
diff --git a/models/ProductUnit.php b/models/ProductUnit.php
index 62d5428..df2970e 100755
--- a/models/ProductUnit.php
+++ b/models/ProductUnit.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\behaviors\LanguageBehavior;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
diff --git a/models/ProductUnitLang.php b/models/ProductUnitLang.php
index c49d76a..6069063 100755
--- a/models/ProductUnitLang.php
+++ b/models/ProductUnitLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
diff --git a/models/ProductVariant.php b/models/ProductVariant.php
index 4505318..1e5731a 100755
--- a/models/ProductVariant.php
+++ b/models/ProductVariant.php
@@ -2,11 +2,9 @@
namespace artweb\artbox\ecommerce\models;
- use common\behaviors\MultipleImgBehavior;
- use common\behaviors\SaveMultipleFileBehavior;
- use common\modules\language\behaviors\LanguageBehavior;
- use artweb\artbox\ecommerce\models\TaxGroup;
- use artweb\artbox\ecommerce\models\TaxOption;
+ use artweb\artbox\behaviors\MultipleImgBehavior;
+ use artweb\artbox\behaviors\SaveMultipleFileBehavior;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
use Yii;
use yii\base\InvalidParamException;
use yii\db\ActiveQuery;
diff --git a/models/ProductVariantLang.php b/models/ProductVariantLang.php
index cb12b4a..88ff471 100755
--- a/models/ProductVariantLang.php
+++ b/models/ProductVariantLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
diff --git a/models/ProductVariantOption.php b/models/ProductVariantOption.php
index da29e6c..c157e25 100755
--- a/models/ProductVariantOption.php
+++ b/models/ProductVariantOption.php
@@ -2,7 +2,6 @@
namespace artweb\artbox\ecommerce\models;
- use artweb\artbox\ecommerce\models\TaxOption;
use yii\db\ActiveRecord;
/**
diff --git a/models/Stock.php b/models/Stock.php
index 8eb6c62..0a52875 100755
--- a/models/Stock.php
+++ b/models/Stock.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\behaviors\LanguageBehavior;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
diff --git a/models/StockLang.php b/models/StockLang.php
index 2024ad3..4d86f5a 100644
--- a/models/StockLang.php
+++ b/models/StockLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
diff --git a/models/TaxGroup.php b/models/TaxGroup.php
index c87a0ac..24423ff 100755
--- a/models/TaxGroup.php
+++ b/models/TaxGroup.php
@@ -2,9 +2,8 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\behaviors\LanguageBehavior;
- use common\modules\language\models\Language;
- use artweb\artbox\ecommerce\models\Category;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
+ use artweb\artbox\language\models\Language;
use yii\base\InvalidValueException;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
diff --git a/models/TaxGroupLang.php b/models/TaxGroupLang.php
index 3058107..9e62f41 100755
--- a/models/TaxGroupLang.php
+++ b/models/TaxGroupLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
@@ -40,7 +40,7 @@
{
return [
'slug' => [
- 'class' => 'common\behaviors\Slug',
+ 'class' => 'artweb\artbox\ecommerce\behaviors\Slug',
],
];
}
diff --git a/models/TaxGroupToCategory.php b/models/TaxGroupToCategory.php
index 97e29de..905031d 100755
--- a/models/TaxGroupToCategory.php
+++ b/models/TaxGroupToCategory.php
@@ -2,7 +2,6 @@
namespace artweb\artbox\ecommerce\models;
- use artweb\artbox\ecommerce\models\Category;
use yii\db\ActiveRecord;
/**
diff --git a/models/TaxOption.php b/models/TaxOption.php
index dbaa865..094cd78 100755
--- a/models/TaxOption.php
+++ b/models/TaxOption.php
@@ -2,10 +2,8 @@
namespace artweb\artbox\ecommerce\models;
- use common\behaviors\SaveImgBehavior;
- use common\modules\language\behaviors\LanguageBehavior;
- use artweb\artbox\ecommerce\models\Product;
- use artweb\artbox\ecommerce\models\ProductVariant;
+ use artweb\artbox\behaviors\SaveImgBehavior;
+ use artweb\artbox\language\behaviors\LanguageBehavior;
use Yii;
use yii\db\ActiveQuery;
use yii\db\ActiveRecord;
diff --git a/models/TaxOptionLang.php b/models/TaxOptionLang.php
index dd09e88..7fcd2ea 100755
--- a/models/TaxOptionLang.php
+++ b/models/TaxOptionLang.php
@@ -2,7 +2,7 @@
namespace artweb\artbox\ecommerce\models;
- use common\modules\language\models\Language;
+ use artweb\artbox\language\models\Language;
use Yii;
use yii\db\ActiveRecord;
@@ -39,7 +39,7 @@
{
return [
'slug' => [
- 'class' => 'common\behaviors\Slug',
+ 'class' => 'artweb\artbox\ecommerce\behaviors\Slug',
'inAttribute' => 'value',
],
];
diff --git a/views/manage/_form.php b/views/manage/_form.php
index 765e924..f1c4948 100755
--- a/views/manage/_form.php
+++ b/views/manage/_form.php
@@ -1,6 +1,6 @@
!empty( $model->imageUrl ) ? \common\components\artboximage\ArtboxImageHelper::getImage(
+ 'initialPreview' => !empty( $model->imageUrl ) ? \artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper::getImage(
$model->imageUrl,
'list'
) : '',
diff --git a/views/tax-option/_form_language.php b/views/tax-option/_form_language.php
index 6f7d22a..c3feaeb 100755
--- a/views/tax-option/_form_language.php
+++ b/views/tax-option/_form_language.php
@@ -1,5 +1,5 @@
session->get('order');
+ unset( $sessionData[ 'order_id' ] );
+ $count = count($sessionData);
+ $price = 0;
+ if (is_array($sessionData) && !empty( $sessionData )) {
+
+ $variant = ProductVariant::find()
+ ->where([ 'product_variant_id' => array_keys($sessionData) ])
+ ->indexBy('product_variant_id')
+ ->all();
+
+ foreach ($sessionData as $k => $item) {
+ $sessionData[ $k ][ 'item' ] = $variant[ $k ];
+ $price += $variant[ $k ]->price * $sessionData[ $k ][ 'num' ];
+ }
+
+ return $this->render(
+ 'basket_head',
+ [
+ 'items' => $sessionData,
+ 'count' => $count,
+ 'price' => $price,
+ ]
+ );
+
+ }
+
+ }
+ }
+
\ No newline at end of file
diff --git a/widgets/BasketModal.php b/widgets/BasketModal.php
new file mode 100644
index 0000000..d9a7513
--- /dev/null
+++ b/widgets/BasketModal.php
@@ -0,0 +1,49 @@
+session->get('order');
+ unset( $sessionData[ 'order_id' ] );
+ $count = count($sessionData);
+ $price = 0;
+ if (is_array($sessionData) && !empty( $sessionData )) {
+
+ $variant = ProductVariant::find()
+ ->where([ 'product_variant_id' => array_keys($sessionData) ])
+ ->indexBy('product_variant_id')
+ ->all();
+
+ foreach ($sessionData as $k => $item) {
+ $sessionData[ $k ][ 'item' ] = $variant[ $k ];
+ $price += $variant[ $k ]->price * $sessionData[ $k ][ 'num' ];
+ }
+
+ return $this->render(
+ 'basket_modal',
+ [
+ 'items' => $sessionData,
+ 'count' => $count,
+ 'price' => $price,
+ ]
+ );
+
+ }
+
+ }
+
+ }
+
\ No newline at end of file
diff --git a/widgets/views/basket_head.php b/widgets/views/basket_head.php
new file mode 100644
index 0000000..6b6b021
--- /dev/null
+++ b/widgets/views/basket_head.php
@@ -0,0 +1,10 @@
+
+
+

+
+
= Yii::t('app','basket');?> = $count? Html::tag('span',$count,['class'=>'head_basket_count']) :'' ?>
+
+
+
diff --git a/widgets/views/basket_modal.php b/widgets/views/basket_modal.php
new file mode 100644
index 0000000..96265f0
--- /dev/null
+++ b/widgets/views/basket_modal.php
@@ -0,0 +1,53 @@
+
+
+
+
+
+ -
+
+
+
+ product->image)) :?>
+

+
+
![<?= $item['item']->product->image->alt ? $item['item']->product->image->alt : $item['item']->product->name?>](/images/<?= $item['item']->product->image->image?>)
+
+
+
+ =$item['item']->product->name.' '.$item['item']->name?>
+ = Yii::t('app', 'code', '45885-01016049')?>
+
+
+
+
= $item['item']->price * $item['num'] ?>грн.
+
+
+
+
+
+
+
+
+
= Yii::t('app','articles')?>: = $count ?>
+
= Yii::t('app','sum')?>: = $price ?> грн.
+
+
+ = Html::a(Yii::t('app','continue_shopping'),'#', ['class'=> 'close']) ?>
+ = Html::a(Yii::t('app','checkout'), ['orders/first'], ['class'=> 'button']);?>
+
+
diff --git a/widgets/views/brandsCarousel.php b/widgets/views/brandsCarousel.php
index 845ed10..d3e3de7 100755
--- a/widgets/views/brandsCarousel.php
+++ b/widgets/views/brandsCarousel.php
@@ -2,7 +2,7 @@
/**
* @var Brand[] $brands
*/
- use common\components\artboximage\ArtboxImageHelper;
+ use artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper;
use artweb\artbox\ecommerce\models\Brand;
?>
diff --git a/widgets/views/product_smart.php b/widgets/views/product_smart.php
index 4db88e7..2ae7a3c 100755
--- a/widgets/views/product_smart.php
+++ b/widgets/views/product_smart.php
@@ -29,7 +29,7 @@
'product' => $product->lang->alias,
]
) ?>">
- = \common\components\artboximage\ArtboxImageHelper::getImage(
+ = \artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper::getImage(
$product->enabledVariants[ 0 ]->imageUrl,
'list',
[
diff --git a/widgets/views/submenu.php b/widgets/views/submenu.php
index ccae3ff..454b70c 100755
--- a/widgets/views/submenu.php
+++ b/widgets/views/submenu.php
@@ -28,7 +28,7 @@
image )) : ?>
- = $_item[ 'item' ]->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($_item[ 'item' ]->imageUrl, 'mainmenu') : '' ?>
+ = $_item[ 'item' ]->imageUrl ? \artweb\artbox\ecommerce\components\artboximage\ArtboxImageHelper::getImage($_item[ 'item' ]->imageUrl, 'mainmenu') : '' ?>
= $_item[ 'item' ]->title ?>
--
libgit2 0.21.4