advancedfeaturesvalues icon indicating copy to clipboard operation
advancedfeaturesvalues copied to clipboard

Hierarchical Product Features

Open mjawaids opened this issue 9 years ago • 37 comments

Can you modify the module to provide parent-child relationship between 2 or more features. Selecting any value in parent feature should filter out the values in child feature. Similarly, if there is any grand child under child feature selecting value of child should filter values in grand child. This will also require the define the parent-child relationship when adding product features in admin.

mjawaids avatar May 09 '15 15:05 mjawaids

That would be hard to do. I don't think I'm able to do that. Anyone interested in that can fork this project. Sorry.

jdanthinne avatar May 11 '15 07:05 jdanthinne

OK. Could you provide some documentation or a short summary of your code? I can try extending it. Thanks.

mjawaids avatar May 11 '15 15:05 mjawaids

The short summary is that the code overrides the default Feature controllers so that it allows multiple rows in the association DB table between products and features instead of just one, and also adds a new column in the features values table so it can handle ordering. If you need specific explanations of the code, just ask, but it is self-explanatory.

jdanthinne avatar May 11 '15 18:05 jdanthinne

I would really appreciate if you could guide me meanwhile I extend it. First of all as you added a new field for ordering we would need another field for parent feature. Adding a field in db is not a problem but where do you think I should handle this parent field to show the relationship.

On Mon, May 11, 2015 at 11:21 PM Jérôme Danthinne [email protected] wrote:

The short summary is that the code overrides the default Feature controllers so that it allows multiple rows in the association DB table between products and features instead of just one, and also adds a new column in the features values table so it can handle ordering. If you need specific explanations of the code, just ask, but it is self-explanatory.

— Reply to this email directly or view it on GitHub https://github.com/jdanthinne/advancedfeaturesvalues/issues/4#issuecomment-101005758 .

mjawaids avatar May 11 '15 18:05 mjawaids

What do you mean by "showing the relationship"? Visually?

jdanthinne avatar May 12 '15 11:05 jdanthinne

When defining product features we need to tell the parent value for child value. For example: I add a product parent feature say 'Series' that has values HP Probook and Dell Latitude, and I add product child feature say 'Model' that has values 4540s and D800. Here I should be able to tell that 4540s belongs the HP Probook in parent feature and D800 belongs to Dell Latitude series.

On Tue, May 12, 2015 at 4:19 PM Jérôme Danthinne [email protected] wrote:

What do you mean by "showing the relationship"? Visually?

— Reply to this email directly or view it on GitHub https://github.com/jdanthinne/advancedfeaturesvalues/issues/4#issuecomment-101241649 .

mjawaids avatar May 12 '15 13:05 mjawaids

What you're talking about looks more like categories than features to me… don't you think?

jdanthinne avatar May 12 '15 15:05 jdanthinne

No I just gave an example. Actually the product can be compatible with multiple models and there can be hundreds of models while category is something like laptop, desktop etc.

Sent from my Phone. On May 12, 2015 8:01 PM, "Jérôme Danthinne" [email protected] wrote:

What you're talking about looks more like categories than features to me… don't you think?

— Reply to this email directly or view it on GitHub https://github.com/jdanthinne/advancedfeaturesvalues/issues/4#issuecomment-101310294 .

mjawaids avatar May 12 '15 15:05 mjawaids

I have couple questions for you.

  1. What is blocklayered.js in your code and why have you used it?
  2. In file advancedfeaturesvalues.php:114 under function hookHeader() what this code snippet does: if (Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY'))) == Configuration::get('PS_HOME_CATEGORY')) return;

mjawaids avatar May 16 '15 12:05 mjawaids

If I add new field parent_id_feature_value in feature_value table and want to reflect changes in back and front office what files do you think will change?

mjawaids avatar May 16 '15 12:05 mjawaids

  1. blocklayered.js is an override of the original blocklayered module script, so it use advancedfeaturesvalues module when selecting a filter and making the Ajax request, instead of the default one
  2. It is also an override just to load our custom javascript file (mentioned above). The condition is there to abort the function if we're browsing the homepage (because the script isn't needed there).
  3. I think you have to change almost all the files, because this kind of relationship influences everything…

jdanthinne avatar May 18 '15 07:05 jdanthinne

Thanks. Actually I'm new to Prestashop development and Prestashop docs are pretty basic while what I need is kind of advanced thing. I can do the architectural thing but if you could help me in developing this functionality I'll be very grateful to you. I think its a small change and just have to add one field in database table and some logic in module. Please let me know we can both together can do this. Thanks in advance.

mjawaids avatar May 18 '15 09:05 mjawaids

Actually I'm new to Prestashop as well, and this module is the first one I've built. And I've done it for a client, so I've been paid for the time spent on this particular function. I'm sorry but I don't have the free time do that for you. If what you were asking was easy, I could, but believe me, it is not (for new PS developers). I think you should ask for help in the Prestashop forums, I've found many advices there.

jdanthinne avatar May 18 '15 09:05 jdanthinne

Sorry to bother you again. There is an issue with your module. I'm not sure if its your module or is it Prestashop. When I install your module and then uninstall and delete it, it leaves FeatureValue.php file behind under override/classes folder with following content that is causing syntax errors. All other overridden files are successfully deleted except this one. Do you have any idea why this file is not being deleted?

