public Product findProductBySlug(String slug) { return this.productStore.get().findBySlug(slug); }
public List<Product> findAllProducts(int number, int offset) { return this.productStore.get().findAll(number, offset); }
@Override public List<Product> findProductsForCollection(Collection collection) { return this.productStore.get().findAllForCollection(collection); }
@Override public void onEvent(Event event, Object source, Object data) { // Update stocks for bought products Order order = (Order) source; List<OrderItem> items = order.getOrderItems(); for (OrderItem item : items) { UUID itemId = item.getPurchasableId(); if (itemId == null) { return; } Long quantity = item.getQuantity(); try { Product product = productStore.get().findById(itemId); if (product.getStock() != null) { productStore.get().updateStock(itemId, -quantity.intValue()); } else if (product.getParentId() != null) { Product parent = productStore.get().findById(product.getParentId()); productStore.get().updateStock(product.getParentId(), -quantity.intValue()); } } catch (EntityDoesNotExistException e) { // Ignore, there is just no stock to update } } } }
@Override public <E extends Entity> void load(EntityData<E> entity, LoadingOption... options) { if (!Product.class.isAssignableFrom(entity.getEntity().getClass())) { return; } List<LoadingOption> optionsAsList = Arrays.asList(options); if (optionsAsList.contains(ProductLoadingOptions.WITH_FEATURE_AND_VARIANTS)) { entity.setChildren(Feature.class, this.productStore.findFeatures((Product) entity.getEntity())); entity.setChildren(Product.class, this.productStore.findVariants((Product) entity.getEntity())); } }
@Override public void deleteProduct(String productSlug) throws EntityDoesNotExistException { Product product = this.findProductBySlug(productSlug); if (product == null) { throw new EntityDoesNotExistException(); } this.productStore.get().delete(product); }
public Product createProduct(Product entity) throws InvalidEntityException, EntityAlreadyExistsException { if (Strings.isNullOrEmpty(entity.getSlug())) { entity.setSlug(this.slugifier.slugify(entity.getTitle())); } productStore.get().create(entity); return this.findProductBySlug(entity.getSlug()); }
Product retrieved = this.productStore.findById(product.getId()); output.println("- indexing " + tenant.getSlug() + ":" + product.getSlug()); output.flush();
public <E extends Entity> E load(String slug) { return (E) productStore.get().findBySlug(slug); }
if (data.containsKey("product")) { Product product = productStore.get().findBySlug((String) data.getFirst("product"));