Commit 96e1054ceb8bf0cd436a7af55c46eb6ea8acad0b
1 parent
bb3c80f4
stock map
Showing
1 changed file
with
14 additions
and
0 deletions
Show diff stats
models/VariantToShop.php
... | ... | @@ -90,4 +90,18 @@ |
90 | 90 | return $this->hasOne(Variant::className(), [ 'id' => 'variant_id' ]); |
91 | 91 | } |
92 | 92 | |
93 | + public function afterSave($insert, $changedAttributes) | |
94 | + { | |
95 | + parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub | |
96 | + | |
97 | + $variant = $this->variant; | |
98 | + if ($variant->stock - $changedAttributes['count'] >= 0){ | |
99 | + $variant->stock = $variant->stock - $changedAttributes['count'] + $this->count; | |
100 | + }else{ | |
101 | + $variant->stock = $this->count; | |
102 | + } | |
103 | + $variant->save(); | |
104 | + | |
105 | + } | |
106 | + | |
93 | 107 | } | ... | ... |