var $searchcustoms is retrieved as an Integer on line 189 of administrator/components/com_virtuemart/models/product.php but is treated as an array from Line 313 onward.
In order for this to work properly line 189 needs to change
from $this->searchcustoms = vRequest::getInt ('customfields');
To $this->searchcustoms = vRequest::getVar ('customfields');
product.php( Line 102 ): var $searchcustoms = FALSE;
product.php( Line 123 ): $this->searchcustoms = FALSE;
product.php( Line 189 ): $this->searchcustoms = vRequest::getInt ('customfields');
product.php( Line 313 ): if (!empty($this->searchcustoms)) {
product.php( Line 315 ): foreach ($this->searchcustoms as $key => $searchcustom) {
product.php( Line 315 ): foreach ($this->searchcustoms as $key => $searchcustom) {
product.php( Line 316 ): $custom_search[] = '(pf.`virtuemart_custom_id`="' . (int)$key . '" and pf.`customfield_value` like "%' . $db->escape ($searchcustom, TRUE) . '%")';
product.php( Line 612 ): if ($this->searchcustoms) {
hmmm
vRequest automatically recognises an array. To change between Var or Int makes no difference, except that we do not use the Int filter, which can be unsecure. So I think the best is to add a fallback, when it is not an array.
if (!empty($this->searchcustoms)) {
if(!is_array($this->searcustoms)) $this->searcustoms = array($this->searcustoms);
I think it is even better to use
$this->searchcustoms = vRequest::getInt ('customfields', false, true);
This should force the return as array, except it is false, which is already handled by the code.
The code does seem to imply there should be no difference between using getInt() and getVar() so I agree with you there.
But what I KNOW is that it will not work with getInt() and it does work fine if I change it to getVar().
Perhaps it is my string causing the issue - this is it:
<?php foreach ($index_output as $brand) {
$link = JROUTE::_('index.php?option=com_virtuemart&view=category&customfields[' . intval($params->get( 'index_field' )) . ']=' . $brand .
'&virtuemart_category_id=0&virtuemart_manufacturer_id=1&categorylayout=PCI&showcategory=0&showproducts=1&productsublayout=products_pci&Itemid=' . $params->get( 'target_item' ));
?>
<a href="<?php echo $link; ?>" class="customfield_menu_link"><?php echo $brand; ?></a>
<?php
}
?>
So, I tested the two alternative options given; neither one works. Here is what my product.php file looks like starting at line 189:
// ORIGINAL STRING; DOES NOT WORK -RETURNS ALL PRODUCTS AS A RESULT
//==============================================================================================
//$this->searchcustoms = vRequest::getInt ('customfields');
// CHANGED TO getVar(); WORKS -RETURNS ONLY THE FILTERED PRODUCTS
//==============================================================================================
$this->searchcustoms = vRequest::getVar ('customfields');
// TEST OPTION ONE; DOES NOT WORK -RETURNS A BLANK PAGE
//==============================================================================================
//$this->searchcustoms = vRequest::getInt ('customfields', false, true);
// TEST OPTION TWO; ALSO DOES NOT WORK -RETURNS A BLANK PAGE. I TRIED IT AS STANDALONE AND ALSO
// ALONG WITH EACH OF THE THREE LINES ABOVE
//==============================================================================================
//if (!empty($this->searchcustoms)) {
//if(!is_array($this->searchcustoms)) $this->searchcustoms = array($this->searchcustoms);
Please enable the error reporting, so that you see the error, not just a blank page (in joomla or vm config, both works),
then please use in line 189
if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
and enable the vmdebug, please post the result here for getInt and getVar, thank you.
I included some screenshots of the actual results pages -
This block (getVar):
// ORIGINAL STRING; DOES NOT WORK -RETURNS ALL PRODUCTS AS A RESULT
//==============================================================================================
//$this->searchcustoms = vRequest::getInt ('customfields');
//if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
// CHANGED TO getVar(); WORKS -RETURNS ONLY THE FILTERED PRODUCTS
//==============================================================================================
$this->searchcustoms = vRequest::getVar ('customfields');
if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
Produces this output: http://awesomescreenshot.com/0165bbx5e5 (http://awesomescreenshot.com/0165bbx5e5)
Message
vmdebug $siteLang: en-GB self::$vmlangSef: self::$_jpConfig->lang en_gb DefLang en_gb
vmdebug vmTime: time to load config: 0.0155999660491943
vmdebug Start used Ram 10.5M
vmdebug my $this->searchcustoms Var1:
Array
(
[3] => ALPS
)
vmdebug getVendorId normal shopper
vmdebug vmTime: sortSearchQuery products: 0.0155999660491943
vmdebug Created new cart
vmdebug Going to set core fields unrequired
vmdebug Created new Calculator Instance
vmdebug vmTime: vm view Finished task : 0.29640007019043
vmdebug End used Ram 20.75M
vmdebug Peak memory peak 20.75M
This block (getInt):
// ORIGINAL STRING; DOES NOT WORK -RETURNS ALL PRODUCTS AS A RESULT
//==============================================================================================
$this->searchcustoms = vRequest::getInt ('customfields');
if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
// CHANGED TO getVar(); WORKS -RETURNS ONLY THE FILTERED PRODUCTS
//==============================================================================================
//$this->searchcustoms = vRequest::getVar ('customfields');
//if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
Produces this output: http://awesomescreenshot.com/0515bbxo27 (http://awesomescreenshot.com/0515bbxo27)
Message
vmdebug $siteLang: en-GB self::$vmlangSef: self::$_jpConfig->lang en_gb DefLang en_gb
vmdebug vmTime: time to load config: 0.0156002044677734
vmdebug Start used Ram 10.5M
vmdebug my $this->searchcustoms Var1:
Array
(
[3] =>
)
vmdebug getVendorId normal shopper
vmdebug vmTime: sortSearchQuery products: 0
vmdebug Created new cart
vmdebug Going to set core fields unrequired
vmdebug Created new Calculator Instance
vmdebug vmTime: vm view Finished task : 0.499200820922852
vmdebug End used Ram 22M
vmdebug Peak memory peak 22M
Interesting side note: I manually edited the URL string, changed the search value "ALPS" to the integer value "3" and refreshed. getInt() gave me a different debug result. Is it possible the integer filtering function inside getInt() is causing the problem?
This block (getInt):
// ORIGINAL STRING; DOES NOT WORK -RETURNS ALL PRODUCTS AS A RESULT
//==============================================================================================
$this->searchcustoms = vRequest::getInt ('customfields');
if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
// CHANGED TO getVar(); WORKS -RETURNS ONLY THE FILTERED PRODUCTS
//==============================================================================================
//$this->searchcustoms = vRequest::getVar ('customfields');
//if($this->searchcustoms)vmdebug('my $this->searchcustoms ',$this->searchcustoms);
Produces this output: ( I had to use a manual screenshot to capture the URL string; see attached )
Message
vmdebug $siteLang: en-GB self::$vmlangSef: self::$_jpConfig->lang en_gb DefLang en_gb
vmdebug vmTime: time to load config: 0.0170009136199951
vmdebug Start used Ram 10.5M
vmdebug my $this->searchcustoms Var1:
Array
(
[3] => 3
)
vmdebug getVendorId normal shopper
vmdebug vmTime: sortSearchQuery products: 0.00600099563598633
vmdebug Created new cart
vmdebug vmTime: vm view Finished task : 0.146008014678955
vmdebug End used Ram 17.75M
vmdebug Peak memory peak 17.75M
Thank you, so we get Strings in the array, not ints
So I think it is
$this->searchcustoms = vRequest::getVar('customfields', false, true);