10 replies [Last post]
StephenGWills's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/07/2007
Juice: 414
Was this information Helpful?

I want to allow my webeditors to use Drupal to create pages that have educational content on them and include a product detail node into the middle of their custom content.

I have envisioned giving them a function like insertProduct(model_no) that they can add to their content which will expand the product at the location in their text that they want the product to appear complete with add to cart functionality.

I have found several modules like node_to_block and also thought about using views but the users who will create these pages are macromedia wysiwig designers and want to know as little about drupal and ubercart as they can.

Any suggestions of the best way to go?

Shawn Conn's picture
Offline
Administrator
Joined: 08/07/2007
Juice: 916
Ideas

I've thought about doing something like this myself for any Drupal nodes. Before I started using Drupal/Ubercart I was big into Wikipedia and the MediaWiki software. MediaWiki has something very similar called transclusion, where you can reference an article name (or node id for our purposes) and insert its content in any other article (node).

Insert View does something similar to this but instead of referencing nodes, you reference views. That might be a easy solution; create a view for product nodes with a url that has an argument for a particular product id, name, etc then you could use insert view to insert a view containing the entire product node's body into any node.

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

StephenGWills's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/07/2007
Juice: 414
Re: Inject Product into static page

Thanks Shawn, I'll experiment with this idea as well. As of now, the designers are claiming that they have it under control by viewing the source of a product node, swiping the add_to_cart elements and statically embedding them into their pages.

Our product info doesn't change quickly so this horrible ERP faux pas is, in reality, not all that bad... it just isn't IT kosher.

I know that on the old site there was a "how to add an Add-To-Cart button" discussion going on. Maybe this thread is it's resurrection?

StephenGWills's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/07/2007
Juice: 414
Re: Inject Product into static page

This note tracks discoveries about form_token, which is created by the form api to guard against cross site request forgeries. I do not know yet if the forms processer will get broken if the same token is sent in repeatedly but this is what will happen when my editors attempt to copy the source of an add-to-cart page and paste it into their static pages.

if session tokens are set then this will cause ubercart to fail, I believe.

Any thoughts?

StephenGWills's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/07/2007
Juice: 414
Re: Inject Product into static page

if you embed a call to theme_uc_product_add_to_cart($node) into an html page, it will create a functioning add_to_cart button in an html page. the problem is that it skips the attributes of the product without even including the default value.

Lyle's picture
Offline
AdministratoreLiTe!
Joined: 08/07/2007
Juice: 6846
Re: Re: Inject Product into static page

It's supposed to include the attributes, because it has a call to drupal_get_form(), which invokes hook_form_alter(). Make sure that $node->nid exists and is the node id you want. A call to node_load() is the easiest way I know, and that will get you the default quantity as well.

StephenGWills's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/07/2007
Juice: 414
Re: Inject Product into static page

so theme_uc_product_add_to_cart is the right thing for this situation.

the API page is: http://www.ubercart.org/docs/api/theme_uc_product_add_to_cart

Here is what I came up with so that my client, who can create html pages but is daunted by PHP can embed product buttons into the pages they create:

<?php
 
//These are the product node id's
 
$myCoolProduct = 1;
 
$myOtherCoolProduct = 2;

 

//Editors, change the name of the product to the name
  //of the product you want inserted.

 

$nid = $myCoolProduct;

 

//This builds the button, qty and attributes.
 
$node = node_load($nid);
  echo
theme('uc_product_add_to_cart', $node);
?>
druru's picture
Offline
Brain Stormer
Joined: 08/08/2007
Juice: 228
Re: Re: Inject Product into static page

If there aren't tons of products, in order to make this easier for your client, i'm wondering if you might be able to

1) add a form select element dropdown to allow them to select from a list of given products that you set in the code (either a hard code list or all nids)

2) allow the client to insert a 'product' filter tag or token WHERE they want the product to be PLACED in the node body

3) have a custom filter module go and automatically perform the theme code and insert the output at the token location in the node body verus force the client to manually place that code in every node right now.

make sense?

it would be easier on the customer and it would be better because you do NOT have to enable php on the node bodies (a potential for mistakes and possible security risk).

i think you could do this pretty easily since you've already taken care of the retheming aspect. you probably could copy and modify an existing filter 'type' module and modifying the form and relevant submit / validate handlers via probably nodeapi would be pretty easy as well. i'm sure the uc guys could help you with the form part in a snap.

2 cents

oh yeah.. if you actually do it, post it back to the site Eye-wink

StephenGWills's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.Not Kulvik
Joined: 08/07/2007
Juice: 414
Re: Inject Product into static page

This is a wonderful idea when I have the time to implement it! Just to be clear, you are suggesting implementing a filter as described in the following link?

http://api.drupal.org/api/file/developer/examples/filter_example.module

very cool!

druru's picture
Offline
Brain Stormer
Joined: 08/08/2007
Juice: 228
right! the key is you want

right!

the key is you want to use hook_filter. there are many contrib modules that are pure filter modules and implement hook_filter. there are probably other contrib modules that are NOT pure filter modules but also incorporate filtering (hook_filter) in what they do.

So if you find any module using hook_filter, you can use that to model on.

Alternatively, i imagine you could use hook_nodeapi as well. with hook_filter you have to worry about the ordering of other filters which means the store admin will have to configure the filter - an extra step. i think you could just use hook_nodeapi on the 'view' op and do a str_replace or preg_replace directly on the node body for your token. that happens automagically each time the node is loaded and requires no filter config!

good luck

druru's picture
Offline
Brain Stormer
Joined: 08/08/2007
Juice: 228
Re: right! the key is you want

just revisiting this at a later time...

i think you could use:

theme_node aka theme('node', $node);

to insert the entire product into your page if you wanted