--- Y:/drupal/testing creating patch/uc_feeds/uc_feeds.module	Fri Feb 25 12:14:48 2011
+++ Y:/drupal/testing creating patch/uc_feeds/uc_feeds_patch.module	Wed Dec 14 09:24:09 2011
@@ -1,130 +1,148 @@
-<?php 
-
-
-/**
- * Implementation of hook_feeds_node_processor_targets_alter().
- */
-function uc_feeds_feeds_node_processor_targets_alter(&$targets, $content_type) {
-	// Proceed only if the content_type is a product type.
-	if (in_array($content_type, uc_product_types())) {
-		// Model
-		$targets['model'] = array(
-			'name' => t('UC: Model/SKU'),
-			'callback' => 'uc_feeds_feeds_set_target',
-			'description' => 'Ubercart:'. t('Model/SKU'),
-		);
-		// List price
-		$targets['list_price'] = array(
-			'name' => t('UC: List price'),
-			'callback' => 'uc_feeds_feeds_set_target',
-			'description' => 'Ubercart:'. t('List price'),
-		);
-		// Cost
-		$targets['cost'] = array(
-			'name' => t('UC: Cost'),
-			'callback' => 'uc_feeds_feeds_set_target',
-			'description' => 'Ubercart:'. t('Cost'),
-		);
-		// Sell price
-		$targets['sell_price'] = array(
-			'name' => t('UC: Sell price'),
-			'callback' => 'uc_feeds_feeds_set_target',
-			'description' => 'Ubercart:'. t('Sell price'),
-		);
-		// Weight
-		$targets['weight'] = array(
-			'name' => t('UC: Weight'),
-			'callback' => 'uc_feeds_feeds_set_target',
-			'description' => 'Ubercart:'. t('Weight'),
-		);
-		$targets['weight_units'] = array(
-			'name' => t('UC: Weight Unit'),
-			'callback' => 'uc_feeds_feeds_set_target',
-			'description' => 'Ubercart:'. t('Weight Unit'),
-		);
-		// Attributes
-		if (module_exists("uc_attribute")) {
-			$attribs = uc_attribute_load_multiple();
-			foreach ($attribs as $attrib) {
-				$aid = $attrib->aid;
-				foreach ($attrib->options as $option) {
-					$oid = $option->oid;
-					$targets['attribute_price_' . $aid . "_" . $oid] = array(
-						'name' => t('UCA Price: ' . $attrib->name . ":" . $option->name),
-						'callback' => 'uc_feeds_feeds_set_target',
-						'description' => 'Ubercart:'. t('Attribute Price:' . $attrib->name . ":" . $option->name),
-					);
-				}
-			}
-			foreach ($attribs as $attrib) {
-				$aid = $attrib->aid;
-				foreach ($attrib->options as $option) {
-					$oid = $option->oid;
-					$targets['attribute_weight_' . $aid . "_" . $oid] = array(
-						'name' => t('UCA Weight: ' . $attrib->name . ":" . $option->name),
-						'callback' => 'uc_feeds_feeds_set_target',
-						'description' => 'Ubercart:'. t('Attribute Weight:' . $attrib->name . ":" . $option->name),
-					);
-				}
-			}
-		}
-	}
-}
-
-/**
- * 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.
- */
-function uc_feeds_feeds_set_target(&$node, $target, $value) {
-	if (!is_array($value)) {
-		if (substr($target,0,10) != "attribute_") {
-			$node->$target = $value;
-		} else {
-			$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;
-			}
-		}
-	}
-}
-
-function uc_feeds_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
-	if (!$node->uc_feeds_flag == "Attributes") return;
-	switch ($op) {
-		case "insert":
-			//dpm($node);
-			if (module_exists("uc_attribute")) {
-				foreach ($node->attributes as $aid=>$feedattrib) {
-					// Enable all options for added attributes.
-					$attribute = uc_attribute_load($aid);
-					foreach ($attribute->options as $option) {
-						if ($node->attributes[$aid]->options[$option->oid]) {
-							$option->price = $node->attributes[$aid]->options[$option->oid]->price;
-							$option->weight = $node->attributes[$aid]->options[$option->oid]->weight;
-						}
-						db_query("INSERT INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) VALUES (%d, %d, %f, %f, %f, %d)", $node->nid, $option->oid, $option->cost, $option->price, $option->weight, $option->ordering);
-						//dpm(array("INSERT INTO uc_product_options (nid, oid, cost, price, weight, ordering) VALUES (%d, %d, %f, %f, %f, %d)", $node->nid, $option->oid, $option->cost, $option->price, $option->weight, $option->ordering));
-					}
-					// Make the first option (if any) the default.
-					$option = reset($attribute->options);
-					if ($option) {
-						$oid = $option->oid;
-					} else {
-						$oid = 0;
-					}
-					db_query("INSERT INTO {uc_product_attributes} (nid, aid, label, ordering, default_option, required, display) SELECT %d, aid, label, ordering, %d, required, display FROM {uc_attributes} WHERE aid = %d", $node->nid, $oid, $aid);
-					//dpm(array("INSERT INTO uc_product_attributes (nid, aid, label, ordering, default_option, required, display) SELECT %d, aid, label, ordering, %d, required, display FROM {uc_attributes} WHERE aid = %d", $node->nid, $oid, $aid));
-				}
-				break;
-			}
-	}
+<?php 
+
+
+/**
+ * Implementation of hook_feeds_node_processor_targets_alter().
+ */
+function uc_feeds_feeds_node_processor_targets_alter(&$targets, $content_type) {
+	// Proceed only if the content_type is a product type.
+	if (in_array($content_type, uc_product_types())) {
+		// Model
+		$targets['model'] = array(
+			'name' => t('UC: Model/SKU'),
+			'callback' => 'uc_feeds_feeds_set_target',
+			'description' => 'Ubercart:'. t('Model/SKU'),
+		);
+		// List price
+		$targets['list_price'] = array(
+			'name' => t('UC: List price'),
+			'callback' => 'uc_feeds_feeds_set_target',
+			'description' => 'Ubercart:'. t('List price'),
+		);
+		// Cost
+		$targets['cost'] = array(
+			'name' => t('UC: Cost'),
+			'callback' => 'uc_feeds_feeds_set_target',
+			'description' => 'Ubercart:'. t('Cost'),
+		);
+		// Sell price
+		$targets['sell_price'] = array(
+			'name' => t('UC: Sell price'),
+			'callback' => 'uc_feeds_feeds_set_target',
+			'description' => 'Ubercart:'. t('Sell price'),
+		);
+		// Weight
+		$targets['weight'] = array(
+			'name' => t('UC: Weight'),
+			'callback' => 'uc_feeds_feeds_set_target',
+			'description' => 'Ubercart:'. t('Weight'),
+		);
+		$targets['weight_units'] = array(
+			'name' => t('UC: Weight Unit'),
+			'callback' => 'uc_feeds_feeds_set_target',
+			'description' => 'Ubercart:'. t('Weight Unit'),
+		);
+		// Roles Prices
+		if (module_exists("uc_price_per_role")) {
+			$roles_list = user_roles();
+			foreach($roles_list as $key => $value) {
+				//$target_name = 'role_prices[' .$key. ']';
+				$targets['roleprices_'.$key] = array(
+				'name' => t('UC: Role Price: '. $value),
+				'callback' => 'uc_feeds_feeds_set_target',
+				'description' => 'Ubercart:'. t($value . 'Price'),
+				);
+			}
+		}
+		// Attributes
+		if (module_exists("uc_attribute")) {
+			$attribs = uc_attribute_load_multiple();
+			foreach ($attribs as $attrib) {
+				$aid = $attrib->aid;
+				foreach ($attrib->options as $option) {
+					$oid = $option->oid;
+					$targets['attribute_price_' . $aid . "_" . $oid] = array(
+						'name' => t('UCA Price: ' . $attrib->name . ":" . $option->name),
+						'callback' => 'uc_feeds_feeds_set_target',
+						'description' => 'Ubercart:'. t('Attribute Price:' . $attrib->name . ":" . $option->name),
+					);
+				}
+			}
+			foreach ($attribs as $attrib) {
+				$aid = $attrib->aid;
+				foreach ($attrib->options as $option) {
+					$oid = $option->oid;
+					$targets['attribute_weight_' . $aid . "_" . $oid] = array(
+						'name' => t('UCA Weight: ' . $attrib->name . ":" . $option->name),
+						'callback' => 'uc_feeds_feeds_set_target',
+						'description' => 'Ubercart:'. t('Attribute Weight:' . $attrib->name . ":" . $option->name),
+					);
+				}
+			}
+		}
+	}
+}
+
+/**
+ * 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.
+ */
+function uc_feeds_feeds_set_target(&$node, $target, $value) {
+	if (!is_array($value)) {
+		if (substr($target,0,10) != "attribute_" && substr($target,0,11) != "roleprices_") {
+			$node->$target = $value;
+		}
+		if (substr($target,0,10) == "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;
+			}
+		}
+		if (substr($target,0,11) == "roleprices_") {
+			$role_array = explode("_",$target);
+			$roleid = $role_array[1];
+			$node->role_prices[$roleid] = $value;
+		}
+	}
+}
+
+function uc_feeds_nodeapi(&$node, $op, $arg3 = NULL, $arg4 = NULL) {
+	if (!$node->uc_feeds_flag == "Attributes") return;
+	switch ($op) {
+		case "insert":
+			//dpm($node);
+			if (module_exists("uc_attribute")) {
+				foreach ($node->attributes as $aid=>$feedattrib) {
+					// Enable all options for added attributes.
+					$attribute = uc_attribute_load($aid);
+					foreach ($attribute->options as $option) {
+						if ($node->attributes[$aid]->options[$option->oid]) {
+							$option->price = $node->attributes[$aid]->options[$option->oid]->price;
+							$option->weight = $node->attributes[$aid]->options[$option->oid]->weight;
+						}
+						db_query("INSERT INTO {uc_product_options} (nid, oid, cost, price, weight, ordering) VALUES (%d, %d, %f, %f, %f, %d)", $node->nid, $option->oid, $option->cost, $option->price, $option->weight, $option->ordering);
+						//dpm(array("INSERT INTO uc_product_options (nid, oid, cost, price, weight, ordering) VALUES (%d, %d, %f, %f, %f, %d)", $node->nid, $option->oid, $option->cost, $option->price, $option->weight, $option->ordering));
+					}
+					// Make the first option (if any) the default.
+					$option = reset($attribute->options);
+					if ($option) {
+						$oid = $option->oid;
+					} else {
+						$oid = 0;
+					}
+					db_query("INSERT INTO {uc_product_attributes} (nid, aid, label, ordering, default_option, required, display) SELECT %d, aid, label, ordering, %d, required, display FROM {uc_attributes} WHERE aid = %d", $node->nid, $oid, $aid);
+					//dpm(array("INSERT INTO uc_product_attributes (nid, aid, label, ordering, default_option, required, display) SELECT %d, aid, label, ordering, %d, required, display FROM {uc_attributes} WHERE aid = %d", $node->nid, $oid, $aid));
+				}
+				break;
+			}
+	}
 }
\ No newline at end of file
