add updateProductList listener, update version number

This commit is contained in:
O K
2025-12-02 10:54:23 +02:00
parent 45eeafa1f7
commit a72c8513d1
3 changed files with 49 additions and 43 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
llmdumper.php
.llmdump

View File

@@ -20,7 +20,7 @@ class B2BPayments extends PaymentModule implements PrestaShop\PrestaShop\Core\Mo
{ {
$this->name = 'b2bpayments'; $this->name = 'b2bpayments';
$this->tab = 'payments_gateways'; $this->tab = 'payments_gateways';
$this->version = '1.0.0'; $this->version = '1.0.1';
$this->author = 'panariga'; $this->author = 'panariga';
$this->need_instance = 0; $this->need_instance = 0;
$this->bootstrap = true; $this->bootstrap = true;

View File

@@ -22,38 +22,32 @@
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
prestashop.on('updatedProduct', function(updatedData) {
applyPriceVisibility(priceToggleSelect.value);
});
const priceToggleSelect = document.getElementById('priceDisplayToggle'); const priceToggleSelect = document.getElementById('priceDisplayToggle');
const storageKey = 'priceDisplayPreference'; // Key for localStorage const storageKey = 'priceDisplayPreference'; // Key for localStorage
// --- Core Functions ---
// Function to apply visibility based on preference // Function to apply visibility based on preference
function applyPriceVisibility(preference) { function applyPriceVisibility(preference) {
const vpcElements = document.querySelectorAll('.vpcrender'); const vpcElements = document.querySelectorAll('.vpcrender');
const mpcElements = document.querySelectorAll('.mpcrender'); const mpcElements = document.querySelectorAll('.mpcrender');
console.log('Applying preference:', preference); // For debugging
console.log('Found VPC elements:', vpcElements.length); // For debugging
console.log('Found MPC elements:', mpcElements.length); // For debugging
switch (preference) { switch (preference) {
case 'vpc': case 'vpc':
// Show VPC, Hide MPC // Show VPC, Hide MPC
vpcElements.forEach(el => el.style.display = ''); // Reset to default display (usually block or inline) vpcElements.forEach(el => el.style.display = '');
mpcElements.forEach(el => el.style.display = 'none'); mpcElements.forEach(el => el.style.display = 'none');
break; break;
case 'mpc': case 'mpc':
// Hide VPC, Show MPC // Hide VPC, Show MPC
vpcElements.forEach(el => el.style.display = 'none'); vpcElements.forEach(el => el.style.display = 'none');
mpcElements.forEach(el => el.style.display = ''); // Reset to default display mpcElements.forEach(el => el.style.display = '');
break; break;
case 'both': case 'both':
default: default:
// Show Both // Show Both
vpcElements.forEach(el => el.style.display = ''); // Reset to default display vpcElements.forEach(el => el.style.display = '');
mpcElements.forEach(el => el.style.display = ''); // Reset to default display mpcElements.forEach(el => el.style.display = '');
break; break;
} }
} }
@@ -62,10 +56,8 @@
function savePreference(preference) { function savePreference(preference) {
try { try {
localStorage.setItem(storageKey, preference); localStorage.setItem(storageKey, preference);
console.log('Saved preference:', preference); // For debugging
} catch (e) { } catch (e) {
console.error('Failed to save preference to localStorage:', e); console.error('Failed to save preference to localStorage:', e);
// LocalStorage might be disabled or full
} }
} }
@@ -74,44 +66,56 @@
try { try {
return localStorage.getItem(storageKey); return localStorage.getItem(storageKey);
} catch (e) { } catch (e) {
console.error('Failed to load preference from localStorage:', e); return null;
return null; // Return null if localStorage is inaccessible
} }
} }
// --- Initialization --- // --- Initialization Logic ---
function initSwitcher() {
if (!priceToggleSelect) return;
// 1. Load saved preference or use default
const savedPreference = loadPreference();
const currentPreference = (savedPreference && ['both', 'vpc', 'mpc'].includes(savedPreference))
? savedPreference
: (priceToggleSelect.value || 'both');
// 2. Sync Select Element and Apply
priceToggleSelect.value = currentPreference;
applyPriceVisibility(currentPreference);
}
// --- Event Listeners ---
if (priceToggleSelect) { if (priceToggleSelect) {
// 1. Load saved preference // Initial Load
const savedPreference = loadPreference(); initSwitcher();
// 2. Set the select element's value and apply visibility // User changes the select dropdown
if (savedPreference && ['both', 'vpc', 'mpc'].includes(savedPreference)) { priceToggleSelect.addEventListener('change', function(event) {
priceToggleSelect.value = savedPreference; const selectedPreference = event.target.value;
applyPriceVisibility(savedPreference); applyPriceVisibility(selectedPreference);
} else { savePreference(selectedPreference);
// No valid saved preference, use the default value from the select element });
const initialPreference = priceToggleSelect.value || 'both'; // Fallback to 'both'
applyPriceVisibility(initialPreference);
// Optionally save the default if nothing was stored
// savePreference(initialPreference);
} }
// 3. Add event listener for changes // Hook into PrestaShop Events
priceToggleSelect.addEventListener('change', function(event) {
const selectedPreference = event.target.value; // 1. Product Page: Attribute update (e.g. Size S -> Size L)
applyPriceVisibility(selectedPreference); prestashop.on('updatedProduct', function(updatedData) {
savePreference(selectedPreference); if(priceToggleSelect) {
applyPriceVisibility(priceToggleSelect.value);
}
}); });
} else { // 2. Category/List Page: AJAX Pagination, Sorting, Filter update
console.warn('Price display toggle select element (#priceDisplayToggle) not found.'); prestashop.on('updateProductList', function(data) {
} if(priceToggleSelect) {
// Re-apply the current value of the select box to the newly injected DOM elements
// Initial check in case elements are added dynamically later (less common for prices) applyPriceVisibility(priceToggleSelect.value);
// If you expect prices to load via AJAX *after* DOMContentLoaded, }
// you might need a MutationObserver or trigger applyPriceVisibility again. });
// For standard page loads, the above should be sufficient.
}); });
</script> </script>