3. Using CCK to create articles with dynamic product information

Submitted by jonnyplatt on Mon, 2007-10-22 15:21.

Getting Started

First check you have the Content (CCK), Content Copy and Computed Fields modules installed, as well as the shopwindow module.

In the Shopwindow folder you will find a text file titled 'content_type_product.txt'. Open this in notepad and copy the contents into the 'Import Content Type' page on drupal (/admin/content/content-types/import)

Next go to node/add/product and create your first product node. Enter the search you wish to use as a title (eg 'Picooz Helicopter') and the article/description as the body. Click submit and the results of a search for 'Picooz Helicopter' will be added to your page.

You can then control the theming as you would with any other node in drupal, or add comments, user reviews, related links etc using the full flexibility offered by Google.

More relevant results

Often you will want to limit the search to one category, and on the node/add/product or edit product pages there is a box marked 'cid'. Enter the category id and submit, and the results will be refreshed and targetted to that one category.

You may also wish to use a slightly different Page Title and product search. To do this, add a text field to your product content type with the machine name 'squery' (you can title it how you like), and edit the 'shopwindow_data' field, uncommenting the line:
// $oProductDisplayListParams->sQuery=$node->field_squery[0]['value'];

Now you can create a product node, enter the product search query in your new field and call the node whatever you want.

More data!
I have already created optional fields that generate thumbnail fields, 'best price' etc which you can enable and disable, but you may want to present more information to the user. To do this, click 'edit' on a simple field such as 'Thumbnail' or 'Picture' to see how the data is pulled from the 'shopwindow_data' field. Refer to the Affiliate Window API docs to see the product datatype's fields and grab the information you require.

To edit the 'compare prices' listing, scroll down to the 'display' area and edit the code. Be careful though, if you create a syntax error your product nodes will stop displaying.

Updating your prices
Unfortunately, you have two options - either display all the price information live, each time a node is loaded (either as a full page or 'teaser' listing) - which can cause delays for the customer and prevents you using fields such as 'thumbnail' and 'best price' in your views, or to save all the data into the database and refresh it manually.

I plan to write a script to auto-update the nodes as a cron job, but at present you will need to 'edit' and 'save' the nodes to refresh the price information.

Alternatively if you want to display live pricing info, gathered as the user browses the site, edit the 'shopwindow_data' field and uncheck 'Store this value in the database'. Each product node already created will need to be re-saved in order for you to notice a change.

Join Us!

Every time you shop on rectifi you save money AND raise money for charity - free - through the advertising funds we receive.

We give 100% of our profits to charity and are volunteer run so the lions share of the commissions we receive go to charity.

You help us raise this extra source of funds for charity, so we think you should have a say in how it is spent

And, of course, we want to thank you for our support and keep you updated on our results

Help us make a difference : Sign up today

Thanks, Jonny Platt