protected function FeedsCommerceCouponProcessor::existingEntityId in Commerce Feeds 7
Get id of an existing feed item term if available.
File
- plugins/
FeedsCommerceCouponProcessor.inc, line 117 - FeedsUserProcessor class.
Class
- FeedsCommerceCouponProcessor
- Feeds processor plugin. Create users from feed items.
Code
protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
if ($coupon_id = parent::existingEntityId($source, $result)) {
return $coupon_id;
}
// Iterate through all unique targets and try to find a coupon for the
// target's value.
foreach ($this
->uniqueTargets($source, $result) as $target => $value) {
switch ($target) {
case 'coupon_code':
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', 'commerce_coupon')
->fieldCondition('commerce_coupon_code', 'value', $value, '=');
$coupon = $query
->execute();
if ($coupon == NULL || !isset($coupon['commerce_coupon']) || !is_array($coupon['commerce_coupon'])) {
return NULL;
}
$coupon = reset($coupon['commerce_coupon']);
if (isset($coupon) && isset($coupon->coupon_id)) {
return $coupon->coupon_id;
}
break;
}
}
return 0;
}