Esempio n. 1
0
 /**
  * Based on passed address information, calculates the total shipping cost
  *
  * @param $fields
  * @param $cart
  * @param string $country
  * @param string $zipcode
  * @param string $state
  * @param string $city
  * @param string $address2
  * @param string $address1
  * @param string $company
  * @param string $lname
  * @param string $fname
  * @return array|bool
  */
 public function total($fields, $cart, $country = '', $zipcode = '', $state = '', $city = '', $address2 = '', $address1 = '', $company = '', $lname = '', $fname = '')
 {
     $config = $this->getConfigValues(get_class($this));
     $weight = $cart->Weight;
     if (_xls_get_conf('WEIGHT_UNIT', 'lb') != 'lb') {
         $weight = $weight * 2.2;
     }
     // one KG is 2.2 pounds
     $length = $cart->Length;
     $width = $cart->Width;
     $height = $cart->Height;
     if (_xls_get_conf('DIMENSION_UNIT', 'in') != 'in') {
         $length = round($length / 2.54);
         $width = round($width / 2.54);
         $height = round($height / 2.54);
     }
     if ($length < 1 && $length > 0) {
         $length = 1;
     }
     if ($width < 1 && $width > 0) {
         $width = 1;
     }
     if ($height < 1 && $height > 0) {
         $height = 1;
     }
     if (empty($config['securitycode']) || empty($config['accnumber']) || empty($config['meternumber'])) {
         return FALSE;
     }
     $ret = array();
     $newline = "<br />";
     //The WSDL is not included with the sample code.
     //Please include and reference in $path_to_wsdl variable.
     $path_to_wsdl = dirname(__FILE__) . "/RateService_v7.wsdl";
     ini_set("soap.wsdl_cache_enabled", "0");
     $client = new SoapClient($path_to_wsdl, array('trace' => 1));
     $request['WebAuthenticationDetail'] = array('UserCredential' => array('Key' => $config['authkey'], 'Password' => $config['securitycode']));
     $request['ClientDetail'] = array('AccountNumber' => $config['accnumber'], 'MeterNumber' => $config['meternumber']);
     $request['TransactionDetail'] = array('CustomerTransactionId' => ' *** Rate Request v7 using PHP ***');
     $request['Version'] = array('ServiceId' => 'crs', 'Major' => '7', 'Intermediate' => '0', 'Minor' => '0');
     $request['ReturnTransitAndCommit'] = true;
     $request['RequestedShipment']['DropoffType'] = 'REGULAR_PICKUP';
     // valid values REGULAR_PICKUP, REQUEST_COURIER, ...
     $request['RequestedShipment']['ShipTimestamp'] = date('c');
     //Uncomment these additional options below if they are needed for your shipments
     //$request['RequestedShipment']['SpecialServicesRequested'] = array( 'SpecialServiceTypes' => array('SIGNATURE_OPTION'), 'SignatureOptionDetail' => array('OptionType' => 'ADULT'));
     //$request['RequestedShipment']['SignatureOptionDetail']['OptionType'] = 'ADULT';
     //$request['RequestedShipment']['ServiceType'] = 'PRIORITY_OVERNIGHT'; // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ...
     $config['origincountry'] = Country::CodeById($config['origincountry']);
     $config['originstate'] = State::CodeById($config['originstate']);
     if ($config['origincountry'] != "CA" && $config['origincountry'] != "US") {
         //Only required for these countries
         $config['originstate'] = "";
     }
     $request['RequestedShipment']['PackagingType'] = $config['packaging'];
     $request['RequestedShipment']['Shipper'] = array('Address' => array('StreetLines' => array($config['originadde']), 'City' => $config['origincity'], 'StateOrProvinceCode' => $config['originstate'], 'PostalCode' => $config['originpostcode'], 'CountryCode' => $config['origincountry']));
     if ($country != "CA" && $country != "US") {
         //Only required for these countries
         $state = "";
     }
     $request['RequestedShipment']['Recipient'] = array('Address' => array('StreetLines' => array($address1, $address2), 'City' => $city, 'StateOrProvinceCode' => $state, 'PostalCode' => $zipcode, 'CountryCode' => $country, 'Residential' => $this->CheckoutForm->shippingResidential == 1 ? 1 : 0));
     $request['RequestedShipment']['ShippingChargesPayment'] = array('PaymentType' => 'SENDER', 'Payor' => array('AccountNumber' => $config['accnumber'], 'CountryCode' => $config['origincountry']));
     $request['RequestedShipment']['RateRequestTypes'] = 'ACCOUNT';
     $request['RequestedShipment']['RateRequestTypes'] = 'LIST';
     if ($config['origincountry'] != $country && $config['customs'] == "CLEARANCEFEE") {
         $request['RequestedShipment']['InternationalDetail'] = array('CustomsValue' => array('Amount' => $cart->subtotal, 'Currency' => _xls_get_conf('CURRENCY_DEFAULT', 'USD')));
     }
     $request['RequestedShipment']['PackageCount'] = '1';
     $request['RateRequest']['CurrencyType'] = _xls_get_conf('CURRENCY_DEFAULT', 'USD');
     $request['RequestedShipment']['PackageDetail'] = 'INDIVIDUAL_PACKAGES';
     if ($length + $width + $height == 0) {
         $request['RequestedShipment']['RequestedPackageLineItems'] = array('0' => array('SequenceNumber' => '1', 'InsuredValue' => array('Amount' => $cart->subtotal, 'Currency' => _xls_get_conf('CURRENCY_DEFAULT', 'USD')), 'ItemDescription' => 'Ordered items', 'Weight' => array('Value' => $weight, 'Units' => 'LB'), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => _xls_get_conf('STORE_NAME', 'Web Order'))));
     } else {
         $request['RequestedShipment']['RequestedPackageLineItems'] = array('0' => array('SequenceNumber' => '1', 'InsuredValue' => array('Amount' => $cart->subtotal, 'Currency' => _xls_get_conf('CURRENCY_DEFAULT', 'USD')), 'ItemDescription' => 'Ordered items', 'Weight' => array('Value' => $weight, 'Units' => 'LB'), 'Dimensions' => array('Length' => $length, 'Width' => $width, 'Height' => $height, 'Units' => 'IN'), 'CustomerReferences' => array('CustomerReferenceType' => 'CUSTOMER_REFERENCE', 'Value' => _xls_get_conf('STORE_NAME', 'Web Order'))));
     }
     try {
         $response = $client->getRates($request);
         Yii::log(get_class($this) . " sending " . print_r($request, true), $this->logLevel, 'application.' . __CLASS__ . "." . __FUNCTION__);
         Yii::log(get_class($this) . " receiving " . print_r($response, true), $this->logLevel, 'application.' . __CLASS__ . "." . __FUNCTION__);
         if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') {
             if (isset($response->RateReplyDetails)) {
                 if (is_array($response->RateReplyDetails) === false) {
                     $response->RateReplyDetails = array($response->RateReplyDetails);
                 }
                 foreach ($response->RateReplyDetails as $rateReply) {
                     if (isset($rateReply->RatedShipmentDetails)) {
                         foreach ($rateReply->RatedShipmentDetails as $choice) {
                             if ($choice->ShipmentRateDetail->RateType == $config['ratetype']) {
                                 $ret[$rateReply->ServiceType] = $choice->ShipmentRateDetail->TotalNetCharge->Amount;
                             } elseif ($rateReply->ServiceType == "FEDEX_GROUND" || $rateReply->ServiceType == "GROUND_HOME_DELIVERY") {
                                 $ret[$rateReply->ServiceType] = $rateReply->RatedShipmentDetails[1]->ShipmentRateDetail->TotalNetCharge->Amount;
                             }
                         }
                     }
                 }
             }
         }
     } catch (SoapFault $exception) {
         _xls_log("FedEx Soap Fault : " . $exception . " ");
         $response = $exception;
     }
     if (count($ret) <= 0) {
         _xls_log("FedEx could not get rate for {$country}, {$state}, {$zipcode} .  ");
         _xls_log("FedEx request: " . print_r($request, true));
         _xls_log("FedEx Response: " . print_r($response, true));
         return false;
     }
     asort($ret);
     Yii::log(get_class($this) . " received shipping array " . print_r($ret, true), $this->logLevel, 'application.' . __CLASS__ . "." . __FUNCTION__);
     return $this->convertRetToDisplay($ret);
 }
