Probing the Cart on the Product Info page
Relevance: Zen Cart™ 1.3.0.* and forward
Cost: Free, but
donation appreciated
It is possible to check the current contents of the customer's cart when
generating the product info page. This allows you to do things like
hiding or showing options, issuing customized messages, etc.
We'll illustrate this by showing how to hide the "add to cart"
button for product 27 when product 60 is not in the cart.
We will also make the page hardcode an obnoxious blinking message -
something you should not really do - just to demonstrate
the approach. (You will want a nicely formatted message in a
language file using CSS styling, etc.)
Create your custom template
if you haven't already done so.
Customize the product_info page. Assuming your template is called "custom," copy
includes/templates/template_default/templates/tpl_product_info_display.php
to
includes/templates/custom/templates
and change
<!--bof Add to Cart Box -->
<?php
if (CUSTOMERS_APPROVAL == 3 and TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM == '') {
// do nothing
} else {
to
<!--bof Add to Cart Box -->
<?php
$show_add_button = 1;
if ((int)$_GET['products_id'] == 27) {
$show_add_button = 0;
$check_prod_list = $_SESSION['cart']->get_products();
for ($i=0, $n=sizeof($check_prod_list); $i<$n; $i++) {
if (zen_get_prid($check_prod_list[$i]['id']) == 60) {
$show_add_button = 1;
}
}
}
if (CUSTOMERS_APPROVAL == 3 and TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM == '') {
// do nothing
} else if ($show_add_button == 0) {
// Warn the user
echo "<div align='right'><blink>Please put item 60 in your cart!</blink></div>";
} else {
This tip
was first submitted to the Zen Cart Support Forum
in this thread
on September 29, 2006.
For a more global look at cart validation, take a look at
Valid Cart.
| Certificates of appreciation most welcome! |
|
|
If the information you learned reading this site is helping your store make
more money, please consider making a donation. Thank you!
|
Want more Zen Cart?
Tips and Tricks
Contributions
Extensions
Custom Software
Newsletter