Thread: ZC 1.5.5f

Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2010
    Location
    Israel
    Posts
    285
    Plugin Contributions
    0

    Default ZC 1.5.5f

    Hi all :)
    On a site that I upgraded from 1.5.4 / PHP 5.6 to 1.5.5f / PHP 7 some codes stopped working
    without any error.
    Any old code I should change in the following code ?
    Code:
        if (!IS_ADMIN_FLAG) {
            global $cart;
            $chk_products_in_cart += $_SESSION['cart']->in_cart_check('master_categories_id', '78');
    		$chk_products_in_cart += $_SESSION['cart']->in_cart_check('master_categories_id', '79');
    		$chk_products_in_cart += $_SESSION['cart']->in_cart_check('products_id', '340'); 
            // do not deliver to cities 1001-1007
            $chk_delivery_zone = $order->delivery['zone_id'];
            $chk_states = '1001, 1002, 1003, 1004, 1005, 1006, 1007';
            $arr1 = explode(", ", $chk_states);
            $arr2 = explode(", ", $chk_delivery_zone);
            $donotshow_state = array_intersect($arr1, $arr2);
            if ((int)$donotshow_state && $chk_products_in_cart > 0) {
              $this->enabled = false;
            }
          }
    The code if for restricting some products to some cities.

    Thanks

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,478
    Plugin Contributions
    88

    Default Re: ZC 1.5.5f

    Where is the $chk_products_in_cart variable initialized? That might be the issue?

  3. #3
    Join Date
    Aug 2010
    Location
    Israel
    Posts
    285
    Plugin Contributions
    0

    Default Re: ZC 1.5.5f

    I found at freeshipper.php ZC1.5.4 the code of $chk_products_in_cart = 0;
    But how could this help ?
    Maybe the $chk_products_in_cart has a new variable @ZC1.5.5 ?

  4. #4
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,684
    Plugin Contributions
    123

    Default Re: ZC 1.5.5f

    One thing I noticed is that you did a global on $cart (which is unused) but not $order (which is used).
    I agree with @lat9 that it would be good to initialize $chk_products_in_cart. (Do it right below the check for IS_ADMIN_FLAG.)
    That Software Guy. My Store: Zen Cart Modifications
    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.

  5. #5
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: ZC 1.5.5f

    Quote Originally Posted by gunni View Post
    I found at freeshipper.php ZC1.5.4 the code of $chk_products_in_cart = 0;
    But how could this help ?
    Maybe the $chk_products_in_cart has a new variable @ZC1.5.5 ?
    No, the difference in operation between what you have seen in ZC 1.5.4 and 1.5.5 would be best explained by a change in php version.

    Older php versions, were more forgiving. If you didn't initialize a variable, then php would sort of figure it out in its own way.

    This was good and bad. Good because it made it easier for others to just try to make something work, bad in that it could result in problems to take advantage of.

    Anyways, the fact that $chk_products_in_cart was initialized (=) rather than added to (+=) somewhere else, means that it likely was of no help in the current module. In fact if that other module were listed before this one then that could further cause issues with this module if it doesn't control the value itself at the time it needs the value.

    Part of making a variable available at the right time is using the global statement. Swguy was pointing out that the cart variable (which really the cart is maintained as a session) is shown to be global. Towards the end of the code posted, the order variable is used; however, we do not see how the $order variable has been made available. It could be that after fixing the addition to a non-defined variable issue is addressed that we will see a post about that issue as well... right now it looks like the last if statement about checking states will never set the enabled flag to false because $order->delivery['zone_id'] will equal a falsey value (0, null, '') such that $donotshow_state will always be false.

    Does that make sense? Of course those of us looking through the forum site can only comment on what has been provided/described or in some cases directly seen.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  6. #6
    Join Date
    Aug 2010
    Location
    Israel
    Posts
    285
    Plugin Contributions
    0

    Default Re: ZC 1.5.5f

    As suggested by you all, adding $chk_products_in_cart = 0; solved the mystery.
    It was not there in ZC1.5.4/PHP5.6 and worked fine.
    Now I understand that PHP 7 is not forgiving as previous versions and this is the reason.
    Thank you all again

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR