Forums / Bug Reports / [NOT A BUG] Possible free shipping bug

[NOT A BUG] Possible free shipping bug

Views: 1,132

Results 1 to 6 of 6
26 Jul 2024, 9:25 PM
#1
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,305
Plugin Contributions:
39

[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.

26 Jul 2024, 10:58 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: [NOT A BUG] 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.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

29 Jul 2024, 11:58 AM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,116
Plugin Contributions:
56

Re: [NOT A BUG] 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.

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();

    [B]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;
    }[/B]

    // 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;
}
29 Jul 2024, 2:12 PM
#4
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: [NOT A BUG] Possible free shipping bug

Nice - this way it covers all shipping methods.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

30 Jul 2024, 11:31 AM
#5
mprough avatar

mprough

Totally Zenned

Join Date:
Nov 2007
Location:
Woodbine, Georgia, United States
Posts:
4,305
Plugin Contributions:
39

Re: [NOT A BUG] Possible free shipping bug

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.

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();

[B]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;
}[/B]

// 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.

global $zco_notifier;
$override_enabled = [B]true[/B];
$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 =)
30 Jul 2024, 4:03 PM
#6
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,725
Plugin Contributions:
56

Re: [NOT A BUG] Possible free shipping bug

Your notifier needs to fire for USPS, not Free Shipping. It's USPS you want to turn on.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.