function testPackageExpansion() { $lib = new ShippingLib(); $lib->addProvider($this); $lib->getRates(array('zip' => '12345678900X'), array('zip' => 'A1B 2C3'), array(array('weight' => 5, 'count' => 2), array('weight' => 10))); $this->assertEquals(array(array('weight' => 5), array('weight' => 5), array('weight' => 10)), $this->packages); }
function prefs_shipping_list() { require_once 'lib/shipping/shippinglib.php'; $all = glob('lib/shipping/custom/*.php'); $custom_providers = array('' => tra('None')); foreach ($all as $file) { if ($file === "lib/shipping/custom/index.php") { continue; } $name = basename($file, '.php'); $provider = ShippingLib::getCustomShippingProvider($name); $custom_providers[$name] = $provider->getName(); } return array('shipping_service' => array('name' => tra('Shipping Service'), 'description' => tra('Expose a JSON shipping rate estimation service. Accounts from providers may be required (FedEx, UPS, ...).'), 'type' => 'flag', 'help' => 'Shipping', 'default' => 'n'), 'shipping_fedex_enable' => array('name' => tra('FedEx API'), 'description' => tra('Enable shipping rate calculation through FedEx APIs'), 'type' => 'flag', 'help' => 'Shipping', 'default' => 'n'), 'shipping_fedex_key' => array('name' => tra('FedEx Key'), 'description' => tra('Developer Key'), 'type' => 'text', 'size' => 16, 'filter' => 'alnum', 'default' => ''), 'shipping_fedex_password' => array('name' => tra('FedEx Password'), 'type' => 'text', 'size' => 25, 'filter' => 'rawhtml_unsafe', 'default' => ''), 'shipping_fedex_meter' => array('name' => tra('FedEx Meter Number'), 'type' => 'text', 'size' => 10, 'filter' => 'digits', 'default' => ''), 'shipping_fedex_account' => array('name' => tra('FedEx Account Number'), 'type' => 'text', 'size' => 10, 'filter' => 'digits', 'default' => ''), 'shipping_ups_enable' => array('name' => tra('UPS API'), 'description' => tra('Enable shipping rate calculation using the UPS carrier.'), 'type' => 'flag', 'help' => 'Shipping', 'default' => 'n'), 'shipping_ups_username' => array('name' => tra('UPS Username'), 'description' => tra('UPS credentials'), 'type' => 'text', 'size' => 15, 'default' => ''), 'shipping_ups_password' => array('name' => tra('UPS Password'), 'description' => tra('UPS credentials'), 'type' => 'text', 'size' => 25, 'default' => ''), 'shipping_ups_license' => array('name' => tra('UPS Access Key'), 'type' => 'text', 'size' => 25, 'default' => ''), 'shipping_custom_provider' => array('name' => tra('Custom Shipping Provider'), 'type' => 'list', 'size' => 25, 'default' => '', 'options' => $custom_providers, 'dependencies' => array('shipping_service'))); }
} } return $out; } static function getCustomShippingProvider($name) { $file = dirname(__FILE__) . '/custom/' . $name . '.php'; $className = 'CustomShippingProvider_' . ucfirst($name); if (is_readable($file)) { require_once $file; if (class_exists($className) && method_exists($className, 'getName')) { $provider = new $className(); return $provider; } } TikiLib::lib('errorreport')->report(tr('Problem reading custom shipping provider "%0"', $name)); } } global $shippinglib, $prefs; $shippinglib = new ShippingLib(); if (!empty($prefs['shipping_fedex_enable']) && $prefs['shipping_fedex_enable'] === 'y') { require_once 'lib/shipping/provider_fedex.php'; $shippinglib->addProvider(new ShippingProvider_FedEx(array('key' => $prefs['shipping_fedex_key'], 'password' => $prefs['shipping_fedex_password'], 'meter' => $prefs['shipping_fedex_meter']))); } if (!empty($prefs['shipping_ups_enable']) && $prefs['shipping_ups_enable'] === 'y') { require_once 'lib/shipping/provider_ups.php'; $shippinglib->addProvider(new ShippingProvider_Ups(array('username' => $prefs['shipping_ups_username'], 'password' => $prefs['shipping_ups_password'], 'license' => $prefs['shipping_ups_license']))); } if (!empty($prefs['shipping_custom_provider'])) { $shippinglib->addProvider(ShippingLib::getCustomShippingProvider($prefs['shipping_custom_provider'])); }