payfrit-works/api/admin/fixBigDeansModifiers.cfm
John Mizerek 51a80b537d Add local dev support and fix menu builder API
Portal local development:
- Add BASE_PATH detection to all portal files (login, portal.js, menu-builder, station-assignment)
- Allows portal to work at /biz.payfrit.com/ path locally

Menu Builder fixes:
- Fix duplicate template options in getForBuilder.cfm query
- Filter template children by business ID with DISTINCT

New APIs:
- api/portal/myBusinesses.cfm - List businesses for logged-in user
- api/stations/list.cfm - List KDS stations
- api/menu/updateStations.cfm - Update item station assignments
- api/setup/reimportBigDeans.cfm - Full Big Dean's menu import script

Admin utilities:
- Various debug and migration scripts for menu/template management
- Beacon switching, category cleanup, modifier template setup

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-04 22:47:12 -08:00

84 lines
3.1 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
bizId = 27;
dryRun = structKeyExists(url, "dryRun") ? true : false;
// These modifier templates were incorrectly deactivated
// We need to reactivate and link them to burgers
modifierTemplates = {
// For burgers: need "Extras" with Add Cheese option
"11196": { name: "Extras", children: "Add Cheese, Add Onions", linkToBurgers: true },
// There's already an active "Onions" (11267), so we don't need 11220
};
// Burger items that need modifiers
burgerIds = [11286, 11287, 11288, 11289, 11290]; // Big Dean's, Single w/Cheese, Single, Beyond, Garden
actions = [];
// First, let's see what templates already exist and are active for burgers
qExistingLinks = queryExecute("
SELECT tl.ItemID as MenuItemID, tl.TemplateItemID, t.ItemName as TemplateName
FROM ItemTemplateLinks tl
JOIN Items t ON t.ItemID = tl.TemplateItemID
WHERE tl.ItemID IN (:burgerIds)
", { burgerIds: { value: arrayToList(burgerIds), list: true } }, { datasource: "payfrit" });
for (row in qExistingLinks) {
arrayAppend(actions, { action: "EXISTS", menuItemID: row.MenuItemID, templateID: row.TemplateItemID, templateName: row.TemplateName });
}
// Reactivate template 11196 (Extras with Add Cheese)
if (!dryRun) {
queryExecute("UPDATE Items SET ItemIsActive = 1 WHERE ItemID = 11196", {}, { datasource: "payfrit" });
queryExecute("UPDATE Items SET ItemIsActive = 1 WHERE ItemParentItemID = 11196", {}, { datasource: "payfrit" });
}
arrayAppend(actions, { action: dryRun ? "WOULD_REACTIVATE" : "REACTIVATED", itemID: 11196, name: "Extras (Add Cheese, Add Onions)" });
// Link template 11196 to all burgers
for (burgerId in burgerIds) {
// Check if link already exists
qCheck = queryExecute("
SELECT COUNT(*) as cnt FROM ItemTemplateLinks WHERE ItemID = :burgerId AND TemplateItemID = 11196
", { burgerId: burgerId }, { datasource: "payfrit" });
if (qCheck.cnt EQ 0) {
if (!dryRun) {
queryExecute("
INSERT INTO ItemTemplateLinks (ItemID, TemplateItemID, SortOrder)
VALUES (:burgerId, 11196, 2)
", { burgerId: burgerId }, { datasource: "payfrit" });
}
arrayAppend(actions, { action: dryRun ? "WOULD_LINK" : "LINKED", menuItemID: burgerId, templateID: 11196 });
}
}
// Verify the result
if (!dryRun) {
qVerify = queryExecute("
SELECT mi.ItemID, mi.ItemName, GROUP_CONCAT(t.ItemName ORDER BY tl.SortOrder) as Templates
FROM Items mi
LEFT JOIN ItemTemplateLinks tl ON tl.ItemID = mi.ItemID
LEFT JOIN Items t ON t.ItemID = tl.TemplateItemID
WHERE mi.ItemID IN (:burgerIds)
GROUP BY mi.ItemID, mi.ItemName
", { burgerIds: { value: arrayToList(burgerIds), list: true } }, { datasource: "payfrit" });
result = [];
for (row in qVerify) {
arrayAppend(result, { itemID: row.ItemID, name: row.ItemName, templates: row.Templates });
}
} else {
result = "Dry run - no changes made";
}
writeOutput(serializeJSON({
"OK": true,
"DryRun": dryRun,
"Actions": actions,
"BurgersAfterFix": result
}));
</cfscript>