Hello,
For the moment, Ubercart Domain Access stores the originating domain when an order is made.
I've some domains, sharings some products, and I let users sharing their shopping cart between domain. So, a user can begin his shopping on a domain by adding some produts to its cart, go to another domain, continue his shopping and ordering on this last domain.
The problem is that I would like to know from wich domain each product of the order was added to the cart, so I could perform better statistics between my domains.
I'm going to start working on it, so if someone can show me the way, it would be a great gain of time.

Thanks

CommentFileSizeAuthor
#2 uc_domain_advanced.zip1.81 KBAnonymous (not verified)

Comments

longwave’s picture

You should be able to do this fairly easily with hook_add_to_cart_data.

Anonymous’s picture

StatusFileSize
new1.81 KB

Thanks, indeed, this simple code did the trick

function uc_domain_advanced_add_to_cart_data($form_values) {
	global $_domain;
	return array('domain_id' => $_domain['domain_id']);
}

The thing a little difficult thant I wanted to do is to save the domain_id in a différent table (it's not very fast to perfom statistics on a serialized value in the data variable)
So I added this code :

function uc_domain_advanced_order($op, &$arg1, $arg2) {
  global $_domain;
  switch ($op) {
    case 'save':
	  $order_product_req = db_query("SELECT order_product_id, nid, data FROM {uc_order_products} WHERE order_id = %d",$arg1->order_id);
	  if($order_product_row = db_fetch_object($order_product_req)){
		do{
			if(db_result(db_query("SELECT count(*) FROM {uc_domain_order_products} WHERE order_product_id = %d",$order_product_row->order_product_id)) == 0){
				$data = unserialize($order_product_row->data);
				if(isset($data["domain_id"])){$domain_id = $data["domain_id"];}
				elseif(isset($arg1->domain_id)){$domain_id = $arg1->domain_id;}
				else{$domain_id = $_domain['domain_id'];}
				db_query("INSERT INTO {uc_domain_order_products} (order_product_id,domain_id) VALUES (%d,%d)", $order_product_row->order_product_id, $domain_id);
			}
		}
		while($order_product_row = db_fetch_object($order_product_req));
	  }
      break;
  }
}

P.S Sorry for not always following drupal coding standart