Page 1 of 2
Products - summary by custom field?
Posted: Tue Aug 11, 2009 9:01 pm
by jezatron
Hi sorry if this has already been answered / detailed somewhere but I have searched and searched and also looked in the module help but can't see it.
In the same way that one can call a summary of products that share a specific category... i.e.
{Products detailpage="yourDetailPage" detailtemplate="yourTemplate" category="selectedCategory"}
how would you call a summary of products with a specific value for a custom field?
obviously you need to detail the fact that you are sorting based on a custom field, the fieldname and the field value but I have no idea what the protocol / syntax for doing so would be?
Thanks
Jamie
Re: Products - summary by custom field?
Posted: Tue Aug 11, 2009 10:58 pm
by jezatron
sorry guys
im sure this will be a fairly generic solution but in case you were put off by lack of set up info i just realised forgot to detail it....
i am running cmsms carolina 1.5.4
products 2.3.1
Re: Products - summary by custom field?
Posted: Thu Oct 15, 2009 11:34 am
by manc
did you ever find a solution to this? i am also trying to find out how to search by field definition
Re: Products - summary by custom field?
Posted: Mon Oct 19, 2009 1:11 pm
by manc
i'm messing around at the moment with some SQL, however, not sure how to get the entered search parameters into the UDT ($searchterm). anyone know how to do this?
here's some code I made:
global $gCms;
$smarty = &$gCms->GetSmarty();
$db = &$gCms->db;
function make_alias($string, $isForm=false)
{
$string = trim($string);
$string = preg_replace("/[_-\W]+/", "-", $string);
$string = trim($string, '_');
return strtolower($string);
}
$prop = 'SELECT * FROM cms_module_products WHERE status="Published"';
$propresult= $db->Execute($prop);
$fields = 'SELECT * FROM cms_module_products_fieldvals WHERE value=$searchterm';
$fieldresult= $db->Execute($fields);
while ($row= $propresult->FetchRow())
{
while ($fieldprop= $fieldresult->FetchRow())
{
echo $fieldprop['value'];
}
}
this just outputs the matched field and will obviously will make more of a template (once i've sorted the rest out).
Re: Products - summary by custom field?
Posted: Mon Oct 19, 2009 3:09 pm
by tyman00
To the best of my knowledge there is no way without building a UDT of sorting by custom fields. I know it has been discussed but it is currently not built into the module.
Re: Products - summary by custom field?
Posted: Mon Oct 19, 2009 3:29 pm
by manc
this is my UDT. do you know how to get parameters from the search entry into the UDT?
Re: Products - summary by custom field?
Posted: Mon Oct 19, 2009 3:32 pm
by tyman00
I'm far from a programmer

So I cannot be of any service. I wish you luck though, I personally wouldn't mind seeing this ability in Products as well.
Re: Products - summary by custom field?
Posted: Mon Oct 19, 2009 3:49 pm
by calguy1000
There's no functionality for this in the Products module.... and if you wanted to do it, it would have to be a sponsored modification. I just don't have time to do it gratis.
Re: Products - summary by custom field?
Posted: Mon Oct 19, 2009 3:51 pm
by manc
ok. if i get something completed i'll post it here...
Re: Products - summary by custom field?
Posted: Tue Oct 20, 2009 3:12 pm
by manc
i'm progessing here. just need a little help. does anyone know how to only call one product, by product id, as a summary template. i tried doing the following to call one id from the detail page, but use a detail template called result which is just a copied version of my default summary template:
{Products action='details' detailtemplate='result' productid='PRODUCT_ID'}
obviously the following does nothing:
{Products productid='PRODUCT_ID'}
any ideas?
Re: Products - summary by custom field?
Posted: Tue Oct 20, 2009 5:48 pm
by tyman00
Try installing the CGSimpleSmarty module and looking at the module_action_link tag. Something like:
{module_action_link module='Products' action='details' productid=$entry->id text=$entry->product_name}
Re: Products - summary by custom field?
Posted: Tue Oct 20, 2009 6:12 pm
by manc
this works, however, i don't want a simple link. i want to be able to output the summary template (or an edited detail template) with information from the module data. i can call them all fine, just not one in particular. this is essential to make the rest of the SQL work.
your suggestion also doesn't make way for the SEO-friendly URLs given in a normal instance
Re: Products - summary by custom field?
Posted: Tue Oct 20, 2009 7:26 pm
by tyman00
I am not sure what you are asking for then. Your descriptions are fairly convoluted.
The {module_action_link} tag does indeed work, but you are right it doesn't do pretty urls. Though it won't hurt your SEO rank it just likely won't improve it.
Re: Products - summary by custom field?
Posted: Fri Oct 30, 2009 3:00 pm
by manc
after much faffing, i've come up with some SQL, however, need a little help that i'm sure one of you will know how to solve.
here's my PHP/SQL as a UDT:
global $gCms;
$smarty = &$gCms->GetSmarty();
$db = &$gCms->db;
function make_alias($string, $isForm=false)
{
$string = trim($string);
$string = preg_replace("/[_-\W]+/", "-", $string);
$string = trim($string, '_');
return strtolower($string);
}
$post=$params['pc'];
$bedrooms=$params['rooms'];
$price=$params['rent'];
$query ="SELECT DISTINCT product_id FROM cms_module_products, cms_module_products_fieldvals WHERE (cms_module_products_fieldvals.fielddef_id=21 AND cms_module_products_fieldvals.value != 'true') ";
if ($post!= '[unspecified]') {
$query .="AND (cms_module_products_fieldvals.fielddef_id IN (8,9) AND cms_module_products_fieldvals.value LIKE '%$post%') ";
}
if ($bedrooms!= '[unspecified]') {
$query .="AND (cms_module_products_fieldvals.fielddef_id IN (12) AND cms_module_products_fieldvals.value >= '$bedrooms') ";
}
if ($price!= '[unspecified]') {
$query .="AND cms_module_products.price >= '$price'";
}
$counting = mysql_query($query);
$count = mysql_num_rows($counting);
echo "We have found ".$count." properties that match your search!
";
echo "
".$query."
";
$fieldresult= $db->Execute($query);
while ($fieldprop= $fieldresult->FetchRow())
{
$smarty_data = "{Products action='details' detailtemplate='result' productid='".$fieldprop['product_id']."'}";
$smarty->_compile_source('temporary template', $smarty_data, $_compiled );
@ob_start();
$smarty->_eval('?>' . $_compiled);
$_contents = @ob_get_contents();
@ob_end_clean();
echo $_contents;
}
the bold is where my issue is. i am having trouble combining the first statement with the other 3. the 3 bold statements are based on search inputs by the user. i know each query within each bracket by itself works fine, but combining them bring out 0 results (even when i know the search query should output something)
Re: Products - summary by custom field?
Posted: Wed Nov 04, 2009 9:50 am
by manc
suggestions here anyone?