Commit 70753ad435c05db144cb98c8fa81728bd9685085
1 parent
2b315849
-Product card (video added)
Showing
2 changed files
with
42 additions
and
18 deletions
Show diff stats
controllers/ManageController.php
... | ... | @@ -11,6 +11,7 @@ |
11 | 11 | use artweb\artbox\ecommerce\models\Product; |
12 | 12 | use artweb\artbox\ecommerce\models\ProductSearch; |
13 | 13 | use yii\db\ActiveQuery; |
14 | + use yii\helpers\VarDumper; | |
14 | 15 | use yii\web\Controller; |
15 | 16 | use yii\web\NotFoundHttpException; |
16 | 17 | use yii\filters\VerbFilter; |
... | ... | @@ -98,6 +99,16 @@ |
98 | 99 | if ($model->load(Yii::$app->request->post())) { |
99 | 100 | $model->loadLangs(\Yii::$app->request); |
100 | 101 | if ($model->save() && $model->transactionStatus) { |
102 | + if (!empty( \Yii::$app->request->post('ProductVideo') )) | |
103 | + { | |
104 | + foreach (\Yii::$app->request->post('ProductVideo') as $video) | |
105 | + { | |
106 | + $modelVideo = new ProductVideo(); | |
107 | + $modelVideo->url = $video['url']; | |
108 | + $model->link('videos', $modelVideo); | |
109 | + } | |
110 | + } | |
111 | + | |
101 | 112 | return $this->redirect( |
102 | 113 | [ |
103 | 114 | 'view', |
... | ... | @@ -127,9 +138,21 @@ |
127 | 138 | { |
128 | 139 | $model = $this->findModel($id); |
129 | 140 | $model->generateLangs(); |
141 | + | |
130 | 142 | if ($model->load(Yii::$app->request->post())) { |
131 | 143 | $model->loadLangs(\Yii::$app->request); |
144 | + $model->unlinkAll('videos', true); | |
132 | 145 | if ($model->save() && $model->transactionStatus) { |
146 | + if (!empty( \Yii::$app->request->post('ProductVideo') )) | |
147 | + { | |
148 | + foreach (\Yii::$app->request->post('ProductVideo') as $video) | |
149 | + { | |
150 | + $modelVideo = new ProductVideo(); | |
151 | + $modelVideo->url = $video['url']; | |
152 | + $model->link('videos', $modelVideo); | |
153 | + } | |
154 | + } | |
155 | + | |
133 | 156 | return $this->redirect( |
134 | 157 | [ |
135 | 158 | 'view', | ... | ... |
views/manage/_form.php
... | ... | @@ -44,7 +44,10 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
44 | 44 | |
45 | 45 | <?php $form = ActiveForm::begin( |
46 | 46 | [ |
47 | - 'options' => [ 'enctype' => 'multipart/form-data' ], | |
47 | + 'options' => [ | |
48 | + 'enctype' => 'multipart/form-data', | |
49 | + 'id' => 'dynamic-form', | |
50 | + ], | |
48 | 51 | ] |
49 | 52 | ); ?> |
50 | 53 | |
... | ... | @@ -55,9 +58,6 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
55 | 58 | <?= $form->field($model, 'is_discount') |
56 | 59 | ->checkbox([ 'label' => 'Акционный' ]) ?> |
57 | 60 | |
58 | - <?= $form->field($model, 'video') | |
59 | - ->textarea(); ?> | |
60 | - | |
61 | 61 | <?php DynamicFormWidget::begin( |
62 | 62 | [ |
63 | 63 | 'widgetContainer' => 'dynamicform_wrapper', |
... | ... | @@ -68,7 +68,7 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
68 | 68 | // required: css class |
69 | 69 | 'limit' => 10, |
70 | 70 | // the maximum times, an element can be added (default 999) |
71 | - 'min' => 1, | |
71 | + 'min' => 0, | |
72 | 72 | // 0 or 1 (default 1) |
73 | 73 | 'insertButton' => '.add-item', |
74 | 74 | // css class |
... | ... | @@ -77,7 +77,8 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
77 | 77 | 'model' => $videos[ 0 ], |
78 | 78 | 'formId' => 'dynamic-form', |
79 | 79 | 'formFields' => [ |
80 | - 'url', | |
80 | + 'quantity', | |
81 | + 'title', | |
81 | 82 | ], |
82 | 83 | ] |
83 | 84 | ); ?> |
... | ... | @@ -85,7 +86,7 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
85 | 86 | <div class="panel panel-default"> |
86 | 87 | <div class="panel-heading"> |
87 | 88 | <h4> |
88 | - <i class="glyphicon glyphicon-envelope"></i> Склады | |
89 | + <i class="glyphicon glyphicon-film"></i> Видео (Пример: <iframe src='https://www.youtube.com/embed/6mXhDfoJau4' frameborder='0' allowfullscreen></iframe>) | |
89 | 90 | <button type="button" class="add-item btn btn-success btn-sm pull-right"> |
90 | 91 | <i class="glyphicon glyphicon-plus"></i> Add |
91 | 92 | </button> |
... | ... | @@ -93,28 +94,28 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { |
93 | 94 | </div> |
94 | 95 | <div class="panel-body"> |
95 | 96 | <div class="container-items"><!-- widgetBody --> |
96 | - <?php foreach ($videos as $i => $video) { ?> | |
97 | + <?php foreach ($videos as $i => $video): ?> | |
97 | 98 | <div class="item panel panel-default"><!-- widgetItem --> |
98 | 99 | <div class="panel-body"> |
99 | -<!-- --><?php | |
100 | -// // necessary for update action. | |
101 | -// if (!$stock->isNewRecord) { | |
102 | -// echo Html::activeHiddenInput($stock, "[{$i}]stock_id"); | |
103 | -// } | |
104 | -// ?> | |
100 | + <?php | |
101 | + // necessary for update action. | |
102 | + if (!$video->isNewRecord) { | |
103 | + echo Html::activeHiddenInput($video, "[{$i}]id"); | |
104 | + } | |
105 | + ?> | |
105 | 106 | <div class="row"> |
106 | - <div class="col-sm-5"> | |
107 | + <div class="col-sm-11"> | |
107 | 108 | <?= $form->field($video, "[{$i}]url") |
108 | - ->textInput([ 'maxlength' => true ]) ?> | |
109 | + ->textInput([ 'maxlength' => true ])->label('Iframe') ?> | |
109 | 110 | </div> |
110 | - <div class="col-sm-2" style="margin-top: 30px"> | |
111 | + <div class="col-sm-1" style="margin-top: 30px"> | |
111 | 112 | <button type="button" class="remove-item btn btn-danger btn-xs"> |
112 | 113 | <i class="glyphicon glyphicon-minus"></i></button> |
113 | 114 | </div> |
114 | 115 | </div><!-- .row --> |
115 | 116 | </div> |
116 | 117 | </div> |
117 | - <?php } ?> | |
118 | + <?php endforeach; ?> | |
118 | 119 | </div> |
119 | 120 | </div> |
120 | 121 | </div><!-- .panel --> | ... | ... |