is_flagged($nid)) { return TRUE; } } /** * Implementation of hook_uc_form_alter(). * * Remove the 'Add to cart' button and attribute selection when they are not relevant. */ function uc_notforsale_uc_form_alter(&$form, &$form_state, $form_id) { if ($form_id == 'uc_product_add_to_cart_form' || $form_id == 'uc_catalog_buy_it_now_form') { $nid = $form['nid']['#value']; if (_uc_notforsale_isnotforsale($nid)) { unset($form['submit']); if (isset($form['attributes'])) { unset($form['attributes']); } } } } /** * Implementation of hook_uc_price_handler(). * * Provide the means to remove the price from display. */ function uc_notforsale_uc_price_handler() { $items['alter'] = array( 'title' => t('Not for sale handler'), 'description' => t('Removes the price for products not for sale.'), 'callback' => 'uc_notforsale_price_handler_alter', ); $items['format'] = array( 'title' => t('Not for sale price handler'), 'description' => t('Removes the price for NULL prices. This is a filthy hack AND UC CORE NEEDS FIXING!'), 'callback' => 'uc_notforsale_price_handler_format', ); return $items; } /** * Price handler alterer callback. * * Sets the price to zero if the product is not for sale. * This is part of a hack: see the formatter below. * Ideally the price would be suppressable but it is not. */ function uc_notforsale_price_handler_alter(&$price, &$context, &$options) { //dsm($price); //dsm($context); //dsm($options); if (isset($context['subject']) && isset($context['subject']['node']) && $context['type'] != 'order_product') { if (_uc_notforsale_isnotforsale($context['subject']['node']->nid)) { //dsm('not for sale'); $price['price'] = NULL; $options['label'] = FALSE; } } } /** * Price handler formatter callback. * * This is a dirty hack to prevent a 0 price showing. * It calls the default formatter, but the need for a formatter just to stop a * 0 showing prevents you from using a different handler. * @see http://drupal.org/node/356919 * and if this bugs you please help get this fixed in UC Core! */ function uc_notforsale_price_handler_format($price, $options) { //dsm('null formatter' . $price); //dsm($options); // $price is already zero here and not NULL!?? WTF? if ($price) { return uc_store_price_handler_format($price, $options); } // Some special handling for zero cases. // Filthy filthy hack for shipping costs. // These *should* be shown if they are zero. // We have to check for the incoming path because we have no context here! // @see http://drupal.org/node/821528 if ($_GET['q'] == 'cart/checkout/shipping/quote') { return uc_store_price_handler_format(0, $options); } } /** * Implementation of hook_add_to_cart(). * * Prevent an item being added to the cart. */ function uc_notforsale_add_to_cart($nid, $qty, $data) { if (_uc_notforsale_isnotforsale($nid)) { $result[] = array('success' => FALSE); return $result; } } /** * Implementation of flag_default_flags(). * * Define our built-in flag: 'notforsale'. */ function uc_notforsale_flag_default_flags() { $flags = array(); // Exported flag: "Not for sale". $flags[] = array ( 'content_type' => 'node', 'name' => 'notforsale', 'title' => 'Not for sale', 'global' => true, 'types' => array ( 0 => 'product', ), 'flag_short' => 'Remove from sale', 'flag_long' => '', 'flag_message' => 'This product is no longer available in the store.', 'unflag_short' => 'Make available for sale', 'unflag_long' => '', 'unflag_message' => 'This product is now available in the store.', 'unflag_denied_text' => '', 'link_type' => 'toggle', 'roles' => array ( 'flag' => array ( 0 => '2', ), 'unflag' => array ( 0 => '2', ), ), 'show_on_page' => false, 'show_on_teaser' => false, 'show_on_form' => true, 'access_author' => '', 'i18n' => 0, 'status' => false, 'locked' => array ( 'name' => 'name', 'global' => 'global', 'status' => 'status', ), 'module' => 'uc_notforsale', 'api_version' => 2, ); return $flags; }