• I see from the debug info that the plugin retrieves time in transit info for each shipping option presented. Is there a way that I can get & use this info to, for instance, only offer the ground option if its time in transit is 2 days or less? Been digging thru the code, tried a bunch of stuff but haven’t found anything that works.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Piotr Jablonowski

    (@jablonowski)

    Hi @zoinks

    unfortunately for now we don’t support the time in transit option. We are planing this feature in one of the next version of the plugin.

    Thread Starter Zoinks! Graphics

    (@zoinks)

    Thanks for the response, Piotr! I wasn’t clear in my request… Can you point me to where/how in your code that *I* can hook in to obtain time in transit information? Specifically the “[TransitTime]” value as displayed below from the plugin’s debugging. I’ll be happy to share my customizations.

    [PackagingType] => YOUR_PACKAGING
    	[CommitDetails] => Array
    		(
    		[0] => FedExVendor\FedEx\RateService\ComplexType\CommitDetail Object
    			(
    			[name:protected] => CommitDetail
    			[values:protected] => Array
    				(
    				[ServiceType] => FEDEX_GROUND
    				[ServiceDescription] => FedExVendor\FedEx\RateService\ComplexType\ServiceDescription Object
    					(
    					[name:protected] => ServiceDescription
    					[values:protected] => Array
    						(
    						[ServiceType] => FEDEX_GROUND
    						[Code] => 92
    						[Description] => FedEx Ground
    						[AstraDescription] => FXG
    						)
    					)
    
    				[DerivedOriginDetail] => FedExVendor\FedEx\RateService\ComplexType\CleansedAddressAndLocationDetail Object
    					(
    					[name:protected] => CleansedAddressAndLocationDetail
    					[values:protected] => Array
    						(
    						[CountryCode] => US
    						[StateOrProvinceCode] => PA
    						[PostalCode] => 18708
    						[LocationNumber] => 185
    						)
    					)
    
    				[DerivedDestinationDetail] => FedExVendor\FedEx\RateService\ComplexType\CleansedAddressAndLocationDetail Object
    					(
    					[name:protected] => CleansedAddressAndLocationDetail
    					[values:protected] => Array
    						(
    						[CountryCode] => US
    						[StateOrProvinceCode] => PA
    						[PostalCode] => 18708
    						[LocationNumber] => 185
    						[AirportId] => ABE
    						)
    					)
    
    				[TransitTime] => ONE_DAY
    				[BrokerToDestinationDays] => 0
    				)
    
    			)
    		)
    • This reply was modified 4 years, 6 months ago by Zoinks! Graphics. Reason: cleaned up code sample
    Plugin Author Piotr Jablonowski

    (@jablonowski)

    Hi @zoinks

    unfortunately, we don’t have a hook at the moment that you can use. This is a very early version of the plugin so thank you for your suggestion.

    We know that the time in transit support is important so it will probably be available in future versions of the plugin.

    Thread Starter Zoinks! Graphics

    (@zoinks)

    Thanks, but again, I didn’t explain clearly. Can you please tell me which file in your plugin the SOAP query fires off to create the code snippet I included above? Then I will add some functions on my end to get the time in transit info.

    Again, I will be happy to send you whatever code I come up with if it helps with developing the next version of your plugin.

    Hi @zoinks,

    the heart of this routine is in flexible-shipping-fedex/src/FedexShippingService/FedexShippingService.php in rate_shipment() method.

    
    try {
    	$response = $this->get_sender()->send( $request );  // 1
    	$reply    = new FedexRateReplyInterpretation( $response, $this->shop_settings->is_tax_enabled() ); // 2
    	if ( $reply->has_reply_warning() ) { // 3
    		$this->logger->info( $reply->get_reply_message() ); // 4
    	} // 5
    	$this->logger->info( 'FedEx response', [ 'response' => $response ] ); // 6 
    	$fedex_rates = $reply->get_rates(); // 7
    	$rates       = new ShipmentRatingImplementation( $this->filter_service_rates( $settings, $fedex_rates ) ); // 8
    } 
    

    I marked the lines for description using the // comment mark and a number.

    In line 1, the prepared request to FedEx api is sent, and the the response that you mentioned is returned. The response is in RateReply object from https://github.com/JeremyDunn/php-fedex-api-wrapper library and it’s a structure for which you asked. The library is prefixed to avoid conflicts with other users of the library in the same WordPress env.
    In line 4 that structure is written to the log file – and that is where you have probably found it.
    In line 2 we convert the raw reply from the library to our own format to ensure internal independence from the library and unify the approach to the rate task. The converted response is received in line 7 as an array of SingleRate[] DTO. SingleRate DTO is defined in flexible-shipping-fedex/src/AbstractShipping/Rate/SingleRate.php
    Finally, in 8 we filter it and return in a unified way as an object that implements ShipmentRating interface.

    Best regards,
    dyszczo

    Thread Starter Zoinks! Graphics

    (@zoinks)

    Cool, thanks! Now how would I call the public function rate_shipment() outside of FedexShippingService.php like say in my theme’s functions.php? Just adding that function results in…

    Fatal error: Uncaught Error: Call to undefined function rate_shipment()

    Hi @zoinks,

    > Now how would I call the public function rate_shipment()

    Well, it’s not a function, it’s a method. To call it from outside the plugin you would have to create a FedexShippingService
    object and then call rate_shipment on it providing all the parameters that the object and the method requires.

    You can also get the FedexShippingService object from flexible_shipping_fedex_shipping_service filter but you still have to provide required parameters for rate_shipment method.

    To learn more about class/object concept I would recommend the https://www.php.net/manual/en/language.oop5.php page as the plugin depends on it heavily.

    Probably the quickest and easiest way to achieve your goal would be to directly modify the rate_shipment method inside the plugin. It would be overwritten after an upgrade so you would have to block upgrade of this plugin but it would be much easier than trying to clone some plugin calls.

    Best regards,
    dyszczo

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Time in transit?’ is closed to new replies.