My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
**Creating Content Types That Are Buyable, Shippable or Donations**

This document is intended for developers who are working with a particular content type that they want to integrate with GetPaid. For example, if you have a "Product" content type and want it to automatically be buyable in the site wherever it appears.

In addition to making existing content types buyable, donatable or
shippable via the GetPaid setup screens (see creating-buyable-content.txt), content types can be specifically created to be of these
types. The following example shows how to do this:

from Products.Archetypes.public import BaseContent,registerType
from Products.PloneGetPaid.interfaces import IBuyableMarker
from Products.PloneGetPaid.interfaces import IDonatableMarker
from Products.PloneGetPaid.interfaces import IShippableMarker
from zope.interface import implements

class MyBuyable(BaseContent):
implements(IBuyableMarker)
registerType(MyBuyable)

class MyDonatable(BaseContent):
implements(IBuyableMarker)
registerType(MyDonatable)

class MyShippable(BaseContent):
implements(IBuyableMarker)
registerType(MyShippable)



Basic integration of a custom content type
==========================================

A regular custom archetypes content type for books. There are a couple
of fields of interest here - content/book.py::

BookSchema = ...

StringField(
'ISBN',
searchable=True,
required=True,
),

FloatField(
'price',
required=True,
widget = DecimalWidget(
label = u'Price',
description = u'Book listing price in pounds',
size = 8,
),
),

...


Now to wire this up with the getpaid core we need a bit of ZCML -
getpaid/configure.zcml::

<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:five="http://namespaces.zope.org/five"
>

<class class="..content.book.Book">
<implements interface="Products.PloneGetPaid.interfaces.IBuyableMarker"/>
</class>

<adapter
for="..content.interfaces.IBook"
provides="getpaid.core.interfaces.IBuyableContent"
factory=".content.BuyableContentAdapter"
/>

</configure>


The ``<implements />`` entry marks our custom content with the
``IBuyableMarker`` interface so that get paid core knows that books
are buyable.

And the ``<adapter>`` entry registers an adaptor that getpaid core can
use to extract relevant data from a book. Here is the implementation
of that adaptor - getpaid/content.py::

from zope.interface import implements
from getpaid.core.interfaces import IBuyableContent

class BuyableContentAdapter(object):

implements(IBuyableContent)

def __init__(self, context):
self.context = context
self.price = context.getPrice()
self.product_code = context.getISBN()


Change log

r3891 by dglick on Jun 21, 2011   Diff
add unnamed IPaymentProcessor adapter
factory to get the default processor
Go to: 
Project members, sign in to write a code review

Older revisions

r2047 by michael.dunstan on Oct 6, 2008   Diff
- Provide a slightly longer example of
how to integrate an existing
  custom content type.
r2008 by cjj.ifpeople on Sep 19, 2008   Diff
review doc and edit (remove
uncertainty "xxx"). split off part to
development docs folder.
All revisions of this file

File info

Size: 2974 bytes, 97 lines
Powered by Google Project Hosting