Version 4.1.19
This commit is contained in:
1 parent
28bd025b35
commit
2bd5025018
2674 files changed
+233518
-77766
No files matched your search
@@ -2,9 +2,9 @@
|
||||
/**
|
||||
* @brief Flat Shipping Rate Node
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Social Suite
|
||||
* @package IPS Community Suite
|
||||
* @subpackage Nexus
|
||||
* @since 13 Feb 2014
|
||||
* @version SVN_VERSION_NUMBER
|
||||
@@ -234,9 +234,9 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
{
|
||||
$rates = array();
|
||||
/* Populate */
|
||||
foreach ( $values[ "s_rates_{$values['s_type']}" ] as $rate )
|
||||
{
|
||||
if ( $rate["{$values['s_type']}_rate_min"] == '*' )
|
||||
foreach ( $values[ "s_rates_{$values['s_type']}" ] as $k => $rate )
|
||||
{
|
||||
if ( $rate["{$values['s_type']}_rate_min"] === '*' )
|
||||
{
|
||||
$min = '*';
|
||||
}
|
||||
@@ -260,7 +260,7 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
}
|
||||
}
|
||||
|
||||
if ( $rate["{$values['s_type']}_rate_max"] == '*' )
|
||||
if ( $rate["{$values['s_type']}_rate_max"] === '*' )
|
||||
{
|
||||
$max = '*';
|
||||
}
|
||||
@@ -283,12 +283,12 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( !$min and !$max )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$price = array();
|
||||
foreach ( $rate["{$values['s_type']}_rate_price"] as $money )
|
||||
{
|
||||
@@ -320,7 +320,7 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
{
|
||||
unset( $rates[$k] );
|
||||
}
|
||||
|
||||
|
||||
/* Save */
|
||||
$values['rates'] = json_encode( $rates );
|
||||
}
|
||||
@@ -406,8 +406,8 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
{
|
||||
$max = $max[ $currency ];
|
||||
}
|
||||
|
||||
if ( ( $min === '*' or $criteria >= $min ) and ( $max === '*' or $criteria <= $max ) )
|
||||
|
||||
if ( ( $min === '*' or $criteria->compare( new \IPS\Math\Number( number_format( $min, 5, '.', '' ) ) ) !== -1 ) and ( $max === '*' or $criteria->compare( new \IPS\Math\Number( number_format( $max, 5, '.', '' ) ) ) !== 1 ) )
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -430,7 +430,7 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
*
|
||||
* @param array $items Items
|
||||
* @param \IPS\nexus\Invoice|NULL $invoice The invoice
|
||||
* @return The criteria the rased is based on (e.g. if the rate is based on invoice total, will return the invoice total)
|
||||
* @return \IPS\Math\Number The criteria the rased is based on (e.g. if the rate is based on invoice total, will return the invoice total)
|
||||
*/
|
||||
protected function _getCriteria( array $items, \IPS\nexus\Invoice $invoice = NULL )
|
||||
{
|
||||
@@ -443,29 +443,29 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
}
|
||||
else
|
||||
{
|
||||
$criteria = 0;
|
||||
$criteria = new \IPS\Math\Number('0');
|
||||
foreach ( $items as $item )
|
||||
{
|
||||
$criteria += ( $item->price->amount * $item->quantity );
|
||||
$criteria = $criteria->add( $item->linePrice()->amount );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
$criteria = 0;
|
||||
$criteria = new \IPS\Math\Number('0');
|
||||
foreach ( $items as $item )
|
||||
{
|
||||
$criteria += $item->quantity;
|
||||
$criteria = $criteria->add( new \IPS\Math\Number( "{$item->quantity}" ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
$criteria = 0;
|
||||
$criteria = new \IPS\Math\Number('0');
|
||||
foreach ( $items as $item )
|
||||
{
|
||||
if ( isset( $item->weight ) )
|
||||
{
|
||||
$criteria += ( $item->weight->kilograms * $item->quantity );
|
||||
$criteria = $criteria->add( ( new \IPS\Math\Number( number_format( $item->weight->kilograms, 5, '.', '' ) ) )->multiply( new \IPS\Math\Number( "$item->quantity" ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -484,7 +484,7 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
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 )
|
||||
{
|
||||
@@ -498,8 +498,8 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
{
|
||||
$max = $max[ $currency ];
|
||||
}
|
||||
|
||||
if ( ( $min === '*' or $criteria >= $min ) and ( $max === '*' or $criteria <= $max ) )
|
||||
|
||||
if ( ( $min === '*' or $criteria->compare( new \IPS\Math\Number( number_format( $min, 5, '.', '' ) ) ) !== -1 ) and ( $max === '*' or $criteria->compare( new \IPS\Math\Number( number_format( $max, 5, '.', '' ) ) ) !== 1 ) )
|
||||
{
|
||||
return new \IPS\nexus\Money( $rate['price'][ $currency ], $currency );
|
||||
}
|
||||
@@ -541,4 +541,19 @@ class _FlatRate extends \IPS\Node\Model implements \IPS\nexus\Shipping\Rate
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( "nexus_shiprate_de_{$this->id}" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Name
|
||||
*/
|
||||
public function apiOutput()
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
'name' => \IPS\Member::loggedIn()->language()->addToStack( 'nexus_shiprate_' . $this->id )
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user