Skip to main content

How to implement a sizes field

More
8 years 8 months ago - 8 years 8 months ago #3880 by sakattack
Hello

I'm using this component for a shoes website and I'd like to have a field for the shoe sizes. Each shoe can ofcourse come in many sizes, so in the database it would be like 35,36,37,38,39 for the sizes Select field of a specific shoe. How can I then have a module to select all the shoes that come in one specific size?

The module would list only the individual sizes and selecting one would show all the shoes that have the selected size, regardless if they have other sizes as well.

Can it be done?

Thank you
Last edit: 8 years 8 months ago by sakattack.

Please Log in to join the conversation.

More
8 years 8 months ago #3882 by redactie
To start with the bad news: the component is not very good at handling variations of items. Many because the component uses normalized data and mysql is not very good at handling arrays.

I will briefly depict some options:

easiest method is te split the sizes and insert an item for each size, this feature is build into the import function so it's fairly easy. Disadvantage is that your database size increases. If you have say five sizes per shoe on average you database explodes 5x.

Another option would be to use the 'set' database type of joomla, however here the problem is that the number of different values is limited to 64 AND the values must be know in advance. 64 seems to fit the shoe sizes ranging from 15 to 55 but there are a lot of variations like US sizes and sizes ike 34EU. This must be converted to known values.

A variation on the previous option is to use the existing string field and add sizes like ,43,44,45,46,

The last two options require a custom query for the field containing the sizes (See example queries below, the feature to use custom queries is build in version 3) AND a extra loop in the module to split the sizes and prepare them for display.

-2- FIND_IN_SET(Selectx,44);
-3- Selectx like '%,44,%'
The following user(s) said Thank You: sakattack

Please Log in to join the conversation.

More
8 years 8 months ago #3883 by sakattack
hmm, last option sounds inbteresting but it is a little bit hard to understand. I'm fairly good at programming and customizing, but i will need you to help me a little bit here to point me in the right direction.

1. For the last option what do you mean use the existing string field? you mean just use a database field as it is now and add the sizes like so 34,35,36 etc ?

2.You say it needs a custom query for the field containing the sizes. Do you mean the custom query of the menu module or the component menu?

3. you say an extra loop is needed in the module to split the sizes and prepare them for display. Can you provide me with an example?

Thank you for your time and your help, you r great!!!

Please Log in to join the conversation.

More
8 years 8 months ago #3884 by sakattack
Ok, I think I get it

I used the SQL Filter of a count_menu module to add Select12 LIKE '%45%'. I mapped the Select12 to my component datafeeds menu and now it correctly chooses the items that have the value 45 in their sizes field (Select12 in the database). I think the next step is to provide the rest of the sizes in the module's sql filter (e.g. Select12 LIKE '%45%' OR Select12 LIKE '%44%' etc ). BUT, how can I make the module show the individual sizes in it's menu? Right now, it just chooses the correct items but displays each unique value as a menu item (e.g. 44,45 and 45)

Please Log in to join the conversation.

More
8 years 8 months ago - 8 years 8 months ago #3885 by sakattack
Do you have any way to help me?

I really need to implement this. Any help will be greatly appreciated. All I need is to make this work for Select12 db field mapped to menu 7 in the component. I need this menu to SELECT LIKE '%size%' instead of SELECT = '' as it is now.

Obviously the menu module will have to be changed to display the correct individual values, but this is not really a problem, the real problem is to make the component show all of the items that contain the selected size in Select12 field.

I'm thinking, for the component, that the compile_query function needs to be changed in the items.php file as well as the make_qQuery function in the helpers.php file?

As for the module, the getList, getWhere, getData, getMenu function in helpers.php need to be changed, along with the module's template file

Please, help me here

By the way I'm only gooing to be having 10 different sizes, not 64
Last edit: 8 years 8 months ago by sakattack.

Please Log in to join the conversation.

More
8 years 8 months ago #3886 by sakattack
So, after a lot of hunting in your code, I managed to make the component show all the items that contain the specific size, regardless if they have other sizes in their db field or not.

The code is in com_datafeeds/helpers/helpers.php, at the very end of th file there is the function df_select which among others has

$t= $db->Quote($s);
if ($not === false ) {
return "`$f` = $t";
} else {
return "`$f` not in ('',$t)";
}

Since I want to apply this functionality to only 1 of my fields (db Select12 mapped to menu 7), I changed the above code part to

if ( $f == 'Select12' ) {
$s = '%'.$s.'%';
$t= $db->Quote($s);
if ($not === false ) {
return "`$f` LIKE $t";
} else {
return "`$f` not in ('',$t)";
}
}
else{
$t= $db->Quote($s);
if ($not === false ) {
return "`$f` = $t";
} else {
return "`$f` not in ('',$t)";
}
}


As for the module, I have made A LOT of customizations and I have it display the individual sizes only, however the module needs a lot more tweaking to be as optimized as possible. My main concern with the module is that I'm applying a series of for statements to get the individual values, remove duplicates, sort them etc and when this fors happen over a few thousand items, php might take a while to compute. At first I used array_unique to remove duplicates but after a bit of reading and testing I realized it's gonna be awfully slow for a few thousands of items each containing 1-10 size values, so I removed the array_unique and added a foreach statement which seems to be 20x faster. Anyway, as I said the module needs some more work.

So

1. What do you think of my changes to the helpers.php file of the component? ANY input from you is welcome

2. If you have any code snippet that could perhaps help me with the module, any ideas, anything at all, I'm really looking forward to hearing it.

Bottom line is I'd feel a lot more comfortable to have the opinion of the component's maker when I'm making such fundamental changes to his code, your code.

Please tell me what you think

Please Log in to join the conversation.

Time to create page: 0.408 seconds