Closed zerbfra closed 1 year ago
After digging in your source code, I find out that, I can edit this method:
private function getProductCldUrlsBySku($sku)
{
$urls = [
'image' => null,
'small_image' => null,
'thumbnail' => null,
'worn_photo' => null,
'media_gallery' => [],
];
try {
$product = $this->productRepository->get($sku);
foreach ($product->getMediaGalleryImages() as $gallItem) {
$urls['media_gallery'][] = $gallItem->getUrl();
if ($product->getData('image') === $gallItem->getFile()) {
$urls['image'] = $gallItem->getUrl();
}
if ($product->getData('small_image') === $gallItem->getFile()) {
$urls['small_image'] = $gallItem->getUrl();
}
if ($product->getData('thumbnail') === $gallItem->getFile()) {
$urls['thumbnail'] = $gallItem->getUrl();
}
if ($product->getData('worn_photo') === $gallItem->getFile()) {
$urls['worn_photo'] = $gallItem->getUrl();
}
}
} catch (\Exception $e) {
$urls = [
'error' => 1,
'message' => $e->getMessage(),
];
}
return $urls;
}
as you can see there is the new worn_photo
:
if ($product->getData('worn_photo') === $gallItem->getFile()) {
$urls['worn_photo'] = $gallItem->getUrl();
}
And then, I modified consequently the graphqls:
type CloudinaryData {
image: String
small_image: String
thumbnail: String
worn_photo: String
media_gallery: [String]
}
How we can generalize this? I'm not a Magento expert ehehe
Hi,
Currently, this is not something that we support. I have submitted a feature request internally to see if it can be added to our roadmap.
Thanks, Wissam
Hi all, I'm currently developing an e-commerce with Magento and a NuxtJS frontend. We are using the GraphQL apis and our client would like to use the Cloudinary service to upload their product pictures.
I tried getting the images in GraphQL via:
This is totally fine and I get the correct product image urls from Cloudinary.
Two questions and feature requests:
1) Is it possible to get always the cloudinary URL in the graphql response? For instance, I would like to get the Cloudinary URL also from the
image
,thumbnail
etc that are originally in the GraphQL definition for the ProductInterface2) Is it possible to add in
cld_data
some additional photo roles? For instance, I have theworn_photo
in my magento backend that I would like to expose and get from thecld_data
object. How can I do that?As you can see from the image,
Foto indossato
(label forworn_photo
) in my roles here:How can I get this in the
cld_data
object?Usually, I get them with a my custom plugin, that simply adds them to the ProductInterface.
I think maybe 1 an 2 can be both resolved by modifying the ProductImage entity (?)