How to implement a sizes field

7 years 7 months ago - 7 years 7 months ago #3887 by bram
Replied by bram on topic How to implement a sizes field
You are on the same track to the solution as i'm using it on my fashion sites. I will try to depict it step by step:


For me ( and probably for you in the future as well ) it's important to have the sizes delimited by a ',' on both sides

size like '%,1' would match ',1' but also ',10'

the following code example shows a solution, it also shows a solution for '|' delimited sizes.

this goes into your feeds.php import filters.
function sizes_cb(&$item) { generic_cb($item); sizes($item); } function sizes_pipe_cb(&$item) { generic_cb($item); $item['menu_12']=explode('|',$item['menu_12']); sizes($item); } function sizes(&$item) { if ( ! is_array($item['menu_12']) ) { $m12=explode(',',$item['menu_12']); } else { $m12=$item['menu_12']; } asort($m12); #todo trim() each element and ommit empty ones $item['menu_12']=','.join(',',$m12).','; }


if you put your version of the db_select function into components/com_datafeeds/helpers/xhelpers.php i will be preserved whenever you update the component.
if ( $f == 'Select12' ) { if ($not === false ) { return '`Select12` like ' . $db->Quote("%,$t,%"); } else { return '`Select12` != \'\''; } } else { #existing code }

the return for the 'not' situation might seem odd, your solution will not work. And Select12 not like '%,$t,%' would neither. Consider a $t='8' and a sizes string like 6,7,8,9. Result sizes 6,7,9 are not shown.


quite right about the sorting and uniques and other issue with large arrays. What I do is loop thru the sizes, explode each, create a new array with those. below a diff for the existing default.php
--- default.php (revision 2123) +++ default.php (working copy) @@ -25,6 +25,25 @@ $baselink .="&q$v=".urlencode($x); } } + $sizelevel='2'; + if ( $dataitems['level'.$sizelevel]) { + foreach ($dataitems['level'.$sizelevel] as $v ) { + foreach (explode(',',$v) as $w ) { + @$new[trim($w)]++; # should be done during import + } + } + unset ( $dataitems['level'.$sizelevel] ) ; + unset ($new[strtolower(${'q'.$sizelevel})]); # THIS IS THE MISSING NOT FROM THE QUERY + unset ($new['']); #fail save, + ksort($new); + # if you don't care about the uppper is array_keys, + # or if you like fancy functions use array walk after array_keys + foreach ( $new as $k => $v ) { + $k=strtoupper($k); + $dataitems['level'.$sizelevel][]=$k; + } + } + print '<div id="'.$mod_div.'" class="menu'.$params->get('moduleclass_sfx').'">'; $verwijder=$params->get('removestring',"Verwijder"); for ($v=$start;$v<=$stop;$v++) {

I did quite some benchmarking in the past, using function like array_walk to do the strtouper didn't make much of a difference.
Last edit: 7 years 7 months ago by bram.
The following user(s) said Thank You: sakattack

Please Log in or Create an account to join the conversation.

7 years 7 months ago #3889 by sakattack
wow, nice!!! Thank you so much, you gave me a lot to think about. I will post my finished code once I'm done with this project.

take care

Please Log in or Create an account to join the conversation.

Time to create page: 0.172 seconds