This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/product/classes/Model/Product/Category.php
2013-10-10 13:44:53 +11:00

56 lines
1.4 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports OSB listing products by category.
*
* @package Product
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Product_Category extends ORM_OSB {
protected $_table_name = 'product_cat';
protected $_has_many = array(
'product_category_translate'=>array('foreign_key'=>'product_cat_id','far_key'=>'id'),
);
protected $_sorting = array(
'name'=>'asc',
);
public function description() {
// If the user is not logged in, show the site default language
// @todo This needs to change to the session language.
if (! $ao=Auth::instance()->get_user())
$ao=Company::instance()->so();
return ($x=$this->product_category_translate->where('language_id','=',$ao->language_id)->find()->description) ? $x : _('No Description');
}
/**
* List all the products belonging to this cateogry
* @todo Consider if we should cache this
*/
public function products() {
$result = array();
foreach (ORM::factory('Product')->where_active()->find_all() as $po)
if (in_array($this->id,$po->categories()))
array_push($result,$po);
return $result;
}
public function list_bylistgroup($cat) {
$result = array();
foreach ($this->where('list_group','=',$cat)->find_all() as $pco)
$result[$pco->id] = $pco;
return $result;
}
}
?>