Accept Credits as payment for only certain products?
ck9 - June 28, 2009 - 15:50
| Project: | Ubercart Userpoints |
| Version: | 6.x-2.x-dev |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
I have a range of products but wish to allow Credits as payment for only one of them. Is this possible?

#1
everything is possible :)
but not out of the box :(
what i would do to achieve this:
first you need to make sure you will not get mixed carts. if ppl put in allowed and not allowed products for your desired payment you will be in trouble at the check out. you can use hook_add_to_cart. check whats already in the cart and the disallow or allow putting the product into the cart.
now all you need to do is another hook when the payment options will be displayed. again, check whats in the cart and display only the payment option that you want. the hook you need is hook_form_alter.
you find details to the hooks at http://api.ubercart.org
#2
as i just did almost the same, here a little more help.
check if a product with a certain nodeID is already in the cart:
function nid_is_in_cart($nid){$items = uc_cart_get_contents();
foreach($items as $item) {
if(in_array($nid,get_object_vars($item))) {
return TRUE;
}else{
return FALSE;
}
}
}
hook_add_to_cart:
in my cases there are two nodes in the shop that should not be in the cart at the same time. node 1 and 9. you can check for more options if you load the node object and check for anything in the node array.
function customize_add_to_cart($nid, $qty, $data) {if (($nid == 1 && nid_is_in_cart(9))||($nid == 9 && nid_is_in_cart(1))) {
$result[] = array(
'success' => FALSE,
'message' => t('whatever you want to write here'),
);
}
return $result;
}