Last active
November 26, 2015 23:25
-
-
Save msigley/ffedd83ed9f9c2d45d1e 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 | |
* @version 1.2 | |
* @copyright Ingenesis Limited, 27 April, 2008 | |
* @package shopp | |
* @since 1.2 | |
* @subpackage OrderAmountAfterDiscounts | |
* | |
* $Id: OrderAmountAfterDiscounts.php 2825 2012-01-04 21:46:40Z jond $ | |
**/ | |
class OrderAmountAfterDiscounts extends ShippingFramework implements ShippingModule { | |
function init () { /* Not implemented */ } | |
function calcitem ($id,$Item) { /* Not implemented */ } | |
function methods () { | |
return __('Order Amount After Discounts Tiers','Shopp'); | |
} | |
function calculate (&$options,$Order) { | |
foreach ($this->methods as $slug => $method) { | |
$tiers = $this->tablerate($method['table']); | |
if ($tiers === false) continue; // Skip methods that don't match at all | |
$amount = 0; | |
$tiers = array_reverse($tiers); | |
$sub_total_after_discounts = $Order->Cart->Totals->subtotal - $Order->Cart->Totals->discounts; | |
if( $sub_total_after_discounts < 0 ) | |
$sub_total_after_discounts = 0; | |
foreach ($tiers as $tier) { | |
extract($tier); | |
$amount = floatvalue($rate); // Capture the rate amount | |
if (floatvalue($sub_total_after_discounts) >= floatvalue($threshold)) break; | |
} | |
$rate = array( | |
'slug' => $slug, | |
'name' => $method['label'], | |
'amount' => $amount, | |
'delivery' => $this->delivery($method), | |
'items' => false | |
); | |
$options[$slug] = new ShippingOption($rate); | |
} | |
return $options; | |
} | |
function settings () { | |
$this->ui->tablerates(0,array( | |
'unit' => array(__('Order Amount','Shopp')), | |
'table' => $this->settings['table'], | |
'threshold_class' => 'money', | |
'rate_class' => 'money' | |
)); | |
} | |
} // end flatrates class | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment