In Shopware 4 waren alle Produktbilder in media/image. In Shopware 5 wurden die Bilder in Unterordner verschoben.
So erhält man den Pfad dazu:
Einen Bilderpfad erhält man z.B. über diesen Select
private function getImageUrl($detail)
{
// [fh] 20161017-112100 - This function returns the image url of the first image as a return value.
$articleDetailID = $detail->getId();
$articleID = $detail->getArticleId();
$query = "SELECT s_media.path, rel.option_id,
s_articles_img.position as pos,
s_articles_img.description as description,
s_articles_img_attributes.attribute1 as imageCaption
FROM s_media
JOIN s_articles_img
ON s_articles_img.media_id = s_media.id OR s_media.name = s_articles_img.img
JOIN s_article_img_mappings
ON s_article_img_mappings.image_id = s_articles_img.id
JOIN s_article_img_mapping_rules
ON s_article_img_mapping_rules.mapping_id = s_article_img_mappings.id
JOIN s_article_configurator_option_relations as rel
ON rel.option_id = s_article_img_mapping_rules.option_id
JOIN s_articles_img_attributes
ON s_articles_img_attributes.imageID = s_articles_img.id
WHERE rel.article_id = '$articleDetailID'
AND s_articles_img.articleID ='$articleID'
AND rel.option_id != 82
GROUP BY path
ORDER BY pos";
$result = Shopware()->DB()->fetchAll($query);
$path = $result[0]['path'];
return $path;
}
Funktionsaufruf:
$imageUrlOld = $this->getImageUrl($article);
Ausgegeben würde der Pfad ($imageUrlOld) so ähnlich: media/image/3477.jpg
Oder alle Thumbnails über die Shopware Methoden und das Artikel Objekt:
if($article) {
$imagesArrayCollection = $article->getArticle()->getImages();
if($imagesArrayCollection) {
$images = $imagesArrayCollection->first();
if($images) {
$media = $images->getMedia();
if($media){
$articleImages = $images->getMedia()->getThumbnails();
}
}
}
}
Jetzt muss der Pfad (oder die Pfade bei den Thumbnails) umgewandelt werden:
$mediaService = Shopware()->Container()->get('shopware_media.media_service');
$imageFullUrl = $mediaService->getUrl($imageUrlOld);
Ausgegeben würde dieser Pfad ($imageFullUrl) so ähnlich: https://shopware.4uweb.de/media/image/ba/98/da/3477.jpg
Um z.B. für ein PDF einen Serverpfad zu generieren hilft dies:
$protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https'; $domain = $_SERVER['SERVER_NAME']; $root = $_SERVER['DOCUMENT_ROOT']; $url = $protocol.'://'.$domain; $imageUrl = str_replace($url, $root, $imageFullUrl);
Ausgegeben würde dieser Pfad ($imageUrl) so ähnlich: /var/www/fvhg/test.forum-verlag.com/media/image/ba/98/da/3477.jpg