Important announcements from CouchCMS team
8 posts Page 1 of 1
17 June 2013: This version of Couch has been promoted to become the release version 1.3.5 available from the main download page

Hi everybody,

Here is the first-cut version of Couch 1.3.5.
(1.85 MiB) Downloaded 1120 times

As previously announced, the major feature of this version is the shopping-cart.

You can see a demo of a sample (and simple) implementation of this cart here.

The full documentation (cum tutorial) is online now
Shopping Cart (Part 1)
Shopping Cart (Part 2)

Some salient features of the cart are:
1. Provides simple tags that can be applied to any HTML shopping-cart design to make it a functional cart.
2. Products are created as Couch's regular cloned pages and hence can make use of all the existing functionality of Couch
(e.g multiple images, thumbnails, repeatable-regions, related pages etc.)
3. Supports creation of product variants (i.e. products having different colors, sizes etc.).
4. Supports full Ajaxification.
5. Supports extending the cart by defining custom discounts, shipping and taxes.
6. Comes pre-built with implementation of many common discounts and shipping methods.
7. Comes with an implementation of 'Coupons'.

This new version also ships with some useful new helper tags -
1. Session Variables
The cart module includes a 'session' module which can also be used in an standalone manner (i.e. without the cart module).
This module provides a set of tags to help you use PHP session variables.
A PHP session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.

These can be very useful, for example, to store visitor's preferences like the language selected or the sort order of a table listing, while they browse your site.
For example, the following statement placed on any template will set a session variable named 'greeting'
Code: Select all
<cms:set_session name='greeting' value='Hello world!' />

The session variable set above now can be accessed from any other template using
Code: Select all
<cms:get_session 'greeting' />

The following two tags help deal with 'Flash data' i.e. session variables that exist for only a single server request, specifically the next one, and then are deleted. This is very helpful to show informational messages like those on successful form submission etc.
Code: Select all
<h3>Flash Message: <cms:get_flash 'flash_msg' /></h3>
<cms:form method="post" anchor='0'>
   <cms:if k_success >
       <cms:set_flash name='flash_msg' value="Your transaction is complete!" />
       <cms:redirect k_page_link />   
   <cms:input name="submit" type="submit" value="Submit" />

As an example, in the snippet above, upon successful form submission, a flash variable named 'flash_msg' is set and (very importantly) the visitor is redirected to the current page itself (i.e. the page is refreshed). When the page loads, the <cms:get_flash 'flash_msg' /> statement shows the content set in 'flash_msg' by the previous page request. If at this point the page is refreshed again, the 'flash_msg' comes up empty as it was valid only for a single request.

IMP: Two scenarios can cause flash messages not to work as expected -
1. Multiple redirects (as happens when prettyURLs are on but a page is accessed using the 'older' URL. This causes Couch to redirect it to the newer (pretty) URL. The second redirection causes the flash message to be lost as it remains available for only one redirect)
2. The page being redirected to has been cached by Couch (in which case the cached page would be supplied).

2. Executing custom SQL queries.
This version ships with a tag named 'query' that can be used to run raw SQL SELECT statements.
While it is a very powerful tag, it expects familiarty with how Couch stores its data in the database.

A useful example of this tag is the following:
As you know, the cms:pages tag's 'masterpage' parameter allows specifying only a single template which constrains us to use it for listing only pages belonging to a single template. Sometimes, it could be useful to show pages from multiple templates in a single list (e.g. for creating a Tumblr style site with a separate template for each 'post type').
The following snippet uses cms:query to execute a raw SQL query that fetches pages from two templates (of course, you're free to set any number of your own here)
Code: Select all
    sql="  SELECT pid, tname
        FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
        inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
        on p.template_id =
        WHERE ('actors.php' or'movies.php')
        AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
        AND NOT publish_date = '0000-00-00 00:00:00'
        ORDER BY publish_date desc;"

    <cms:show pid />-<cms:show tname /><br/>

    <cms:pages masterpage=tname id=pid>
       <a href="<cms:show k_page_link />"><cms:show k_page_title /></a><br />

    <br />
    <cms:paginator />

Some important points for using this tag:
1. Only SELECT statements can be used.
2. Don't use LIMIT / OFFSET in the raw SQL statement itself. Use the tag's parameters instead else the tag will throw error.
3. ORDER BY clause in raw SQL can mess up the count query (used internally for pagination) if it contains 'calculated fields'. For such cases
the raw query can be stripped off this clause and the 'orderby' param of 'cms:query' tag used to provide the raw clause (this can include asc, desc etc.).

3. 'no_results' tag
This tag can be used with pages, comments, search, related_pages, reverse_related_pages & query tags for conditions where the number of pages fetched by these tags is zero.
For example:
Code: Select all
<cms:pages ..>
      <h3>No pages found</h3>

4. 'addslashes' tag
This tag has been created specially for use with cms:php tag where a PHP variable is set using Couch statements.
For example:
Code: Select all
<cms:set test="O'Reilly" /> 
<cms:show test />
    //$test = '<cms:show test />'; // this throws parse error because the value being set contains a single-quote (which is also used to surround the statement)
    $test = '<cms:addslashes quote='single'><cms:show test /></cms:addslashes>'; //default is 'double'
    echo '<h1>' . $test . '</h1>';

5. 'not' tag
This tag is used to test the 'reverse' of a logical statement. For example:
Code: Select all
<cms:set age='11' />
<cms:not age ge '18' /> // age greater than or equal to '18'? Outputs 1 (i.e. reverses the result of the logic being tested)

This tag is meant to be used with cms:if tag. e.g.
Code: Select all
<cms:if "<cms:not age ge '18' />" >
    <h3>You are under age!</h3>

Of course, the snippet above could have been coded as the following but you'll definitely run into situations where the cms:not tag will come in really handy.
Code: Select all
<cms:if age lt '18' >
    <h3>You are under age!</h3>

Hope you like it.
As always, your comments are solicited :)

Downloading now and throwing into a Dev setup to "play" with!

Great work Kamran
WOW! :o Thanks! Kamran! This looks really great! :)

Will try this in the next few days.

Keep up the good work!
The shopping cart looks great - I have shied away from anything to do with ecommerce, but now I might well take the plunge the next opportunity I get. Custom SQL queries exciting too! Thanks KK for all your hard work!
I'm glad the cart allows for the same level of customization and control as the rest of Couch's features, as always leaving the design uncompromised. I think for those who may have pigeonholed Couch as just a "simple" cms, the last few updates should put any such characterization to rest. Great work KK.

I hope everyone likes the theme. ;)
First time I saw the theme, I immediately knew it was your theme. :) Great work!
Hi @KK

I've spotted delete_session in the description above. Any hints on when it's advisable to use it? Also what happens if it's not deleted somewhere in code? Thanks!

your best friends: github, StackOverflow, telegram
@trendoman, that tag could be used to wipe off certain session variables set earlier and start clean - not awfully useful, if you ask me but there could be scenarios where it might come in handy.

No harm if a session variable is not deleted. PHP will do the cleaning up in the background.
8 posts Page 1 of 1