VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: henry_osn on June 02, 2020, 00:40:57 AM

Title: [SOLVED] Read Category Parameters
Post by: henry_osn on June 02, 2020, 00:40:57 AM
Hi, how I read the parameter "cat_params->showsearch" in following array:

QuoteArray (
   [virtuemart_category_id] => 81
   [category_parent_id] => 78
   [virtuemart_vendor_id] => 1
   [category_name] => Cozinhas e Churrasqueiras
   [slug] => cozinhas-e-churrasqueiras-1
   [cat_params] => show_store_desc=""|showcategory_desc=""|showcategory=""|categories_per_row=""|showproducts=""|omitLoaded=""|showsearch="0"|productsublayout=""|featured=""|featured_rows=""|omitLoaded_featured=""|discontinued=""|discontinued_rows=""|omitLoaded_discontinued=""|latest=""|latest_rows=""|omitLoaded_latest=""|topten=""|topten_rows=""|omitLoaded_topten=""|recent=""|recent_rows=""|omitLoaded_recent=""|
   [limit_list_step] => 0
   [limit_list_initial] => 0
)

I need "showsearch" value for show or not a classe in my template.

For example, the way "$this->product->category_name" work, but "$this->product->cat_params" do not.

Thanks
Title: Re: Read Category Parameters
Post by: Jörgen on June 02, 2020, 06:46:18 AM
The parameters are json decoded
https://www.php.net/manual/en/function.json-decode.php (https://www.php.net/manual/en/function.json-decode.php)

Jörgen @ Kreativ Fotografi
Title: Re: Read Category Parameters
Post by: henry_osn on June 02, 2020, 18:50:28 PM
Can you give me an example in this case?
Thanks again.
Title: Re: Read Category Parameters
Post by: GJC Web Design on June 02, 2020, 22:49:45 PM
$cat_params = json_decode($this->product->cat_params);
Title: Re: Read Category Parameters
Post by: henry_osn on June 03, 2020, 01:10:40 AM
Thanks for reply.

Quote from: GJC Web Design on June 02, 2020, 22:49:45 PM
$cat_params = json_decode($this->product->cat_params);

The return this is EMPTY. I tried json_decode($this->product->categoryItem[0]['cat_params']); but not worked.

With
Quoteprint_r($this->product->categoryItem[0]['cat_params']);

Show:

Quoteshow_store_desc=""|showcategory_desc=""|showcategory=""|categories_per_row=""|showproducts=""|omitLoaded=""|showsearch="0"|productsublayout=""|featured=""|
featured_rows=""|omitLoaded_featured=""|discontinued=""|discontinued_rows=""|omitLoaded_discontinued=""|latest=""|latest_rows=""|omitLoaded_latest=""|
topten=""|topten_rows=""|omitLoaded_topten=""|recent=""|recent_rows=""|omitLoaded_recent=""|

Thanks again
Title: Re: Read Category Parameters
Post by: GJC Web Design on June 03, 2020, 09:08:33 AM
its not JSON

try explode("|", $this->product->categoryItem[0]['cat_params'])
Title: Re: Read Category Parameters
Post by: Jörgen on June 03, 2020, 09:42:44 AM
Sorry, did not look close enough, John is right, exploding the data is the way to go.

Jörgen
Title: Re: Read Category Parameters
Post by: Studio 42 on June 03, 2020, 13:04:34 PM
The system is a little tricky.
It's not json, but if the parameter is not a string, then it's json encoded.
All this because the team do not wanted json in year 2012
Title: Re: Read Category Parameters
Post by: PRO on June 03, 2020, 20:46:32 PM
Just leave it a string

$showsearch=0;
if (strpos($this->product->categoryItem[0]['cat_params'], 'showsearch="1"') !== false) {
    echo 'hello';
$showsearch=1;
}
Title: Re: Read Category Parameters
Post by: henry_osn on June 03, 2020, 21:53:59 PM
Quote from: GJC Web Design on June 03, 2020, 09:08:33 AM
its not JSON

try explode("|", $this->product->categoryItem[0]['cat_params'])

Yes, that's what I imagined. I was looking for a direct way to access the parameter, but it will have to be the traditional way, transforming it into an array. Thanks.
Title: Re: Read Category Parameters
Post by: henry_osn on June 03, 2020, 21:59:28 PM
Quote from: PRO on June 03, 2020, 20:46:32 PM
Just leave it a string

$showsearch=0;
if (strpos($this->product->categoryItem[0]['cat_params'], 'showsearch="1"') !== false) {
    echo 'hello';
$showsearch=1;
}

Also works.
Thanks.