function uc_feeds_feeds_set_target in Ubercart Feed Mappers 6
Callback for mapping. Here is where the actual mapping happens.
When the callback is invoked, $target contains the name of the field the user has decided to map to and $value contains the value of the feed item element the user has picked as a source.
Parameters
object $node:
string $target:
mixed $value:
Return value
void
1 string reference to 'uc_feeds_feeds_set_target'
- uc_feeds_feeds_node_processor_targets_alter in ./
uc_feeds.module - Implementation of hook_feeds_node_processor_targets_alter().
File
- ./
uc_feeds.module, line 146 - Integrates Ubercart properties with Feeds
Code
function uc_feeds_feeds_set_target(&$node, $target, $value) {
if (is_array($value) || $value == '') {
return;
}
// Examine target: first part is module, second part is target
list($module, $target) = explode(':', $target);
switch ($module) {
// Ubercart Attributes
case 'uc_attribute':
$ao_arr = explode('_', $target);
$aid = $ao_arr[2];
$oid = $ao_arr[3];
// just flag the attributes for now - node API will take care of saving them
$node->uc_feeds_flag = 'Attributes';
if (substr($target, 0, 15) == 'attribute_price') {
$node->attributes[$aid]->options[$oid]->price = $value;
}
elseif (substr($target, 0, 16) == 'attribute_weight') {
$node->attributes[$aid]->options[$oid]->weight = $value;
}
return;
// Stock
case 'uc_stock':
if (!isset($node->model)) {
// Error: model is unknown.
drupal_set_message(t("You can not set the stock for a product if the Model/SKU is not known. Ensure that you map the Model/SKU first.", 'warning'));
return;
}
if (uc_stock_is_active($node->model)) {
// Update stock levels
uc_stock_set($node->model, $value);
}
else {
// Insert new stock level. Not sure how to set the threshold. This would be zero now.
$sQuery = "INSERT INTO {uc_product_stock} (sku, nid, active, stock) VALUES ('%s', %d, %d, %d)";
db_query($sQuery, $node->model, $node->nid, 1, $value);
}
return;
// Product
case 'uc_product':
switch ($target) {
case 'length':
case 'width':
case 'height':
$d = "dim_{$target}";
$node->{$d} = $value;
break;
default:
$node->{$target} = $value;
}
return;
}
}