我正在尝试用Hybris编写URL解析器,但遇到了一些错误;
类型getBaseProduct(ProductModel)
的方法TrialProductModelUrlResolver
未定义
类型为getCategoryPath(CategoryModel)
的方法DefaultCategoryModelUrlResolver
不适用于参数(ProductModel)
ProductService类型的getProductForCode(String)方法不适用于参数(ProductModel)
public class TrailerProductModelUrlResolver extends DefaultCategoryModelUrlResolver {
private TrailerURLNormalizationStrategy trailerURLNormalizationStrategy;
@Autowired
private ProductService productService;
@Override
protected String resolveInternal(final ProductModel source) {
final ProductModel baseProduct = getBaseProduct(source);
final BaseSiteModel currentBaseSite = getBaseSiteService().getCurrentBaseSite();
String url = getPattern();
if ((currentBaseSite != null) && (url.contains("{baseSite-uid}"))) {
url = url.replace("{baseSite-uid}", currentBaseSite.getUid());
}
if (url.contains("{category-path}")) {
url = url.replace("{category-path}", trailerURLNormalizationStrategy.normalizeString(buildPathString(getCategoryPath(source))));
}
if (url.contains("{product-name}")) {
String productName = source.getName(TrailerCoreConstants.LOCALE_TR);
if (StringUtils.isEmpty(productName)) {
productName = baseProduct.getName(TrailerCoreConstants.LOCALE_TR);
}
CategoryModel categoryModel = productService.getProductForCode(baseProduct);
if (categoryModel != null) {
if (categoryModel.getName() != null) {
if (!categoryModel.getName(TrailerCoreConstants.LOCALE_TR).isEmpty()) {
productName = categoryModel.getName(TrailerCoreConstants.LOCALE_TR) + " " + productName;
}
}
}
url = url.replace("{product-name}", trailerURLNormalizationStrategy.normalizeString(productName));
}
if (url.contains("{product-code}")) {
url = url.replace("{product-code}", trailerURLNormalizationStrategy.normalizeString(source.getCode()));
}
return url;
}
@Override
protected String buildPathString(final List<CategoryModel> path) {
if ((path == null) || (path.isEmpty())) {
return "c";
}
final StringBuilder result = new StringBuilder();
for (int i = 0; i < path.size(); ++i) {
if (i != 0) {
result.append('/');
}
result.append(path.get(i).getName());
}
return result.toString();
}
public TrailerURLNormalizationStrategy getTrailerURLNormalizationStrategy() {
return trailerURLNormalizationStrategy;
}
public void setTrailerURLNormalizationStrategy(TrailerURLNormalizationStrategy trailerURLNormalizationStrategy) {
this.trailerURLNormalizationStrategy = trailerURLNormalizationStrategy;
}
}
任何帮助
致谢
答案 0 :(得分:1)
只需将DefaultCategoryModelUrlResolver
更改为DefaultProductModelUrlResolver
对于产品UrlResolver,扩展DefaultProductModelUrlResolver
public class TrailerProductModelUrlResolver extends DefaultProductModelUrlResolver
{
private static final Logger LOG = Logger.getLogger(TrailerProductModelUrlResolver.class);
@Override
protected String resolveInternal(final ProductModel source)
{
final ProductModel baseProduct = getBaseProduct(source);
...
}
}
对于类别UrlResolver,扩展DefaultCategoryModelUrlResolver
public class TrailerCategoryModelUrlResolver extends DefaultCategoryModelUrlResolver
{
@Override
protected String resolveInternal(CategoryModel source)
{
}
}