3 replies [Last post]
fsiddiqi's picture
Offline
Joined: 01/02/2008
Juice: 22
Was this information Helpful?

Not all items in our product catalog are orderable online, so I'm looking for a way to turn off the "add to cart" form on a per-product basis.

I looked in the documentation and configuration, but it wasn't apparent to me if there was an existing way to do this.

I was going to write a custom hook_form_alter function to handle, but thought it was a good idea to ask about this first.

Thanks

Faisal

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Switch off ordering by product

I did this on our site but it took a little bit of work, using Contemplate and Views - and CCK. Using CCK, I created a select list (drop down) called "Available" and the two choices were:

Available|Y
Coming Soon|N

<?php
if ($node->field_available[0]['value'] == "N") {
?>

<img src="/<?php echo path_to_theme(); ?>/images/add-cart-detail-soon.gif">

<?php
} else { 
?>

<a href="/cart/add/p<?php print $node->nid; ?>_q1?destination=cart"><img src="/<?php echo path_to_theme(); ?>/images/Product_Purchase_Button_Add.jpg" border="0"></a>

<?php
}
?>

So briefly, I created an Add to Cart image for the button, and another image for "Coming Soon!" And then in my Product template, it checks the value of that CCK field, and if it's "N" it shows the Coming Soon image. Any other values will show the Buy Now button (made using an image and Cart Links API).. which means if a product isn't for sale yet, you'll need to remember to specifically select "Coming soon" when you're creating it.

The same process was done for our Catalog Views, editing the tpl file directly, but in the same exact manner. Hope this helps.

You'll also need to include the code that I wrote here: http://www.ubercart.org/forum/ideas_and_suggestions/1415/able_purchase_v...

That will prevent a user from plugging values into a Cart Link, despite them not being able to use a Buy Now button.

One day I will make this a proper Contrib, as you can see it was done quite some time ago Smiling

--
Help directly fund development: Donate via PayPal!

fsiddiqi's picture
Offline
Joined: 01/02/2008
Juice: 22
Re: Re: Switch off ordering by product

Thanks - that got me started.

I added a CCK field to the product content type called "Orderable Online". Then added a custom hook_form_alter to clear out the add to cart form for appropriate items.

Seems to work.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Switch off ordering by product

Looking back, that's probably how I would've done it too. Glad you found a better solution! Smiling Of course if you were to use cart links then my solution would still work, (having to check the CCK field's values).

Wouldn't mind having this option in core, instead of relying on CCK Eye-wink

--
Help directly fund development: Donate via PayPal!