saf_fire Posted August 31, 2013 Posted August 31, 2013 I have build an online shopping store, but would want to give away a promo code or Gift coupon to some of my customers so that they can avail discounts while they check out. Please tell me what coding should I do or what addition should I do for this feature. 1
diogo Posted September 1, 2013 Posted September 1, 2013 I've never done this, but the first idea that comes to my mind is to create all the promotions as pages with a field for the code and another for the discount: -promotions --promo1(title, code, discount) --promo2(title, code, discount) --promo3(title, code, discount) When someone submits a code, you can look for the discount with: $discount = $pages->get("parent=/promotions/, code=$code")->discount; You can generate your dscount code with something like this http://stackoverflow.com/questions/3521621/php-code-for-generating-decent-looking-coupon-codes-mix-of-alphabets-and-number (first result on my google search), and make sure that the code is unique by turning that code into a function, and matching the result against your other discount codes: // written on the browser and not tested. might be completely wrong function generateCode(){ $chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $res = ""; for ($i = 0; $i < 10; $i++) { $res .= $chars[mt_rand(0, strlen($chars)-1)]; } foreach (wire('pages')->get("parent=/promotions")->children as $c) { if ($c->code == $res) { $res = 0; break; } } if ($res == 0) generateCode(); return $res; } 1
saf_fire Posted September 2, 2013 Author Posted September 2, 2013 Thank you for the help... I will try this out and tell the results soon.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now