Hi,

Is there an easy way to know whether the current user has already bought a file referenced on a product display ? That way I can remove the add to cart button.
There is a way described here http://drupal.org/node/1266132#comment-5672306 but I find it difficult so I was hoping there could be an easy or at least easier way to find this out.

Thank you.

Comments

bojanz’s picture

Status: Active » Fixed

You can do an entityfieldquery with a propertyCondition on "uid" and a fieldCondition on "commerce_line_item_reference".

bojanz’s picture

Status: Fixed » Active

Actually, no, that won't work, you need the fid on the other side. An entityfieldquery won't do the trick.

recrit’s picture

Status: Active » Needs work

there is a helper field query function commerce_file_license_load_by_property() that gets used in various places such as the "commerce_file_access_link" field formatter to switch between a link and plain text display.

If you only know the file ids and user account, it can be called:

      $access = FALSE;
      $licenses = commerce_file_license_load_by_property($fids, array(), $account);
      if (!empty($licenses)) {
        foreach($licenses as $license) {
          if (_commerce_file_field_view_access_license($license, $account)) {
            $access = TRUE;
            break;
          }
        }
      }

This could be broken out to be used elsewhere.

bojanz’s picture

Status: Needs work » Fixed

Marking as fixed based on #3.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

nico

daniel wentsch’s picture

Issue summary: View changes

Bump. It seems commerce_file_license_load_by_property is gone – is there any alternative we could use today (still D7)?