Guest Posted April 8, 2004 Posted April 8, 2004 How many times, how many lines, must we repeat before we realise? At least 6 times, at least 20 lines. Product code, people is a mess. I needed to change the pricing structure, to the following. Retail price. 2 membership levels. special offers. Customer gets.... Retail price, until they log in. Then everyone gets Level 1 price. Unless they upgrade, in which case they get level 2 price. Unless the special offer is better. Lots of if()'s and else's and queries, based originally on the Customer Group price module. When I found the code repeated again and again and again and again... annoyed yet? I was. Again and again and again... So... I started a Product class, put the price code in there, and replaced the 20 or 30 lines with 5. I dont have the time to compelte it, at least not for the next month or so, but if anyone wants me to post product.php or submit to CVS where we can all update it I will. Regards.
Mark Evans Posted April 8, 2004 Posted April 8, 2004 We will be looking into improving the product code at the same time we do the product attributes system. If you have some code you find that works I would be happy to take a look and see if we can get something in the core code. Mark Evans osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops) --------------------------------------- Software is like sex: It's better when it's free. (Linus Torvalds)
Guest Posted April 8, 2004 Posted April 8, 2004 An approach I propose. Move all functions that deal with Products to a Product class. Move all data that relates to products to a product class. Move all functions that deal with Customers to a Customer class. Move all data that relates to Customer to a Customer class. Move all MySQL data acquiring for the above into the classes (or ideally a base class, or indepentant class passed to the above.... a DB class with all DB functions and data). A lot of other encapsulatable parts of code can be classed to all our advanrages. Price... Account... Address... Product, customer, Cart but...... rather than just a collection of functions each be a defined component. 100% responsible for their area of functionality and state. OK, OK, OK, yes, I am from the OOP stables. I confess it! I will help, I need to know how you guys work about working with the code. To make these kind of changes means.... Writing the replacement OOP code... Most of which can be lifted for existing repeated or procedural code. Testing it.... Replacing the existing code with calls to the classes. testing it releaseing the beta... and so on I dont want to just fire code at you, incomplete I would like to talk about helping make osCommerce a maintainable and extentable project taking advantage of OOP and minimising code repeatition.
Mark Evans Posted April 9, 2004 Posted April 9, 2004 Move all functions that deal with Customers to a Customer class. Move all data that relates to Customer to a Customer class. Move all MySQL data acquiring for the above into the classes (or ideally a base class, or indepentant class passed to the above.... a DB class with all DB functions and data). All this is already done in CVS :-) Mark Evans osCommerce Monkey & Lead Guitarist for "Sparky + the Monkeys" (Album on sale in all good record shops) --------------------------------------- Software is like sex: It's better when it's free. (Linus Torvalds)
Guest Posted April 9, 2004 Posted April 9, 2004 Excellent, I'll check that out and rework my product class to fit and post it around here somewhere.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.