Blame view

views/order/_form.php 11.1 KB
2a050410   Yarik   Order
1
2
  <?php
      
fd40a9e1   Yarik   Products to order
3
      use kartik\select2\Select2;
2a050410   Yarik   Order
4
      use yii\bootstrap\Html;
fd40a9e1   Yarik   Products to order
5
6
      use yii\helpers\Url;
      use yii\web\JsExpression;
0b5518db   Alexey Boroda   -Order products h...
7
      use yii\web\View;
2a050410   Yarik   Order
8
9
10
11
12
13
14
15
16
17
      use yii\widgets\ActiveForm;
      
      /**
       * @var \yii\web\View              $this
       * @var \artbox\order\models\Order $model
       * @var array                      $labels
       * @var array                      $deliveries
       * @var array                      $payments
       * @var ActiveForm                 $form
       */
0b5518db   Alexey Boroda   -Order products h...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
      
      $js = <<< JS
  $(document).on('click', '#create-add', function(e) {
    e.preventDefault();
    var variant_id = $('#add-to-order').val();
    var count = $('#count-to-order').val();
    
    $.ajax({
        url: '/admin/order-product/add',
        type: "GET",
        data: {
            variant_id: variant_id,
            count: count
        },
        success: function(data) {
b6da6360   Alexey Boroda   -Order products r...
33
34
35
36
37
38
39
40
41
42
            if (data.id != 0) {
               var row = $('#products #' + data.id);
               if (row.length !== 0) {
                   row.find('.count-input').val(function(i, oldVal) {
                     return parseInt(oldVal, 10) + data.count;
                   });
               } else {
                  $('#products').append(data.row);                 
               }
            }
0b5518db   Alexey Boroda   -Order products h...
43
44
45
        }
    });
  });
b6da6360   Alexey Boroda   -Order products r...
46
47
48
49
  $(document).on('click', '.delete-product-row', function(e) {
    e.preventDefault();
    $(this).parent().parent().remove();
  })
0b5518db   Alexey Boroda   -Order products h...
50
51
52
53
  JS;
      
      $this->registerJs($js, View::POS_READY);
  
