Giter Site home page Giter Site logo

pixelandtonic / digitalproducts Goto Github PK

View Code? Open in Web Editor NEW
50.0 6.0 7.0 134 KB

Sell digital products with Craft Commerce

License: MIT License

PHP 82.65% JavaScript 4.90% HTML 12.45%
craft-plugin ecommerce commerce e-commerce digital-products craft-commerce craftcms craft2

digitalproducts's Introduction

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:

  • autoAssignLicensesOnUserRegistration (boolean) – Whether licenses should be automatically assigned to newly-registered users if the emails match. (Default is true.)
  • autoAssignUserOnPurchase (boolean) – Whether license should automatically be assigned to existing users if the emails match. (Default is false.)
  • licenseKeyCharacters (string) – The available characters that can be used in license key generation. (Default is all alphanumeric ASCII characters.)
  • licenseKeyLength (integer) – The length of generated license keys. (Default is 24.)
  • requireLoggedInUser (boolean) – Whether a user must be logged in when completing an order with at least one digital product in the cart. (Default is false.)

Plugin Hooks

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

  • digitalProducts_modifyLicenseKey – Gives plugins a chance to modify a license key when it’s getting generated.

  • digitalProducts_modifyProductSources – Gives plugins a chance to modify the sources on digital product indexes.

  • digitalProducts_defineAdditionalProductTableAttributes – Gives plugins a chance to add additional available table attributes to digital product indexes.

  • digitalProducts_getProductTableAttributeHtml – Gives plugins a chance to override the HTML of the table cells on digital product indexes.

  • digitalProducts_modifyProductSortableAttributes – Gives plugins a chance to modify the array of sortable attributes on digital product indexes.

  • digitalProducts_modifyLicenseSources – Gives plugins a chance to modify the sources on license indexes.

  • digitalProducts_defineAdditionalLicenseTableAttributes – Gives plugins a chance to add additional available table attributes to license indexes.

  • digitalProducts_getLicenseTableAttributeHtml – Gives plugins a chance to override the HTML of the table cells on license indexes.

  • digitalProducts_modifyLicenseSortableAttributes – Gives plugins a chance to modify the array of sortable attributes on license indexes.

Events

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

  • digitalProducts_products.onBeforeSaveDigitalProduct – Raised right before a digital product is saved. Passed with params product (the digital product) and isNewProduct (whether it’s new). Event handlers can prevent the digital product from being saved by setting $event->performAction = false.
  • digitalProducts_products.onSaveDigitalProduct – Raised after a digital product is saved. Passed with the param product (the digital product).
  • digitalProducts_products.onBeforeDeleteDigitalProduct – Raised right before a digital product is deleted. Passed with the param product (the digital product). Event handlers can prevent the digital product from being saved by setting $event->performAction = false.
  • digitalProducts_products.onDeleteDigitalProduct – Raised after a digital product is deleted. Passed with the param product (the digital product).
  • digitalProducts_licenses.onBeforeSaveLicense – Raised right before a license is being saved. Passed with params license (the license) and isNewLicense (whether it’s new). Event handlers can prevent the license from being saved by setting $event->performAction = false.
  • digitalProducts_licenses.onSaveLicense – Raised after a license is saved. Passed with the param license (the license).
  • digitalProducts_licenses.onBeforeDeleteLicense - Raised when a license is being deleted. Passed with the param license (the license). Event handlers can prevent the license from being saved by setting $event->performAction = false.
  • digitalProducts_licenses.onDeleteLicense - Raised when a license is deleted. Passed with the param license (the license).

Eager loading

Both licenses and products have several eager-loadable properties

Licenses

  • product - Allows you to eager-load the product associated with the license.
  • order - Allows you to eager-load the order associated with the license, if any.
  • owner - Allows you to eager-load the Craft user that owns the license, if any.

Products

  • isLicensed - Eager-loads whether the product is licensed for the currently logged in Craft User.

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="{{ 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="/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="{{ product.getUrl() }}">Get it now!</a>
                            {% endif %}
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    {% endif %}

Changelog

