My product images are served from https://website-list.s3.amazonaws.com/xxxxxx.jpg where xxxxxx is the product sku. I have created a module to change the Image URL on several templates, following the very useful instructions here: How to Change Product Images with external Image url in all magento 2 frontend and Backend Image display?. However it doesn't work for me on 2.4.2 for the minicart, checkout table and Recently viewed widget.

For the Recently Viewed I seem to need to edit: theme/Magento_Catalog/web/template/product/list/columns/image_with_borders.html and theme/Magento_Catalog/web/js/product/list/columns/image.js

In image_with_borders.html I changed the js function that is calling the image :

<img class="product-image-photo"
                     data-bind="attr: {src: getImageUrl($row()),
                                       alt: getLabel($row()), title: getLabel($row())}" />


<img class="product-image-photo"
                     data-bind="attr: {src: getNewImageUrl('160253'),
                                       alt: getLabel($row()), title: getLabel($row())}" />

And added a function in the image.js file:

getImageUrl: function (row) {
            return this.getImage(row.images).url;
        getNewImageUrl: function (sku) {
            return "https://website.s3.amazonaws.com/" + sku + ".jpg";

This works with a hardcoded sku but I need to be able to get the actual sku in the initial image_with_borders.html page, to send it through to the js file. How can I do that? All that's in that image_with_borders.html page to start with is:

<if args="isAllowed()">
    <a if="imageExists($row())"
       attr="href: $row().url">
        <span class="product-image-container"
              data-bind="style: {width: getWidth($row()) + 'px'}">
            <span class="product-image-wrapper"
                  data-bind="style: {'padding-bottom': getHeight($row())/getWidth($row()) * 100 + '%'}">
                <img class="product-image-photo"
                     data-bind="attr: {src: getOBImageUrl('160253'),
                                       alt: getLabel($row()), title: getLabel($row())}" />

How can I access sku from here? I tried $row.sku but that didn't work. Thanks!



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.