Zen Cart Logo
Forums / All Other Contributions/Addons / Shoppingcart/Freeship in Header support

Shoppingcart/Freeship in Header support

Views: 19,391

Results 141 to 160 of 181
21 Dec 2012, 17:35
#141
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Shoppingcart/Freeship in Header support

First off, you need to address the product data with the right number of fields: not
$cart_header_products['linkProductsName']
but
$cart_header_products[$item]['linkProductsName']
so you can output each item's data in turn.
You need to use class= and not id= for the tags, since they will be repeated.
You need to iterate through the products, as the foreach in your previous post did. Foreach has complex behavior that can make it hard to use right without some testing on the particular subject; a simple for() statement will be more reliable here even if it is theoretically less efficient.
The code posted is a mixture of HTML with PHP insertions, and PHP with HTML output strings. It would be clearer to go to all one style, as shown below.

$cart_header_products = $_SESSION['cart']->get_products();
for ($item=0; $item<sizeof($cart_header_products); $item++) {
  echo '<a href="' . $cart_header_products[$item]['linkProductsName'] . '"><span class="cartImage" class="back">' . $cart_header_products[$item]['productsImage'] . '</span><span class="cartProdTitle">' . $cart_header_products[$item]['productsName'] . '<span class="alert bold">' . $cart_header_products[$item]['flagStockCheck'] . '</span></span></a>' . "\n";
}
03 Jan 2013, 02:23
#142
jackolive avatar

jackolive

New Zenner

Join Date:
Apr 2012
Location:
California
Posts:
21
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Glenn,

I tried using the code that you provided but I couldn't get it to work. Can you be more specific about what needs to be done? I'm sure that you provided the information necessary, but I am not well versed in php.

Can you include the entire code that needs to be installed and where? Or could I add this to a wish list for Shoppingcart/Freeship in Header plugin?

I want to show the product name and product image below the "Shopping Cart" header and above the Sub-Total in the dropdown. I would like to add the quantity of the individual product also if possible.

Your plugin works great. I do have it installed, but it would be more functional and look better with the product name and image displayed. Check it out on my site www.4twentee.com (add a product to the shopping cart first and hover over the Shopping Cart menu tab). I understand that the plugin is designed to display in the header or sidebox, and this added function would not fit well.

Thanks again for answering my posts.

