EvDiscount Plugin
=================

Authors: Andy Carter


Introduction
------------

Plugin for handling discounts with EvCheckout.

Installation
------------

This is a composer plugin so from www/app just run composer as:-

	composer require evoluted/discount

To setup the database use the CakeDC Migrations plugin. To run the migrations and setup the database run:-

	Console/cake Migrations.migration run all --plugin EvDiscount

You will want to add an item to the admin menu for managing discounts:-

* /admin/ev_discount/discounts/

Attach event listeners in bootstrap:-

	App::uses('ClassRegistry', 'Utility');
	App::uses('DiscountListener', 'EvDiscount.Lib/Event');
	$Order = ClassRegistry::init('EvCheckout.Order');
	$Order->getEventManager()->attach(new DiscountListener());


Using EvDiscount
----------------

As long as you've setup the event listeners correctly everything should work fine.

You need to expose an Order.discount_code field somewhere in the checkout process (preferably in the basket).

EvDiscount will apply discount codes (Order.discount_code) when updating the basket total in EvCheckout. If the discount code is invalid it will remove the code from the order.

Once the order has been flagged as 'completed' it will add to the discount 'uses' counter. This only happens the first time the order is flagged as completed.

The discount_total column on ev_checkout_orders excludes VAT so when displaying this you may need to include it:-

	echo $this->Number->currency($cart['Order']['discount_total']*(1+($cart['Order']['subtotal_inc_vat']-$cart['Order']['subtotal'])/$cart['Order']['subtotal']));