I've been thinking about this for a while now, but I am still not sure as the best way to go about it.
So basically, in my online shop I have an order table:
+------+-------+---------+-------------+----------------+--------------+--------+
| id | name | email | grand-total | shipping-costs | address | status |
+------+-------+---------+-------------+----------------+--------------+--------+
| 4312 | Roger | r#g.com | 5.99 | 1 | 22 Road Lane | 1 |
+------+-------+---------+-------------+----------------+--------------+--------+
And linked to that table is the cart table:
+-----+---------+-----------+---------------+-------+----------+--------+
| id | orderID | productID | name | price | quantity | status |
+-----+---------+-----------+---------------+-------+----------+--------+
| 234 | 4312 | G55Sd | Super Product | 5.99 | 1 | 1 |
+-----+---------+-----------+---------------+-------+----------+--------+
This all works correctly. However, the problem comes when I want to start adding discounts. I want to be able to look at a past order, and know exactly what discount was applied, how much etc. But I don't know where to save it. And what if the customer has multiple discounts? I can't just add another column in the orders table for discount, or discount amount, as that wouldn't help future me look over it at all.
I was thinking maybe I could add a line in the cart table for that order, and apply it like a product, just with a minus amount. I could do with some advice please.
Be careful you don't over-normalise. Disk is cheap - I would consider holding discount details in the order table and the cart table. The business logic could be every product might accrue a discount and the order itself might have a discount on top of the product discount(s).
Related
I want to create table on the database to set how much is the discount for each user.
Table user_discount
-------------------------
|user | product_id | disc |
-------------------------
| A | 1 | $1 |
-------------------------
| B | 1 | $2 |
-------------------------
| C | 1 | $1 |
-------------------------
| A | 2 | $2 |
--------------------------
So, when user go to checkout page, the price will subtract with the discount value from table discount for each product that match in the cart.
Consider using membership plugin, anyone. There are a number of plugins available for this purpose. So you will define membership type, any user which will be eligible for a discounted rate under that membership type, will get the relevant discount.
I don't know if this question should be here or not but i don't see any other place fit to ask my problem.
See, i am developing an online food portal which obviously sells food , snacks ,cakes and desserts.The real deal comes up when i have to sell a cake which can exist in various weights such as 0.1|0.5|0.9|...4.5 and every one of them costs different.Furthermore, every one of them are present in different quantities in warehouse.
My solution to achieve this was to provide a different row for every variant
ID | product_code | product name | Quantity | price | weight | company_id
1 | 12345 | beer cake | 34 |345 |0.5 |343434defee
2 | 12345 | beer cake | 343 |600 |1.0 |343434defee
3 | 12345 | beer cake | 4 |845 |1.5 |343434defee
4 | 12346 | vodka cake | 341 |345 |0.5 |343434deereee
Here , i looked every product to be a different product,I provided the relation using product code while to differentitate every row , i choose id,product_code as the primary key.
But, using this method involves redudancy as well, every row is looked as a different product.So if i were to display them using php it would show them as different product.
Something like this,
How do i change my structure of my database in order to achieve a single product but with different variants option on the same item?
I could use a php solution , if it's there.
Regards,
BOTjr.
Split the table into two with product_code as foreign key.
Table One
ID | product_code | product name | company_id
1 | 12345 | beer cake |343434defee
2 | 12346 | vodka cake |343434deereee
Table Two
Product_code |Quantity | price | weight
12345 | 34 |345 |0.5
12345 | 343 |600 |1.0
12345 | 4 |845 |1.5
12346 | 341 |345 |0.5
Use Table One to display items, Use Table Two is product description page to select the right quantity
I have one question about my database.
table inventory
_______________________________________
id_item | item_name | quantity |price |
--------+------------+----------+------+
1 | brake | 20 |60 |
--------+------------+----------+------+
2 | oil filter | 20 |80 |
--------+------------+----------+------+
table invoice
______________________________
id_invoice | items | quantity |
-----------+-------+----------+
1 | 1,2 | 4, 1 |
-----------+-------+----------+
So I'm going to display back items in a table as an invoice ( view purpose )
but I'm stucked at how to explode/ display it using SQL.
I mean I want to display it like this:
table html
_________________________________________
No | item | quantity | total price |
---+------------+----------+-------------+
1 | brake | 4 | 240 |
---+------------+----------+-------------+
2 | oil filter | 1 | 80 |
---+------------+----------+-------------+
I just need a simple code to make this function. I only left this function to complete my system.
Thank you!
Follow the following steps : (dont have the patience to write the code for you right now, I am a PHP beginner too)..
Get the list of Invoice items by a select query on invoice table with the invoice number criteria.
Since your items and comma-separated in the database, get the quantity(list) field into a string variable.
Apply the explode function on the quantity(list) variable and get the output into an array.
Loop through the array and build the html rows. If you want a quick and generic function to do this, and if you know how PHP functions work, you can use readymade code html_show_array from here to accomplish this step.
I'm bending my mind for some time now over this problem. Could someone please help me?
I have two tables: products and product_attributes. The product has all basic product information and product_attributes has all specific information for products on different categories. It's much like the magenta attribute system. this table has 4 columns: id, product_id, attribute_name, attribute_value.
Now let's say a product has 2 attributes:
------------------------------------------------------
| id | product_id | attribute_name | attribute_value |
------------------------------------------------------
| 1 | 123 | length | 123cm |
------------------------------------------------------
| 2 | 123 | material | Denim |
------------------------------------------------------
| 3 | 123 | season | Summer |
------------------------------------------------------
Now if I set up the eloquent relationships and query a product, I get a product object with all three attributes. So far this is what I wanted. But now in a blade template I would like to be able to do something like this:
$product->attribute->length
Is this even possible or do I need to achieve these kind of things with a total different approach (like creating different tables for different product types/categories)?
Thanks in advance!
length is a tuple value not an attribute you need
$product->attribute->where('attribute_name', 'length')
or
$product->attribute->whereAttributeName('length')
I have one working import xml to my mysql, which import to tables.
Now I want to update with these imported tables my new tables. But I don't know how.
The importer import from 3 different xml.
products, price, stock
It's import to products, product_descriptions, images, etc
Example:
Products
ID | Name | stock | date
1 | product 1 | 9999 | 2013.07.13
2 | product 2 | ....
Product_description
ID | description | price | date | sale price
1 | product 1... | 1$ | 2013.07.17 | 0$
2 | Product 2 is blabla.. | 999 $ | 2013... | 10$
I want to update with these items my another tables:
posts
Post ID | post title | description | product ID
100 | products-name | product_description-description | product-ID <- with these item from another tables.
and,
postmeta
post id | meta | value
100 | price | products_description - price
100 | sale price | product_description - sale price
100 | title | products-name
100 | image | imagepath
I don't know how can I do this.
Anyone help me?
You can use INSERT INTO ... SELECT construction.
There is a nice manual from MySQL: http://dev.mysql.com/doc/refman/5.0/en/insert-select.html
For instance,
INSERT INTO posts (post_title, description)
SELECT
Products.Name, Products.stock
FROM Products
This will insert to the posts table all names & stock levels of your products in a title and description columns
P.S. I do not see any connection between Products and Product Description. Are there any foreign keys?