03 Jan 2013, 04:27
#143
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Seeing the way you want to display this, it makes more sense. The usual header location would not hold a variable number of item displays comfortably, but the dropdown from the tab will.
Try this (adding the part between // products comments) ```php

  • /includes/templates/your_template/templates/tpl_cart_header.php
  • Shoppingcart/Freeship in Header - Glenn Herbert (gjh42) - 2012-11-20 ========== modified to show products 20130102
    */
    $cart_count = $_SESSION['cart']->count_contents();
    ?>
<div id="cartHeader"> <h3><?php echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . CART_HEADER_TITLE . '</a>':CART_HEADER_TITLE); ?></h3> <div id="cartCount"> <?php if ($cart_count) { //bof products $cart_header_products = $_SESSION['cart']->get_products(); define('CART_PRODUCT_QTY_PRE', ' (');//put in cart_header_defines.php define('CART_PRODUCT_QTY_POST', ') ');//put in cart_header_defines.php echo '<div id="cartProducts">'; for ($item=0; $item<sizeof($cart_header_products); $item++) { echo '<a href="' . $cart_header_products[$item]['linkProductsName'] . '"><span class="cartProdImage">' . $cart_header_products[$item]['productsImage'] . '</span><span class="cartProdQty">' . CART_PRODUCT_QTY_PRE . $cart_header_products[$item]['quantityField'] . CART_PRODUCT_QTY_POST . '</span><span class="cartProdTitle">' . $cart_header_products[$item]['productsName'] . '<span class="alert bold">' . $cart_header_products[$item]['flagStockCheck'] . '</span></span></a>' . "\n"; } echo '</div>'; //eof products //$_SESSION['cart']->get_products(); //?not needed after products code? $basket_total = $_SESSION['cart']->show_total(); ```
03 Jan 2013, 04:54
#144
jackolive avatar

jackolive

New Zenner

Join Date:
Apr 2012
Location:
California
Posts:
21
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Glenn,

I added the code but the product name and image are not displaying. All that is showing is this "()" and it links to the index page. I will leave the code in so you can see what it is doing.

Do I have to define these?

define('CART_PRODUCT_QTY_PRE', ' (');//put in cart_header_defines.php
define('CART_PRODUCT_QTY_POST', ') ');//put in cart_header_defines.php

The entire code that I have in tpl_cart_header.php is below. I don't know how to add code to the forum like you did above. Is there a button to do that?

<?php /** * tpl_cart_header.php * @copyright Copyright 2012 Glenn Herbert * @copyright Portions Copyright 2003-2006 Zen Cart Development Team * @copyright Portions Copyright 2003 osCommerce * @license <http://www.gnu.org/licenses/> GNU Public License V3.0 * /includes/templates/your_template/templates/tpl_cart_header.php * Shoppingcart/Freeship in Header - Glenn Herbert (gjh42) - 2012-11-20 */ $cart_count = $_SESSION['cart']->count_contents(); ?> <div id="cartHeader"> <h3><?php echo ($cart_count? '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . CART_HEADER_TITLE . '</a>':CART_HEADER_TITLE); ?></h3> <div id="cartCount"> <?php if ($cart_count) { $cart_header_products = $_SESSION['cart']->get_products(); define('CART_PRODUCT_QTY_PRE', ' (');//put in cart_header_defines.php define('CART_PRODUCT_QTY_POST', ') ');//put in cart_header_defines.php echo '<div id="cartProducts">'; for ($item=0; $item<sizeof($cart_header_products); $item++) { echo '<a href="' . $cart_header_products[$item]['linkProductsName'] . '"><span class="cartProdImage">' . $cart_header_products[$item]['productsImage'] . '</span><span class="cartProdQty">' . CART_PRODUCT_QTY_PRE . $cart_header_products[$item]['quantityField'] . CART_PRODUCT_QTY_POST . '</span><span class="cartProdTitle">' . $cart_header_products[$item]['productsName'] . '<span class="alert bold">' . $cart_header_products[$item]['flagStockCheck'] . '</span></span></a>' . "\n"; } echo '</div>'; $basket_total = $_SESSION['cart']->show_total(); echo '<span id="cartTotal">' . CART_HEADER_TOTAL . $currencies->format($basket_total) . '</span><br /> ' ; } echo ($cart_count? '':'') . CART_HEADER_IN_CART_PRE . $cart_count . (($cart_count == 1)? CART_HEADER_IN_CART_SINGULAR: CART_HEADER_IN_CART_PLURAL) . ($cart_count? '': ''); ?> </div> <?php if ($cart_count) { echo '<div class="buttonRow back"><a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_VIEW_CART, BUTTON_VIEW_CART_ALT) . '</a></div>'; echo '<div class="buttonRow forward"><a href="' . zen_href_link(FILENAME_CHECKOUT_SHIPPING, '', 'SSL') . '">' . zen_image_button(BUTTON_IMAGE_CHECKOUT, BUTTON_CHECKOUT_ALT) . '</a></div>'; } ?> </div>
03 Jan 2013, 05:50
#145
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

The code is executing properly, except that the array fields are empty. Let's try some debugging to see exactly what is there...
Add after this line
$cart_header_products = $_SESSION['cart']->get_products();

var_dump($cart_header_products);//debug

Once the code is working, the defines ought to move to the file mentioned for orderliness. It doesn't matter now.

03 Jan 2013, 07:41
#146
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

