Forums / Templates, Stylesheets, Page Layout / featured sidebox add to cart/more info

featured sidebox add to cart/more info

Views: 1,363

Results 1 to 14 of 14
21 Jan 2012, 11:10 PM
#1
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

featured sidebox add to cart/more info

ok, not seeing the issue in my code, any help would be greatly appreciated.

Simply want an add to cart button & more info button unless product has attributes then just a more info button.

working great on the specials & new sidebox, also works on the featured, new & specials centerbox

code:

    if (zen_has_product_attributes($random_featured_product->fields['products_id'])) {
      // show a more link for attributes
      $lc_button1 = '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id']) . '&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) . '</a>';
    } else {
      // show an add to cart choose one or the other
      $lc_button2 = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW_SMALL, BUTTON_BUY_NOW_SMALL_ALT, 'class="sideBoxContentItemBuyNowImage"') . '</a>';
    }
22 Jan 2012, 12:02 AM
#2
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

UPDATE

After playing around with this I noticed when changing from the right column to the left column it worked fine.

Any Ideas!

22 Jan 2012, 2:38 AM
#3
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

I figured it out

22 Jan 2012, 8:42 AM
#4
athens_collectibles avatar

athens_collectibles

Zen Follower

Join Date:
May 2010
Location:
Athens, Greece
Posts:
293
Plugin Contributions:
0

Re: featured sidebox add to cart/more info

Sorry but if I understand correctly, you wanted to include an "Add to Cart" link to items in the "Featured" sidebox. You give a few lines of code asking for help and then say that it works fine.

Unless you don't want to share, is it possible to tell us which is the final code (if you changed it since your first post) and where to add it please?

Thanks in advance and have a nice day.

30 Jan 2012, 9:15 PM
#5
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

sorry, thread got lost.

what I wanted was to add an add to cart and more info button to the featured, new and specials sidebox but only wanted the more info button to show if product has attributes.

I will use the featured sidebox to keep subject within thread name

I added the following statement to:
/includes/templates/YOUR_TEMPLATE/sideboxes/tpl_featured.php

    if (zen_has_product_attributes($random_featured_product->fields['products_id'])) {
      // show a more link for attributes
      $lc_button = '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id']) . '&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) . '</a>';
    } else {
      // show an add to cart choose one or the other
      $lc_button = '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id']) . '&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) . '</a>';
      $lc_button1 = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW_SMALL, BUTTON_BUY_NOW_SMALL_ALT, 'class="sideBoxContentItemBuyNowImage"') . '</a>';
    } 

then added this:

$content .= $lc_button;
$content .= $lc_button1;

hope that makes sense and helps!

31 Jan 2012, 5:18 AM
#6
athens_collectibles avatar

athens_collectibles

Zen Follower

Join Date:
May 2010
Location:
Athens, Greece
Posts:
293
Plugin Contributions:
0

Re: featured sidebox add to cart/more info

Thank you for coming back. I hope that you will come back once more! :blush:

This is the whole of the tpl_featured.php file, a small one really.

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2011 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_featured.php 18698 2011-05-04 14:50:06Z wilt $
 */
  $content = "";
  $content .= '<div class="sideBoxContent centeredContent">';
  $featured_box_counter = 0;
  while (!$random_featured_product->EOF) {
    $featured_box_counter++;
    $featured_box_price = zen_get_products_display_price($random_featured_product->fields['products_id']);
    $content .= "\n" . '  <div class="sideBoxContentItem">';
    $content .=  '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields["products_id"]), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields["master_categories_id"]) . '&products_id=' . $random_featured_product->fields["products_id"]) . '">' . zen_image(DIR_WS_IMAGES . $random_featured_product->fields['products_image'], $random_featured_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
    $content .= '<br />' . $random_featured_product->fields['products_name'] . '</a>';
    $content .= '<div>' . $featured_box_price . '</div>';
    $content .= '</div>';
    $random_featured_product->MoveNextRandom();
  }
  $content .= '</div>' . "\n";

