Multi enhancements, including auto serialization, product editing
This commit is contained in:
@@ -12,17 +12,41 @@
|
||||
*/
|
||||
class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
|
||||
protected $secure_actions = array(
|
||||
'ajaxtranslateform'=>TRUE,
|
||||
'list'=>TRUE,
|
||||
'update'=>TRUE,
|
||||
'view'=>TRUE,
|
||||
);
|
||||
|
||||
public function action_ajaxtranslateform() {
|
||||
$this->auto_render = FALSE;
|
||||
|
||||
$po = ORM::factory('product',$this->request->param('id'));
|
||||
|
||||
if (! $this->request->is_ajax() OR ! $po->loaded() OR ! isset($_REQUEST['key']))
|
||||
$this->response->body(_('Unable to find translate data'));
|
||||
|
||||
else {
|
||||
|
||||
$pto = $po->product_translate->where('language_id','=',$_REQUEST['key'])->find();
|
||||
|
||||
$this->response->body(View::factory($this->viewpath())->set('pto',$pto));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a list of products
|
||||
*/
|
||||
public function action_list() {
|
||||
if ($this->request->param('id'))
|
||||
$prods = ORM::factory('product')->list_category($this->request->param('id'),FALSE);
|
||||
else
|
||||
$prods = ORM::factory('product')->order_by('active DESC,prod_plugin_file')->find_all();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Customer Products'),
|
||||
'body'=>Table::display(
|
||||
ORM::factory('product')->order_by('active DESC,prod_plugin_file')->find_all(),
|
||||
$prods,
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'product/view/'),
|
||||
@@ -43,5 +67,78 @@ class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
|
||||
)),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit a product configuration
|
||||
*/
|
||||
public function action_update() {
|
||||
$po = ORM::factory('product',$this->request->param('id'));
|
||||
|
||||
if (! $po->loaded())
|
||||
Request::current()->redirect('welcome/index');
|
||||
|
||||
if ($_POST) {
|
||||
if (isset($_POST['product_translate']['id']) AND ($pto=ORM::factory('product_translate',$_POST['product_translate']['id'])) AND $pto->loaded())
|
||||
if (! $pto->values($_POST['product_translate'])->update()->saved())
|
||||
throw new Kohana_Exception('Failed to save updates to product_translate data for record :record',array(':record'=>$po->id()));
|
||||
|
||||
if (! $po->values($_POST)->update()->saved())
|
||||
throw new Kohana_Exception('Failed to save updates to product data for record :record',array(':record'=>$so->id()));
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s %s:%s',_('Update Product'),$po->id,$po->name()),
|
||||
'body'=>View::factory($this->viewpath())
|
||||
->set('po',$po)
|
||||
->set('mediapath',Route::get('default/media'))
|
||||
->set('plugin_form',$po->admin_update()),
|
||||
));
|
||||
|
||||
Script::add(array('type'=>'stdin','data'=>'
|
||||
$(document).ready(function() {
|
||||
$("select[name=language_id]").change(function() {
|
||||
// Send the request and update sub category dropdown
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
data: "key="+$(this).val(),
|
||||
dataType: "html",
|
||||
cache: false,
|
||||
url: "'.URL::site('admin/product/ajaxtranslateform/'.$po->id).'",
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
alert("Failed to submit");
|
||||
},
|
||||
success: function(data) {
|
||||
$("div[id=translate]").replaceWith(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
'));
|
||||
}
|
||||
|
||||
public function action_view() {
|
||||
$po = ORM::factory('product',$this->request->param('id'));
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('Current Services Using this Product'),$po->name()),
|
||||
'body'=>Table::display(
|
||||
ORM::factory('service')->where('product_id','=',$po->id)->find_all(),
|
||||
25,
|
||||
array(
|
||||
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
|
||||
'account->accnum()'=>array(),
|
||||
'account->name()'=>array('label'=>'Account'),
|
||||
'name()'=>array('label'=>'Details'),
|
||||
'active'=>array('label'=>'Active'),
|
||||
'price(TRUE,TRUE)'=>array('label'=>'Price','align'=>'right'),
|
||||
),
|
||||
array(
|
||||
'page'=>TRUE,
|
||||
'type'=>'select',
|
||||
'form'=>'user/service/view',
|
||||
)),
|
||||
));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@@ -42,6 +42,8 @@ class Controller_Product extends Controller_TemplateDefault {
|
||||
Request::current()->redirect('welcome/index');
|
||||
|
||||
Breadcrumb::name($this->request->uri(),$cat->name);
|
||||
Breadcrumb::url('product','product/categorys');
|
||||
Breadcrumb::url('product/category','product/categorys');
|
||||
|
||||
Block::add(array(
|
||||
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
|
||||
@@ -68,6 +70,7 @@ class Controller_Product extends Controller_TemplateDefault {
|
||||
Request::current()->redirect('product_category/index');
|
||||
|
||||
Breadcrumb::name($this->request->uri(),$po->product_translate->find()->name);
|
||||
Breadcrumb::url('product','product/categorys');
|
||||
|
||||
// Work out our category id for the control line
|
||||
if (! empty($_GET['cid'])) {
|
||||
@@ -78,6 +81,7 @@ class Controller_Product extends Controller_TemplateDefault {
|
||||
Request::current()->redirect('product_category/index');
|
||||
|
||||
Breadcrumb::name('product/view',$co->name);
|
||||
Breadcrumb::url('product/view','product/category/'.$co->id);
|
||||
}
|
||||
|
||||
Block::add(array(
|
||||
|
@@ -41,6 +41,19 @@ class Model_Product extends ORMOSB {
|
||||
),
|
||||
);
|
||||
|
||||
// Our attributes that are arrays, we'll convert/unconvert them
|
||||
protected $_serialize_column = array(
|
||||
'price_group',
|
||||
);
|
||||
|
||||
public function rules() {
|
||||
return array_merge(parent::rules(),array(
|
||||
'price_group'=>array(
|
||||
array('ORMOSB::serialize_array',array(':model',':field',':value')),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object of the product plugin
|
||||
*/
|
||||
@@ -81,14 +94,14 @@ class Model_Product extends ORMOSB {
|
||||
// @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 (is_array($this->price_group))
|
||||
foreach ($this->price_group as $bill_freq => $pg) {
|
||||
if (isset($pg['show']) AND $pg['show'])
|
||||
foreach ($groups as $gid) {
|
||||
if (! empty($pg[$gid])) {
|
||||
@@ -133,6 +146,50 @@ class Model_Product extends ORMOSB {
|
||||
echo '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable the plugin to store data
|
||||
*/
|
||||
public function admin_update() {
|
||||
if (is_null($plugin = $this->plugin()))
|
||||
return NULL;
|
||||
else
|
||||
return $plugin->admin_update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is price shown for a specific period
|
||||
*/
|
||||
public function isPriceShown($p) {
|
||||
$x = $this->keyget('price_group',$p);
|
||||
|
||||
return (isset($x['show']) AND $x['show']) ? TRUE : FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the configured price groups for this product
|
||||
*/
|
||||
public function availPriceGroups() {
|
||||
// @todo This needs to be worked out dynamically
|
||||
return array(0,2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available pricing options
|
||||
*/
|
||||
public function availPriceOptions() {
|
||||
// @todo This needs to be worked out dynamically
|
||||
return array('price_base','price_setup');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the price for the particle group and price option for the period
|
||||
*/
|
||||
public function price($grp,$period,$option) {
|
||||
$x = $this->keyget('price_group',$period);
|
||||
|
||||
return isset($x[$grp][$option]) ? $x[$grp][$option] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the number of services using this product
|
||||
*/
|
||||
@@ -151,14 +208,20 @@ class Model_Product extends ORMOSB {
|
||||
* Return the products for a given category
|
||||
* @todo This shouldnt be here.
|
||||
*/
|
||||
public function list_category($cat) {
|
||||
public function list_category($cat,$active=TRUE) {
|
||||
$results = array();
|
||||
|
||||
foreach ($this->where('active','=',TRUE)->find_all() as $po) {
|
||||
if ($active)
|
||||
$cats = $this->where('active','=',TRUE);
|
||||
else
|
||||
$cats = $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;
|
||||
}
|
||||
}
|
||||
|
20
modules/product/classes/model/product/category/translate.php
Normal file
20
modules/product/classes/model/product/category/translate.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class product access to product category 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_Category_Translate extends ORMOSB {
|
||||
protected $_table_name = 'product_cat_translate';
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'product_category'=>array(),
|
||||
);
|
||||
}
|
||||
?>
|
@@ -14,6 +14,12 @@ abstract class Model_Product_Plugin extends ORMOSB {
|
||||
// Reset any sorting that may be defined in our parent
|
||||
protected $_sorting = array();
|
||||
|
||||
/**
|
||||
* The admin_update should be implemented in plugins.
|
||||
* It is used to update the plugin specific product information
|
||||
*/
|
||||
abstract public function admin_update();
|
||||
|
||||
/**
|
||||
* The feature summary should be implemented in plugins.
|
||||
* It is displayed on the product overview page, as a summary of the products features.
|
||||
|
@@ -11,6 +11,8 @@
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Product_Translate extends ORMOSB {
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
protected $_belongs_to = array(
|
||||
'product'=>array(),
|
||||
);
|
||||
|
15
modules/product/views/product/admin/ajaxtranslateform.php
Normal file
15
modules/product/views/product/admin/ajaxtranslateform.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php echo Form::hidden('product_translate[id]',$pto->id); ?>
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width: 40%;">Product Name</td>
|
||||
<td style="width: 60%;" style="data"><?php echo Form::input('product_translate[name]',$pto->name); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Product Short Description</td>
|
||||
<td style="data"><?php echo Form::input('product_translate[description_short]',$pto->description_short); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Product Long Description</td>
|
||||
<td style="data"><?php echo Form::textarea('product_translate[description_full]',$pto->description_full); ?></td>
|
||||
</tr>
|
||||
</table>
|
63
modules/product/views/product/admin/update.php
Normal file
63
modules/product/views/product/admin/update.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<!-- @todo NEEDS TO BE TRANSLATED -->
|
||||
<?php echo Form::open(); ?>
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="width: 50%; vertical-align: top;">
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="width: 40%;">Product Active</td>
|
||||
<td style="width: 5%;"> </td>
|
||||
<td style="width: 60%;" class="data"><?php echo StaticList_YesNo::form('active',$po->active); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">Base Price</td>
|
||||
<td class="data"><?php echo Form::input('price_base',$po->price_base); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">Price</td>
|
||||
<td class="data">
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="2"> </td>
|
||||
<?php foreach (StaticList_RecurSchedule::keys() as $k) { ?>
|
||||
<td class="head"><?php echo StaticList_RecurSchedule::display($k); ?></td>
|
||||
<td><?php echo Form::checkbox("price_group[$k][show]",1,$po->isPriceShown($k)); ?>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php foreach ($po->availPriceGroups() as $g) { ?>
|
||||
<?php foreach ($po->availPriceOptions() as $o) { ?>
|
||||
<tr>
|
||||
<td><?php echo ORM::factory('group',$g)->name; ?></td>
|
||||
<td><?php echo $o; ?></td>
|
||||
<?php foreach (StaticList_RecurSchedule::keys() as $k) { ?>
|
||||
<td colspan="2"><?php echo Form::input("price_group[$k][$g][$o]",$po->price($g,$k,$o),array('size'=>5)); ?></td>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</table>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">Default Period</td>
|
||||
<td class="data"><?php echo StaticList_RecurSchedule::form('price_recurr_default',$po,$po->price_recurr_default); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">Order</td>
|
||||
<td class="data"><?php echo Form::input('position',$po->position); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Product Descriptions</td>
|
||||
<td><?php echo Form::select('language_id',array('','EN'=>'EN')); ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td class="data" colspan="2"><div id="translate"></div></td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php if ($plugin_form) { echo '<br/>'.$plugin_form; } ?>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php echo Form::submit('submit',_('Update'),array('class'=>'form_button')); ?>
|
||||
<?php echo Form::close(); ?>
|
@@ -27,7 +27,7 @@ echo Form::open('cart/add');
|
||||
<td style="background-color: #FFFFFF;">
|
||||
<table width="100%" border="0" cellpadding="4">
|
||||
<tr>
|
||||
<td class="body" rowspan="3"><?php echo $translate->description_full; ?></td>
|
||||
<td class="body" rowspan="4"><?php echo $translate->description_full; ?></td>
|
||||
<td style="text-align: right;"><?php if ($a=$record->show_thumb()) echo $a; ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -43,10 +43,8 @@ echo Form::open('cart/add');
|
||||
} ?>
|
||||
</tr>
|
||||
<tr>
|
||||
<?php if ($record->prod_plugin_file && method_exists($record->prod_plugin_file,'feature_summary')) {
|
||||
// @todo This doesnt work, it needs to be product_plugin_xx class
|
||||
$pio = new $record->prod_plugin_file;
|
||||
echo '<td style="vertical-align: top;">'.$pio->feature_summary().'</td>';
|
||||
<?php if ($record->prod_plugin_file && method_exists($record->plugin(),'feature_summary')) {
|
||||
echo '<td style="vertical-align: top;">'.$record->plugin()->feature_summary().'</td>';
|
||||
} ?>
|
||||
</tr>
|
||||
<tr>
|
||||
@@ -57,7 +55,7 @@ echo Form::open('cart/add');
|
||||
<td class="body" style="width: 50%;"><b>Currency</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="body"><?php echo StaticList_RecurSchedule::form('recurr_schedule',$record);?> </td>
|
||||
<td class="body"><?php echo StaticList_RecurSchedule::form('recurr_schedule',$record,$record->price_recurr_default);?> </td>
|
||||
<!-- @todo The default currency should be system configurable and displayed by default -->
|
||||
<!-- @todo If CURRENCY's value is not active in the DB, then the wrong flag is shown, as StaticList_Module::form() only returns active values -->
|
||||
<!-- @todo Currency is not used in the cart? -->
|
||||
|
Reference in New Issue
Block a user