/** * 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; }
/** * 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; }
public function getLiveRates() { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Call to getLiveRates"); if (!CART66_PRO) { return false; } $weight = Cart66Session::get('Cart66Cart')->getCartWeight(); $zip = Cart66Session::get('cart66_shipping_zip') ? Cart66Session::get('cart66_shipping_zip') : false; $countryCode = Cart66Session::get('cart66_shipping_country_code') ? Cart66Session::get('cart66_shipping_country_code') : Cart66Common::getHomeCountryCode(); // Make sure _liveRates is a Cart66LiveRates object if (get_class($this->_liveRates) != 'Cart66LiveRates') { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] WARNING: \$this->_liveRates is not a Cart66LiveRates object so we're making it one now."); $this->_liveRates = new Cart66LiveRates(); } // Return the live rates from the session if the zip, country code, and cart weight are the same if (Cart66Session::get('Cart66LiveRates') && get_class($this->_liveRates) == 'Cart66LiveRates') { $cartWeight = $this->getCartWeight(); $this->_liveRates = Cart66Session::get('Cart66LiveRates'); $liveWeight = $this->_liveRates->weight; $liveZip = $this->_liveRates->toZip; $liveCountry = $this->_liveRates->getToCountryCode(); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] \n {$liveWeight} == {$weight}\n {$liveZip} == {$zip}\n {$liveCountry} == {$countryCode}\n "); if ($this->_liveRates->weight == $weight && $this->_liveRates->toZip == $zip && $this->_liveRates->getToCountryCode() == $countryCode) { Cart66Common::log("Using Live Rates from the session: " . $this->_liveRates->getSelected()->getService()); return Cart66Session::get('Cart66LiveRates'); } } if ($this->getCartWeight() > 0 && Cart66Session::get('cart66_shipping_zip') && Cart66Session::get('cart66_shipping_country_code')) { Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Clearing current live shipping rates and recalculating new rates."); $this->_liveRates->clearRates(); $this->_liveRates->weight = $weight; $this->_liveRates->toZip = $zip; $method = new Cart66ShippingMethod(); // Get USPS shipping rates if (Cart66Setting::getValue('usps_username')) { $this->_liveRates->setToCountryCode($countryCode); $rates = $countryCode == 'US' ? $this->getUspsRates() : $this->getUspsIntlRates($countryCode); $uspsServices = $method->getServicesForCarrier('usps'); foreach ($rates as $name => $price) { $price = number_format($price, 2, '.', ''); if (in_array($name, $uspsServices)) { $this->_liveRates->addRate('USPS', 'USPS ' . $name, $price); } } } // Get UPS Live Shipping Rates if (Cart66Setting::getValue('ups_apikey')) { $rates = $this->getUpsRates(); foreach ($rates as $name => $price) { $this->_liveRates->addRate('UPS', $name, $price); } } // Get FedEx Live Shipping Rates if (Cart66Setting::getValue('fedex_developer_key')) { $this->_liveRates->setToCountryCode($countryCode); $rates = $this->getFedexRates(); foreach ($rates as $name => $price) { $this->_liveRates->addRate('FedEx', $name, $price); } } // Get Australia Post Live Shipping Rates if (Cart66Setting::getValue('aupost_developer_key')) { $this->_liveRates->setToCountryCode($countryCode); $rates = $this->getAuPostRates(); foreach ($rates as $name => $price) { $this->_liveRates->addRate('Australia Post', $name, $price); } } // Get Canada Post Live Shipping Rates if (Cart66Setting::getValue('capost_merchant_id') || Cart66Setting::getValue('capost_username')) { $this->_liveRates->setToCountryCode($countryCode); $rates = $this->getCaPostRates(); foreach ($rates as $name => $price) { $this->_liveRates->addRate('Canada Post', $name, $price); } } if (Cart66Setting::getValue('shipping_local_pickup')) { $this->_liveRates->addRate('Local Pickup', Cart66Setting::getValue('shipping_local_pickup_label'), number_format(Cart66Setting::getValue('shipping_local_pickup_amount'), 2)); } } else { $this->_liveRates->clearRates(); $this->_liveRates->weight = 0; $this->_liveRates->toZip = $zip; $this->_liveRates->setToCountryCode($countryCode); $this->_liveRates->addRate('SYSTEM', 'Free Shipping', '0.00'); } Cart66Session::set('Cart66LiveRates', $this->_liveRates); Cart66Common::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Dump live rates: " . print_r($this->_liveRates, true)); return $this->_liveRates; }
/** * 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; }
/** * 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; }