2a050410   Yarik   Order
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
  ?>
  
  <div class="order-form">
      
      <?php $form = ActiveForm::begin(); ?>
      
      <?php
          if ($model->isNewRecord) {
              echo $form->field($model, 'user_id')
                        ->textInput();
          }
      ?>
      
      <?= $form->field($model, 'name')
               ->textInput([ 'maxlength' => true ]) ?>
      
      <?= $form->field($model, 'phone')
               ->textInput([ 'maxlength' => true ]) ?>
      
      <?= $form->field($model, 'email')
               ->textInput([ 'maxlength' => true ]) ?>
      
      <?= $form->field($model, 'city')
               ->textInput([ 'maxlength' => true ]) ?>
      
      <?= $form->field($model, 'address')
               ->textInput([ 'maxlength' => true ]) ?>
      
      <?= $form->field($model, 'comment')
               ->textInput([ 'maxlength' => true ]) ?>
      
      <?= $form->field($model, 'label_id')
               ->dropDownList($labels) ?>
      
      <?= $form->field($model, 'delivery_id')
               ->dropDownList($deliveries) ?>
      
      <?= $form->field($model, 'payment_id')
               ->dropDownList($payments) ?>
      <?php
          if (!$model->isNewRecord) {
              ?>
            <div class="order-product-container">
fd40a9e1   Yarik   Products to order
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
              <div id="order-product-pjax" style="position: relative;">
                <div class="row strong">
                  <div class="col-md-4">
                      <?php
                          echo Html::tag('strong', \Yii::t('order', 'Product'));
                      ?>
                  </div>
                  <div class="col-md-4">
                      <?php
                          echo Html::tag('strong', \Yii::t('order', 'Price'));
                      ?>
                  </div>
                  <div class="col-md-4">
                      <?php
                          echo Html::tag('strong', \Yii::t('order', 'Count'));
                      ?>
                  </div>
                </div>
b12f37d7   Alexey Boroda   -Order products s...
115
      
fd40a9e1   Yarik   Products to order
116
                  <?php
b588767b   Anastasia   all sum in order
117
                    $sum = 0;
fd40a9e1   Yarik   Products to order
118
                      foreach ($model->orderProducts as $index => $orderProduct) {
b588767b   Anastasia   all sum in order
119
                        $sum += ($orderProduct->count * $orderProduct->price)
fd40a9e1   Yarik   Products to order
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
                          ?>
                        <div class="row row-order-product">
                          <div class="col-md-4">
                              <?php
                                  echo $form->field($orderProduct, "[$index]variant_id")
                                            ->hiddenInput()
                                            ->label(false);
                                  echo $orderProduct->variant->product->lang->title . '(' . $orderProduct->variant->sku . ')';
                              ?>
                          </div>
                          <div class="col-md-4">
                              <?php echo $orderProduct->price; ?>
                          </div>
                          <div class="col-md-3">
                              <?php
                                  echo $form->field($orderProduct, "[$index]count")
                                            ->textInput()
                                            ->label(false);
                              ?>
                          </div>
                          <div class="col-md-1">
                              <?php
                                  echo Html::a(
                                      Html::icon(
                                          'trash-o',
                                          [
                                              'prefix' => 'fa fa-',
                                          ]
                                      ),
                                      '#',
                                      [
                                          'class' => 'remove-order-product',
                                      ]
                                  )
                              ?>
                          </div>
                        </div>
                          <?php
                      }
                  ?>
              </div>
              <div class="row">
                <div class="col-md-8">
2a050410   Yarik   Order
163
                    <?php
fd40a9e1   Yarik   Products to order
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
                        echo Select2::widget(
                            [
                                'name'          => 'add-to-order',
                                'options'       => [
                                    'placeholder' => \Yii::t('order', 'Select product'),
                                ],
                                'pluginOptions' => [
                                    'allowClear'         => true,
                                    'minimumInputLength' => 3,
                                    'language'           => [
                                        'errorLoading' => new JsExpression(
                                            "function() {return '" . \Yii::t('order', 'Waiting for results') . "'; }"
                                        ),
                                    ],
                                    'ajax'               => [
                                        'url'      => Url::to([ 'product-list' ]),
                                        'dataType' => 'json',
                                        'data'     => new JsExpression('function(params) { return {q:params.term}; }'),
                                    ],
                                    'escapeMarkup'       => new JsExpression('function (markup) { return markup; }'),
                                    'templateResult'     => new JsExpression('function(city) { return city.text; }'),
                                    'templateSelection'  => new JsExpression('function (city) { return city.text; }'),
                                ],
                                'id'            => 'add-to-order',
                            ]
                        );
2a050410   Yarik   Order
190
191
                    ?>
                </div>
fd40a9e1   Yarik   Products to order
192
                <div class="col-md-3">
2a050410   Yarik   Order
193
                    <?php
fd40a9e1   Yarik   Products to order
194
195
196
197
198
199
200
201
                        echo Html::textInput(
                            'count-to-order',
                            null,
                            [
                                'class' => 'form-control',
                                'id'    => 'count-to-order',
                            ]
                        );
2a050410   Yarik   Order
202
203
                    ?>
                </div>
fd40a9e1   Yarik   Products to order
204
                <div class="col-md-1">
2a050410   Yarik   Order
205
                    <?php
fd40a9e1   Yarik   Products to order
206
207
208
209
210
211
212
213
214
215
216
217
218
                        echo Html::a(
                            Html::icon(
                                'plus-circle',
                                [
                                    'prefix' => 'fa fa-',
                                ]
                            ),
                            '#',
                            [
                                'class'   => 'variant-to-order',
                                'data-id' => $model->id,
                            ]
                        );
2a050410   Yarik   Order
219
220
221
                    ?>
                </div>
              </div>
2a050410   Yarik   Order
222
223
            </div>
              <?php
b12f37d7   Alexey Boroda   -Order products s...
224
225
          } else {
              ?>
b12f37d7   Alexey Boroda   -Order products s...
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
            <div class="row">
              <div class="col-md-8">
                  <?php
                      echo Select2::widget(
                          [
                              'name'          => 'add-to-order',
                              'options'       => [
                                  'placeholder' => \Yii::t('order', 'Select product'),
                              ],
                              'pluginOptions' => [
                                  'allowClear'         => true,
                                  'minimumInputLength' => 3,
                                  'language'           => [
                                      'errorLoading' => new JsExpression(
                                          "function() {return '" . \Yii::t('order', 'Waiting for results') . "'; }"
                                      ),
                                  ],
                                  'ajax'               => [
                                      'url'      => Url::to([ 'product-list' ]),
                                      'dataType' => 'json',
                                      'data'     => new JsExpression('function(params) { return {q:params.term}; }'),
                                  ],
                                  'escapeMarkup'       => new JsExpression('function (markup) { return markup; }'),
                                  'templateResult'     => new JsExpression('function(city) { return city.text; }'),
                                  'templateSelection'  => new JsExpression('function (city) { return city.text; }'),
                              ],
                              'id'            => 'add-to-order',
                          ]
                      );
                  ?>
              </div>
              <div class="col-md-3">
                  <?php
0b5518db   Alexey Boroda   -Order products h...
259
260
                      echo Html::input(
                          'number',
b12f37d7   Alexey Boroda   -Order products s...
261
262
263
264
265
266
267
268
269
270
271
272
                          'count-to-order',
                          null,
                          [
                              'class' => 'form-control',
                              'id'    => 'count-to-order',
                          ]
                      );
                  ?>
              </div>
              <div class="col-md-1">
                  <?php
                      echo Html::a(
0b5518db   Alexey Boroda   -Order products h...
273
                          '<i class="fa fa-plus"></i>',
b12f37d7   Alexey Boroda   -Order products s...
274
275
                          '#',
                          [
0b5518db   Alexey Boroda   -Order products h...
276
277
                              'class' => 'btn btn-success',
                              'id'    => 'create-add',
b12f37d7   Alexey Boroda   -Order products s...
278
279
280
281
282
                          ]
                      );
                  ?>
              </div>
            </div>
0b5518db   Alexey Boroda   -Order products h...
283
284
    
            <div id="products"></div>
b12f37d7   Alexey Boroda   -Order products s...
285
286
      
              <?php
2a050410   Yarik   Order
287
288
289
          }
      ?>
    
b12f37d7   Alexey Boroda   -Order products s...
290
    <div class="ln_solid"></div>
4cc8ac6c   Anastasia   all sum in order
291
    <div class="form-group">Всего: <?=$sum?></div>
2a050410   Yarik   Order
292
293
294
295
296
297
298
299
300
301
    <div class="form-group">
        <?= Html::submitButton(
            $model->isNewRecord ? Yii::t('order', 'Create') : Yii::t('order', 'Update'),
            [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
        ) ?>
    </div>
      
      <?php ActiveForm::end(); ?>
  
  </div>