pixelandtonic / DigitalProducts

Sell digital products with Craft Commerce
MIT License
50 stars 6 forks source link
commerce craft-commerce craft-plugin craft2 craftcms digital-products e-commerce ecommerce

Digital Products plugin for Craft Commerce 1.x.

This plugin makes it possible to sell licenses for digital products with Craft Commerce.

Requirements

Digital Products requires Craft CMS 2.6 or later and Craft Commerce 1.1 or later.

Installation

To install Digital Products, copy the digitalproducts/ folder into craft/plugins/, and then go to Settings → Plugins and click the “Install” button next to “Digital Products”.

Configuration

Digital Products gets its own configuration file, located at craft/config/digitalproducts.php. It can have the following config settings:

Plugin Hooks

Digital Products offers a few hooks that enable other plugins to modify its behavior:

Events

Digital Products offers a few events that other plugins can listen to:

Eager loading

Both licenses and products have several eager-loadable properties

Licenses

Products

Examples

Displaying the licensed product for the currently logged in Craft User.

    {% if currentUser %}
        {% set licenses = craft.digitalProducts.licenses.owner(currentUser).with(['products', 'order']) %}

        <div class="panel panel-default">
        <div class="panel-heading"><h3 class="panel-title">Licenses</h3></div>
        {% if licenses %}
            <table class="table">
                <thead>
                    <tr>
                        <th>Licensed product</th>
                        <th>License date</th>
                        <th>Order</th>
                    </tr>
                </thead>
                <tbody>
                {% for license in licenses %}
                    <tr>
                        <td><a href="https://github.com/pixelandtonic/DigitalProducts/blob/master/{{ license.product.getUrl() }}">{{ license.product.title }}</a></td>
                        <td>{{ license.dateCreated|date('Y-m-d H:i:s') }}</td>
                        <td>
                            {% if license.orderId %}
                                <a href="https://github.com/pixelandtonic/DigitalProducts/blob/master/store/order?number={{ license.order.number }}">Order no. {{ license.orderId }}</a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        {% endif %}
    {% else %}
        <p>Please log in first</p>
    {% endif %}

Checking if currently logged in user is licensed to access a product.

    {% set products = craft.digitalProducts.products({type: 'onlineCourses'}).with(['isLicensed']) %}
    {% if products %}
        <table class="table">
            <thead>
                <tr>
                    <th>Product</th>
                    <th>License status</th>
                </tr>
            </thead>
            <tbody>
                {% for product in products %}
                    <tr>
                        <td>{{ product.title }}</td>
                        <td>
                            {% if product.isLicensed() %}
                                You already own this product.
                            {% else %}
                                <a href="https://github.com/pixelandtonic/DigitalProducts/blob/master/{{ product.getUrl() }}">Get it now!</a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}

Changelog

1.0.5

1.0.4

1.0.3

1.0.2

1.0.1

1.0.0