UX Improvements for Home page and Accessibility Statement page
This commit is contained in:
Binary file not shown.
@@ -18,17 +18,18 @@ Datastore for Store
|
||||
# internal
|
||||
# from routes import bp_home
|
||||
import lib.argument_validation as av
|
||||
from business_objects.category import Category_List, Category
|
||||
from business_objects.product import Product, Product_Permutation, Price, Product_Filters # Permutation_Variation_Link
|
||||
from business_objects.variation import Variation
|
||||
from business_objects.image import Image
|
||||
from business_objects.currency import Currency
|
||||
from business_objects.delivery_region import Delivery_Region
|
||||
from business_objects.delivery_option import Delivery_Option
|
||||
from business_objects.discount import Discount
|
||||
from business_objects.basket import Basket, Basket_Item
|
||||
from business_objects.category import Category_List, Category
|
||||
from business_objects.currency import Currency
|
||||
from business_objects.image import Image
|
||||
from business_objects.delivery_option import Delivery_Option
|
||||
from business_objects.delivery_region import Delivery_Region
|
||||
from business_objects.discount import Discount
|
||||
from business_objects.order import Order
|
||||
from business_objects.product import Product, Product_Permutation, Price, Product_Filters # Permutation_Variation_Link
|
||||
from business_objects.sql_error import SQL_Error
|
||||
from business_objects.stock_item import Stock_Item, Stock_Item_Filters
|
||||
from business_objects.variation import Variation
|
||||
from helpers.helper_db_mysql import Helper_DB_MySQL
|
||||
# from models.model_view_store_checkout import Model_View_Store_Checkout # circular!
|
||||
# external
|
||||
@@ -40,6 +41,7 @@ import os
|
||||
from flask import Flask
|
||||
from pydantic import BaseModel, ConfigDict
|
||||
from typing import ClassVar
|
||||
from datetime import datetime
|
||||
|
||||
# VARIABLE INSTANTIATION
|
||||
|
||||
@@ -528,6 +530,129 @@ class DataStore_Store(BaseModel):
|
||||
ids_permutation.append(msg_error_availability[:index_comma])
|
||||
return ids_permutation
|
||||
|
||||
# Stock Items
|
||||
def get_many_stock_item(self, stock_item_filters):
|
||||
# redundant argument validation?
|
||||
_m = 'DataStore_Store.get_many_stock_item'
|
||||
av.val_instance(stock_item_filters, 'stock_item_filters', _m, Stock_Item_Filters)
|
||||
argument_dict = stock_item_filters.to_json()
|
||||
is_user_logged_in, id_user = self.get_login_user()
|
||||
argument_dict['a_id_user'] = 'auth0|6582b95c895d09a70ba10fef' # id_user
|
||||
print(f'argument_dict: {argument_dict}')
|
||||
print('executing p_shop_get_many_stock_item')
|
||||
result = self.db_procedure_execute('p_shop_get_many_stock_item', argument_dict)
|
||||
cursor = result.cursor
|
||||
print('data received')
|
||||
# categories, category_index = DataStore_Store.input_many_product(cursor)
|
||||
category_list, errors = DataStore_Store.input_many_stock_item(cursor)
|
||||
DataStore_Store.db_cursor_clear(cursor)
|
||||
|
||||
return category_list, errors # categories, category_index
|
||||
|
||||
|
||||
def input_many_stock_item(cursor):
|
||||
_m = 'DataStore_Store.input_many_stock_item'
|
||||
category_list = Category_List()
|
||||
# Categories
|
||||
result_set_1 = cursor.fetchall()
|
||||
print(f'raw categories: {result_set_1}')
|
||||
for row in result_set_1:
|
||||
new_stock_item = Stock_Item.make_from_DB_stock_item(row)
|
||||
# category_list.add_stock_item(new_stock_item, row)
|
||||
try:
|
||||
index_category = category_list.get_index_category_from_id(new_stock_item.id_category)
|
||||
# category_list.add_stock_item(new_stock_item)
|
||||
category = category_list.categories[index_category]
|
||||
"""
|
||||
try:
|
||||
index_product = category.get_index_product_from_id(new_stock_item.id_product)
|
||||
product = category.products[index_product]
|
||||
try:
|
||||
index_permutation = product.get_index_permutation_from_id(new_stock_item.id_permutation)
|
||||
permutation = product.permutations[index_permutation]
|
||||
permutation.add_stock_item(new_stock_item)
|
||||
except KeyError:
|
||||
permutation = Product_Permutation.make_from_DB_stock_item(row)
|
||||
permutation.add_stock_item(new_stock_item)
|
||||
product.add_permutation(permutation)
|
||||
except KeyError:
|
||||
product = Product.make_from_DB_stock_item(row)
|
||||
permutation = Product_Permutation.make_from_DB_stock_item(row)
|
||||
permutation.add_stock_item(new_stock_item)
|
||||
product.add_permutation(permutation)
|
||||
category_list.add_product(product)
|
||||
"""
|
||||
except KeyError:
|
||||
new_category = Category.make_from_DB_stock_item(row)
|
||||
"""
|
||||
product = Product.make_from_DB_stock_item(row)
|
||||
permutation = Product_Permutation.make_from_DB_stock_item(row)
|
||||
permutation.add_stock_item(new_stock_item)
|
||||
product.add_permutation(permutation)
|
||||
new_category.add_product(product)
|
||||
"""
|
||||
category_list.add_category(new_category)
|
||||
try:
|
||||
index_product = category.get_index_product_from_id(new_stock_item.id_product)
|
||||
product = category.products[index_product]
|
||||
except KeyError:
|
||||
new_product = Product.make_from_DB_stock_item(row)
|
||||
category_list.add_product(new_product)
|
||||
try:
|
||||
index_permutation = product.get_index_permutation_from_id(new_stock_item.id_permutation)
|
||||
permutation = product.permutations[index_permutation]
|
||||
permutation.add_stock_item(new_stock_item)
|
||||
except KeyError:
|
||||
new_permutation = Product_Permutation.make_from_DB_stock_item(row)
|
||||
product.add_permutation(new_permutation)
|
||||
category_list.add_stock_item(new_stock_item)
|
||||
|
||||
# Variations
|
||||
cursor.nextset()
|
||||
result_set_3 = cursor.fetchall()
|
||||
variations = []
|
||||
for row in result_set_3:
|
||||
new_variation = Variation.make_from_DB_product(row)
|
||||
variations.append(new_variation)
|
||||
category_list.add_variation(new_variation)
|
||||
|
||||
# Errors
|
||||
cursor.nextset()
|
||||
result_set_e = cursor.fetchall()
|
||||
print(f'raw errors: {result_set_e}')
|
||||
errors = []
|
||||
if len(result_set_e) > 0:
|
||||
errors = [SQL_Error.make_from_DB_record(row) for row in result_set_e] # (row[0], row[1])
|
||||
for error in errors:
|
||||
print(f"Error [{error.code}]: {error.msg}")
|
||||
|
||||
category_list.get_all_variation_trees()
|
||||
"""
|
||||
for category in category_list.categories:
|
||||
print(f'category: {category.name}')
|
||||
for product in category.products:
|
||||
permutation = product.get_permutation_selected()
|
||||
print(f'product: {product.name}\nselected permutation: {permutation}')
|
||||
"""
|
||||
|
||||
if len(errors) > 0:
|
||||
for error in errors:
|
||||
if error.code == 'PRODUCT_AVAILABILITY':
|
||||
ids_permutation_unavailable = DataStore_Store.get_ids_permutation_from_error_availability(error.msg)
|
||||
for id_permutation in ids_permutation_unavailable:
|
||||
index_category = category_list.get_index_category_from_id_permutation(id_permutation)
|
||||
category = category_list.categories[index_category]
|
||||
index_product = category.get_index_product_from_id_permutation(id_permutation)
|
||||
product = category.products[index_product]
|
||||
index_permutation = product.get_index_permutation_from_id(id_permutation)
|
||||
permutation = product.permutations[index_permutation]
|
||||
permutation.is_available = False
|
||||
if 'region' in error.msg or 'currency' in error.msg:
|
||||
permutation.is_unavailable_in_currency_or_region = True
|
||||
|
||||
return category_list, errors # categories, category_index
|
||||
|
||||
|
||||
def get_many_user_order(self, id_user, ids_order, n_order_max, id_checkout_session):
|
||||
_m = 'Model_View_Store.get_many_user_order'
|
||||
# av.val_str(id_user)
|
||||
@@ -767,4 +892,33 @@ class DataStore_Store(BaseModel):
|
||||
id_user = info_user['sub'] if self.is_user_logged_in else None
|
||||
return is_user_logged_in, id_user
|
||||
except:
|
||||
return False, None
|
||||
return False, None
|
||||
|
||||
def save_permutations(self, comment, permutations):
|
||||
_m = 'DataStore_Store.save_permutations'
|
||||
av.val_str(comment, 'comment', _m)
|
||||
av.val_list(permutations, 'list_permutations', _m, Product_Permutation, 1)
|
||||
|
||||
guid = Helper_DB_MySQL.create_guid()
|
||||
now = datetime.now()
|
||||
is_user_logged_in, id_user = self.get_login_user()
|
||||
for permutation in permutations:
|
||||
setattr(permutation, 'guid', guid)
|
||||
setattr(permutation, 'created_on', now)
|
||||
setattr(permutation, 'created_by', id_user)
|
||||
|
||||
cursor = self.db.cursor()
|
||||
cursor.executemany(
|
||||
'INSERT INTO Shop_Product_Permutation_Temp (id_permutation, id_product, description, cost_local, id_currency_cost, profit_local_min, latency_manufacture, quantity_min, quantity_max, quantity_step, quantity_stock, is_subscription, id_recurrence_interval, count_recurrence_interval, id_stripe_product, active, display_order, guid) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)',
|
||||
permutations
|
||||
)
|
||||
self.db.commit()
|
||||
|
||||
argument_dict_list = {
|
||||
'a_id_user': id_user,
|
||||
'a_comment': comment,
|
||||
'a_guid': guid
|
||||
}
|
||||
self.db_procedure_execute('p_shop_save_permutation', argument_dict_list)
|
||||
|
||||
cursor.close()
|
||||
Reference in New Issue
Block a user