Commit 86301a927906a2d7829be20693eb956def65f901

Authored by Administrator
1 parent 19a7a33f

14.06.16

common/modules/product/models/Import.php
@@ -125,6 +125,7 @@ class Import extends Model { @@ -125,6 +125,7 @@ class Import extends Model {
125 // ===== Set stock ==== 125 // ===== Set stock ====
126 if ( $city_name ) { 126 if ( $city_name ) {
127 if ( ($stock = Stock::find()->filterWhere(['name' => trim($city_name)])->one()) === null ) { 127 if ( ($stock = Stock::find()->filterWhere(['name' => trim($city_name)])->one()) === null ) {
  128 +
128 // Create stock 129 // Create stock
129 $stock = new Stock(); 130 $stock = new Stock();
130 $stock->name = trim($city_name); 131 $stock->name = trim($city_name);
@@ -139,8 +140,8 @@ class Import extends Model { @@ -139,8 +140,8 @@ class Import extends Model {
139 $productStock->product_id = $productVariant->product_id; 140 $productStock->product_id = $productVariant->product_id;
140 } 141 }
141 $productStock->quantity = $count; 142 $productStock->quantity = $count;
142 - $productStock->save();  
143 143
  144 + $productStock->save();
144 $productStocks = ProductStock::find()->where(['product_variant_id' => $productVariant->product_variant_id])->andWhere(['<>', 'stock_id', $stock->stock_id])->all(); 145 $productStocks = ProductStock::find()->where(['product_variant_id' => $productVariant->product_variant_id])->andWhere(['<>', 'stock_id', $stock->stock_id])->all();
145 146
146 $quantity = array_sum(ArrayHelper::getColumn($productStocks, 'quantity')) + $count; 147 $quantity = array_sum(ArrayHelper::getColumn($productStocks, 'quantity')) + $count;
common/modules/product/models/ProductStock.php
@@ -79,6 +79,6 @@ class ProductStock extends \yii\db\ActiveRecord @@ -79,6 +79,6 @@ class ProductStock extends \yii\db\ActiveRecord
79 79
80 public static function primaryKey() 80 public static function primaryKey()
81 { 81 {
82 - return ["product_id"]; 82 + return ["stock_id","product_variant_id"];
83 } 83 }
84 } 84 }