Example #1
0
 /**
  * Return an array where the keys are the service names and the values are the prices
  */
 public function getAllRates($toZip, $toCountryCode, $weight)
 {
     $rates = array();
     $method = new Cart66ShippingMethod();
     $upsServices = $method->getServicesForCarrier('ups');
     /*
     $shippingMethods = Cart66Common::getTableName('shipping_methods');
     $sql = "SELECT name, code from $shippingMethods where carrier = 'ups'";'
     $results = $wpdb->get_results($sql);
     */
     foreach ($upsServices as $service => $code) {
         $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, $code, $weight);
         if ($rate !== FALSE) {
             $rates[$service] = number_format((double) $rate, 2, '.', '');
         }
         Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: {$rate}");
     }
     return $rates;
 }
Example #2
0
        		<th><?php 
        _e('Shipping cost', 'cart66');
        ?>
</th>
        		<th><?php 
        _e('Actions', 'cart66');
        ?>
</th>
        	</tr>
        </thead>
        <tbody>
          <?php 
        foreach ($rules as $rule) {
            ?>
            <?php 
            $method = new Cart66ShippingMethod();
            $method->load($rule->shipping_method_id);
            ?>
           <tr>
             <td><?php 
            echo Cart66Common::currency($rule->min_amount);
            ?>
</td>
             <td><?php 
            echo $method->name ? $method->name : "<span style='color:red;'>Please select a method</span>";
            ?>
</td>
             <td><?php 
            echo Cart66Common::currency($rule->shipping_cost);
            ?>
</td>
 public static function saveSettings()
 {
     $error = '';
     foreach ($_REQUEST as $key => $value) {
         if ($key[0] != '_' && $key != 'action' && $key != 'submit' && $key) {
             if (is_array($value) && $key != 'admin_page_roles') {
                 $value = array_filter($value, 'strlen');
                 if (empty($value)) {
                     $value = '';
                 } else {
                     $value = implode('~', $value);
                 }
             }
             if ($key == 'status_options') {
                 $value = str_replace('&', '', Cart66Common::deepTagClean($value));
             }
             if ($key == 'home_country') {
                 $hc = Cart66Setting::getValue('home_country');
                 if ($hc != $value) {
                     $method = new Cart66ShippingMethod();
                     $method->clearAllLiveRates();
                 }
             } elseif ($key == 'countries') {
                 if (strpos($value, '~') === false) {
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] country list value: {$value}");
                     $value = '';
                 }
                 if (empty($value) && !empty($_REQUEST['international_sales'])) {
                     $error = "Please select at least one country to ship to.";
                 }
             } elseif ($key == 'enable_logging' && $value == '1') {
                 try {
                     Cart66Log::createLogFile();
                 } catch (Cart66Exception $e) {
                     $error = '<span>' . $e->getMessage() . '</span>';
                     Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Caught Cart66 exception: " . $e->getMessage());
                 }
             } elseif ($key == 'constantcontact_list_ids') {
             } elseif ($key == 'admin_page_roles') {
                 $value = serialize($value);
                 Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Saving Admin Page Roles: " . print_r($value, true));
             } elseif ($key == 'currency_decimals' && $value == 0) {
                 $value = 'no_decimal';
             }
             Cart66Setting::setValue($key, trim(stripslashes($value)));
             if (CART66_PRO && $key == 'order_number') {
                 $versionInfo = get_transient('_cart66_version_request');
                 if (!$versionInfo) {
                     $versionInfo = Cart66ProCommon::getVersionInfo();
                     set_transient('_cart66_version_request', $versionInfo, 43200);
                 }
                 if (!$versionInfo) {
                     Cart66Setting::setValue('order_number', '');
                     $error = '<span>' . __('Invalid Order Number', 'cart66') . '</span>';
                 }
             }
         }
     }
     if ($error) {
         $result[0] = 'Cart66Modal alert-message alert-error';
         $result[1] = "<strong>" . __("Warning", "cart66") . "</strong><br/>{$error}";
     } else {
         $result[0] = 'Cart66Modal alert-message success';
         $result[1] = '<strong>Success</strong><br/>' . $_REQUEST['_success'] . '<br>';
     }
     $out = json_encode($result);
     echo $out;
     die;
 }
Example #4
0
 /**
  * Return an array where the keys are the service names and the values are the prices
  */
 public function getAllRates($toZip, $toCountryCode, $weight)
 {
     $rates = array();
     $method = new Cart66ShippingMethod();
     if ($toCountryCode == 'CA') {
         $capostServices = $method->getServicesForCarrier('capost');
         $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
         if ($rate !== false) {
             foreach ($capostServices as $service => $code) {
                 if (is_array($rate)) {
                     foreach ($rate as $r) {
                         if ($rate !== FALSE && $r["name"] == $code) {
                             $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                         }
                         //Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: $toZip Service: $service $code) Rate: " . print_r($rate, true));
                     }
                 }
             }
         }
     } else {
         $capostServices = $method->getServicesForCarrier('capost_intl');
         $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
         if ($rate !== false) {
             foreach ($capostServices as $service => $code) {
                 if (is_array($rate)) {
                     foreach ($rate as $r) {
                         $code = str_replace('INTL', 'INT\'L', $code);
                         if ($rate !== FALSE && $r["name"] == $code) {
                             $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                         }
                         //Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: $toZip Service: $service $code) Rate: " . print_r($rate, true));
                     }
                 }
             }
         }
     }
     return $rates;
 }
 protected function _setDefaultShippingMethodId()
 {
     // Set default shipping method to the cheapest method
     $method = new Cart66ShippingMethod();
     $methods = $method->getModels("where code IS NULL or code = ''", 'order by default_rate asc');
     if (is_array($methods) && count($methods) && is_object($methods[0]) && get_class($methods[0]) == 'Cart66ShippingMethod') {
         $this->_shippingMethodId = $methods[0]->id;
         if (Cart66Setting::getValue('require_shipping_validation')) {
             $this->_shippingMethodId = 'select';
         }
     }
 }
