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: Looping of data by reference with null coalescing #2829

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions engine/Shopware/Controllers/Backend/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -4055,8 +4055,12 @@ protected function prepareSimilarAssociatedData($data, $article)
*/
protected function prepareImageAssociatedData($data)
{
if (!isset($data['images']) || !\is_array($data['images']) || \count($data['images']) === 0) {
return $data;
}

$position = 1;
foreach ($data['images'] ?? [] as &$imageData) {
foreach ($data['images'] as &$imageData) {
$imageData['position'] = $position;
if (!empty($imageData['mediaId'])) {
$media = $this->get('models')->find(Media::class, $imageData['mediaId']);
Expand Down Expand Up @@ -4140,7 +4144,11 @@ protected function preparePricesAssociatedData($prices, $article, $tax)
*/
protected function prepareLinkAssociatedData($data)
{
foreach ($data['links'] ?? [] as &$linkData) {
if (!isset($data['links']) || !\is_array($data['links']) || \count($data['links']) === 0) {
return $data;
}

foreach ($data['links'] as &$linkData) {
$linkData['link'] = trim($linkData['link']);
// Map the boolean ExtJS link target to the string format which used in the database
$linkData['target'] = ($linkData['target'] === true) ? '_blank' : '_parent';
Expand All @@ -4158,8 +4166,12 @@ protected function prepareLinkAssociatedData($data)
*/
protected function prepareDownloadAssociatedData($data)
{
if (!isset($data['downloads']) || !\is_array($data['downloads']) || \count($data['downloads']) === 0) {
return $data;
}

$mediaService = Shopware()->Container()->get(MediaServiceInterface::class);
foreach ($data['downloads'] ?? [] as &$downloadData) {
foreach ($data['downloads'] as &$downloadData) {
$downloadData['file'] = $mediaService->normalize($downloadData['file']);
}

Expand Down
Loading