Jump to content

Need Help with Sort on Custom Quantity Discount Column


Dirty Butter

Recommended Posts

Sorry, but I tried unsuccessfully to find the original forum thread.

From my notes I'm assuming that Bsmither helped me add this code:

products.index.php

               <td align="center">{$product.stock_level}</td>
	       <!-- BSMITHER DISCOUNT IMAGE  rest of code in products.index.inc.php -->
	       <td align="center"><img src="{$STORE_URL}/{$SKIN_VARS.admin_folder}/skins/default/images/{if $product.discount}1{else}0{/if}.png" class="toggle" /></td>
               <td>
	       <!-- END BSMITHER DISCOUNT IMAGE -->
                  {if $product.updated == '0000-00-00 00:00:00'}
                  {$LANG.common.unknown}
                  {else}
                  {formatTime(strtotime($product.updated))}
                  {/if}
               </td>

And in products.index.inc.php

	$thead_sort = array (
		'status'   => $GLOBALS['db']->column_sort('status', $lang['common']['status'], 'sort', $current_page, $_GET['sort']),
		'digital'   => $GLOBALS['db']->column_sort('digital', $lang['common']['type'], 'sort', $current_page, $_GET['sort']),
		'image'   => $lang['catalogue']['title_image'],
		'name'    => $GLOBALS['db']->column_sort('name', $lang['catalogue']['product_name'], 'sort', $current_page, $_GET['sort']),
		'product_code'  => $GLOBALS['db']->column_sort('product_code', $lang['catalogue']['product_code'], 'sort', $current_page, $_GET['sort']),
		'price'   => $GLOBALS['db']->column_sort('price', $lang['common']['price'], 'sort', $current_page, $_GET['sort']),
		// BSMITHER EXTRA TABS 'stock_level' 	=> $lang['catalogue']['title_stock'],
		'sale_price' 	=> $GLOBALS['db']->column_sort('sale_price',$lang['common']['price_sale'],'sort',$current_page,$_GET['sort']),
		'stock_level' 	=> $GLOBALS['db']->column_sort('stock_level',$lang['catalogue']['title_stock'],'sort',$current_page,$_GET['sort']),
		'discount' => $GLOBALS['db']->column_sort('discount',$lang['catalogue']['title_discount_quantity'],'sort',$current_page,$_GET['sort']),	  	
		// BSMITHER END EXTRA TABS
		'updated'   => $GLOBALS['db']->column_sort('updated', $lang['catalogue']['title_last_updated'], 'sort', $current_page, $_GET['sort']),
		'translations'  => $lang['translate']['title_translations']
	);

also in products.index.inc.php

			$updated_time  = $result['updated'];
			$result['updated']  = $updated_time ? $updated_time : $lang['common']['unknown'];
		/* BSMITHER CHECK FOR QUANTITY DISCOUNTS rest of code is in products.index.php */
		  $quanDiscount = $GLOBALS['db']->count('CubeCart_pricing_quantity', 'product_id', array('product_id' => $result['product_id']));
		  $result['discount'] = ($quanDiscount) ? true : false;
		/* BSMITHER END CHECK FOR QUANTITY DISCOUNTS */
			$smarty_data['products'][] = $result;
		}

This code DOES create a column in the Product Summary listings for the Discount Code. It DOES create an empty box if there is no discount code and a checked box if there is a quantity discount.

But it's of no real use in 6.2+ as is, because the column will not sort.

Is this fixable? I know there is a GitHub entry having something to do with a sort of some column that's not working.

 

Link to comment
Share on other sites

I found my notes on doing something like this for if an item has an image, and the additional code needed to sort on whether this one or not.

But I have not found my notes on doing the same for whether or not the item has a Quantity Discount schedule.

Link to comment
Share on other sites

Well, it's the two images that would need to be sorted I guess. So maybe it is from the same discussion. The sort code " appears" to be there - and it did work at some point in the past - v5?. I kept putting off asking about it while dealing with more pressing code problems.

Link to comment
Share on other sites

There would have to be a lot more code to make this indicator sortable.

