I get an ajax error when trying to add products to a cart in drupal commerce when using themeky for anonymous users.

I have tried the various fixes from another thread and nothing seems to work. I am using commerce, and only see the issue in the following combination:

On a custom theme provided by a themekey switching rule (rule is category tid and children)
on a commerce product display page (a product detail page)
as an anonymous user
as a user who doesn't have anything in their cart (i.e., no anonymous session key yet)
using commerce_ajax_cart
only on themes based on drupal bootstrap theme.
when user clicks the add to cart button, I get the ajax error.

In the logs I get this:

PHP Fatal error: Call to undefined function _bootstrap_process_element()

Which is a function in the bootstrap theme (and sub-themes)

I am using themekey 3.0, and have tried the various ajax settings provided but I still get the error. If I set 'retain theme until new theme set' it does work for auth'ed and anon users, but then other areas of my sites break. For example ,if the user browses back to the home page, the default theme does not display.

Of course, I could try another rule resetting the theme to default for the front page, but I just feel like there are probably other areas that I might miss. It's not entirely clear to me, on my own site, which pages would bring up the default theme right now, so I can't be sure I could catch them all in a rule.

In the other thread, it was suggested that I make sure that I have selected the themes as 'safe' and I tried that but no change.

thanks,

Comments

meecect’s picture

Don't know if it is relevant, but even after clearing my cache, I notice that themekey_menu_alter is not being called. I put some watchdog commands in there and it doesn't seem to be firing. However, themekey_ajax_base_page_theme does get called several times during my page render, so I'm not sure what is going on.

mkalkbrenner’s picture

Category: Bug report » Support request

Did you try the "Bypass" option and set your themes as safe themes at /admin/config/user-interface/themekey/settings/ajax

meecect’s picture

Yes, I set bypass and chose my themes as safe. Running drush rr made the menu_alter register. I did some more digging and found that at this point:

function themekey_ajax_base_page_theme() {
  watchdog('themekey ajax base theme called', 'in function');
  if (
    variable_get('themekey_unsafe_ajax_base_page_theme', 0) &&
    !empty($_POST['ajax_page_state']['theme']) &&
    !empty($_POST['ajax_page_state']['theme_token']) &&
    themekey_check_theme_enabled($_POST['ajax_page_state']['theme_token']) &&
    themekey_is_ajax_theme_safe($_POST['ajax_page_state']['theme_token'])
  ) {
    watchdog('themekey ajax base theme called', 'in return');
   return $_POST['ajax_page_state']['theme'];

if I remove themekey_check_theme_enabled and themekey_is_ajax_theme_safe, ajax starts working again. I'm not sure why those two checks are failing. I even checked 'Provide all themes for selection' in case that was the stumbling block. I'll add some more debug messages in there to find out why the enabled theme check and safe theme check are failing.

mkalkbrenner’s picture

I remove themekey_check_theme_enabled ... ajax starts working again

Is the theme enabled at /admin/appearance ?

meecect’s picture

Yes they are, but I'm just thinking here... shouldn't the check be for themekey_check_theme_enabled($_POST['ajax_page_state']['theme']) and themekey_is_ajax_theme_safe($_POST['ajax_page_state']['theme'])

and not

themekey_check_theme_enabled($_POST['ajax_page_state']['theme_token']) &&
themekey_is_ajax_theme_safe($_POST['ajax_page_state']['theme_token'])

Seems like the enabled themes and safe themes are stored as theme machine names, not tokens.

meecect’s picture

changing theme_token to theme does make it work, if that helps.

mkalkbrenner’s picture

OMG what a typo. You're right!
Maybe I missed to commit the version I tested :-(

meecect’s picture

WOOT!

mkalkbrenner’s picture

Title: Drupal commerce ajax cart returns mixed themes » ajax forms still return mixed themes
Assigned: Unassigned » mkalkbrenner
Category: Support request » Bug report

  • Commit 47a1cad on 7.x-3.x authored by meecect, committed by mkalkbrenner:
    [#2232571] meecect: ajax forms still return mixed themes
    
mkalkbrenner’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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