Search code examples
joomlae-commercevirtuemart

Virtuemart Coupon Plugin based on quantity not value


I've had a look at available Virtuemart plugins and I can't find anything close to what I am after. This is what I need.

  • Allow admin user to create coupon codes. An import feature would be nice as there will be thousands but I can handle this bit if needed anyway.
  • The admin user selects the number of products the customer is allowed for each coupon code.
  • When the customer uses the coupon code they are allowed to choose any product on the website up to the total amount of products issued to the coupon. Regardless of the products price.
  • Nice extra would be to allow free shipping with the coupon.

I've looked at the possibility of extending virtuemart and I think it would be possible. It would however require quite a lot of changes and if I can find something that is halfway there it would help me on my way.

Thanks in advance.


Solution

  • OK well time was running out and I didn't get an answer so I rolled my own. It was actually fairly painless. I can't release the code but I can give you a good idea of the steps and a direction to go in.

    1. extend vm_ps_coupon and override the update, add and process methods. Add and update should only require a change to the array that is sent to the DB. See here for more info on extending classes
    2. Alter the enum in the database to allow for quantity as well as total and percent.
    3. Within your new update method handle the variation of quantity to do as you need.
    4. In the update method you can also set a flag for free shipping in a session variable.
    5. In templates/checkout edit list_shipping_methods.php. Simply check for the free shipping flag and load the free_shipping class. You can then call free_shipping->list_rates($vars);
    6. extend vm_ps_checkout, override the add method, call the parent add method and then check the result so you can delete the session variable for the free shipping.

    Finally you will need to make some changes in the HTML. Unfortunatly i could not find a way to override this easily and since its only two small changes to the markup i just went ahead and hacked the core. If anyone knows of another way that would be great? I did see something online about using a Joomla hook and a System plugin but I'd rather keep it reliant on Virtuemart only.

    In administrator/components/com_virtuemart/html/ edit coupon.coupon_form.php to show the new quantity radio button.

    Then edit coupon.coupon_list.php to display the correct values. Currently it will only display percent and total.

    Hope this helps someone in the future. If you need some assistance then post on here and I'll be happy to help.