Get all Variant SKUs using getCriteria I want to create an array of all SKUs on Craft Commerce. The end goal is to create a plugin that only applies Sales to certain variants. It does this by  checking the Sale's description for any mention of SKUs and comparing this against the list of all available SKUs.

I thought this would do the trick…

$allvariants = craft()-&gt;elements-&gt;getCriteria('Commerce_Variant');
$allskus = $allvariants -&gt; sku;


But it doesn't appear to work. The full code of the plugin is…

craft()-&gt;on('commerce_sales.onBeforeMatchProductAndSale', function($event){
    $sale = $event-&gt;params['sale'];

    $allvariants = craft()-&gt;elements-&gt;getCriteria('Commerce_Variant');
    $allskus = $allvariants -&gt; sku;

    if (stripos($sale-&gt;description, 'only') === false) {
       return; /* do nothing, and let the sale match as it normally would, because the sale does not have 'only' in the description. */
    } else {
        if (stripos($sale-&gt;description, $allskus) === false) {
            $event-&gt;performAction = false; /* since this SKU is not in the description string, then don't apply this discount */
        }
    }
});`


(Full credit to @luke-holder who wrote the plugin to do this for Discounts)
This should grab all of the variant's SKUs like you're looking for:

$criteria = craft()-&gt;elements-&gt;getCriteria('Commerce_Variant');
$allVariants = $criteria-&gt;find();
$allSkus = array();

foreach ($allVariants as $variant)
{
    $allSkus[] = $variant-&gt;sku;
}