Commit 70753ad435c05db144cb98c8fa81728bd9685085

Authored by Alexey Boroda
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,6 +11,7 @@
11 use artweb\artbox\ecommerce\models\Product; 11 use artweb\artbox\ecommerce\models\Product;
12 use artweb\artbox\ecommerce\models\ProductSearch; 12 use artweb\artbox\ecommerce\models\ProductSearch;
13 use yii\db\ActiveQuery; 13 use yii\db\ActiveQuery;
  14 + use yii\helpers\VarDumper;
14 use yii\web\Controller; 15 use yii\web\Controller;
15 use yii\web\NotFoundHttpException; 16 use yii\web\NotFoundHttpException;
16 use yii\filters\VerbFilter; 17 use yii\filters\VerbFilter;
@@ -98,6 +99,16 @@ @@ -98,6 +99,16 @@
98 if ($model->load(Yii::$app->request->post())) { 99 if ($model->load(Yii::$app->request->post())) {
99 $model->loadLangs(\Yii::$app->request); 100 $model->loadLangs(\Yii::$app->request);
100 if ($model->save() && $model->transactionStatus) { 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 return $this->redirect( 112 return $this->redirect(
102 [ 113 [
103 'view', 114 'view',
@@ -127,9 +138,21 @@ @@ -127,9 +138,21 @@
127 { 138 {
128 $model = $this->findModel($id); 139 $model = $this->findModel($id);
129 $model->generateLangs(); 140 $model->generateLangs();
  141 +
130 if ($model->load(Yii::$app->request->post())) { 142 if ($model->load(Yii::$app->request->post())) {
131 $model->loadLangs(\Yii::$app->request); 143 $model->loadLangs(\Yii::$app->request);
  144 + $model->unlinkAll('videos', true);
132 if ($model->save() && $model->transactionStatus) { 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 return $this->redirect( 156 return $this->redirect(
134 [ 157 [
135 'view', 158 'view',
views/manage/_form.php
@@ -44,7 +44,10 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { @@ -44,7 +44,10 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) {
44 44
45 <?php $form = ActiveForm::begin( 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 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) { @@ -55,9 +58,6 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) {
55 <?= $form->field($model, 'is_discount') 58 <?= $form->field($model, 'is_discount')
56 ->checkbox([ 'label' => 'Акционный' ]) ?> 59 ->checkbox([ 'label' => 'Акционный' ]) ?>
57 60
58 - <?= $form->field($model, 'video')  
59 - ->textarea(); ?>  
60 -  
61 <?php DynamicFormWidget::begin( 61 <?php DynamicFormWidget::begin(
62 [ 62 [
63 'widgetContainer' => 'dynamicform_wrapper', 63 'widgetContainer' => 'dynamicform_wrapper',
@@ -68,7 +68,7 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) { @@ -68,7 +68,7 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) {
68 // required: css class 68 // required: css class
69 'limit' => 10, 69 'limit' => 10,
70 // the maximum times, an element can be added (default 999) 70 // the maximum times, an element can be added (default 999)
71 - 'min' => 1, 71 + 'min' => 0,
72 // 0 or 1 (default 1) 72 // 0 or 1 (default 1)
73 'insertButton' => '.add-item', 73 'insertButton' => '.add-item',
74 // css class 74 // css class
@@ -77,7 +77,8 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) { @@ -77,7 +77,8 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) {
77 'model' => $videos[ 0 ], 77 'model' => $videos[ 0 ],
78 'formId' => 'dynamic-form', 78 'formId' => 'dynamic-form',
79 'formFields' => [ 79 'formFields' => [
80 - 'url', 80 + 'quantity',
  81 + 'title',
81 ], 82 ],
82 ] 83 ]
83 ); ?> 84 ); ?>
@@ -85,7 +86,7 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) { @@ -85,7 +86,7 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) {
85 <div class="panel panel-default"> 86 <div class="panel panel-default">
86 <div class="panel-heading"> 87 <div class="panel-heading">
87 <h4> 88 <h4>
88 - <i class="glyphicon glyphicon-envelope"></i> Склады 89 + <i class="glyphicon glyphicon-film"></i> Видео (Пример: &ltiframe src='https://www.youtube.com/embed/6mXhDfoJau4' frameborder='0' allowfullscreen&gt&lt/iframe&gt)
89 <button type="button" class="add-item btn btn-success btn-sm pull-right"> 90 <button type="button" class="add-item btn btn-success btn-sm pull-right">
90 <i class="glyphicon glyphicon-plus"></i> Add 91 <i class="glyphicon glyphicon-plus"></i> Add
91 </button> 92 </button>
@@ -93,28 +94,28 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) { @@ -93,28 +94,28 @@ $(&quot;.dynamicform_wrapper&quot;).on(&quot;limitReached&quot;, function(e, item) {
93 </div> 94 </div>
94 <div class="panel-body"> 95 <div class="panel-body">
95 <div class="container-items"><!-- widgetBody --> 96 <div class="container-items"><!-- widgetBody -->
96 - <?php foreach ($videos as $i => $video) { ?> 97 + <?php foreach ($videos as $i => $video): ?>
97 <div class="item panel panel-default"><!-- widgetItem --> 98 <div class="item panel panel-default"><!-- widgetItem -->
98 <div class="panel-body"> 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 <div class="row"> 106 <div class="row">
106 - <div class="col-sm-5"> 107 + <div class="col-sm-11">
107 <?= $form->field($video, "[{$i}]url") 108 <?= $form->field($video, "[{$i}]url")
108 - ->textInput([ 'maxlength' => true ]) ?> 109 + ->textInput([ 'maxlength' => true ])->label('Iframe') ?>
109 </div> 110 </div>
110 - <div class="col-sm-2" style="margin-top: 30px"> 111 + <div class="col-sm-1" style="margin-top: 30px">
111 <button type="button" class="remove-item btn btn-danger btn-xs"> 112 <button type="button" class="remove-item btn btn-danger btn-xs">
112 <i class="glyphicon glyphicon-minus"></i></button> 113 <i class="glyphicon glyphicon-minus"></i></button>
113 </div> 114 </div>
114 </div><!-- .row --> 115 </div><!-- .row -->
115 </div> 116 </div>
116 </div> 117 </div>
117 - <?php } ?> 118 + <?php endforeach; ?>
118 </div> 119 </div>
119 </div> 120 </div>
120 </div><!-- .panel --> 121 </div><!-- .panel -->