I tried to add your code but couldn't make it to work. I put it in various places but, unfortunately, I'm not good with PHP. Would you please spare two minutes and give me the complete code after your additions? And, would you let me know, if any extra button definitions need to be added?

I would really appreciate a reply and thank you in advance. Incidentally, I visited your interesting site but is was down for maintenance and could not explore it. I bookmarked it for another visit when it's up again.

31 Jan 2012, 8:40 PM
#7
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

this is the complete code for:
/includes/templates/YOUR_TEMPLATE/sideboxes/tpl_featured.php

<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_featured.php 17617 2010-09-25 20:13:29Z drbyte $
 * @rbarbour zcadditions alterations 2012-01-21
 */
    if (zen_has_product_attributes($random_featured_product->fields['products_id'])) {
      // show a more link for attributes
      $lc_button = '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id']) . '&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) . '</a>';
    } else {
      // show an add to cart choose one or the other
      $lc_button = '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id']) . '&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) . '</a>';
      $lc_button1 = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $random_featured_product->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW_SMALL, BUTTON_BUY_NOW_SMALL_ALT, 'class="sideBoxContentItemBuyNowImage"') . '</a>';
    }
  $content = "";
  $content .= '<div class="sideBoxContent centeredContent">';
  $featured_box_counter = 0;
  while (!$random_featured_product->EOF) {
    $featured_box_counter++;
    $featured_box_price = zen_get_products_display_price($random_featured_product->fields['products_id']);
    $content .= "\n" . '  <div class="sideBoxContentItem">';
    $content .=  '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields["products_id"]), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields["master_categories_id"]) . '&products_id=' . $random_featured_product->fields["products_id"]) . '">' . zen_image(DIR_WS_IMAGES . $random_featured_product->fields['products_image'], $random_featured_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
    $content .= '<br />' . $random_featured_product->fields['products_name'] . '</a>';
    $content .= '<div>' . $featured_box_price . '</div>';
    $content .= '<div>' . $lc_button . $lc_button1 . '</div>';
    $content .= '</div>';
    $random_featured_product->MoveNextRandom();
  }
  $content .= '</div>' . "\n";

You need an image named:
button_more_info_small.png
&
button_buy_now_small.png

Upload those images to:
/includes/templates/YOUR_TEMPLATE/buttons/english

You will need to add those buttons to your
/includes/languages/english/YOUR_TEMPLATE/button_names.php

like this:

define('BUTTON_IMAGE_BUY_NOW_SMALL', 'button_buy_now_small.png');
define('BUTTON_BUY_NOW_SMALL_ALT', 'Buy Now');
define('BUTTON_MORE_INFO_SMALL', 'button_more_info_small.png');
define('BUTTON_MORE_INFO_SMALL_ALT', 'Get More Info');

hope this helps!

31 Jan 2012, 8:48 PM
#8
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

sorry about the site being down - I am in a huge revamping process.

3 Feb 2012, 5:05 PM
#9
athens_collectibles avatar

athens_collectibles

Zen Follower

Join Date:
May 2010
Location:
Athens, Greece
Posts:
293
Plugin Contributions:
0

Re: featured sidebox add to cart/more info

Sorry for the delayed reply, I was trying to implement another add-on which took some time.

I implemented the code and the buttons appear, but...

... whatever product's button I select for "Buy" or "Info", it only links to the top product in the featured sidebox and places it in the cart or shows its description! :shocking:

Any ideas why?

PS: I'm watching your site's count down (well. not all the time).

3 Feb 2012, 9:30 PM
#10
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

$lc_button

hence

rbarbour:

I figured it out

featured side-box I had to change it to
$lc_buttonFS
$lc_buttonFS1

whats new side-box
$lc_buttonNS
$lc_buttonNS1

specials side-box
$lc_buttonSS
$lc_buttonSS1

and to get all them to work even in the centerboxes I just duplicated same code but again changed the $lc_button

featured center-box I had to change it to
$lc_buttonFC
$lc_buttonFC1

whats new center-box
$lc_buttonNC
$lc_buttonNC1

