Update product category view to include default price_display configured by category
This commit is contained in:
parent
f08215717c
commit
3fa1ca3665
@ -16,6 +16,7 @@ return array
|
||||
'ajax'=>FALSE, // AJAX actions can only be run by ajax calls if set to FALSE
|
||||
'etag'=>FALSE, // Force generating ETAGS
|
||||
'invoice'=>0, // Number of invoices to generate in a pass
|
||||
'show_inactive'=>FALSE, // Show Inactive Items
|
||||
'task_sim'=>FALSE, // Simulate running tasks
|
||||
);
|
||||
?>
|
||||
|
@ -39,7 +39,7 @@ class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
|
||||
*/
|
||||
public function action_list() {
|
||||
if ($this->request->param('id'))
|
||||
$prods = ORM::factory('Product')->list_category($this->request->param('id'),FALSE);
|
||||
$prods = ORM::factory('Product_Category',$this->request->param('id'))->products();
|
||||
else
|
||||
$prods = ORM::factory('Product')->order_by('status DESC,prod_plugin_file')->find_all();
|
||||
|
||||
|
@ -36,30 +36,33 @@ class Controller_Product extends Controller_TemplateDefault {
|
||||
* @todo Obey sort order
|
||||
*/
|
||||
public function action_category() {
|
||||
$id = $this->request->param('id');
|
||||
$output = '';
|
||||
|
||||
$cat = ORM::factory('Product_Category',$id);
|
||||
$pco = ORM::factory('Product_Category',$this->request->param('id'));
|
||||
|
||||
if (! $cat->loaded())
|
||||
if (! $pco->loaded())
|
||||
HTTP::redirect('welcome/index');
|
||||
|
||||
BreadCrumb::name($this->request->uri(),$cat->name);
|
||||
if (! $pco->status AND ! Kohana::$config->load('debug')->show_inactive)
|
||||
HTTP::redirect('welcome/index');
|
||||
|
||||
BreadCrumb::name($this->request->uri(),$pco->name);
|
||||
BreadCrumb::url('product','product/categorys');
|
||||
BreadCrumb::url('product/category','product/categorys');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
|
||||
'body'=>View::factory($this->viewpath().'/view')
|
||||
->set('results',$this->_get_category($cat->id))
|
||||
->set('cat',$cat->id),
|
||||
));
|
||||
}
|
||||
foreach ($pco->products() as $po)
|
||||
$output .= View::factory($this->viewpath().'/list_item')
|
||||
->set('co',$pco)
|
||||
->set('o',$po);
|
||||
|
||||
/**
|
||||
* Obtain a list of pages in a category
|
||||
*/
|
||||
private function _get_category($id) {
|
||||
return ORM::factory('Product')->list_category($id);
|
||||
// If our output is blank, then there are no products
|
||||
if (! $output)
|
||||
$output = _('Sorry, no pages were found in this category, or your account is not authorized for this category.');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('Category'),$pco->name),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -81,7 +84,7 @@ class Controller_Product extends Controller_TemplateDefault {
|
||||
$co = ORM::factory('Product_Category',$_GET['cid']);
|
||||
|
||||
// If the product category doesnt exist, or doesnt match the product
|
||||
if (! $co->loaded() OR ! in_array($co->id,unserialize($po->avail_category)))
|
||||
if (! $co->loaded() OR ! in_array($co->id,$po->avail_category))
|
||||
HTTP::redirect('Product_Category/index');
|
||||
|
||||
BreadCrumb::name('product/view',$co->name);
|
||||
|
@ -43,9 +43,48 @@ class Model_Product extends ORM_OSB {
|
||||
|
||||
// Our attributes that are arrays, we'll convert/unconvert them
|
||||
protected $_serialize_column = array(
|
||||
'avail_category',
|
||||
'price_group',
|
||||
);
|
||||
|
||||
/**
|
||||
* Which categories is this product available in
|
||||
*/
|
||||
public function categories() {
|
||||
return $this->avail_category;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product description, after translating
|
||||
* @todo This needs to be improved to find the right language item.
|
||||
*/
|
||||
public function description_long() {
|
||||
return $this->product_translate->find()->display('description_full');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product description, after translating
|
||||
* @todo This needs to be improved to find the right language item.
|
||||
*/
|
||||
public function description_short() {
|
||||
return $this->product_translate->find()->display('description_short');
|
||||
}
|
||||
|
||||
/**
|
||||
* This will render the product feature summary information
|
||||
*/
|
||||
public function feature_summary() {
|
||||
return (is_null($plugin = $this->plugin())) ? HTML::nbsp('') : $plugin->feature_summary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product name, after translating
|
||||
* @todo This needs to be improved to find the right language item.
|
||||
*/
|
||||
public function name() {
|
||||
return $this->product_translate->find()->display('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object of the product plugin
|
||||
*/
|
||||
@ -59,21 +98,6 @@ class Model_Product extends ORM_OSB {
|
||||
return ORM::factory(sprintf('Product_Plugin_%s',$this->prod_plugin_file),$this->prod_plugin_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the product name, after translating
|
||||
* @todo This needs to be improved to find the right language item.
|
||||
*/
|
||||
public function name() {
|
||||
return $this->product_translate->find()->display('name');
|
||||
}
|
||||
|
||||
/**
|
||||
* This will render the product feature summary information
|
||||
*/
|
||||
public function feature_summary() {
|
||||
return (is_null($plugin = $this->plugin())) ? HTML::nbsp('') : $plugin->feature_summary();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the best price to the uesr based on the users group's memberships
|
||||
* @todo This needs to be tested with more than one price group enabled
|
||||
@ -190,28 +214,13 @@ class Model_Product extends ORM_OSB {
|
||||
/**
|
||||
* Return the price for the particle group and price option for the period
|
||||
*/
|
||||
public function price($grp,$period,$option) {
|
||||
public function price($grp,$period,$option,$taxed=FALSE) {
|
||||
$x = $this->keyget('price_group',$period);
|
||||
|
||||
return isset($x[$grp][$option]) ? $x[$grp][$option] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the products for a given category
|
||||
* @todo This shouldnt be here.
|
||||
*/
|
||||
public function list_category($cat,$active=TRUE) {
|
||||
$results = array();
|
||||
|
||||
$cats = $active ? $this->_where_active() : $this;
|
||||
|
||||
foreach ($cats->find_all() as $po) {
|
||||
if ($c = unserialize($po->avail_category) AND in_array($cat,$c))
|
||||
array_push($results,$po);
|
||||
}
|
||||
|
||||
Sort::MAsort($results,'position,price_base');
|
||||
return $results;
|
||||
if (isset($x[$grp][$option]))
|
||||
return $taxed ? Tax::add($x[$grp][$option]) : $x[$grp][$option];
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -30,6 +30,20 @@ class Model_Product_Category extends ORM_OSB {
|
||||
return ($a=$this->product_category_translate->where('language_id','=',$ao->language_id)->find()->description) ? $a : _('No Description');
|
||||
}
|
||||
|
||||
/**
|
||||
* List all the products belonging to this cateogry
|
||||
* @todo Consider if we should cache this
|
||||
*/
|
||||
public function products() {
|
||||
$return = array();
|
||||
|
||||
foreach (ORM::factory('Product')->where_active()->find_all() as $po)
|
||||
if (in_array($this->id,$po->categories()))
|
||||
array_push($return,$po);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
public function list_bylistgroup($cat) {
|
||||
$result = array();
|
||||
|
||||
|
8
modules/product/views/product/category/list_item.php
Normal file
8
modules/product/views/product/category/list_item.php
Normal file
@ -0,0 +1,8 @@
|
||||
<table class="product-list-item">
|
||||
<tr class="head">
|
||||
<td class="heading"><a href="<?php echo URL::site(sprintf('product/view/%s?cid=%s',$o->id,$co->id));?>"><?php echo $o->name(); ?></a> (<?php echo Currency::display($o->price(0,$co->recur_price_display,'price_base',TRUE)); ?>)</td>
|
||||
</tr>
|
||||
<tr class="body">
|
||||
<td><?php echo $o->description_short(); ?></td>
|
||||
</tr>
|
||||
</table>
|
Reference in New Issue
Block a user