All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sphere.internal.CartServiceImpl Maven / Gradle / Ivy

There is a newer version: 0.72.1
Show newest version
package io.sphere.internal;

import java.util.Currency;
import io.sphere.client.CommandRequest;
import io.sphere.client.FetchRequest;
import io.sphere.client.ProjectEndpoints;
import io.sphere.client.QueryRequest;
import io.sphere.client.model.QueryResult;
import io.sphere.client.model.VersionedId;
import io.sphere.client.shop.ApiMode;
import io.sphere.client.shop.CartService;
import io.sphere.client.shop.model.Cart;
import io.sphere.client.shop.model.CartUpdate;
import io.sphere.internal.command.CartCommands;
import io.sphere.internal.command.UpdateCommand;
import io.sphere.internal.request.RequestFactory;
import com.google.common.base.Optional;
import com.neovisionaries.i18n.CountryCode;
import org.codehaus.jackson.type.TypeReference;

public class CartServiceImpl extends ProjectScopedAPI implements CartService {

    public CartServiceImpl(RequestFactory requestFactory, ProjectEndpoints endpoints) {
        super(requestFactory, endpoints, new TypeReference() {}, new TypeReference>() { });
    }

    @Override public FetchRequest byId(String id) {
        return requestFactory.createFetchRequest(
                endpoints.carts.byId(id),
                Optional.absent(),
                new TypeReference() {});
    }

    @Override public FetchRequest forCustomer(String customerId) {
        return requestFactory.createFetchRequest(
                endpoints.carts.forCustomer(customerId),
                Optional.absent(),
                new TypeReference() {});
    }

    @Deprecated
    @Override public QueryRequest all() {
        return query();
    }

    @Override public QueryRequest query() {
        return queryImpl(endpoints.carts.root());
    }

    @Override public CommandRequest createCart(Currency currency, String customerId, CountryCode country, Cart.InventoryMode inventoryMode) {
        return createCommandRequest(
                endpoints.carts.root(),
                new CartCommands.CreateCart(currency, customerId, country, inventoryMode));
    }

    @Override public CommandRequest createCart(Currency currency, String customerId, Cart.InventoryMode inventoryMode) {
        return createCommandRequest(
                endpoints.carts.root(),
                new CartCommands.CreateCart(currency, customerId, null, inventoryMode));
    }

    @Override public CommandRequest createCart(Currency currency, Cart.InventoryMode inventoryMode) {
        return createCart(currency, null, null, inventoryMode);
    }

    @Override
    public CommandRequest createCart(Currency currency) {
        return createCart(currency, Cart.InventoryMode.None);
    }

    @Override public CommandRequest createCart(Currency currency, CountryCode country, Cart.InventoryMode inventoryMode) {
        return createCart(currency, null, country, inventoryMode);
    }

    @Override public CommandRequest updateCart(VersionedId cartId, CartUpdate update) {
        return createCommandRequest(
                endpoints.carts.byId(cartId.getId()),
                new UpdateCommand(cartId.getVersion(), update));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy