use of com.adobe.cq.commerce.api.Product in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class MockCommerceFactory method getProduct.
public static Product getProduct(Resource resource) {
Product product = mock(Product.class);
when(product.getPath()).thenReturn(resource.getPath());
Resource image = resource.getChild("image");
if (image != null) {
ImageResource imageResource = new ImageResource(image);
when(product.getImage()).thenReturn(imageResource);
}
return product;
}
use of com.adobe.cq.commerce.api.Product in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImpl method createMetadataProvider.
/**
* Instantiates the suitable metadata provider based on the contents of the current page.
*/
private WebsiteMetadata createMetadataProvider() {
try {
Product product = CommerceHelper.findCurrentProduct(currentPage);
ExperienceFragmentSocialVariation smVariant = findExperienceFragmentSocialVariation();
if (product == null) {
if (smVariant == null) {
return new WebsiteMetadataProvider();
} else {
return new ExperienceFragmentWebsiteMetadataProvider(smVariant);
}
} else {
if (smVariant == null) {
return new ProductMetadataProvider(product);
} else {
return new ExperienceFragmentProductMetadataProvider(product, smVariant);
}
}
} catch (NoClassDefFoundError e) {
return new WebsiteMetadataProvider();
}
}
use of com.adobe.cq.commerce.api.Product in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class SocialMediaHelperImpl method createMetadataProvider.
/**
* Instantiates the suitable metadata provider based on the contents of the current page.
*/
private WebsiteMetadata createMetadataProvider() {
Product product = CommerceHelper.findCurrentProduct(currentPage);
ExperienceFragmentSocialVariation smVariant = findExperienceFragmentSocialVariation();
if (product == null) {
if (smVariant == null) {
return new WebsiteMetadataProvider();
} else {
return new ExperienceFragmentWebsiteMetadataProvider(smVariant);
}
} else {
if (smVariant == null) {
return new ProductMetadataProvider(product);
} else {
return new ExperienceFragmentProductMetadataProvider(product, smVariant);
}
}
}
use of com.adobe.cq.commerce.api.Product in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class MockCommerceFactory method getCommerceService.
public static CommerceService getCommerceService(Resource resource) {
CommerceService commerceService = mock(CommerceService.class);
try {
when(commerceService.login(any(SlingHttpServletRequest.class), any(SlingHttpServletResponse.class))).then(invocationOnMock -> {
CommerceSession commerceSession = mock(CommerceSession.class);
when(commerceSession.getProductPriceInfo(any(Product.class), any(PriceFilter.class))).then(invocation -> {
Product product = invocation.getArgumentAt(0, Product.class);
if (product.getPath().equals(resource.getPath())) {
return new ArrayList<PriceInfo>() {
{
add(new PriceInfo(UNIVERSAL_PRICE, new Locale("en", "US")));
}
};
}
return null;
});
return commerceSession;
});
} catch (CommerceException e) {
throw new RuntimeException("Unable to mock CommerceService.");
}
return commerceService;
}
use of com.adobe.cq.commerce.api.Product in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class MockCommerceFactory method getProduct.
public static Product getProduct(Resource resource) {
Product product = mock(Product.class);
when(product.getPath()).thenReturn(resource.getPath());
Resource image = resource.getChild("image");
if (image != null) {
ImageResource imageResource = new ImageResource(image);
when(product.getImage()).thenReturn(imageResource);
}
return product;
}
Aggregations