public function onDisableLocations() { $enable = post('enable', false); if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $objectId) { if (!($object = Country::find($objectId))) { continue; } $object->is_enabled = $enable; $object->save(); } } if ($enable) { Flash::success(Lang::get('rainlab.user::lang.locations.enable_success')); } else { Flash::success(Lang::get('rainlab.user::lang.locations.disable_success')); } return Redirect::to(Backend::url('rainlab/user/locations')); }
/** * Returns rate information for a given location, optionally ignoring by priority. * @param array $locationInfo * @param array $ignoredPriorities * @return object */ protected function getRate($locationInfo, $ignoredPriorities = []) { $country = Country::find($locationInfo->country_id); if (!$country) { return null; } $state = null; if (strlen($locationInfo->state_id)) { $state = State::find($locationInfo->state_id); } $countryCode = $country->code; $stateCode = $state ? mb_strtoupper($state->code) : '*'; $zipCode = str_replace(' ', '', trim(strtoupper($locationInfo->zip))); if (!strlen($zipCode)) { $zipCode = '*'; } $city = str_replace('-', '', str_replace(' ', '', trim(mb_strtoupper($locationInfo->city)))); if (!strlen($city)) { $city = '*'; } $rate = null; foreach ($this->rates as $row) { $taxPriority = isset($row['priority']) ? $row['priority'] : 1; if (in_array($taxPriority, $ignoredPriorities)) { continue; } if ($row['country'] != $countryCode && $row['country'] != '*') { continue; } if (mb_strtoupper($row['state']) != $stateCode && $row['state'] != '*') { continue; } $rowZip = isset($row['zip']) && strlen($row['zip']) ? str_replace(' ', '', $row['zip']) : '*'; if ($rowZip != $zipCode && $rowZip != '*') { continue; } $rowCity = isset($row['city']) && strlen($row['city']) ? str_replace('-', '', str_replace(' ', '', mb_strtoupper($row['city']))) : '*'; if ($rowCity != $city && $rowCity != '*') { continue; } $compound = isset($row['compound']) ? $row['compound'] : 0; if (preg_match('/^[0-9]+$/', $compound)) { $compound = (int) $compound; } else { $compound = $compound == 'Y' || $compound == 'YES'; } $rateObj = ['rate' => $row['rate'], 'priority' => $taxPriority, 'name' => isset($row['tax_name']) ? $row['tax_name'] : 'TAX', 'compound' => $compound]; $rate = (object) $rateObj; break; } return $rate; }
/** * Updates and save the metadata for a user object */ public function updateMetadata(OctoberUser $user, $wordpressId) { $metadata = $this->db->table('wp_usermeta')->where('user_id', $wordpressId)->get(); // Organize the metadata for mapping to user fields $data = ['phone' => '', 'street_address' => '', 'city' => '', 'state' => '', 'zip' => '', 'first_name' => '', 'last_name' => '', '_badgeos_points' => '', 'email_optin' => false, 'current_member' => false, 'current_member_number' => '']; foreach ($metadata as $mdata) { $data[$mdata->meta_key] = $mdata->meta_value; } $user->phone = $data['phone']; $user->street_addr = $data['street_address']; $user->city = $data['city']; $user->zip = $data['zip']; $user->points = $data['_badgeos_points']; // Ensures that we have a barcode id for the user if (empty($user->barcode_id)) { $user->barcode_id = $user->name; } // Populate state and country objects if (!empty($data['state'])) { $state = State::where('code', strtoupper($data['state']))->first(); if (!$state) { $state = State::where('name', $data['state'])->first(); } if ($state) { $user->state()->associate($state); $user->country()->associate(Country::find($state->country_id)); } } $metadata = new Usermeta(); $metadata->first_name = $data['first_name']; $metadata->last_name = $data['last_name']; $metadata->email_optin = $data['email_optin']; $metadata->current_member = $data['current_member']; $metadata->current_member_number = $data['current_member_number']; try { $user->forceSave(); $user->metadata()->delete(); $user->metadata()->save($metadata); } catch (Exception $e) { var_dump($e); } }