Hi,

I would like to ask you how I could display discounted prices along with items with catalog. I have a page like this one http://demo.ubercart.org/catalog/uberthreads but I am not able to display the discounted price.

I assume that I have to modify function phptemplate_uc_catalog_product_grid (I display products in a Grid layout). However, I don't know which variable contains the discounted price. I have already tried Devel modul.

So, how can I get a discounted price in function phptemplate_uc_catalog_product_grid? Thank you.

Comments

miguel_angel’s picture

This solution is working on my website:
(Place it at template.php of your theme)
(For uc 2.4 and uc_discounts_alt 6.x-2.x-dev)

/**
 * Display a list of products in grid format().
 *
 * Override theme_uc_catalog_product_grid function from uc_catalog module
 * @ingroup themeable
 */
function phptemplate_uc_catalog_product_grid($products) {
  $product_table = '<div class="category-grid-products"><table>';
  $count = 0;
  $context = array(
    'revision' => 'themed',
    'type' => 'product',
  );
  foreach ($products as $nid) {
    $product = node_load($nid);
    $context['subject'] = array('node' => $product);

    if ($count == 0) {
      $product_table .= "<tr>";
    }
    elseif ($count % variable_get('uc_catalog_grid_display_width', 3) == 0) {
      $product_table .= "</tr><tr>";
    }

    $titlelink = l($product->title, "node/$nid", array('html' => TRUE));
    if (module_exists('imagecache') && ($field = variable_get('uc_image_'. $product->type, '')) && isset($product->$field) && file_exists($product->{$field}[0]['filepath'])) {
      $imagelink = l(theme('imagecache', 'product_list', $product->{$field}[0]['filepath'], $product->title, $product->title), "node/$nid", array('html' => TRUE));
    }
    else {
      $imagelink = '';
    }

    $product_table .= '<td>';
    if (variable_get('uc_catalog_grid_display_title', TRUE)) {
      $product_table .= '<span class="catalog-grid-title">'. $titlelink .'</span>';
    }
    if (variable_get('uc_catalog_grid_display_model', TRUE)) {
      $product_table .= '<span class="catalog-grid-ref">'. $product->model .'</span>';
    }
    $product_table .= '<span class="catalog-grid-image">'. $imagelink .'</span>';
    if (module_exists('uc_discounts')) {
    	$discounted_price = theme("get_discounted_price", $product);
    	if (!is_null($discounted_price) && $product->sell_price > $discounted_price) {
    		if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
      		$product_table .= '<p class="original-sell-price">'. uc_price($product->sell_price, $context) .'</p>';
    		}
    		$product_table .= '<span class="field-type-discounted-price">'. theme("product_discounted_price", $product, uc_price($discounted_price, $context)) .'</span>';
			}
			else {
    		if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
      		$product_table .= '<span class="catalog-grid-sell-price">'. uc_price($product->sell_price, $context) .'</span>';
    		}
			}
			theme("add_product_price_altering_css", $product);
			theme("add_product_price_altering_javascript", $product);
		}
		else {
   		if (variable_get('uc_catalog_grid_display_sell_price', TRUE)) {
     		$product_table .= '<span class="catalog-grid-sell-price">'. uc_price($product->sell_price, $context) .'</span>';
   		}
		}

    if (module_exists('uc_cart') && variable_get('uc_catalog_grid_display_add_to_cart', TRUE)) {
      if (variable_get('uc_catalog_grid_display_attributes', TRUE)) {
        $product_table .= theme('uc_product_add_to_cart', $product);
      }
      else {
        $product_table .= drupal_get_form('uc_catalog_buy_it_now_form_'. $product->nid, $product);
      }
    }
    $product_table .= '</td>';

    $count++;
  }
  $product_table .= "</tr></table></div>";
  return $product_table;
}
mandreato’s picture

...and don't forget to clear the cached data from Site configuration -> Performance ;-)
Thank you !

jrust’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

joshfromdallas’s picture

I was using this, but when I upgraded to UC Discounts 2.2 it seems to not work anymore? Did something change?