Commit 41068668f9feea6ffb045860f9441949cd4deb45
1 parent
96f5a822
29.06.16
Showing
18 changed files
with
140 additions
and
50 deletions
Show diff stats
common/modules/product/controllers/ManageController.php
@@ -133,7 +133,7 @@ class ManageController extends Controller | @@ -133,7 +133,7 @@ class ManageController extends Controller | ||
133 | return $this->redirect(['view', 'id' => $model->product_id]); | 133 | return $this->redirect(['view', 'id' => $model->product_id]); |
134 | } | 134 | } |
135 | } else { | 135 | } else { |
136 | - $groups = $model->category->getTaxGroups(); | 136 | + $groups = $model->category-> getTaxGroupsByLevel(0); |
137 | 137 | ||
138 | return $this->render('update', [ | 138 | return $this->render('update', [ |
139 | 'model' => $model, | 139 | 'model' => $model, |
common/modules/product/controllers/VariantController.php
100644 → 100755
@@ -4,8 +4,10 @@ namespace common\modules\product\controllers; | @@ -4,8 +4,10 @@ namespace common\modules\product\controllers; | ||
4 | 4 | ||
5 | use common\modules\product\models\Product; | 5 | use common\modules\product\models\Product; |
6 | use common\modules\product\models\ProductImage; | 6 | use common\modules\product\models\ProductImage; |
7 | +use common\modules\product\models\ProductStock; | ||
7 | use common\modules\product\models\ProductVariant; | 8 | use common\modules\product\models\ProductVariant; |
8 | use common\modules\product\models\ProductVariantListSearch; | 9 | use common\modules\product\models\ProductVariantListSearch; |
10 | +use common\modules\product\models\Stock; | ||
9 | use Yii; | 11 | use Yii; |
10 | use yii\web\Controller; | 12 | use yii\web\Controller; |
11 | use yii\web\NotFoundHttpException; | 13 | use yii\web\NotFoundHttpException; |
@@ -94,8 +96,12 @@ class VariantController extends Controller | @@ -94,8 +96,12 @@ class VariantController extends Controller | ||
94 | return $this->redirect(['index', 'product_id' => $product_id]); | 96 | return $this->redirect(['index', 'product_id' => $product_id]); |
95 | } | 97 | } |
96 | } else { | 98 | } else { |
99 | + $groups = $model->category->getTaxGroupsByLevel(1); | ||
100 | + | ||
97 | return $this->render('create', [ | 101 | return $this->render('create', [ |
98 | 'model' => $model, | 102 | 'model' => $model, |
103 | + 'groups' => $groups, | ||
104 | + 'stocks' => [new ProductStock()], | ||
99 | ]); | 105 | ]); |
100 | } | 106 | } |
101 | } | 107 | } |
@@ -112,14 +118,9 @@ class VariantController extends Controller | @@ -112,14 +118,9 @@ class VariantController extends Controller | ||
112 | $model = $this->findModel($id); | 118 | $model = $this->findModel($id); |
113 | if ($model->load(Yii::$app->request->post())) { | 119 | if ($model->load(Yii::$app->request->post())) { |
114 | 120 | ||
115 | - | ||
116 | - | ||
117 | - | ||
118 | - | ||
119 | - | ||
120 | - | ||
121 | if ($model->save()) { | 121 | if ($model->save()) { |
122 | 122 | ||
123 | + | ||
123 | if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | 124 | if ( ($image = UploadedFile::getInstance($model, 'image')) ) { |
124 | $imageModel = ProductImage::find()->where(['product_variant_id' => $model->product_variant_id])->one(); | 125 | $imageModel = ProductImage::find()->where(['product_variant_id' => $model->product_variant_id])->one(); |
125 | 126 | ||
@@ -146,6 +147,31 @@ class VariantController extends Controller | @@ -146,6 +147,31 @@ class VariantController extends Controller | ||
146 | $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); | 147 | $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); |
147 | } | 148 | } |
148 | 149 | ||
150 | + | ||
151 | + $ProductStocks = Yii::$app->request->post('ProductStock'); | ||
152 | + $Stocks = Yii::$app->request->post('Stock'); | ||
153 | + | ||
154 | + foreach($ProductStocks as $index => $ProductStock){ | ||
155 | + $stock = Stock::find()->where(['name'=>$Stocks[$index]['name']])->one(); | ||
156 | + if(!$stock instanceof Stock){ | ||
157 | + $stock = new Stock(); | ||
158 | + $stock->name = $Stocks[$index]['name']; | ||
159 | + $stock->save(); | ||
160 | + } | ||
161 | + $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]); | ||
162 | + if(!$psModel instanceof ProductStock){ | ||
163 | + $psModel = new ProductStock; | ||
164 | + $psModel->load(['ProductStock'=>$ProductStock]); | ||
165 | + $psModel->stock_id = $stock->stock_id; | ||
166 | + $psModel->save(); | ||
167 | + } else { | ||
168 | + $psModel->load(['ProductStock'=>$ProductStock]); | ||
169 | + $psModel->save(); | ||
170 | + } | ||
171 | + | ||
172 | + } | ||
173 | + | ||
174 | + | ||
149 | } | 175 | } |
150 | return $this->redirect(['index', 'product_id'=>$product_id]); | 176 | return $this->redirect(['index', 'product_id'=>$product_id]); |
151 | 177 | ||
@@ -172,6 +198,7 @@ class VariantController extends Controller | @@ -172,6 +198,7 @@ class VariantController extends Controller | ||
172 | return $this->render('update', [ | 198 | return $this->render('update', [ |
173 | 'model' => $model, | 199 | 'model' => $model, |
174 | 'groups' => $groups, | 200 | 'groups' => $groups, |
201 | + 'stocks' => (!empty($model->variantStocks)) ? $model->variantStocks : [new ProductStock], | ||
175 | ]); | 202 | ]); |
176 | } | 203 | } |
177 | } | 204 | } |
common/modules/product/models/ProductStock.php
@@ -47,7 +47,7 @@ class ProductStock extends \yii\db\ActiveRecord | @@ -47,7 +47,7 @@ class ProductStock extends \yii\db\ActiveRecord | ||
47 | return [ | 47 | return [ |
48 | 'product_id' => 'Product ID', | 48 | 'product_id' => 'Product ID', |
49 | 'stock_id' => 'Stock ID', | 49 | 'stock_id' => 'Stock ID', |
50 | - 'quantity' => 'Quantity', | 50 | + 'quantity' => 'Количество', |
51 | 'product_variant_id' => 'Product Variant ID', | 51 | 'product_variant_id' => 'Product Variant ID', |
52 | ]; | 52 | ]; |
53 | } | 53 | } |
common/modules/product/models/ProductVariant.php
@@ -37,7 +37,7 @@ class ProductVariant extends \yii\db\ActiveRecord | @@ -37,7 +37,7 @@ class ProductVariant extends \yii\db\ActiveRecord | ||
37 | public $translit; | 37 | public $translit; |
38 | public $translit_rubric; | 38 | public $translit_rubric; |
39 | private $data; | 39 | private $data; |
40 | - public $stocks; | 40 | + |
41 | 41 | ||
42 | /** @var array $_images */ | 42 | /** @var array $_images */ |
43 | public $imagesUpload = []; | 43 | public $imagesUpload = []; |
@@ -142,6 +142,18 @@ class ProductVariant extends \yii\db\ActiveRecord | @@ -142,6 +142,18 @@ class ProductVariant extends \yii\db\ActiveRecord | ||
142 | return is_null($this->stock) ? '∞' : ($this->stock > 0 ? Yii::t('product', 'Enable') : Yii::t('product', 'Disable')); // intval($this->stock); | 142 | return is_null($this->stock) ? '∞' : ($this->stock > 0 ? Yii::t('product', 'Enable') : Yii::t('product', 'Disable')); // intval($this->stock); |
143 | } | 143 | } |
144 | 144 | ||
145 | + public function getVariantStocks(){ | ||
146 | + | ||
147 | + return $this->hasMany(ProductStock::className(),['product_variant_id'=> 'product_variant_id'])->joinWith('stock'); | ||
148 | + } | ||
149 | + | ||
150 | + public function getStocks(){ | ||
151 | + | ||
152 | + return $this->hasMany(Stock::className(),['stock_id'=>'stock_id']) | ||
153 | + ->viaTable(ProductStock::tableName(),['product_variant_id'=> 'product_variant_id']); | ||
154 | + } | ||
155 | + | ||
156 | + | ||
145 | public function getFilters(){ | 157 | public function getFilters(){ |
146 | 158 | ||
147 | return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) | 159 | return $this->hasMany(TaxOption::className(), ['tax_option_id' => 'option_id']) |
common/modules/product/models/ProductVariantListSearch.php
100644 → 100755
common/modules/product/models/ProductVariantOption.php
100644 → 100755
common/modules/product/models/Stock.php
common/modules/product/views/variant/_form.php
100644 → 100755
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | +use common\modules\product\models\Stock; | ||
3 | use yii\helpers\Html; | 4 | use yii\helpers\Html; |
5 | +use yii\web\View; | ||
4 | use yii\widgets\ActiveForm; | 6 | use yii\widgets\ActiveForm; |
5 | use yii\helpers\ArrayHelper; | 7 | use yii\helpers\ArrayHelper; |
6 | -use common\components\artboxtree\ArtboxTreeHelper; | ||
7 | -use common\modules\product\helpers\ProductHelper; | ||
8 | -use kartik\file\FileInput; | ||
9 | -use unclead\widgets\MultipleInput; | ||
10 | -use unclead\widgets\MultipleInputColumn; | ||
11 | -use kartik\select2\Select2; | ||
12 | - | 8 | +use wbraganca\dynamicform\DynamicFormWidget; |
13 | /* @var $this yii\web\View */ | 9 | /* @var $this yii\web\View */ |
14 | /* @var $model common\modules\product\models\Product */ | 10 | /* @var $model common\modules\product\models\Product */ |
15 | /* @var $form yii\widgets\ActiveForm */ | 11 | /* @var $form yii\widgets\ActiveForm */ |
16 | -?> | 12 | +/* @var $stocks common\modules\product\models\Stock */ |
13 | + | ||
14 | + | ||
15 | +$js = ' | ||
16 | +$(".dynamicform_wrapper").on("beforeInsert", function(e, item) { | ||
17 | + console.log("beforeInsert"); | ||
18 | +}); | ||
19 | + | ||
20 | +$(".dynamicform_wrapper").on("afterInsert", function(e, item) { | ||
21 | + console.log("afterInsert"); | ||
22 | +}); | ||
23 | + | ||
24 | +$(".dynamicform_wrapper").on("beforeDelete", function(e, item) { | ||
25 | + if (! confirm("Are you sure you want to delete this item?")) { | ||
26 | + return false; | ||
27 | + } | ||
28 | + return true; | ||
29 | +}); | ||
17 | 30 | ||
31 | +$(".dynamicform_wrapper").on("afterDelete", function(e) { | ||
32 | + console.log("Deleted item!"); | ||
33 | +}); | ||
34 | + | ||
35 | +$(".dynamicform_wrapper").on("limitReached", function(e, item) { | ||
36 | + alert("Limit reached"); | ||
37 | +}); | ||
38 | +'; | ||
39 | + | ||
40 | +$this->registerJs($js, View::POS_END); | ||
41 | +?> | ||
18 | <div class="product-form"> | 42 | <div class="product-form"> |
19 | 43 | ||
20 | <?php $form = ActiveForm::begin([ | 44 | <?php $form = ActiveForm::begin([ |
45 | + 'id' => 'dynamic-form', | ||
21 | 'options' => ['enctype' => 'multipart/form-data'] | 46 | 'options' => ['enctype' => 'multipart/form-data'] |
22 | ]); ?> | 47 | ]); ?> |
23 | 48 | ||
@@ -44,38 +69,58 @@ use kartik\select2\Select2; | @@ -44,38 +69,58 @@ use kartik\select2\Select2; | ||
44 | ], | 69 | ], |
45 | ]); ?> | 70 | ]); ?> |
46 | 71 | ||
47 | - <?= $form->field($model, 'variants')->widget(MultipleInput::className(), [ | ||
48 | - 'columns' => [ | ||
49 | - [ | ||
50 | - 'name' => '', | ||
51 | - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, | ||
52 | - 'title' => Yii::t('product', 'Name'), | ||
53 | - ], | ||
54 | - [ | ||
55 | - 'name' => 'sku', | ||
56 | - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, | ||
57 | - 'title' => Yii::t('product', 'SKU'), | ||
58 | - ], | ||
59 | - [ | ||
60 | - 'name' => 'price', | ||
61 | - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, | ||
62 | - 'title' => Yii::t('product', 'Price'), | ||
63 | - ], | ||
64 | - [ | ||
65 | - 'name' => 'price_old', | ||
66 | - 'type' => MultipleInputColumn::TYPE_TEXT_INPUT, | ||
67 | - 'title' => Yii::t('product', 'Old Price'), | ||
68 | - ], | ||
69 | - [ | ||
70 | - 'name' => 'product_unit_id', | ||
71 | - 'type' => MultipleInputColumn::TYPE_DROPDOWN, | ||
72 | - 'title' => Yii::t('product', 'Unit'), | ||
73 | - 'items' => ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), | ||
74 | - ], | ||
75 | - | 72 | + <?php DynamicFormWidget::begin([ |
73 | + 'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_] | ||
74 | + 'widgetBody' => '.container-items', // required: css class selector | ||
75 | + 'widgetItem' => '.item', // required: css class | ||
76 | + 'limit' => 10, // the maximum times, an element can be added (default 999) | ||
77 | + 'min' => 0, // 0 or 1 (default 1) | ||
78 | + 'insertButton' => '.add-item', // css class | ||
79 | + 'deleteButton' => '.remove-item', // css class | ||
80 | + 'model' => $stocks[0], | ||
81 | + 'formId' => 'dynamic-form', | ||
82 | + 'formFields' => [ | ||
83 | + 'quantity', | ||
84 | + 'name', | ||
76 | ], | 85 | ], |
77 | - ]); | ||
78 | - ?> | 86 | + ]); ?> |
87 | + | ||
88 | + <div class="panel panel-default"> | ||
89 | + <div class="panel-heading"> | ||
90 | + <h4> | ||
91 | + <i class="glyphicon glyphicon-envelope"></i> Склады | ||
92 | + <button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button> | ||
93 | + </h4> | ||
94 | + </div> | ||
95 | + <div class="panel-body"> | ||
96 | + <div class="container-items"><!-- widgetBody --> | ||
97 | + <?php foreach ($stocks as $i => $stock): ?> | ||
98 | + <div class="item panel panel-default"><!-- widgetItem --> | ||
99 | + <div class="panel-body"> | ||
100 | + <?php | ||
101 | + // necessary for update action. | ||
102 | + if (! $stock->isNewRecord) { | ||
103 | + echo Html::activeHiddenInput($stock, "[{$i}]stock_id"); | ||
104 | + } | ||
105 | + ?> | ||
106 | + <div class="row"> | ||
107 | + <div class="col-sm-5"> | ||
108 | + <?= $form->field($stock, "[{$i}]quantity")->textInput(['maxlength' => true]) ?> | ||
109 | + </div> | ||
110 | + <div class="col-sm-5"> | ||
111 | + <?= $form->field($stock->stock, "[{$i}]name")->textInput(['maxlength' => true]) ?> | ||
112 | + </div> | ||
113 | + <div class="col-sm-2" style="margin-top: 30px"> | ||
114 | + <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button> | ||
115 | + </div> | ||
116 | + </div><!-- .row --> | ||
117 | + </div> | ||
118 | + </div> | ||
119 | + <?php endforeach; ?> | ||
120 | + </div> | ||
121 | + </div> | ||
122 | + </div><!-- .panel --> | ||
123 | + <?php DynamicFormWidget::end(); ?> | ||
79 | 124 | ||
80 | <?= $form->field($model, 'product_unit_id')->dropDownList( | 125 | <?= $form->field($model, 'product_unit_id')->dropDownList( |
81 | ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), | 126 | ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), |
common/modules/product/views/variant/_search.php
100644 → 100755
common/modules/product/views/variant/create.php
100644 → 100755
@@ -16,6 +16,8 @@ $this->params['breadcrumbs'][] = $this->title; | @@ -16,6 +16,8 @@ $this->params['breadcrumbs'][] = $this->title; | ||
16 | 16 | ||
17 | <?= $this->render('_form', [ | 17 | <?= $this->render('_form', [ |
18 | 'model' => $model, | 18 | 'model' => $model, |
19 | + 'groups' => $groups, | ||
20 | + 'stocks' => $stocks, | ||
19 | ]) ?> | 21 | ]) ?> |
20 | 22 | ||
21 | </div> | 23 | </div> |
common/modules/product/views/variant/index.php
100644 → 100755
common/modules/product/views/variant/update.php
100644 → 100755
@@ -21,6 +21,7 @@ $this->params['breadcrumbs'][] = Yii::t('product', 'Update'); | @@ -21,6 +21,7 @@ $this->params['breadcrumbs'][] = Yii::t('product', 'Update'); | ||
21 | <?= $this->render('_form', [ | 21 | <?= $this->render('_form', [ |
22 | 'model' => $model, | 22 | 'model' => $model, |
23 | 'groups' => $groups, | 23 | 'groups' => $groups, |
24 | + 'stocks' => $stocks, | ||
24 | ]) ?> | 25 | ]) ?> |
25 | 26 | ||
26 | </div> | 27 | </div> |
composer.json
@@ -13,6 +13,7 @@ | @@ -13,6 +13,7 @@ | ||
13 | "source": "https://github.com/yiisoft/yii2" | 13 | "source": "https://github.com/yiisoft/yii2" |
14 | }, | 14 | }, |
15 | "minimum-stability": "dev", | 15 | "minimum-stability": "dev", |
16 | + | ||
16 | "require": { | 17 | "require": { |
17 | "php": ">=5.4.0", | 18 | "php": ">=5.4.0", |
18 | "yiisoft/yii2": ">=2.0.6", | 19 | "yiisoft/yii2": ">=2.0.6", |
@@ -42,7 +43,8 @@ | @@ -42,7 +43,8 @@ | ||
42 | "iutbay/yii2-imagecache": "*", | 43 | "iutbay/yii2-imagecache": "*", |
43 | "yurkinx/yii2-image": "dev-master", | 44 | "yurkinx/yii2-image": "dev-master", |
44 | "cics/yii2-video-embed-widget": "dev-master", | 45 | "cics/yii2-video-embed-widget": "dev-master", |
45 | - "sersid/yii2-owl-carousel-asset": "*" | 46 | + "sersid/yii2-owl-carousel-asset": "*", |
47 | + "wbraganca/yii2-dynamicform": "dev-master" | ||
46 | }, | 48 | }, |
47 | "require-dev": { | 49 | "require-dev": { |
48 | "yiisoft/yii2-codeception": "*", | 50 | "yiisoft/yii2-codeception": "*", |
frontend/controllers/SiteController.php
@@ -167,7 +167,7 @@ class SiteController extends Controller | @@ -167,7 +167,7 @@ class SiteController extends Controller | ||
167 | print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>"; | 167 | print "<categoryId>" . htmlspecialchars($product->category->category_id) . "</categoryId>"; |
168 | print "<vendor>" . $product->brand->name . "</vendor>"; | 168 | print "<vendor>" . $product->brand->name . "</vendor>"; |
169 | print "<code>" . htmlspecialchars($variant->sku) . "</code>"; | 169 | print "<code>" . htmlspecialchars($variant->sku) . "</code>"; |
170 | - print "<name>" . htmlspecialchars($product->name) . " </name>"; | 170 | + print "<name>" . htmlspecialchars($product->name)." " .htmlspecialchars($variant->name). " </name>"; |
171 | print "<description>" . htmlspecialchars($product->description) . "</description>"; | 171 | print "<description>" . htmlspecialchars($product->description) . "</description>"; |
172 | print "<url>http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}</url>"; | 172 | print "<url>http://rukzachok.com.ua{$product->url}#{$variant->product_variant_id}</url>"; |
173 | print "<image>http://rukzachok.com.ua{$variant->imageUrl}</image>"; | 173 | print "<image>http://rukzachok.com.ua{$variant->imageUrl}</image>"; |