<p>While this may not be the best solution, here is a working example for anyone else who has a similar problem (pure twig).</p>

<p>The <code>saleContainsOtherProduct</code> variable is an indication that the sale did <strong>NOT</strong> match the criteria of <strong>only related to product type</strong> so in order to check for only related, use <code>not saleContainsOtherProduct</code>.
Additionally, this only lists sales, but the code within the loop will work for discounts too, so just repeat with a for loop on <code>craft.commerce.discounts.getAllDiscounts()</code></p>

<pre><code>{% set ignoredProductTypes = ['bundles'] %}
{% for sale in craft.commerce.sales.getAllSales() %}
    {% set saleContainsOtherProduct = false %}
    {% set purchasables = [] %}
    {% for id in sale.purchasableIds %}
        {% set purchasable = craft.commerce.purchasables.getPurchasableById(id) %}
        {% if purchasable.product.enabled %}
            {% set purchasables = purchasables | merge([purchasable]) %}
        {% endif %}
    {% endfor %}
    {% for id in sale.categoryIds %}
        {% set category = craft.categories.id(id).one() %}
        {% for product in craft.products().relatedTo(category).all() %}
            {% if product.enabled %}
                {% for purchasable in product.variants %}
                    {% set purchasables = purchasables | merge([purchasable]) %}
                {% endfor %}
            {% endif %}
        {% endfor %}
    {% endfor %}
    {% for purchasable in purchasables if purchasable.product.type.handle not in ignoredProductTypes %}
        {% set saleContainsOtherProduct = true %}
    {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2019-06-28T12:53:06.067Z
2019-06-28T12:53:06.067Z
Seraphim Jester
<p>Imagine a less than perfect world, where a 'bundles' product type is just a new product with a sale/discount on it.
Would there be any way to query all sales and all products <strong>only related to these</strong> but ignore every other regular "used as intended" sale/discount?</p>

<p>From what I can tell, there is no way to categorise sales/discount, only ways to categorise what the affect?</p>

<craft3><plugin-craftcommerce><plugin-craftcommerce2>
Query a subselection of Sales and Discounts
# Query a subselection of Sales and Discounts

(Asked by: username_0 on 2019-06-28)

Imagine a less than perfect world, where a 'bundles' product type is just a new product with a sale/discount on it.
Would there be any way to query all sales and all products **only related to these** but ignore every other regular "used as intended" sale/discount?

From what I can tell, there is no way to categorise sales/discount, only ways to categorise what the affect?

**Tags:** craft3, plugin-craftcommerce, plugin-craftcommerce2

---

## 1 answers

### Answer by username_0 on 2019-06-28. Score: 0 | Accepted answer

While this may not be the best solution, here is a working example for anyone else who has a similar problem (pure twig).
The saleContainsOtherProduct variable is an indication that the sale did NOT match the criteria of only related to product type so in order to check for only related, use not saleContainsOtherProduct.
Additionally, this only lists sales, but the code within the loop will work for discounts too, so just repeat with a for loop on craft.commerce.discounts.getAllDiscounts()
{% set ignoredProductTypes = ['bundles'] %}
{% for sale in craft.commerce.sales.getAllSales() %}
    {% set saleContainsOtherProduct = false %}
    {% set purchasables = [] %}
    {% for id in sale.purchasableIds %}
        {% set purchasable = craft.commerce.purchasables.getPurchasableById(id) %}
        {% if purchasable.product.enabled %}
            {% set purchasables = purchasables | merge([purchasable]) %}
        {% endif %}
    {% endfor %}
    {% for id in sale.categoryIds %}
        {% set category = craft.categories.id(id).one() %}
        {% for product in craft.products().relatedTo(category).all() %}
            {% if product.enabled %}
                {% for purchasable in product.variants %}
                    {% set purchasables = purchasables | merge([purchasable]) %}
                {% endfor %}
            {% endif %}
        {% endfor %}
    {% endfor %}
    {% for purchasable in purchasables if purchasable.product.type.handle not in ignoredProductTypes %}
        {% set saleContainsOtherProduct = true %}
    {% endfor %}
{% endfor %}


---

