Skip to content

Commit

Permalink
Issue #2 - Add unique option for SKU
Browse files Browse the repository at this point in the history
Thanks @philsward
  • Loading branch information
stpaultim committed Nov 18, 2021
2 parents 9407c46 + 663780c commit f12b891
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions uc_feeds.module
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function uc_feeds_feeds_processor_targets_alter(&$targets, $entity_type, $bundle
'name' => t('UC: Model/SKU'),
'callback' => 'uc_feeds_set_target',
'description' => 'Ubercart:' . t('Model/SKU'),
'optional_unique' => TRUE,
'unique_callbacks' => array('uc_feeds_sku_mapper_unique')
);
// List price.
$targets['list_price'] = array(
Expand Down Expand Up @@ -141,6 +143,32 @@ function uc_feeds_feeds_processor_targets_alter(&$targets, $entity_type, $bundle
}
}

/**
* Looks for node matching the given SKU
*
* @param FeedsSource $source
* The Feed source.
* @param string $entity_type
* Entity type for the entity to be processed.
* @param string $bundle
* Bundle name for the entity to be processed.
* @param string $target
* A string identifying the unique target on the entity.
* @param array $values
* The unique values to be checked.
*
* @return int|null
* The existing entity id, or NULL if no existing entity is found.
*
* @see hook_feeds_processor_targets()
* @see FeedsProcessor::existingEntityId()
*/
function uc_feeds_sku_mapper_unique(FeedsSource $source, $entity_type, $bundle, $target, array $values) {
$nid = db_query("SELECT nid FROM {uc_products} WHERE model = :model", array(':model' => $values[0]))->fetchField();

return $nid;
}

/**
* User has decided to map to and $value contains the value of the feed item
* element the user has picked as a source.
Expand Down

0 comments on commit f12b891

Please sign in to comment.