Skip to main content

Posts

Showing posts with the label Salesforce Commerce Cloud

How to create dynamic urls without actually having sub-categories ?

How to create dynamic urls without actually having sub-categories ? By using only root categories, without sub categories and use search refinements to get desired results page. We can use dw.web.URLUtils class to create links from code. Use $url$ content link function to create links from content. Use Search-Show as controller route, add prefnX and prefvX parameters to apply the needed refinements where X is a number starting from 1

Response Structure coming from OCAPI

Is there anyway to change the response structure coming from OCAPI? There are hooks for certain OCAPI endpoints that you can use to modify the output.If need something more specific and it goes with use case ... create a custom controller to get what you need in a certain format.

What is the right way of adding jquery to the page?

What is the right way of adding jquery to the page? There is no "right" way. All depends on what you want to achieve or avoid. For example, SFRA exposes jQuery at the very beginning of JS execution like: window.jQuery = window.$ = require('jquery'); In that way, you have access to $ in any code you execute below without adding additional bundling mechanisms. The drawback is that you "ban" jQuery and $ names globally for yourself and should always remember it, especially when you use 3-rd party scripts, just controlling (while you can't do it fully) what they can do with this names. Also, there is no way to understand, if jQuery is used on a particular page or not, it always here, even when the page does not need it.

Product.getLastModified() is Not changing on price change

In cartridge code in SFCC, how to find if product price have changed recently. In case product.getLastModified() is not changing on price change. There is no built in way to do this. I suggest using ProductPriceInfo. You can get priceBook information for any product by Product.getPriceModel(), which returns a instance of ProductPriceModel. This class has a method getPriceInfo(), which will return a ProductPriceInfo class instance with attribute priceInfo : String, which you can use to store information about the date of change for a given price point for a product. Demandware Docs

Variation Group in SFCC

Variation Group in SFCC Technically a variant could be in multiple groups. One way to do this is to get the ProductVariationModel of that variant's master. Then you could set the selected value (setSelectedAttributeValue(String, String)) of the attribute your group is represented by. Finally you can get the collection of groups (getVariationGroups()) that share that selected value. Demandware Docs