diff --git a/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini b/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini index 6547cb73c12f00506c6091eee7a66e564eef80d4..61c468515cbceb56f8a25e55541c1e7e138d3c72 100644 --- a/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini +++ b/language/en-GB/en-GB.plg_vmshipment_rules_shipping.ini @@ -16,7 +16,7 @@ VMSHIPMENT_RULES_HELP="<div style='background: #DDDDDD; padding:5px; margin:3px; <li>All rule parts with <b>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</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>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> <p>EXAMPLE: A rule named "Europe" 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<=Amount<100; Shipping=4.50<br>Name=Free Shipping; 100<= Amount; 0</tt></blockquote> </div>" @@ -26,7 +26,7 @@ VMSHIPMENT_RULES_HELP_ADV="<div style='background: #DDDDDD; padding:5px; margin: <li>All rule parts with <b>comparison operators (<, <=, =<, ==, !=, <>, >=, =>, >)</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>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> </ul> <p>EXAMPLE: A rule named "Europe" 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<=Amount<100; Shipping=5+1.50*Articles<br>Name=Free Shipping; 100<= Amount; 0</blockquote> diff --git a/releases/plg_vmshipment_rules_shipping_advanced_v1.1.0.zip b/releases/plg_vmshipment_rules_shipping_advanced_v1.1.0.zip index 71c2698fe8ca2c5d4845c37e5e472481a0c1a01b..bc8194d2c78effe96a515be99d637d0c52a1b353 100644 Binary files a/releases/plg_vmshipment_rules_shipping_advanced_v1.1.0.zip and b/releases/plg_vmshipment_rules_shipping_advanced_v1.1.0.zip differ diff --git a/releases/plg_vmshipment_rules_shipping_v1.1.0.zip b/releases/plg_vmshipment_rules_shipping_v1.1.0.zip index 97ee94ce54995548e32170d87491efefb4ec0be4..4e48f0e5155014a3d69236c4796f41a724009750 100644 Binary files a/releases/plg_vmshipment_rules_shipping_v1.1.0.zip and b/releases/plg_vmshipment_rules_shipping_v1.1.0.zip differ diff --git a/rules_shipping.php b/rules_shipping.php index e11f970a1635f5699415791212423832bdff06ef..6c3265d4092351f58bcbf81f278b3e28b74dd7d8 100644 --- a/rules_shipping.php +++ b/rules_shipping.php @@ -226,6 +226,7 @@ class plgVmShipmentRules_Shipping extends vmPSPlugin { $method->matched_rule = $r; $method->rule_name = $r->name; $method->cost = $r->getShippingCosts($cartvals); + $method->includes_tax = $r->includes_tax; return $method->cost; } } @@ -234,6 +235,57 @@ class plgVmShipmentRules_Shipping extends vmPSPlugin { 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) { $rules1 = preg_split("/(\r\n|\n|\r)/", $rulestring); @@ -478,7 +530,7 @@ class ShippingRule { var $tax_id = 0; var $conditions = array(); var $shipping = 0; - var $shippingWithTax = 0; + var $includes_tax = 0; var $name = ''; function __construct ($rule, $countries, $tax_id) { @@ -495,7 +547,7 @@ class ShippingRule { function handleAssignment ($variable, $value, $rulepart) { switch ($variable) { 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; default: JFactory::getApplication()->enqueueMessage(JText::sprintf('VMSHIPMENT_RULES_UNKNOWN_VARIABLE', $variable, $rulepart), 'error'); }