Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default How to refresh shopping cart page?

    I have a requirement to prohibit a certain group of customers from purchasing one or more specific products. I've seen the add-on which effectively hides the category and/or products from a specified customer group. But I have had problems setting up a development branch to integrate the add-on. So I decided to work on an extra cart action that removes the prohibited products from a customers cart and displays a message on the shopping cart page telling them that the product(s) will not be added to the cart. The shopping cart page should remain displayed with the prohibited products not displayed in the cart, and with updated subtotal price.

    I have used the shopping cart class method "remove(product_id)" and while notifier trace tells me that the remove method is executed for the prohibited products, and the warning message is displayed, the products remain displayed on the shopping cart page when multiple prohibited products are selected from the product listing page. There are no php errors logged. I think that, even though the products have been removed, the page display has not been updated to reflect the current cart contents. How can I refresh the shopping cart display? I'll admit there could be reasons for the problem other than no cart refresh. The code to call the remove method is:
    Code:
    $_SESSION['cart']->remove($pid);
    Anyone's help is greatly appreciated!

    Dave

    zc155f, php7.1.x, heavy customization

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: How to refresh shopping cart page?

    I recommend calling actionRemoveProduct() instead. You can see an example of it in main_cart_actions.php

    When it's finished it will refresh the page with the updated data.

    Code, circa 1.5.5:
    https://github.com/zencart/zencart/b...hp#L2205-L2207


    If you have multiple products to handle, then go ahead with calling remove() on them in a loop, and then call actionRemoveProduct ... or just do the same redirect that it does.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: How to refresh shopping cart page?

    Thank you DrByte! Works great. I have one more minor problem. When I add one prohibited item to an empty cart, that the extra cart action removes, the message I want displayed doesn't appear on the empty cart page using $messageStack->add_session('shopping_page',...). I got around that by using $messageStack->add_session('header',...) which displays the message at the top of the empty cart page. But I would prefer the message be displayed in the center column. I also tried $messageStack->add('shopping_cart',...), but that didn't help. Everything works perfectly if there are other items in the cart.

    How can I get the message to display in the center column on the empty cart page?

    Thank you.
    Dave

  4. #4
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,488
    Plugin Contributions
    88

    Default Re: How to refresh shopping cart page?

    Quote Originally Posted by Dave224 View Post
    Thank you DrByte! Works great. I have one more minor problem. When I add one prohibited item to an empty cart, that the extra cart action removes, the message I want displayed doesn't appear on the empty cart page using $messageStack->add_session('shopping_page',...). I got around that by using $messageStack->add_session('header',...) which displays the message at the top of the empty cart page. But I would prefer the message be displayed in the center column. I also tried $messageStack->add('shopping_cart',...), but that didn't help. Everything works perfectly if there are other items in the cart.

    How can I get the message to display in the center column on the empty cart page?

    Thank you.
    Dave
    For whatever reason, the as-shipped tpl_shopping_cart_default.php doesn't invoke the messageStack on an empty cart. Find this section (starting on line 181 for the zc157 template_default version):
    Code:
    <?php
      } else {
    ?>
    
    <h2 id="cartEmptyText"><?php echo TEXT_CART_EMPTY; ?></h2>
    
    <?php
    $show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY);
    
    while (!$show_display_shopping_cart_empty->EOF) {
    ?>
    ... and add the message-stack display:
    Code:
    <?php
      } else {
    ?>
    
    <h2 id="cartEmptyText"><?php echo TEXT_CART_EMPTY; ?></h2>
    <?php if ($messageStack->size('shopping_cart') > 0) echo $messageStack->output('shopping_cart'); ?>
    <?php
    $show_display_shopping_cart_empty = $db->Execute(SQL_SHOW_SHOPPING_CART_EMPTY);
    
    while (!$show_display_shopping_cart_empty->EOF) {
    ?>

  5. #5
    Join Date
    Jan 2004
    Location
    N of San Antonio TX
    Posts
    9,149
    Plugin Contributions
    11

    Default Re: How to refresh shopping cart page?

    If you are using responsive_classic or a clone of it, the line number is 209 for the responsive_classic version of the tpl_shopping_cart_default.php in 1.5.7.

 

 

Similar Threads

  1. v151 unnecessary refresh button on shopping cart page
    By barricades in forum General Questions
    Replies: 3
    Last Post: 21 May 2014, 06:14 PM
  2. Replies: 0
    Last Post: 18 Jun 2012, 01:02 AM
  3. Shopping Cart Refresh / Update Image too large
    By Jim21 in forum General Questions
    Replies: 3
    Last Post: 10 Jul 2011, 12:35 PM
  4. Revise Shopping Cart Contents and Refresh Quantity
    By limelites in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 5 Feb 2009, 10:28 AM
  5. [not a bug] refresh button on shopping cart page
    By cjmarley in forum Bug Reports
    Replies: 1
    Last Post: 4 Dec 2006, 03:06 AM

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