Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AddProductToCartCommand implements Command {
- private final CartService carService;
- private final ProductService productService;
- private Scanner sc = new Scanner(System.in);
- public AddProductToCartCommand(Context context) {
- carService = context.getCartService();
- productService = context.getProductService();
- }
- @Override
- public void execute() {
- System.out.println("Write product id");
- String id = UserManager.getIdFromUser(sc);
- Product p = productService.getProductById(Integer.parseInt(id));
- if (p == null) {
- System.out.println("Sorry , but we haven't got product with this id");
- return;
- }
- carService.addProductToCart(p);
- System.out.println("Product " + p + " was added.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement