Version 4.1.2
This commit is contained in:
1 parent
3ba79295ee
commit
28bd025b35
1131 files changed
+63658
-20579
No files matched your search
@@ -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 )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user