News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to add another Product Unit

Started by edudflog, September 06, 2012, 03:37:10 AM

Previous topic - Next topic

edudflog

I am truly new to Virtuemart and have had several challenges.  I've worked through most on my own but this one has me stumped.

On the Product Dimensions and Weight tab in the product module, the Product Unit drop down list only shows the following:

kg, 100 mg, m, m2, m3, l and 100ml.  It does not show "pieces" which is what I need.  How do I get "pieces" onto the list so it will display?

Thanks for anyone's assistance

Joomla v 2.5.6
VM 2.0.10
PHP ver: 5.2.17


[attachment cleanup by admin]

ivus

#1
Hi edudflog,

HMMM... this is odd. The list has been hard coded into a function.

To modify it you'll need to open the following file "/administrator/components/com_virtuemart/helpers/shopfunctions.php" @ line 467. Look for the function "static function renderUnitIsoList($name, $selected){}"



static function renderUnitIsoList($name, $selected){

$weight_unit_default = array(
'KG' => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_KG')
, '100MG' => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_100MG')
, 'M'   => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_M')
, 'SM'   => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_SM')
, 'CUBM'   => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_CUBM')
, 'L'   => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_L')
, '100ML'   => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_100ML')
);
foreach ($weight_unit_default as  $key => $value) {
$wu_list[] = JHTML::_ ('select.option', $key, $value, $name);
}
$listHTML = JHTML::_ ('Select.genericlist', $wu_list, $name, '', $name, 'text', $selected);
return $listHTML;
}



to add you own, just copy and adjust the last item:

      , '100ML'   => JText::_ ('COM_VIRTUEMART_UNIT_SYMBOL_100ML')

to

      , 'YOUR VALUE'   => JText::_ ('YOUR TEXT')

I hope this helps.

edudflog

This helped immensely.  Thank you very much for providing the information.

Regards

Bill

mykee

Please add this unit to list by default, because TV or DVD Player not sell with kg or m3, just pieces...
Thanks!

Milbo

but TV or DVD DONT HAVE A UNIT PRICE!

man, guys, come on, put your brain together. Look here http://www.mathsisfun.com/measure/unit-price.html.
You cannot do this with a DVD, or TV. You buy stuff like this in whole pieces. The unitprice is done for fluids, meterware, cutware and products which can be sold in different units.
you cannot buy a 0.5 TV. So if you sell something like this, just leave it empty. Furthermore in this list are only units, which are legal according to EU law.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

edudflog

Milbo:

Your reply is a bit surprising.  Last things first - Virtuemart may have included only those units that are legal according to EU law, however unless I am mistaken, you are trying to distribute this excellent shop system worldwide.  By restricting it to only EU sanctioned units, you are doing a disservice to all other people trying to use Virtuemart in non-EU countries.  Unless VM has been developed with the financial support of the EU with a caveat that only EU units are acceptable, I don't quite understand the logic.

Second, as foolish as it sounds to you, there are reasons to have "pieces" or other unit descriptors in the list (or at least an easy way to add other units.)  If I sell widgets and each widget unit has 3 pieces, a buyer should know that, the same way a buyer should know that each unit weighs 100 KG.  If nothing else, would it not be helpful to end users to add an easy way to supplement the list with other units?

Finally, like many others, I am new to Virtuemart and am using it to make building a website a bit easier for someone who does not know coding.  As far as I can see in my version of Virtuemart, Kg is a default unit and I cannot leave the box blank.  Please correct me if I am wrong.

I hope you take these comments constructively.

Thanks

efocus

I want to chime in. I'm assuming this feature allows customers to order decimal quantities or product? If that's right, I'm thrilled.

I had to have VM 1.2 custom hacked in the past to allow for purchasing yards of fabric. It would be great if I could add in yards so customers can order 1.75 yards without hacking VM in the future. I know others sell things by the inch, foot, pound, etc. I was told as a schoolchild that we were changing to the metric system here in the U.S. Well, that was 40 years ago and we're still using old measurements so we have to deal with them.

sandomatyas

I have to migrate a VM 1.1.3 shop to 3.0.16 where the customer uses "product unit" a lot because this is a free text field.
They don't want to display the unit price but the sales price like this:
Price $123 / piece
Price $123 / pair
Price $123 / box
Price $123 / clew
Price $123 / bottle
Price $123 / hour
etc
So no way to do this with VM?

Milbo

The best way would be to add another table, which keeps this entries.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sandomatyas

Please consider extending VirtueMart's funcionality with this. It would be great using a table to store units even it doesn't have admin form yet but it would be easily extendable. :)
Maybe it's only around renderUnitIsoList function in class ShopFunctions

Studio 42

Quote from: Milbo on September 13, 2016, 13:41:49 PM
The best way would be to add another table, which keeps this entries.

Hi max,
I have the same problem, and i hacked the list, because this is a migration from VM 1 and client cannot use another one, the price per unit use real price and using another field for ajax price refresh is not possible.
I think that a good idea is perhaps to add 1 or 2 Customizable option in the list
For my hack, i added "custom and COM_VIRTUEMART_UNIT_SYMBOL_CUSTOM, because i always use same.
But adding other option can be usefull too as COM_VIRTUEMART_UNIT_SYMBOL_PACK,COM_VIRTUEMART_UNIT_SYMBOL_BOTTLE or hour ...

Greets,
Patrick


Studio 42

Hi
I found here sample of code easy to implement, to do editable list : http://stackoverflow.com/questions/264640/how-can-i-create-an-editable-dropdownlist-in-html
This can be a solution, to use custom options.

sandomatyas

If I'm right from next year there will be a law in Hungary which says that every online shop needs to display unit price, but if you are using a bit different units as the list in Virtuemart (e.g. bottle, pair, event) you can't display it properly. So it would be quite important for Hungarian VM users

Studio 42

Quote from: sandomatyas on December 23, 2016, 12:29:03 PM
If I'm right from next year there will be a law in Hungary which says that every online shop needs to display unit price, but if you are using a bit different units as the list in Virtuemart (e.g. bottle, pair, event) you can't display it properly. So it would be quite important for Hungarian VM users
It's important for 2 of my customers.
So yes, i think this a needed feature for many shops, because the VM unit list is very short !

sandomatyas