I have done this on my local test site, and find that the array field names are quite different from the ones in your transplanted code snippet that I started from. The relevant fields: ```
$cart_header_products = $_SESSION['cart']->get_products();
//relevant fields
["id"]=> int(19)
["category"]=> string(2) "12"
["name"]=> string(35) "There's Something About Mary Linked"
["image"]=> string(35) "dvd/theres_something_about_mary.gif"
["quantity"]=> int(1)

03 Jan 2013, 07:47
#147
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

The shopping cart page was apparently using its own array to hold this info and much more, with its own terminology, which does not match the terminology used in the $_SESSION content. At any rate, we're on the way...

03 Jan 2013, 08:41
#148
jackolive avatar

jackolive

New Zenner

Join Date:
Apr 2012
Location:
California
Posts:
21
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

I am sure that you already know this, I just want to let you know I am here doing what I can. Mostly inserting the code that you are providing and testing what happens.

This is what the dropdown is showing after adding this code, var_dump($cart_header_products);//debug.

array(1) { [0]=> array(17) { ["id"]=> string(34) "3:4f4ef1da0c407f06362a1c6ae9652e3b" ["category"]=> string(1) "2" ["name"]=> string(19) ""Shirt of the Week"" ["model"]=> string(0) "" ["image"]=> string(11) "sow/sow.jpg" ["price"]=> string(7) "10.0000" ["quantity"]=> int(1) ["weight"]=> int(1) ["final_price"]=> float(10) ["onetime_charges"]=> int(0) ["tax_class_id"]=> string(1) "1" ["attributes"]=> array(2) { [1]=> int(1) [2]=> int(4) } ["attributes_values"]=> string(0) "" ["products_priced_by_attribute"]=> string(1) "0" ["product_is_free"]=> string(1) "0" ["products_discount_type"]=> string(1) "0" ["products_discount_type_from"]=> string(1) "0" } }

()

03 Jan 2013, 09:07
#149
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Edit /includes/templates/your_template/templates/tpl_cart_header.php.
After
if ($cart_count) {
around line 17, replace the
$_SESSION['cart']->get_products();
with the following```php
//bof products
$cart_header_products = $_SESSION['cart']->get_products();
echo '<div id="cartProducts">';
for ($item=0; $item<sizeof($cart_header_products); $item++) {
echo '<a href="' . zen_href_link(zen_get_info_page($cart_header_products[$item]['id']), 'products_id=' . $cart_header_products[$item]['id']) . '"><span class="cartProdImage">' . zen_image(DIR_WS_IMAGES . $cart_header_products[$item]['image']) . '</span><span class="cartProdQty">' . CART_PRODUCT_QTY_PRE . $cart_header_products[$item]['quantity'] . CART_PRODUCT_QTY_POST . '</span><span class="cartProdTitle">' . $cart_header_products[$item]['name'] . '</span></a>' . "\n";
}
echo '</div>';
//eof products

Edit /includes/languages/english/extra_definitions/your_template/cart_header_defines.php
and add```php
define('CART_PRODUCT_QTY_PRE', ' (');//products display
define('CART_PRODUCT_QTY_POST', ') ');//products display
``` Adjust the defines as desired.
  
You can style 
.cartProdImage ()
.cartProdQty ()
.cartProdTitle ()
in your stylesheet as desired for your layout.
03 Jan 2013, 21:04
#150
jackolive avatar

jackolive

New Zenner

Join Date:
Apr 2012
Location:
California
Posts:
21
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Glenn,

I'm dialing it in. I have it set up but need help with one thing. The product image is too big. I would like to use the image (size) from the shopping cart. I tried inserting "productsImage" but it didn't quite work. It was displaying the proper size, but the image was not showing.

You can see what I've got so far. I rearranged some items. I will post all of the code and css that I have after we have it all set.

03 Jan 2013, 21:15
#151
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

There are parameters you can add to zen_image() to specify the size... I will have to look up an example. I have other stuff to do now - be back later.

04 Jan 2013, 01:44
#152
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

