Restructure pages for permutations and basket with metadata for is_included_VAT, id_currency, id_region_delivery
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -38,15 +38,19 @@ class Model_View_Base(ABC):
|
||||
# app: Flask
|
||||
is_page_store: bool
|
||||
# Global constants
|
||||
ATTR_TEXT_COLLAPSED = 'textCollapsed'
|
||||
ATTR_TEXT_EXPANDED = 'textExpanded'
|
||||
FLAG_BUTTON_MODAL_CLOSE = 'btn-overlay-close'
|
||||
FLAG_BUTTON_SUBMIT = 'btn-submit'
|
||||
FLAG_CARD = 'card'
|
||||
FLAG_COLLAPSED = 'collapsed'
|
||||
FLAG_COLLAPSIBLE = 'collapsible'
|
||||
FLAG_COLUMN = 'column'
|
||||
FLAG_CONTAINER = 'container'
|
||||
FLAG_CONTAINER_INPUT = FLAG_CONTAINER + '-input'
|
||||
FLAG_EXPANDED = 'expanded'
|
||||
FLAG_INITIALISED = 'initialised'
|
||||
FLAG_ROW = 'column'
|
||||
FLAG_ROW = 'row'
|
||||
FLAG_SCROLLABLE = 'scrollable'
|
||||
FLAG_SUBMITTED = 'submitted'
|
||||
# flagIsDatePicker = 'is-date-picker'
|
||||
|
||||
@@ -67,26 +67,30 @@ class Model_View_Store(Model_View_Base):
|
||||
ID_BUTTON_CHECKOUT = 'btnCheckout'
|
||||
ID_BUTTON_BASKET_ADD = 'btnBasketAdd'
|
||||
ID_BUTTON_BUY_NOW = 'btnBuyNow'
|
||||
ID_CURRENCY = Form_Currency.id_id_currency # 'id_currency'
|
||||
ID_CURRENCY_DEFAULT = 1
|
||||
ID_LABEL_BASKET_EMPTY = 'basketEmpty'
|
||||
ID_REGION_DELIVERY = Form_Delivery_Region.id_id_region_delivery # 'id_region_delivery'
|
||||
ID_REGION_DELIVERY_DEFAULT = 1
|
||||
IS_INCLUDED_VAT_DEFAULT = True
|
||||
KEY_BASKET = 'basket'
|
||||
KEY_BASKET = Basket.KEY_BASKET # 'basket'
|
||||
# KEY_CODE_CURRENCY = 'code_currency'
|
||||
KEY_FORM = 'form'
|
||||
KEY_ID_CURRENCY = 'id_currency'
|
||||
KEY_ID_CURRENCY = Basket.KEY_ID_CURRENCY # 'id_currency'
|
||||
KEY_ID_PRODUCT = 'product_id'
|
||||
KEY_ID_PERMUTATION = 'permutation_id'
|
||||
KEY_ID_REGION_DELIVERY = 'id_region_delivery'
|
||||
KEY_IS_INCLUDED_VAT = 'is_included_VAT'
|
||||
KEY_ID_REGION_DELIVERY = Basket.KEY_ID_REGION_DELIVERY # 'id_region_delivery'
|
||||
KEY_IS_INCLUDED_VAT = Basket.KEY_IS_INCLUDED_VAT # 'is_included_VAT'
|
||||
KEY_ITEMS = Basket.KEY_ITEMS # 'items'
|
||||
KEY_PRICE = 'price'
|
||||
KEY_QUANTITY = 'quantity'
|
||||
KEY_VALUE_DEFAULT = 'default'
|
||||
TYPE_FORM_BASKET_ADD = 'Form_Basket_Add'
|
||||
TYPE_FORM_BASKET_EDIT = 'Form_Basket_Edit'
|
||||
# development variables
|
||||
# valid_product_id_list = ['prod_PB0NUOSEs06ymG']
|
||||
|
||||
def __new__(cls, db, info_user, app, id_currency, id_region_delivery): # , *args, **kwargs``
|
||||
def __new__(cls, db, info_user, app, id_currency, id_region_delivery, is_included_VAT): # , *args, **kwargs``
|
||||
# Initialiser - validation
|
||||
_m = 'Model_View_Store.__new__'
|
||||
v_arg_type = 'class attribute'
|
||||
@@ -95,26 +99,27 @@ class Model_View_Store(Model_View_Base):
|
||||
# return super().__new__(cls, *args, **kwargs)
|
||||
return super().__new__(cls, db, info_user, app) # Model_View_Store, cls
|
||||
|
||||
def __init__(self, db, info_user, app, id_currency, id_region_delivery):
|
||||
def __init__(self, db, info_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
_m = 'Model_View_Store.__init__'
|
||||
print(f'{_m}\nstarting')
|
||||
super().__init__(db, info_user, app)
|
||||
self.is_page_store = True
|
||||
self.basket = Basket()
|
||||
self.basket = Basket(id_currency, id_region_delivery, is_included_VAT)
|
||||
# self.basket_total = 0
|
||||
# self.db = db
|
||||
# if logged in:
|
||||
# else:
|
||||
self.id_currency = id_currency
|
||||
self.id_region_delivery = id_region_delivery
|
||||
self.is_included_VAT = is_included_VAT
|
||||
self.show_delivery_option = True
|
||||
self.form_is_included_VAT = Form_Is_Included_VAT()
|
||||
regions, currencies = self.get_regions_and_currencies()
|
||||
self.form_currency = Form_Currency()
|
||||
self.form_currency = Form_Currency(id_currency=self.id_currency)
|
||||
self.form_currency.id_currency.choices = [(currency.id_currency, f'{currency.code} - {currency.name}') for currency in currencies]
|
||||
self.form_currency.id_currency.data = str(self.id_currency) if len(currencies) > 0 else None
|
||||
self.form_delivery_region = Form_Delivery_Region()
|
||||
self.form_delivery_region = Form_Delivery_Region(id_region_delivery=self.id_region_delivery)
|
||||
self.form_delivery_region.id_region_delivery.choices = [(region.id_region, f'{region.code} - {region.name}') for region in regions]
|
||||
self.form_delivery_region.id_region_delivery.data = str(self.id_region_delivery) if len(regions) > 0 else None
|
||||
|
||||
@@ -203,14 +208,14 @@ class Model_View_Store(Model_View_Base):
|
||||
# item_added = False
|
||||
print(f'basket: {self.basket}')
|
||||
ids_permutation, quantities_permutation = self.basket.to_csv()
|
||||
self.basket = DataStore_Store(self.db, self.info_user, self.app).edit_basket(ids_permutation, quantities_permutation, permutation_id, quantity, quantity_sum_not_replace, self.app.id_currency, self.app.id_region_delivery)
|
||||
self.basket = DataStore_Store(self.db, self.info_user, self.app).edit_basket(ids_permutation, quantities_permutation, permutation_id, quantity, quantity_sum_not_replace, self.id_currency, self.id_region_delivery, self.is_included_VAT)
|
||||
return True
|
||||
|
||||
def get_basket(self, json_data):
|
||||
self.import_JSON_basket(json_data)
|
||||
if self.is_user_logged_in:
|
||||
ids_permutation, quantities_permutation = self.basket.to_csv()
|
||||
self.basket = DataStore_Store(self.db, self.info_user, self.app).edit_basket(ids_permutation, quantities_permutation, None, None, None, self.app.id_currency, self.app.id_region_delivery)
|
||||
self.basket = DataStore_Store(self.db, self.info_user, self.app).edit_basket(ids_permutation, quantities_permutation, None, None, None, self.id_currency, self.id_region_delivery, self.is_included_VAT)
|
||||
# return self.basket
|
||||
|
||||
def _get_json_basket_id_CSVs_product_permutation(self, basket):
|
||||
@@ -223,8 +228,8 @@ class Model_View_Store(Model_View_Base):
|
||||
product_ids += ','
|
||||
permutation_ids += ','
|
||||
basket_item = basket[index_item]
|
||||
id_product = basket_item[self.key_id_product]
|
||||
id_permutation = basket_item[self.key_id_permutation]
|
||||
id_product = basket_item[self.KEY_ID_PRODUCT]
|
||||
id_permutation = basket_item[self.KEY_ID_PERMUTATION]
|
||||
id_permutation = '' if (id_permutation is None or id_permutation == 'None') else str(id_permutation)
|
||||
product_ids += str(id_product) # str(basket[b].product.id)
|
||||
permutation_ids += id_permutation # str(basket[b].product.id)
|
||||
@@ -235,7 +240,7 @@ class Model_View_Store(Model_View_Base):
|
||||
return product_ids, permutation_ids, item_index_dict
|
||||
|
||||
def _get_basket_from_json(self, json_data):
|
||||
basket = json_data[self.key_basket]['items']
|
||||
basket = json_data[self.KEY_BASKET]['items']
|
||||
av.val_instance(basket, 'basket', 'Model_View_Store._get_basket_from_json', list)
|
||||
print(f'basket = {basket}')
|
||||
return basket
|
||||
@@ -244,6 +249,10 @@ class Model_View_Store(Model_View_Base):
|
||||
_m = 'Model_View_Store.import_JSON_basket'
|
||||
# av.val_instance(db, 'db', _m, SQLAlchemy)
|
||||
items = self._get_basket_from_json(json_data)
|
||||
basket = json_data[self.KEY_BASKET]
|
||||
id_currency = basket[self.KEY_ID_CURRENCY]
|
||||
id_region_delivery = basket[self.KEY_ID_REGION_DELIVERY]
|
||||
is_included_VAT = basket[self.KEY_IS_INCLUDED_VAT]
|
||||
print(f'json basket items: {items}')
|
||||
product_ids, permutation_ids, item_index_dict = self._get_json_basket_id_CSVs_product_permutation(items)
|
||||
category_list, errors = DataStore_Store(self.db, self.info_user, self.app).get_many_product_category(Product_Filters(
|
||||
@@ -252,12 +261,12 @@ class Model_View_Store(Model_View_Base):
|
||||
False, product_ids, False, False, # :a_get_all_product, :a_ids_product, :a_get_inactive_product, :a_get_first_product_only
|
||||
False, permutation_ids, False, # :a_get_all_permutation, :a_ids_permutation, :a_get_inactive_permutation
|
||||
False, '', False, True, # :a_get_all_image, :a_ids_image, :a_get_inactive_image, :a_get_first_image_only
|
||||
False, str(self.app.id_region_delivery), False, # :a_get_all_delivery_region, :a_ids_delivery_region, :a_get_inactive_delivery_region
|
||||
False, str(self.app.id_currency), False, # :a_get_all_currency, :a_ids_currency, :a_get_inactive_currency
|
||||
False, str(id_region_delivery), False, # :a_get_all_delivery_region, :a_ids_delivery_region, :a_get_inactive_delivery_region
|
||||
False, str(id_currency), False, # :a_get_all_currency, :a_ids_currency, :a_get_inactive_currency
|
||||
True, '', False # :a_get_all_discount, :a_ids_discount, :a_get_inactive_discount
|
||||
)) # product_ids=product_ids, get_all_category=False, get_all_product=False)
|
||||
# print(f'categories = {categories}')
|
||||
self.basket = Basket()
|
||||
self.basket = Basket(id_currency, id_region_delivery, is_included_VAT)
|
||||
if len(category_list.categories) > 0: # not (categories is None):
|
||||
for category in category_list.categories:
|
||||
for product in category.products:
|
||||
@@ -265,7 +274,7 @@ class Model_View_Store(Model_View_Base):
|
||||
product.form_basket_edit = Form_Basket_Edit()
|
||||
# key_index_product = Basket.get_key_product_index_from_ids_product_permutation(product.id_product, product.get_id_permutation())
|
||||
permutation = product.get_permutation_selected()
|
||||
self.basket.add_item(Basket_Item.make_from_product_and_quantity_and_VAT_included(product, items[item_index_dict[str(permutation.id_permutation)]][self.key_quantity], self.app.is_included_VAT))
|
||||
self.basket.add_item(Basket_Item.make_from_product_and_quantity_and_VAT_included(product, items[item_index_dict[str(permutation.id_permutation)]][self.KEY_QUANTITY], self.is_included_VAT))
|
||||
"""
|
||||
if len(items) > 0:
|
||||
for index_item in range(len(items)):
|
||||
@@ -317,8 +326,8 @@ class Model_View_Store(Model_View_Base):
|
||||
|
||||
# print(f'product id: {product_id}, type: {str(type(product_id))}')
|
||||
try:
|
||||
permutation_id = json_data[self.key_id_permutation]
|
||||
av.full_val_int(permutation_id, self.key_id_permutation, _m)
|
||||
permutation_id = json_data[self.KEY_ID_PERMUTATION]
|
||||
av.full_val_int(permutation_id, self.KEY_ID_PERMUTATION, _m)
|
||||
permutation_id = int(permutation_id)
|
||||
except:
|
||||
permutation_id = None
|
||||
|
||||
@@ -65,13 +65,13 @@ class Model_View_Store_Basket(Model_View_Store):
|
||||
def title(self):
|
||||
return 'Store Basket'
|
||||
|
||||
def __new__(cls, db, id_user, app, id_currency, id_region_delivery):
|
||||
def __new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Initialiser - validation
|
||||
return super(Model_View_Store_Basket, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery)
|
||||
return super(Model_View_Store_Basket, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
|
||||
def __init__(self, db, id_user, app, id_currency, id_region_delivery):
|
||||
def __init__(self, db, id_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery)
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
# self.product_categories = Model_View_Store_Basket.get_many_product_category(get_all_category = True, get_all_product = True)
|
||||
self.form_billing = Form_Billing()
|
||||
self.form_billing.form_type_billing_not_delivery = True
|
||||
|
||||
@@ -41,13 +41,13 @@ class Model_View_Store_Checkout(Model_View_Store_Basket):
|
||||
def title(self):
|
||||
return 'Store Checkout'
|
||||
|
||||
def __new__(cls, db, id_user, app):
|
||||
def __new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Initialiser - validation
|
||||
return super(Model_View_Store_Checkout, cls).__new__(cls, db, id_user, app)
|
||||
return super(Model_View_Store_Checkout, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
|
||||
def __init__(self, db, id_user, app):
|
||||
def __init__(self, db, id_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
super().__init__(db, id_user, app)
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
self.key_secret_stripe = os.environ.get("KEY_SECRET_STRIPE")
|
||||
self.key_public_stripe = os.environ.get("KEY_PUBLIC_STRIPE")
|
||||
|
||||
|
||||
@@ -40,16 +40,16 @@ class Model_View_Store_Checkout_Success(Model_View_Store_Checkout):
|
||||
def title(self):
|
||||
return 'Store Checkout Success'
|
||||
|
||||
def __new__(cls, db, id_user, app, id_checkout_session, checkout_items = None):
|
||||
def __new__(cls, db, id_user, app, id_checkout_session, checkout_items, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Initialiser - validation
|
||||
_m = 'Model_View_Store_Checkout_Success.__new__'
|
||||
# av.val_list(checkout_items, 'checkout_items', _m)
|
||||
av.val_str(id_checkout_session, 'id_checkout_session', _m)
|
||||
return super(Model_View_Store_Checkout_Success, cls).__new__(cls, db, id_user, app)
|
||||
return super(Model_View_Store_Checkout_Success, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
|
||||
def __init__(self, db, id_user, app, id_checkout_session, checkout_items = None):
|
||||
def __init__(self, db, id_user, app, id_checkout_session, checkout_items, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
super().__init__(db, id_user, app)
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
self.checkout_items = checkout_items
|
||||
self.id_checkout_session = id_checkout_session
|
||||
self.order = self.get_many_user_order('', 1, id_checkout_session)
|
||||
@@ -40,13 +40,13 @@ class Model_View_Store_Home(Model_View_Store):
|
||||
return 'Store Home'
|
||||
max_products_per_category = -1
|
||||
|
||||
def __new__(cls, db, id_user, app, id_currency, id_region_delivery):
|
||||
def __new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Initialiser - validation
|
||||
return super(Model_View_Store_Home, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery)
|
||||
return super(Model_View_Store_Home, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
|
||||
def __init__(self, db, id_user, app, id_currency, id_region_delivery):
|
||||
def __init__(self, db, id_user, app, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery)
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
# self.categories = Model_View_Store_Home.get_many_product_category(self.db, get_all_category = True, get_all_product = True)
|
||||
# self.get_many_product_category(get_all_category = True, get_all_product = True)
|
||||
"""
|
||||
|
||||
@@ -37,7 +37,7 @@ class Model_View_Store_Product(Model_View_Store):
|
||||
def title(self):
|
||||
return 'Store Home'
|
||||
|
||||
def __new__(cls, db, id_user, app, id_permutation, id_currency, id_region_delivery): # *args, **kwargs
|
||||
def __new__(cls, db, id_user, app, id_permutation, id_currency, id_region_delivery, is_included_VAT): # *args, **kwargs
|
||||
# Initialiser - validation
|
||||
_m = 'Model_View_Store_Product.__new__'
|
||||
print(f'{_m}\nstarting...')
|
||||
@@ -51,13 +51,13 @@ class Model_View_Store_Product(Model_View_Store):
|
||||
print(f'ending')
|
||||
|
||||
# return super().__new__(cls, *args, **kwargs) # Model_View_Store_Product, cls # , db, id_user, id_product) # , db, id_user)
|
||||
return super(Model_View_Store_Product, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery)
|
||||
return super(Model_View_Store_Product, cls).__new__(cls, db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
|
||||
def __init__(self, db, id_user, app, id_permutation, id_currency, id_region_delivery):
|
||||
def __init__(self, db, id_user, app, id_permutation, id_currency, id_region_delivery, is_included_VAT):
|
||||
# Constructor
|
||||
_m = 'Model_View_Store_Product.__init__'
|
||||
print(f'{_m}\nstarting...')
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery)
|
||||
super().__init__(db, id_user, app, id_currency, id_region_delivery, is_included_VAT)
|
||||
print('supered')
|
||||
print(f'user info: {self.info_user}')
|
||||
# print(f'user id: {self.info_user.get("sub")}')
|
||||
|
||||
Reference in New Issue
Block a user