Hi all.

Can views be used to have Call for price instead of sale price showing, and for the add to cart button to disable if say the list price has a set number in the box?

Comments

madsph’s picture

You can change any of the default views that ships with uc_views using the Views_ui (admin/build/views), e.g. for showing other fields than sell price.

To add a button with the requested functionality would require that you make your own field and a custom handler, I don't think it would be that hard to do. The files uc_product_handler_field_addtocart.inc and uc_product.views.inc in ubercart\uc_product\views should get you off to a good start.

If such a button was to be added to the uc_views module, I would have to get an idea of what your usecase for it is, since I can't figure out why you would promote a product through a view that sometimes offers to add it to the cart and sometimes not. Can you elaborate on what you are trying to achieve?

GavinC’s picture

@madsph:

Thank you for your reply.

Basically I have a product of which the price will change on a day-2-day basis as it is a gold product.

What I want to be able to do is have the product listed as normal, but have 'Call for Price' or something like that in stead of the Sell Price. And therefore would require that the button be disabled so people cannot add a product to cart that has no sell price attached.

I hope that kinda clears it up a little.

madsph’s picture

Ahh, that makes sense.

Just out of curiosity, how do you sell product from your site if you can't assign a price? Have you made some kind of module to handle that?

Are all your products like this, or do you have products with an assigned price. If all products are like this, you could modify the view by removing the button and the sell price all together.

Another way could be to leave the gold product out using a filter - which of cause would have the downside that the gold product does not get promoted by the view.

Yes, if you think I am looking for excuses to go around the problem rather than solving it, you are right ;-)
After looking into the problem, I think it might be a bit more difficult than my initial response. I am sure that it can be done though.

GavinC’s picture

It will only be the odd one or two products that will be like that.

Unfortunately I have no module that does this yet, although I think I will look into how this is done.

Thank you for having a look into it. Most greatful

domesticat’s picture

@madsph, I can give you an example of a use case for why we'd want to list items but not actually sell them

I'm working on a site for the fundraising arm of my county's library system. While there are items that are small and easy to purchase, like sponsoring a book purchase in someone's memory, we'd also like to make it clear that there are bigger-ticket items that can be negotiated on a per-case basis, such as sponsoring an event. Our donors should be aware of the option when browsing the donation options, but we want to plan out the donation with them before a check is actually signed.

madsph’s picture

@domesticat

I realize that there is a need for this. But I can't figure out which options should be made available for controlling the toggling of the 'add to cart' button, if I were to make a custom handler for this.

Price == 0 is one of course, but I don't think that is general enough to make it into a standard handler of a module.
php code is another, but also a little dangerous and not so user friendly.

GavinC’s picture

Could the disabling of the Add to Cart button be triggered if 'List Price' was to = and particular figure? say 99999.99?

madsph’s picture

Okay, you managed to intrigue me :-D

So I went ahead and made a new field handler for uc_products, similar to the current buy-it-now button, only you can add a condition for the sell price to be met if the button must be shown.

The handler is in the 2.1 release branch, so if you need it you must check out the nightly build.

Have fun, and let me know if it works as requested.

madsph’s picture

Assigned: Unassigned » madsph
Category: support » feature
Status: Active » Needs review
madsph’s picture

Version: 6.x-1.x-dev » 6.x-2.0
madsph’s picture

Status: Needs review » Closed (fixed)
dean.p’s picture

Hi, I found this can quite easily be done with a cck field and theme function.

I created a single check box "field_product_offline" which is off by default. Clicking on gives is a value of 1. I added some help text to describe it's function.

Then, in my template.php if have the following function:

function yourtheme_uc_product_add_to_cart($node, $teaser = 0, $page = 0) {
	if (!empty($node->field_product_offline[0][value])) {
		$output = '<div class="offline-message"><p>some offline text</p></div>'; // some offline text or something
	} else {
 		$output = '<div class="add-to-cart">';
 			if ($node->nid) {
    			$output .= drupal_get_form('uc_product_add_to_cart_form_'. $node->nid, $node);
  			} else {
    			$output .= drupal_get_form('uc_product_add_to_cart_form', $node);
  			}
		$output .= '</div>';
	} 
  return $output;
}

Seems to work a charm. Obviously I could add another field for dynamic offline message.

Using Drupal 6.10 and Ubercart 2

dean.p’s picture

Actually, I forgot to mention the "field_product_offline" field was added to the Product content type ;)

ahimsauzi’s picture

So I went ahead and made a new field handler for uc_products, similar to the current buy-it-now button

Hi msdsph,

I am trying to create a custom form to add product into the cart and direct buyers into the checkout. Can you point me in the right direction on how to go about creating a theme version of uc_product_handler_field_buyitnow?

Thanks

madsph’s picture

I am not sure what you are trying to do - do you want to alter the navigation such that adding a product to the cart, redirect the user to the cart where the new product is present?

If so, I don't think the theme is the right place to do it (but I am no great expert on theming).

I think what you need to do is add another submit hook through hook_form_alter.

I am not sure exactly how the code should look, but I made something similar once where I had to customize a search for users that ended up redirecting to a custom page I made. I think you should be able to get some inspiration from that:

 /**
  * Implementation of hook_form_alter().
  */
   function userfinder_form_alter(&$form, &$form_state, $form_id) {
     //This code gets called for every form Drupal build; use an if statement to
     //respond only to the vaious search forms.
     if ($form_id == 'search_block_form' || $form_id == 'search_form' || $form_id == 'search_theme_form') {
       //Redirect to our own usersearch by adding a new listner to the submit list
       $form['#submit'][] = 'userfinder_search_submit';
     }
   }

   function userfinder_search_submit($form, &$form_state) {
     $form_id = $form['form_id']['#value'];
     $args = trim($form_state['values'][$form_id]);
     if ($args && $args != '') {
       $form_state['redirect'] = 'search/userfinder/'. $args;
     }
   }

These lines of code is among my first 100 lines of Drupal code - so I can't guarantee that it is the 'right' way of doing it - but it worked :-)

ahimsauzi’s picture

Thanks I suspected that form_alter has something to do with it. I'll have to give it a try but right now I have uc_ajax_cart stuck in my module interface although it was uninstalled and removed!

alexJohnston’s picture

I have a site that is mostly for information purposes but is built around ubercart as two or three products are available for purchase (out of 100+ products). I need to completely remove the product-details element instead of displaying "call for price" or anything of the sort. Please help and thanks in advance!

madsph’s picture

Sorry for the late3 response - my time has been consumed by other projects lately.

I need a little more information to understand precisely what you are trying to do.

iantresman’s picture

Module "UC Price Visibility" seem to do this.