This was totally NOT fun to do ...
This is what I finally did in Zen Cart v1.5.1 to make this work, after a zillion attempts to get it working right ...
Start with the shipping module, this was a total re-write, then I found a better way so do this:
/includes/modules/shipping/freeoptions.php
Code:
// disable only when entire cart is free shipping
if (zen_get_shipping_enabled($this->code)) {
$this->enabled = ((MODULE_SHIPPING_FREEOPTIONS_STATUS == 'True') ? true : false);
}
// bof: manage Free Shipping Options exclude discounts
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && isset($_SESSION['cc_id'])) {
$this->enabled = false;
}
// eof: manage Free Shipping Options exclude discounts
if ( ($this->enabled == true) && ((int)MODULE_SHIPPING_FREEOPTIONS_ZONE > 0) ) {
Then add the code in RED:
Code:
// final check for display of Free Options
if ($this->ck_freeoptions_total or $this->ck_freeoptions_weight or $this->ck_freeoptions_items) {
$this->enabled = true;
} else {
$this->enabled = false;
}
// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
$this->enabled = false;
}
// eof: manage Free Shipping Options exclude discounts
if ($this->enabled) {
Next, for the Order Total module, this was also a total re-write, then I found a better way to do this:
/includes/modules/order_total/ot_coupon.php
Code:
$this->output[] = array('title' => $this->title . ': ' . $this->coupon_code . ' :',
'text' => '-' . $currencies->format($od_amount['total']),
'value' => $od_amount['total']);
// bof: manage Free Shipping Options exclude discounts
$_SESSION['free_shipping_options_total'] = ($order_total['total'] - $od_amount['total']);
// eof: manage Free Shipping Options exclude discounts
Now add to the checkout_payment header:
/includes/modules/pages/checkout_payment/header_php.php
Code:
// load all enabled payment modules
require(DIR_WS_CLASSES . 'payment.php');
$payment_modules = new payment;
$flagOnSubmit = sizeof($payment_modules->selection());
// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . ' MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN: ' . MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN . ' $_SESSION[cc_id]: ' . $_SESSION['cc_id'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
// eof: manage Free Shipping Options exclude discounts
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
And finally, the Page file for the checkout_confirmation:
/includes/modules/pages/checkout_confirmation/header_php.php
Code:
if (isset($$_SESSION['payment']->flagDisablePaymentAddressChange)) {
$flagDisablePaymentAddressChange = $$_SESSION['payment']->flagDisablePaymentAddressChange;
}
// bof: manage Free Shipping Options exclude discounts
//echo '$_SESSION[free_shipping_options_total]: ' . $_SESSION['free_shipping_options_total'] . '<br>';
if ($_SESSION['free_shipping_options_total'] < MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN && $_SESSION['shipping']['id'] == 'freeoptions_freeoptions' && isset($_SESSION['cc_id'])) {
zen_redirect(zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'));
}
// eof: manage Free Shipping Options exclude discounts
require(DIR_WS_MODULES . zen_get_module_directory('require_languages.php'));
Now, in theory a customer can come along and pick Free Shipping Options when the Total is >= 40.00 (MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) and if they then go on and add a Discount Coupon that reduces it to less than 40.00 (MODULE_SHIPPING_FREEOPTIONS_TOTAL_MIN) they will be redirected back to the checkout_shipping when they try to go to the checkout_confirmation page ...
Please test this heavily to ensure that it is working correctly ...
Bookmarks