protected function FeedsCommerceProductProcessor::existingEntityId in Commerce Feeds 7
Get product_id of an existing product if available.
File
- plugins/
FeedsCommerceProductProcessor.inc, line 182 - Class definition of FeedsCommerceProductProcessor.
Class
- FeedsCommerceProductProcessor
- Creates products from feed items.
Code
protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
if ($product_id = parent::existingEntityId($source, $result)) {
return $product_id;
}
// Iterate through all unique targets and test whether they do already
// exist in the database.
foreach ($this
->uniqueTargets($source, $result) as $target => $value) {
switch ($target) {
case 'product_id':
$product_id = db_query("SELECT product_id FROM {commerce_product} WHERE product_id = :product_id", array(
':product_id' => $value,
))
->fetchField();
break;
case 'sku':
$product_id = db_query("SELECT product_id FROM {commerce_product} WHERE sku = :sku", array(
':sku' => $value,
))
->fetchField();
break;
}
if ($product_id) {
// Return with the first sku found.
return $product_id;
}
}
return 0;
}