How to save a complex shopping cart in parse database - database

How can I save a shopping cart order and order history? The items price is different according to add-ons attached with it. Can I save as an object ? or use different rows for each item and link or any better and efficient ideas. addons are kept in different class and items in different class.

Maybe,one of the possible implementations of the shopping kart is to have one class Kart where you save the different attributes of the shopping kart. If there are certain properties of it that won't change over time then one option is to create a class to save the shopping kart identifier alongside the attributes that don't change and then in a separate class have the pointer to the original class that represents the shopping kart (by having a pointer to the row in Kart) and rest of the properties that do change (for example the total, or the items).
In this separated class SepKart, it is a good Idea to have the attributes validSince and validUntil, and to have in the beforeSave trigger, a function that sets the validUntil attribute of another row in SepKart that points to the same shopping kart in Kart and doesn't have it's validUntil set.
In the case of the items and the order of them, a list of objects that point to the items would do it, because then, if the order changes, then just saving a new instance of it would save the new order and you would then be able to see what is the history of the shipping kart in the time A just by querying in SepKart for the row that points to the shopping kart Kart, has a validSince of a time before A and a validUntil after A (or validUntil not set).

Related

How use one field of a form to populate other fields in Bonita?

I have a form variable of type external API called customersList. It is a list of customer objects. In my form, I have a Customer Name and Customer Id. For the Customer Name, I use an auto-complete widget. So, when I type something in the Customer Name field, it will give me a list of suggestions. When I click on one of the suggestion, I want the Customer Id field automatically populated with the information corresponding to the name I choose.
For example, the first object of a customersList variable which is:
customersList[0] = { "customerName" = "One Time Customer", "customerNumber" = "0000" }
Thus, when I choose Customer Name field to be One Time Customer, I want the Customer Id to be set to 0000 automatically.
I set the value of the Customer Id field to be customersList[0].customerNumber. But, it is static.
(please note: customerNumber represents Customer Id)
Any tips on how to do it?
Sadly the default autocomplete widget won't let you achieve such use case.
In fact the default autocomplete widget can take a list of JSON object as "Available values", can use one of the attribute of those objects as the display value ("Displayed key" property) and use it for autocompletion but it will only store this value (i.e. the one being displayed).
In your use case it means that you can use your customersList for "Available values" and customerName for "Displayed key" but you will only be able to save the customerName in "Value".
The good news is that a custom widget that do just what you want is available as a community contribution. Checkout the project page to download it and then import it in your UI Designer. An example of usage of this custom widget is also available for download from the project releases.

How do I create and save a set/array of objects for a given Core Data entity?

I have an app that will ideally compare luxury restaurants and their respective dishes against each other. This means I have a Core Data entity called Restaurant with attributes like restaurantName, location, averagePrice, and foodType. I have a second Core Data entity called MenuItem with attributes like foodName, caloryCount, price, and rating.
Since the goal is to compare, say, two steakhouses and their filet mignons on calories/price/rating, I'd really like to take a preloaded list of MenuItem objects I have (an array called selectedMenuItems) and somehow save that as an attribute of the Restaurant entity so that each individual restaurant will have an instance of those menu item objects attached to it (after which the user could edit the calories/price/rating for each menu item on a restaurant by restaurant basis). In the most ideal scenario, if anything was added or subtracted from the selectedMenuItems array of objects it would be reflected across all individual restaurants.
What I've tried so far:
1.) Many-to-many relationship between Restaurant and MenuItem
As you can probably guess from my above description, this didn't work out how I wanted it to since it only connected each restaurant to the selectedMenuItems array, and any alterations made in a restaurant propagated through the relationship to the array (this was a fundamental misunderstanding of relationships, on my part).
2.) Create an attribute of type Transformable in Restaurant to hold the selectedMenuItems array
This looked like it was going to work for a moment. As I said, I created an attribute called menuItems in my Restaurant entity of type Transformable, and then in the view controller for each restaurant's detail view (the view controller that displays the menuItems is an additional navigation step) I added the following inside of viewDidLoad():
// The selected Restaurant is passed from the prior screen to restaurant
restaurant.menuItems = selectedMenuItems as NSObject?
Which resulted in seemingly what I needed, except for the fact that if I made any changes to the selectedMenuItems array, it would cause the app to crash with the console readout 'NSInvalidArgumentException', reason: '-[Restaurant encodeWithCoder:]: unrecognized selector sent to instance.
3.) Break apart the selectedMenuItems array of objects into matched arrays of properties
After doing some experimenting with 2.), it appeared as though having an array of objects was the issue. Because of this, I iterated through selectedMenuItems and stripped out the properties into their own arrays (foodNameArray, caloryCountArray, priceArray, etc.). After that, I assigned each of those to newly created attributes of my Restaurant entity:
restaurant.foodNames = foodNameArray as NSObject?
restaurant.caloryCounts = caloryCountArray as NSObject?
restaurant.prices = priceArray as NSObject?
Now, this was already looking very dodgy and prone to catastrophic failure. It did, however, work pretty much how I wanted it to. The issue here was that any changes to selectedMenuItems (like adding/removing a new object) didn't pass through to my restaurants after the first load. This is in contrast with 1.) where the changes propagated from the restaurants to selectedMenuItems (bottom to top) compared to 3.), where I want the changes to flow top to bottom.
Given the above descriptions, does anyone have advice on how I can get the functionality I'm looking for?
Rather than a many-many relationship, I would use three entities:
Restaurant, as you currently have;
Dish, which represents the generic menu item, such as "Filet mignon" or "Rib-eye"; and
MenuItem, which is a particular Dish served by a particular Restaurant.
Because Dish is generic, it would have only one attribute foodName (though you might want others). MenuItem would have attributes caloryCount, price, rating.
Since each MenuItem represents a particular dish served by a particular restaurant, it would have "to-one" relationships to Restaurant and Dish. For each relationship, the inverse would be "to-many": a Restaurant will serve many MenuItems, and a Dish could feature in many MenuItems.
You can then preload the list of Dishes, from which users can select those which are served by a particular restaurant. You can then create corresponding MenuItems and can presumably let users record calories/price/rating. If the user deletes a MenuItem, the corresponding Dish is unaffected, so will be available for other existing and/or new Restaurants. If the user wants to add a MenuItem for which there is no existing Dish, you can add a new Dish, which will then be available for any subsequent MenuItems.

