Version 4.1.2

This commit is contained in:
Neo committed 2025-12-19 05:32:19 -08:00
1 parent 3ba79295ee
commit 28bd025b35
1131 files changed
+63658 -20579

No files matched your search

@@ -40,12 +40,15 @@ class _EasyPostRate implements \IPS\nexus\Shipping\Rate
}
/**
* Is available to destination?
* Is available?
*
* @param \IPS\GeoLocation $destination Desired destination
* @param \IPS\GeoLocation $destination Desired destination
* @param array $items Items
* @param string $currency Desired currency
* @param \IPS\nexus\Invoice|NULL $invoice The invoice
* @return bool
*/
public function isAvailable( \IPS\GeoLocation $destination )
public function isAvailable( \IPS\GeoLocation $destination, array $items, $currency, \IPS\nexus\Invoice $invoice = NULL )
{
return TRUE;
}
@@ -141,7 +144,7 @@ class _EasyPostRate implements \IPS\nexus\Shipping\Rate
*/
public static function getRates( $lengthInInches, $widthInInches, $heightInInches, $weightInOz, \IPS\nexus\Customer $toCustomer, \IPS\Geolocation $toAddress, $currency )
{
$fromAddress = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address );
$fromAddress = \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->easypost_address ?: \IPS\Settings::i()->site_address );
return \IPS\Http\Url::external( 'https://api.easypost.com/v2/shipments' )->request()->login( \IPS\Settings::i()->easypost_api_key, '' )->post( array( 'shipment' => array(
'to_address' => array(
@@ -363,35 +363,56 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
}
/**
* Is available to destination?
* Is available?
*
* @param \IPS\GeoLocation $destination Desired destination
* @param \IPS\GeoLocation $destination Desired destination
* @param array $items Items
* @param string $currency Desired currency
* @param \IPS\nexus\Invoice|NULL $invoice The invoice
* @return bool
*/
public function isAvailable( \IPS\GeoLocation $destination )
public function isAvailable( \IPS\GeoLocation $destination, array $items, $currency, \IPS\nexus\Invoice $invoice = NULL )
{
if ( $this->locations === '*' )
{
return TRUE;
}
else
/* Is available to destination? */
if ( $this->locations !== '*' )
{
$locations = json_decode( $this->locations, TRUE );
if ( isset( $locations[ $destination->country ] ) )
{
if ( $locations[ $destination->country ] === '*' )
if ( $locations[ $destination->country ] !== '*' and !in_array( $destination->region, $locations[ $destination->country ] ) )
{
return TRUE;
}
else
{
return in_array( $destination->region, $locations[ $destination->country ] );
return FALSE;
}
}
return FALSE;
else
{
return FALSE;
}
}
/* Is it available for what's being bought? */
$criteria = $this->_getCriteria( $items, $invoice );
$rates = json_decode( $this->rates, TRUE );
foreach ( $rates as $rate )
{
$min = $rate['min'];
if ( is_array( $min ) )
{
$min = $min[ $currency ];
}
$max = $rate['max'];
if ( is_array( $max ) )
{
$max = $max[ $currency ];
}
if ( ( $min === '*' or $criteria >= $min ) and ( $max === '*' or $criteria <= $max ) )
{
return TRUE;
}
}
return FALSE;
}
/**
@@ -405,14 +426,13 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
}
/**
* Price
* Get criteria
*
* @param array $items Items
* @param string $currency Desired currency
* @param \IPS\nexus\Invoice|NULL $invoice The invoice
* @return \IPS\nexus\Money
* @return The criteria the rased is based on (e.g. if the rate is based on invoice total, will return the invoice total)
*/
public function getPrice( array $items, $currency, \IPS\nexus\Invoice $invoice = NULL )
protected function _getCriteria( array $items, \IPS\nexus\Invoice $invoice = NULL )
{
switch ( $this->type )
{
@@ -450,6 +470,21 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
}
}
return $criteria;
}
/**
* Price
*
* @param array $items Items
* @param string $currency Desired currency
* @param \IPS\nexus\Invoice|NULL $invoice The invoice
* @return \IPS\nexus\Money
*/
public function getPrice( array $items, $currency, \IPS\nexus\Invoice $invoice = NULL )
{
$criteria = $this->_getCriteria( $items, $invoice );
$rates = json_decode( $this->rates, TRUE );
foreach ( $rates as $rate )
{
+6 -3
View File
@@ -25,12 +25,15 @@ if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
interface Rate
{
/**
* Is available to destination?
* Is available?
*
* @param \IPS\GeoLocation $destination Desired destination
* @param \IPS\GeoLocation $destination Desired destination
* @param array $items Items
* @param string $currency Desired currency
* @param \IPS\nexus\Invoice|NULL $invoice The invoice
* @return bool
*/
public function isAvailable( \IPS\GeoLocation $destination );
public function isAvailable( \IPS\GeoLocation $destination, array $items, $currency, \IPS\nexus\Invoice $invoice = NULL );
/**
* Name