Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: media name and description usage #2631

Closed

Conversation

lacknere
Copy link
Contributor

@lacknere lacknere commented Feb 19, 2024

1. Why is this change necessary?

Media name and description are not correctly mapped.

2. What does this change do, exactly?

  • Fix the hydration and conversion of media name and description.
  • Add media name fallbacks if no description is available.

3. Describe each step to reproduce the issue or behaviour.

4. Please link to the relevant issues (if any).

5. Which documentation changes (if any) need to be made because of this PR?

6. Checklist

  • I have written tests and verified that they fail without my change
  • I have squashed any insignificant commits
  • This change has comments for package types, values, functions, and non-obvious lines of code
  • I have read the contribution requirements and fulfil them.

Copy link
Contributor

@mitelg mitelg left a comment

Choose a reason for hiding this comment

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

thanks for your contribution, nice fix!
would you mind adding a few tests?

UPGRADE-5.7.md Outdated
@@ -10,11 +10,18 @@ This changelog references changes done in Shopware 5.7 patch versions.

* Added compatibility with PHP 8.3
* Added new polyfill `symfony/polyfill-php83` to be able to use PHP 8.3 features
* Added image name fallbacks if no image description is available to:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Added image name fallbacks if no image description is available to:
* Added fallback to image name for `alt` and `title` attributes if image description is not available in following templates:

and then please list the tpl files and then the block names

@@ -206,7 +206,10 @@
{if $sArticle.additionaltext}
{$lastSeenProductsConfig.currentArticle.articleName = $lastSeenProductsConfig.currentArticle.articleName|cat:' ':$sArticle.additionaltext}
{/if}
{$lastSeenProductsConfig.currentArticle.imageTitle = $sArticle.image.description}
{$lastSeenProductsConfig.currentArticle.imageTitle = $sArticle.image.name}
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we need to escape here as well? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$lastSeenProductsConfig is json encoded here so it should be escaped anyways, I think 🤔

@lacknere lacknere force-pushed the fix-media-name-and-description-usage branch from df83dc3 to 40b94b7 Compare February 19, 2024 18:01
@@ -126,8 +126,9 @@ public function hydrateProductImage(array $data)
$translation = $this->getTranslation($data, '__image');
$data = array_merge($data, $translation);

$media->setName($data['__image_description']);
$media->setName($data['__image_img']);
Copy link
Contributor

@mitelg mitelg Feb 21, 2024

Choose a reason for hiding this comment

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

hey @lacknere

I had another thought about that. This change is a break. People and code are assuming, that the "name" contains the image description, if this hydration method is used. If we now change this, their code will break. So unfortunately we cannot merge it like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about using description primarily and name as a fallback there, if no description is available? Something like $media->setName($data['__image_description'] ?: $data['__image_img']);

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for the late answer 🙈

I am not sure, if this is also a desired state 🤔 could also lead to unexpected behaviour, where not values where before.

what about deprecating the old behaviour and trigger the new one with a parameter? 🤔 where the default ensures the old behaviour.

to not break the public method, we would need to add the parameter commented at first, and get the value with https://www.php.net/manual/en/function.func-get-args.php 🤔

maybe you can find a way to build it like that, that you have the possibility to get the hydrated media with "correct" values, but the default way stays at it is.

@mitelg
Copy link
Contributor

mitelg commented Mar 23, 2024

hey @lacknere
are you still on this? what are your thoughts?

@mitelg
Copy link
Contributor

mitelg commented Apr 5, 2024

Hey @lacknere

I will close this PR due to inactivity. Let me know, if you want to discuss this further 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants