I am setting up the ecommerce ... and have to implement the case of free downloads of some contents/nodes.
Of course I might do this using a simple file field ... and don't fill the commerce file field reference for the same node.

But I am minding if this might be done in Commerce file itself, on products with zero prize.
Would be great if (going through an admin specific option even much better) when the prize is zero then the file is exposed for free download to all users (able to access that commerce file field reference).

Don't know which way would be best to implement this. Anyway something similar to what done here in ubercart: http://drupal.org/project/uc_free_order

Comments

itamair’s picture

any feedback on this?

yanniboi’s picture

Yes this would be really helpful! I would like to take one of my existing products once a month and offer it as a free download without having to create a new node with a file field as the product should already be on the website.

alexander_danilenko’s picture

Try to use rules:

Events: Calculating the sell price of a product.
Conditions: as you need. For example, if user has a role.
Actions: Set the unit price to a specific amount.

itamair’s picture

Mmmhhh … but what might such a Rule accomplish but setting as zero the price of the product?
Should I create a new Rule that based on that would bypass the checkout process and then expose the file for free download.
May be … but still didn't go to much through this solution, yet.

Rather I would now accomplish this integrating and as a variation to the solution I found to expose already bought files to user that bought them, hiding the add to chart bottom contextually. I did it with the solution (personal module) described here: http://drupal.org/node/1266132#comment-5672306

In the case of zero price I might simply alter the form to hide the add to cart bottom and use views to expose the commerce_file for free download, to anybody.
Though quite creative, tt really should work … although I don't know if might be considered the best solution and workaround the this issue.

any further comments would be really welcome!

;-)

cameron prince’s picture

My solution to this problem was to create a second file field for the product type. The first file field is the Commerce File type which is stored in the private file system. The second, free file, is the normal file type stored in the public file system. A free download item has a price of zero and the download is stored in the free file field whereas non-free downloads have a price greater than zero and are stored in the commerce file field. The widgets automatically detect the presence of a file in the fields and hide/show themselves appropriately.

The following code takes care of hiding the price and add to cart form:


function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if (preg_match('/^commerce_cart_add_to_cart_form/', $form_id)) {

    // Lookup the item price.
    $product = commerce_product_load($form['product_id']['#value']);
    $price = entity_metadata_wrapper('commerce_product', $product)->commerce_price->value();

    if ($price['amount'] == 0) {

      // Hide the price and add to cart form.
      drupal_add_css('div.field-type-commerce-price, form.commerce-add-to-cart{display:none}', array('group' => CSS_THEME, 'type' => 'inline'));

    }
  }
}

hmartens’s picture

I've done this for a client. I wrote a step by step tutorial with screenshots on getting this functionality in Drupal Commerce. To view the full tutorial, head on over to the page on my website
Basically this is what I did:
Go to Store > Configuration > Payment methods
Click on "edit" next to your payment rule, in my case it is "Paypal WPS"
Under "Conditions", add a condition called "Price comparison" . Under "Operator", select '>=' and under "Second Price" type in $0.1 . It didn't want to take $0 so I made it $0.1 because I know I'll never have something that cheap. Save this rule and now it should be active.

bojanz’s picture

Category: feature » support
Status: Active » Fixed

Thanks, hmartens!

I would personally always force a checkout, even for free files (since that's where the license is usually created, and it gives you the order as the record of "purchase" too). Commerce No Payment or a similar solution can be used to register a "0 payment" for free orders.

hmartens’s picture

Bojanz, I am actually going through the whole checkout process with my steps and it is creating a license file and keeping it on record that you "purchased" the file. I'm only bypassing the payment method and assigning transaction completed to the "purchase".

But I'll look into Commerce No Payment next time round :) Thanks for your feedback.

Status: Fixed » Closed (fixed)

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

chandu7929’s picture

Issue summary: View changes

hi every one!
since i didn't find any sol. regarding this so i have modified the commerce_file.module file and now it working as i was expecting.

please find the below function

function commerce_file_bypass_license_control($account = NULL) {
return user_access('bypass license control', $account) || user_access('administer licenses', $account);
}

and replace with

function commerce_file_bypass_license_control($account = NULL) {
return user_access('bypass license control', $account) || user_access('administer licenses', $account) || download_free_product_file();
}
now add this additional function in the same file

/**
* it will expose the file for the product whose price is 0 (zero).
*/
function download_free_product_file() {
global $user, $pid;//this is define in
$lp = commerce_product_load($pid);
//$price = entity_metadata_wrapper('commerce_product', $lp)->commerce_price->value();
$price = $lp->commerce_price['und'][0]['amount'];
if($price == 0 && $user->uid) {
return TRUE;
}
}

now add this line in function
commerce_file_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {

global $pid;
$pid = $entity->product_id;
keep all the content as it is.

now you are done any autheticated user will be able to see the commerce file link. you dont need to checkout for those product whose price is 0 (zero).