OSB enhancements to date
This commit is contained in:
75
modules/product/classes/controller/product.php
Normal file
75
modules/product/classes/controller/product.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides product categories
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Page
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Product extends Controller_TemplateDefault {
|
||||
/**
|
||||
* Show the available topics in a category
|
||||
* @todo Only show categories according to their validity dates
|
||||
* @todo Obey sort order
|
||||
*/
|
||||
public function action_category($id) {
|
||||
$cat = ORM::factory('product_category',$id);
|
||||
|
||||
if (! $cat->loaded())
|
||||
Request::instance()->redirect('welcome/index');
|
||||
|
||||
Breadcrumb::name($this->request->uri(),$cat->name);
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
|
||||
'body'=>View::factory('product/category/view')
|
||||
->set('results',$this->_get_category($cat->id))
|
||||
->set('cat',$cat->id),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a list of pages in a category
|
||||
*/
|
||||
private function _get_category($id) {
|
||||
return ORM::factory('product')->category($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a product
|
||||
*/
|
||||
public function action_view($id) {
|
||||
$po = ORM::factory('product',$id);
|
||||
|
||||
if (! $po->loaded())
|
||||
Request::instance()->redirect('product_category/index');
|
||||
|
||||
Breadcrumb::name($this->request->uri(),$po->product_translate->find()->name);
|
||||
|
||||
// Work out our category id for the control line
|
||||
if (! empty($_GET['cid'])) {
|
||||
$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_id)))
|
||||
Request::instance()->redirect('product_category/index');
|
||||
|
||||
Breadcrumb::name('product/view',$co->name);
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>$po->product_translate->find()->description_short,
|
||||
'body'=>View::factory('product/view')
|
||||
->set('record',$po),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
}
|
||||
?>
|
38
modules/product/classes/controller/product/category.php
Normal file
38
modules/product/classes/controller/product/category.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides product categories
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Page
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Deon George
|
||||
* @license http://dev.leenooks.net/license.html
|
||||
*/
|
||||
class Controller_Product_Category extends Controller_TemplateDefault {
|
||||
/**
|
||||
* By default show a menu of available categories
|
||||
*/
|
||||
public function action_index() {
|
||||
Block::add(array(
|
||||
'title'=>_('Product Categories'),
|
||||
'body'=>View::factory('product/category/list')
|
||||
->set('results',$this->_get_categories()),
|
||||
));
|
||||
|
||||
$this->template->content = Block::factory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain a list of our categories
|
||||
* @todo Only show categories according to the users group memeberhsip
|
||||
* @todo Obey sort order
|
||||
*/
|
||||
private function _get_categories() {
|
||||
return ORM::factory('product_category')
|
||||
->where('status','=',TRUE)
|
||||
->find_all();
|
||||
}
|
||||
}
|
||||
?>
|
89
modules/product/classes/model/product.php
Normal file
89
modules/product/classes/model/product.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports OSB listing products
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Product
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Product extends ORMOSB {
|
||||
// @todo this doesnt have our site_id when getting the translation
|
||||
protected $_has_many = array(
|
||||
'product_translate'=>array(),
|
||||
);
|
||||
|
||||
protected $_sorting = array(
|
||||
'position'=>'asc',
|
||||
'sku'=>'asc',
|
||||
);
|
||||
|
||||
protected $_formats = array(
|
||||
'price_type'=>array('StaticList_PriceType::display'=>array()),
|
||||
);
|
||||
|
||||
/**
|
||||
* Return the products for a given category
|
||||
*/
|
||||
public function category($cat) {
|
||||
$results = array();
|
||||
foreach ($this->where('active','=',TRUE)->find_all() as $po) {
|
||||
if ($c = unserialize($po->avail_category_id) AND in_array($cat,$c))
|
||||
array_push($results,$po);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public function get_price_array() {
|
||||
if (! $this->loaded())
|
||||
throw new Kohana_Exception('Call to :method where no object loaded?',array(':method'=>__METHOD__));
|
||||
|
||||
// Figure out our eligable groups
|
||||
// @todo Need to work out our default groups elsewhere, not in product
|
||||
// All users are members of the all user group "0"
|
||||
$groups = array(0);
|
||||
$pg = unserialize($this->price_group);
|
||||
if (Auth::instance()->logged_in())
|
||||
foreach (Auth::instance()->get_user()->group->find_all() as $go)
|
||||
array_push($groups,$go->id);
|
||||
|
||||
// Work out the best price for the user
|
||||
$price = array();
|
||||
foreach (unserialize($this->price_group) as $bill_freq => $pg) {
|
||||
if ($pg['show'])
|
||||
foreach ($groups as $gid) {
|
||||
if (! empty($pg[$gid])) {
|
||||
if (empty($price[$bill_freq]['price_base'])
|
||||
OR ($pg[$gid]['price_base'] AND $price[$bill_freq]['price_base'] > $pg[$gid]['price_base'])) {
|
||||
$price[$bill_freq]['price_setup'] = $pg[$gid]['price_setup'];
|
||||
$price[$bill_freq]['price_base'] = $pg[$gid]['price_base'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the product is a TRIAL product
|
||||
* (price_type == 2)
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function is_trial() {
|
||||
if ($this->price_type == 2)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
?>
|
20
modules/product/classes/model/product/category.php
Normal file
20
modules/product/classes/model/product/category.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class supports OSB listing products by category.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Product
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Product_Category extends ORMOSB {
|
||||
protected $_table_name = 'product_cat';
|
||||
|
||||
protected $_sorting = array(
|
||||
'name'=>'asc',
|
||||
);
|
||||
}
|
||||
?>
|
18
modules/product/classes/model/product/translate.php
Normal file
18
modules/product/classes/model/product/translate.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class product access to product translation.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Product
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Product_Translate extends ORMOSB {
|
||||
protected $_belongs_to = array(
|
||||
'product'=>array(),
|
||||
);
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user