Class ProductReferenceResolutionUtils


  • public final class ProductReferenceResolutionUtils
    extends java.lang.Object
    Util class which provides utilities that can be used when syncing resources from a source commercetools project to a target one.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static io.sphere.sdk.products.queries.ProductQuery buildProductQuery()
      Builds a ProductQuery for fetching products from a source CTP project with all the needed references expanded for the sync: Product Type Tax Category Product State Staged Assets' Custom Types Staged Product Categories Staged Prices' Channels Staged Prices' Customer Groups Staged Prices' Custom Types Reference Attributes Reference Set Attributes
      static io.sphere.sdk.products.ProductDraftBuilder getDraftBuilderFromStagedProduct​(io.sphere.sdk.products.Product product)
      Given a Product this method creates a ProductDraftBuilder based on the staged projection values of the supplied product.
      static java.util.List<io.sphere.sdk.products.ProductDraft> mapToProductDrafts​(java.util.List<io.sphere.sdk.products.Product> products)
      Returns an List<ProductDraft> consisting of the results of applying the mapping from Product to ProductDraft with considering reference resolution.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • mapToProductDrafts

        @Nonnull
        public static java.util.List<io.sphere.sdk.products.ProductDraft> mapToProductDrafts​(@Nonnull
                                                                                             java.util.List<io.sphere.sdk.products.Product> products)
        Returns an List<ProductDraft> consisting of the results of applying the mapping from Product to ProductDraft with considering reference resolution.
        Mapping of Reference fields for the reference resolution
        Reference field from to
        productType Reference<ProductType> ResourceIdentifier<ProductType>
        categories Set<Reference<Category>> Set<ResourceIdentifier<Category>>
        variants.prices.channel Reference<Channel> ResourceIdentifier<Channel>
        variants.prices.customerGroup * Reference<CustomerGroup> Reference<CustomerGroup> (with key replaced with id field)
        variants.prices.custom.type Reference<Type> ResourceIdentifier<Type>
        variants.assets.custom.type Reference<Type> ResourceIdentifier<Type>
        variants.attributes on List<Attribute * Reference<ProductType> (example for ProductType) Reference<ProductType> (with key replaced with id field)
        taxCategory Reference<TaxCategory> ResourceIdentifier<TaxCategory>
        state * Reference<State> ResourceIdentifier<State>

        Note: The aforementioned references should be expanded with a key. Any reference that is not expanded will have its id in place and not replaced by the key will be considered as existing resources on the target commercetools project and the library will issues an update/create API request without reference resolution.

        Parameters:
        products - the products with expanded references.
        Returns:
        a List of ProductDraft built from the supplied List of Product.
      • getDraftBuilderFromStagedProduct

        @Nonnull
        public static io.sphere.sdk.products.ProductDraftBuilder getDraftBuilderFromStagedProduct​(@Nonnull
                                                                                                  io.sphere.sdk.products.Product product)
        Given a Product this method creates a ProductDraftBuilder based on the staged projection values of the supplied product.
        Parameters:
        product - the product to create a ProductDraftBuilder based on it's staged data.
        Returns:
        a ProductDraftBuilder based on the staged projection values of the supplied product.
      • buildProductQuery

        @Nonnull
        public static io.sphere.sdk.products.queries.ProductQuery buildProductQuery()
        Builds a ProductQuery for fetching products from a source CTP project with all the needed references expanded for the sync:
        • Product Type
        • Tax Category
        • Product State
        • Staged Assets' Custom Types
        • Staged Product Categories
        • Staged Prices' Channels
        • Staged Prices' Customer Groups
        • Staged Prices' Custom Types
        • Reference Attributes
        • Reference Set Attributes

        Note: Please only use this util if you desire to sync all the aforementioned references from a source commercetools project. Otherwise, it is more efficient to build the query without expansions, if they are not needed, to avoid unnecessarily bigger payloads fetched from the source project.

        Returns:
        the query for fetching products from the source CTP project with all the aforementioned references expanded.