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

Boolean customfields is illogical :o

Started by hazael, March 09, 2023, 22:47:43 PM

Previous topic - Next topic

hazael

I have the latest version of Virtuemart. I'm trying to multiply the price in the cart using a boolean custom field, but some total crap comes up :o

For example, for multiply: Increase/Reduce

in product settings:
product base price = 100
field A = 1
field B = 10
field C = 100

A selection list is displayed in the cart:
A + 1 PLN
B + 12 PLN
C + 123 PLN

The same data in the case Percentage on Baseprice
A + 1% + 1 PLN
B + 1% + 10 PLN
C + 1% + 100 PLN

The second option, in terms of percentage, seems to count well, but I don't understand the "1%" part in each selection option?   :o

pinochico

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

hazael

There is no such thing as 0/1 in this default custom addon, which is called "boolean"
There is a selection list and each item has its value expressed as a percentage or as a multiplication of prices in the basket. I don't know why it's called boolean? :-/

I was looking for an add-on that would multiply the price in the basket depending on the option selected. It's probably the only add-on that has this capability, but it's acting weird  :D

pinochico

#3
Customfiled type boolean (B) is the only name, but inside code is as string (S).
Can you use for math operation field type string? Really?

If we used Customfield type Boolean as right Boolean (dropdown with values 1/0 or Yes/No) on our websites, we have to hack in core (sorry, I send info about this bug into forum - boolean is not right boolean before 7!!! years, when i worked in company EasySoftware and VM version was 3.0.3, but nothing changed - in version VM 2.6.X was right!!!!).

Our Hack is:


/* boolean - HACK */
case 'B':
return JHTML::_ ('select.booleanlist', 'field[' . $row . '][customfield_value]', 'class="inputbox"', $field->customfield_value) . '</td><td>' . $priceInput;
break;
/* string or integer */
case 'S':
case 'I':

if($field->is_list){
$options = array();
$values = explode (';', $field->custom_value);

foreach ($values as $key => $val) {
$options[] = array('value' => $val, 'text' => $val);
}

$currentValue = $field->customfield_value;
return JHtml::_ ('select.genericlist', $options, 'field[' . $row . '][customfield_value]', NULL, 'value', 'text', $currentValue) . '</td><td>' . $priceInput;
} else{
return '<input type="text" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" /></td><td>' . $priceInput;
break;
}

break;


In last version not exist Integer, only boolean (B) and string (S), both as string type :)


/* string or integer */
case 'B':
case 'S':

if($field->is_list){
$options = array();
$values = explode (';', $field->custom_value);

foreach ($values as $key => $val) {
$options[] = array('value' => $val, 'text' => $val);
}

$currentValue = $field->customfield_value;
$translate = (vmLanguage::$langCount>1)? true:false;
return $priceInput . '</td><td>'.JHtml::_ ('select.genericlist', $options, 'field[' . $row . '][customfield_value]', NULL, 'value', 'text', $currentValue, false, $translate).$serials ;
} else{
if(vmText::_($field->customfield_value)!=$field->customfield_value) {
$serials = '<span  style="max-width: 100px">'. vmText::_($field->customfield_value).'</span>'.$serials;
}
return $priceInput . '</td><td><input type="text" value="' . $field->customfield_value . '" name="field[' . $row . '][customfield_value]" />'.$serials;
break;
}

break;


I think you have to hack core VM and create right type for Integer or retype your boolean type from string to right Integer customfield :)
But Im not developper, i'ts only logic....

administrator/components/com_virtuemart/models/customfields.php
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

Milbo

Quote from: hazael on March 10, 2023, 01:33:17 AM
I was looking for an add-on that would multiply the price in the basket depending on the option selected. It's probably the only add-on that has this capability, but it's acting weird  :D

That is native part of the core! But why do you not use strings type S for that? Check the customfield prototype edit view, not the one in the product edit. The product edit does not show all options (intended!).

imho we removed the boolean and integer, because they are in fact just S fields. they were created generically in vm1.8 times or so. What is the problem with that pinochico ?
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

pinochico

@Max:

Why return Boolean type checkbox with values Yes/No or 1/0 back to the administration:
- because customers will fill "Yes, YEs, YES&nbsp;, Ano, 1, ..." if Customfield of type Boolean (B) remains as String (S)
- because there are many 3d party applications linked to this customfield that judge whether the value of the customfield is 0/1, Yes/No, True/False and cannot eliminate admin errors
- because it is easier for administrators to select a checkbox than to fill in a value (see attachment different between my hacked Boolean and VM core Boolean)

If it won't be in core again, it doesn't matter, for me it's always just adding 2 lines to the core customfield model and my clients will be fine.

The same situation I think will be with Integer (I) == Number for Math calc process ?

We can discus on the chat
www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

hazael

#6
Quote from: Milbo on March 11, 2023, 12:50:40 PM
That is native part of the core! But why do you not use strings type S for that?

OK Milbo, but how do I remove "1%" from an <option>? Where to look for it? 2 zeros are missing.
If I enter 100 then I see 1% in the option. If I enter 200 then I see 2% - this is a bug.
Should be: 100 -> 100%; 200 -> 200%


<select>
<option value="0">Select</option>
<option value="23046">2 pc 1% +3690 zł</option>
<option value="23047">3 pc 2% +7380 zł</option>
<option value="23048">4 pc 3% +11070 zł</option>
<option value="23049">5 pc 4% +14760 zł</option>
</select>

in the template file customfields.php I temporarily removed these strange percentages
$customfields[$selectList[$customfield->virtuemart_custom_id]]->display = preg_replace('/[1-9]\%/','', $customfields[$selectList[$customfield->virtuemart_custom_id]]->display); or
$customfields[$selectList[$customfield->virtuemart_custom_id]]->display = preg_replace('/([1-9]\%)|(\+[0-9]+\ zł)/','', $customfields[$selectList[$customfield->virtuemart_custom_id]]->display);