]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-282 Нужно сделать интерфейс настройки магазина
authormarina <m.zozirova@gmail.com>
Tue, 28 Jan 2025 07:56:09 +0000 (10:56 +0300)
committermarina <m.zozirova@gmail.com>
Tue, 28 Jan 2025 07:56:09 +0000 (10:56 +0300)
erp24/records/CityStoreParams.php

index 25502245551071440a7b7260a3dca67448fca025..adc9150f173fc07a49aaa5163f9461917f942207 100644 (file)
@@ -99,60 +99,69 @@ class CityStoreParams extends ActiveRecord
 
     public function afterSave($insert, $changedAttributes)
     {
-        if (isset($changedAttributes->address_region)) {
-            CityStore::update(['region' => $changedAttributes->address_region], ['id' => $changedAttributes->store_id]);
-        }
-
-        if (isset($changedAttributes->address_city)) {
-            CityStore::update(['city' => $changedAttributes->address_city], ['id' => $changedAttributes->store_id]);
-        }
+        $fields = [
+            'address_region' => 'region',
+            'address_city' => 'city',
+            'address_district' => 'district',
+            'store_type' => 'type'
+        ];
 
-        if (isset($changedAttributes->address_district)) {
-            CityStore::update(['district' => $changedAttributes->address_district], ['id' => $changedAttributes->store_id]);
-        }
+        foreach ($fields as $attribute => $field) {
+            $value = $insert ? $this->$attribute : ($changedAttributes[$attribute] ?? null);
 
-        if (isset($changedAttributes->address_type)) {
-            CityStore::update(['type' => $changedAttributes->address_type], ['id' => $changedAttributes->store_id]);
+            if (!empty($value)) {
+                CityStore::updateAll([$field => $value], ['id' => $this->store_id]);
+            }
         }
     }
 
-    public function getStore() {
+    public function getStore()
+    {
         return $this->hasOne(CityStore::class, ['id' => 'store_id']);
     }
 
-    public function getUpdatedBy() {
+    public function getUpdatedBy()
+    {
         return $this->hasOne(Admin::class, ['id' => 'updated_by']);
     }
 
-    public function getCreatedBy() {
+    public function getCreatedBy()
+    {
         return $this->hasOne(Admin::class, ['id' => 'created_by']);
     }
 
-    public function getTerritorialManager() {
+    public function getTerritorialManager()
+    {
         return $this->hasOne(Admin::class, ['id' => 'territorial_manager']);
     }
 
-    public function getBushChefFlorist() {
+    public function getBushChefFlorist()
+    {
         return $this->hasOne(Admin::class, ['id' => 'bush_chef_florist']);
     }
 
-    public function getMatrixType() {
+    public function getMatrixType()
+    {
         return $this->hasOne(MatrixType::class, ['id' => 'matrix_type']);
     }
 
-    public function getStoreType() {
+    public function getStoreType()
+    {
         return $this->hasOne(StoreType::class, ['id' => 'store_type']);
     }
 
-    public function getAddressRegion() {
+    public function getAddressRegion()
+    {
         return $this->hasOne(StoreCityList::class, ['id' => 'address_region']);
     }
 
-    public function getAddressDistrict() {
+    public function getAddressDistrict()
+    {
         return $this->hasOne(StoreCityList::class, ['id' => 'address_district']);
     }
 
-    public function getAddressCity() {
+    public function getAddressCity()
+    {
         return $this->hasOne(StoreCityList::class, ['id' => 'address_city']);
     }
 }