Forked from msigley/OrderAfterDiscountsRates.php
Last active
November 26, 2015 23:26
-
-
Save meredevelopment/a515df2ac7a68e79cee9 to your computer and use it in GitHub Desktop.
Shopp Shipping Order Rates based on sub total after discounts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Order Amount After Discounts Tiers | |
* | |
* Provides shipping calculations based on order amount ranges | |
* | |
* @author Jonathan Davis, Matthew Sigley, Ben Hutchings | |
* @version 1.3 | |
* @copyright Ingenesis Limited, 27 April, 2008 | |
* @package shopp | |
* @since 1.3 | |
* @subpackage OrderAmountAfterDiscounts | |
* | |
**/ | |
defined( 'WPINC' ) || header( 'HTTP/1.1 403' ) & exit; // Prevent direct access | |
class OrderAmountAfterDiscounts extends ShippingFramework implements ShippingModule { | |
public function init () { | |
/* Not implemented */ | |
} | |
public function calcitem ($id,$Item) { | |
/* Not implemented */ | |
} | |
public function methods () { | |
return Shopp::__('Order Amount After Discounts Tiers'); | |
} | |
public function calculate ( &$options, $Order ) { | |
foreach ( $this->methods as $slug => $method ) { | |
$tiers = isset($method['table']) ? $this->tablerate($method['table']) : false; | |
if ( $tiers === false ) continue; // Skip methods that don't match at all | |
$amount = 0; | |
$matched = false; | |
$tiers = array_reverse($tiers); | |
$sub_total_after_discounts = $Order->Cart->total('order') + $Order->Cart->total('discount'); | |
if( $sub_total_after_discounts < 0 ) { | |
$sub_total_after_discounts = 0; | |
} | |
foreach ( $tiers as $tier ) { | |
extract($tier); | |
$amount = Shopp::floatval($rate); // Capture the rate amount | |
if ( Shopp::floatval($sub_total_after_discounts) >= Shopp::floatval($threshold) ) { | |
$matched = true; | |
break; | |
} | |
} | |
if ( ! $matched ) return $options; | |
$rate = array( | |
'slug' => $slug, | |
'name' => $method['label'], | |
'amount' => $amount, | |
'delivery' => $this->delivery($method), | |
'items' => false | |
); | |
$options[$slug] = new ShippingOption($rate); | |
} | |
return $options; | |
} | |
public function settings () { | |
$this->setup('table'); | |
$this->ui->tablerates(0,array( | |
'unit' => array( Shopp::__('Order Amount') ), | |
'table' => $this->settings['table'], | |
'threshold_class' => 'money', | |
'rate_class' => 'money' | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment