def get_items(self, resource, context): items = [] for payment_way in resource.search_resources(cls=PaymentWay): name = payment_way.name logo = '<img src="./%s/%s/;download"/>' % (name, payment_way.get_property('logo')) kw = {'enabled': bool_to_img(payment_way.get_property('enabled')), 'logo': XMLParser(logo), 'title': (payment_way.get_title(), name), 'description': payment_way.get_property('description')} items.append(kw) return items
def get_items(self, resource, context): items = [] for payment_way in resource.search_resources(cls=PaymentWay): name = payment_way.name logo = '<img src="./%s/%s/;download"/>' % ( name, payment_way.get_property('logo')) kw = { 'enabled': bool_to_img(payment_way.get_property('enabled')), 'logo': XMLParser(logo), 'title': (payment_way.get_title(), name), 'description': payment_way.get_property('description') } items.append(kw) return items
def get_items(self, resource, context): shop = get_shop(resource) items = [] groups = [] # Get list of groups for option in UserGroup_Enumerate.get_options(): group = context.root.get_resource(option['name']) groups.append(group) # Get all declinations for declination in resource.search_resources(cls=Declination): name = declination.name title = declination.get_property('title') if not title: title = declination.get_declination_title() kw = {'checkbox': (name, True), 'title': (title, name)} for key in ['reference', 'stock-quantity']: kw[key] = declination.get_property(key) declination_dynamic_schema = declination.get_dynamic_schema() for name, datatype in declination_dynamic_schema.items(): value = declination.get_dynamic_property(name, declination_dynamic_schema) if value: kw[name] = datatype.get_value(value) else: kw[name] = None # Img img = None#declination.get_property('associated-image') if img: img = context.get_link(context.root.get_resource(img)) kw['img'] = XMLParser('<img src="%s/;thumb?width=150&height=150"/>' % img) else: kw['img'] = None # Barcode shop_uri = context.resource.get_pathto(shop) reference = declination.get_property('reference') kw['barcode'] = XMLParser('<img src="%s/;barcode?reference=%s"/>' % (shop_uri, reference)) # Weight base_weight = resource.get_property('weight') weight_impact = declination.get_property('impact-on-weight') weight_value = declination.get_property('weight-impact-value') if weight_impact == 'none': kw['weight'] = u'%s ' % base_weight elif weight_impact == 'increase': kw['weight'] = u'%s kg' % (base_weight + weight_value) kw['weight'] += u' (+ %s kg)' % (base_weight + weight_value) elif weight_impact == 'decrease': kw['weight'] = u'%s kg' % (base_weight - weight_value) kw['weight'] += u' (- %s kg)' % (base_weight - weight_value) # Price for group in groups: if group.get_property('use_default_price') is True: continue k_price = {'id_declination': declination.name, 'prefix': group.get_prefix(), 'pretty': True} if group.get_property('show_ht_price'): price = resource.get_price_without_tax(**k_price) else: price = resource.get_price_with_tax(**k_price) kw['price-%s' % group.name] = price # Default ? is_default = declination.get_property('is_default') kw['is_default'] = bool_to_img(is_default) items.append(kw) return items
def get_namespace(self, resource, context): resource_zones = resource.get_resource('../countries-zones') handler_countries = resource.get_resource('../countries').handler if self.show_inactive: page_title = MSG('Inactives shippings prices') else: page_title = MSG('Shippings price') namespace = { 'zones': [], 'msg_if_no_shipping': resource.get_property('msg_if_no_shipping'), 'page_title': page_title } for zone in resource_zones.handler.get_records_in_order(): countries = [] for country in handler_countries.search(zone=str(zone.id)): title = handler_countries.get_record_value(country, 'title') if handler_countries.get_record_value(country, 'enabled') is False: continue countries.append(title) if len(countries) == 0: continue zone_title = resource_zones.handler.get_record_value(zone, 'title') tarifications = [] for tarification in resource.get_resources(): # We show only active or inactives modes, depending on config if tarification.get_property('enabled') is self.show_inactive: continue mode = tarification.get_property('mode') unit = MSG(u'Kg') if mode == 'weight' else MSG(u'Unit') prices = [] min = old_price = 0 prices_resource = tarification.get_resource('prices') prices_handler = prices_resource.handler tarif_edit = context.get_link(prices_resource) tarif_edit += '/?zone=%i&search=' % zone.id records = prices_handler.search(zone=str(zone.id)) records.sort(key=lambda x: prices_handler.get_record_value( x, 'max-%s' % mode)) for price in records: max = prices_handler.get_record_value( price, 'max-%s' % mode) price = prices_handler.get_record_value(price, 'price') prices.append({ 'title': '%s to %s %s' % (min, max, unit.gettext()), 'price': price, 'error': price <= old_price }) min = max old_price = price if len(prices) == 0: continue kw = { 'name': tarification.name, 'models': [], 'title': tarification.get_title(), 'img': tarification.get_property('logo'), 'is_free': tarification.get_property('is_free'), 'prices': prices, 'description': tarification.get_property('description'), 'tarif_edit': tarif_edit } models = tarification.get_property('only_this_models') for model_abspath in models: model = context.root.get_resource(model_abspath) kw['models'].append(model.get_title()) tarifications.append(kw) zone_edit = '/shop/countries?zone=%i&search=' % zone.id has_tax = resource_zones.handler.get_record_value(zone, 'has_tax') tax_image = list(bool_to_img(has_tax)) namespace['zones'].append({ 'title': zone_title, 'countries': countries, 'tarifications': tarifications, 'zone_edit': zone_edit, 'tax_image': tax_image }) return namespace
def get_namespace(self, resource, context): resource_zones = resource.get_resource('../countries-zones') handler_countries = resource.get_resource('../countries').handler if self.show_inactive: page_title = MSG('Inactives shippings prices') else: page_title = MSG('Shippings price') namespace = { 'zones': [], 'msg_if_no_shipping': resource.get_property('msg_if_no_shipping'), 'page_title': page_title} for zone in resource_zones.handler.get_records_in_order(): countries = [] for country in handler_countries.search(zone=str(zone.id)): title = handler_countries.get_record_value(country, 'title') if handler_countries.get_record_value(country, 'enabled') is False: continue countries.append(title) if len(countries) == 0: continue zone_title = resource_zones.handler.get_record_value(zone, 'title') tarifications = [] for tarification in resource.get_resources(): # We show only active or inactives modes, depending on config if tarification.get_property('enabled') is self.show_inactive: continue mode = tarification.get_property('mode') unit = MSG(u'Kg') if mode == 'weight' else MSG(u'Unit') prices = [] min = old_price = 0 prices_resource = tarification.get_resource('prices') prices_handler = prices_resource.handler tarif_edit = context.get_link(prices_resource) tarif_edit += '/?zone=%i&search=' % zone.id records = prices_handler.search(zone=str(zone.id)) records.sort(key=lambda x: prices_handler.get_record_value(x, 'max-%s' % mode)) for price in records: max = prices_handler.get_record_value(price, 'max-%s' % mode) price = prices_handler.get_record_value(price, 'price') prices.append( {'title': '%s to %s %s' % (min, max, unit.gettext()), 'price': price, 'error': price<=old_price}) min = max old_price = price if len(prices) == 0: continue kw = { 'name': tarification.name, 'models': [], 'title': tarification.get_title(), 'img': tarification.get_property('logo'), 'is_free': tarification.get_property('is_free'), 'prices': prices, 'description': tarification.get_property('description'), 'tarif_edit': tarif_edit} models = tarification.get_property('only_this_models') for model_abspath in models: model = context.root.get_resource(model_abspath) kw['models'].append(model.get_title()) tarifications.append(kw) zone_edit = '/shop/countries?zone=%i&search=' % zone.id has_tax = resource_zones.handler.get_record_value(zone, 'has_tax') tax_image = list(bool_to_img(has_tax)) namespace['zones'].append({'title': zone_title, 'countries': countries, 'tarifications': tarifications, 'zone_edit': zone_edit, 'tax_image': tax_image}) return namespace