ecommerce site and product options displaying |
[eluser]mmatti[/eluser]
Hi, I'm new to CI and not very experienced in php either. Just started building ecommerce website (store with clothes), based on a book "Professional CodeIgniter". One of the changes I'm trying to apply is having as many options for products as it's needed- so quite a usual requirement for ecommerce website. So there's a table for products: Code: CREATE TABLE IF NOT EXISTS `products` ( And three tables for supporting product options: 1) product_options: Code: CREATE TABLE IF NOT EXISTS `products_options` ( 2) options Code: CREATE TABLE IF NOT EXISTS `options` ( 3) options_values Code: CREATE TABLE IF NOT EXISTS `options_values` ( Now, I've managed to create function that extracts available Option names (e.g.Colour, Size) for a specific product (input data for displaying products is $path which is seo slug, eg. www.mydomain.com/product/great-shirt, where 'product' is name of the controller function as I hid controller name in routes file). Here's the controller function: Code: function product($path){ Here's the MOptions model 2 functions: Code: function getProductOptions($path){ And here's the view for displaying single product: Code: <div class='product'>
[eluser]mmatti[/eluser]
And it produces the following html: Code: <div class='product'> What I want to achieve is that in the view there ware listed all the options available for a product being displayed (not all options available in the database) and next to each option name there would be a dropdown list with values for that option, e.g. Color - Dropdown(Red,Yellow,Blue) Size - Dropdown(L,XL,XXL) Any help or suggestions on how to solve that are highly appreciated, as it already gave me a big headache... If I need to post more information or other parts of the code please let me know.
[eluser]mmatti[/eluser]
maybe I wasn't clear on what I need help with- I don't know how to display- as you can see on the view it shows "Red" for both Color and Size, and I need it to show available colors and sizes as a dropdown. Please help me... anyone? Matt
[eluser]danmontgomery[/eluser]
Code: foreach ($options as $key => $opt_name){ This is poor logic... You're passing it an $options array with (presumably) each of the dropdown names (size, color, etc), and a $option_values array, which is supposed to produce different options for each iteration, even though nothing is done to it? You need to rethink this... You're getting $option_values directly from getOptionValues(), so I would look there. Code: if ($Q->num_rows() > 0){ Here, for example, you're only ever going to return one row, there's no iteration through the result.
[eluser]mmatti[/eluser]
Thanks for your reply. I figured that the way it should be done in the model is: for current_product { extract from db options assigned to current_product { for each of extracted options { extract values } so now my model looks like this: Code: function getProductOptions($path){ but still not sure if it's correct and what to do with controller and the view. |
Welcome Guest, Not a member yet? Register Sign In |