diff --git a/common/modules/product/controllers/VariantController.php b/common/modules/product/controllers/VariantController.php index 92bd8a5..c855a83 100755 --- a/common/modules/product/controllers/VariantController.php +++ b/common/modules/product/controllers/VariantController.php @@ -149,13 +149,12 @@ class VariantController extends Controller $ProductStocks = Yii::$app->request->post('ProductStock'); - $Stocks = Yii::$app->request->post('Stock'); foreach($ProductStocks as $index => $ProductStock){ - $stock = Stock::find()->where(['name'=>$Stocks[$index]['name']])->one(); + $stock = Stock::find()->where(['name'=>$ProductStock['name']])->one(); if(!$stock instanceof Stock){ $stock = new Stock(); - $stock->name = $Stocks[$index]['name']; + $stock->name = $ProductStock['name']; $stock->save(); } $psModel = ProductStock::find()->where(['product_variant_id'=>$model->product_variant_id, 'stock_id' =>$stock->stock_id ]); diff --git a/common/modules/product/models/ProductStock.php b/common/modules/product/models/ProductStock.php index e2e15b2..ead58bc 100755 --- a/common/modules/product/models/ProductStock.php +++ b/common/modules/product/models/ProductStock.php @@ -33,6 +33,7 @@ class ProductStock extends \yii\db\ActiveRecord { return [ [['product_id', 'stock_id', 'quantity', 'product_variant_id'], 'integer'], + [['name'],'required'], [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], [['product_variant_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['product_variant_id' => 'product_variant_id']], [['stock_id'], 'exist', 'skipOnError' => true, 'targetClass' => Stock::className(), 'targetAttribute' => ['stock_id' => 'stock_id']], @@ -49,6 +50,7 @@ class ProductStock extends \yii\db\ActiveRecord 'stock_id' => 'Stock ID', 'quantity' => 'Количество', 'product_variant_id' => 'Product Variant ID', + 'name' => "Название" ]; } @@ -68,6 +70,15 @@ class ProductStock extends \yii\db\ActiveRecord return $this->hasOne(ProductVariant::className(), ['product_variant_id' => 'product_variant_id']); } + + public function getName(){ + return (!empty($this->stock))? $this->stock->name : ''; + } + + public function setName($value){ + $this->name = $value; + } + /** * @return \yii\db\ActiveQuery */ diff --git a/common/modules/product/views/variant/_form.php b/common/modules/product/views/variant/_form.php index bd74bf5..ff2d070 100755 --- a/common/modules/product/views/variant/_form.php +++ b/common/modules/product/views/variant/_form.php @@ -108,7 +108,7 @@ $this->registerJs($js, View::POS_END); = $form->field($stock, "[{$i}]quantity")->textInput(['maxlength' => true]) ?>