class IShippingBehavior(model.Schema): """Shipping behavior. """ model.fieldset('shop', label=u"Shop", fields=[ 'shipping_item_shippable', 'shipping_item_weight', 'shipping_item_free_shipping' ]) shipping_item_shippable = schema.Bool( title=_(u'label_shipping_item_shippable', default=u'Item Shippable'), description=_('help_shipping_item_shippable', default=u'Flag whether item is shippable, i.e. ' u'downloads are not'), defaultFactory=default_shipping_item_shippable) shipping_item_weight = schema.Float(title=_(u'label_shipping_item_weight', default=u'Item Weight'), required=False) shipping_item_free_shipping = schema.Bool( title=_(u'label_shipping_item_free_shipping', default=u'Free Shipping'), description=_('help_shipping_item_free_shipping', default=u'Flag whether shipping of this item is free.'))
def CurrencyDisplayOptionsVocabulary(context): items = [ ('yes', _('yes', default='Yes')), ('no', _('no', default='No')), ('symbol', _('symbol', default='Symbol')), ] return SimpleVocabulary([SimpleTerm(value=k, title=v) for k, v in items])
def __init__(self, context): permissions = [VIEW_ORDERS_PERMISSION] super(ShopPortletOrdersLink, self).__init__( context, view_permissions=permissions) # check if authenticated user is vendor if self.display and not get_vendors_for(): self.display = False # Find the nearest context, where this functionality can be bound to. def _find_context(ctx): return ctx\ if ISite.providedBy(ctx) or IVendor.providedBy(ctx)\ else _find_context(aq_parent(ctx)) context = _find_context(context) if IPloneSiteRoot.providedBy(context): self.title = _( 'orders_global', default=u'Orders (global)' ) elif ISite.providedBy(context): self.title = _( 'orders_site', default=u'Orders (site-wide)' ) elif IVendor.providedBy(context): self.title = _( 'orders_vendor', default=u'Orders (vendor specific)' ) self.url = '%s/@@orders' % context.absolute_url() self.order = 10 self.cssclass = 'orders'
def __init__(self, context): permissions = [MANAGE_SHOP_PERMISSION] super(ShopPortletControlpanelLink, self).__init__( context, view_permissions=permissions) # Find the nearest context, where this functionality can be bound to. def _find_context(ctx): return ctx\ if ISite.providedBy(ctx)\ else _find_context(aq_parent(ctx)) context = _find_context(context) if IPloneSiteRoot.providedBy(context): self.title = _( 'shop_controlpanel_global', default=u'Shop Controlpanel (global)' ) elif ISite.providedBy(context): self.title = _( 'shop_controlpanel_site', default=u'Shop Controlpanel (site-wide)' ) self.url = '%s/@@shop_controlpanel' % context.absolute_url() self.order = 50 self.cssclass = 'controlpanel'
def __init__(self, context): permissions = [MANAGE_TEAMPLETS_PERMISSION] super(ShopPortletMailTemplatesLink, self).__init__( context, view_permissions=permissions) # Find the nearest context, where this functionality can be bound to. def _find_context(ctx): return ctx\ if ISite.providedBy(ctx) or IVendor.providedBy(ctx)\ else _find_context(aq_parent(ctx)) context = _find_context(context) if IPloneSiteRoot.providedBy(context): self.title = _( 'mailtemplates_global', default=u'Notification Templates (global)' ) elif ISite.providedBy(context): self.title = _( 'mailtemplates_site', default=u'Notification Templates (site-wide)' ) elif IVendor.providedBy(context): self.title = _( 'mailtemplates_vendor', default=u'Notification Templates (vendor specific)' ) self.url = '%s/@@mailtemplates' % context.absolute_url() self.order = 50 self.cssclass = 'mailtemplates'
class GlobalNotificationTextExtender(ExtenderBase): """Schema extender for global notification text. """ layer = IShopExtensionLayer fields = [ XTextField( name='global_order_text', schemata='Shop', default_content_type="text/plain", allowable_content_types=('text/plain', ), default_output_type="text/plain", widget=TextAreaWidget(label=_( u'label_item_global_notification_text', default=u"Additional overall notification text for " u"the order confirmation mail of this item"), ), ), XTextField( name='global_overbook_text', schemata='Shop', default_content_type="text/plain", allowable_content_types=('text/plain', ), default_output_type="text/plain", widget=TextAreaWidget(label=_( u'label_item_global_overbook_notification_text', default=u"Additional overall notification text for " u"the order confirmation mail of this item " u"ordered if out of stock"), ), ), ]
class ItemNotificationTextExtender(ExtenderBase): """Schema extender for notification text. """ layer = IShopExtensionLayer fields = [ XTextField( name='order_text', schemata='Shop', default_content_type="text/plain", allowable_content_types=('text/plain', ), default_output_type="text/plain", widget=TextAreaWidget(label=_( u'label_item_notification_text', default=u"Notification text for this item in the " u"order confirmation mail"), ), ), XTextField( name='overbook_text', schemata='Shop', default_content_type="text/plain", allowable_content_types=('text/plain', ), default_output_type="text/plain", widget=TextAreaWidget(label=_( u'label_item_overbook_notification_text', default=u"Notification text for this item in the " u"order confirmation mail if item is out " u"of stock"), ), ), ]
class IShopTaxSettings(model.Schema): """Shop controlpanel schema for tax settings. """ model.fieldset("tax", label=_(u"Tax Settings"), fields=["vat", "default_item_vat"]) widget("vat", CheckBoxFieldWidget) vat = schema.List( title=_(u"label_vat", default=u"VAT in %"), description=_(u"help_vat", default=u"Specify all allowed vat settings"), required=True, missing_value=set(), value_type=schema.Choice( vocabulary="bda.plone.shop.vocabularies.AvailableVatVocabulary"), ) default_item_vat = schema.Choice( title=_(u"label_default_vat", default=u"Default Value added tax name"), description=_(u"help_default_vat", default=u"Specify default vat name"), vocabulary="bda.plone.shop.vocabularies.VatVocabulary", )
class TradingExtender(ExtenderBase): """Schema extender for trading information. """ layer = IShopExtensionLayer fields = [ XStringField( name='item_number', schemata='Shop', widget=StringWidget( label=_(u'label_item_number', default=u'Item number'), description=_(u'help_item_number', default=u'Buyable Item number') ), ), XStringField( name='gtin', schemata='Shop', widget=StringWidget( label=_(u'label_gtin', default=u'GTIN'), description=_(u'help_gtin', default=u'Global Trade Item Number') ), ), ]
def CurrencyDisplayOptionsVocabulary(context): items = [ ("yes", _("yes", default="Yes")), ("no", _("no", default="No")), ("symbol", _("symbol", default="Symbol")), ] return SimpleVocabulary([SimpleTerm(value=k, title=v) for k, v in items])
class IStockBehavior(model.Schema): """Stock behavior. """ model.fieldset('shop', label=u"Shop", fields=[ 'item_display_stock', 'item_available', 'item_overbook', 'item_stock_warning_threshold' ]) item_display_stock = schema.Bool(title=_(u'label_item_display_stock', default=u'Display item stock'), required=False, defaultFactory=default_item_display_stock) item_available = schema.Float(title=_(u'label_item_available', default=u'Item stock available'), required=False) item_overbook = schema.Float(title=_(u'label_item_overbook', default=u'Item stock overbook'), required=False) item_stock_warning_threshold = schema.Float( title=_(u'label_item_stock_warning_threshold', default=u'Item stock warning threshold.'), required=False, defaultFactory=default_item_stock_warning_threshold)
class ShopSettingsEditForm(controlpanel.RegistryEditForm): schema = IShopSettings label = _(u"Shop settings") description = _(u"") def getContent(self): interfaces = [self.schema] interfaces.extend(self.additionalSchemata) return ContextProxy(interfaces) @property def additionalSchemata(self): registry = getUtility(IRegistry) interface_names = set(record.interfaceName for record in list(registry.records.values())) for name in interface_names: if not name: continue interface = None try: interface = resolve(name) except ImportError: # In case of leftover registry entries of uninstalled Products continue if IShopSettingsProvider.providedBy(interface): yield interface def updateFields(self): super(ShopSettingsEditForm, self).updateFields() def updateWidgets(self): super(ShopSettingsEditForm, self).updateWidgets()
class StockExtender(ExtenderBase): """Schema extender for item stock. """ layer = IShopExtensionLayer fields = [ XBooleanField( name='item_display_stock', schemata='Shop', widget=BooleanField._properties['widget'](label=_( u'label_item_display_stock', default=u'Display item stock'), ), ), XFloatField( name='item_available', schemata='Shop', widget=FloatField._properties['widget'](label=_( u'label_item_available', default=u'Item stock available'), ), ), XFloatField( name='item_overbook', schemata='Shop', widget=FloatField._properties['widget'](label=_( u'label_item_overbook', default=u'Item stock overbook'), ), ), XFloatField( name='item_stock_warning_threshold', schemata='Shop', widget=FloatField._properties['widget'](label=_( u'label_stock_warning_threshold', default=u'Item stock warning threshold.'), ), ), ]
class ILanguageAwareTextRow(model.Schema): lang = schema.Choice( title=_(u"language", default=u"Language"), vocabulary="plone.app.vocabularies.SupportedContentLanguages", required=False, ) text = schema.Text(title=_(u"text", default=u"Text"), required=False)
def validate_set(self, uid): try: buyable = api.content.get(UID=uid) except ValueError: message = _( u'buyable_does_not_exist', default=u'Buyable item with UID {uuid} does not exist.', mapping={'uuid': uid}) return { 'success': False, 'error': message, 'update': True, } # check whether user can modify cart if not api.user.has_permission(permissions.ModifyCart, obj=buyable): remove_item_from_cart(self.request, uid) message = _(u'permission_not_granted_to_buy_item', default=u'Permission to buy ${title} not granted.', mapping={'title': buyable.Title()}) message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } # check buyable period buyable_period = queryAdapter(buyable, IBuyablePeriod) if buyable_period: now = datetime.now() # effective date not reached yet effective = buyable_period.effective if effective and now < effective: remove_item_from_cart(self.request, uid) message = _('item_not_buyable_yet', default=u'Item not buyable yet') message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } # expires date exceed expires = buyable_period.expires if expires and now > expires: remove_item_from_cart(self.request, uid) message = _('item_no_longer_buyable', default=u'Item no longer buyable') message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } return { 'success': True, 'error': '', }
def validate_set(self, uid): try: buyable = api.content.get(UID=uid) except ValueError: message = _( u'buyable_does_not_exist', default=u'Buyable item with UID {uuid} does not exist.', mapping={'uuid': uid}) return { 'success': False, 'error': message, 'update': True, } # check whether user can buy item if not api.user.has_permission(permissions.BuyItems, obj=buyable): remove_item_from_cart(self.request, uid) message = _(u'permission_not_granted_to_buy_item', default=u'Permission to buy ${title} not granted.', mapping={'title': buyable.Title()}) message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } # check buyable period buyable_period = queryAdapter(buyable, IBuyablePeriod) if buyable_period: now = datetime.now() # effective date not reached yet effective = buyable_period.effective if effective and now < effective: remove_item_from_cart(self.request, uid) message = _('item_not_buyable_yet', default=u'Item not buyable yet') message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } # expires date exceed expires = buyable_period.expires if expires and now > expires: remove_item_from_cart(self.request, uid) message = _('item_no_longer_buyable', default=u'Item no longer buyable') message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } return { 'success': True, 'error': '', }
class IPaymentTextSettings(model.Schema): # XXX: rename to IPaymentSettings model.fieldset( "payment", label=_(u"Payment", default=u"Payment"), fields=[ "available_payment_methods", "payment_method", "skip_payment_if_order_contains_reservations", "payment_text", "cash_on_delivery_costs", ], ) available_payment_methods = schema.List( title=_(u"label_available_payment_methods", default=u"Available Payment Methods"), description=_( u"help_available_payment_methods", default=u"Available payment methods in checkout", ), required=True, min_length=1, value_type=schema.Choice(vocabulary="bda.plone.shop.vocabularies." "AvailablePaymentMethodsVocabulary"), ) payment_method = schema.Choice( title=_(u"label_payment_method", default=u"Payment Method"), description=_(u"help_payment_method", default=u"Default payment method in checkout"), vocabulary="bda.plone.shop.vocabularies." "PaymentMethodsVocabulary", ) skip_payment_if_order_contains_reservations = schema.Bool( title=_( u"label_skip_payment_if_order_contains_reservations", default=u"Skip Payment if order contains reservations", ), required=False, ) widget("payment_text", DataGridFieldFactory) payment_text = schema.List( title=_(u"label_payment_text", default=u"Payment Texts"), value_type=DictRow( title=_(u"payment_text", default="Payment Text"), schema=ILanguageAndPaymentAwareTextRow, ), required=False, ) cash_on_delivery_costs = schema.Float( title=_(u"label_cash_on_delivery_costs", default=u"Cash on delivery costs in gross"), required=False, )
class IBuyableBehavior(model.Schema, IBuyable): """Buyable behavior. """ model.fieldset('shop', label=u"Shop", fields=[ 'item_net', 'item_vat', 'item_cart_count_limit', 'item_display_gross', 'item_comment_enabled', 'item_comment_required', 'item_quantity_unit_float', 'item_quantity_unit' ]) item_net = schema.Float(title=_(u'label_item_net', default=u'Item net price'), required=False, defaultFactory=default_item_net) item_vat = schema.Choice( title=_(u'label_item_vat', default=u'Item VAT (in %)'), vocabulary='bda.plone.shop.vocabularies.VatVocabulary', required=False, defaultFactory=default_item_vat) item_cart_count_limit = schema.Float( title=_(u'label_item_cart_count_limit', default=u'Max count of this item in cart'), required=False, defaultFactory=default_item_cart_count_limit) item_display_gross = schema.Bool( title=_(u'label_item_display_gross', default=u'Display Gross Price'), description=_(u'help_item_display_gross', default=u'Show price with taxes included'), required=False, defaultFactory=default_item_display_gross) item_comment_enabled = schema.Bool(title=_(u'label_item_comment_enabled', default='Comment enabled'), required=False, defaultFactory=item_comment_enabled) item_comment_required = schema.Bool( title=_(u'label_item_comment_required', default='Comment required'), required=False, defaultFactory=default_item_comment_required) item_quantity_unit_float = schema.Bool( title=_(u'label_item_quantity_unit_float', default='Quantity as float'), required=False, defaultFactory=default_item_quantity_unit_float) item_quantity_unit = schema.Choice( title=_(u'label_item_quantity_unit', default='Quantity unit'), vocabulary='bda.plone.shop.vocabularies.QuantityUnitVocabulary', required=False, defaultFactory=default_item_quantity_unit)
def __init__(self, context, request): # acquire desired context context = self.acquire_context(context, interfaces=[ISite]) # call super class constructor super(ControlPanelLink, self).__init__(context, request) # set title by context interface if IPloneSiteRoot.providedBy(context): self.title = _("shop_controlpanel_global", default=u"Shop Controlpanel (global)") elif ISite.providedBy(context): self.title = _("shop_controlpanel_site", default=u"Shop Controlpanel (site-wide)") # set target URL self.url = "{}/@@shop_controlpanel".format(context.absolute_url())
class IShopSettings(model.Schema): """Shop controlpanel schema. """ admin_email = schema.ASCIILine( title=_(u"label_admin_email", default=u"Shop Admin E-Mail"), description=_(u"help_admin_email", default=u"No typos please...."), required=True, default="", ) # XXX: change value type to schema.TextLine (needs migration) admin_name = schema.ASCIILine( title=_(u"label_admin_name", default=u"Shop Admin Name"), description=_(u"help_admin_name", default=u"Name used for Shop E-Mails."), required=True, default="", ) add_customer_role_to_new_users = schema.Bool( title=_( u"label_add_customer_role_to_new_users", default=u"Add Customer role to new Users", ), required=False, default=True, ) # XXX: this is an article setting, move to IShopArticleSettings default_item_display_gross = schema.Bool( title=_(u"label_default_item_display_gross", default=u"Display Gross by default"), required=False, ) currency = schema.Choice( title=_(u"label_currency", default="Currency"), description=_(u"help_currency", default=u"Choose the default currency"), vocabulary="bda.plone.shop.vocabularies.AvailableCurrenciesVocabulary", ) show_currency = schema.Choice( title=_(u"label_show_currency", default=u"Show the currency for items"), description=_(u"help_show_currency", default=u""), vocabulary="bda.plone.shop.vocabularies." "CurrencyDisplayOptionsVocabulary", )
class IBuyablePeriodBehavior(model.Schema): """Buyable period behavior. """ model.fieldset('shop', label=u"Shop", fields=['buyable_effective', 'buyable_expires']) buyable_effective = schema.Datetime(title=_( u'label_buyable_effective_date', default=u'Buyable effective date'), required=False) buyable_expires = schema.Datetime(title=_( u'label_buyable_expiration_date', default=u'Buyable expiration date'), required=False)
class ILanguageAndPaymentAwareTextRow(model.Schema): payment = schema.Choice( title=_(u"payment", default=u"Payment"), vocabulary="bda.plone.shop.vocabularies.PaymentMethodsVocabulary", required=False, ) lang = schema.Choice( title=_(u"language", default=u"Language"), vocabulary="plone.app.vocabularies.SupportedContentLanguages", required=False, ) text = schema.Text(title=_(u"text", default=u"Text"), required=False)
class ExportOrdersInContext(ShopNavigationLink): """Link for navigating to ``Export Context Orders`` view. """ id = "shop_export_orders_in_context_link" group = "shop_export_group" permission = EXPORT_ORDERS title = _("exportorders_item", default=u"Export Orders on this Item") order = 41 cssclass = "export_orders_item" def __init__(self, context, request): # acquire desired context interfaces = [IBuyable, IFolder, ISite] context = self.acquire_context(context, interfaces=interfaces) # skip link if context is site if self.context_provides(context, interfaces=[ISite]): self.display = False return # call super class constructor super(ExportOrdersInContext, self).__init__(context, request) # do not display on site if self.display and ISite.providedBy(context): self.display = False return # check if buyables in context if self.display and not self.buyables_in_context(context): self.display = False return # set target URL self.url = "{}/@@exportorders_contextual".format( context.absolute_url())
def completely_exceeded_alert(self): message = _( u"alert_item_no_longer_available", default=u"No longer available, please " u"remove from cart", ) return translate(message, context=self.request)
class BookingsInContextLink(ShopNavigationLink): """Link for navigating to ``Context Bookings`` view. """ id = "shop_bookings_in_context_link" group = "shop_bookings_group" permission = VIEW_ORDERS title = _("bookings_in_context", default=u"Bookings in Context") order = 21 cssclass = "bookings" def __init__(self, context, request): # acquire desired context interfaces = [IBuyable, IFolder, ISite] context = self.acquire_context(context, interfaces=interfaces) # skip link if context is vendor or site if self.context_provides(context, interfaces=[IVendor, ISite]): self.display = False return # call super class constructor super(BookingsInContextLink, self).__init__(context, request) # check if authenticated user is vendor if self.display and not get_vendors_for(): self.display = False return # check if buyables in context if self.display and not self.buyables_in_context(context): self.display = False return # set target URL self.url = "{}/@@bookings".format(context.absolute_url())
def validate_set(self, uid): buyable = get_object_by_uid(self.context, uid) # check whether user can buy item sm = getSecurityManager() if not sm.checkPermission(permissions.BuyItems, buyable): remove_item_from_cart(self.request, uid) message = _(u'permission_not_granted_to_buy_item', default=u'Permission to buy ${title} not granted.', mapping={'title': buyable.Title()}) message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } # check buyable period buyable_period = queryAdapter(buyable, IBuyablePeriod) if buyable_period: now = datetime.now() # effective date not reached yet effective = buyable_period.effective if effective and now < effective: remove_item_from_cart(self.request, uid) message = _('item_not_buyable_yet', default=u'Item not buyable yet') message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } # expires date exceed expires = buyable_period.expires if expires and now > expires: remove_item_from_cart(self.request, uid) message = _('item_no_longer_buyable', default=u'Item no longer buyable') message = translate(message, context=self.request) return { 'success': False, 'error': message, 'update': True, } return { 'success': True, 'error': '', }
class IItemNotificationTextBehavior(model.Schema): model.fieldset('shop', label=u"Shop", fields=['order_text', 'overbook_text']) order_text = schema.Text(title=_( u"label_item_notification_text", default=u"Notification text for this item in order confirmation " u"mail"), required=False) overbook_text = schema.Text(title=_( u"label_item_overbook_notification_text", default=u"Notification text for this item in order confirmation " u"mail if item out of stock"), required=False)
def number_reservations_alert(self, reserved, quantity_unit): message = _(u'alert_item_number_reserved', default=u'${reserved} ${quantity_unit} reserved', mapping={ 'reserved': reserved, 'quantity_unit': quantity_unit }) return translate(message, context=self.request)
def partly_exceeded_alert(self, exceed, quantity_unit): message = _(u'alert_item_number_exceed', default=u'Limit exceed by ${exceed} ${quantity_unit}', mapping={ 'exceed': exceed, 'quantity_unit': quantity_unit }) return translate(message, context=self.request)
def __init__(self, context, request): # acquire desired context context = self.acquire_context(context, interfaces=[IVendor, ISite]) # call super class constructor super(MailTemplatesLink, self).__init__(context, request) # set title by context interface if IPloneSiteRoot.providedBy(context): self.title = _('mailtemplates_global', default=u'Notification Templates (global)') elif ISite.providedBy(context): self.title = _('mailtemplates_site', default=u'Notification Templates (site-wide)') elif IVendor.providedBy(context): self.title = _('mailtemplates_vendor', default=u'Notification Templates (vendor specific)') # set target URL self.url = '{}/@@mailtemplates'.format(context.absolute_url())
class IGlobalNotificationTextBehavior(model.Schema): model.fieldset('shop', label=u"Shop", fields=['global_order_text', 'global_overbook_text']) global_order_text = schema.Text(title=_( u"label_item_global_notification_text", default=u"Additional overall notification text for order " u"confirmation mail if this item in cart"), required=False) global_overbook_text = schema.Text(title=_( u"label_item_global_overbook_notification_text", default=u"Additional overall notification text for order " u"confirmation mail if this item in cart and out of stock"), required=False)
def __init__(self, context): permissions = [EXPORT_ORDERS_PERMISSION] super(ShopPortletExportOrdersLink, self).__init__(context, view_permissions=permissions) site = plone.api.portal.get() self.url = "%s/@@exportorders" % site.absolute_url() self.title = _("exportorders", default=u"Export Orders") self.order = 30 self.cssclass = "export_orders"
class VendorAction(EnableDisableFeature): feature_iface = IVendor potential_feature_iface = IContainer enable_message = _(u'enabled_vendor', u'Enabled Vendor.') disable_message = _(u'disabled_vendor', u'Disabled Vendor.') def enableFeature(self): self.context.manage_permission(permissions.DelegateVendorRole, roles=['Manager', 'Site Administrator'], acquire=0) super(VendorAction, self).enableFeature() def disableFeature(self): self.context.manage_permission(permissions.DelegateVendorRole, roles=[], acquire=0) super(VendorAction, self).disableFeature()
def critical_available_message(self): available = self.available if not get_item_data_provider(self.context).quantity_unit_float: available = int(available) message = _(u'critical_available_message', default=u'Just ${available} items(s) left.', mapping={'available': available}) return message
class ITradingBehavior(model.Schema): """Trading behavior. """ model.fieldset("shop", label=u"Shop", fields=["item_number", "gtin"]) item_number = schema.TextLine( title=_(u"label_item_number", default=u"Item number"), description=_(u"help_item_number", default=u"Buyable Item number"), required=False, ) gtin = schema.TextLine( title=_(u"label_gtin", default=u"GTIN"), description=_(u"help_gtin", default=u"Global Trade Item Number"), required=False, )
def __init__(self, context): permissions = [MANAGE_DISCOUNT_PERMISSION] super(ShopPortletCartDiscountLink, self).__init__(context, view_permissions=permissions) if self.display: self.display = ISite.providedBy(context) self.url = "%s/@@cart_discount" % context.absolute_url() self.title = _("cart_discount", default=u"Cart Discount") self.order = 60 self.cssclass = "cart_discount"
def __init__(self, context): permissions = [MANAGE_DISCOUNT_PERMISSION] super(ShopPortletCartItemDiscountLink, self).__init__(context, view_permissions=permissions) if self.display: self.display = ISite.providedBy(context) or IDiscountSettingsEnabled.providedBy(context) self.url = "%s/@@item_discount" % context.absolute_url() self.title = _("item_discount", default=u"Item Discount") self.order = 70 self.cssclass = "item_discount"
def __init__(self, context, request): # acquire desired context context = self.acquire_context(context, interfaces=[ISite]) # call super class constructor super(ControlPanelLink, self).__init__(context, request) # set title by context interface if IPloneSiteRoot.providedBy(context): self.title = _( 'shop_controlpanel_global', default=u'Shop Controlpanel (global)' ) elif ISite.providedBy(context): self.title = _( 'shop_controlpanel_site', default=u'Shop Controlpanel (site-wide)' ) # set target URL self.url = '{}/@@shop_controlpanel'.format(context.absolute_url())
def __init__(self, context): permissions = [EXPORT_ORDERS_PERMISSION] super(ShopPortletExportOrdersItemLink, self).__init__(context, view_permissions=permissions) if IPloneSiteRoot.providedBy(context): self.display = False return self.url = "%s/@@exportorders_contextual" % self.context.absolute_url() self.title = _("exportorders_item", default=u"Export Orders on this Item") self.order = 40 self.cssclass = "export_orders_item"
def number_reservations_alert(self, reserved, quantity_unit): message = _( u"alert_item_number_reserved", default=u"${reserved} ${quantity_unit} reserved", mapping={ "reserved": reserved, "quantity_unit": quantity_unit }, ) return translate(message, context=self.request)
def purchasable_as_of_message(self): date = ulocalized_time( queryAdapter(self.context, IBuyablePeriod).effective, long_format=1, context=self.context, request=self.request, ) message = _(u'purchasable_as_of_message', default=u'Item is purchasable as of ${date}', mapping={'date': date}) return message
def __init__(self, context): # XXX: buy items permission is meant to control whether a user can buy # a specific item. Change check to whether a user is customer # somewhere in the portal, which is semantically the correct way. permissions = [VIEW_OWN_ORDERS_PERMISSION] super(ShopPortletMyOrdersLink, self).__init__(context, view_permissions=permissions) site = plone.api.portal.get() self.url = "%s/@@myorders" % site.absolute_url() self.title = _("my_orders", default=u"My Orders") self.order = 20 self.cssclass = "myorders"
def full_available_message(self): available = self.available if available is None: available = '' else: if not get_item_data_provider(self.context).quantity_unit_float: available = int(available) message = _(u'full_available_message', default=u'${available} items(s) available.', mapping={'available': available}) return message
def __init__(self, context): permissions = [VIEW_ORDERS_PERMISSION] super(ShopPortletContactsLink, self).__init__(context, view_permissions=permissions) # check if authenticated user is vendor if self.display and not get_vendors_for(): self.display = False site = plone.api.portal.get() self.url = "%s/@@contacts" % site.absolute_url() self.title = _("contacts", default=u"Contacts") self.order = 23 self.cssclass = "bookings"
def __init__(self, context, request): # acquire desired context context = self.acquire_context(context, interfaces=[IVendor, ISite]) # call super class constructor super(BookingsLink, self).__init__(context, request) # check if authenticated user is vendor if self.display and not get_vendors_for(): self.display = False return # set title by context interface if IPloneSiteRoot.providedBy(context): self.title = _('bookings_global', default=u'Bookings (global)') elif ISite.providedBy(context): self.title = _('bookings_site', default=u'Bookings (site-wide)') elif IVendor.providedBy(context): self.title = _( 'bookings_vendor', default=u'Bookings (vendor specific)' ) # set target URL self.url = '{}/@@bookings'.format(context.absolute_url())
def __init__(self, context, request): # acquire desired context context = self.acquire_context(context, interfaces=[IVendor, ISite]) # call super class constructor super(MailTemplatesLink, self).__init__(context, request) # set title by context interface if IPloneSiteRoot.providedBy(context): self.title = _( 'mailtemplates_global', default=u'Notification Templates (global)' ) elif ISite.providedBy(context): self.title = _( 'mailtemplates_site', default=u'Notification Templates (site-wide)' ) elif IVendor.providedBy(context): self.title = _( 'mailtemplates_vendor', default=u'Notification Templates (vendor specific)' ) # set target URL self.url = '{}/@@mailtemplates'.format(context.absolute_url())
def overbook_available_message(self): state = get_item_state(self.context, self.request) overbook = self.stock.overbook if overbook is None: reservable = '' else: reservable = overbook - state.reserved if not get_item_data_provider(self.context).quantity_unit_float: reservable = int(reservable) message = _(u'overbook_available_message', default=u'Item is sold out. You can pre-order ' u'${reservable} items. As soon as item is ' u'available again, it gets delivered.', mapping={'reservable': reservable}) return message
def __init__(self, context): permissions = [VIEW_ORDERS_PERMISSION] super(ShopPortletBookingsInContextLink, self).__init__( context, view_permissions=permissions) # check if authenticated user is vendor if self.display and not get_vendors_for(): self.display = False # Go to appropriate context if not IBuyable.providedBy(context) \ and not IFolder.providedBy(context) \ and not IPloneSiteRoot.providedBy(context): context = context.aq_inner.aq_parent self.url = '%s/@@bookings' % context.absolute_url() self.title = _('bookings_in_context', default=u'Bookings in Context') self.order = 22 self.cssclass = 'bookings'
def __init__(self, context): permissions = [VIEW_ORDERS_PERMISSION] super(ShopPortletOrdersInContextLink, self).__init__(context, view_permissions=permissions) # check if authenticated user is vendor if self.display and not get_vendors_for(): self.display = False # Go to appropriate context if ( not IBuyable.providedBy(context) and not IFolder.providedBy(context) and not IPloneSiteRoot.providedBy(context) ): context = context.aq_inner.aq_parent self.url = "%s/@@orders" % context.absolute_url() self.title = _("orders_in_context", default=u"Orders in Context") self.order = 11 self.cssclass = "orders"
def completely_exceeded_alert(self): message = _(u'alert_item_no_longer_available', default=u'No longer available, please ' u'remove from cart') return translate(message, context=self.request)
from bda.plone.payment import Payments from bda.plone.shipping import Shippings from bda.plone.shop import message_factory as _ from bda.plone.shop.utils import get_shop_article_settings from bda.plone.shop.utils import get_shop_tax_settings from zope.interface import provider from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm from zope.schema.vocabulary import SimpleVocabulary # This are the overall avaiable quantity units which then can be reduced in # control panel. If you need to provide more quantity units add it here or # patch this vocab AVAILABLE_QUANTITY_UNITS = { 'quantity': _('quantity', default='Quantity'), 'meter': _('meter', default='Meter'), 'kilo': _('kilo', default='Kilo'), 'liter': _('liter', default='Liter'), } @provider(IVocabularyFactory) def AvailableQuantityUnitVocabulary(context): # vocab is used in shop settings control panel items = list(AVAILABLE_QUANTITY_UNITS.items()) return SimpleVocabulary([SimpleTerm(value=k, title=v) for k, v in items]) @provider(IVocabularyFactory) def QuantityUnitVocabulary(context):
def description(self): settings = get_shop_shipping_settings() currency = get_shop_settings().currency show_currency = get_shop_settings().show_currency if show_currency == 'symbol': currency = CURRENCY_LITERALS[currency] shipping_limit_from_gross = settings.shipping_limit_from_gross free_shipping_limit = Decimal(str(settings.free_shipping_limit)) flat_shipping_cost = Decimal(str(settings.flat_shipping_cost)) item_shipping_cost = Decimal(str(settings.item_shipping_cost)) shipping_vat = Decimal(str(settings.shipping_vat)) def gross(val): return format_amount(val + (val / Decimal(100) * shipping_vat)) # no shipping costs if not flat_shipping_cost and not item_shipping_cost: return _(u"free_shipping", default=u"Free Shipping") # no free shipping limit if not free_shipping_limit: # flat and item costs defined if flat_shipping_cost and item_shipping_cost: msg = _(u"no_free_shipping_flat_and_item", default=u"Minimum ${flat} ${currency} or ${item} " u"${currency} per item in cart") return Message(msg, mapping={ 'flat': gross(flat_shipping_cost), 'item': gross(item_shipping_cost), 'currency': currency, }) # flat costs only if flat_shipping_cost and not item_shipping_cost: msg = _(u"no_free_shipping_flat_only", default=u"Flat ${flat} ${currency}") return Message(msg, mapping={ 'flat': gross(flat_shipping_cost), 'currency': currency, }) # item costs only if not flat_shipping_cost and item_shipping_cost: msg = _(u"no_free_shipping_item_only", default=u"${item} ${currency} per item in cart") return Message(msg, mapping={ 'item': gross(item_shipping_cost), 'currency': currency, }) # free shipping above limit # flat and item costs defined if flat_shipping_cost and item_shipping_cost: # from gross if shipping_limit_from_gross: msg = _(u"free_shipping_limit_flat_and_item_gross", default=u"Minimum ${flat} ${currency} or " u"${item} ${currency} per item in cart. Free " u"shipping if gross purchase price above " u"${limit} ${currency}") # from net else: msg = _(u"free_shipping_limit_flat_and_item_net", default=u"Minimum ${flat} ${currency} or " u"${item} ${currency} per item in cart. Free " u"shipping if net purchase price above " u"${limit} ${currency}") return Message(msg, mapping={ 'flat': gross(flat_shipping_cost), 'item': gross(item_shipping_cost), 'limit': format_amount(free_shipping_limit), 'currency': currency, }) # flat costs only if flat_shipping_cost and not item_shipping_cost: # from gross if shipping_limit_from_gross: msg = _(u"free_shipping_limit_flat_only_gross", default=u"Flat ${flat} ${currency}. Free " u"shipping if gross purchase price above " u"${limit} ${currency}") # from net else: msg = _(u"free_shipping_limit_flat_only_net", default=u"Flat ${flat} ${currency}. Free " u"shipping if net purchase price above " u"${limit} ${currency}") return Message(msg, mapping={ 'flat': gross(flat_shipping_cost), 'limit': format_amount(free_shipping_limit), 'currency': currency, }) # item costs only if not flat_shipping_cost and item_shipping_cost: # from gross if shipping_limit_from_gross: msg = _(u"free_shipping_limit_item_only_gross", default=u"${item} ${currency} per item in " u"cart. Free shipping if gross purchase " u"price above ${limit} ${currency}") # from net else: msg = _(u"free_shipping_limit_item_only_net", default=u"${item} ${currency} per item in " u"cart. Free shipping if net purchase " u"price above ${limit} ${currency}") return Message(msg, mapping={ 'item': gross(item_shipping_cost), 'limit': format_amount(free_shipping_limit), 'currency': currency, })
def description(self): return _('cash_and_carry_descripton', default='Customer picks up goods at dealer\'s place')
def number_reservations_alert(self, reserved, quantity_unit): message = _(u'alert_item_number_reserved', default=u'${reserved} ${quantity_unit} reserved', mapping={'reserved': reserved, 'quantity_unit': quantity_unit}) return translate(message, context=self.request)
def partly_exceeded_alert(self, exceed, quantity_unit): message = _(u'alert_item_number_exceed', default=u'Limit exceed by ${exceed} ${quantity_unit}', mapping={'exceed': exceed, 'quantity_unit': quantity_unit}) return translate(message, context=self.request)
def some_reservations_alert(self): message = _(u'alert_item_some_reserved', default=u'Partly reserved') return translate(message, context=self.request)
def description(self): return _('shipping_calculated_separately', default='Shipping will be calculated separately')