I have below query , when it run with non-registered user return null but with any register used with any role has result .
also non-registered user has permission to view any product
$result = db_query("SELECT * FROM {node} node
LEFT JOIN {field_data_field_course_ref} field_data_field_course_ref ON node.nid = field_data_field_course_ref.entity_id AND (field_data_field_course_ref.entity_type = 'node' AND field_data_field_course_ref.deleted = '0')
LEFT JOIN {commerce_product} commerce_product_field_data_field_course_ref ON field_data_field_course_ref.field_course_ref_product_id = commerce_product_field_data_field_course_ref.product_id
WHERE (( (node.nid = :nid ) )AND(( (node.status = '1') AND (node.type IN ('course_display')) )))
", array(':nid' => $nid));
$coursePIDs = array();
//get node product variation
foreach ($result as $record) {
$coursePIDs[$record->field_course_ref_product_id] = $record->field_course_ref_product_id;
}
ym($coursePIDs);
any idea?