Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

DB - quantity is a calculated field?


specialk

Recommended Posts

First of all - I am very impressed with the entire application and the support offered by the community....and this is more of a question than suggestion.

I am not sure why the quantity of items is tracked in both the basket and order tables, when (I think) there should be an individual record for each line item. I only mean in the database tables - I understand why it is good for display purposes. It would make the adjustment of orders easier (i.e. I have 2 ABC products, you ordered 3 - just cancel a single line item) and allow for better control of discount campaigns (I have a coupon good for 1 free ABC, but I want to buy 2).

Am I missing something, or can anyone explain why this decision was made or suggest why changing this would be undesirable (other than the fact I am creating a lot of work for myself).

 

Thanks.

 

Kyle

Link to comment
Share on other sites

The basket is a temporary thing that changes prior to an order being complete.

 

The order, on the other hand is permanent.

 

Once a basket is processed via checkout ... then it will leave the basket and only be in the order.

 

This allows for flexibility and recalculation of prices etc. during the buying process. Otherwise, as a customer is buying and you are updating prices, quantity etc. they would not be in sync with one another.

Link to comment
Share on other sites

Hi Linda,

 

I may not have been clear - I think I have a good understanding of the shopping process from basket to order. I meant that if I have two ABC products each one would have it own record in the customer_basket table

 

current basket

product_id quantity price

ABC 2 14.00

DEF 1 12.00

 

proposed

product_id quantity price

ABC 1 14.00

ABC 1 14.00

DEF 1 12.00

 

And actually, the quantity field doesn't even need to be there - as a quantity of one is implied.

 

You would still have the ability to update basket (if prices/stock levels changed), you would just need to update two record (in this example). I can get the quantity of an item via SQL, and I believe it is common DB practice to not have calculated fields in a table.

Link to comment
Share on other sites

Once a shopping cart becomes an order ... the prices are now fixed they are not calculation.

 

As for the two seperate entries, for the same product with different attributes you will notice if you are on the Shopping Cart and click the link for one entry then the other, the selected attributes change so that the quanity can be updated correctly otherwise a new entry is made if the attributes change again.

 

On a product with no attributes, there is just the one entry and the attributes do not need to be considered to update the cart correctly.

 

If you look in the /includes/classes/shopping_cart.php you will see a variety of functions available in regards to the cart and how it is processed.

 

At this point, the cart has nothing to do with the order until the customer moves along to the checkout ... and until the order is confirmed nothing is put in the orders table.

 

Once in the orders table, everything is added to store the information as if it were frozen, not to be recalculated again, so to speak.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...