Commit d4cce0f1 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

AwoCoupon: First version of the AwoCoupon variables plugin

parent 237f155d
......@@ -6,7 +6,7 @@ defined ('_JEXEC') or die('Restricted access');
* AwoCoupon variables for VM Shipping by Rules
*
* @subpackage Plugins - VmShipmentRules
* @copyright Copyright (C) 2014 Reinhold Kainhofer, office@open-tools.net
* @copyright Copyright (C) 2015 Reinhold Kainhofer, office@open-tools.net
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
......@@ -23,22 +23,53 @@ if (!class_exists ('VmPlugin')) {
/** Extension plugin for the "Shipping by Rules" shipping plugin for VirtueMart
*/
class plgVmShipmentRulesRules_AwoCoupon extends VmPlugin {
class plgVmShipmentRulesAwoCoupon extends VmPlugin {
/** Trigger to add variables to the cart values
* You can add new variables to the $cartvals array or modify existing ones. They will be directly
* available in all rules.
* Please notice that this function might also be called for only a subset of products of the cart.
*/
function onVmShippingRulesGetCartValues(&$cartvals, $cart, $products, $method, $cart_prices) {
// First, make sure coupons are processes (VM core processes third-party coupons AFTER the shipping)
// This does NOT update the cart_prices array, but at least it makes sure Awocoupon has processed the coupon
JPluginHelper::importPlugin('vmcoupon');
if (!empty($cart->couponCode)) {
$dispatcher = JDispatcher::getInstance();
// TODO: This does not yet work...
// $returnValues = $dispatcher->trigger('plgVmCouponHandler', array($cart->couponCode, &$cart->cartData, $cart->cartPrices));
}
$coupon_discount = 0;
$session = JFactory::getSession();
$coupon_row = $session->get('coupon', '', 'awocoupon');
$cartvals['awoproductdiscount'] = 0.0;
$cartvals['awoproductdiscountnotax'] = 0.0;
// $cartvals['awoproductdiscounttax'] = 0.0;
$cartvals['awoshippingdiscount'] = 0.0;
$cartvals['awoshippingdiscountnotax'] = 0.0;
// $cartvals['awoshippingdiscounttax'] = 0.0;
$cartvals['awodiscount'] = 0.0;
if(!empty($coupon_row)) {
$coupon_row = unserialize($coupon_row);
$coupon_discount = $coupon_row['product_discount'] + $coupon_row['shipping_discount'];
// JFactory::getApplication()->enqueueMessage("<pre>AwoCoupon row: ".print_r($coupon_row,1)."</pre>", 'error');
$cartvals['awoproductdiscount'] = $coupon_row['product_discount'];
$cartvals['awoproductdiscountnotax'] = $coupon_row['product_discount_notax'];
// $cartvals['awoproductdiscounttax'] = $coupon_row['product_discount_tax'];
$cartvals['awoshippingdiscount'] = $coupon_row['shipping_discount'];
$cartvals['awoshippingdiscountnotax'] = $coupon_row['shipping_discount_notax'];
// $cartvals['awoshippingdiscounttax'] = $coupon_row['shipping_discount_tax'];
$cartvals['awodiscount'] = $coupon_row['product_discount'] + $coupon_row['shipping_discount'];
}
$cartvals['awodiscount'] = $coupon_discount;
$cartvals['amountaftercoupon'] = $cartvals['amount'] - $cartvals['awoproductdiscount'];
$cartvals['amountwithtaxaftercoupon'] = $cartvals['amountaftercoupon'];
$cartvals['taxamountaftercoupon'] = $cartvals['taxamount'] - ($cartvals['awoproductdiscount'] - $cartvals['awoproductdiscountnotax']);
$cartvals['amountwithouttaxaftercoupon'] = $cartvals['amountaftercoupon'] - $cartvals['taxamountaftercoupon'];
// TODO: Apply shipping coupon discounts
}
}
// No closing tag
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment