Improve dynamic terminal selection with AJAX loading#310
Improve dynamic terminal selection with AJAX loading#310TLabutis wants to merge 1 commit intorelease-2.0.3from
Conversation
Summary of ChangesHello @TLabutis, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the configuration experience for SaferPay terminals within the admin panel. It transitions the terminal selection process from a static list to a dynamic, AJAX-driven mechanism, enabling administrators to fetch and select terminals in real-time. The addition of a manual input field and a refresh button further improves flexibility and usability, making the terminal setup more robust and user-friendly. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant improvement by dynamically loading SaferPay terminals via AJAX, enhancing the user experience in the admin settings. The implementation correctly uses debouncing for performance and provides good UI feedback. However, there are several critical issues that need to be addressed before merging. A fatal error will occur when fetching terminals due to a method signature mismatch between the controller and the service. The JavaScript file contains leftover debugging code, including an alert() that will block the UI, and a bug in the form submission logic. I've left detailed comments on these points.
| /** @var SaferPayTerminalService $terminalService */ | ||
| $terminalService = $this->module->getService(SaferPayTerminalService::class); | ||
|
|
||
| $terminals = $terminalService->getAvailableTerminals($customerId, $username, $password, $isTestMode); |
There was a problem hiding this comment.
The getAvailableTerminals method is called with four arguments ($customerId, $username, $password, $isTestMode), but its definition in SaferPayTerminalService only accepts one optional argument ($customerId). This will cause a fatal error.
The SaferPayTerminalService::getAvailableTerminals method needs to be updated to accept these new parameters and use them to make the API request with the correct credentials and environment, instead of relying on the stored configuration values.
| console.log('[DEBUG] Making AJAX request with params:', Object.assign({}, params, {password: '***'})); | ||
| // #endregion | ||
|
|
||
| alert('Customer ID before AJAX: ' + customerId); // Temporary debug alert |
|
|
||
| $('form').on('submit', function() { | ||
| if ($manualInput.val() && !$select.val()) { | ||
| var manualValue = $(this).val(); |
There was a problem hiding this comment.
There is a bug in the form submit handler. $(this).val() is being used to get the value of the manual input, but this refers to the form element, not the input. This will not retrieve the correct value. You should use $manualInput.val() instead.
| var manualValue = $(this).val(); | |
| var manualValue = $manualInput.val(); |
| // #region agent log | ||
| console.log('[DEBUG] saferpay_settings.js loaded'); | ||
| // #endregion |
There was a problem hiding this comment.
| class="saferpay-terminal-manual-input form-control fixed-width-xl" | ||
| placeholder="{l s='Or enter Terminal ID manually' mod='saferpayofficial'}" | ||
| value="{if (!isset($field['terminals']) || count($field['terminals']) == 0) && $field['value']}{$field['value']|escape:'htmlall':'UTF-8'}{/if}" | ||
| style="margin-top: 5px; {if isset($field['terminals']) && count($field['terminals']) > 0}display: none;{/if}" |
There was a problem hiding this comment.
Using inline styles for conditional display logic is not ideal as it mixes presentation with structure. It's better to toggle a CSS class. PrestaShop/Bootstrap provides utility classes like hidden or d-none for this purpose. This improves code readability and maintainability.
For example:
class="... {if isset($field['terminals']) && count($field['terminals']) > 0}hidden{/if}"
style="margin-top: 5px;"
Self-Checks
JIRA task link
Summary
QA Checklist Labels
QA Checklist
Additional Context
Frontend Changes