1.0.5

  • Fixed a bug where digital product prices would sometimes not be saved correctly.

1.0.4

  • Fixed a bug where digital product prices did not display correctly.

1.0.3

  • Added support for a plugin release feed.

1.0.2

  • Fixed bugs.

1.0.1

  • Fixed bugs.

1.0.0

  • Initial release

digitalproducts's People

Contributors

andris-sevcenko avatar angrybrad avatar artdepartmentmj avatar brandonkelly avatar lukeholder avatar monachilada avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

digitalproducts's Issues

Changing status of license is not saved when making changes in CP

Changing the value in the dropdown labeled "Status" when editing a license, is not persistent after saving the license. Changing the value for "Enabled", on the right hand side does work, and also changes the value displayed in "Status", however, see #1 for how that's handled incorrectly on the front end.

Is the field handle "description" a reserved word in Digital Products?

I have a field with the handle 'description'. In my template, I call that field using {{ product.description }}, but all it does is spit out the Title. I can confirm there are actual sentences within the 'description' field that it should be displaying. I've also changed the 'description' field to 'pDescription' and, after the change, the field shows the correct information.

Seems like the 'description' field handle is a reserved word?

Save as a new product

Entries and Commerce Products have this feature, but I don't believe Digital Products do. In the save button dropdown, it would be nice to have "Save as a new product" as an option.

Craft\DigitalProducts_ProductModel and its behaviors do not have a method or closure named "variants".

I had started a new project using Commerce with a handful of products and have now switched them entirely over to Digital Downloads. I'm trying to use the same template as when they were standard Commerce products, so perhaps thats the issue. Should anything change?

The error I now get is: "Craft\DigitalProducts_ProductModel and its behaviors do not have a method or closure named "variants"."

Looking for some advice. Thanks!

Digital products pricing

When I give a digital product an pricing of € 12.50 and view it again after saving it shows 12,50. When you save it again it becomes € 12.
In Craft Commerce products it's okey.

Allow Dynamic Titles

Hi guys, dropping a note here about a feature request. I'd like to be able to create titles of digital products dynamically with custom fields and possibly entry ID's as well. This process is already in place for general entries if you're needing an example.

I'm not 100% sure, but I don't think you can do this with Commerce entries either, and that would be something to think about adding as well :)

Thanks!

Allow settings to configure when a license will expire

It would be great to be able to set a license to expire after a certain time frame, or under other variable circumstances such as the release of a new software version or support being dropped for an older version of software.

Auto Expire Licenses?

Is it possible to have the licenses auto-expire based on the date of purchase (Ex: licenses would only be valid for one year after purchase)?

Cannot save Digital Product types

I created a digital product type. When I try to make changes to its settings or product fields, I receive the follow PHP error:

Fatal error: Class Craft\DigitalProducts_ProductModel contains 3 abstract methods and must therefore be declared abstract or implement the remaining methods (Commerce\Interfaces\Purchasable::getShippingCategoryId, Commerce\Interfaces\Purchasable::getIsAvailable, Commerce\Interfaces\Purchasable::populateLineItem) in /sync/zift/craft/plugins/digitalproducts/models/DigitalProducts_ProductModel.php on line 318

I am using Craft Commerce v1.2.1327 with Craft CMS v2.6.2950. My server is running PHP 5.6.4.

Type missing from product data?

With regular Craft Commerce products I can get the Product Type with {{ product.type }} but this seems to be missing from digital products. There is typeId but I would like to use the Product Type handle. Could this be added? Thank you.

Deprecation issue

The switch on Commerce from craft.commerce.settings.defaultCurrency to craft.commerce.defaultCurrency needs updating here — looks like it is just on templates/products/_fields.html, as well as on the element type.

Navigation active state incorrect in submenu

Clicking on "Settings" in the Digital Products subnavigation does not show the correct active nav state for the URL. It goes to the correct page, but highlights "Products" instead.

Feature Request: Add checkboxes for multiple deletes

Currently there is not way to mass delete Digital Products as the checkbox column is missing.

Request to have that functionality added as it exists with regular commerce products and other content elements.

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.