Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Thi Tar 11 posts 91 karma points
    Aug 24, 2017 @ 08:37
    Thi Tar
    0

    How to get the url of Merchello products images?

    Hi All,

    I am trying to achieve to get the products data (products' name, brief, description, availability, and image url, etc.) as a json in Merchello.

    I used extended content to add brief and description to the product and I have managed to get the data (excluding image) as the json with the Product Service GetAll () in Umbraco API Controller.

    Now I have got one problem regarding with the product images. Where can I upload the product image and how to get the url of the images? I also tried to use extended data and file upload editor to upload the image for products but after I upload and pressed save button, the image is gone.

    Do I need to write some code to save or it will auto save somewhere? Where the uploaded images are saved?

    And ideas? Can please share advices or guide how to do to achieve to get the image url?

    Thanks in Advance,

    Thi Tar

  • Tolu Jemilua 39 posts 166 karma points
    Aug 24, 2017 @ 10:10
    Tolu Jemilua
    0

    From what I have seen, If you go on a product variant and select the checkbox "This variant has digital goods", you can add an image there

  • Thi Tar 11 posts 91 karma points
    Aug 25, 2017 @ 04:12
    Thi Tar
    0

    Hi Tolu,

    Thanks for your reply. I tried to upload product image under the product variant and was able to upload. But when I called my Umbraco API to get the product data, I am not getting any image url.

    Did I do something wrong? I used GetAll () to get the products data. Do I need to use some other method to get the products variants? If possible, I would like to get the image url in the same json with other product data.

    Thanks again,

  • William Zhang 39 posts 243 karma points
    Aug 27, 2017 @ 10:54
    William Zhang
    0

    Hi Thi,

    The idea behind extended content is that you can leverage Umbraco property editors to "attach" additional values to your products. An example of this would be product images.

    The way we've solved this is to add a Media Picker property to our "product" document type. When you add images to your product in Merchello the image ID's will be saved - you can then use UmbracoHelper.TypedMedia() to obtain the image URL:

    var product = productService.GetByKey(/*you product key*/); 
    
    // Detached contents are culture-specific
    var detachedContent = product.DetachedContents.FirstOrDefault(d => d.CultureName == "en-US");
    
    if (detachedContent != null && detachedContent.DetachedDataValues.ContainsKey(propertyName))
    {
        // myImageProperty = the normalized Umbraco property name
        var imageIds = detachedContent.DetachedDataValues["myImageProperty"];
        // The media picker saves images a comma-separated string. In this example we just get the first image URL.
        IPublishedContent media = UmbracoHelper.TypedMedia(imageIds.Split(',')[0]);
    
        var imageUrl = media.Url;
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft