Jump to content

Attribute AJAX search for one character attribute name


alexm
 Share

Recommended Posts

Hi again @kongondo,

I've also got a little issue whereby attributes for sizes are as few as 1 or 2 characters for the sizes - e.g. S, M, L, XL, 2XL, 3XL

The ajax search only kicks in when the query string length is longer than 3 characters.
I've tried enabling "Use ajax/options pages" then adding the hook to init.php like so: 

$wire->addHook("/find-padloper_product_attributes_options/", function($e) { 
  $q = $e->input->get("q", "text,selectorValue");
  if(strlen($q) < 1) return [];
  $selector = "templates_id=62, include=hidden, title%=$q";
  $fields = [ "id" => "value", "title" => "label" ]; 
  return array_values($e->pages->findRaw($selector, $fields));
});

but unfortunately it doesn't retrieve the pages with 1 or 2 character titles. Is there anything I can do about this? I'm trying to tie the attribute option titles in directly with the way the supplier lists them.

Any thoughts on this?

Appreciate your time, thank you in advance ?

 

 

Link to comment
Share on other sites

Sorted! I've updated the hook hookFindPadloperProductAttributesOptions in PadloperHooks.module. Obviously not ideal that I have updated it there, as it will get overwritten, but I can see in your notes that using site/init.php doesn't work.

Link to comment
Share on other sites

Hmm. I'll have to have a think about this. I might make this configurable. Ideally, although I see when it might come handy as per your use case, a 1-character limit should be avoided - to limit server hits, primarily. 

Link to comment
Share on other sites

Agreed, I did think that this might be rather resource hungry. But, so far so good. And like with my stupid amount of variants and products in general, that is with a TON of attribute options.

The other conclusion I had was that people could alternatively add another field to that template, perhaps called shorthand/abbreviated for instance. And then use the long form name to search and have an alternative short form name for mapping or front end usage. 

  • Like 2
Link to comment
Share on other sites

7 hours ago, alexm said:

The other conclusion I had was that people could alternatively add another field to that template, perhaps called shorthand/abbreviated for instance. And then use the long form name to search and have an alternative short form name for mapping or front end usage. 

Yeah, good idea. It does create extra work for your editors though. Hopefully, they can live with that.

  • Like 1
Link to comment
Share on other sites

@csaggo.com if you just want a short hand field, you can literally do as I suggested. Use the title field supplied as long version, then create a new field called shorthand attribute name and assign it to the padloped-attribute-option template.

Otherwise, you can gamble on changing the hook as I have done and taking that extra server load.

  • Like 1
Link to comment
Share on other sites

Yes. A custom field is the way to go. Not only will it survive an upgrade, it also offers much more flexibility. Incidentally, you can add any custom field to different templates to suit extra needs. E.g., if you wanted your attributes or categories to have images, you could reuse padloper_images on their respective templates. Currently, the only exception is a repeater field on a product template. They don't play along nicely due to some JavaScript issues (on the part of Padloper).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...