Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Hide Add To Cart box if mod shows on Product Page

Hide Add To Cart box if mod shows on Product Page

Locked

Views: 897

Results 1 to 9 of 9
This thread is locked. New replies are disabled.
8 Nov 2009, 6:05 PM
#1
ryanb4614 avatar

ryanb4614

Totally Zenned

Join Date:
Feb 2008
Posts:
556
Plugin Contributions:
0

Hide Add To Cart box if mod shows on Product Page

Hello, I can figured the cross sell mod to work with a add to cart function. I have one problem, I need the add to cart box to be hidden if the cross sell mod is on the specific product page, So if product A has the cross sell mod on it I need the "add to cart" box to be hidden. If product B doesn't have the cross sell mod on its page i need the "add to cart box" to be visible.

8 Nov 2009, 6:59 PM
#2
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Hide Add To Cart box if mod shows on Product Page

Cross Sell is run after the fact ... so you need to do a little more work ...

You can test if there are any products for the XSell with the code used by the xcell_products.php module file:

// collect information on available cross-sell products for the current product-id
if (isset($_GET['products_id']) && SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS > 0 ) {
  $xsell_sort_by = XSELL_SORT_ORDER=="sort_order"?" order by xp.sort_order asc ": " order by rand() ";
  $xsell_query = $db->Execute("select distinct p.products_id, p.products_image, pd.products_name
                                 from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                 where xp.products_id = '" . $_GET['products_id'] . "'
                                  and xp.xsell_id = p.products_id
                                  and p.products_id = pd.products_id
                                  and pd.language_id = '" . $_SESSION['languages_id'] . "'
                                  and p.products_status = 1 ".
                                  $xsell_sort_by." limit " . MAX_DISPLAY_XSELL);

  $num_products_xsell = $xsell_query->RecordCount();

where $num_products_xsell would be > 0 if there are any ...

Which that information, you could place an IF around the code for the Add to Cart button to disable that ...

8 Nov 2009, 9:05 PM
#3
ryanb4614 avatar

ryanb4614

Totally Zenned

Join Date:
Feb 2008
Posts:
556
Plugin Contributions:
0

Re: Hide Add To Cart box if mod shows on Product Page

I have found the part of coding you are saying, not sure about how to insert a IF for... what I want it to function, if the cross sell mod is active on the product page, i want the "Add to cart" box hidden, but if the cross sell mod if NOTactive on the specific product page, I want the "Add to Cart box" to be active, any help with this would be great, I was able to fix the coding problems I had before, this mod will be a great option for people that want to setup attributes and have a model number for each. I used the cross sell mod as the base mod and worked around it. I want to get it to work 100% before I post on how to do anything. This is the last part i need fixed but i am stuck. Not good with placing IF to codes

8 Nov 2009, 9:21 PM
#4
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Hide Add To Cart box if mod shows on Product Page

What ajeh is saying is that you place that lump of code with a closing bracket at the end of it like this ' } ' (sorry linda couldn't resist!) anywhere in the page above the add to cart. If it is not in an area that is enclosed by <?php and ?> tags then it needs to be enclosed.

Then around your add to cart box you use an if statement like this:

<?php
if($num_products_xsell==0){
?>

the html for the add to cart goes in here.

<?php
}
?>
8 Nov 2009, 9:32 PM
#5
ryanb4614 avatar

ryanb4614

Totally Zenned

Join Date:
Feb 2008
Posts:
556
Plugin Contributions:
0

Re: Hide Add To Cart box if mod shows on Product Page

Are you saying to place that around this:
/includes/templates/template_default/templates/tpl_product_info_display.php

<!--bof Add to Cart Box -->
<?php
if (CUSTOMERS_APPROVAL == 3 and TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM == '') {
  // do nothing
} else {
?>
            <?php
    $display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($_GET['products_id'])) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($_GET['products_id']) . '</p>' : '');
            if ($products_qty_box_status == 0 or $products_quantity_order_max== 1) {
              // hide the quantity box and default to 1
              $the_button = '<input type="hidden" name="cart_quantity" value="1" />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
            } else {
              // show the quantity box
    $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($_GET['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '<br />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
            }
    $display_button = zen_get_buy_now_button($_GET['products_id'], $the_button);
  ?>
  <?php if ($display_qty != '' or $display_button != '') { ?>
    <div id="cartAdd">
    <?php
      echo $display_qty;
      echo $display_button;
            ?>
          </div>
  <?php } // display qty and button ?>
<?php } // CUSTOMERS_APPROVAL == 3 ?>
<!--eof Add to Cart Box-->

If so it didn't work but thats probly not the place to put it...Thanks for all your help I hope to finish this soon!

8 Nov 2009, 10:03 PM
#6
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Hide Add To Cart box if mod shows on Product Page

Yes, that looks like the correct lump of code.

In total yours should look like this:

<?php
// collect information on available cross-sell products for the current product-id
if (isset($_GET['products_id']) && SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS > 0 ) {
  $xsell_sort_by = XSELL_SORT_ORDER=="sort_order"?" order by xp.sort_order asc ": " order by rand() ";
  $xsell_query = $db->Execute("select distinct p.products_id, p.products_image, pd.products_name
                                 from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                 where xp.products_id = '" . $_GET['products_id'] . "'
                                  and xp.xsell_id = p.products_id
                                  and p.products_id = pd.products_id
                                  and pd.language_id = '" . $_SESSION['languages_id'] . "'
                                  and p.products_status = 1 ".
                                  $xsell_sort_by." limit " . MAX_DISPLAY_XSELL);

  $num_products_xsell = $xsell_query->RecordCount();
}
?>

<?php
if($num_products_xsell==0){
?>

the section of code that you have indicated

<?php
}
?>

Which should display the add to cart if there are no xsell products and not display it if there are any xsell products.

When you say it didn't work do you mean that you didn't get the right result or that you got a page that looked wrong?

8 Nov 2009, 11:05 PM
#7
ryanb4614 avatar

ryanb4614

Totally Zenned

Join Date:
Feb 2008
Posts:
556
Plugin Contributions:
0

Re: Hide Add To Cart box if mod shows on Product Page

okay this is what i did:
in /includes/modules/classic/xsell_products.php
i did this:

<?php
/**
 * Cross Sell products
 *
 * Derived from:
 * Original Idea From Isaac Mualem [email protected] <mailto:[email protected]>
 * Portions Copyright (c) 2002 osCommerce
 * Complete Recoding From Stephen Walker [email protected]
 * Released under the GNU General Public License
 *
 * Adapted to Zen Cart by Merlin - Spring 2005
 * Reworked for Zen Cart v1.3.0  03-30-2006
 */

// in case admin switches aren't added properly, assume default settings:
if (!defined('MAX_DISPLAY_XSELL')) define('MAX_DISPLAY_XSELL',6);
if (!defined('MIN_DISPLAY_XSELL')) define('MIN_DISPLAY_XSELL',1);
if (!defined('XSELL_DISPLAY_PRICE')) define('XSELL_DISPLAY_PRICE','false');
if (!defined('SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS')) define('SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS',3);

<?php
// collect information on available cross-sell products for the current product-id
if (isset($_GET['products_id']) && SHOW_PRODUCT_INFO_COLUMNS_XSELL_PRODUCTS > 0 ) {
  $xsell_sort_by = XSELL_SORT_ORDER=="sort_order"?" order by xp.sort_order asc ": " order by rand() ";
  $xsell_query = $db->Execute("select distinct p.products_id, p.products_image, pd.products_name
                                 from " . TABLE_PRODUCTS_XSELL . " xp, " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                                 where xp.products_id = '" . $_GET['products_id'] . "'
                                  and xp.xsell_id = p.products_id
                                  and p.products_id = pd.products_id
                                  and pd.language_id = '" . $_SESSION['languages_id'] . "'
                                  and p.products_status = 1 ".
                                  $xsell_sort_by." limit " . MAX_DISPLAY_XSELL);

  $num_products_xsell = $xsell_query->RecordCount();echo '</form>';
}
?>

<?php
if($num_products_xsell==0){
?>

<?php
if (CUSTOMERS_APPROVAL == 3 and TEXT_LOGIN_FOR_PRICE_BUTTON_REPLACE_SHOWROOM == '') {
  // do nothing
} else {
?>
            <?php
    $display_qty = (($flag_show_product_info_in_cart_qty == 1 and $_SESSION['cart']->in_cart($_GET['products_id'])) ? '<p>' . PRODUCTS_ORDER_QTY_TEXT_IN_CART . $_SESSION['cart']->get_quantity($_GET['products_id']) . '</p>' : '');
            if ($products_qty_box_status == 0 or $products_quantity_order_max== 1) {
              // hide the quantity box and default to 1
              $the_button = '<input type="hidden" name="cart_quantity" value="1" />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
            } else {
              // show the quantity box
    $the_button = PRODUCTS_ORDER_QTY_TEXT . '<input type="text" name="cart_quantity" value="' . (zen_get_buy_now_qty($_GET['products_id'])) . '" maxlength="6" size="4" /><br />' . zen_get_products_quantity_min_units_display((int)$_GET['products_id']) . '<br />' . zen_draw_hidden_field('products_id', (int)$_GET['products_id']) . zen_image_submit(BUTTON_IMAGE_IN_CART, BUTTON_IN_CART_ALT);
            }
    $display_button = zen_get_buy_now_button($_GET['products_id'], $the_button);
  ?>
  <?php if ($display_qty != '' or $display_button != '') { ?>
    <div id="cartAdd">
    <?php
      echo $display_qty;
      echo $display_button;
            ?>
          </div>
  <?php } // display qty and button ?>
<?php } // CUSTOMERS_APPROVAL == 3 ?>

<?php
}
?>

The mod doesn't appear now.

8 Nov 2009, 11:20 PM
#8
niccol avatar

niccol

Totally Zenned

Join Date:
Apr 2009
Posts:
2,138
Plugin Contributions:
1

Re: Hide Add To Cart box if mod shows on Product Page

Sorry, There seems to be a bit of misunderstanding.

The edit you want to make is where you tried originally. You need to edit tpl_product_info_display.php .

It looked like you had done almost the correct thing the first time around. My next post was to confirm that, and that you had got the code from ajeh in there too.

What we are doing is checking the database to see how many xsell products there are (that is the code that ajeh supplied) and then only if there are no cross sell products we display the add to cart box. (that's the is statement I provided). All this happens in tpl_product_info.php.

8 Nov 2009, 11:28 PM
#9
ryanb4614 avatar

ryanb4614

Totally Zenned

Join Date:
Feb 2008
Posts:
556
Plugin Contributions:
0

Re: Hide Add To Cart box if mod shows on Product Page

GOT IT !! Works great thanks niccol & Adjeh always a great help!! :)