Esempio n. 2
0
 function __runCurl()
 {
     $y = $this->construct_request_xml();
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, "{$this->upstool}");
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, "{$y}");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
     $this->xmlreturndata = curl_exec($ch);
     curl_close($ch);
     if (_xls_get_conf('DEBUG_SHIPPING', false)) {
         _xls_log(get_class($this) . " sending " . $y, true);
         _xls_log(get_class($this) . " receiving " . $this->xmlreturndata, true);
     }
 }
 /**
  * Flushes a DB Table
  * This gets called during a Reset Store Products for the following tables in sequence:
  * Product, Category, Tax, TaxCode, TaxStatus, Family, ProductRelated, ProductQtyPricing, Images
  *
  * @param string $passkey
  * @param string $strObj
  * @return string
  */
 public function db_flush($passkey, $strObj)
 {
     if (!$this->check_passkey($passkey)) {
         return self::FAIL_AUTH;
     }
     if (_xls_get_conf('DEBUG_RESET', 0) == 1) {
         _xls_log("Skipped flush operation due to DEBUG mode");
         return self::OK;
     }
     if (!class_exists($strObj)) {
         _xls_log("SOAP ERROR : There is no object type of {$strObj}");
         return self::NOT_FOUND;
     }
     if (in_array($strObj, array('Cart', 'Configuration', 'ConfigurationType', 'CartType', 'ViewLogType'))) {
         _xls_log("SOAP ERROR : Objects of type {$strObj} are not allowed for flushing");
         return self::UNKNOWN_ERROR;
     }
     /**
     		Lightspeed will send commands to flush the following tables
     		Product
     		Category
     		Tax
     		TaxCode
     		TaxStatus
     		Family
     		ProductRelated
     		ProductQtyPricing
     		Images
     */
     Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute();
     //For certain tables, we flush related data as well
     switch ($strObj) {
         case "Product":
             //Yii::app()->db->createCommand()->truncateTable('xlsws_product_image_assn');
             Yii::app()->db->createCommand()->truncateTable('xlsws_product_category_assn');
             Yii::app()->db->createCommand()->truncateTable('xlsws_classes');
             Yii::app()->db->createCommand()->truncateTable('xlsws_family');
             Yii::app()->db->createCommand()->truncateTable('xlsws_tags');
             Yii::app()->db->createCommand()->truncateTable('xlsws_product_tags');
             $strTableName = "xlsws_product";
             break;
         case "Category":
             Yii::app()->db->createCommand()->truncateTable('xlsws_product_category_assn');
             $strTableName = "xlsws_category_addl";
             //We blank our caching table, not the real table
             break;
         case "Tax":
             $strTableName = "xlsws_tax";
             break;
         case "TaxCode":
             $strTableName = "xlsws_tax_code";
             break;
         case "TaxStatus":
             $strTableName = "xlsws_tax_status";
             break;
         case "Family":
             $strTableName = "xlsws_family";
             break;
         case "ProductRelated":
             $strTableName = "xlsws_product_related";
             break;
         case "ProductQtyPricing":
             $strTableName = "xlsws_product_qty_pricing";
             break;
         case "Images":
             //Because we could have a huge number of Image entries, we need to just use SQL/DAO directly
             $cmd = Yii::app()->db->createCommand("SELECT image_path FROM xlsws_images WHERE image_path IS NOT NULL AND left(image_path,2)<>'//'");
             $dataReader = $cmd->query();
             while (($image = $dataReader->read()) !== false) {
                 @unlink(Images::GetImagePath($image['image_path']));
             }
             $cmd = Yii::app()->db->createCommand("SELECT cloudinary_public_id FROM xlsws_images_cloud WHERE cloudinary_public_id IS NOT NULL");
             $dataReader = $cmd->query();
             while (($image = $dataReader->read()) !== false) {
                 $objEvent = new CEventPhoto('Images', 'onDeletePhoto', null, null, null);
                 $objEvent->cloudinary_public_id = $image['cloudinary_public_id'];
                 _xls_raise_events('CEventPhoto', $objEvent);
                 Yii::app()->db->createCommand("delete FROM xlsws_images_cloud WHERE cloudinary_public_id='" . $image['cloudinary_public_id'] . "'");
             }
             $objEvent = new CEventPhoto('LegacysoapController', 'onFlushTable', null, null, 0);
             _xls_raise_events('CEventPhoto', $objEvent);
             $strTableName = "xlsws_images";
             break;
     }
     //Then truncate the table
     Yii::app()->db->createCommand()->truncateTable($strTableName);
     Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute();
     return self::OK;
 }
Esempio n. 4
0
function _xls_mail_body_from_template($templatefile, $vars)
{
    if (!file_exists($templatefile)) {
        _xls_log(_sp("FATAL ERROR : e-mail template file not found") . $templatefile);
        return "";
    }
    try {
        extract($vars);
    } catch (Exception $exc) {
        _xls_log(_sp("FATAL ERROR : problem extracting e-mail" . " variables in") . " " . print_r($vars, true));
        return "";
    }
    ob_start();
    include templateNamed('email_header.tpl.php');
    include $templatefile;
    include templateNamed('email_footer.tpl.php');
    $content = ob_get_contents();
    ob_end_clean();
    return $content;
}