Exemplo n.º 1
0
 /**
  * Remove the old store locations
  * @param array  $location  contains 'province','city' and 'district'
  * @param string $accountId
  */
 private function _removeOldLocation($location, $accountId)
 {
     $locationKeys = ['province', 'city', 'district'];
     foreach ($locationKeys as $key) {
         if (empty($location[$key])) {
             return false;
         }
     }
     $result = true;
     $parentName = null;
     if (!empty($locationKeys)) {
         // remove the old store locations
         foreach (array_reverse($locationKeys) as $key) {
             if (!empty($location[$key])) {
                 $storeLocation = StoreLocation::findOne(['parentName' => $location[$key], 'accountId' => $accountId]);
                 if (empty($storeLocation)) {
                     $result &= StoreLocation::deleteAll(['name' => $location[$key], 'accountId' => $accountId]);
                 }
             }
         }
     }
     return (bool) $result;
 }