The autocomplete for products is not working with custom international URL's
The issue is caused by splitting up URL into args.
The current split is limited to only 5 args, while with multi country/language setups, you can have more.

Example: http://example.com/BE/en/commerce_product/autocomplete/commerce_product/...

Where "BE" represents the country and "en" represent the language

The rest is of the URL is a normal autocomplete link.

How do I resolve this?

I tried to use make the autocomplete path absolute but this does break the widget '#autocomplete_path' => '/commerce_product/autocomplete/commerce_product/line_item_product_selector/product',

Comments

rszrama’s picture

Can you explain to me how you split up your language URL argument like that?

thim’s picture

Hi Rszrama,

That's the way the webstore is build-up.
http://shop.schoellerallibert.com/BE/en

Where BE (or NL, LU, DE, ...) stands for the country
And en (or nl, de, fr, ...) stands for the language in that country.

We have 1 central platform which has this country AND language specific context.

For a technical reason, if you are logged-in in the back-end the respects this country and language context.
Which causes that the base URL is always like:
http://shop.schoellerallibert.com/BE/en/admin/commerce/products

This causes the URL args to have an additional 2 more parameters in autocomplete($entity_type, $field_name, $bundle, $string = '') and the autocomplete URL looks like:
http://www.domainname.com/BE/en/commerce_product/autocomplete/commerce_product/line_item_product_selector/product/big

SInce the previous version of Commerce (7.x.1.3), this extra coded was added to the autocomplete function.

  // Extract the SKU string from the URL while preserving support for SKUs that
  // contain slashes. Whereas we previously relied on the $string parameter, its
  // value was being truncated when any SKUs in the autocomplete widget had a /.
  // @see http://drupal.org/node/1962144
  $args = explode('/', request_path());

  if (count($args) <= 5) {
    drupal_json_output($matches);
  }

  array_splice($args, 0, 5);

Since it fixed to 6 URL arguments, it causes to take the incorrect arguments which causes the function to return no results.

I can take away these lines or increase the number of arguments, but perhaps you have a better solution?

Regards,
Tim

rszrama’s picture

I was actually looking for more of a tutorial for how to reproduce what you've done with the URLs. Also, is there any way for you to simply ignore the i18n URL prefix for the autocomplete URL?

thim’s picture

I'll look into it and provide you with some more information

rszrama’s picture

Version: 7.x-1.6 » 7.x-1.x-dev
Component: Product reference » Product
Status: Active » Fixed

Well, regardless of how you've configured yours, I created a simple workaround to offset that array_splice() based on the argument position of commerce_product. This will work regardless of how many leading arguments there are.

Commit: http://drupalcode.org/project/commerce.git/commitdiff/cfc8326

thim’s picture

Tested and confirmed this is working as expected.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Corrected typo's and improved description