Search in sources :

Example 1 with Product

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;
}
Also used : ImageResource(com.day.cq.commons.ImageResource) Resource(org.apache.sling.api.resource.Resource) ImageResource(com.day.cq.commons.ImageResource) Product(com.adobe.cq.commerce.api.Product)

Example 2 with 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();
    }
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Product(com.adobe.cq.commerce.api.Product)

Example 3 with 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() {
    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);
        }
    }
}
Also used : ExperienceFragmentSocialVariation(com.adobe.cq.xf.social.ExperienceFragmentSocialVariation) Product(com.adobe.cq.commerce.api.Product)

Example 4 with Product

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;
}
Also used : SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Locale(java.util.Locale) CommerceSession(com.adobe.cq.commerce.api.CommerceSession) PriceFilter(com.adobe.cq.commerce.common.PriceFilter) CommerceService(com.adobe.cq.commerce.api.CommerceService) ArrayList(java.util.ArrayList) Product(com.adobe.cq.commerce.api.Product) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) CommerceException(com.adobe.cq.commerce.api.CommerceException) PriceInfo(com.adobe.cq.commerce.api.PriceInfo)

Example 5 with Product

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;
}
Also used : ImageResource(com.day.cq.commons.ImageResource) Resource(org.apache.sling.api.resource.Resource) ImageResource(com.day.cq.commons.ImageResource) Product(com.adobe.cq.commerce.api.Product)

Aggregations

Product (com.adobe.cq.commerce.api.Product)6 CommerceException (com.adobe.cq.commerce.api.CommerceException)2 CommerceService (com.adobe.cq.commerce.api.CommerceService)2 CommerceSession (com.adobe.cq.commerce.api.CommerceSession)2 PriceInfo (com.adobe.cq.commerce.api.PriceInfo)2 PriceFilter (com.adobe.cq.commerce.common.PriceFilter)2 ExperienceFragmentSocialVariation (com.adobe.cq.xf.social.ExperienceFragmentSocialVariation)2 ImageResource (com.day.cq.commons.ImageResource)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)2 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)2 Resource (org.apache.sling.api.resource.Resource)2