Skip to content

Conversation

@GytisZum
Copy link

No description provided.

@GytisZum GytisZum merged commit cd8d2ab into master Jul 24, 2025
@GytisZum GytisZum deleted the SMAR-26/dependencies-improvements branch July 24, 2025 07:11
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @GytisZum, 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 focuses on improving the stability and error handling of the smartsupp module by making its interaction with external constants and Smarty template variables more robust. The changes prevent potential runtime errors by gracefully handling cases where expected dependencies or variables might be undefined or missing, leading to a more resilient application.

Highlights

  • Enhanced Robustness for Constant Usage: I've added defined() checks around the self::PRESTASHOP_CLOUDSYNC_CDC constant in smartsupp.php. This ensures that if the constant is not defined, an empty string is used instead, preventing potential runtime errors and improving the module's resilience.
  • Safer Smarty Variable Assignment: I've replaced the null coalescing operator (??) with explicit !== null checks when retrieving Smarty template variables (smartsuppVar). This provides a more explicit and robust way to handle cases where the Smarty variable might not be set, ensuring that array_merge_recursive always receives an array.
  • Conditional Script Rendering in Templates: In views/templates/admin/cloudsync.tpl, I've wrapped the script tag that loads cloudSyncPathCDC with a Smarty {if isset($smartsupp.url.cloudSyncPathCDC)} condition. This prevents the rendering of a malformed or empty script src attribute if the cloudSyncPathCDC variable is not available in the template context, complementing the PHP changes.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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 or fill out our survey to provide feedback.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces changes to improve dependency compatibility. However, there are critical issues with the implementation of the defined() checks, which will cause the cloudSyncPathCDC variable to always be an empty string. Additionally, the isset() check in cloudsync.tpl is insufficient and will lead to unnecessary requests. There's also an opportunity to improve maintainability by addressing duplicated code.

Comment on lines +483 to +485
'cloudSyncPathCDC' => defined('self::PRESTASHOP_CLOUDSYNC_CDC')
? self::PRESTASHOP_CLOUDSYNC_CDC
: '',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The defined('self::PRESTASHOP_CLOUDSYNC_CDC') check is incorrect and will always evaluate to false. The string 'self::PRESTASHOP_CLOUDSYNC_CDC' is treated as the name of a global constant, which doesn't exist. To check for a class constant, you would need to use defined('Smartsupp::PRESTASHOP_CLOUDSYNC_CDC').

However, since PRESTASHOP_CLOUDSYNC_CDC is a constant defined within this same class, this check is unnecessary. The constant will always be available here.

This change will result in cloudSyncPathCDC always being an empty string, which is a bug. Please revert to the original implementation.

                'cloudSyncPathCDC' => self::PRESTASHOP_CLOUDSYNC_CDC

Comment on lines +495 to +497
'cloudSyncPathCDC' => defined('self::PRESTASHOP_CLOUDSYNC_CDC')
? self::PRESTASHOP_CLOUDSYNC_CDC
: '',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

Similar to the previous occurrence, this defined() check is incorrect and will always result in an empty string for cloudSyncPathCDC. The check for the class constant is also redundant as it's defined within this class.

Please revert to using the constant directly.

                    'cloudSyncPathCDC' => self::PRESTASHOP_CLOUDSYNC_CDC

Comment on lines +3 to +5
{if isset($smartsupp.url.cloudSyncPathCDC)}
<script src="{$smartsupp.url.cloudSyncPathCDC|escape:'htmlall':'UTF-8'}"></script>
{/if}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The isset() check is not sufficient here. If cloudSyncPathCDC is set to an empty string (which it will be, due to the issue in smartsupp.php), this condition will be true, and an empty script tag <script src=""></script> will be rendered. This causes the browser to make an unnecessary request to the current page.

To prevent this, you should check for a non-empty string. A simple truthiness check is sufficient and more concise in Smarty.

{if $smartsupp.url.cloudSyncPathCDC}
    <script src="{$smartsupp.url.cloudSyncPathCDC|escape:'htmlall':'UTF-8'}"></script>
{/if}

Comment on lines +478 to +479
$smartsuppVar = $this->context->smarty->getTemplateVars('smartsupp');
$existing = $smartsuppVar !== null ? $smartsuppVar : [];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This logic to retrieve the 'smartsupp' template variable with a fallback to an empty array is duplicated from the loadPsAccounts method (lines 442-443). To improve maintainability and adhere to the DRY (Don't Repeat Yourself) principle, consider extracting this logic into a private helper method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants