В общем может быть кому-то пригодиться. Я делал ширину и длину и добавлял в количество.
Так-с, делаем ширину и длину.
1) в administrator/components/com_virtuemart/clases/ps_product_attribute.php
на ~1058 строке будет функция show_quantity_box и на ~ 1069 строке вставляет код:
$uri = new JURI();
$uri->parse($category);
$categoryID = $uri->getVar('category_id');
и добавляем обязательный параметр $category:
1067:
function show_quantity_box( $product_id, $prod_id, $category, $child = false, $use_parent = 'N' ) {
на строке 1112 после
$tpl->set( 'quantity_options', $quantity_options ) ;
добавляем
$tpl->set( 'categoryID', $categoryID ) ;
Что мы имеем на данном шаге:
Дополнительный атрибут добавлен в div "Количество" - это номер РУТ категории.
2) В файле
/components/com_virtuemart/themes/YOUR_THEME/templates/product_details/includes/addtocart_form.tpl.php добавляем и изменяем такой код:
Было:
if ($children == "drop") {
echo $ps_product_attribute->show_quantity_box($product_id,$product_id);
}
Стало:
if ($children == "drop") {
$category = $pathway['0']->link;
echo $ps_product_attribute->show_quantity_box($product_id,$product_id, $category);
}
3) Если надо в категории выводить тогда в файлике
/components/com_virtuemart/themes/YOUR_THEME/templates/browse/includes/addtocart_form.tpl.php делаем точно такие же изменения.
4) В /components/com_virtuemart/themes/YOUR_THEME/templates/product_details/includes/quantity_bоx_general.tpl.php делаем такой код:
<?php if (!defined('_VALID_MOS') && !defined('_JEXEC')) die('Direct Access to ' . basename(__FILE__). ' is not allowed.');
mm_showMyFileName(__FILE__);
/** This template is used for the quantity box arrangement of products, within the add-to-cart form */
extract($quantity_options);
$html = '';?>
<script language="javascript">
jQuery(document).ready(function ($){
var weight = 2;
var height = 1;
var quantity = 1;
$("select").change(function () {
$("select option:selected").each(function () {
weight = $(this).val();
quantity = Math.round(parseFloat(height)*100 * parseFloat(weight)*100)/10000;
reuse();
});
});
$("input.inputboxquantity2").change(function () {
height = $(this).val();
quantity = Math.round(parseFloat(height)*100 * parseFloat(weight)*100)/10000;
reuse();
});
function reuse() {
$('input.hidden').attr('value','');
$('input.hidden').attr('value',quantity);
}
});
</script>
<?php
if (!$child && $display_type != 'hide' && $categoryID != '3' && $categoryID != '38') {
$html = '<span class="quantity" style="display:block;"><label for="quantity' . $prod_id . '" class="quantity_box">' . $VM_LANG->_('PHPSHOP_CART_QUANTITY'). ': </label>';
} else {
$html = '<span class="quantity" style="display:block;"><label for="quantity' . $prod_id . '" class="quantity_box">Ширина: </label>';
}
if ($categoryID == '3' || $categoryID == '38') {
$width = array('2','2.5','3','3.5','4','5');
$code = '<select class="inputboxquantity1" class="quantity" name="quantity[]">';
foreach($width as $v) {
$code .= ' <option value="' . $v . '"';
if ($v == $quantity) {
$code .= ' selected="selected"';
}
$code .= '>' . $v . "</option>\n";
}
$code .= "</select>\n<br>";
$code .= '<span class="quantity" style="display:block;"><label for="quantity' . $prod_id . '" class="quantity_box">Длина: </label><input type="text" class="inputboxquantity2" size="4" value="' . $quantity . '" />';
$html .= $code;
} else {
switch ($display_type) {
case "radio" : //Radio Box
$html .= '<input type="hidden" id="quantity' . $prod_id . '" name="quantity[]" value="' . $quantity . '" />';
$html .= '<input type="radio" class="quantitycheckbox" id="selItem' . $prod_id . '" name="selItem" value="0" ';
if ($quantity > 0) {
$html .= 'checked="checked" ';
}
$html .= 'onclick="alterQuantity(this.form)" />';
break;
case "hide" : // Hide box - but set quantity to 1!
$html .= '<input type="hidden" id="quantity' . $prod_id . '" name="quantity[]" value="1" />';
break;
case "check" :
$html .= '<input type="hidden" id="quantity' . $prod_id . '" name="quantity[]" value="' . $quantity . '" style="vertical-align: middle;"/>
<input type="checkbox" class="quantitycheckbox" id ="selItem' . $id . '" name="check[]" ';
if ($quantity > 0) {
$html .= 'checked="checked"';
}
$html .= ' value="1" onclick="javascript: if(this.checked==true) document.getElementById(\'quantity' . $prod_id . '\').value = 1; else {document.getElementById(\'quantity' . $prod_id . '\').value=0;} "/> ';
break;
case "drop" :
$code = '<select class="inputboxquantity" id="quantity' . $prod_id . '" name="quantity[]">';
for ($i = $quantity_start; $i < $quantity_end + 1; $i += $quantity_step) {
$code .= ' <option value="' . $i . '"';
if ($i == $quantity) {
$code .= ' selected="selected"';
}
$code .= '>' . $i . "</option>\n";
}
$code .= "</select>\n";
$html .= $code;
break;
case "none" :
default:
$html .= '<input type="text" class="inputboxquantity" size="4" id="quantity' . $prod_id . '" name="quantity[]" value="' . $quantity . '" />
<input type="button" class="quantity_box_button quantity_box_button_up png" onclick="var qty_el = document.getElementById(\'quantity' . $prod_id . '\'); var qty = qty_el.value; if( !isNaN( qty )) qty_el.value++;return false;" />
<input type="button" class="quantity_box_button quantity_box_button_down png" onclick="var qty_el = document.getElementById(\'quantity' . $prod_id . '\'); var qty = qty_el.value; if( !isNaN( qty ) && qty > 0 ) qty_el.value--;return false;" /></span>
';
break;
}
}
if ($categoryID == '3' || $categoryID == '38') {
$html .= '<input type="hidden" class="hidden" size="4" id="quantity' . $prod_id . '" name="quantity[]" value="2" />';
} else {
$html .= '<input type="hidden" class="hidden" size="4" id="quantity' . $prod_id . '" name="quantity[]" value="1" />';
}
echo $html;
?>
5)Для тех, кому тоже не применимо решение с целыми числами, рассказываю:
1) в БД в таблице jos_vm_product поле product_in_stock меняем тип int на float
2) дальше работаем с файлом
../administrator/components/com_virtuemart/classes/ps_product.php
- в функции add находим строку 'product_in_stock' => vmRequest::getInt('product_in_stock'), и меняем getInt на getFloat
- в функции update делаем тоже самое
Теперь уже можно писать в остатках на складе дробные числа. Но еще остается сделать чтоб можно было при покупке вводить дробное число.
3) в БД в таблице jos_wm_order_item поле product_quantity меняем тип int на float
4) дальше работаем с файлом ../administrator/components/com_virtuemart/classes/ps_cart.php
- в функции add находим строку $quantity = intval($quantity); и комментируем ее или удаляем
- в функции update в строке $quantity = isset($d["quantity"])? (int)$d["quantity"] : 1; меняем int на float (наверно можно просто убрать (int), но лучше наверняка

)
- и аналогично делаем в функции updateSaved
P.S. Знаю, что здесь все коряво, неправильно и вообще быдлокод, но лучше что-то, чем ничего.