Download & Extend

storing the originating domain when an product is added to the cart

Project:Ubercart Domain Access
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

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

Comments

#1

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

#2

Thanks, indeed, this simple code did the trick

<?php
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 :
<?php
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

AttachmentSize
uc_domain_advanced.zip 1.81 KB