Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6389683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:26:05+00:00 2026-05-25T03:26:05+00:00

We have one product, payment is by PayPal. Before going to PayPal need to

  • 0

We have one product, payment is by PayPal. Before going to PayPal need to apply a discount. We want to create a system where people can enter a gift certificate code to get product free (ie 100% discount) or enter some code to get a specific discount (ie SAVE10 – get a 10% discount).

Some codes will be just for one use (ie gift certificates), some can be used multiple times – ie SAVE10. Some will also have expiry dates.

Going to use MySQL and php to put together.

Has anyone out there already done this and put something together? or know of some code we can use to save time? Do not need entire shopping cart just the discount code parts..

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:26:06+00:00Added an answer on May 25, 2026 at 3:26 am

    This is essentially a one class functionality, really. You’d need a class interface that would look like this

     class ProductDiscount {
       /**
        * Create a NEW discount code and return the instance of
        *
        * @param $code string      the discount code
        * @param $discount float   price adjustment in % (ex:        
        * @param $options array    (optional) an array of options :
        *                            'expire'   => timestamp    (optional)
        *                            'limited'  => int          (optional)
        * @return ProductDiscount                         
        */
       static public function create($code, $discount, $options = NULL);
    
       /**
        * This essentially validate the code, and return the instance of the
        * discount if the code exists. The method returns null if the discount 
        * is not valid for any reason. If an instance is returned, to apply
        * the discount, one should invoke the "consume()" method of the instance.
        *
        * @param $code string
        *
        * @return ProductDiscount|null
        */
       static public function validate($code);
    
       private $_code;     // string
       private $_discount; // float
       private $_expire;   // unix timestamp (see time()) or null if unlimited
       private $_count;    // int or null if unlimited
    
       private function __construct();
       public function getCode();      // return string
       public function getDiscount();  // return float
       public function isLimited();    // return bool; true if $_count || $_expire is not null
       public function getCount();     // returns int; how many of this discount is left or null if unlimited
       public function getExpireDate();// returns int (unix timestamp) or null if unlimited
    
       public function consume();      // apply this discount now
    
       public function consumeAll();   // invalidate this discount for future use
    }
    

    The DB table could look like this

    id UNSIGNED INT(10) NOT NULL AUTOINCREMENT  -- (Primary Key)
    code VARCHAR(12) NOT NULL                   -- (Indexed, unique)
    discount UNSIGNED INT(3) NOT NULL           -- percent value 0..100
    expire DATETIME DEFAULT NULL                -- unlimited by default
    count INT(10) DEFAULT 1                     -- can be NULL
    

    Note : The validation process could just be a simple SELECT statement :

    SELECT * 
      FROM tblproductdiscount
     WHERE code = {$code}                  -- $code = mysql_real_escape_string($code)
       AND (count IS NULL OR count > 0)
       AND (expire IS NULL or expire > NOW())
    

    Then just use this class when validating checkout form. For example,

    if (!empty($discountCode)) {
       $discount = ProductDiscount::validate($discountCode);
    
       if ($discount !== null) {
          $price *= (1 - $discount->getDiscount());
          $discount->consume();
       }
    }
    

    Well, that’s somewhat how I would do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have implemented product management system.I want to add one new features in which
I have one product, let's say a book. Now I want to retrieve k
i have developed our company site where we show one product detail means one
I am working on one product which requires extensive testing of emails. I have
Did any one have luck recently register Visual studio 2008 express C# product? Look
I have some Javascript code that creates 2 arrays: One for Product Category and
I have two tables. One has some product details, the other holds various photos
I have two product tables Product1 and Product2. There is a one 2 one
I have such database structure (1 - one, 0 - many) Product 1->0 Orders
It's quite simple to program just one product to get sold via my payment

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.