I am setting up a new site using 2.4.2 and need to use existing product images which are set up on a CDN, in the following formats: https://website-list.s3.amazonaws.com/xxxxxx.jpg https://website-thumb.s3.amazonaws.com/xxxxxx.jpg https://website-zoom.s3.amazonaws.com/xxxxxx.jpg where xxxxxx is the product sku.
Because of this structure I can't just edit the base media url
I was trying to just hardcode the main url path in and then get the sku, so I need to be able to getSku() on the image phtmls that are part of the category lists etc, as well as standard product view. Currently I'm working on \themefolder\mag-catalog\templates\product\image_with_borders.phtml. Trying something like this:
src="https://website-thumb.s3.amazonaws.com/<?= /* @noEscape */ $block->getSku() ?>.jpg"
I can get ProductId but not Sku. It just comes back blank.
I thought if I set Yes on the Attribute page for "Visible on Catalog Pages on Storefront" and "Used in Product Listing" that it would make this Sku attribute available but it makes no difference.
Any ideas? Thanks!
Edit - I got this to work:
$product_id = $block->getProductId();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
$sku = $product->getSku();
Is there any reason not to do it this way?