Zen Cart Logo
Forums / General Questions / Add to Cart button that can be placed on other pages?

Add to Cart button that can be placed on other pages?

Locked

Views: 714

Results 1 to 6 of 6
This thread is locked. New replies are disabled.
6 Jul 2010, 6:40 PM
#1
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Add to Cart button that can be placed on other pages?

Hello Zen Community,

Like the subject line states, I'm in need of a custom piece of code to allow the use of an add to cart button with a value of +1 item of what the product ID is. Traditionally Zen would normally show the shopping cart of the customer with the product after this add to cart feature was selected. I'd like to keep that feature if possible.

The objective is to create a button that is not on the main website and when clicked will automatically link them to their shopping cart with the item inside.

I tried to tackle this problem myself, but I had some problems with finding the right portions of code to edit. I have a test page on my website and right now the button keeps stating that it is sold out. This indicates I'm missing the product id somewhere as it's not reading the id value for the intended product.

I took this line of code right out of Zen Cart's product_info_display.php and edited the two places where I saw input fields for product ID values. Any and all assistance would be appreciated. Thanks!

<!--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 name="cart_quantity" value="1" maxlength="6" size="4" type="text"><input name="products_id" value="38" type="hidden">' . 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 name="cart_quantity" value="1" maxlength="6" size="4" type="text"><input name="products_id" value="38" type="hidden">' . (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_button;
        ?>
</div> <?php } // display qty and button ?> <?php } // CUSTOMERS_APPROVAL == 3 ?> <!--eof Add to Cart Box-->

This is the test bed link, but be forewarned I just dropped it in the file, the actual button displays on the top banner so make sure to look there when trying to find it. I just haven't bumped the CSS code to make it move down yet.

http://www.primevapor.com/index.php?main_page=test

Thanks for your time Zenners,

Jonah

6 Jul 2010, 6:43 PM
#2
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Add to Cart button that can be placed on other pages?

Sorry, but I'm unclear about what you want to do.

You want an Add to Cart button where, on what page and for what product ?

Do you mean on pages outside of Zencart ?

6 Jul 2010, 8:04 PM
#3
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Add to Cart button that can be placed on other pages?

Yes, as I stated in my wall of text above,

"The objective is to create a button that is not on the main website and when clicked will automatically link them to their shopping cart with the item inside."

This function needs to be able to work on a static HTML page that I can install wherever we see fit to do it. This HTML format will be used in static pages on the site (but not in zen's php files) and also in a mass e-mail that we design for special announcements.

The 'add to cart' button needs to be on these items and be able to add said item and send the user to their shopping cart on the website when the product is added to the cart.

Does that make sense?

Thanks for your time.

6 Jul 2010, 8:18 PM
#4
stevesh avatar

stevesh

Black Belt

Join Date:
Feb 2005
Location:
Lansing, Michigan USA
Posts:
19,793
Plugin Contributions:
2

Re: Add to Cart button that can be placed on other pages?

It makes sense, and has been asked many, many times. The usual answer is 'you can't do that'.

Zencart isn't meant, and wasn't designed, to be a back-end cart script for an existing flat HTML page.

That said, it has been done successfully with a site consisting of a very few products. It sounds like you want to link several HTML sites to one Zencart installation. Problem with that is that you can run into sessions problems by switching back and forth between Zencart and non-Zencart pages.

If you want to explain exactly what problem you're trying to solve, we may be able to suggest alternatives.

7 Jul 2010, 4:16 PM
#6
youngblood avatar

youngblood

New Zenner

Join Date:
Apr 2010
Posts:
59
Plugin Contributions:
0

Re: Add to Cart button that can be placed on other pages?

Schoolboy,

You schooled me. Thank you for taking the time to search through where I failed to do so.

That linkage in the other topic worked like a charm and will make me look good to the employers!

Thanks Zenners!