Commit 65eb3e514fa44fef5295b0aed913936e1a678e57

Authored by Administrator
1 parent 41068668

29.06.16

common/modules/product/controllers/VariantController.php
@@ -149,13 +149,12 @@ class VariantController extends Controller @@ -149,13 +149,12 @@ class VariantController extends Controller
149 149
150 150
151 $ProductStocks = Yii::$app->request->post('ProductStock'); 151 $ProductStocks = Yii::$app->request->post('ProductStock');
152 - $Stocks = Yii::$app->request->post('Stock');  
153 152
154 foreach($ProductStocks as $index => $ProductStock){ 153 foreach($ProductStocks as $index => $ProductStock){
155 - $stock = Stock::find()->where(['name'=>$Stocks[$index]['name']])->one(); 154 + $stock = Stock::find()->where(['name'=>$ProductStock['name']])->one();
156 if(!$stock instanceof Stock){ 155 if(!$stock instanceof Stock){
157 $stock = new Stock(); 156 $stock = new Stock();
158 - $stock->name = $Stocks[$index]['name']; 157 + $stock->name = $ProductStock['name'];
159 $stock->save(); 158 $stock->save();
160 } 159 }
161 $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]); 160 $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]);
common/modules/product/models/ProductStock.php
@@ -33,6 +33,7 @@ class ProductStock extends \yii\db\ActiveRecord @@ -33,6 +33,7 @@ class ProductStock extends \yii\db\ActiveRecord
33 { 33 {
34 return [ 34 return [
35 [['product_id', 'stock_id', 'quantity', 'product_variant_id'], 'integer'], 35 [['product_id', 'stock_id', 'quantity', 'product_variant_id'], 'integer'],
  36 + [['name'],'required'],
36 [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], 37 [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']],
37 [['product_variant_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['product_variant_id' => 'product_variant_id']], 38 [['product_variant_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['product_variant_id' => 'product_variant_id']],
38 [['stock_id'], 'exist', 'skipOnError' => true, 'targetClass' => Stock::className(), 'targetAttribute' => ['stock_id' => 'stock_id']], 39 [['stock_id'], 'exist', 'skipOnError' => true, 'targetClass' => Stock::className(), 'targetAttribute' => ['stock_id' => 'stock_id']],
@@ -49,6 +50,7 @@ class ProductStock extends \yii\db\ActiveRecord @@ -49,6 +50,7 @@ class ProductStock extends \yii\db\ActiveRecord
49 'stock_id' => 'Stock ID', 50 'stock_id' => 'Stock ID',
50 'quantity' => 'Количество', 51 'quantity' => 'Количество',
51 'product_variant_id' => 'Product Variant ID', 52 'product_variant_id' => 'Product Variant ID',
  53 + 'name' => "Название"
52 ]; 54 ];
53 } 55 }
54 56
@@ -68,6 +70,15 @@ class ProductStock extends \yii\db\ActiveRecord @@ -68,6 +70,15 @@ class ProductStock extends \yii\db\ActiveRecord
68 return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'product_variant_id']); 70 return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'product_variant_id']);
69 } 71 }
70 72
  73 +
  74 + public function getName(){
  75 + return (!empty($this->stock))? $this->stock->name : '';
  76 + }
  77 +
  78 + public function setName($value){
  79 + $this->name = $value;
  80 + }
  81 +
71 /** 82 /**
72 * @return \yii\db\ActiveQuery 83 * @return \yii\db\ActiveQuery
73 */ 84 */
common/modules/product/views/variant/_form.php
@@ -108,7 +108,7 @@ $this->registerJs($js, View::POS_END); @@ -108,7 +108,7 @@ $this->registerJs($js, View::POS_END);
108 <?= $form->field($stock, "[{$i}]quantity")->textInput(['maxlength' => true]) ?> 108 <?= $form->field($stock, "[{$i}]quantity")->textInput(['maxlength' => true]) ?>
109 </div> 109 </div>
110 <div class="col-sm-5"> 110 <div class="col-sm-5">
111 - <?= $form->field($stock->stock, "[{$i}]name")->textInput(['maxlength' => true]) ?> 111 + <?= $form->field($stock, "[{$i}]name")->textInput(['maxlength' => true]) ?>
112 </div> 112 </div>
113 <div class="col-sm-2" style="margin-top: 30px"> 113 <div class="col-sm-2" style="margin-top: 30px">
114 <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button> 114 <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>