Appcelerator: The best way to create a Cart - shopping-cart

I wanna do an app store, and I need program a CART. This cart need to be a global var. Then, I think that i have two options:
1- Create a Global object with Alloy.Globals.
2- Create a new Modal and work with Collection.
Are there any other options? What is the best practice?

If the cart is an object or you must save data in database, colletion is better option, because you can list data saved more easily.

Related

Is it possible to make 'cart' with django Class Based View?

I am trying to make a simple e-commerce website and followed some tutorials.
However, the author of the book used complicated function based view to make cart function..
there are bunch of session stuffs.. and I don't understand the logic..
and I am trying to think the other way..
what about using database to store all the cart related data, and
use CBV to build it?
for example,
CartListView to see the contents of the cart, and CartUpdateView to change the quantity..
then are they going to be two different pages? separated page that user should go to the
different page to change the value??
please help me T T
You can access the session in any sort of CBV as self.request.session and a "shopping cart" is normally stored therein.
You'll certainly need to implement a CartListView to see what's in it, or possibly a CartEditView to show the cart with options to edit the quantities and delete anything that shouldn't be in there.
Adding products to the cart may well be an "Add" button on a ProductDetailView or lots of add buttons in a ProductListView. You might add a POST handler method to these views which are otherwise read-only (GET-only) bt default. Or you might make them FormViews, even though the form would be hidden and filled/POSTed by JS rather than the shopper doing anything other than clicking "add".
And then there will be a CheckoutView.
Check https://djangopackages.org/ (put "cart" in the search box). this will throw up several shopping cart things which might be the code you want, or the source of which might be a valuable learning resource before you end up rolling your own.

Saving all user input data in Django simply?

This is may be an obvious question to a Django expert, but is there a way that I can save all user inputs (clicks through content without having to explicitly save every entry in a table). If this is possible, then how do I access it later?
If I have to create models, like this I can:
#(within a view function)
UserInputs.objects.get_or_create(user=request.user,
selection1=request.POST.get('selection1'),
id=request.POST.get('id')),
thumbs_up=request.POST.get('thumbs_up'),
thumbs_down=request.POST.get('thumbs_down'),
comments=request.POST.get('comments')
)
Is there an easier way to get it done? Because I have lots and lots of different user click inputs and specifying every one like this will really slow down my application.
Is this data by chance saved in one of the sessions tables? Or can we create a custom sessions table to do this?

Updating model hasMany relationships in UI

I've trying to modify the contents of a hasMany relationship view some UI elements. I have two basic models, container and item. Containers have multiple items and they can have varying numbers of items. For instance:
App.Container.FIXTURES = [
{id:1,name:'Container 1',slots:[0,0]},
{id:2,name:'Container 2',slots:[0,0,0,0]},
{id:3,name:'Container 3',slots:[0,0,0]}
];
I'm using the id 0 as sort of an empty item. It shows that this container can have an item here, but it's currently empty. There are numerous different items that can go into each position.
In my app, I have a custom UI that I've created that allows a user to select a new item to fill each slot. The problem is that for some reason, it's not updating in the container model. No matter what I try, it's just updating in the view, but not on the actual model instance. I thought this would work because the properties would be automatically bound.
I've created a JSBin here displaying the problem. If you click the save button, a json object of the current state of the model will be printed to the console.
What can I do to update the actual model properties? Please keep in mind that the position matters. For instance, if I change the item in the middle position of three, only it should update; not pushed onto the end.
Thanks. Any ideas would be appreciated.
This is a modelling issue.
You have Container, each of which has many Item... except that what's actually happening is you're using the Item class as your options - this is your catalogue, if you will, and you want to put these items into "slots" which you haven't created a model for.
So, depending on what you want to do, you should probably model it like this (using better names - I chose mine for clarity of explanation):
Container hasMany Slots each of which is connected to its Item
So: Container hasMany -> Slots <- belongsTo Item
That is, you have a non-reified "join", which you're sort of calling "slots" and attaching to Container at the moment.
I say depending on what you want to do because I'm not sure if you want to have the simple case I outlined above, which is "here are a bunch of possible items you can choose to put any number of copies of into your containers" or if you want the more complicated to develop case which is "here is a bunch of items which are finite... as you add each item to a container, it disappears from the list of possibilities". To do the latter is much more complicated, but of course it's possible... this is how inventory systems work.
I hope that's answered your question...
To put it another way, you need to build yourself a Slot model, related to each of your other models, and manage the join properly. If you bind the slots properly to each dropdown then Ember will take care of hooking up the data for you.
Let me know if you need further help on how to do this.
I've modified your JSBin to comprehensively show you what I mean. Hope that helps explain it:
http://emberjs.jsbin.com/tenoqimu/5/edit

Best way to have an updatable object in a partial?

jsbin
I am new to ember.js and trying to figure out the best way to accomplish an updatable list.
The list, inside a partial, is updated when a list item from another object is clicked. Is it better to save the clicked(chosen) items in a separate model? or is it better to use an array in the controller as I was trying to do in the above jsbin?
In either case, how is it accomplished? In my above attempt the totalValue seems to update fine, but the array does not which makes me think I was going about it wrong.
The chosenList is an array and ember array has it's own api methods in order to inform observes...
With this variation in your code, the property updates http://jsbin.com/eyatORO/3/edit
this.get('chosenList').addObject({
title:item.title,
value:item.value
});
Good Luck

Django inline formset with child of a child

I have three models:
Variable, which has Group as a foreign key
Group, which has Set as a foreign key
Set
I want to create a form that lets user create a new Set based on existing Set. Only things that user is able to modify are the Set name and Variable values.
This has given me an idea of using inlineformset_factory to access models' children. Sadly, all the examples I found go only one layer down.
Is there any way to access the Variables of a Set through inlineformset_factory?
If not - what is a good way to accomplish my goal?
Thank you.
From my experience, it is not worth hacking the existing inlineformset_factory to achieve much beyond what it is meant to do.
You are better off writing a custom view with the qs you want to use and create unique ids for each form element, to identify its parent.