specials center-box
$lc_buttonSC
$lc_buttonSC1

4 Feb 2012, 5:12 AM
#11
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

retract-

I only have 1 featured, 1 new and 1 special product side-box

you are correct when I changed it to three products the buttons picked up the first products id.

I will play with it a little

4 Feb 2012, 9:23 AM
#12
athens_collectibles avatar

athens_collectibles

Zen Follower

Join Date:
May 2010
Location:
Athens, Greece
Posts:
293
Plugin Contributions:
0

Re: featured sidebox add to cart/more info

I'll watch to see if you come up with something. You certainly know more than me!

6 Feb 2012, 2:43 AM
#13
rbarbour avatar

rbarbour

Totally Zenned

Join Date:
Feb 2010
Posts:
2,159
Plugin Contributions:
10

Re: featured sidebox add to cart/more info

this is the complete code for:
/includes/templates/YOUR_TEMPLATE/sideboxes/tpl_featured.php

and it works with multiple products activated for the features sidebox

<?php /**  * Side Box Template  *  * @package templateSystem  * @copyright Copyright 2003-2010 Zen Cart Development Team  * @copyright Portions Copyright 2003 osCommerce  * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0  * @version $Id: tpl_featured.php 17617 2010-09-25 20:13:29Z drbyte $  * @rbarbour zcadditions alterations 2012-01-21  */        

$content = "";   
$content .= '<div class="sideBoxContent centeredContent">';   $featured_box_counter = 0;   while (!$random_featured_product->EOF) {     $featured_box_counter++;     $featured_box_price = zen_get_products_display_price($random_featured_product->fields['products_id']);     $content .= "\n" . '  <div class="sideBoxContentItem">';     $content .=  '<a href="' . zen_href_link(zen_get_info_page($random_featured_product->fields["products_id"]), 'cPath=' . zen_get_generated_category_path_rev($random_featured_product->fields["master_categories_id"]) . '&products_id=' . $random_featured_product->fields["products_id"]) . '">' . zen_image(DIR_WS_IMAGES . $random_featured_product->fields['products_image'], $random_featured_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);     $content .= '<br />' . $random_featured_product->fields['products_name'] . '</a>';     $content .= '<div>' . $featured_box_price . '</div>';
if (zen_has_product_attributes($random_featured_product->fields['products_id'])) {
$content .= '<div>' . '<a href="' .  zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']),  'cPath=' .  zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id'])  . '&products_id=' .  $random_featured_product->fields['products_id']) . '">' .  zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) .  '</a></div>';
} else {
$content .= '<div>' . '<a href="' .  zen_href_link(zen_get_info_page($random_featured_product->fields['products_id']),  'cPath=' .  zen_get_generated_category_path_rev($random_featured_product->fields['master_categories_id'])  . '&products_id=' .  $random_featured_product->fields['products_id']) . '">' .  zen_image_button(BUTTON_MORE_INFO_SMALL, BUTTON_MORE_INFO_SMALL_ALT) .  '</a><a href="' . zen_href_link($_GET['main_page'],  zen_get_all_get_params(array('action')) .  'action=buy_now&products_id=' .  $random_featured_product->fields['products_id']) . '">' .  zen_image_button(BUTTON_IMAGE_BUY_NOW_SMALL, BUTTON_BUY_NOW_SMALL_ALT,  'class="sideBoxContentItemBuyNowImage"') . '</a></div>';
}
$content .= '</div>';     
$random_featured_product->MoveNextRandom();   
}   
$content .= '</div>' . "\n"; 
6 Feb 2012, 8:30 AM
#14
athens_collectibles avatar

athens_collectibles

Zen Follower

Join Date:
May 2010
Location:
Athens, Greece
Posts:
293
Plugin Contributions:
0

Re: featured sidebox add to cart/more info

Thank you, the new code in your post #13 works perfectly now. I have implemented it on the live store (link in signature) both in English and Greek pages.

Looking forward to your new upgraded site, although I will be away from the computer and will see it after the 23rd of February.

Kind regards and thanks again! :D