How to sync two models representing the same object but with a different cid?

In my app, user can create vehicles. On the "show specific vehicle" page, I have an instance of Vehicle (which extend RelationalModel from Backbone Relational). When I change the avatar of the vehicle, this model is changed.
In another page "show vehicles list" of the application, I have a gallery showing the vehicles of the user. The models (instances of Vehicle too) are in a collection. Unfortunately, they have a different CID and thus are not updated properly when the user changes the avatar of the Vehicle in the show Page.
How to deal with that? I would like the Vehicle #9 to be the same everywhere.
I would define an application-level vehicleCollection (A) where you store all vehicles you get from every single request that returns vehicles (B, C). Since every vehicleId will be the same, you can do a look-up in the main collection (A) if the model already exists when you loop over the resultset from the other collection fetch (B, C).
You will most likely need to work with temporary collections and inject the relevant model from the main collection (A)
If you look through the tests that come with the Backbone package (or just go to their github repo) you can clearly see how it works adding the same model to different collections

How Can I store attributes to add_cart Manually in Zen Cart?

It's Default Store in Zen Cart > http://awesomescreenshot.com/00bcd2jdf so I just want to add this manually attribute by my customized page > http://awesomescreenshot.com/0ebcd1w57
How can I store it and Which table in Zen cart? In this site.
Thanks
You would have to define the option and its possible values in the products_options and products_options_values tables, and then attach the possible combinations to products in the products_attributes table, otherwise they're not going to be handled properly by the order process.
When placing an affected product in the shopping cart you would need to pass information about the options and values for the item being purchased in the form's post array.
However, this is an awful lot of work just to do stuff that's already built into Zen Cart.

Flex 4 data management - how do I approach this?

quite an explanation here, hope someone has the patience to read it through
I'm building an application in Flex 4 that handles an ordering system. I have a small mySql database and I've written a few services in php to handle the database.
Basically the logic goes like this:
I have tables for customers, products, productGroups, orders, and orderContent
I have no problem with the CRUD management of the products, orders and customers, it is the order submission that the customer will fill in that is giving me headaches:
What I want is to display the products in dataGrids, ordered by group, which will be populated with Flex datamanagement via the php-services, and that per se is no problem. But I also want an extra column in the datagrid that the user can fill in with the amount he wishes to order of that product. This column would in theory then bind to the db table "orderContent" via the php services.
The problem is that you would need to create a new order in the database first that the data could bind to (orderContent is linked to an order in the db).
I do not want to create a new order every time a user enters the page to look at the products, rather I would like to create the order when a button is pressed and then take everything from the datagrids on the page and submit it into the database.
My idea has been to create a separate one-column datagrid, line it up next to the datagrid that contains the products and in that datagrid the user would be able to enter the amount of that product he'd like to order.
I've created a valueObject that contains the data I would need for an order:
Code:
package valueObjects
{
public class OrderAmount
{
public var productId:int;
public var productAmount:int;
public var productPrice:Number;
public function orderAmount()
{
}
}
}
My idea was to use a service to get all products from a certain group, populate an ArrayCollection with the data, then transfer each object in that ArrayCollection to an instance of the Value Object above, add the value object to another ArrayCollection that would the be used as a dataProvider for the one-column datagrid (I would only display amount which would be set to zero at first, but use the other data upon transfering it to the db)
I've tried to use the results from the automatically generated serviceResults that retrieve the products for the datagrid and put in a resultHandler that transfers the valueobjects, however this does not seem to work.
Basically my question is this: Am I approaching this thing completely wrong, or is there a way I can get it to work the way I planned?
Would I need to create a completely new service request to get the product id:s, and price to populate the one-column datagrid.
I'll post some code if that would help.
Thank you if you read this far.
Solved it by creating a Value Object class to hold all the info needed for each row in the grid and from the php service that returned all products in a group, I looped through the result and transfered the data needed into my Value Object.
I then added each Value Object into an ArrayCollection and made that the dataProvider for the dataGrid.
No need to use two grids. I forgot how logic things get when you think of datagrid data just as an ArrayCollection and forget the visual presentation of it on screen.
Put in a few itemRenderers and the whole thing is beautiful!

Resources