Best practices for customizing GetPaid

by Christopher Johnson last modified Dec 30, 2008 05:54 PM

We often get asked: "Is there any preferred approach to allow integrators to implement customizations? For instance, if I want to default the billing/shipping addr country, or reorder the form so that country precedes state, etc." GetPaid leverages the Zope 3 best practices for customization. This document explains more about those.

Purpose

Help developers and integrators understand best practices for introducing their customizations to GetPaid, thereby preserving quality in the code and community and making upgrades easier for users.

Prerequisities

A GetPaid installation. Development environment (editor).

Step by step

You may notice that PloneGetPaid and getpaid.core do not use the old skin_path approach to override templates in order to introduce customizations. Since the product is architected entirely with Zope 3, you will need to be familiar with the new ways. In order to change how something behaves or looks in GetPaid, you need to override the view template.

For example, say you had a myecommercesite product. In it, you would have an overrides.zcml which would define custom checkout views or viewlets.

A more detailed example, provided by Lucie:

  • Let's say my product is named MyProduct
  • I want to change the way the cart looks like because I want to add a line at the end of the cart to show if there is a discount or not.
  • In the end, I want to change/override the cart-listing.pt template, so I will create a new cart-listing.py template and put it in my skins folder
  • To do that, I will create an overrides.zcml file in /MyProduct  In this file I will put the following code:
<configure
 
xmlns="http://namespaces.zope.org/zope"
 
xmlns:browser="http://namespaces.zope.org/browser">
 
 
<browser:viewlet
       
name="10cart-listing"
       
manager="Products.PloneGetPaid.interfaces.IGetPaidCartViewletManager"
       
template="skins/cart-listing.pt"
       
class="Products.MyProduct.browser.WRJShoppingCartListing"
       
permission="zope2.View"
       
/>

</configure>
  • Then I need to create the view class that will override the ShoppingCartListing view class (I chose to put it in browser.py):
fromProducts.PloneGetPaid.browser.cart importShoppingCartListing
classWRJShoppingCartListing(ShoppingCartListing):
   
"""
    """

   
template=ZopeTwoPageTemplateFile('skins/cart-listing.pt')
   
   
def __init__( self,*args,**kw):
       
super(WRJShoppingCartListing, self ).__init__(*args,**kw )
  • You just have to restart your instance and you will be able to do the changes you want to the template.

 

Changing the available countries listed on the first checkout page

  • Into my product, in the overrides.zcml file, I had to add this:

<vocabulary
name="getpaid.countries"
factory="Products.MyProduct.vocabularies.Countries"
/>

  • Then into my product, I created a file named vocabularies.py and put the following in it:

from Products.PloneGetPaid.vocabularies import TitledVocabulary
from Products.MyProduct.config import MY_COUNTRIE

def Countries( context ):
return TitledVocabulary.fromTitles(MY_COUNTRIES)

  • And to finish, I put into the config.py file the following (but you can put the countries you want as soon as they have the correct key):

MY_COUNTRIES = [ ('AR', u'ARGENTINA'),
('AU', u'AUSTRALIA'),
('BR', u'BRAZIL'),
('CA', u'CANADA'),
('IL', u'ISRAEL'),
('NZ', u'NEW ZEALAND'),
('GB', u'UNITED KINGDOM'),
('US', u'UNITED STATES'),
('ZA', u'SOUTH AFRICA') ]

Further information

A great example of how to do this is provided by Martin Aspelli in his tutorial and code on Plone 3.0 customization best practices. Find the presentation and code here: http://svn.plone.org/svn/collective/examples/policy-buildout/