Commit 776dd7a1036a3fd052c139023d7e08c297acaf25
1 parent
599302f3
-Added status 'waiting'
Showing
2 changed files
with
176 additions
and
116 deletions
Show diff stats
common/modules/product/views/variant/_form.php
1 | 1 | <?php |
2 | - | |
3 | -use common\modules\product\models\Stock; | |
4 | -use yii\helpers\Html; | |
5 | -use yii\web\View; | |
6 | -use yii\widgets\ActiveForm; | |
7 | -use yii\helpers\ArrayHelper; | |
8 | -use wbraganca\dynamicform\DynamicFormWidget; | |
9 | -/* @var $this yii\web\View */ | |
10 | -/* @var $model common\modules\product\models\Product */ | |
11 | -/* @var $form yii\widgets\ActiveForm */ | |
12 | -/* @var $stocks common\modules\product\models\Stock */ | |
13 | - | |
14 | - | |
15 | -$js = ' | |
2 | + | |
3 | + use common\modules\product\models\ProductVariant; | |
4 | + use common\modules\product\models\Stock; | |
5 | + use yii\helpers\Html; | |
6 | + use yii\web\View; | |
7 | + use yii\widgets\ActiveForm; | |
8 | + use yii\helpers\ArrayHelper; | |
9 | + use wbraganca\dynamicform\DynamicFormWidget; | |
10 | + | |
11 | + /** | |
12 | + * @var View $this | |
13 | + * @var ProductVariant $model | |
14 | + * @var ActiveForm $form | |
15 | + * @var Stock $stocks | |
16 | + */ | |
17 | + | |
18 | + $js = ' | |
16 | 19 | $(".dynamicform_wrapper").on("beforeInsert", function(e, item) { |
17 | 20 | console.log("beforeInsert"); |
18 | 21 | }); |
... | ... | @@ -36,114 +39,170 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
36 | 39 | alert("Limit reached"); |
37 | 40 | }); |
38 | 41 | '; |
39 | - | |
40 | -$this->registerJs($js, View::POS_LOAD); | |
42 | + | |
43 | + $this->registerJs($js, View::POS_LOAD); | |
41 | 44 | ?> |
42 | 45 | <div class="product-form"> |
43 | - | |
44 | - <?php $form = ActiveForm::begin([ | |
45 | - 'id' => 'dynamic-form', | |
46 | - 'options' => ['enctype' => 'multipart/form-data'] | |
47 | - ]); ?> | |
48 | - | |
49 | - <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?> | |
50 | - | |
51 | - <?= $form->field($model, 'product_id')->hiddenInput()->label(false); ?> | |
52 | - | |
53 | - <?= $form->field($model, 'sku')->textarea(); ?> | |
54 | - <?= $form->field($model, 'price')->textarea(); ?> | |
55 | - <?= $form->field($model, 'price_old')->textarea(); ?> | |
56 | - <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ | |
57 | - 'model' => $model, | |
58 | - 'attribute' => 'image', | |
59 | - 'options' => [ | |
60 | - 'accept' => 'image/*', | |
61 | - 'multiple' => true | |
62 | - ], | |
63 | - 'pluginOptions' => [ | |
64 | - 'allowedFileExtensions' => ['jpg','gif','png'], | |
65 | - 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage($model->imageUrl, 'products') : '', | |
66 | - 'overwriteInitial' => true, | |
67 | - 'showRemove' => true, | |
68 | - 'showUpload' => false, | |
69 | - ], | |
70 | - ]); ?> | |
71 | - | |
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', | |
85 | - ], | |
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, "[{$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(); ?> | |
124 | - | |
125 | - <?= $form->field($model, 'product_unit_id')->dropDownList( | |
126 | - ArrayHelper::map(\common\modules\product\models\ProductUnit::find()->all(), 'product_unit_id', 'name'), | |
46 | + | |
47 | + <?php $form = ActiveForm::begin( | |
127 | 48 | [ |
128 | - 'prompt' => Yii::t('product', 'Unit'), | |
129 | - ])->label(Yii::t('product', 'Unit')) ?> | |
49 | + 'id' => 'dynamic-form', | |
50 | + 'options' => [ 'enctype' => 'multipart/form-data' ], | |
51 | + ] | |
52 | + ); ?> | |
53 | + | |
54 | + <?= $form->field($model, 'name') | |
55 | + ->textInput([ 'maxlength' => true ]) ?> | |
56 | + | |
57 | + <?= $form->field($model, 'product_id') | |
58 | + ->hiddenInput() | |
59 | + ->label(false); ?> | |
60 | + | |
61 | + <?= $form->field($model, 'sku') | |
62 | + ->textarea(); ?> | |
63 | + | |
64 | + <?= $form->field($model, 'status') | |
65 | + ->dropDownList( | |
66 | + [ | |
67 | + 0 => 'В наличии / под заказ', | |
68 | + 1 => 'снят с производства', | |
69 | + 2 => 'в ожидании', | |
70 | + ] | |
71 | + )->label('Статус') ?> | |
72 | + | |
73 | + <?= $form->field($model, 'price') | |
74 | + ->textarea(); ?> | |
75 | + <?= $form->field($model, 'price_old') | |
76 | + ->textarea(); ?> | |
77 | + <?= $form->field($model, 'image') | |
78 | + ->widget( | |
79 | + \kartik\file\FileInput::classname(), | |
80 | + [ | |
81 | + 'model' => $model, | |
82 | + 'attribute' => 'image', | |
83 | + 'options' => [ | |
84 | + 'accept' => 'image/*', | |
85 | + 'multiple' => true, | |
86 | + ], | |
87 | + 'pluginOptions' => [ | |
88 | + 'allowedFileExtensions' => [ | |
89 | + 'jpg', | |
90 | + 'gif', | |
91 | + 'png', | |
92 | + ], | |
93 | + 'initialPreview' => $model->imageUrl ? \common\components\artboximage\ArtboxImageHelper::getImage( | |
94 | + $model->imageUrl, | |
95 | + 'products' | |
96 | + ) : '', | |
97 | + 'overwriteInitial' => true, | |
98 | + 'showRemove' => true, | |
99 | + 'showUpload' => false, | |
100 | + ], | |
101 | + ] | |
102 | + ); ?> | |
130 | 103 | |
131 | - <?php if(isset($groups)) :?> | |
132 | - <?php foreach($groups->all() as $group) :?> | |
133 | - <?= $form->field($model, 'options')->checkboxList( | |
134 | - ArrayHelper::map($group->options, 'tax_option_id', 'ValueRenderFlash'), | |
104 | + <?php DynamicFormWidget::begin( | |
135 | 105 | [ |
136 | - 'multiple' => true, | |
137 | - 'unselect' => null, | |
106 | + 'widgetContainer' => 'dynamicform_wrapper', | |
107 | + // required: only alphanumeric characters plus "_" [A-Za-z0-9_] | |
108 | + 'widgetBody' => '.container-items', | |
109 | + // required: css class selector | |
110 | + 'widgetItem' => '.item', | |
111 | + // required: css class | |
112 | + 'limit' => 10, | |
113 | + // the maximum times, an element can be added (default 999) | |
114 | + 'min' => 0, | |
115 | + // 0 or 1 (default 1) | |
116 | + 'insertButton' => '.add-item', | |
117 | + // css class | |
118 | + 'deleteButton' => '.remove-item', | |
119 | + // css class | |
120 | + 'model' => $stocks[ 0 ], | |
121 | + 'formId' => 'dynamic-form', | |
122 | + 'formFields' => [ | |
123 | + 'quantity', | |
124 | + 'name', | |
125 | + ], | |
138 | 126 | ] |
139 | - )->label($group->name);?> | |
140 | - <?php endforeach?> | |
141 | - <?php endif?> | |
142 | - | |
143 | - <div class="form-group"> | |
144 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
127 | + ); ?> | |
128 | + | |
129 | + <div class="panel panel-default"> | |
130 | + <div class="panel-heading"> | |
131 | + <h4> | |
132 | + <i class="glyphicon glyphicon-envelope"></i> Склады | |
133 | + <button type="button" class="add-item btn btn-success btn-sm pull-right"> | |
134 | + <i class="glyphicon glyphicon-plus"></i> Add | |
135 | + </button> | |
136 | + </h4> | |
145 | 137 | </div> |
146 | - | |
138 | + <div class="panel-body"> | |
139 | + <div class="container-items"><!-- widgetBody --> | |
140 | + <?php foreach ($stocks as $i => $stock): ?> | |
141 | + <div class="item panel panel-default"><!-- widgetItem --> | |
142 | + <div class="panel-body"> | |
143 | + <?php | |
144 | + // necessary for update action. | |
145 | + if (!$stock->isNewRecord) { | |
146 | + echo Html::activeHiddenInput($stock, "[{$i}]stock_id"); | |
147 | + } | |
148 | + ?> | |
149 | + <div class="row"> | |
150 | + <div class="col-sm-5"> | |
151 | + <?= $form->field($stock, "[{$i}]quantity") | |
152 | + ->textInput([ 'maxlength' => true ]) ?> | |
153 | + </div> | |
154 | + <div class="col-sm-5"> | |
155 | + <?= $form->field($stock, "[{$i}]name") | |
156 | + ->textInput([ 'maxlength' => true ]) ?> | |
157 | + </div> | |
158 | + <div class="col-sm-2" style="margin-top: 30px"> | |
159 | + <button type="button" class="remove-item btn btn-danger btn-xs"> | |
160 | + <i class="glyphicon glyphicon-minus"></i></button> | |
161 | + </div> | |
162 | + </div><!-- .row --> | |
163 | + </div> | |
164 | + </div> | |
165 | + <?php endforeach; ?> | |
166 | + </div> | |
167 | + </div> | |
168 | + </div><!-- .panel --> | |
169 | + <?php DynamicFormWidget::end(); ?> | |
170 | + | |
171 | + <?= $form->field($model, 'product_unit_id') | |
172 | + ->dropDownList( | |
173 | + ArrayHelper::map( | |
174 | + \common\modules\product\models\ProductUnit::find() | |
175 | + ->all(), | |
176 | + 'product_unit_id', | |
177 | + 'name' | |
178 | + ), | |
179 | + [ | |
180 | + 'prompt' => Yii::t('product', 'Unit'), | |
181 | + ] | |
182 | + ) | |
183 | + ->label(Yii::t('product', 'Unit')) ?> | |
184 | + | |
185 | + <?php if (isset($groups)) : ?> | |
186 | + <?php foreach ($groups->all() as $group) : ?> | |
187 | + <?= $form->field($model, 'options') | |
188 | + ->checkboxList( | |
189 | + ArrayHelper::map($group->options, 'tax_option_id', 'ValueRenderFlash'), | |
190 | + [ | |
191 | + 'multiple' => true, | |
192 | + 'unselect' => null, | |
193 | + ] | |
194 | + ) | |
195 | + ->label($group->name); ?> | |
196 | + <?php endforeach ?> | |
197 | + <?php endif ?> | |
198 | + | |
199 | + <div class="form-group"> | |
200 | + <?= Html::submitButton( | |
201 | + $model->isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), | |
202 | + [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ] | |
203 | + ) ?> | |
204 | + </div> | |
205 | + | |
147 | 206 | <?php ActiveForm::end(); ?> |
148 | 207 | |
149 | 208 | </div> | ... | ... |
frontend/views/catalog/product.php
... | ... | @@ -13,7 +13,6 @@ |
13 | 13 | use yii\bootstrap\ActiveForm; |
14 | 14 | use yii\bootstrap\Html; |
15 | 15 | use yii\helpers\Url; |
16 | - use yii\helpers\VarDumper; | |
17 | 16 | use yii\web\View; |
18 | 17 | use yii\widgets\MaskedInput; |
19 | 18 | use frontend\assets\FlipclockAsset; |
... | ... | @@ -227,6 +226,8 @@ |
227 | 226 | <td class="left_count available"> |
228 | 227 | <?php if($product->variant->status == 1){?> |
229 | 228 | снят с производства |
229 | + <?php } elseif($product->variant->status == 2) {?> | |
230 | + в ожидании | |
230 | 231 | <?php } elseif($product->variant->stock > 0) {?> |
231 | 232 | в наличии |
232 | 233 | <?php } else {?> | ... | ... |