To implement ImageEngine’s image optimization for SAP Commerce Cloud/Hybris, you will first need to sign up for an ImageEngine account, if you do not already have one. During the signup process, you’ll be asked for the website domain where you intend to use ImageEngine and origin URL for the majority of the images. For more information about signing up, please refer to this article: Getting Started: Signup.
Once signed up, you will be issued a unique delivery address following this pattern: “aabbcc.cdn.imgeng.in.” Custom delivery addresses may also be made after the initial signup process is complete. For more information, see our article here: https://imageengine.io/docs/implementation/domain-name.
Take note of your delivery address, as we will be needing it in the next step.
Getting Started
- Override Hybris’ Basic Media URL strategy
To override Hybris’ out-of-the-box media URL strategy and replace it with one configured for ImageEngine, download the ImageEngineUrlStrategy.java class from Github to your project’s core extension.
Note: If you already have a custom URL strategy, please contact our support team for guidance on how to proceed.
Make sure its package and folder path look like the following examples:
• Class package: com.imageengine.media.url.impl.ImageEngineUrlStrategy
• Folder path would be similar to: /trainingcore/src/com/imageengine/media/url /impl/ImageEngineUrlStrategy.java - Define Bean For The Override Strategy
Go to your core extension’s resource folder. Find and edit *core-spring.xml to add the below bean definition that references the new imageEngineURL strategy:
<bean id="imageEngineUrlStrategy" class="com.imageengine.media.url.impl.ImageEngineUrlStrategy" parent="localMediaWebURLStrategy"/>
Make sure above in the class attribute you have given a correct class package path. - Configure Your local.properties File
Find your local.properties in ${HYBRIS_HOME}/hybris/config/local.properties
Add the below properties to local.properties. They will point your image media URL to your ImageEngine delivery address for image media. Use the ImageEngine Delivery Address that you were provided or configured during your ImageEngine account sign up on the second line.
media.folder.images.url.strategy = imageEngineUrlStrategy
media.folder.images.hostname = aabbcc.cdn.imgeng.in - Build and Test the Changes
Open your Terminal
# Go to the Hybris platform dir
cd ${HYBRIS_HOME}/hybris/bin/platform
# Setup and run ant (for Linux, run "./setantenv.sh")
setantenv.bat
ant clean all
# Start the hybris server (for Linux, run "./hybrisserver.sh")
hybrisserver.bat
Open the home page in your browser and see the rendered image URL. When you inspect the image, It should point to the hostname URL which you have configured in local.properties
For example, a home page image tree.jpg would have an image URL of aabbcc.cdn.imgeng.in/tree.jpg.
Comments
0 comments
Please sign in to leave a comment.