From 70753ad435c05db144cb98c8fa81728bd9685085 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 15 Nov 2016 16:37:18 +0200 Subject: [PATCH] -Product card (video added) --- controllers/ManageController.php | 23 +++++++++++++++++++++++ views/manage/_form.php | 37 +++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/controllers/ManageController.php b/controllers/ManageController.php index 7b89685..2701cb8 100755 --- a/controllers/ManageController.php +++ b/controllers/ManageController.php @@ -11,6 +11,7 @@ use artweb\artbox\ecommerce\models\Product; use artweb\artbox\ecommerce\models\ProductSearch; use yii\db\ActiveQuery; + use yii\helpers\VarDumper; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -98,6 +99,16 @@ if ($model->load(Yii::$app->request->post())) { $model->loadLangs(\Yii::$app->request); if ($model->save() && $model->transactionStatus) { + if (!empty( \Yii::$app->request->post('ProductVideo') )) + { + foreach (\Yii::$app->request->post('ProductVideo') as $video) + { + $modelVideo = new ProductVideo(); + $modelVideo->url = $video['url']; + $model->link('videos', $modelVideo); + } + } + return $this->redirect( [ 'view', @@ -127,9 +138,21 @@ { $model = $this->findModel($id); $model->generateLangs(); + if ($model->load(Yii::$app->request->post())) { $model->loadLangs(\Yii::$app->request); + $model->unlinkAll('videos', true); if ($model->save() && $model->transactionStatus) { + if (!empty( \Yii::$app->request->post('ProductVideo') )) + { + foreach (\Yii::$app->request->post('ProductVideo') as $video) + { + $modelVideo = new ProductVideo(); + $modelVideo->url = $video['url']; + $model->link('videos', $modelVideo); + } + } + return $this->redirect( [ 'view', diff --git a/views/manage/_form.php b/views/manage/_form.php index d9b708a..2ad795d 100755 --- a/views/manage/_form.php +++ b/views/manage/_form.php @@ -44,7 +44,10 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { [ 'enctype' => 'multipart/form-data' ], + 'options' => [ + 'enctype' => 'multipart/form-data', + 'id' => 'dynamic-form', + ], ] ); ?> @@ -55,9 +58,6 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { field($model, 'is_discount') ->checkbox([ 'label' => 'Акционный' ]) ?> - field($model, 'video') - ->textarea(); ?> - 'dynamicform_wrapper', @@ -68,7 +68,7 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { // required: css class 'limit' => 10, // the maximum times, an element can be added (default 999) - 'min' => 1, + 'min' => 0, // 0 or 1 (default 1) 'insertButton' => '.add-item', // css class @@ -77,7 +77,8 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { 'model' => $videos[ 0 ], 'formId' => 'dynamic-form', 'formFields' => [ - 'url', + 'quantity', + 'title', ], ] ); ?> @@ -85,7 +86,7 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) {

- Склады + Видео (Пример: <iframe src='https://www.youtube.com/embed/6mXhDfoJau4' frameborder='0' allowfullscreen></iframe>) @@ -93,28 +94,28 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) {

- $video) { ?> + $video): ?>
-isNewRecord) { -// echo Html::activeHiddenInput($stock, "[{$i}]stock_id"); -// } -// ?> + isNewRecord) { + echo Html::activeHiddenInput($video, "[{$i}]id"); + } + ?>
-
+
field($video, "[{$i}]url") - ->textInput([ 'maxlength' => true ]) ?> + ->textInput([ 'maxlength' => true ])->label('Iframe') ?>
-
+
- +
-- libgit2 0.21.4