2

In ubercart,While buyer sees a product and clicks on add-to-cart button for buying that product, i want to know which action is responsible for that product being added in to the cart?

I want to edit the sell price, so that only this question. Already tried this hook, but it was not printing anything,

    mymodulename_uc_add_to_cart($nid, $qty, $data) {
    print "<pre>";print_r($data);print "</pre>";exit;

    if ($qty > 1) {
        $result[] = array(
                'success' => FALSE,
                'message' => t('Sorry, you can only add one of those at a time.'),
        );
    }
    return $result;
}

Which of these hooks

hook_uc_add_to_cart
hook_uc_add_to_cart_data
hook_uc_cart_checkout_start
hook_uc_cart_display
hook_uc_cart_item_delete
hook_uc_cart_item_insert
hook_uc_cart_item_presave
hook_uc_cart_item_update
hook_uc_cart_pane
hook_uc_cart_pane_alter
hook_uc_checkout_complete
hook_uc_checkout_pane
hook_uc_checkout_pane_alter
hook_uc_update_cart_item
uc_checkout_pane_callback

is responsible for adding quantity and price to cart in the cart page.Or is there any other hook which is doing it ?

Any ideas? Thanks in advance

2

If you want to alter the cart item, then you can use hook_uc_cart_alter of ubercart.

This hook is not in documentation of ubercart 7 but its still working for Ubercart 7.

This is called every time the cart is rebuild (e.g. when products are added), so it's a good place to alter the cart item.

I have checked uc_coupon module and hook hook_uc_cart_alter is implemented into that module. So, you can try this hook.

Edit: Code snippets to modify the price of item

/**
 * Implements uc_cart_alter.
 */
function mymodule_uc_cart_alter(&$items ) {

  foreach ($items as $index => $item) {

   //you can add condition for your bid product

    $items[$index]->price = 100;
  }
}

For reference:

http://www.ubercart.org/docs/api/hook_uc_cart_alter

  • I am not using uc_coupon. Before product is added to cart page(if i click on add-to-cart button), i want to alter the sell price of tat product ? is tat possible using hook_uc_cart_alter? If so how? – Ram Nov 18 '13 at 5:16
  • @Ram, Yes, its possible to alter sell price of the product. I only mentioned uc_coupon module, so you know that this hook is working in other contrib module. – Jayendra Kainthola Nov 18 '13 at 5:18
  • Let me try hook_uc_cart_alter – Ram Nov 18 '13 at 5:19
  • on clicking on add-to-cart button in hook_uc_cart_alter, it doesn't have currently added product in the order object. $order = new UcOrder(); $order->products = $items; $order->data = array(); print "<pre>"; print_r($order);exit; print "</pre>"; – Ram Nov 18 '13 at 10:03
  • @Ram, hook_uc_cart_alter will allow you to alter the item of cart content. $order will automatically fetch the updated cart item by hook_uc_cart_alter. – Jayendra Kainthola Nov 18 '13 at 10:08
0

with little googling I found this,might be what you are looking for

core add to functionality is handled by

uc_cart_add_item($nid, $qty = 1, $data = NULL, $cid = NULL, $msg = TRUE, $check_redirect = TRUE, $rebuild = TRUE)

reference

http://api.ubercart.me/api/drupal/ubercart!uc_cart!uc_cart.module/function/uc_cart_add_item/7

But if you are looking for a hook which allows you to penetrate your codes,

hook_uc_add_to_cart($nid, $qty, $data)

reference

http://api.ubercart.me/api/drupal/ubercart!uc_cart!uc_cart.api.php/function/hook_uc_add_to_cart/7

Also check the following links for more info about different API's

http://api.ubercart.me/api/drupal/ubercart!uc_cart!uc_cart.api.php/7

http://api.ubercart.me/api/drupal/functions/7

Updates:

Checkout already being discussed thread for custom alteration of prices here.

  • Tried all those and i can't find which one is the 'ONE'.Also tried hook_uc_add_to_cart and it didnt help. – Ram Nov 12 '13 at 10:22
  • can you make sure if there is any cache issue – arpitr Nov 12 '13 at 10:35
  • Already tried clearing cache stil no success. – Ram Nov 12 '13 at 10:36
  • @ram just to make sure if you have missed replacing hook with your module name, I am suggesting as your sample code does not reflect so – arpitr Nov 12 '13 at 10:40
  • That's an example.In the code i have my module name only. – Ram Nov 12 '13 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.