The image code used in the shopping cart page:```php
zen_image(DIR_WS_IMAGES . $products[$i]['image'], $products[$i]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT)

You could apply it in the cart header as ```php
zen_image(DIR_WS_IMAGES . $cart_header_products[$item]['image'], $cart_header_products[$item]['name'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT)
04 Jan 2013, 20:06
#153
jackolive avatar

jackolive

New Zenner

Join Date:
Apr 2012
Location:
California
Posts:
21
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Glenn,

Your'e a Rock Star!

It works great. The shopping cart image was a little too big so I substituted SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT. Check out my site.

This is exactly what I was hoping for. Now that it is dialed in, I have a few more questions.

Is there a way to limit the number of products to display in the dropdown? I make my sites on an HP laptop. If I place more than 5 products in the shopping cart the dropdown reaches the bottom of the screen. If I add 6 or more products to the shopping cart the dropdown extends below the screen and the checkout button is not visible. Is there a way to limit the array(?) to four products and create a fifth item or output that says "More..."?

Can you help with adding the product attributes? I looked at the shopping cart to see how it is done, but cannot figure out how to adapt it to your plugin.

Thanks again!

09 Jan 2013, 15:21
#154
kman55 avatar

kman55

New Zenner

Join Date:
Feb 2011
Location:
Washington, D.C.
Posts:
80
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Hi Glenn & JackOlive

I was following your conversations as I was looking to do exactly what jackolive was doing. Thank you Glenn for the solution that you have provided jackolive as it helped me as well. I was able to get an image of the product in the shopping cart drop down that I created, however - when I add more than 1 product and try to hover over the shopping cart link on the menu, the images and product titles, prices etc. are all over the place. Is there a way in CSS to control multiple products to display side by side? I tried searching on these forums as well as google but I can't seem to figure it out. Any help or direction will be appreciated.

Edited: I can't seem to provide the link to my production site as it is being built to sell adult novelties. If either of you can help, I can PM you the site link.

09 Jan 2013, 18:27
#155
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Is it not the site in your sig? If the forum obfuscates the actual link text, you can add spaces to break up the words.

It should be possible to alter the layout with CSS to fit whatever you want; some rearrangements may require moving PHP code to change output order.

09 Jan 2013, 19:08
#156
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Is there a way to limit the number of products to display in the dropdown? Yes, you can add a bit inside the for() loop.

  //bof products
  $cart_header_products = $_SESSION['cart']->get_products();
  echo '<div id="cartProducts">';
  for ($item=0; $item<sizeof($cart_header_products); $item++) {
    echo '<a href="' . zen_href_link(zen_get_info_page($cart_header_products[$item]['id']), 'products_id=' . $cart_header_products[$item]['id']) . '"><span class="cartProdImage">' . zen_image(DIR_WS_IMAGES . $cart_header_products[$item]['image'], IMAGE_SHOPPING_CART_WIDTH, IMAGE_SHOPPING_CART_HEIGHT) . '</span><span class="cartProdQty">' . CART_PRODUCT_QTY_PRE . $cart_header_products[$item]['quantity'] . CART_PRODUCT_QTY_POST . '</span><span class="cartProdTitle">' . $cart_header_products[$item]['name'] . '</span></a>' . "\n";
    if ($item >= 3) { //adjust to suit
      echo '<a href="' . zen_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . CART_HEADER_MORE . '</a>';
      $item = sizeof($cart_header_products);
    }
  }  
  echo '</div>';
  //eof products  
``` Add to your define file ```php
define('CART_HEADER_MORE', 'More...');

Tested on my local site.

09 Jan 2013, 19:32
#157
kman55 avatar

kman55

New Zenner

Join Date:
Feb 2011
Location:
Washington, D.C.
Posts:
80
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

gjh42:

Is it not the site in your sig? If the forum obfuscates the actual link text, you can add spaces to break up the words.

It should be possible to alter the layout with CSS to fit whatever you want; some rearrangements may require moving PHP code to change output order.

Hi Glenn
The site in my signature is all set. I'm working on a new site for myself where I'm trying to add this functionality. The new site where I'm having this issue can be seen at www dot just - d i l d o.com / zencart. ** NOTE ** Site is being designed to sell adult novelty items.

09 Jan 2013, 20:13
#158
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Shoppingcart/Freeship in Header support

Add to your stylesheet

#cartProducts>a {display: block; float: left; max-width: 12em; margin-right: 1em;}
09 Jan 2013, 20:57
#159
kman55 avatar

kman55

New Zenner

Join Date:
Feb 2011
Location:
Washington, D.C.
Posts:
80
Plugin Contributions:
0

Re: Shoppingcart/Freeship in Header support

Wow. Thank you for the quick response and solution.