Community Forums

coupons by category

Coding & concept discussion for OpenCart v1.x development

coupons by category

Postby mondokat » Sat Feb 25, 2012 8:38 pm

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.
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby mondokat » Sat Feb 25, 2012 10:35 pm

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.
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby mondokat » Sat Feb 25, 2012 11:41 pm

Man, the indention in this code is all over, yuck. Code style makes for good readability, guys. C'mon.
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby mondokat » Sun Feb 26, 2012 12:37 am

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.
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby mondokat » Sun Feb 26, 2012 1:25 am

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.
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby mondokat » Sun Feb 26, 2012 3:12 am

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.
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby mondokat » Sun Feb 26, 2012 1:59 pm

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
mondokat
 
Posts: 27
Joined: Mon Feb 20, 2012 2:55 am

Re: coupons by category

Postby Lisaweb » Sun Feb 26, 2012 6:30 pm

This is great work, really appreciate the effort, thanks much! I'm gonna go download and try it now...
Using OC v1.5.4.1 with Evisu Theme
User avatar
Lisaweb
 
Posts: 123
Joined: Tue Dec 06, 2011 11:01 am

Re: coupons by category

Postby tarang1906 » Sat May 05, 2012 7:52 am

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! 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
tarang1906
 
Posts: 17
Joined: Wed Mar 07, 2012 8:41 am

Re: coupons by category

Postby burley » Tue May 08, 2012 7:30 am

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.
User avatar
burley
 
Posts: 488
Joined: Sun Oct 09, 2011 2:30 am


Return to Concepts

Who is online

Users browsing this forum: No registered users and 22 guests

Hosted by Arvixe Web Hosting