Compare commits

...

5 Commits

Author SHA1 Message Date
O K
4101d4df6f fix latest fixes 2025-12-02 14:15:13 +02:00
O K
a72c8513d1 add updateProductList listener, update version number 2025-12-02 10:54:23 +02:00
Mihael
45eeafa1f7 validation - change order status ID for default Prepaid 2025-09-18 12:07:12 +02:00
Mihael
5227a50e01 add hookActionEmailSendBefore to set bankwire details for mail template 2025-07-31 16:46:11 +02:00
Mihael
7458f80c53 validation change order statuses 2025-07-31 16:23:49 +02:00
4 changed files with 138 additions and 104 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;
@@ -44,8 +44,9 @@ class B2BPayments extends PaymentModule implements PrestaShop\PrestaShop\Core\Mo
{ {
if ( if (
!parent::install() || !parent::install() ||
!$this->registerHook('paymentOptions') !$this->registerHook('paymentOptions') ||
|| !$this->registerHook('DisplayOrderConfirmation') !$this->registerHook('DisplayOrderConfirmation') ||
!$this->registerHook('actionEmailSendBefore')
) { ) {
return false; return false;
} }
@@ -411,4 +412,13 @@ class B2BPayments extends PaymentModule implements PrestaShop\PrestaShop\Core\Mo
Context::getContext()->customer = $originalCustomer; Context::getContext()->customer = $originalCustomer;
return $regularPrice; return $regularPrice;
} }
public function hookActionEmailSendBefore($params)
{
if ($params['template'] == 'bankwire_postpaid') {
$params['templateVars']['{bankwire_owner}'] = Configuration::get('BANK_WIRE_OWNER');
$params['templateVars']['{bankwire_details}'] = nl2br(Configuration::get('BANK_WIRE_DETAILS'));
}
}
} }

View File

