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.

defaultWeight #

Fetch products based on the default variant’s weight

defaultHeight #

Fetch products based on the default variant’s height

defaultLength #

Fetch products based on the default variant’s length

defaultWidth #

Fetch products based on the default variant’s width

defaultSku #

Fetch products based on the default variant’s sku

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

  • Developer support
  • One year of updates ($199/year for updates after that)
  • 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, without any restrictions, as long as you’re running it from a development, testing, or staging domain.

Will there be recurring/upgrade fees?

Each Commerce license comes with one year of updates. After that, you can unlock additional updates for $199 per year.

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), you can purchase Craft Commerce directly from the Plugin Store or just leave the switch off that says “Include a Craft Pro license” in the purchase form.

Is Craft Pro required?

Craft Commerce does not require Craft Pro; it works perfectly fine on Craft Solo 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, without any restrictions, as long as you’re running it from a development, testing, or staging domain.

Will there be recurring/upgrade fees?

Each Commerce license comes with one year of updates. After that, you can unlock additional updates for $199 per year.

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), you can purchase Craft Commerce directly from the Plugin Store or just leave the switch off that says “Include a Craft Pro license” in the purchase form.

Is Craft Pro required?

Craft Commerce does not require Craft Pro; it works perfectly fine on Craft Solo as well!