[NOT A BUG] Possible free shipping bug
Zen Cart 2.0.1
PHP 8.3.9
Bootstrap 3.7.1
OPC 2.5.2
We have a physical product marked Yes, Always Free Shipping in the product entry.
The freeshipper module is set to a working custom zone. Someone outside of said zone with this product does not qualify for free shipping, but USPS is not coming up. No error, just blank... no shipping options.
Re: Possible free shipping bug
Short term workaround for you would be to edit includes/modules/shipping/usps.php and update the update_status() function to remove this block:
// disable only when entire cart is free shipping
if (!zen_get_shipping_enabled($this->code)) {
$this->enabled = false;
}
If that works, you can ask @lat9 to add a notifier so you can do this without modifying the USPS module.
Re: Possible free shipping bug
The product is set to indicate that it's always free shipping, which results in the call to zen_get_shipping_enabled to return (bool)false. What's needed for this site-specific requirement is the addition of a notifier in that function, not in a specific shipping method.
Give this a try, along with your observer. If that does the trick, I'll be happy to submit a PR.
Code:
function zen_get_shipping_enabled(string $shipping_module): bool
{
global $PHP_SELF;
// for admin always true
if (IS_ADMIN_FLAG && strstr($PHP_SELF, FILENAME_MODULES)) {
return true;
}
$check_cart_free = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping', '1');
$check_cart_cnt = $_SESSION['cart']->count_contents();
$check_cart_weight = $_SESSION['cart']->show_weight();
global $zco_notifier;
$override_enabled = false;
$zco_notifier->notify('ZEN_GET_SHIPPING_ENABLED_OVERRIDE', compact('check_cart_free', 'check_cart_cnt', 'check_cart_weight'), $override_enabled);
if ($override_enabled === true) {
return true;
}
// Free Shipping when 0 weight - enable freeshipper - ORDER_WEIGHT_ZERO_STATUS must be on
if (ORDER_WEIGHT_ZERO_STATUS == '1' && ($check_cart_weight == 0 && $shipping_module == 'freeshipper')) {
return true;
}
// Free Shipping when 0 weight - disable everyone - ORDER_WEIGHT_ZERO_STATUS must be on
if (ORDER_WEIGHT_ZERO_STATUS == '1' && ($check_cart_weight == 0 && $shipping_module != 'freeshipper')) {
return false;
}
if ($_SESSION['cart']->free_shipping_items() == $check_cart_cnt && $shipping_module == 'freeshipper') {
return true;
}
if ($_SESSION['cart']->free_shipping_items() == $check_cart_cnt && $shipping_module != 'freeshipper') {
return false;
}
// Always free shipping only true - enable freeshipper
if ($check_cart_free == $check_cart_cnt && $shipping_module == 'freeshipper') {
return true;
}
// Always free shipping only true - disable everyone
if ($check_cart_free == $check_cart_cnt && $shipping_module != 'freeshipper') {
return false;
}
// Always free shipping only is false - disable freeshipper
if ($check_cart_free != $check_cart_cnt && $shipping_module == 'freeshipper') {
return false;
}
return true;
}
Re: Possible free shipping bug
Nice - this way it covers all shipping methods.
Re: Possible free shipping bug
Quote:
Originally Posted by
lat9
The product is set to indicate that it's
always free shipping, which results in the call to zen_get_shipping_enabled to return
(bool)false. What's needed for this site-specific requirement is the addition of a notifier in that function, not in a specific shipping method.
Give this a try, along with your observer. If that does the trick, I'll be happy to submit a PR.
Code:
function zen_get_shipping_enabled(string $shipping_module): bool
{
global $PHP_SELF;
// for admin always true
if (IS_ADMIN_FLAG && strstr($PHP_SELF, FILENAME_MODULES)) {
return true;
}
$check_cart_free = $_SESSION['cart']->in_cart_check('product_is_always_free_shipping', '1');
$check_cart_cnt = $_SESSION['cart']->count_contents();
$check_cart_weight = $_SESSION['cart']->show_weight();
global $zco_notifier;
$override_enabled = false;
$zco_notifier->notify('ZEN_GET_SHIPPING_ENABLED_OVERRIDE', compact('check_cart_free', 'check_cart_cnt', 'check_cart_weight'), $override_enabled);
if ($override_enabled === true) {
return true;
}
// Free Shipping when 0 weight - enable freeshipper - ORDER_WEIGHT_ZERO_STATUS must be on
if (ORDER_WEIGHT_ZERO_STATUS == '1' && ($check_cart_weight == 0 && $shipping_module == 'freeshipper')) {
return true;
}
// Free Shipping when 0 weight - disable everyone - ORDER_WEIGHT_ZERO_STATUS must be on
if (ORDER_WEIGHT_ZERO_STATUS == '1' && ($check_cart_weight == 0 && $shipping_module != 'freeshipper')) {
return false;
}
if ($_SESSION['cart']->free_shipping_items() == $check_cart_cnt && $shipping_module == 'freeshipper') {
return true;
}
if ($_SESSION['cart']->free_shipping_items() == $check_cart_cnt && $shipping_module != 'freeshipper') {
return false;
}
// Always free shipping only true - enable freeshipper
if ($check_cart_free == $check_cart_cnt && $shipping_module == 'freeshipper') {
return true;
}
// Always free shipping only true - disable everyone
if ($check_cart_free == $check_cart_cnt && $shipping_module != 'freeshipper') {
return false;
}
// Always free shipping only is false - disable freeshipper
if ($check_cart_free != $check_cart_cnt && $shipping_module == 'freeshipper') {
return false;
}
return true;
}
This does not work. In 1.5.8 it wasn't an issue. I get the always free shipping gist, but the freeshipper module has a zone definition. I can see where it would need to be limited by zone... can't ship free to the UK for the same price as the US. I appreciate your help with this. Have it working with this temporarily.
Code:
global $zco_notifier;
$override_enabled = true;
$zco_notifier->notify('ZEN_GET_SHIPPING_ENABLED_OVERRIDE', compact('check_cart_free', 'check_cart_cnt', 'check_cart_weight'), $override_enabled);
if ($override_enabled === true) {
return true;
}
Thanks again =)
Re: Possible free shipping bug
Your notifier needs to fire for USPS, not Free Shipping. It's USPS you want to turn on.