updated webform, uuid, synonyms modules
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Enables Commerce Price field type for synonyms integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Definition of CommercePriceSynonymsBehavior class.
|
||||
*/
|
||||
class CommercePriceSynonymsBehavior extends AbstractFieldSynonymsBehavior {
|
||||
|
||||
public function extractSynonyms($entity, $langcode = NULL) {
|
||||
$synonyms = array();
|
||||
|
||||
foreach ($this->entityItems($entity, $langcode) as $item) {
|
||||
$synonyms[] = commerce_currency_format($item['amount'], $item['currency_code'], $entity);
|
||||
}
|
||||
|
||||
return $synonyms;
|
||||
}
|
||||
|
||||
public function mergeEntityAsSynonym($trunk_entity, $synonym_entity, $synonym_entity_type) {
|
||||
// TODO: remove this thing.
|
||||
}
|
||||
|
||||
public function synonymsFind(QueryConditionInterface $condition) {
|
||||
if ($this->field['storage']['type'] != 'field_sql_storage') {
|
||||
throw new SynonymsBehaviorException(t('Not supported storage engine %type in @method() method.', array(
|
||||
'%type' => $this->field['storage']['type'],
|
||||
'@method' => __METHOD__,
|
||||
)));
|
||||
}
|
||||
$table = array_keys($this->field['storage']['details']['sql'][FIELD_LOAD_CURRENT]);
|
||||
$table = reset($table);
|
||||
$columns = $this->field['storage']['details']['sql'][FIELD_LOAD_CURRENT][$table];
|
||||
|
||||
$query = db_select($table, 'field');
|
||||
|
||||
$query->fields('field', array('entity_id'));
|
||||
$query->addField('field', $columns['amount'], 'amount');
|
||||
$query->addField('field', $columns['currency_code'], 'currency_code');
|
||||
$query->condition('field.entity_type', $this->instance['entity_type']);
|
||||
$query->condition('field.bundle', $this->instance['bundle']);
|
||||
|
||||
$this->synonymsFindProcessCondition($condition, 'field.' . $columns['amount'], 'field.entity_id');
|
||||
$query->condition($condition);
|
||||
$result = $query->execute();
|
||||
|
||||
$matches = array();
|
||||
|
||||
foreach ($result as $row) {
|
||||
$matches[] = (object) array(
|
||||
'entity_id' => $row->entity_id,
|
||||
'synonym' => commerce_currency_format($row->amount, $row->currency_code),
|
||||
);
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
}
|
@@ -10,11 +10,11 @@
|
||||
*/
|
||||
class CommerceProductReferenceSynonymsBehavior extends AbstractFieldSynonymsBehavior {
|
||||
|
||||
public function extractSynonyms($entity) {
|
||||
public function extractSynonyms($entity, $langcode = NULL) {
|
||||
$synonyms = array();
|
||||
|
||||
$product_ids = array();
|
||||
foreach ($this->entityItems($entity) as $item) {
|
||||
foreach ($this->entityItems($entity, $langcode) as $item) {
|
||||
$product_ids[] = $item['product_id'];
|
||||
}
|
||||
$entities = commerce_product_load_multiple($product_ids);
|
||||
|
@@ -4,16 +4,18 @@ package = Synonyms
|
||||
core = 7.x
|
||||
dependencies[] = synonyms_provider_field
|
||||
dependencies[] = commerce_product_reference
|
||||
dependencies[] = commerce_price
|
||||
|
||||
test_dependencies[] = commerce:commerce_product_ui
|
||||
|
||||
files[] = synonyms_commerce.test
|
||||
|
||||
files[] = includes/CommerceProductReferenceSynonymsBehavior.class.inc
|
||||
files[] = includes/CommercePriceSynonymsBehavior.class.inc
|
||||
|
||||
; Information added by Drupal.org packaging script on 2016-05-07
|
||||
version = "7.x-1.5"
|
||||
; Information added by Drupal.org packaging script on 2017-06-30
|
||||
version = "7.x-1.6"
|
||||
core = "7.x"
|
||||
project = "synonyms"
|
||||
datestamp = "1462586641"
|
||||
datestamp = "1498833845"
|
||||
|
||||
|
@@ -154,6 +154,7 @@ function synonyms_commerce_synonyms_provider_field_behavior_implementation_info(
|
||||
case 'autocomplete':
|
||||
return array(
|
||||
'commerce_product_reference' => 'CommerceProductReferenceSynonymsBehavior',
|
||||
'commerce_price' => 'CommercePriceSynonymsBehavior',
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
@@ -117,7 +117,9 @@ function synonyms_commerce_autocomplete($field_name, $entity_type, $bundle) {
|
||||
$synonym_entities = commerce_product_load_multiple($synonym_entities);
|
||||
foreach ($matches as $k => $match) {
|
||||
if (!isset($match['name']) && isset($match['synonym'])) {
|
||||
$entity_ids = entity_extract_ids('commerce_product', $synonym_entities[$match['target_id']]);
|
||||
$matches[$k]['name'] = entity_label('commerce_product', $synonym_entities[$match['target_id']]);
|
||||
$matches[$k]['bundle'] = $entity_ids[2];
|
||||
}
|
||||
}
|
||||
$matches = array_values($matches);
|
||||
|
@@ -847,3 +847,248 @@ class CommerceProductReferenceSynonymsBehaviorWebTestCase extends AbstractSynony
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test CommercePriceSynonymsBehavior class.
|
||||
*/
|
||||
class CommercePriceSynonymsBehaviorWebTestCase extends AbstractSynonymsProviderFieldWebTestCase {
|
||||
|
||||
/**
|
||||
* GetInfo method.
|
||||
*/
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'CommercePriceSynonymsBehavior',
|
||||
'description' => 'Ensure that the synonyms module extracts synonyms from commerce price fields correctly.',
|
||||
'group' => 'Synonyms',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* SetUp method.
|
||||
*/
|
||||
public function setUp($modules = array()) {
|
||||
$modules[] = 'commerce_price';
|
||||
$modules[] = 'commerce_product_reference';
|
||||
$modules[] = 'commerce_product_ui';
|
||||
$modules[] = 'synonyms_commerce';
|
||||
|
||||
$this->fields['enabled']['field'] = array(
|
||||
'field_name' => 'synonyms_commerce_price',
|
||||
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
|
||||
'type' => 'commerce_price',
|
||||
);
|
||||
|
||||
parent::setUp($modules);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test synonyms extraction for 'commerce_price' field type.
|
||||
*/
|
||||
public function testCommercePrice() {
|
||||
// Testing synonymsExtract().
|
||||
$this->assertSynonymsExtract(array(), array(), 'on empty field.');
|
||||
|
||||
$this->assertSynonymsExtract(array(
|
||||
LANGUAGE_NONE => array(
|
||||
0 => array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
), array(commerce_currency_format(1000, 'USD')), 'on a field that holds one value.');
|
||||
|
||||
// Testing synonymFind() method.
|
||||
$this->assertSynonymsFind(array(), db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on empty field');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(),
|
||||
'found_synonyms' => array(),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on a field without values');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, $this->randomName()), 'on a field with a value but searching for another string');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000), 'on a field with a single value searching for that string');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 2000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000), 'on a field with 2 values searching for one of those 2 values');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 2000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
|
||||
);
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 100,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 200,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000), 'on 2 fields with 2 values each searching for one of those values');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(10) . '%', 'LIKE'), 'on a field with a value searching for a string LIKE the %value%');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 100,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(
|
||||
commerce_currency_format(1000, 'USD'),
|
||||
commerce_currency_format(100, 'USD'),
|
||||
),
|
||||
);
|
||||
$this->assertSynonymsFind($meta_data, db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, db_like(100) . '%', 'LIKE'), 'on a field with 2 similar values searching a string like %both values%');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 2000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(
|
||||
commerce_currency_format(1000, 'USD'),
|
||||
commerce_currency_format(2000, 'USD'),
|
||||
),
|
||||
);
|
||||
$condition = db_or()
|
||||
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000)
|
||||
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 2000);
|
||||
$this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 or value2');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 2000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(commerce_currency_format(1000, 'USD')),
|
||||
);
|
||||
$condition = db_and()
|
||||
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000)
|
||||
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(10) . '%', 'LIKE');
|
||||
$this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for value1 and LIKE value1%');
|
||||
|
||||
$meta_data = array();
|
||||
$meta_data[] = array(
|
||||
'items' => array(
|
||||
LANGUAGE_NONE => array(
|
||||
array(
|
||||
'amount' => 1000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
array(
|
||||
'amount' => 2000,
|
||||
'currency_code' => 'USD',
|
||||
),
|
||||
),
|
||||
),
|
||||
'found_synonyms' => array(
|
||||
commerce_currency_format(1000, 'USD'),
|
||||
commerce_currency_format(2000, 'USD'),
|
||||
),
|
||||
);
|
||||
$condition = db_or()
|
||||
->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 1000)
|
||||
->condition(db_and()->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, 2000)->condition(AbstractSynonymsBehavior::COLUMN_SYNONYM_PLACEHOLDER, '%' . db_like(20) . '%', 'LIKE'));
|
||||
$this->assertSynonymsFind($meta_data, $condition, 'on a field with 2 values searching for (value1 or (value2 AND value2%))');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user