craft.commerce.products

How to get products #

You can access your site’s products from your templates via craft.commerce.products It returns an ElementCriteriaModel object.

{% set products = craft.commerce.products.type('normal').find() %}

{% for product in products %}
  {% for variant in product.variants %}
    {{ variant.sku }} - {{ variant.salePrice }} <br>
  {% endfor %}
{% endfor %}

Parameters #

craft.commerce.products supports the following parameters:

ID #

The Product’s element ID.

type #

Product Type model or handle.

typeId #

Product type ID.

status #

Only fetch products with the given status.

Possible values are ‘live’, ‘pending’, ‘expired’, ‘disabled’, and null. The default value is ‘live’. null will return all entries regardless of status.

An entry is ‘live’ if it is enabled, has a availableOn in the past and an expiresOn Date in the future. An entry is ‘pending’ if it is enabled and has availableOn and expiresOn Dates in the future. An entry is ‘expired’ if it is enabled and has availableOn and expiresOn Dates in the past.

postDate #

Fetch products based on their postDate.

expiryDate #

Fetch products based on their date of expiry.

after #

Fetch products based on available dates after this date.

before #

Fetch products based on their date available.

hasVariant #

Only return products where the hasVariant params match the product’s variants.

For example:

{% set products = craft.commerce.products.type('tshirt').hasVariant({ color: 'red' }) %}

Variant Parameters #

There is no way to query all variants directly, but within the hasVariant product criteria parameters you have access to all basic element criteria parameters in addition to the following special criteria that apply to variants:

hasStock #

Returns products that have at least one variant in stock.

Accepts: true or false

For example:

{% set products = craft.commerce.products({
  hasVariant: {
    hasStock: true
  },
}) %}

hasSales #

Returns products that have at least one sale available to the current user.

Accepts: true or false

For example:

{% set products = craft.commerce.products({
  hasSales: true
}) %}

Buy Craft Commerce

Craft Commerce site license

Includes

  • Standard tech support
  • Unlimited app updates
  • Craft Pro site license
Buy now for $999
Can I try before buying?

Absolutely. Just download it from the “Download” button in the site header and follow our installation instructions. You’ll have the full feature set to experiment with, with just one limitation: you won’t be able to charge credit cards. Until Craft Commerce has been purchased and activated, it’s limited to a single dummy gateway.

Will there be recurring/upgrade fees?

Nope, it’s just a one-time license fee per site.

Can I use this on an existing Craft site?

Yes! And if you already have a Craft Pro license (or you don’t need one), just flip that “Include a Craft Pro license” switch in the purchase form, and we’ll drop the price to $700.

Is Craft Pro required?

Craft Commerce does not require Craft Pro; it works perfectly fine on Craft Client and Personal editions as well!

Can I try before buying?

Absolutely. Just download it from the “Download” button in the site header and follow our installation instructions. You’ll have the full feature set to experiment with, with just one limitation: you won’t be able to charge credit cards. Until Craft Commerce has been purchased and activated, it’s limited to a single dummy gateway.

Will there be recurring/upgrade fees?

Nope, it’s just a one-time license fee per site.

Can I use this on an existing Craft site?

Yes! And if you already have a Craft Pro license (or you don’t need one), just flip that “Include a Craft Pro license” switch in the purchase form, and we’ll drop the price to $700.

Is Craft Pro required?

Craft Commerce does not require Craft Pro; it works perfectly fine on Craft Client and Personal editions as well!