/**
  * get all information from all configured ups and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     if (defined('PSI_UPS_NUT_LIST') && is_string(PSI_UPS_NUT_LIST)) {
         if (preg_match(ARRAY_EXP, PSI_UPS_NUT_LIST)) {
             $upses = eval(PSI_UPS_NUT_LIST);
         } else {
             $upses = array(PSI_UPS_NUT_LIST);
         }
         foreach ($upses as $ups) {
             CommonFunctions::executeProgram('upsc', '-l ' . trim($ups), $output, PSI_DEBUG);
             $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
             foreach ($ups_names as $ups_name) {
                 CommonFunctions::executeProgram('upsc', trim($ups_name) . '@' . trim($ups), $temp, PSI_DEBUG);
                 if (!empty($temp)) {
                     $this->_output[trim($ups_name) . '@' . trim($ups)] = $temp;
                 }
             }
         }
     } else {
         //use default if address and port not defined
         CommonFunctions::executeProgram('upsc', '-l', $output, PSI_DEBUG);
         $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
         foreach ($ups_names as $ups_name) {
             CommonFunctions::executeProgram('upsc', trim($ups_name), $temp, PSI_DEBUG);
             if (!empty($temp)) {
                 $this->_output[trim($ups_name)] = $temp;
             }
         }
     }
 }
 /**
  * get all information from all configured ups and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     CommonFunctions::executeProgram('pmset', '-g batt', $temp);
     if (!empty($temp)) {
         $this->_output[] = $temp;
     }
 }
 /**
  * get all information from all configured ups in config.php and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     CommonFunctions::executeProgram('powersoftplus', '-p', $temp);
     if (!empty($temp)) {
         $this->_output[] = $temp;
     }
 }
 /**
  * get all information from all configured ups and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     CommonFunctions::executeProgram('upsc', '-l', $output);
     $ups_names = preg_split("/\n/", $output, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($ups_names as $value) {
         CommonFunctions::executeProgram('upsc', $value, $temp);
         $this->_output[$value] = $temp;
     }
 }
 /**
  * get all information from all configured ups in config.php and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     $upses = preg_split('/,/', PSI_UPS_APCUPSD_LIST, -1, PREG_SPLIT_NO_EMPTY);
     foreach ($upses as $ups) {
         CommonFunctions::executeProgram('apcaccess', 'status ' . trim($ups), $temp);
         if (!empty($temp)) {
             $this->_output[] = $temp;
         }
     }
 }
 /**
  * get all information from all configured ups in config.php and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     if (defined('PSI_UPS_APCUPSD_LIST') && is_string(PSI_UPS_APCUPSD_LIST)) {
         if (preg_match(ARRAY_EXP, PSI_UPS_APCUPSD_LIST)) {
             $upses = eval(PSI_UPS_APCUPSD_LIST);
         } else {
             $upses = array(PSI_UPS_APCUPSD_LIST);
         }
         foreach ($upses as $ups) {
             CommonFunctions::executeProgram('apcaccess', 'status ' . trim($ups), $temp);
             if (!empty($temp)) {
                 $this->_output[] = $temp;
             }
         }
     }
 }
Exemple #7
0
 public function testship()
 {
     print_r(get_declared_classes());
     try {
         //set shipper
         $fromAddress = new \SimpleUPS\InstructionalAddress();
         $fromAddress->setAddressee('Mark Stevens');
         $fromAddress->setStreet('10571 Pico Blvd');
         $fromAddress->setStateProvinceCode('CA');
         $fromAddress->setCity('Los Angeles');
         $fromAddress->setPostalCode(90064);
         $fromAddress->setCountryCode('US');
         $shipper = new \SimpleUPS\Shipper();
         $shipper->setNumber('CCE85AD5154DDC46');
         $shipper->setAddress($fromAddress);
         \SimpleUPS\UPS::setShipper($shipper);
         //define a shipping destination
         $shippingDestination = new \SimpleUPS\InstructionalAddress();
         $shippingDestination->setStreet('220 Bowery');
         $shippingDestination->setStateProvinceCode('NY');
         $shippingDestination->setCity('New York');
         $shippingDestination->setPostalCode(10453);
         $shippingDestination->setCountryCode('US');
         //define a package, we could specify the dimensions of the box if we wanted a more accurate estimate
         $package = new \SimpleUPS\Rates\Package();
         $package->setWeight('7');
         $shipment = new \SimpleUPS\Rates\Shipment();
         $shipment->setDestination($shippingDestination);
         $shipment->addPackage($package);
         echo 'Rates: ';
         echo '<ul>';
         foreach (UPS::getRates($shipment) as $shippingMethod) {
             echo '<li>' . $shippingMethod->getService()->getDescription() . ' ($' . $shippingMethod->getTotalCharges() . ')</li>';
         }
         echo '</ul>';
     } catch (Exception $e) {
         //doh, something went wrong
         echo 'Failed: (' . get_class($e) . ') ' . $e->getMessage() . '<br/>';
         echo 'Stack trace:<br/><pre>' . $e->getTraceAsString() . '</pre>';
     }
 }
Exemple #8
0
 public function getUPSRates($id_zone, $is_cart, $cart, $product_weight, $dest_zip, $dest_state, $dest_country, $currency, $product, $id_product_attribute, $qty)
 {
     $rates = array();
     if (file_exists(dirname(__FILE__) . '/../../ups/classes/RateAvailableServices.php')) {
         include_once dirname(__FILE__) . '/../../ups/ups.php';
         include_once dirname(__FILE__) . '/../../ups/classes/RateAvailableServices.php';
         $ups = new UPS();
         if ($ups->active) {
             // Get handling cost (once)
             $handling = Configuration::get('PS_SHIPPING_HANDLING');
             $carriers = $ups->getCarriers($id_zone, $cart, $is_cart, $product);
             foreach ($carriers as $carrier) {
                 //check if UPS module is new or old
                 if (get_parent_class($ups) == 'PrestoChangeoCarrierModule') {
                     $UPSRate = new UPSRate();
                     $amount = $UPSRate->getRate($carrier['id_carrier'], $carrier['id_zone'], $is_cart != '' ? $cart->getTotalWeight() : max($product_weight, 0.001), $dest_zip, $dest_state, $dest_country, "", $is_cart != '' ? 0 : $product->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty), $is_cart != '' ? 0 : $product->id, $is_cart != '' ? 0 : $id_product_attribute, $qty);
                 } else {
                     $amount = getUPSRate($carrier['id_carrier'], $carrier['id_zone'], $is_cart != '' ? $cart->getTotalWeight() : max($product_weight, 0.001), $dest_zip, $dest_state, $dest_country, $is_cart != '' ? 0 : $product->getPrice(true, $id_product_attribute, 6, NULL, false, true, $qty), $is_cart != '' ? 0 : $product->id, $is_cart != '' ? 0 : $id_product_attribute, $qty);
                 }
                 // Add product spercific cost + handling fee
                 if ($amount > 0) {
                     $amount += $this->getExtraShippingCost($carrier, $handling, $is_cart != '' ? $cart->getProducts() : array(), $product, $qty);
                 }
                 // Apply shipping tax if needed
                 if (!Tax::excludeTaxeOption()) {
                     $carrierTax = Tax::getCarrierTaxRate($carrier['id_carrier']);
                 }
                 if (isset($carrierTax) && $amount !== false) {
                     $amount *= 1 + $carrierTax / 100;
                 }
                 $amount = $amount === false ? -1 : Tools::convertPrice($amount, $currency);
                 if ($amount > 0) {
                     $rates[$carrier['name']] = array(Tools::displayPrice($amount, $currency, false), $carrier['id_carrier']);
                 } elseif ($amount !== false && $amount == 0) {
                     $rates[$carrier['name']] = array($ups->l('Free!'), $carrier['id_carrier']);
                 }
             }
         }
     }
     return $rates;
 }
Exemple #9
0
 /**
  * Prints debug output
  * @see   \SimpleUPS\UPS::getDebug()
  * @see   \SimpleUPS\UPS::setDebug()
  * @api
  * @since 1.0
  */
 public static function getDebugOutput()
 {
     if (UPS::getDebug()) {
         require_once 'debug_output.inc';
     } else {
         throw new \Exception('Debug mode must be enabled');
     }
 }
 /**
  * get all information from all configured ups in phpsysinfo.ini and store output in internal array
  */
 public function __construct()
 {
     parent::__construct();
     switch (strtolower(PSI_UPS_SNMPUPS_ACCESS)) {
         case 'command':
             if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
                 if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
                     $upss = eval(PSI_UPS_SNMPUPS_LIST);
                 } else {
                     $upss = array(PSI_UPS_SNMPUPS_LIST);
                 }
                 foreach ($upss as $ups) {
                     CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.1", $buffer, PSI_DEBUG);
                     if (strlen($buffer) > 0) {
                         $this->_output[$ups] = $buffer;
                         $buffer = "";
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.2", $buffer, PSI_DEBUG);
                         if (strlen($buffer) > 0) {
                             $this->_output[$ups] .= "\n" . $buffer;
                         }
                         $buffer = "";
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.3", $buffer, PSI_DEBUG);
                         if (strlen($buffer) > 0) {
                             $this->_output[$ups] .= "\n" . $buffer;
                         }
                         $buffer = "";
                         CommonFunctions::executeProgram("snmpwalk", "-Ona -c public -v 1 -r 1 " . $ups . " .1.3.6.1.4.1.318.1.1.1.4", $buffer, PSI_DEBUG);
                         if (strlen($buffer) > 0) {
                             $this->_output[$ups] .= "\n" . $buffer;
                         }
                     }
                 }
             }
             break;
         case 'php-snmp':
             if (!extension_loaded("snmp")) {
                 $this->error->addError("Requirements error", "SNMPups plugin requires the snmp extension to php in order to work properly");
                 break;
             }
             snmp_set_valueretrieval(SNMP_VALUE_LIBRARY);
             snmp_set_oid_output_format(SNMP_OID_OUTPUT_NUMERIC);
             if (defined('PSI_UPS_SNMPUPS_LIST') && is_string(PSI_UPS_SNMPUPS_LIST)) {
                 if (preg_match(ARRAY_EXP, PSI_UPS_SNMPUPS_LIST)) {
                     $upss = eval(PSI_UPS_SNMPUPS_LIST);
                 } else {
                     $upss = array(PSI_UPS_SNMPUPS_LIST);
                 }
                 foreach ($upss as $ups) {
                     if (!PSI_DEBUG) {
                         restore_error_handler();
                         /* default error handler */
                         $old_err_rep = error_reporting();
                         error_reporting(E_ERROR);
                         /* fatal errors only */
                     }
                     $bufferarr = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.1", 1000000, 1);
                     if (!PSI_DEBUG) {
                         error_reporting($old_err_rep);
                         /* restore error level */
                         set_error_handler('errorHandlerPsi');
                         /* restore error handler */
                     }
                     if (!empty($bufferarr)) {
                         $buffer = "";
                         foreach ($bufferarr as $id => $string) {
                             $buffer .= $id . " = " . $string . "\n";
                         }
                         if (!PSI_DEBUG) {
                             restore_error_handler();
                             /* default error handler */
                             $old_err_rep = error_reporting();
                             error_reporting(E_ERROR);
                             /* fatal errors only */
                         }
                         $bufferarr2 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.2", 1000000, 1);
                         $bufferarr3 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.3", 1000000, 1);
                         $bufferarr4 = snmprealwalk($ups, "public", ".1.3.6.1.4.1.318.1.1.1.4", 1000000, 1);
                         if (!PSI_DEBUG) {
                             error_reporting($old_err_rep);
                             /* restore error level */
                             set_error_handler('errorHandlerPsi');
                             /* restore error handler */
                         }
                         if (!empty($bufferarr2)) {
                             foreach ($bufferarr2 as $id => $string) {
                                 $buffer .= $id . " = " . $string . "\n";
                             }
                             if (!empty($bufferarr3)) {
                                 foreach ($bufferarr3 as $id => $string) {
                                     $buffer .= $id . " = " . $string . "\n";
                                 }
                             }
                         }
                         if (!empty($bufferarr4)) {
                             foreach ($bufferarr4 as $id => $string) {
                                 $buffer .= $id . " = " . $string . "\n";
                             }
                         }
                         if (strlen(trim($buffer)) > 0) {
                             $this->_output[$ups] = $buffer;
                         }
                     }
                 }
             }
             break;
         default:
             $this->error->addError("switch(PSI_UPS_SNMPUPS_ACCESS)", "Bad SNMPups configuration in phpsysinfo.ini");
             break;
     }
 }