Skip to content

Commit

Permalink
default registry settings on installation
Browse files Browse the repository at this point in the history
  • Loading branch information
petschki committed Apr 17, 2024
1 parent 02cbc3b commit 6671fda
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/bda/plone/shop/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@
name="shop_controlpanel"
for="zope.component.interfaces.ISite"
class=".controlpanel.ShopSettingsControlPanel"
permission="cmf.ManagePortal" />
permission="cmf.ManagePortal"
layer="..interfaces.IShopExtensionLayer" />

<!-- generic resources -->
<browser:resourceDirectory
Expand Down
6 changes: 5 additions & 1 deletion src/bda/plone/shop/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class IShopArticleSettings(model.Schema):
default="Quantity units (what the buyable items are measured in)",
),
required=False,
default=["quantity"],
missing_value=set(["quantity"]),
value_type=schema.Choice(
vocabulary="bda.plone.shop.vocabularies.AvailableQuantityUnitVocabulary"
Expand All @@ -209,6 +210,7 @@ class IShopArticleSettings(model.Schema):
),
description=_("help_default_quantity_unit", default="default measurement"),
vocabulary="bda.plone.shop.vocabularies.QuantityUnitVocabulary",
default="quantity",
)

default_item_net = schema.Decimal(
Expand Down Expand Up @@ -307,6 +309,7 @@ class IShopShippingSettings(model.Schema):
default="Available shipping methods in checkout",
),
required=True,
default=["default_shipping", ],
min_length=1,
value_type=schema.Choice(
vocabulary="bda.plone.shop.vocabularies."
Expand Down Expand Up @@ -394,7 +397,7 @@ class IShopTaxSettings(model.Schema):
title=_("label_vat", default="VAT in %"),
description=_("help_vat", default="Specify all allowed vat settings"),
required=False,
missing_value=set([0]),
default=["0", "20"],
value_type=schema.Choice(
vocabulary="bda.plone.shop.vocabularies.AvailableVatVocabulary"
),
Expand Down Expand Up @@ -646,6 +649,7 @@ class IPaymentTextSettings(model.Schema):
default="Available payment methods in checkout",
),
required=True,
default=["invoice", ],
min_length=1,
value_type=schema.Choice(
vocabulary="bda.plone.shop.vocabularies."
Expand Down
15 changes: 15 additions & 0 deletions src/bda/plone/shop/setuphandlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding:utf-8 -*-
from bda.plone.shop.user.properties import PAS_ID
from bda.plone.shop.user.properties import UserPropertiesPASPlugin
from bda.plone.shop.vocabularies import AVAILABLE_VAT_VALUES
from plone import api
from plone.base.interfaces import INonInstallable
from Products.PluggableAuthService.interfaces.plugins import IPropertiesPlugin
Expand Down Expand Up @@ -69,6 +70,20 @@ def install(context):
pas = api.portal.get_tool(name="acl_users")
logger.info(add_plugin(pas))

# add sane defaults on installation
api.portal.set_registry_record(
"bda.plone.shop.interfaces.IShopTaxSettings.vat",
AVAILABLE_VAT_VALUES.keys(),
)
api.portal.set_registry_record(
"bda.plone.shop.interfaces.IShopSettings.admin_email",
api.portal.get_registry_record("plone.email_from_address", default="")
)
api.portal.set_registry_record(
"bda.plone.shop.interfaces.IShopSettings.admin_name",
api.portal.get_registry_record("plone.email_from_name", default="")
)


def uninstall(context):
"""
Expand Down
16 changes: 8 additions & 8 deletions src/bda/plone/shop/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ def format_amount(val):


def get_shop_settings():
return getUtility(IRegistry).forInterface(IShopSettings)
return getUtility(IRegistry).forInterface(IShopSettings, check=False)


def get_shop_tax_settings():
return getUtility(IRegistry).forInterface(IShopTaxSettings)
return getUtility(IRegistry).forInterface(IShopTaxSettings, check=False)


def get_shop_article_settings():
return getUtility(IRegistry).forInterface(IShopArticleSettings)
return getUtility(IRegistry).forInterface(IShopArticleSettings, check=False)


def get_shop_cart_settings():
return getUtility(IRegistry).forInterface(IShopCartSettings)
return getUtility(IRegistry).forInterface(IShopCartSettings, check=False)


def get_shop_shipping_settings():
return getUtility(IRegistry).forInterface(IShopShippingSettings)
return getUtility(IRegistry).forInterface(IShopShippingSettings, check=False)


def get_shop_notification_settings():
return getUtility(IRegistry).forInterface(INotificationTextSettings)
return getUtility(IRegistry).forInterface(INotificationTextSettings, check=False)


def get_shop_invoice_settings():
return getUtility(IRegistry).forInterface(IInvoiceSettings)
return getUtility(IRegistry).forInterface(IInvoiceSettings, check=False)


def get_shop_payment_settings():
return getUtility(IRegistry).forInterface(IPaymentTextSettings)
return getUtility(IRegistry).forInterface(IPaymentTextSettings, check=False)
2 changes: 1 addition & 1 deletion src/bda/plone/shop/vocabularies.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def QuantityUnitVocabulary(context):
def AvailableVatVocabulary(context):
# vocab is used in shop settings control panel
items = list(AVAILABLE_VAT_VALUES.items())
items = sorted(items, key=lambda x: x[0])
items.sort(key=lambda x: x[0])
return SimpleVocabulary([SimpleTerm(value=k, title=v) for k, v in items])


Expand Down

0 comments on commit 6671fda

Please sign in to comment.