Skip to content
Snippets Groups Projects
Commit 6ba51b36 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 1.1.0: Allow ShippingWithTax in assignments

parent d8729628
Branches
Tags V1.1.0
No related merge requests found
...@@ -16,7 +16,7 @@ VMSHIPMENT_RULES_HELP="<div style='background: #DDDDDD; padding:5px; margin:3px; ...@@ -16,7 +16,7 @@ VMSHIPMENT_RULES_HELP="<div style='background: #DDDDDD; padding:5px; margin:3px;
<li>All rule parts with <b>comparison operators (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</b> are conditions.</li> <li>All rule parts with <b>comparison operators (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</b> are conditions.</li>
<li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li> <li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li>
<li>A condition can consist of multiple chained comparisons.</li> <li>A condition can consist of multiple chained comparisons.</li>
<li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost if the rule matches). The <tt>Shipping=</tt> can be left out. I.e. a rule part consisting only of a numerical value is understood as shipping cost.</li> <li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost without tax if the rule matches) and <b><tt>ShippingWithTax</tt></b> (shipping cost including taxes if the rule matches). The <tt>Shipping=</tt> can be left out (<tt>ShippingWithTax=</tt> can not be left out). I.e. a rule part consisting only of a numerical value is understood as net shipping cost without tax.</li>
</ul> </ul>
<p>EXAMPLE: A rule named &quot;Europe&quot; that sets shipping costs of 4.50 for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50&lt;=Amount&lt;100; Shipping=4.50<br>Name=Free Shipping; 100&lt;= Amount; 0</tt></blockquote> <p>EXAMPLE: A rule named &quot;Europe&quot; that sets shipping costs of 4.50 for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50&lt;=Amount&lt;100; Shipping=4.50<br>Name=Free Shipping; 100&lt;= Amount; 0</tt></blockquote>
</div>" </div>"
...@@ -26,7 +26,7 @@ VMSHIPMENT_RULES_HELP_ADV="<div style='background: #DDDDDD; padding:5px; margin: ...@@ -26,7 +26,7 @@ VMSHIPMENT_RULES_HELP_ADV="<div style='background: #DDDDDD; padding:5px; margin:
<li>All rule parts with <b>comparison operators (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</b> are conditions.</li> <li>All rule parts with <b>comparison operators (&lt;, &lt;=, =&lt;, ==, !=, &lt;&gt;, &gt;=, =&gt;, &gt;)</b> are conditions.</li>
<li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li> <li> Supported <b>variables (case-insensitive)</b>: <b><tt>Amount</tt></b>, <b><tt>Weight</tt></b>, <b><tt>ZIP</tt></b>, <b><tt>Products</tt></b> (number of different products), <b><tt>Articles</tt></b> (counted with quantity), <b><tt>Volume</tt></b> (total volume of the order) and <b><tt>MinVolume</tt>, <tt>MinLength</tt>, <tt>MinWidth</tt>, <tt>MinHeight</tt></b> as well as the same variables with <tt>Max</tt> instead of <tt>Min</tt>.</li>
<li>A condition can consist of multiple chained comparisons.</li> <li>A condition can consist of multiple chained comparisons.</li>
<li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost if the rule matches). The <tt>Shipping=</tt> can be left out. I.e. a rule part consisting only of a numerical value is understood as shipping cost.</li> <li>All rule parts of the form <b><tt>[VARIABLE]=VALUE</tt> are assignments</b>, with <tt>[VARIABLE]</tt> being one of <b><tt>Name</tt></b> (optional name of the rule, displayed in the cart and invoice), <b><tt>Shipping</tt></b> (shipping cost without tax if the rule matches) and <b><tt>ShippingWithTax</tt></b> (shipping cost including taxes if the rule matches). The <tt>Shipping=</tt> can be left out (<tt>ShippingWithTax=</tt> can not be left out). I.e. a rule part consisting only of a numerical value is understood as net shipping cost without tax.</li>
<li>In the advanced version, all expressions (conditions and shipping costs) may contain <b>arbitrary basic arithmetic expressions (+, -, *, /, %, ^ and parentheses)</b> of the above variables.</li> <li>In the advanced version, all expressions (conditions and shipping costs) may contain <b>arbitrary basic arithmetic expressions (+, -, *, /, %, ^ and parentheses)</b> of the above variables.</li>
</ul> </ul>
<p>EXAMPLE: A rule named &quot;Europe&quot; that sets shipping costs of 5€ plus 1.50€ per article for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50&lt;=Amount&lt;100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100&lt;= Amount; 0</blockquote> <p>EXAMPLE: A rule named &quot;Europe&quot; that sets shipping costs of 5€ plus 1.50€ per article for order amounts from 50 to less than 100, and free shipping from 100€ on would be:</p><blockquote><tt>Name=Europe; 50&lt;=Amount&lt;100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100&lt;= Amount; 0</blockquote>
......
No preview for this file type
No preview for this file type
...@@ -226,6 +226,7 @@ class plgVmShipmentRules_Shipping extends vmPSPlugin { ...@@ -226,6 +226,7 @@ class plgVmShipmentRules_Shipping extends vmPSPlugin {
$method->matched_rule = $r; $method->matched_rule = $r;
$method->rule_name = $r->name; $method->rule_name = $r->name;
$method->cost = $r->getShippingCosts($cartvals); $method->cost = $r->getShippingCosts($cartvals);
$method->includes_tax = $r->includes_tax;
return $method->cost; return $method->cost;
} }
} }
...@@ -234,6 +235,57 @@ class plgVmShipmentRules_Shipping extends vmPSPlugin { ...@@ -234,6 +235,57 @@ class plgVmShipmentRules_Shipping extends vmPSPlugin {
return 0; return 0;
} }
/**
* update the plugin cart_prices (
*
* @author Valérie Isaksen (original), Reinhold Kainhofer (tax calculations from shippingWithTax)
*
* @param $cart_prices: $cart_prices['salesPricePayment'] and $cart_prices['paymentTax'] updated. Displayed in the cart.
* @param $value : fee
* @param $tax_id : tax id
*/
function setCartPrices (VirtueMartCart $cart, &$cart_prices, $method) {
if (!class_exists ('calculationHelper')) {
require(JPATH_VM_ADMINISTRATOR . DS . 'helpers' . DS . 'calculationh.php');
}
$calculator = calculationHelper::getInstance ();
$value = $calculator->roundInternal ($this->getCosts ($cart, $method, $cart_prices), 'salesPrice');
$_psType = ucfirst ($this->_psType);
$cart_prices[$this->_psType . 'Value'] = $value;
$taxrules = array();
if (!empty($method->tax_id)) {
$cart_prices[$this->_psType . '_calc_id'] = $method->tax_id;
$db = JFactory::getDBO ();
$q = 'SELECT * FROM #__virtuemart_calcs WHERE `virtuemart_calc_id`="' . $method->tax_id . '" ';
$db->setQuery ($q);
$taxrules = $db->loadAssocList ();
}
if (count ($taxrules) > 0) {
if ($method->includes_tax) {
$cart_prices['salesPrice' . $_psType] = $calculator->roundInternal ($cart_prices[$this->_psType . 'Value'], 'salesPrice');
// Calculate the tax from the final sales price:
$calculator->setRevert (true);
$cart_prices[$this->_psType . 'Tax'] = $cart_prices['salesPrice' . $_psType] - $calculator->roundInternal ($calculator->executeCalculation($taxrules, $cart_prices[$this->_psType . 'Value'], true));
$calculator->setRevert (false);
} else {
$cart_prices['salesPrice' . $_psType] = $calculator->roundInternal ($calculator->executeCalculation ($taxrules, $cart_prices[$this->_psType . 'Value']), 'salesPrice');
$cart_prices[$this->_psType . 'Tax'] = $calculator->roundInternal (($cart_prices['salesPrice' . $_psType] - $cart_prices[$this->_psType . 'Value']), 'salesPrice');
}
$cart_prices[$this->_psType . '_calc_id'] = $taxrules[0]['virtuemart_calc_id'];
} else {
$cart_prices['salesPrice' . $_psType] = $value;
$cart_prices[$this->_psType . 'Tax'] = 0;
$cart_prices[$this->_psType . '_calc_id'] = 0;
}
}
private function parseMethodRule ($rulestring, $countries, $tax, &$method) { private function parseMethodRule ($rulestring, $countries, $tax, &$method) {
$rules1 = preg_split("/(\r\n|\n|\r)/", $rulestring); $rules1 = preg_split("/(\r\n|\n|\r)/", $rulestring);
...@@ -478,7 +530,7 @@ class ShippingRule { ...@@ -478,7 +530,7 @@ class ShippingRule {
var $tax_id = 0; var $tax_id = 0;
var $conditions = array(); var $conditions = array();
var $shipping = 0; var $shipping = 0;
var $shippingWithTax = 0; var $includes_tax = 0;
var $name = ''; var $name = '';
function __construct ($rule, $countries, $tax_id) { function __construct ($rule, $countries, $tax_id) {
...@@ -495,7 +547,7 @@ class ShippingRule { ...@@ -495,7 +547,7 @@ class ShippingRule {
function handleAssignment ($variable, $value, $rulepart) { function handleAssignment ($variable, $value, $rulepart) {
switch ($variable) { switch ($variable) {
case 'shipping': $this->shipping = $this->parseShippingTerm($value); break; case 'shipping': $this->shipping = $this->parseShippingTerm($value); break;
case 'shippingwithtax': $this->shippingWithTax = $this->parseShippingTerm($value); break; case 'shippingwithtax': $this->shipping = $this->parseShippingTerm($value); $this->includes_tax = True; break;
case 'name': $this->name = $value; break; case 'name': $this->name = $value; break;
default: JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_UNKNOWN_VARIABLE', $variable, $rulepart), 'error'); default: JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_UNKNOWN_VARIABLE', $variable, $rulepart), 'error');
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment