Adding products on the fly to order - java

I would like to add products to cart on the fly. This means the products to add are not stored in the database and doesn't have to. But when I take a look into the cart endpoint how items added to an order the class org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO requires a product id.
So this means I've to override blCatalogService which would allow temporary products too? Is this all or did I forget something else to achieve the adding of products to the cart/order on the fly?

The OrderItem data model and services don't strictly require a SKU but many of the out of box examples do.
You should be able to override the CartEndpoint and instead of creating an OrderItemRequestDTO, create a NonDiscreteOrderItemRequestDTO.
The AddOrderItemActivity which is part of the workflow executed when an item is added checks for this type and will create an OrderItem instead of a DiscreteOrderItem or BundleOrderItem (both of which require a SKU).
Hope this helps,
Brian
Note : I work for Broadleaf

Related

How can I model a relation with user and entity?

I am trying to add a feature on the "Bookshelf App for Java on App Engine Standard Environment" that lists books based on read or not read. The codes are available here https://github.com/GoogleCloudPlatform/getting-started-java
There is a Book.java file that defines the model a book. If I want to add the feature of read or not read do I add a boolean variable in Book.java? Is this a right approach? Or just keep a database table of bookID, user, readOrNot? Or the are some other smart approaches?
In general, a class like Book.java should only contains properties specific to a book like title, author, published date. If you want to add information like number of pages, you would add it to the book class. In the case of the read or not read feature, it is better to keep this information in a database where book IDs would be attached to a specific user. The user class could keep a book read list but I would recommend a database class that exposes an API to get a list of books for a user. The code would be more reusable.
I hope this help you a bit.

Foursquare sub-category search

I can get a list of categories and all nested subs as well, but the only category I want to search is 'food'. What I need back is a list of subcategories for food.
Searching categories is done with: https://api.foursquare.com/v2/venues/categories?oauth_token=[auth_token]&v=20150501
Is there a known way to just search for subcategories if I provide a category id?
You're missing categoryId=... from your query. You can find the IDs here: https://developer.foursquare.com/categorytree
At the time of writing the categoryId for food is 4d4b7105d754a06374d81259
There is a danger in what I am about to suggest, but here goes.
You could create a sample app which hits https://api.foursquare.com/v2/venues/categories?oauth_token=[oAuthToken]&v=20150506, parses the json response and stuffs the results into a database. With this database populated, copy it (and necessary model files) into your real app.
Using this local category database, your app can search for just parent categories (Arts & Entertainment, Food, etc.), or just subCategories within a given parent category (brazillian restaurants, cafes, etc.), and so on.
The danger is that if Foursquare chooses to change their category data, your local source will be out of date. You will need to have a way to update your data and, of course, ensure your app handles the change(s).

jpa multiple bidirectional many to one relationship to the same field

I have a problem i hope someone can help me solving.
My system has got an entity "Product". On a product it should be possible to set "replacement products" (products that are supposed to be sold instead of the original product). We have two types of replacement. On a product, i need to be able to set either none, one of them or both types of replacement product. But, only one product should be set per type. In addition to this, i want to be able to look at a product and get a list of other products that has this product as their replacement product.
Short version:
Product -> replacement (two types, one of each)
Product -> list of
products that it replaces (of both types of replacement)
My solution this far has been to create an abstract class ReplacementProduct with subclasses(one for each replacement type), with discriminatorvalues.
The replacementproduct table in the database has the following fields:
id, replacementproduct, replacementType
Further, i have placed two fields on the Product entity (instances of the subclasses for replacement types). Like this i have obtained a one way link from product to another product with a replacement type.
My problem is to make this link go both ways. As I said, I want to be able to get a list of products with the Product in question as their replacement product.
Is this possible without using a lot of java logic?
I'm open to any suggestion.
Sounds like a bidirectional ManyToMany is needed between products. The owning side would setup a mapkey mapping, using the type as the key. The other side doesn't need a key, and would reflect all the products it can replace.
This is described here
http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Map_Key_Columns_.28JPA_2.0.29

How to save JPA/Spring Data entity that contains a list of other entities without having to look them all up?

Lets say you had an entity called Bus. In that entity you have a list of passengers. In the UI you select the passengers that will be in the Bus. After all the passengers have been added to the bus you submit the page. Server side you get The Bus entity and you get a list of ids that represents the passengers. Do I really have to look up all these passengers and set the list of passengers on the Bus before I save the Bus. I haven't changed any information about the passengers themselves and would hate to have to do the database hit if its not needed.
Searching around I have seen people using the entity manager find() to do this, but I am not sure how I would do that with spring-data.
Ideally it would be nice to just set this list of ids on the json object I send up and use some annotation on the Bus entity so that it knows to expect ids when saving the passenger list on the Bus entity.
I am fairly new to JPA so feel free to point me to the correct words to search on google. I am just not sure how to go about doing something like this.
With spring data it uses the merges so all I had to do is save the bus with a newly created list of passengers that only had the id set on them. No need to look them up, just create a new object and set the id on it and then save. It is as easy as that.

Play! Framework save list of rows from form

I display a list of db table rows which are editable. I would like to allow users to edit the data in the displayed table and save all updates at the same time. How should I get back the list of updates to the controller?
As Play can bind to POJO's and also bind to Lists, it should be possible to simply create a list of POJOs.
See here for more details http://www.playframework.org/documentation/1.2.2/controllers#array.
It does not give this as an explicit example, but it should work.
If it does not, then the other options you have is to create your own custom binder (also described on the page linked to above).

Categories

Resources