From 3fa1ca3665a97cee7592648b817e067e96ed11f1 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 11 Jan 2013 13:33:57 +1100 Subject: [PATCH] Update product category view to include default price_display configured by category --- application/config/debug.php | 1 + .../classes/Controller/Admin/Product.php | 2 +- .../product/classes/Controller/Product.php | 37 +++++---- modules/product/classes/Model/Product.php | 79 +++++++++++-------- .../classes/Model/Product/Category.php | 14 ++++ .../views/product/category/list_item.php | 8 ++ 6 files changed, 88 insertions(+), 53 deletions(-) create mode 100644 modules/product/views/product/category/list_item.php diff --git a/application/config/debug.php b/application/config/debug.php index ac2fed04..db6ffbf0 100644 --- a/application/config/debug.php +++ b/application/config/debug.php @@ -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 ); ?> diff --git a/modules/product/classes/Controller/Admin/Product.php b/modules/product/classes/Controller/Admin/Product.php index fc64aa76..14c6646d 100644 --- a/modules/product/classes/Controller/Admin/Product.php +++ b/modules/product/classes/Controller/Admin/Product.php @@ -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(); diff --git a/modules/product/classes/Controller/Product.php b/modules/product/classes/Controller/Product.php index 1bbd7519..463f9ea8 100644 --- a/modules/product/classes/Controller/Product.php +++ b/modules/product/classes/Controller/Product.php @@ -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); diff --git a/modules/product/classes/Model/Product.php b/modules/product/classes/Model/Product.php index c7e4ba4c..1ff381ee 100644 --- a/modules/product/classes/Model/Product.php +++ b/modules/product/classes/Model/Product.php @@ -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; } } ?> diff --git a/modules/product/classes/Model/Product/Category.php b/modules/product/classes/Model/Product/Category.php index b266b426..4d8a0165 100644 --- a/modules/product/classes/Model/Product/Category.php +++ b/modules/product/classes/Model/Product/Category.php @@ -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(); diff --git a/modules/product/views/product/category/list_item.php b/modules/product/views/product/category/list_item.php new file mode 100644 index 00000000..fdf8fcd8 --- /dev/null +++ b/modules/product/views/product/category/list_item.php @@ -0,0 +1,8 @@ + + + + + + + +
name(); ?> (price(0,$co->recur_price_display,'price_base',TRUE)); ?>)
description_short(); ?>