Page 1 of 1

coupons by category

Posted: Sun Feb 26, 2012 9:38 am
by mondokat
So, I noticed that coupons don't really go by category, like is sort of implied by the interface. What it actually does is when you click the category control on the coupon code page, it adds all the products from that category that exist at the time into the product list and stores that in a "coupon_product" table in the database. There is no internal processing of categories at all.

The problem with this is that any new products added after the code won't be part of that coupon code, even if they are in the correct category. You'd have to add you product, then go back and re-add the category to the coupon code to "refresh" it. This is a non-starter for me, and must be fixed before I can use opencart, so I'm going to give a shot at writing a vqmod to fix it tonite. Wish me luck. I'll record progress here.

Re: coupons by category

Posted: Sun Feb 26, 2012 11:35 am
by mondokat
So, here's a list of things that likely should be changed:
  • 1. Clicking on categories should not populate the products list on the coupon page
    2. loading the page should remember what was clicked before
    3. referencing the coupon code should refer to the product list AND any products associated with the selected category.
The first step is easy. Looks like there is a line of javascript that references the scrollbox that houses the category list. Looks like this:

Code: Select all

$('input[name=\'category[]\']').bind('change', function() {
If I change the input name to something that doesn't exist, it will sufficiently break the function. I'm just going to have it look for an array called "junk". This step was easy.

Next step is to make it remember what was selected. For that, I'm going to have to make a schema change in the db, add a new table (coupon_category) and add the contents of the control to it. I'll look at how the product scrollbox gets populated and just copy that code.

Re: coupons by category

Posted: Sun Feb 26, 2012 12:41 pm
by mondokat
Man, the indention in this code is all over, yuck. Code style makes for good readability, guys. C'mon.

Re: coupons by category

Posted: Sun Feb 26, 2012 1:37 pm
by mondokat
I just learned that order of operation matters in vqmod. If you do a insert of some code on one pass that matches a replace on a second pass, it will modify the inserted code. Good to know.

Re: coupons by category

Posted: Sun Feb 26, 2012 2:25 pm
by mondokat
Done with making the ui elements work as expected. The category selector is actually more closely related to the product page's category selector than the coupon page's product selector on the front end, but more like the product selector on the backend. Pretty easy to mod, just took me a while to find all the pieces. Ok, so now that the admin pages will let me configure it, I need to figure out how to make it get applied when checking out. I have an idea for this already, or I wouldn't have even started, I am pretty confident.

Re: coupons by category

Posted: Sun Feb 26, 2012 4:12 pm
by mondokat
So I wrote a mod for "catalog/model/checkout/coupon.php", and it is working. Yay! I can't find another place where this code would be used, but if anybody knows any different, I'd love to hear it. It is definitely calculating correctly on the checkout page though. I have checked a category in my coupon code admin ui, and an item in that category reflects the code. awesome. This was easier than I thought.

Re: coupons by category

Posted: Mon Feb 27, 2012 2:59 am
by mondokat
And, since I don't think this thing is worth ten bucks (the minimum you can charge on the extensions web site on opencart.com, wish I could charge a dollar, beer money), here it is for free:

http://www.opencart.com/index.php?route ... on_id=5166

Re: coupons by category

Posted: Mon Feb 27, 2012 7:30 am
by Lisaweb
This is great work, really appreciate the effort, thanks much! I'm gonna go download and try it now...

Re: coupons by category

Posted: Sat May 05, 2012 8:52 pm
by tarang1906
Hi mondokat,

Awesome work!!

I am facing an issue with coupons, i know it might not be the right place to post this, but i have already started a thread on this with no response! http://forum.opencart.com/viewtopic.php?f=24&t=54253

When I select a category, ALL the products from ALL the categories are getting inserted in the products section...whereas only products from that particular category should be added.

I check my files with OC original ones but no difference...! ???

I tried with your module to see if this issue could get solved..but nothing! Its working the same way with the above issue.

Could you please suggest something?

Really appreciate any help. Please reply


Thanks

Re: coupons by category

Posted: Tue May 08, 2012 8:30 pm
by burley
WoW! mondokat!!! really awesome work, thanks for your efforts!
This is a great addition to the shop and very much needed!

Going to download and install it right now.

Voting for "mod of the month" if there were such a thing!!


Edit: did anyone get it to work in v1.5.1? I installed it but can't seem to get it to work.
At least I can't see anything different in my coupon section.