Developing a shopping cart addon

13 views
Skip to first unread message

george hu

unread,
Apr 20, 2012, 1:25:18 AM4/20/12
to pooly...@googlegroups.com
I'm wondering for the current design of Poolyx, is it possible to develop a shopping cart addon for it? Think about a inventory entity in traditional db, is there a way to implement business logic in the CMS? My first impression is that Poolyx is focusing on content only, and as for the natural of traversal pattern in pyramid, is it possible to develop shopping cart in a style like traversal+url dispatch? Coz the major and essential part of the poolyx is traversal,  now we need add url dispatch pattern for it. I can't figure out a way to do it.

Arndt Droullier

unread,
Apr 20, 2012, 9:01:42 AM4/20/12
to pooly...@googlegroups.com
Hi George,
yes, this should be possible and not too difficult. However figuring out where to start to integrate your business logic is not easy. I'm already working on an explanation on poolyx views integrate into pyramid views and how to use a combination of both. 

The pyramid docs describe how to use traversal and url dispatch in one application:
 
But I think the traversal/poolyx way is easier to handle than using url dispatch. 
Here is one approach how to do it:
 
To link your shopping cart business logic to callable urls you can use the poolyx root object (http://www.poolyx.net/doc/html/api/root.html) as context for the view. Root objects provide the 'IRoot' interface, so your code will only be called on the root level. 
The poolyx resource tree structure is explained here: http://www.poolyx.net/doc/html/basics.html#definitions-and-basics


For example create a shoppingcart python module and use the following in the modules __init__.py:

from poolyx import ViewConf
from poolyx import IWebsiteRoot

def shoppingcart(context, request):
    # shopping cart html page rendering and business logic
    # e.g. read the users session, render a checkout form
    # .....
    return """ My shopping cart """

configuration = ViewConf(name="cart", context=IWebsiteRoot, view=shoppingcart)


Include it in poolyx project directory 'website/__init__.py' by calling

website.modules.append("shoppingcart")


This adds the following url and maps it to the shoppingcart function above.

----------------------------------------------------------------------------------------------------------------------------
Alternative: Using pyramid configuration functions directly this would look like:

def shoppingcart(context, request):
    # shopping cart html page rendering and business logic
    # e.g. read the users session, render a checkout form
    # .....
    return """ My shopping cart """

config.add_view(name="cart", context=IWebsiteRoot, view=shoppingcart)


Well, it's just a rough explanation and I don't know your concept for a shopping cart. Do you think this approach fits your needs? 

I'm currently working on plugin templates and examples for the webpage and documentation and will add the above as another use case. I'm going to release the next version in about 1 or 2 weeks.

Arndt.

2012/4/20 george hu <geo...@gmail.com>

I'm wondering for the current design of Poolyx, is it possible to develop a shopping cart addon for it? Think about a inventory entity in traditional db, is there a way to implement business logic in the CMS? My first impression is that Poolyx is focusing on content only, and as for the natural of traversal pattern in pyramid, is it possible to develop shopping cart in a style like traversal+url dispatch? Coz the major and essential part of the poolyx is traversal,  now we need add url dispatch pattern for it. I can't figure out a way to do it.



--
DV Electric / Arndt Droullier / www.dvelectric.de

george hu

unread,
Apr 20, 2012, 1:33:44 PM4/20/12
to pooly...@googlegroups.com
I think I was confused by "Combining Traversal and URL Dispatch" - 

in the text, "A hybrid application implies that traversal is performed during a request after a route has matched.", so we have the following route pattern,
config.add_route('home', '{foo}/{bar}/*traverse')

which implies "we are using URL dispatch to take care of the hardcoded URLs at the top of the tree, and we are using traversal only for the arbitrarily nested subdirectories."

but in our case is "traversal to a node of the tree, and then use URL dispatch", seems like not possible regarding to the explanation  of the pyramid document. I guess I have difficult to understand the "hybrid application" in pyramid.

Arndt Droullier

unread,
Apr 25, 2012, 8:36:40 AM4/25/12
to pooly...@googlegroups.com
sorry, I've been out of office for a few days.

Using add_rout to reflect a tree structure is not easy.
What kind of urls do you need for your shopping cart? 
Dynamic urls or fix urls like the following:

http://domain.com/cart
http://domain.com/checkout
http://domain.com/confirmation

Arndt.


2012/4/20 george hu <geo...@gmail.com>
I think I was confused by "Combining Traversal and URL Dispatch" - 
Reply all
Reply to author
Forward
0 new messages