However, the indicator does not need to add a sorter to the query. The most it should accomplish is to filter the query. That is, "Show only those products that have a Quantity Discount schedule assigned."

That said, here are instructions to do that:

In products.index.inc.php, in the code following near line 1102:

} else {
	// List all products
	$GLOBALS['main']->addTabControl($lang['catalogue']['title_product_list'], 'general');

Find the statements and make the changes.

Find:

	foreach ($GLOBALS['hooks']->load('admin.product.table_head_sort') as $hook) include $hook;

Change to:

$thead_sort['discount'] = "QuanDisc";$thead_sort['discount_link'] = (isset($_GET['has_quan_discount'])) ? currentPage(array('has_quan_discount')) : currentPage(null,array('has_quan_discount' => "1")) ;
	foreach ($GLOBALS['hooks']->load('admin.product.table_head_sort') as $hook) include $hook;

Find:

	if (($where === false || strlen($where) > 0) && ($results = $GLOBALS['db']->select('CubeCart_inventory', false, $where, $_GET['sort'], $per_page, $page)) !== false) {
		$pagination = $GLOBALS['db']->pagination(false, $per_page, $page, 9);

Change to:

$quan_discounts_products = $GLOBALS['db']->select('CubeCart_pricing_quantity', array('DISTINCT' => 'product_id'));
if ($quan_discounts_products) { foreach ($quan_discounts_products as $prod) { $has_quan_discounts_products[$prod['product_id']] = $prod['product_id']; } }
if (isset($_GET['has_quan_discount']) && !empty($_GET['has_quan_discount'])) {
	if (!$where){ $where = ''; } else { $where .= ' AND '; } $where .= '(product_id IN (' . implode(",",$has_quan_discounts_products) . '))';
}
	if (($where === false || strlen($where) > 0) && ($results = $GLOBALS['db']->select('CubeCart_inventory', false, $where, $_GET['sort'], $per_page, $page)) !== false) {
		$pagination = $GLOBALS['db']->pagination(false, $per_page, $page, 9);

Find:

		foreach ($GLOBALS['hooks']->load('admin.product.products_list') as $hook) include $hook;
		$GLOBALS['smarty']->assign('PRODUCTS', $smarty_data['products']);
		$GLOBALS['smarty']->assign('PAGINATION', $pagination);

Change to:

foreach($smarty_data['products'] as &$result) {
	$result['has_quan_discount'] = (isset($has_quan_discounts_products[$result['product_id']])) ? true : false ;
}
		foreach ($GLOBALS['hooks']->load('admin.product.products_list') as $hook) include $hook;
		$GLOBALS['smarty']->assign('PRODUCTS', $smarty_data['products']);
		$GLOBALS['smarty']->assign('PAGINATION', $pagination);
In the admin skin template products.index.php, find:

               <th nowrap="nowrap">{$THEAD.stock_level}</th>
               <th nowrap="nowrap">{$THEAD.updated}</th>

Change to:

               <th nowrap="nowrap">{$THEAD.stock_level}</th>
<th nowrap="nowrap">{if $THEAD.discount_link}<a href="{$THEAD.discount_link}">{$THEAD.discount}</a>{else}{$THEAD.discount}{/if}</th>
               <th nowrap="nowrap">{$THEAD.updated}</th>


Find:

               <td align="center">{$product.stock_level}</td>
               <td>
                  {if $product.updated == '0000-00-00 00:00:00'}

Change to:

               <td align="center">{$product.stock_level}</td>
<td align="center"><img src="{$STORE_URL}/{$SKIN_VARS.admin_folder}/skins/default/images/{if $product.has_quan_discount}1{else}0{/if}.png" /></td>
               <td>
                  {if $product.updated == '0000-00-00 00:00:00'}

What you will now see is a column labeled QuanDisc. It is a link back to this page, but has a flag in the URL (the querystring) that will affect the filtering of the query. The WHERE component of the query will now look for records with specific product_id values - along with any other filtering choice made previously or to follow. The specific product_id values are those that have been identified as having records in the Quantity Discounts database table.

To switch off this particular filtering, click the link QuanDisc again.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...