예제 #1
0
 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.location::lang.locations.enable_success'));
     } else {
         Flash::success(Lang::get('rainlab.location::lang.locations.disable_success'));
     }
     return Backend::redirect('rainlab/location/locations');
 }
예제 #2
0
 public function onUnpinLocations()
 {
     $pin = post('pin', false);
     if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) {
         foreach ($checkedIds as $objectId) {
             if (!($object = Country::find($objectId))) {
                 continue;
             }
             $object->is_pinned = $pin;
             $object->save();
         }
     }
     if ($pin) {
         Flash::success(Lang::get('rainlab.location::lang.locations.pin_success'));
     } else {
         Flash::success(Lang::get('rainlab.location::lang.locations.unpin_success'));
     }
     return Backend::redirect('rainlab/location/locations');
 }
예제 #3
0
파일: Tax.php 프로젝트: dogiedog/pay-plugin
 /**
  * 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;
 }