Commit 65eb3e514fa44fef5295b0aed913936e1a678e57
1 parent
41068668
29.06.16
Showing
3 changed files
with
14 additions
and
4 deletions
Show diff stats
common/modules/product/controllers/VariantController.php
| ... | ... | @@ -149,13 +149,12 @@ class VariantController extends Controller |
| 149 | 149 | |
| 150 | 150 | |
| 151 | 151 | $ProductStocks = Yii::$app->request->post('ProductStock'); |
| 152 | - $Stocks = Yii::$app->request->post('Stock'); | |
| 153 | 152 | |
| 154 | 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 | 155 | if(!$stock instanceof Stock){ |
| 157 | 156 | $stock = new Stock(); |
| 158 | - $stock->name = $Stocks[$index]['name']; | |
| 157 | + $stock->name = $ProductStock['name']; | |
| 159 | 158 | $stock->save(); |
| 160 | 159 | } |
| 161 | 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 | 33 | { |
| 34 | 34 | return [ |
| 35 | 35 | [['product_id', 'stock_id', 'quantity', 'product_variant_id'], 'integer'], |
| 36 | + [['name'],'required'], | |
| 36 | 37 | [['product_id'], 'exist', 'skipOnError' => true, 'targetClass' => Product::className(), 'targetAttribute' => ['product_id' => 'product_id']], |
| 37 | 38 | [['product_variant_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductVariant::className(), 'targetAttribute' => ['product_variant_id' => 'product_variant_id']], |
| 38 | 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 | 50 | 'stock_id' => 'Stock ID', |
| 50 | 51 | 'quantity' => 'Количество', |
| 51 | 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 | 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 | 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 | 108 | <?= $form->field($stock, "[{$i}]quantity")->textInput(['maxlength' => true]) ?> |
| 109 | 109 | </div> |
| 110 | 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 | 112 | </div> |
| 113 | 113 | <div class="col-sm-2" style="margin-top: 30px"> |
| 114 | 114 | <button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button> | ... | ... |