Ejemplo n.º 1
0
 /**
  * @dataProvider calculateDomesticParcelPostageProvider
  */
 public function testCalculateDomesticParcelPostage($mock, $args, $cost, $subcosts = null)
 {
     $this->setMockResponse($this->client, $mock);
     $response = $this->client->calculateDomesticParcelPostage($args);
     $this->assertArrayHasKey('postage_result', $response);
     $this->assertArrayHasKey('total_cost', $response['postage_result']);
     $price = $response['postage_result']['total_cost'];
     $this->assertEquals($cost, $price);
     if ($subcosts) {
         $this->assertArrayHasKey('costs', $response['postage_result']);
         $this->assertArrayHasKey('cost', $response['postage_result']['costs']);
         $costs = $response['postage_result']['costs']['cost'];
         $this->assertCount(count($subcosts), $costs);
         $items = array();
         foreach ($costs as $subcost) {
             $items[$subcost['item']] = $subcost['cost'];
         }
         foreach ($subcosts as $key => $value) {
             $this->assertArrayHasKey($key, $items);
             $this->assertEquals($value, $items[$key]);
         }
     }
 }
Ejemplo n.º 2
0
 protected function _getQuotes($extraCover, $config)
 {
     $destCountry = $config['country_code'];
     try {
         if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
             $services = $this->_client->listDomesticParcelServices($config);
         } else {
             $services = $this->_client->listInternationalParcelServices($config);
         }
     } catch (Exception $e) {
         Mage::logException($e);
         return;
     }
     // TODO: Clean up this logic
     $allowedMethods = $this->getAllowedMethods();
     $extraCoverParent = $this->getCode('extra_cover');
     foreach ($services['services']['service'] as $service) {
         $serviceCode = $service['code'];
         // e.g. AUS_PARCEL_REGULAR
         if (in_array($serviceCode, $allowedMethods)) {
             $serviceName = $service['name'];
             // e.g. Parcel Post
             $servicePrice = $service['price'];
             // Just add the shipping method if the call to Australia Post
             // returns no options for that method
             if (!isset($service['options']['option']) && $this->_isAvailableShippingMethod($serviceName, $destCountry)) {
                 $method = $this->createMethod($serviceCode, $serviceName, $servicePrice);
                 $this->_result->append($method);
                 // If a shipping method has a bunch of options, we will have to
                 // create a specific method for each of the variants
             } else {
                 $serviceOption = $service['options']['option'];
                 // Unlike domestic shipping methods where the "default"
                 // method is listed as simply another service option (this
                 // allows us to simply loop through each one), we have to
                 // extrapolate the default international shipping method
                 // from what we know about the service itself
                 if ($destCountry != Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE && $this->_isAvailableShippingMethod($serviceName, $destCountry)) {
                     $method = $this->createMethod($serviceCode, $serviceName, $servicePrice);
                     $this->_result->append($method);
                 }
                 // Checks to see if the API has returned either a single
                 // service option or an array of them. If it is a single
                 // option then turn it into an array.
                 if (isset($serviceOption['name'])) {
                     $serviceOption = array($serviceOption);
                 }
                 foreach ($serviceOption as $option) {
                     $serviceOptionName = $option['name'];
                     $serviceOptionCode = $option['code'];
                     $config = array_merge($config, array('service_code' => $serviceCode, 'option_code' => $serviceOptionCode, 'extra_cover' => $extraCover));
                     try {
                         if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
                             $postage = $this->_client->calculateDomesticParcelPostage($config);
                         } else {
                             $postage = $this->_client->calculateInternationalParcelPostage($config);
                         }
                     } catch (Exception $e) {
                         continue;
                     }
                     $servicePrice = $postage['postage_result']['total_cost'];
                     /** @var Fontis_Australia_Helper_Clickandsend $clickandsendHelper */
                     $clickandsendHelper = Mage::helper('australia/clickandsend');
                     // Create a shipping method with only the top-level options
                     $_finalCode = $serviceCode . '_' . $serviceOptionCode;
                     $_finalName = $serviceName . ' (' . $serviceOptionName . ')';
                     if ($this->_isAvailableShippingMethod($_finalName, $destCountry) && !(in_array($serviceOptionCode, $clickandsendHelper->getDisallowedServiceOptions()) && in_array($serviceCode, $clickandsendHelper->getDisallowedServiceCodes()) && $clickandsendHelper->isClickAndSendEnabled() && $clickandsendHelper->isFilterShippingMethods())) {
                         $method = $this->createMethod($_finalCode, $_finalName, $servicePrice);
                         $this->_result->append($method);
                     }
                     // Add the extra cover options (these are suboptions of
                     // the top-level options)
                     if (array_key_exists($serviceOptionCode, $extraCoverParent) && !($clickandsendHelper->isClickAndSendEnabled() && $clickandsendHelper->isFilterShippingMethods())) {
                         try {
                             if ($destCountry == Fontis_Australia_Helper_Data::AUSTRALIA_COUNTRY_CODE) {
                                 $config = array_merge($config, array('suboption_code' => ServiceOption::AUS_SERVICE_OPTION_EXTRA_COVER));
                                 $postageWithExtraCover = $this->_client->calculateDomesticParcelPostage($config);
                             } else {
                                 $postageWithExtraCover = $this->_client->calculateInternationalParcelPostage($config);
                             }
                             unset($config['suboption_code']);
                         } catch (Exception $e) {
                             continue;
                         }
                         if ($serviceOptionName == 'Signature on Delivery') {
                             $serviceOptionName = $serviceOptionName . ' + Extra Cover';
                         } else {
                             $serviceOptionName = 'Extra Cover';
                         }
                         if ($serviceOptionCode == ServiceOption::AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY) {
                             $serviceOptionCode = 'FULL_PACKAGE';
                         } else {
                             $serviceOptionCode = 'EXTRA_COVER';
                         }
                         $servicePrice = $postageWithExtraCover['postage_result']['total_cost'];
                         $_finalCode = $serviceCode . '_' . $serviceOptionCode;
                         $_finalName = $serviceName . ' (' . $serviceOptionName . ')';
                         if ($this->_isAvailableShippingMethod($_finalName, $destCountry)) {
                             $method = $this->createMethod($_finalCode, $_finalName, $servicePrice);
                             $this->_result->append($method);
                         }
                     }
                 }
             }
         }
     }
 }