'feature_value', 'primary' => 'id_feature_value', 'multilang' => true, 'fields' => array( 'id_feature' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), 'position' => array('type' => self::TYPE_INT, 'validate' => 'isInt'), 'custom' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'value' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), ), ); ``` }

mjawaids avatar May 24 '15 08:05 mjawaids

Unfortunately, I don't think the issue is related to the module, but to Prestashop itself, and its uninstall function. No module installs itself, PS manages that, but it seems that sometimes, the process fails… (i.e. http://forge.prestashop.com/browse/PSCSX-4910)

jdanthinne avatar May 24 '15 18:05 jdanthinne

OK thanks. I have another question. Where does the method getFrontFeaturesStatic() in /override/classes/Product.php gets called from and what it does?

mjawaids avatar May 24 '15 21:05 mjawaids

This function is called when a page need to display all the feature values, given a feature id and a language. I had to override this function so I can order alphabetical instead of by ID.

jdanthinne avatar May 25 '15 06:05 jdanthinne

Do you have any idea how to override Feature Add/Edit form so I can display my custom field as well. I am able to do the same thing for Feature Value but cannot find place to do for Feature.

mjawaids avatar May 27 '15 02:05 mjawaids

You have to override the renderForm() function in /controllers/admin/AdminFeaturesController.php, I think.

jdanthinne avatar May 27 '15 06:05 jdanthinne

Ya I did that but its not working. Any clues?

mjawaids avatar May 27 '15 11:05 mjawaids

What is not working exactly? Where can I see the code/fork?

jdanthinne avatar May 27 '15 12:05 jdanthinne

Attached is the code.

Muhammad Jawaid Shamshad

On Wed, May 27, 2015 at 5:21 PM, Jérôme Danthinne [email protected] wrote:

What is not working exactly? Where can I see the code/fork?

— Reply to this email directly or view it on GitHub https://github.com/jdanthinne/advancedfeaturesvalues/issues/4#issuecomment-105887940 .

mjawaids avatar May 27 '15 14:05 mjawaids

I think attachment didn't went through. Let me know your email I'll send it to you.

mjawaids avatar May 27 '15 14:05 mjawaids

I prefer not to handle that by emails. Just give me the link your repository on GitHub, and tell me what is not working from there, it will be much easier.

jdanthinne avatar May 27 '15 15:05 jdanthinne

OK I fixed it. Actually had to call AdminController::renderForm() instead of parent::renderForm() in my override. But now there is new problem. My custom field for Feature is not saving in the database. Custom field for FeatureValue is working fine and saving in the database but not for Feature. What should I do so it also saves in the database.

mjawaids avatar May 27 '15 15:05 mjawaids

As I told you, I can hardly help you if you don't give me the link to your repository.

jdanthinne avatar May 27 '15 18:05 jdanthinne

Here you go https://github.com/mjawaids/advancedfeaturesvalues

mjawaids avatar May 27 '15 19:05 mjawaids

OK, it saves parent feature value when adding a new feature. But if I edit a feature it doesn't update.

mjawaids avatar May 27 '15 20:05 mjawaids

Does it output an error message (with debug mode enabled) ? But I'm kind of lost in what you're trying to achieve… Are you building parent-child relationship between features and child features AND between features values and features child values?? Wouldn't be easier to just do that for features values?

jdanthinne avatar May 28 '15 14:05 jdanthinne

No it doesn't show any error. Yes that's what I'm trying to achieve. Basically relationship between feature and child feature is necessary in order for feature values to know who their parent are and show only parent values in drop drown instead of populating all the values from all the features.

Current problem is that parent feature is saving when adding new feature. But when I edit it, the parent feature doesn't get updated.

Do you get my point? If this is fixed then we are almost done with some minor tweaks. On May 28, 2015 7:38 PM, "Jérôme Danthinne" [email protected] wrote:

Does it output an error message (with debug mode enabled) ? But I'm kind of lost in what you're trying to achieve… Are you building parent-child relationship between features and child features AND between features values and features child values?? Wouldn't be easier to just do that for features values?

— Reply to this email directly or view it on GitHub https://github.com/jdanthinne/advancedfeaturesvalues/issues/4#issuecomment-106363264 .

mjawaids avatar May 28 '15 14:05 mjawaids

Does Prestashop say "Feature updated" or nothing? No fields are updated or only your new field?

jdanthinne avatar May 29 '15 15:05 jdanthinne

Yes it says feature updated and it does update the data but not my custom field. On May 29, 2015 8:14 PM, "Jérôme Danthinne" [email protected] wrote:

Does Prestashop say "Feature updated" or nothing? No fields are updated or only your new field?

— Reply to this email directly or view it on GitHub https://github.com/jdanthinne/advancedfeaturesvalues/issues/4#issuecomment-106842478 .

mjawaids avatar May 29 '15 19:05 mjawaids

Any clue?

mjawaids avatar May 30 '15 14:05 mjawaids

I've just had a look, and no, I don't understand directly why this isn't working. Perhaps you should have a look into the Category class/controllers, because it's already handling parent-children relationship in this one.

jdanthinne avatar Jun 01 '15 14:06 jdanthinne

Yep, have a look at https://github.com/PrestaShop/PrestaShop/blob/1.6/controllers/admin/AdminCategoriesController.php#L477, they're using a tree index (but not documented).

jdanthinne avatar Jun 01 '15 14:06 jdanthinne

My hierarchy problem is solved by adding a parent field for each feature and feature value since one feature/value can have only one parent. Current problem is when editing a feature it does not update the parent field that I have added while it does update other fields. Also, if I add a new feature it saves all the fields including the parent successfully. I'm not sure why it doesn't update when editing it.

mjawaids avatar Jun 01 '15 18:06 mjawaids

The tree they are using is I think for displaying it as tree structure.

mjawaids avatar Jun 01 '15 18:06 mjawaids