diff --git a/controllers/OrderController.php b/controllers/OrderController.php
index d5409d9..5d723ff 100755
--- a/controllers/OrderController.php
+++ b/controllers/OrderController.php
@@ -202,7 +202,7 @@
$dataProvider = new ActiveDataProvider(
[
- 'query' => $model->getProducts(),
+ 'query' => $model->getProducts()->joinWith('productVariant'),
]
);
@@ -271,7 +271,7 @@
$dataProvider = new ActiveDataProvider(
[
- 'query' => $model->getProducts(),
+ 'query' => $model->getProducts()->joinWith('productVariant.product.brand'),
]
);
diff --git a/models/Order.php b/models/Order.php
index 8ce9a07..4cf4380 100755
--- a/models/Order.php
+++ b/models/Order.php
@@ -2,6 +2,7 @@
namespace artweb\artbox\ecommerce\models;
use artweb\artbox\models\Customer;
+ use common\models\User;
use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
@@ -20,6 +21,7 @@
* @property string $check
* @property string $sms
* @property int $id
+ * @property integer $manager_id
* @property int $user_id
* @property string $name
* @property string $phone
@@ -88,10 +90,15 @@
'payment',
'reason',
'label',
+ 'manager_id',
],
'integer',
],
[
+ [ 'total' ],
+ 'double',
+ ],
+ [
[
'phone',
],
@@ -127,7 +134,6 @@
'shipping_by',
'city',
'adress',
- 'total',
'status',
'check',
'sms',
@@ -170,17 +176,19 @@
public function attributeLabels()
{
return [
- 'name' => Yii::t('app', 'order_name'),
- 'phone' => Yii::t('app', 'order_phone'),
- 'email' => Yii::t('app', 'order_email'),
- 'comment' => Yii::t('app', 'order_comment'),
- 'created_at' => Yii::t('app', 'Дата добавления'),
- 'updated_at' => Yii::t('app', 'Дата обновления'),
- 'deleted_at' => Yii::t('app', 'Дата удаления'),
- 'deadline' => Yii::t('app', 'Дедлайн'),
- 'reason' => Yii::t('app', 'Причина'),
- 'check' => Yii::t('app', 'Чек'),
- 'sms' => Yii::t('app', 'СМС'),
+ 'name' => Yii::t('app', 'order_name'),
+ 'phone' => Yii::t('app', 'order_phone'),
+ 'email' => Yii::t('app', 'order_email'),
+ 'comment' => Yii::t('app', 'order_comment'),
+ 'created_at' => Yii::t('app', 'Дата добавления'),
+ 'updated_at' => Yii::t('app', 'Дата обновления'),
+ 'deleted_at' => Yii::t('app', 'Дата удаления'),
+ 'deadline' => Yii::t('app', 'Дедлайн'),
+ 'reason' => Yii::t('app', 'Причина'),
+ 'check' => Yii::t('app', 'Чек'),
+ 'sms' => Yii::t('app', 'СМС'),
+ 'consignment' => Yii::t('app', 'Номер накладной'),
+ 'manager_id' => Yii::t('app', 'Менеджер'),
];
}
@@ -236,18 +244,27 @@
return '';
}
}
-
+
/**
* If deadline is fucked up returns true,
* if deadline is not setted return false, like everything is ok
+ *
* @return bool
*/
public function getWasted()
{
- if (empty($this->deadline)) {
+ if (empty( $this->deadline )) {
return false;
} else {
return time() > strtotime($this->deadline);
}
}
+
+ /**
+ *
+ */
+ public function getManager()
+ {
+ $this->hasOne(User::className(), [ 'id' => 'manager_id' ]);
+ }
}
\ No newline at end of file
diff --git a/models/OrderProduct.php b/models/OrderProduct.php
index ce36314..1f308b3 100755
--- a/models/OrderProduct.php
+++ b/models/OrderProduct.php
@@ -29,6 +29,13 @@
return 'order_product';
}
+ public function beforeSave($insert)
+ {
+ $this->price = $this->productVariant->price;
+ $this->sum_cost = $this->price * $this->count;
+ return parent::beforeSave($insert); // TODO: Change the autogenerated stub
+ }
+
public function rules()
{
return [
diff --git a/models/OrderSearch.php b/models/OrderSearch.php
index a5b667c..1fe71cb 100755
--- a/models/OrderSearch.php
+++ b/models/OrderSearch.php
@@ -4,6 +4,7 @@
use yii\base\Model;
use yii\data\ActiveDataProvider;
+ use yii\helpers\VarDumper;
/**
* OrderSearch represents the model behind the search form about `\artweb\artbox\ecommerce\models\Order`.
@@ -13,6 +14,7 @@
public $date_from;
public $date_to;
public $date_range;
+ public $sku;
/**
* @inheritdoc
@@ -23,10 +25,7 @@
[
[
'id',
- 'user_id',
- 'delivery',
- 'payment',
- 'status',
+ 'manager_id',
],
'integer',
],
@@ -38,7 +37,13 @@
'date_from',
'date_to',
'date_range',
- 'created_at'
+ 'created_at',
+ 'body',
+ 'declaration',
+ 'consignment',
+ 'delivery',
+ 'label',
+ 'sku',
],
'safe',
],
@@ -75,20 +80,27 @@
$this->load($params);
+ // VarDumper::dump($params, 10, true); die();
+
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
+ if (!empty( $this->sku )) {
+ $query->innerJoinWith('products.productVariant')
+ ->andWhere(
+ [
+ 'product_variant.id' => $this->sku,
+ ]
+ );
+ }
+
// grid filtering conditions
$query->andFilterWhere(
[
- 'id' => $this->id,
- 'user_id' => $this->user_id,
- 'delivery' => $this->delivery,
- 'payment' => $this->payment,
- 'status' => $this->status,
+ 'id' => $this->id,
]
);
@@ -98,25 +110,63 @@
'name',
$this->name,
]
- )
- ->andFilterWhere(
- [
- 'like',
- 'email',
- $this->email,
- ]
- )
- ->andFilterWhere(
- [
- 'like',
- 'phone',
- $this->phone,
- ]
- );
- if (!empty($this->date_range)) {
+ );
+ $query->andFilterWhere(
+ [
+ 'like',
+ 'email',
+ $this->email,
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'like',
+ 'phone',
+ $this->phone,
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'like',
+ 'body',
+ $this->body,
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'like',
+ 'consignment',
+ $this->consignment,
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'like',
+ 'declaration',
+ $this->declaration,
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'label' => $this->label,
+
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'manager_id' => $this->manager_id,
+
+ ]
+ );
+ $query->andFilterWhere(
+ [
+ 'delivery' => $this->delivery,
+ ]
+ );
+ if (!empty( $this->date_range )) {
$this->date_from = strtotime(explode('to', $this->date_range)[ 0 ]);
$this->date_to = strtotime(explode('to', $this->date_range)[ 1 ]);
-
+
$query->andFilterWhere(
[
'>=',
diff --git a/models/TaxGroup.php b/models/TaxGroup.php
index 2bc665f..1642ed4 100755
--- a/models/TaxGroup.php
+++ b/models/TaxGroup.php
@@ -117,8 +117,8 @@
'is_filter' => 'Use in filter',
'sort' => 'Sort',
'display' => 'Display',
- 'is_menu' => 'Отображать в меню',
- 'level' => 'уровень',
+ 'is_menu' => 'Отображать в характеристиках',
+ 'level' => 'уровень',
'ppsition' => 'Позиция',
];
}
diff --git a/views/order/_form.php b/views/order/_form.php
index 488b9e7..52dc876 100755
--- a/views/order/_form.php
+++ b/views/order/_form.php
@@ -4,10 +4,12 @@
use artweb\artbox\ecommerce\models\Order;
use artweb\artbox\ecommerce\models\OrderPayment;
use artweb\artbox\ecommerce\models\OrderProduct;
+ use backend\models\SmsTemplate;
use kartik\grid\GridView;
use kartik\widgets\DatePicker;
use kartik\widgets\Select2;
use kartik\widgets\SwitchInput;
+ use yii\bootstrap\Dropdown;
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
@@ -52,7 +54,17 @@ $('#order-phone, #order-phone2').mask('+38(000)000-00-00', {
JS;
$this->registerJs($js, View::POS_READY);
-
+
+ $js = <<< JS
+$(document).on('change', '#sms-template-selector', function(event) {
+ var text = $('#select2-sms-template-selector-container').attr('title');
+ var val = $('option:contains(' + text + ')')
+ console.log(text);
+ console.log(val);
+});
+JS;
+
+ $this->registerJs($js, View::POS_READY);
?>
@@ -65,9 +77,14 @@ JS;
) ?>
= Html::a(
\Yii::t('app', 'Печать'),
- '#',
+ yii\helpers\Url::to(
+ [
+ 'order/print',
+ 'order_id' => $model->id,
+ ]
+ ),
[
- 'class' => 'btn btn-info',
+ 'class' => $model->isNewRecord ? 'btn btn-info disabled' : 'btn btn-info',
'target' => '_blank',
]
) ?>
@@ -206,20 +223,26 @@ JS;
'layout' => '{items}{pager}',
'columns' => [
'id',
- 'product_name',
'sku',
+ 'product_name',
+ 'productVariant.product.brand.lang.title',
+ 'productVariant.lang.title',
+ 'price',
[
'class' => 'kartik\grid\EditableColumn',
'attribute' => 'count',
'editableOptions' => [
- 'header' => \Yii::t('app', 'Количество'),
- 'inputType' => kartik\editable\Editable::INPUT_SPIN,
- 'options' => [
+ 'header' => \Yii::t('app', 'Количество'),
+ 'inputType' => kartik\editable\Editable::INPUT_SPIN,
+ 'options' => [
'pluginOptions' => [
'min' => 0,
'max' => 5000,
],
],
+ 'pluginEvents' => [
+ 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }',
+ ],
],
'format' => [
'decimal',
@@ -227,6 +250,7 @@ JS;
],
'pageSummary' => false,
],
+ 'sum_cost',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{delete}',
@@ -316,3 +340,42 @@ JS;
+
+
+
+
+
+
= Html::a('Add order', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
- + $searchModel, - 'attribute' => 'label', - 'data' => Label::find() - ->joinWith('lang') - ->select( - [ - 'CONCAT(order_label.label,order_label_lang.title) AS name', - 'id', - ] - ) - ->indexBy('id') - ->asArray() - ->column(), - 'options' => [ 'placeholder' => 'Select a state ...' ], - 'pluginOptions' => [ - 'allowClear' => true, - 'multiple' => true, - ], - ] - ); + echo $searchForm->field($searchModel, 'label') + ->widget( + Select2::className(), + [ + 'data' => Label::find() + ->joinWith('lang') + ->select( + [ + 'CONCAT(order_label.label,order_label_lang.title) AS name', + 'id', + ] + ) + ->indexBy('id') + ->asArray() + ->column(), + 'options' => [ 'placeholder' => 'Select a state ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'multiple' => true, + ], + ] + ); ?>'deadline', - 'content' => function($model) { - if ($model->deadline == ''){ + 'content' => function($model) { + if ($model->deadline == '') { return ''; } else { return \Yii::$app->formatter->asDate($model->deadline); } - } + }, ], 'name', 'total', @@ -165,6 +233,7 @@ JS; 'adress', [ 'attribute' => 'label', + 'filter' => false, 'value' => function($model) { /** * @var Order $modl @@ -199,3 +268,4 @@ JS; + -- libgit2 0.21.4