Restructure pages for permutations and basket with metadata for is_included_VAT, id_currency, id_region_delivery

This commit is contained in:
2024-04-21 15:13:09 +01:00
parent f1b095ba83
commit bbb7800dc8
40 changed files with 524 additions and 277 deletions

View File

@@ -57,6 +57,8 @@ h5 {
border-bottom-left-radius: 2.5vh;
border-bottom-right-radius: 2.5vh;
flex-wrap: wrap;
font-weight: bold;
font-size: 2vh;
}
/* Style the topnav links */
@@ -82,6 +84,23 @@ h5 {
height: 100%;
}
.topnav select {
padding: 1vh;
margin: 1vh;
border-radius: 1vh;
/* background-color: var(--c_purple_light); */
color: var(--c_purple_dark);
border: 2px solid white;
font-weight: bold;
text-align: center;
}
.topnav select .collapsed {
width: 5vw;
}
.topnav select .expanded {
width: 25vw;
}
/* Create two unequal columns that floats next to each other */
/* Left column */
.leftcolumn {

View File

@@ -81,6 +81,7 @@ function hookupOverlay(idOverlay) {
}
function hookupSelectorCurrency() {
/*
let elForm = $(idFormCurrency);
let elSelector = $(elForm.find('select')[0]);
initialiseEventHandler(elSelector, flagInitialised, function(){
@@ -97,8 +98,43 @@ function hookupSelectorCurrency() {
});
});
console.log("form currency initialised")
*/
let dropdownCurrency = $(idCurrency)[0];
// dropdownCurrency.options.map(function(option) {
let option, indexHyphen, textOption;
for (let indexOption = 0; indexOption < dropdownCurrency.options.length; indexOption++) {
option = $(dropdownCurrency.options[indexOption]);
textOption = option.text();
indexHyphen = textOption.indexOf('-');
option.attr(attrTextExpanded, textOption);
option.attr(attrTextCollapsed, textOption.substring(0, indexHyphen - 1));
option.addClass(flagCollapsed);
}
handleSelectCollapse(dropdownCurrency);
initialiseEventHandler(dropdownCurrency, flagInitialised, function() {
dropdownCurrency = $(dropdownCurrency);
dropdownCurrency.on("focus", function() {
handleSelectExpand(dropdownCurrency);
});
dropdownCurrency.on("blur", function() {
handleSelectCollapse(dropdownCurrency);
});
dropdownCurrency.on("change", function() {
let selectedCurrency = dropdownCurrency.val();
console.log("selected currency: ", selectedCurrency);
let basket = getLocalStorage(keyBasket);
basket[keyIdCurrency] = selectedCurrency;
// setLocalStorage(keyIdCurrency, selectedCurrency);
setLocalStorage(keyBasket, basket);
let ajaxData = {};
ajaxData[keyBasket] = basket;
ajaxJSONData('update currency', mapHashToController(hashPageCurrent), ajaxData, loadPageBody, false);
});
});
}
function hookupSelectorDeliveryRegion() {
/*
let elForm = $(idFormDeliveryRegion);
let elSelector = $(elForm.find('select')[0]);
initialiseEventHandler(elSelector, flagInitialised, function(){
@@ -111,7 +147,62 @@ function hookupSelectorDeliveryRegion() {
});
console.log("form delivery region initialised")
});
*/
let dropdownRegion = $(idRegionDelivery)[0];
let option, indexHyphen, textOption;
for (let indexOption = 0; indexOption < dropdownRegion.options.length; indexOption++) {
option = $(dropdownRegion.options[indexOption]);
textOption = option.text();
indexHyphen = textOption.indexOf('-');
option.attr(attrTextExpanded, textOption);
option.attr(attrTextCollapsed, textOption.substring(0, indexHyphen - 1));
option.addClass(flagCollapsed);
}
handleSelectCollapse(dropdownRegion);
initialiseEventHandler(dropdownRegion, flagInitialised, function() {
dropdownRegion = $(dropdownRegion);
dropdownRegion.on("focus", function() {
console.log("dropdown region focused");
handleSelectExpand(dropdownRegion);
});
dropdownRegion.on("blur", function() {
console.log("dropdown region blurred");
handleSelectCollapse(dropdownRegion);
});
dropdownRegion.on("change", function() {
handleSelectCollapse(dropdownRegion);
let selectedRegion = dropdownRegion.val();
console.log("selected region: ", selectedRegion);
let basket = getLocalStorage(keyBasket);
basket[keyIdRegionDelivery] = selectedRegion;
// setLocalStorage(keyIdRegionDelivery, selectedRegion);
setLocalStorage(keyBasket, basket);
let ajaxData = {};
ajaxData[keyIdRegionDelivery] = selectedRegion;
ajaxJSONData('update region', mapHashToController(hashStoreSetRegion), ajaxData, null, false);
});
});
}
function handleSelectCollapse(elementSelect) {
let optionSelected = $(elementSelect).find('option:selected');
optionSelected.text(optionSelected.attr(attrTextCollapsed));
console.log('collapsed: ', optionSelected.text());
optionSelected.removeClass(flagExpanded);
optionSelected.addClass(flagCollapsed);
}
function handleSelectExpand(elementSelect) {
let optionSelected = $(elementSelect).find('option:selected');
optionSelected.text(optionSelected.attr(attrTextExpanded));
console.log('expanded: ', optionSelected.text());
optionSelected.removeClass(flagCollapsed);
optionSelected.addClass(flagExpanded);
}
function hookupCheckboxIsIncludedVAT() {
let elForm = $(idFormIsIncludedVAT);
let elSelector = $(elForm.find('input[type="checkbox"]')[0]);

View File

@@ -11,7 +11,6 @@ function hookupStore() {
function hookupBasket() {
// const containerBasket = $(idContainerBasket);
toggleShowBtnCheckout(); // containerBasket
hookupBtnCheckout();
hookupBtnsPlusMinus();
@@ -45,13 +44,19 @@ function hookupLocalStorageStore() {
}
if (createNewBasket) {
basket = {'items': []};
basket = {};
basket[keyItems] = [];
basket[keyIsIncludedVAT] = true;
basket[keyIdCurrency] = 1;
basket[keyIdRegionDelivery] = 1;
setLocalStorage(keyBasket, basket);
console.log("new local basket created");
}
let ajaxData = {}
ajaxData[keyBasket] = basket;
// console.log('ajax:' + ajaxData);
// console.log("hookupLocalStorageStore\nhashStoreBasketLoad: " + hashStoreBasketLoad + "\n");
// ajaxData[keyIsIncludedVAT] = getLocalStorage(keyIsIncludedVAT);
console.log('ajax:' + ajaxData);
ajaxJSONData(keyBasket, mapHashToController(hashStoreBasketLoad), ajaxData, loadBasket, false);
}

View File

@@ -178,6 +178,14 @@ BEGIN
SET a_get_inactive_discount = 0;
END IF;
/*
SELECT a_id_user, a_get_all_category, a_ids_category, a_get_inactive_category, a_get_all_product,
a_ids_product, a_get_inactive_product, a_get_first_product_only, a_get_all_product_permutation, a_ids_permutation,
a_get_inactive_permutation, a_get_all_image, a_ids_image, a_get_inactive_image, a_get_first_image_only,
a_get_all_delivery_region, a_ids_delivery_region, a_get_inactive_delivery_region, a_get_all_currency, a_ids_currency,
a_get_inactive_currency, a_get_all_discount, a_ids_discount, a_get_inactive_discount
;
*/
-- Temporary tables
DROP TABLE IF EXISTS tmp_Discount;
@@ -277,7 +285,8 @@ BEGIN
FOREIGN KEY (id_region)
REFERENCES Shop_Region(id_region),
active BIT NOT NULL,
display_order INT NOT NULL
display_order INT NOT NULL,
requires_delivery_option BIT NOT NULL DEFAULT 0
);
CREATE TABLE tmp_Currency (
@@ -506,18 +515,20 @@ BEGIN
INSERT INTO tmp_Delivery_Region (
id_region,
active,
display_order
display_order,
requires_delivery_option
)
WITH RECURSIVE Recursive_CTE_Delivery_Region AS (
SELECT
DR.id_region AS id_region_parent,
NULL AS id_region_child
FROM Shop_Region DR
INNER JOIN Shop_Product_Delivery_Option_Link PDOL
ON DR.id_region = PDOL.id_region
INNER JOIN tmp_Shop_Product t_P
ON PDOL.id_product = t_P.id_product
AND PDOL.id_permutation <=> t_P.id_permutation
NULL AS id_region_child,
CASE WHEN FIND_IN_SET(DR.id_region, a_ids_delivery_region) > 0 THEN 1 ELSE 0 END AS requires_delivery_option
FROM Shop_Product_Currency_Region_Link PCRL
INNER JOIN Shop_Currency C ON PCRL.id_currency = C.id_currency
INNER JOIN tmp_Shop_Product t_P
ON PCRL.id_product <=> t_P.id_product
AND PCRL.id_permutation <=> t_P.id_permutation
INNER JOIN Shop_Region DR ON PCRL.id_region_purchase = DR.id_region
WHERE
(
a_get_all_delivery_region
@@ -525,39 +536,79 @@ BEGIN
)
AND (
a_get_inactive_delivery_region
OR DR.active
OR DR.active = 1
)
UNION
SELECT
DRB.id_region_parent,
DRB.id_region_child
DRB.id_region_child,
0 AS requires_delivery_option
FROM Shop_Region_Branch DRB
INNER JOIN Recursive_CTE_Delivery_Region r_DR
ON DRB.id_region_parent = r_DR.id_region_child
AND (
a_get_inactive_delivery_region
OR DRB.active
OR DRB.active = 1
)
)
SELECT
DR.id_region,
DR.active,
DR.display_order
DR.display_order,
requires_delivery_option
FROM Shop_Region DR
INNER JOIN Recursive_CTE_Delivery_Region r_DR
ON DR.id_region = r_DR.id_region_parent
OR DR.id_region = r_DR.id_region_child
;
/*
select * from tmp_delivery_region;
SELECT *
FROM tmp_Shop_Product t_P
WHERE
/*(
a_get_all_category
OR a_get_all_product
OR a_get_all_product_permutation
)*
FIND_IN_SET(t_P.id_category, a_ids_category) > 0
OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0
;
*/
IF v_has_filter_delivery_region THEN
SET v_ids_permutation_unavailable = (
SELECT GROUP_CONCAT(t_P.id_permutation SEPARATOR ', ')
FROM tmp_Shop_Product t_P
INNER JOIN Shop_Product_Currency_Region_Link PCRL
ON t_P.id_permutation = PCRL.id_permutation
FROM (
SELECT *
FROM tmp_Shop_Product t_P
WHERE
/*(
a_get_all_category
OR a_get_all_produc
OR a_get_all_product_permutation
)*/
FIND_IN_SET(t_P.id_category, a_ids_category) > 0
OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0
) t_P
LEFT JOIN (
SELECT *
FROM Shop_Product_Currency_Region_Link PCRL
WHERE
(
a_get_all_delivery_region
OR FIND_IN_SET(PCRL.id_region_purchase, a_ids_delivery_region) > 0
)
) PCRL
ON t_P.id_product <=> PCRL.id_product
AND t_P.id_permutation <=> PCRL.id_permutation
LEFT JOIN tmp_Delivery_Region t_DR
ON PCRL.id_region_purchase = t_DR.id_region
WHERE ISNULL(t_DR.id_region)
AND t_DR.requires_delivery_option = 1
WHERE
ISNULL(t_DR.id_region)
);
IF NOT ISNULL(v_ids_permutation_unavailable) THEN
INSERT INTO tmp_Msg_Error (
@@ -586,7 +637,7 @@ BEGIN
-- select * from tmp_Shop_Product;
# Currencies
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error) THEN
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN
INSERT INTO tmp_Currency (
id_currency,
active,
@@ -625,14 +676,14 @@ BEGIN
SELECT *
FROM tmp_Shop_Product t_P
WHERE
(
/*(
a_get_all_category
OR a_get_all_product
OR a_get_all_product_permutation
)
AND FIND_IN_SET(t_P.id_category, a_ids_category) = 0
AND FIND_IN_SET(t_P.id_product, a_ids_product) = 0
AND FIND_IN_SET(t_P.id_permutation, a_ids_permutation) = 0
)*/
FIND_IN_SET(t_P.id_category, a_ids_category) > 0
OR FIND_IN_SET(t_P.id_product, a_ids_product) > 0
OR FIND_IN_SET(t_P.id_permutation, a_ids_permutation) > 0
) t_P
INNER JOIN (
SELECT *
@@ -674,30 +725,31 @@ BEGIN
END IF;
# Discounts
INSERT INTO tmp_Discount (
id_discount,
active,
display_order
)
SELECT
D.id_discount,
D.active,
D.display_order
FROM Shop_Discount D
INNER JOIN tmp_Shop_Product t_P
ON D.id_product = t_P.id_product
AND D.id_permutation <=> t_P.id_permutation
WHERE
(
a_get_all_discount
OR FIND_IN_SET(D.id_discount, a_ids_discount) > 0
IF NOT EXISTS (SELECT * FROM tmp_Msg_Error WHERE guid = v_guid) THEN
INSERT INTO tmp_Discount (
id_discount,
active,
display_order
)
AND (
a_get_inactive_discount
OR D.active
)
;
SELECT
D.id_discount,
D.active,
D.display_order
FROM Shop_Discount D
INNER JOIN tmp_Shop_Product t_P
ON D.id_product = t_P.id_product
AND D.id_permutation <=> t_P.id_permutation
WHERE
(
a_get_all_discount
OR FIND_IN_SET(D.id_discount, a_ids_discount) > 0
)
AND (
a_get_inactive_discount
OR D.active
)
;
END IF;
# select 'pre-permission results';
# select * from tmp_Shop_Product;
@@ -725,7 +777,7 @@ BEGIN
DELETE FROM tmp_Shop_Product t_P
WHERE
FIND_IN_SET(t_P.id_product, (SELECT GROUP_CONCAT(UET.id_product SEPARATOR ',') FROM Shop_User_Eval_Temp UET)) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_User_Eval_Temp), '%');
FIND_IN_SET(t_P.id_permutation, (SELECT GROUP_CONCAT(UET.id_permutation SEPARATOR ',') FROM Shop_User_Eval_Temp UET)) = 0 # id_product NOT LIKE CONCAT('%', (SELECT GROUP_CONCAT(id_product SEPARATOR '|') FROM Shop_User_Eval_Temp), '%');
OR (
ISNULL(t_P.can_view)
AND (
@@ -833,6 +885,13 @@ BEGIN
ON t_P.id_permutation = PPVL.id_permutation
ORDER BY t_P.display_order
;
*/
-- select * from Shop_Product_Currency_Region_Link;
-- select * from shop_currency;
/*
select * from tmp_Currency;
select * from tmp_delivery_region;
select * from tmp_shop_product;
*/
# Product Price
@@ -851,8 +910,8 @@ BEGIN
ROW_NUMBER() OVER(ORDER BY t_P.rank_permutation, C.display_order) AS display_order
FROM Shop_Product_Currency_Region_Link PCRL
INNER JOIN tmp_Shop_Product t_P
ON t_P.id_product = PCRL.id_product
AND t_P.id_permutation <=> PCRL.id_permutation
ON PCRL.id_product <=> t_P.id_product
AND PCRL.id_permutation <=> t_P.id_permutation
-- INNER JOIN Shop_Product P ON PCRL.id_product = P.id_product
INNER JOIN tmp_Currency t_C ON PCRL.id_currency = t_C.id_currency
INNER JOIN Shop_Currency C ON t_C.id_currency = C.id_currency
@@ -1056,7 +1115,7 @@ CALL p_shop_get_many_product (
0, # a_get_inactive_product
0, # a_get_first_product_only
1, # a_get_all_product_permutation
'', # a_ids_permutation
'1,2,3,4,5,6', # a_ids_permutation
0, # a_get_inactive_permutation
0, # a_get_all_image
'', # a_ids_image