You are here

function CommerceBpcTestCase::getNumberOfProductsWithFieldValues in Commerce Bulk Product Creation 7

Determine how many products exist with the provided field values.

Parameters

array $attributes: An array of associative arrays with the following keys, each specifying one field condition.

  • field: The name of the field.
  • column: The column of the field, as in EntityFieldQuery::entityCondition (optional, defaults to 'value').
  • value: The value to test for.
2 calls to CommerceBpcTestCase::getNumberOfProductsWithFieldValues()
CommerceBpcTestCase::assertCorrectPermutationsExist in ./commerce_bpc.test
Asserts that a product with the correct permutations exists.
CommerceBpcTestCase::testTwoFieldsTwoListValues in ./commerce_bpc.test
Test the correct creation of 2x3 combinations.

File

./commerce_bpc.test, line 173
Tests for Commerce bulk product creation

Class

CommerceBpcTestCase
@file Tests for Commerce bulk product creation

Code

function getNumberOfProductsWithFieldValues($attributes = array()) {
  $query = new EntityFieldQuery();
  $query
    ->entityCondition('entity_type', 'commerce_product', '=')
    ->entityCondition('bundle', $this->productType['type'], '=');
  foreach ($attributes as $attr) {
    $attr += array(
      'column' => 'value',
    );
    $query = $query
      ->fieldCondition($attr['field'], $attr['column'], $attr['value']);
  }
  $query
    ->count();
  return $query
    ->execute();
}