Creating Discount Code System (MySQL/php) -
We have a product, payments have been made by PayPal Before going to PayPal, we need to apply a discount, Where people want to get product free (i.e. 100% discount) you can enter a gift certificate code or you can enter some code to get a specific discount (i.e. sev 10 - 10% discount Please).
Some codes will only be used for one usage (i.e. gift certificate), some can be used multiple times - i.e. SAVE10 will also have an expiry date.
Is going to use MySQL and php to keep it together.
Has anyone done this and has done anything together? Or can we use some code to save time?
P> This is essentially the functionality of a class, actually In this case, you will need a class interface which will create a new discount code for
product discount {/ ** *} and return the * $ @ discount code code for the ultimate $ code string * @ best $ Expiry float value adjustment% ex: * @param $ option array (optional) An array of options: * 'expire' => timestamp (optional) * 'limited' => int (optional) * @ and Make a product discount * / stable public function ($ code, $ discount, $ option = zero); / ** * This essentially validates the code, and returns the example of discount if the code exists. * If there is an example returned, to apply the discount *, you should invite the example "Consumption ()" method. * * @ The ultimate $ code string * * @ Return product Discount | faucet * / stationary public The function valid ($ code); private $ _code; // string private $ _ Discount; // float private $ _ expire; // Unix Timestamp (View Time) or Unlimited Private $ _count; // integer or tap if unlimited private function __ conversion (); Public function getCode (); // return string public function getDiscount (); // Return Float is the public function (limited); // return bool; True if $ _count || $ _ Empire empty public function is not getCount (); // returns int; Unlimited public function getExpireDate (); // If you consume unlimited public functions like Return Int (Unix timestamp) or unlimited public functions, how many of these discounts are left or zero? // Consumption of public function now applicable on this discount (); // Invalid this discount for future use) The DB table can look like this
ID unintended INT (10) No tap control - (Primary Key) Code VARCHAR (12) No Zero - (Indexed, Unique) Exempt Countless INT (3) No Zero - Percentage End of 0.01.00 DATETIME DEFAULT NULL - By default Unlimited INT (10) DEFAULT 1 - < / Code> Note: The verification process can be just a simple SELECT statement: from SELECT * to tblproductdiscount WHERE code = {$ Code} - $ code = mysql_real_escape_string ($ code) and (count is zero or count> 0) and (when not ending or ending & gt; NOW ())
Then just use this class when validating the checkout form. For example,
(empty! $ Discount code) {$ discount = product discount :: Validate ($ discount code); If ($ rebate! == zero) {$ value * = (1 - $ discount-> get discount ()); $ Discount & gt; Consumption (); }} Well, it's up to some extent how I will do it.
Comments
Post a Comment