Jump to content
  • 0

Importing Coupon Codes


Question

Posted

Does anyone know a quick way to import coupon codes?

 

WagJag.com is going to be running a special on my company and they've provided me with 1500 codes to import :o

 

 

5 answers to this question

Recommended Posts

  • 0
Posted

Does anyone know a quick way to import coupon codes?

 

WagJag.com is going to be running a special on my company and they've provided me with 1500 codes to import :o

 

Whoa, that's a lot of codes.

I suppose a utility to loop through all those coupon codes and enter them into the database would be necessary. There's currently no built in support for importing coupon codes.

  • 0
Posted

Sounds good.  I'm going to write a utility to iterate through this CSV and import it all the codes then.  If I could get some confirmation on which tables need to be updated that would really help.

Basically these Wag Jag coupon codes are going to give a 100% discount and will expire November 16th.  I created a special package just for the Wag Jag customers, which got assigned package id "10"

Looking at the DB I came up with this:
table: coupons
fields: id, code, company_id, used_qty, max_qty, start_date, end_date, status, type, recurring, limit_recurring
table: coupon_amounts
fields: coupon_id, currency, amount, type
table: coupon_packages
fields: coupon_id, package_id

%fcid% = first coupon code available

Pseudo code:

for $i = %fcid% to 1500+%fcid%
   table coupons
        id = $i, code = from csv, company_id = my company id, used_qty = 0, max_qty = 1, start_date = 2013-10-08 00:00:00, end_date = 2013-11-17 00:00:00, status = active, type = exclusive, recurring = 0, limit_recurring = 0
   table coupon_amounts
           coupon_id = $i, currency = my currency, amount = 100.0000, type = percent
   table coupon_packages
           coupon_id = $i, package_id = 10
loop

other than these three tables, are there any other tables I would have to update with the utility for a successful import?

  • 0
Posted

I don't think there any other tables to consider, however, if it were me, I'd use the API SDK and make a call to Coupons::add() to handle everything. Manually updating table data is prone to mistakes, especially for constraints that are not discernible from the database schema alone.

  • 0
Posted

$coupon = $GET['code'];

$id = $api->put("Coupons", "add", array('code' => $coupon, 'company_id' => "1", 'max_qty' => "1", 'end_date' => "2013-11-17 03:59:59",'recurring' => "0", 'limit_recurring' => "0", 'packages' => array('0' => "10"), 'currency' => "USD", 'amount' => "100.0000"))->response();

 

returns "Internal error: Failed to retrieve the default value"

 

can you point me in the right direction Tyson?

  • 0
Posted

Try using POST. The discount amount also needs to be in an array:

 

$id = $api->post("coupons", "add", array('code' => $coupon, 'company_id' => "1", 'max_qty' => "1", 'end_date' => "2013-11-17 03:59:59",'recurring' => "0", 'limit_recurring' => "0", 'packages' => array("10"), array(array('currency' => "USD", 'amount' => "100.0000"))))->response();

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...