예제 #1
0
 public function getAllowedTypes($request)
 {
     switch ($this->_config->type) {
         case 'Per Weight':
             $value = $request['weight'];
             break;
         case 'Per Item':
             $value = $request['qty'];
             break;
         case 'Per Price':
         default:
             $value = $request['price'];
             break;
     }
     $select = Axis::table('shippingtable_rate')->select();
     $select->where('value <= ? ', $value)->where('site_id = ? OR site_id = 0', Axis::getSiteId())->where('country_id = ? OR country_id = 0', $request['country']['id'])->where('zip = ? OR zip = "*"', $request['postcode'])->order('site_id DESC')->order('country_id ASC')->order('zone_id ASC')->order('zip ASC')->order('value DESC')->limit(1);
     if (isset($request['zone']['id'])) {
         $select->where('zone_id = ? OR zone_id = 0', $request['zone']['id']);
     } else {
         $select->where('zone_id = 0');
     }
     $row = $select->fetchRow();
     $this->_types = array(array('id' => $this->_code, 'title' => $this->getTitle(), 'price' => $row['price'] + (is_numeric($this->_config->handling) ? $this->_config->handling : 0)));
     return $this->_types;
 }
 /**
  *
  * @param mixed $value
  * @return mixed
  */
 public static function getSaveValue($value)
 {
     if (!is_array($value)) {
         return $value;
     }
     function remove_quotes(&$str)
     {
         $str = str_replace(array('"', "'"), '', $str);
     }
     $filename = Axis::config()->system->path . '/var/export/' . current($value);
     if (@(!($fp = fopen($filename, 'r')))) {
         Axis::message()->addError(Axis::translate('core')->__("Can't open file : %s", $filename));
         return current($value);
     }
     $titles = fgetcsv($fp, 2048, ',', "'");
     array_walk($titles, 'remove_quotes');
     $rowSize = count($titles);
     Axis::table('shippingtable_rate')->delete("site_id = " . $value['siteId']);
     while (!feof($fp)) {
         $data = fgetcsv($fp, 2048, ',', "'");
         if (!is_array($data)) {
             continue;
         }
         $data = array_pad($data, $rowSize, '');
         array_walk($data, 'remove_quotes');
         $data = array_combine($titles, $data);
         Axis::table('shippingtable_rate')->insert(array('site_id' => $value['siteId'], 'country_id' => Axis::single('location/country')->getIdByIsoCode3($data['Country']), 'zone_id' => Axis::single('location/zone')->getIdByCode($data['Region/State']), 'zip' => $data['Zip'], 'value' => $data['Value'], 'price' => $data['Price']));
     }
     return current($value);
 }
 /**
  *
  * @static
  * @param array $value
  * @return mixed
  */
 public static function getSaveValue($value)
 {
     if (!is_array($value)) {
         return $value;
     }
     $filename = Axis::config()->system->path . '/var/export/' . current($value);
     if (@(!($fp = fopen($filename, 'w')))) {
         Axis::message()->addError(Axis::translate('core')->__("Can't write in file: %s", $filename));
         return current($value);
     }
     $titles = explode(',', 'Country,Region/State,Zip,Value,Price');
     fputcsv($fp, $titles, ',', "'");
     foreach (Axis::table('shippingtable_rate')->fetchAll() as $row) {
         fputcsv($fp, array(Axis::single('location/country')->getIsoCode3ById($row->country_id), Axis::single('location/zone')->getCodeById($row->zone_id), $row->zip, $row->value, $row->price), ',', "'");
     }
     return current($value);
 }