**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::
The ```` entry marks our custom content with the
``IBuyableMarker`` interface so that get paid core knows that books
are buyable.
And the ```` 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()