def action(self, resource, context, form): cart = ProductCart(context) # Set addresses cart._set_addresses(form['delivery_address'], form['bill_address']) # Set delivery zone addresses = resource.get_resource('addresses').handler delivery_address = addresses.get_record(int(form['delivery_address'])) country_id = addresses.get_record_value(delivery_address, 'country') countries = resource.get_resource('countries').handler country_record = countries.get_record(int(country_id)) cart.set_id_zone(countries.get_record_value(country_record, 'zone')) return context.come_back(MSG_CHANGES_SAVED, ';addresses')
def GET(self, resource, context): # If user has no addresses, redirect to edit_address view cart = ProductCart(context) delivery_address = cart.addresses['delivery_address'] if delivery_address==None: delivery_address = resource.get_user_main_address(context.user.name) if not delivery_address: return context.uri.resolve(';add_address') else: # Set delivery address cart.set_delivery_address(delivery_address.id) # Set delivery zone addresses = resource.get_resource('addresses').handler country_id = addresses.get_record_value(delivery_address, 'country') countries = resource.get_resource('countries').handler country_record = countries.get_record(int(country_id)) cart.set_id_zone( countries.get_record_value(country_record, 'zone')) # Normal return STLView.GET(self, resource, context)
def GET(self, resource, context): # If user has no addresses, redirect to edit_address view cart = ProductCart(context) delivery_address = cart.addresses['delivery_address'] if delivery_address == None: delivery_address = resource.get_user_main_address( context.user.name) if not delivery_address: return context.uri.resolve(';add_address') else: # Set delivery address cart.set_delivery_address(delivery_address.id) # Set delivery zone addresses = resource.get_resource('addresses').handler country_id = addresses.get_record_value( delivery_address, 'country') countries = resource.get_resource('countries').handler country_record = countries.get_record(int(country_id)) cart.set_id_zone( countries.get_record_value(country_record, 'zone')) # Normal return STLView.GET(self, resource, context)