News:

Support the VirtueMart project and become a member

Main Menu

Bug with the constant VM_VALUE_ADDED_TAX

Started by ViPeS, November 04, 2024, 11:29:56 AM

Previous topic - Next topic

ViPeS

I have a multilingual site. I override the VM_VALUE_ADDED_TAX constant for the Site and Administrator so that the cart displays the VAT according to the language. This works fine with the cart. But the name of the constant is displayed in the Products Admin Panel, not its value.
VM 4.2.18 11050, Joomla 5.2.1, PHP 8.3.8

hazael

#1
This is just the name of the calculation rule - it is not displayed anywhere. Why do you want to translate it into another language?

ViPeS

#2
To @hazael
The name of the calculation rule is displayed in the header of the cart table.
In Fig. 2 there are three images of the same product in different languages. And it should be displayed in its own language.
You are lucky that Poland switched to the English abbreviation VAT (Value Added Tax) instead of the Polish PTU (Podatek od Towarów i Usług). But other countries have their own abbreviation. For example, in Lithuania it is PVM, in Norway - МВА. It is a pity that VM did not provide for this for multilingual sites.
VM 4.2.18 11050, Joomla 5.2.1, PHP 8.3.8

hazael

#3
Ok, now I understand. But after all, you don't have to put the direct rule name in the front-end user interface.  You can just put the tax value, and next to it an independent variable with a string that will translate the name of the tax to you in any language.

Hmmm. if you added more than one tax rule (VatTax) for a single product, it might look weird. :)

Where does the shopping cart module come from? Surely it can be changed directly in its template

ViPeS

#4
QuoteWhere does the shopping cart module come from?
\components\com_virtuemart\views\cart\tmpl\default_pricelist.php
<?php if (VmConfig::get ('show_tax')) {
$tax vmText::('COM_VIRTUEMART_CART_SUBTOTAL_TAX_AMOUNT');
if(!empty($this->cart->cartData['VatTax'])){
if(count($this->cart->cartData['VatTax']) < 2) {
reset($this->cart->cartData['VatTax']);
$taxd current($this->cart->cartData['VatTax']);
$tax shopFunctionsF::getTaxNameWithValue(vmText::_($taxd['calc_name']),$taxd['calc_value']);
}
}
?>

<th class="vm-cart-item-tax" ><?php echo "<span  class='priceColor2'>" $tax '</span>' ?></th>
The word VAT is displayed in the cart as 'calc_name' according to the VM_VALUE_ADDED_TAX language.
It is also displayed correctly in Tax & Calculation Rule (Admin panel) via calc_name
/administrator/templates/vmadmin/html/com_virtuemart/calc/default.php
<td>
<span class="uk-hidden@m uk-margin-small-right md-color-grey-500"
  uk-tooltip="<?php echo vmText::_('COM_VIRTUEMART_NAME'?>"
  uk-icon="icon: pencil"></span>
<a href="<?php echo $editlink?>"><?php echo vmText::_($row->calc_name); ?></a>
</td>
But the word VAT is not displayed in Product pricing (Admin panel)
/administrator/templates/vmadmin/html/com_virtuemart/product/product_edit_price.php
<td>
<span uk-tooltip="<?php echo vmText::_('COM_VIRTUEMART_RULES_EFFECTING_TIP'?>">
<?php echo vmText::_('COM_VIRTUEMART_TAX_EFFECTING') . '<br />' $this->taxRules ?>
</span>
</td>
Here it is output via taxRules, but not as VAT but as VM_VALUE_ADDED_TAX.
How should I write the code here correctly?
VM 4.2.18 11050, Joomla 5.2.1, PHP 8.3.8

hazael

#5
Just replace it:

$tax = shopFunctionsF::getTaxNameWithValue(vmText::_($taxd['calc_name']),$taxd['calc_value']);
to
$tax = shopFunctionsF::getTaxNameWithValue(vmText::_ ('COM_VIRTUEMART_CART_SUBTOTAL_TAX_AMOUNT'),$taxd['calc_value']);

You can insert any language variable that suits you and adapt it to other languages
COM_VIRTUEMART_CART_SUBTOTAL_TAX_AMOUNT


In the administration panel, name the rule for the tax whatever you want, because only you can see it - I assume so ;-)

ViPeS

This option is not suitable. The VM system constant COM_VIRTUEMART_CART_SUBTOTAL_TAX_AMOUNT contains "Tax" and it is unknown where else it is used. Instead of $this->taxRules I want to have the output of any user constant.
I am not a programmer, I do not know how to write this correctly.
VM 4.2.18 11050, Joomla 5.2.1, PHP 8.3.8

hazael

#7
 I gave you this string as an example. I have already written to you above that you can enter anything else - practically anything you want. You don't really need to be a programmer for this. I'm also not a programmer, as it's not my goal, but sometimes all it takes is logical thinking and a bit of independence. In this case, a basic knowledge of Joomla is all you need.

You create a unique string of characters: MY_NAME_FOR_TAX or anything else:
$tax = shopFunctionsF::getTaxNameWithValue(vmText::_ ('MY_NAME_FOR_TAX'),$taxd['calc_value']);
In the panel, you open the page:
/administrator/index.php?option=com_languages&view=overrides
...and assign values to the newly created language constant depending on the selected language

ViPeS

#8
I don't want to change anything in the cart code!
I want to change the output ($this->taxRules) of Calculation Rule name in Product pricing (Admin panel)
/administrator/templates/vmadmin/html/com_virtuemart/product/product_edit_price.php
<td>
<span uk-tooltip="<?php echo vmText::_('COM_VIRTUEMART_RULES_EFFECTING_TIP'?>">
<?php echo vmText::_('COM_VIRTUEMART_TAX_EFFECTING') . '<br />' $this->taxRules ?>
</span>
</td>
In Tax & Calculation Rule (Admin panel) the name is displayed regardless of whether the value or user constant is written.
/administrator/templates/vmadmin/html/com_virtuemart/calc/default.php
<td>
<span class="uk-hidden@m uk-margin-small-right md-color-grey-500"
  uk-tooltip="<?php echo vmText::_('COM_VIRTUEMART_NAME'?>"
  uk-icon="icon: pencil"></span>
<a href="<?php echo $editlink?>"><?php echo vmText::_($row->calc_name); ?></a>
</td>
VM 4.2.18 11050, Joomla 5.2.1, PHP 8.3.8