Skip to content

fix: Only retrieve attributes from filter template when filter template is selected#60

Open
jansentjeu wants to merge 3 commits into
developfrom
fix/TW-129-backend-api-attributes
Open

fix: Only retrieve attributes from filter template when filter template is selected#60
jansentjeu wants to merge 3 commits into
developfrom
fix/TW-129-backend-api-attributes

Conversation

@jansentjeu

Copy link
Copy Markdown
Collaborator

Currently, all attributes are retrieved via the backend API in the attribute landing pages admin functionality. This should be based on the selected filter template.

Customers select filters that are not included in the filter template, causing landing pages to break.

With this fix, only all filters from the selected filter template are retrieved.

Comment thread src/ApiClient/BackendApiClient.php Outdated
@jansentjeu jansentjeu requested a review from bramstroker May 16, 2026 19:29
}

foreach ($result as $filterTemplateAttribute) {
if (!isset($allAttributes[$filterTemplateAttribute['AttributeId']])) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

$allAttributes is conditionally defined but unconditionally accessed, it may not be initialised


$attributes = [];
try {
$response = $this->doRequest(sprintf('filtertemplate/%s/attribute', $filterTemplate), $store);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

filterTemplate can be null but is used directly in sprintf.

The method should either require a non-null int or add an early guard:

if ($filterTemplate === null) {
    return [];
}

private function executeBackendApiRequest(Store $store): array
{
$filterTemplate = $this->request->getParam('filter_template') ?
(int)$this->request->getParam('filter_template') :

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This calls getParam() twice. Prefer a single assignment:

$rawFilterTemplate = $this->request->getParam('filter_template');
$filterTemplate = $rawFilterTemplate !== null && $rawFilterTemplate !== '' ? (int)$rawFilterTemplate : null;

@ahuininga-orisha ahuininga-orisha left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please ignore the comment, was posted without checking it first

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.

3 participants