7 replies [Last post]
amitaibu@drupal.org's picture
Offline
Bug Finder
Joined: 09/08/2007
Juice: 239
Was this information Helpful?

Hi,
Non-developer here, so sorry if it's an annoying question.
I'd like to create a block, that will show the Price and the Add to cart button (like the attached snap). What's would be the PHP for that?

PreviewAttachmentSize
Snap1.pngSnap1.png37.1 KB
oslinux's picture
Offline
Joined: 09/06/2007
Juice: 461
Re: How to create a block with 'Add to cart'

you would use the function node_api (look it up at api.drupal.org) and then when the node you are displaying is of type X your product, then you can create/fill a block with the price in the $node object and you also would create a link with the print function like /addtocart/$node->nid ...

amitaibu@drupal.org's picture
Offline
Bug Finder
Joined: 09/08/2007
Juice: 239
Re: Re: How to create a block with 'Add to cart'

thanks oslinux. hmm, am I even close?

<?php
  $nid
= arg(1);
 
$node = node_load($nid);
  print
$node->nid;
 
//Show the price
 
print $node->content['display_price']['#value'];

 

//Show the 'add to cart' button
 
$node->content['add_to_cart']['#value']
?>
amitaibu@drupal.org's picture
Offline
Bug Finder
Joined: 09/08/2007
Juice: 239
Re: Re: Re: How to create a block with 'Add to cart'

Here's the answer (thanks to contemplate module):

1. install contemplate module.
2. Goto http://XXX/admin/content/templates/product (or any content type that is a product)
3. Select Body> Body Variables
4. Expand the text area - this will make it enabled.
5. look for the code under $node->content['add_to_cart']['#value']
6. Copy the code (from <div> to <div> )
7. Paste it into a block or as I use it into a mini panel.

AttachmentSize
Snap1.png 10.53 KB
amitaibu@drupal.org's picture
Offline
Bug Finder
Joined: 09/08/2007
Juice: 239
Re: Re: Re: Re: How to create a block with 'Add to cart'

The above is actually incorrect, since it brings only a static form. Any idea anyone?

Summit_drupal's picture
Offline
Joined: 12/11/2010
Juice: 137
Re: Re: Re: Re: Re: How to create a block with 'Add to cart'

Hi, Also interested in having the "add to cart" button in a block related to the node.
The posts above didn't work. Anyone please?

ekkljs's picture
Offline
Joined: 04/30/2011
Juice: 8
Re: How to create a block with 'Add to cart'

subscribing

end user's picture
Offline
Joined: 01/11/2008
Juice: 1198
Re: Re: How to create a block with 'Add to cart'

I've posted some info here http://drupal.org/node/1143596