So I've been trying to implement an anonymous "wish list" for an eCommerce site using webform_select_options and Flag. My implementation uses an anonymous flag set on my products and uses webform_hook_select to add a select list of the flagged products to a webform.
The issue I have is that the webform_select_options only show up in the webform when the user's logged in, thus failing as an anonymous implementation.
UPDATE (number 2 8/12/15)
I can confirm that the items are flagged when an anonymous user flags them. I tested this with a block displaying the flagged items when the site was viewed in incognito mode, the list is modifiable (I can add and remove flagged items), so it behaves more or less the way I expect it to.
The view shows commerce products that have been flagged by the current user. This shows me that the items are flagged. I have tested this with multiple browsers in incognito mode and can confirm that the lists are different for different anonymous users.
I tried the dpm($view->result); and it looks like the function doesn't get called with anonymous users. The function prints results with an authenticated user, but no result with anonymous users. I adjusted anonymous permissions to see devel information and can confirm that the function is called with anonymous viewers but returns an array with 0 objects.
Here is the code I'm using, the flag is defined through the flag module UI.
<?php
function webform_hook_webform_select_options_info() {
$items = array();
if (function_exists('webform_hook_user_flag_sample_requests')) {
$items['webform_hook_user_flag_sample_requests'] = array(
'title' => t("Sample Requests (User Flag list)"),
'options callback' => 'webform_hook_user_flag_sample_requests',
);
}
return $items;
}
function webform_hook_user_flag_sample_requests() {
$view = views_get_view('webform_flag_views', TRUE);
$view->set_display('webform_options');
$view->execute();
dpm($view->result);
$options = array();
if ($view->result) {
foreach($view->result as $item) {
$options[$item->product_id]= $item->commerce_product_title . render($item->field_field_image[0]['rendered']);
}
}
else {
$options[0] = t("Nothing");
}
return $options;
}
So, I am at a loss at to what is wrong here, or how to approach this problem. I followed the tutorial here http://drupalsteve.com/node/57, but there doesn't seem to be an obvious way to resolve this.
I now strongly suspect that this is related to the general issue of showing a view to an anonymous user. Normally, you'd mitigate this by disabling SQL rewriting. Now, I wonder if my flags aren't showing up because I haven't programmaticaly set the advanced options of the "view" being created in the script.
So, I can think of two options: 1) create the flag array without generating a view; or 2) set the advanced query setting to disable sql rewriting.
thanks in advance.
dpm($view->result)
may help?)