Commerce 1 find if Discount object is valid based on start/end dates (Twig) In Twig, I want to find out if a discount is valid based on start/end date.  startDate and endDate don't seem to exist and I can't inspect the discount object by using the json_encode filter (returns {}).

How can we do this?

This is the code used to grab the discount object:

{% set discount = null %}
{% for d in craft.commerce.discounts %}
    {% if d.id == 1 %}{% set discount = d %}{% endif %}
{% endfor %}


name, description and enabled variables are available but no startDate/endDate.
In Commerce 1, craft.commerce.discounts will return an array of Commerce_DiscountModel objects of all available discounts.

public function getAllDiscounts($criteria = [])
{
    $records = Commerce_DiscountRecord::model()-&gt;findAll($criteria);

    return Commerce_DiscountModel::populateModels($records);
}


Commerce_DiscountModel objects have a dateFrom and a dateTo property, which is probably what you're looking for.

Completely untested, but something like this:

{% set discount = null %}
{% for d in craft.commerce.discounts %}
    {% if d.id == 1 %}
        {% set discount = d %}
        {% if discount.dateTo &gt; '2018-01-01 00:00:00' and discount.dateFrom &lt; '2018-12-31 23:59:59' %}
            Matches!
        {% endif %}
    {% endif %}
{% endfor %}