Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
I've added a simple "add_to_cart" operation for uc_views_bulk_operations.
Patch is attached.
Comment | File | Size | Author |
---|---|---|---|
uc_views_bulk_operations_add_cart.patch | 1.07 KB | RazvanRanca |
Comments
Comment #1
longwaveCommitted to CVS, but using hook_action_info() rather than hook_node_operations().
Comment #3
goose2000 CreditAttribution: goose2000 commentedHi,
I was wondering if this operation is included in the latest dev version?
EDIT, yes it is showing up for me, ignore...
Comment #4
amorsent CreditAttribution: amorsent commentedIt seems to me that the shippable flag does not properly get set.
The following variation seems to work for me.
/**
* "Add to cart" node action.
*/
function uc_views_bulk_operations_add_to_cart_action($node) {
$data = array('module' => 'uc_product', 'shippable' => $node->shippable);
uc_cart_add_item($node->nid, 1, $data);
}
Comment #5
amorsent CreditAttribution: amorsent commentedAs I noted in my last comment, the shippable flag is the most noticeable deficiency here ( you will know it's missing when the checkout form skips the shipping info pane ). However, the main issue is that hook_add_to_cart_data is not fired.
Modules may expect to use this hook to attach additional data to the cart item. There are 2 implementations in ubercart itself.
uc_product_add_to_cart_data sets the shippable flag.
uc_attribute_add_to_cart_data handles the product's attributes.
Take a look at the buy it now button's submit function and note how uc_cart_add_item is called.
To properly build the $data argument for uc_cart_add_item we need to call hook_add_to_cart_data.
At the bare minimum we'll also need to fake a $form_state with the nid
Alternately, we could drupal_execute the buy it now form. This would have the advantage of allowing other modules their form_alter opportunity. This may be vital for the attributes module, I'm not sure. At any rate, I think that woud look something like this: