Welcome Guest, Not a member yet? Register   Sign In
CI Cart Class, options array [Solved]
#1

[eluser]packetfox[/eluser]
Hello all,

i am working on a Shopping Cart that uses the CI Cart class, which is very nice.

I want to use the options field to store attributes for my products, such as color or size. This is easy, and nicely described in the manual. My problem however is that my attributes influence the price of the product; so a red laptop is more expensive than a blue laptop.

Can anyone share ideas about how or where to note down my price for each attribute? It seems i cannot store an array inside the options array. One idea i have is maybe simply storing an ID of an attribute inside the options array. Via that ID i can then query a database table that holds more detailed attribute info. Do you have a better idea?

Many thanks!
#2

[eluser]mandaman2k[/eluser]
Hi packetfox,

I have the same problem, could you be kindly enough to post you solution, i havetn figured it out yet

Thanks.
#3

[eluser]skunkbad[/eluser]
One way you could do this is by serializing an array and storing it as extra field in your products table. No need for an extra table and query.
#4

[eluser]mandaman2k[/eluser]
I Don't know much about serializing, but my DB structure is as follows:
Quote:Products Product-Characteristic Characteristic-Name
-------- ---------------------- -------------------
Prod_Id Charact_Id Name_Id
Prod_Nam Prod_Id Charact_Id
Prod_Price Charact_Name Name
Price

This way each product may have any given characteristics (Size, Color, etc..) and on the 3rd table, as the same as the products, the Characteristics may have any number of values (Size -> Small($0), Size-> Medium($10), Size -> Large($20), Color -> Red($0), Color -> Blue($0).

So what the app needs to do is that when the products page is loaded it should load the product, and different drop-downs for each characteristic.

And when the user chooses the quantity of that product, what i kind of made happen after a lot of coding which i think is quite bad programmed but came through is that if the user chooses 2 or more products, with a little help of jquery I can make that quantity of option appear:

Quote:Product Name -> qty[2]
-> Details 1
-> Dropdown Size
-> Dropdown Color
-> Details 2
-> Dropdown Size
-> Dropdown Color

and where I'm having most trouble is when the user submits the product, on the cart it should show:

Quote:Product_Name - $10
Detail 1
-> Medium - $10
-> Red - $0
Detail 2
-> Large - $20
-> Red - $0
Total $40

and I haven't quite figured it out on how to do it, I even did another post on how can I get all tables in one and only multidimensional array (http://ellislab.com/forums/viewthread/175089/) and another one on how could i break array so that i can show my cart like above (http://ellislab.com/forums/viewthread/175583/)

I hope I was clear enough

If someone could help me, I would be very grateful
#5

[eluser]skunkbad[/eluser]
Serializing an array simply stores it as a string so that you can insert it into a database. See the official php documentation:

http://php.net/serialize

You simply serialize the data before the db insert or update, and unserialize it when you want to use it. By storing all of your product data in one table, you don't have to worry about advanced queries to retrieve all product data. Community Cart does this with product pricing, because it allows for quantity discount. You can check it out using the link in my signature.
#6

[eluser]umefarooq[/eluser]
i am also facing the same problem, i have to different prices one is item own price and other additional price,i am saving that additional price in cart options but not able put in bill total how can i add that additional price in bill, additional price differ for each option , how can i add to the bill




Theme © iAndrew 2016 - Forum software by © MyBB