Hi there,
I'm writing a very simple shopping cart for a friend, but I'm confusing myself with the SQL required to return postage costs for each product in the cart, at checkout.
It's probably best to show you my tables first, each postage rate can apply to multiple products, product ranges, and countries. For example, postage rate X could be $80 postage to USA, France, Germany for all products within ranges 1,2,3 and product 15 which is not in the aforementioned ranges.
At checkout, my script loops through each product in the cart passing the productID and customer's countryID to a function which queries the database for a postage rate for the item. These rates are then added together to give the postage total for an order.
Ideally, I would like the postage rate for a productID to override that of a rangeID if applicable. My table structures are below:
Here is my attempt at the SQL for returning a product's postage, as you can see I haven't been able to include shopPostageCoun try (really confused!)
[CODE=SQL]
SELECT *
FROM ((product
RIGHT JOIN shopPostageRang e ON productRangeID= shopPostageRang e.rangeID)
RIGHT JOIN shopPostageProd uct ON product.product ID=shopPostageP roduct.productI D)
INNER JOIN shopPostage ON
shopPostageProd uct.postageID=s hopPostage.post ageID
OR
shopPostageRang e.postageID=sho pPostage.postag eID
WHERE product.product ID =13 AND shopPostageCoun try.countryID=2
[/CODE]
Any help with this would be greatly appreciated!
Kind Regards,
Alex
I'm writing a very simple shopping cart for a friend, but I'm confusing myself with the SQL required to return postage costs for each product in the cart, at checkout.
It's probably best to show you my tables first, each postage rate can apply to multiple products, product ranges, and countries. For example, postage rate X could be $80 postage to USA, France, Germany for all products within ranges 1,2,3 and product 15 which is not in the aforementioned ranges.
At checkout, my script loops through each product in the cart passing the productID and customer's countryID to a function which queries the database for a postage rate for the item. These rates are then added together to give the postage total for an order.
Ideally, I would like the postage rate for a productID to override that of a rangeID if applicable. My table structures are below:
Code:
product (productID*, productName, productPrice, productRangeID) shopPostage (postageID*, postagePrice, postageFriendlyName) shopPostageProduct(ID*, postageID, productID) shopPostageRange(ID*, postageID, rangeID) shopPostageCountry(ID*, postageID, countryID)
[CODE=SQL]
SELECT *
FROM ((product
RIGHT JOIN shopPostageRang e ON productRangeID= shopPostageRang e.rangeID)
RIGHT JOIN shopPostageProd uct ON product.product ID=shopPostageP roduct.productI D)
INNER JOIN shopPostage ON
shopPostageProd uct.postageID=s hopPostage.post ageID
OR
shopPostageRang e.postageID=sho pPostage.postag eID
WHERE product.product ID =13 AND shopPostageCoun try.countryID=2
[/CODE]
Any help with this would be greatly appreciated!
Kind Regards,
Alex
Comment