Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Display Shopping Cart Count

    I'd like to display the amount of items in the shopping cart on the top of my webpage.

    Code:
    <?php if ($_SESSION['cart']->count_contents() != 0) { ?>
                    <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>">
    <?php echo HEADER_TITLE_CART_CONTENTS; ?><?php echo ' (' . $shopcartdisplay . ' items)'; ?></a>&nbsp;|&nbsp;<a href="<?php echo zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>"><?php echo HEADER_TITLE_CHECKOUT; ?>&raquo;</a>
                  <?php }?>
    
    <?php if ($_SESSION['cart']->count_contents() == 0) { ?>
                    <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>">
    <?php echo HEADER_TITLE_CART_CONTENTS; ?> (0 items)</a>&nbsp;|&nbsp;<a href="<?php echo zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>"><?php echo HEADER_TITLE_CHECKOUT; ?>&raquo;</a>
                  <?php }?>
    This is what I attempted to do and it works but it doesn't seem to efficient. I am fairly new to php so I don't know efficient ways to code with correct syntax. Hopefully someone can help me reorganize this...

    Basiclly, when theres no items I want it to display (0 items) and when there are items I want it to display (5 items)

    ---------------

    I noticed when there is no item, the printout turns out to be ( items) and it doesn't print out the 0, that is why i had to manually text it out.

  2. #2
    Join Date
    May 2004
    Location
    Hong Kong
    Posts
    1,291
    Plugin Contributions
    1

    Default Re: Display Shopping Cart Count

    Take a look of the following topic.

    micro Shopping Cart - Zen Cart Support
    A New Starter again

  3. #3
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Re: Display Shopping Cart Count

    wow haha, dunno why i didn't try just removing the if else statements and just use the code directly lolz..


    heres the code if anyones interested
    Code:
     <a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>">
    <?php echo HEADER_TITLE_CART_CONTENTS; ?><?php echo ' (' . $_SESSION['cart']->count_contents() . ' items)'; ?></a>&nbsp;|&nbsp;<a href="<?php echo zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL'); ?>"><?php echo HEADER_TITLE_CHECKOUT; ?>&raquo;</a>

    thanks for the help

  4. #4
    Join Date
    Nov 2004
    Posts
    80
    Plugin Contributions
    0

    Default Re: Display Shopping Cart Count

    And if you want it to get the item/items part right, use this:

    Code:
        <li><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><?php echo HEADER_TITLE_CART_CONTENTS; ?><?php echo ' (' . $_SESSION['cart']->count_contents(); ?><?php if ($_SESSION['cart']->count_contents() != 1) { echo ' items)'; } else { echo ' item)'; } ?></a></li>

  5. #5
    Join Date
    May 2006
    Posts
    13
    Plugin Contributions
    0

    Default Re: Display Shopping Cart Count

    wow thanks, little detail that makes it even better haha. I really need to learn basics of php, but i figure i'm learning by modifing codes... kinda how i learned html that way.

    heres a slight correction from "1" to "0"


    <li><a href="<?php echo zen_href_link(FILENAME_SHOPPING_CART, '', 'NONSSL'); ?>"><?php echo HEADER_TITLE_CART_CONTENTS; ?><?php echo ' (' . $_SESSION['cart']->count_contents(); ?><?php if ($_SESSION['cart']->count_contents() != 0) { echo ' items)'; } else { echo ' item)'; } ?></a></li>
    wasn't shifting correct but definetly thank you =D

 

 

Similar Threads

  1. v154 Removing, weight and item count on shopping cart screen
    By resqjoc in forum General Questions
    Replies: 1
    Last Post: 29 Jan 2015, 12:20 AM
  2. shopping cart count in header showing link
    By tod4life in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 17 Aug 2014, 03:03 PM
  3. Add shopping cart count to the header.
    By markpr9 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 15 Apr 2009, 01:37 AM
  4. Shopping Cart wont display after adding product to cart
    By fmf_tactical in forum General Questions
    Replies: 2
    Last Post: 6 Mar 2009, 03:43 AM
  5. cart sidebox item count (not total count)
    By mrmarcus66 in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 11 Nov 2006, 01:01 AM

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