Example #6
0
 /**
  * Return an array where the keys are the service names and the values are the prices
  */
 public function getAllRates($toZip, $toCountryCode, $weight)
 {
     $rates = array();
     $method = new Cart66ShippingMethod();
     if ($toCountryCode == 'AU') {
         $aupostServices = $method->getServicesForCarrier('aupost');
         if ($this->getPackageCount() > 1 && Cart66Setting::getValue('aupost_ship_individually')) {
             foreach ($this->getRequestedPackageLineItems($weight) as $line_item) {
                 $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $line_item['weight']);
                 foreach ($aupostServices as $service => $code) {
                     if (is_array($rate)) {
                         foreach ($rate as $r) {
                             if ($rate !== FALSE && $r["name"] == $code) {
                                 $pre_rates[] = array('service' => $service, 'rate' => number_format((double) $r["rate"], 2, '.', ''));
                             }
                         }
                         Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: {$rate}");
                     }
                 }
             }
         } else {
             $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
             foreach ($aupostServices as $service => $code) {
                 if (is_array($rate)) {
                     foreach ($rate as $r) {
                         if ($rate !== FALSE && $r["name"] == $code) {
                             $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                         }
                     }
                     Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: {$rate}");
                 }
             }
         }
     } else {
         $aupostServices = $method->getServicesForCarrier('aupost_intl');
         if ($this->getPackageCount() > 1 && Cart66Setting::getValue('aupost_ship_individually')) {
             foreach ($this->getRequestedPackageLineItems($weight) as $line_item) {
                 $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $line_item['weight']);
                 foreach ($aupostServices as $service => $code) {
                     if (is_array($rate)) {
                         foreach ($rate as $r) {
                             if ($rate !== FALSE && $r["name"] == $code) {
                                 $pre_rates[] = array('service' => $service, 'rate' => number_format((double) $r["rate"], 2, '.', ''));
                             }
                         }
                         Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: {$rate}");
                     }
                 }
             }
         } else {
             $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
             foreach ($aupostServices as $service => $code) {
                 foreach ($rate as $r) {
                     if ($rate !== FALSE && $r["name"] == $code) {
                         $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                     }
                 }
                 Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: {$rate}");
             }
         }
     }
     if (isset($pre_rates)) {
         $rates = array();
         foreach ($pre_rates as $pr) {
             if (array_key_exists($pr['service'], $rates)) {
                 $rates[$pr['service']] = number_format((double) $pr['rate'] + $rates[$pr['service']], 2, '.', '');
             } else {
                 $rates[$pr['service']] = number_format((double) $pr['rate'], 2, '.', '');
             }
         }
     }
     return $rates;
 }
Example #7
0
 /**
  * Return an array where the keys are the service names and the values are the prices
  */
 public function getAllRates($toZip, $toCountryCode, $weight)
 {
     $rates = array();
     $method = new Cart66ShippingMethod();
     if ($toCountryCode == 'US' || $toCountryCode == 'CA') {
         $fedexServices = $method->getServicesForCarrier('fedex');
         $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
         if ($rate !== false) {
             foreach ($fedexServices as $service => $code) {
                 foreach ($rate as $r) {
                     if ($r["name"] == $code) {
                         $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                     }
                 }
             }
             Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: " . print_r($rates, true));
         }
         $fedexServices = $method->getServicesForCarrier('fedex_intl');
         $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
         if ($rate !== false) {
             foreach ($fedexServices as $service => $code) {
                 foreach ($rate as $r) {
                     if ($r["name"] == $code) {
                         $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                     }
                 }
             }
             Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: " . print_r($rates, true));
         }
     } else {
         $fedexServices = $method->getServicesForCarrier('fedex_intl');
         $rate = $this->getRate($this->fromZip, $toZip, $toCountryCode, null, $weight);
         if ($rate !== false) {
             foreach ($fedexServices as $service => $code) {
                 foreach ($rate as $r) {
                     if ($r["name"] == $code) {
                         $rates[$service] = number_format((double) $r["rate"], 2, '.', '');
                     }
                 }
             }
             Cart66Common::log("LIVE RATE REMOTE RESULT ==> ZIP: {$toZip} Service: {$service} {$code}) Rate: " . print_r($rates, true));
         }
     }
     return $rates;
 }