10 replies [Last post]
yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Was this information Helpful?

I tried searching and googling... and I found an old post http://www.ubercart.org/forum/support/1452/how_create_block_add_cart but it sounds like things have changed since then...

I want to put in a block something like: "e-book $30 " the price and a add to cart button. How? the best I have so far is...

<?php
<!-- the php tag is just to get the code below to show here in the forum -->

e-book $39.00 <div class="add_to_cart"><form><a href="/cart/add/e-p5_q1?destination=cart"><input type="submit" value="ORDER NOW!"  /></a></form></div>
?>

There has to be a better way! And I'm hoping a way to have it "find" the right product price and not just $39 in text! Smiling

Thanks for any help.

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
<?php$my_product_node =
<?php
$my_product_node
= node_load('5');
echo
"e-book $"; print $my_product_node->sell_price;
print
$my_product_node->content['add_to_cart']['#value'];
?>

... seems better, but the add to cart value line does not seem to have any effect (does not show a button ...

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: <?php$my_product_node =

So, I'm not sure if the way you're doing it is the best way or not, but you might also try:

<?php
$my_product_node
= node_load('5');
echo
"e-book $"; print $my_product_node->sell_price;
print
drupal_render($my_product_node->content['add_to_cart']);
?>
yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: Re: <?php$my_product_node =

thanks for the fast reply. Smiling I'm impressed! I tried it out... and still nothing... does it work when you try it?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: <?php$my_product_node =

Nah, I didn't actually try it, was just guessing. Eye-wink

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: Re: Re: Re: <?php$my_product_node =

Well, what I have seems to be working ... For me and some others.. But for some people, they click the button to add to cart and what happens is they just reload the home page instead of getting redirected to the cart . And if they manually view the cart, it is empty!

The misbehavior is confirmed on a blackberry running opera ...

Could a couple people try adding something to the cart on my devel?

Http://avoidremodelingnightmares.yestrainingandeducation.com

Thanks a ton!

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: Re: Re: Re: Re: <?php$my_product_node =

I tried something.. I promoted the product node to the front page, and when the person who previously my add to cart links did NOT work for, when they tried the default button as part of the product node, it DID work...

this is the code (from view page source in the browser) for the default that results from the product node:

<?php
 
<div class="content">

    <

div class="display_price">$39.00</div><p>blah blah</p>
<
div class="add_to_cart"><form action="/node"  accept-charset="UTF-8" method="post" id="uc-product-add-to-cart-form-5">
<
div><input type="hidden" name="qty" id="edit-qty" value="1"  />
<
input type="submit" name="op" id="edit-submit-5" value="ORDER NOW!"  class="form-submit node-add-to-cart" />
<
input type="hidden" name="form_build_id" id="form-c40646ca772b308ef7de6bca9faf9801" value="form-c40646ca772b308ef7de6bca9faf9801"  />
<
input type="hidden" name="form_token" id="edit-uc-product-add-to-cart-form-5-form-token" value="8178dfd6b40aea99bcd81d1716769805"  />
<
input type="hidden" name="form_id" id="edit-uc-product-add-to-cart-form-5" value="uc_product_add_to_cart_form_5"  />

</

div></form>
</
div>  </div>
?>

and this is from my button I tried to write:

<?php
<div class="content">
   
e-book $39.00

<div class="add_to_cart">
<
form>
<
a href="/cart/add/e-p5_q1?destination=cart"><input type="submit" value="ORDER NOW!"  /></a></form>
</
div>

  </

div>
?>

so what did I do wrong when I wrote my own button? why does it only NOT work for some people... ?

thanks!

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: Re: Re: Re: Re: Re: <?php$my_product_node =

hmmm strangely .. it seems if the product node is on the front page, then the html I copied out of the page source will work in the other blocks with a functioning add to cart button. BUT if the product node is not on the front page, then the SAME html I copied in use on the front page will redirect people to the frontpage instead of to the cart. ... hmmm more mystery.

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Re: Re: Re: Re: Re: <?php$my_product_node =

Hmm, yeah, I should've thought of cart links... but you should know that wrapping a form submit button with an a tag won't do what you want. Sticking out tongue What you really need to do is make the action of the form be the cart link if you want the button to submit to that URL. That should work out fine.

yesct@drupal.org's picture
Offline
Uber Donor
Joined: 11/18/2008
Juice: 294
Re: Re: Re: Re: Re: Re: Re: Re: <?php$my_product_node =

I feel a bit dense... I'm not sure what to put in the block to code the submit button... maybe if I looked at the code that produced the product node.

I started off using the cart links... which worked great IN SOME BROWSERS ... so then in order to get something that worked in ALL BROWSERS, I just copied the generated html from the product node into blocks where I wanted other add to cart buttons.

But I know this is a hack, and not a good hack on my part.

mrag's picture
Offline
Joined: 11/12/2008
Juice: 40
any ideas

Just wondered if anybody ever figured this out.

I have a similar problem, I am trying to include the "add to cart" form in a drupal block on a different region of the page. The block shows up but none of the variables such as price or the add to cart button get included.

The code I am using in the block is:

<div id="prod_content">
  <div id="product_infos">
    <div id="was_price">Retail Price: <?php print uc_currency_format($node->list_price); ?></div>
    <div id="now_price">Web Special: <?php print uc_currency_format($node->sell_price); ?></div>
    <div id="prod_special"><?php print $node->content['field_prod_special']['#children'] ?></div>
    <div id="order_button"><?php print $node->content['add_to_cart']["#value"]; ?> </div>
  </div>
</div>

This code works fine in the node-product.tpl.php but won't work when in a block. Sorry if this is a dumb question but my technical ability is fairly limited.

My best guess is where node is referenced it doesn't know which node as it is "outside" of the node as such, but I don't really know how to fix that. I basically just want it to use whatever node the block is being displayed on at that time if that makes sense.

Can anybody give me a hint here please?

Thanks

Andy