How do I add an "add to cart " button to the front page in featured products
How do I add an "add to cart " button to the front page in featured products
This might help you, i'm not sure. good luck.
$disc_prod_image_id = " product id number"
$lc_button = '<a href="'.zen_href_link($_GET['main_page'],zen_get_all_get_params(array('action')).'action=buy_now&products_id='.$disc_pro d_image_id).'">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>';
echo $lc_button;
You will need to clean up the look of this, but the peices and parts are here and the logic for working with the featured products centerbox and adding either a buy now button or the add to cart with quantity box, plus the more info for products with attributes ...
PHP Code:if (zen_has_product_attributes($featured_products->fields['products_id'])) {
// show a more link for attributes
$lc_button = '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . ( ($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : $_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id'])) . '&products_id=' . $featured_products->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
$lc_button2 = '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . ( ($_GET['manufacturers_id'] > 0 and $_GET['filter_id']) > 0 ? zen_get_generated_category_path_rev($_GET['filter_id']) : $_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id'])) . '&products_id=' . $featured_products->fields['products_id']) . '">' . MORE_INFO_TEXT . '</a>';
} else {
// show an add to cart choose one or the other
$lc_button = '<a href="' . zen_href_link($_GET['main_page'], zen_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $featured_products->fields['products_id']) . '">' . zen_image_button(BUTTON_IMAGE_BUY_NOW, BUTTON_BUY_NOW_ALT, 'class="listingBuyNowButton"') . '</a>';
$lc_button2= zen_draw_form('cart_quantity', zen_href_link(zen_get_info_page($featured_products->fields['products_id']), zen_get_all_get_params(array('action')) . 'action=add_product&products_id=' . $featured_products->fields['products_id']), 'post', 'enctype="multipart/form-data"') . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($featured_products->fields['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_draw_hidden_field('products_id', $featured_products->fields['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT) . '</form>';
}
$list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => (($featured_products->fields['products_image'] == '' and PRODUCTS_IMAGE_NO_IMAGE_STATUS == 0) ? '' : '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . zen_image(DIR_WS_IMAGES . $featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) . '</a><br />') . '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'cPath=' . $productsInCategory[$featured_products->fields['products_id']] . '&products_id=' . $featured_products->fields['products_id']) . '">' . $featured_products->fields['products_name'] . '</a><br />' . $products_price . '<br />' . $lc_button . '<br />' . $lc_button2);
Linda McGrath
If you have to think ... you haven't been zenned ...
Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
The code I gave you has 2 ways to do the button ...
You can have the buy now button or the add to cart button with a quantity box ...
You need to include the code you want or don't want from what I gave you ...
I used $lc_button1 and $lc_button2 for this code ...
Linda McGrath
If you have to think ... you haven't been zenned ...
Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!
Ajeh - This is a powerful, powerful much needed code addition for me. Thank you very much.
A question for you - On the front site of my cart, when an "add to cart" button is clicked for a product (even a product without attributes), the item amount is added to the cart successfully, but the user is redirected to the category listing page. From what I've learned, this is how Zen Cart is designed to function.
I need to have a user stay on whatever page they are already on when they click an "add to cart button," rather than being redirected to the category or product info page (as Zen Cart now does). The whole idea is to give the user control of their cart experience, rather than redirecting them unnecessarily to another page (which I think will confuse more people than help them).
I customized much of the code for the "add to cart" buttons already, but can't figure out how to prevent this redirect (no help yet in other places on the Zen Cart forums). If you go the main page of my test site, you will see products with "add to cart" buttons.
http://www.sarasotafarms.org/biz/
I'm getting more familiar with the Zen Cart php pages, but I cannot seem to find where this redirect is occurring in the code. Once I find this, I guess the next step will be altering the code to prevent the redirect. I'm not great at php, but I understand it enough to make minor adjustments and add snippets.
I once was using oscommerce, which I've heard Zen Cart was partially created from. In oscommerce, it was easy to adjust the code to prevent the "add to cart" button from redirecting to a category page (the user would stay on the same page after a brief refresh).
Anyway, any suggestions greatly appreciated.
I'd look to change the module for the featured_products.php ...![]()
Linda McGrath
If you have to think ... you haven't been zenned ...
Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!
Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here
Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!