@@ -36,9 +36,11 @@ class B2BPaymentsValidationModuleFrontController extends ModuleFrontController
$this->context->customer->id; $this->context->customer->id;
$b2b_postpaid_group_id = (int)Configuration::get('B2BPAYMENTS_POSTPAID_GROUP'); $b2b_postpaid_group_id = (int)Configuration::get('B2BPAYMENTS_POSTPAID_GROUP');
$b2b_prepaid_group_id = (int)Configuration::get('B2BPAYMENTS_PREPAID_GROUP'); $b2b_prepaid_group_id = (int)Configuration::get('B2BPAYMENTS_PREPAID_GROUP');
$payment_status = Configuration::get('PS_OS_PAYMENT'); // Default: Payment accepted //$payment_status = Configuration::get('PS_OS_PAYMENT'); // Default: Payment accepted
$payment_status = 16; // Default for Prepaid (Avans) - custom status ID 16
if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_postpaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_postpaid_group_id)) { if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_postpaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_postpaid_group_id)) {
$payment_status = Configuration::get('PS_OS_PREPARATION'); // Order processing in progress. Adjust as needed. //$payment_status = Configuration::get('PS_OS_PREPARATION'); // Order processing in progress. Adjust as needed.
$payment_status = 15; // For Postpaid (Odgoda) - custom status ID 15
$payment_method = $this->module->b2b_postpaid_payment_name; $payment_method = $this->module->b2b_postpaid_payment_name;
} else if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_prepaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_prepaid_group_id)) { } else if ($this->module->isDefaultCustomerGroup($this->context->customer->id, $b2b_prepaid_group_id) && $this->module->isCustomerInGroup($this->context->customer->id, $b2b_prepaid_group_id)) {
//Payment Status Already fine. //Payment Status Already fine.

View File

@@ -1,16 +1,10 @@
{* {*
* Price Display Toggle Template * Price Display Toggle Template
*
* Module: B2bpayments * Module: B2bpayments
* Author: Panariga *}
*
* Provides a select element to switch between showing VPC, MPC, or both prices.
* Saves the user's preference in localStorage.
*}
<div class="price-display-switcher"> <div class="price-display-switcher">
<div id="price-display-switcher" class="payments-selection"> <div id="price-display-switcher" class="payments-selection">
<select id="priceDisplayToggle" name="price_display_preference" class="custom-select"> <select id="priceDisplayToggle" name="price_display_preference" class="custom-select">
{* Default option, selected if nothing is stored or if 'both' is stored *}
<option value="both">{l s='Show VPC & MPC' d='Modules.B2bpayments.ShopBreadcrumb'}</option> <option value="both">{l s='Show VPC & MPC' d='Modules.B2bpayments.ShopBreadcrumb'}</option>
<option value="vpc">{l s='Show VPC only (B2B)' d='Modules.B2bpayments.ShopBreadcrumb'}</option> <option value="vpc">{l s='Show VPC only (B2B)' d='Modules.B2bpayments.ShopBreadcrumb'}</option>
<option value="mpc">{l s='Show MPC only (B2C)' d='Modules.B2bpayments.ShopBreadcrumb'}</option> <option value="mpc">{l s='Show MPC only (B2C)' d='Modules.B2bpayments.ShopBreadcrumb'}</option>
@@ -19,100 +13,126 @@
</div> </div>
{literal} {literal}
<script> <script>
document.addEventListener('DOMContentLoaded', function() { // Define functions in a way that they are accessible when needed.
const b2bStorageKey = 'priceDisplayPreference';
prestashop.on('updatedProduct', function(updatedData) { /**
applyPriceVisibility(priceToggleSelect.value); * Main logic to hide/show prices.
}); * It queries the DOM every time it runs to handle AJAX-injected elements.
* @param {string} preference - The user's choice ('vpc', 'mpc', 'both').
const priceToggleSelect = document.getElementById('priceDisplayToggle'); */
function b2bApplyPriceVisibility(preference) {
const storageKey = 'priceDisplayPreference'; // Key for localStorage
// Function to apply visibility based on 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) { const pref = preference || 'both';
case 'vpc':
// Show VPC, Hide MPC vpcElements.forEach(el => {
vpcElements.forEach(el => el.style.display = ''); // Reset to default display (usually block or inline) el.style.display = (pref === 'mpc') ? 'none' : '';
mpcElements.forEach(el => el.style.display = 'none'); });
break; mpcElements.forEach(el => {
case 'mpc': el.style.display = (pref === 'vpc') ? 'none' : '';
// Hide VPC, Show MPC });
vpcElements.forEach(el => el.style.display = 'none');
mpcElements.forEach(el => el.style.display = ''); // Reset to default display
break;
case 'both':
default:
// Show Both
vpcElements.forEach(el => el.style.display = ''); // Reset to default display
mpcElements.forEach(el => el.style.display = ''); // Reset to default display
break;
}
} }
// Function to save preference to localStorage /**
function savePreference(preference) { * Saves the user's preference to localStorage.
* @param {string} preference
*/
function b2bSavePreference(preference) {
try { try {
localStorage.setItem(storageKey, preference); localStorage.setItem(b2bStorageKey, preference);
console.log('Saved preference:', preference); // For debugging
} catch (e) { } catch (e) {
console.error('Failed to save preference to localStorage:', e); console.error('B2B Payments: LocalStorage is not available.', e);
// LocalStorage might be disabled or full
} }
} }
// Function to load preference from localStorage /**
function loadPreference() { * Loads the user's preference from localStorage.
* @returns {string|null}
*/
function b2bLoadPreference() {
try { try {
return localStorage.getItem(storageKey); return localStorage.getItem(b2bStorageKey);
} catch (e) { } catch (e) {
console.error('Failed to load preference from localStorage:', e); console.error('B2B Payments: LocalStorage is not available.', e);
return null; // Return null if localStorage is inaccessible return null;
} }
} }
// --- Initialization --- /**
* Determines the current price display preference.
* @returns {string}
*/
function b2bGetCurrentPreference() {
const saved = b2bLoadPreference();
if (['both', 'vpc', 'mpc'].includes(saved)) {
return saved;
}
// Fallback to the dropdown's current value if it exists, otherwise default.
const toggle = document.getElementById('priceDisplayToggle');
return toggle ? toggle.value : 'both';
}
/**
* Initializes PrestaShop-specific event listeners.
* This function should only be called after the 'prestashop' object is available.
*/
function initPrestaShopListeners() {
console.log('B2B Payments: Attaching PrestaShop listeners.');
// Event for faceted search, pagination, and sorting updates.
prestashop.on('updateProductList', (data) => {
console.log('B2B Payments: updateProductList event triggered.');
const currentPref = b2bGetCurrentPreference();
// Use a small timeout to ensure the DOM is fully updated by the theme.
setTimeout(() => b2bApplyPriceVisibility(currentPref), 50);
});
// Event for product variant changes on the product page.
prestashop.on('updatedProduct', (data) => {
console.log('B2B Payments: updatedProduct event triggered.');
const currentPref = b2bGetCurrentPreference();
setTimeout(() => b2bApplyPriceVisibility(currentPref), 50);
});
}
// --- Main Execution ---
// This event fires after the initial HTML document has been completely loaded and parsed,
// without waiting for stylesheets, images, and subframes to finish loading.
document.addEventListener('DOMContentLoaded', () => {
const priceToggleSelect = document.getElementById('priceDisplayToggle');
const currentPref = b2bGetCurrentPreference();
// 1. Apply the preference on initial page load.
b2bApplyPriceVisibility(currentPref);
// 2. Setup the dropdown listener if it exists.
if (priceToggleSelect) { if (priceToggleSelect) {
// 1. Load saved preference priceToggleSelect.value = currentPref; // Sync dropdown
const savedPreference = loadPreference(); priceToggleSelect.addEventListener('change', (event) => {
// 2. Set the select element's value and apply visibility
if (savedPreference && ['both', 'vpc', 'mpc'].includes(savedPreference)) {
priceToggleSelect.value = savedPreference;
applyPriceVisibility(savedPreference);
} else {
// 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
priceToggleSelect.addEventListener('change', function(event) {
const selectedPreference = event.target.value; const selectedPreference = event.target.value;
applyPriceVisibility(selectedPreference); b2bSavePreference(selectedPreference);
savePreference(selectedPreference); b2bApplyPriceVisibility(selectedPreference);
}); });
} else {
console.warn('Price display toggle select element (#priceDisplayToggle) not found.');
} }
// Initial check in case elements are added dynamically later (less common for prices) // 3. Wait for PrestaShop's core JS to be ready.
// If you expect prices to load via AJAX *after* DOMContentLoaded, // The 'prestashop' object is often not ready right at DOMContentLoaded.
// you might need a MutationObserver or trigger applyPriceVisibility again. // A robust way is to poll for it.
// For standard page loads, the above should be sufficient. let attempts = 0;
const psReadyCheck = setInterval(() => {
if (typeof prestashop !== 'undefined' && prestashop.on) {
clearInterval(psReadyCheck); // Stop polling
initPrestaShopListeners(); // Initialize listeners
} else if (attempts > 50) { // Stop trying after ~5 seconds
clearInterval(psReadyCheck);
console.warn('B2B Payments: PrestaShop object was not found.');
}
attempts++;
}, 100);
}); });
</script> </script>
{/literal} {/literal}