Work on Email and other major consistency work

This commit is contained in:
Deon George
2013-11-22 15:36:50 +11:00
parent 89deb9c97b
commit c18d5a3881
55 changed files with 550 additions and 575 deletions

View File

@@ -14,9 +14,9 @@
*/
class Model_Product extends ORM_OSB {
protected $_has_many = array(
'product_translate'=>array('far_key'=>'id'),
'service'=>array('far_key'=>'id'),
'invoice'=>array('through'=>'invoice_item'),
'service'=>array('far_key'=>'id'),
'translate'=>array('model'=>'Product_Translate','far_key'=>'id'),
);
protected $_sorting = array(
@@ -44,6 +44,8 @@ class Model_Product extends ORM_OSB {
'price_group',
);
protected $_save_message = TRUE;
/**
* Which categories is this product available in
*/
@@ -106,29 +108,22 @@ class Model_Product extends ORM_OSB {
}
public function save(Validation $validation=NULL) {
if ($this->changed())
if (parent::save($validation))
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Record %s Updated',$this->id));
parent::save($validation);
// Save our Translated Message
if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['product_translate']) AND is_array($_POST['product_translate'])) {
$pto = $this->product_translate->where('language_id','=',$_POST['language_id'])->find();
if ($x = array_diff_key($_POST,$this->_object) AND ! empty($_POST['language_id']) AND ! empty($_POST['translate']) AND is_array($_POST['translate'])) {
$to = $this->translate->where('language_id','=',$_POST['language_id'])->find();
// For a new entry, we need to set the product_id
if (! $pto->loaded()) {
$pto->product_id = $this->id;
$pto->language_id = $_POST['language_id'];
if (! $to->loaded()) {
$to->product_id = $this->id;
$to->language_id = $_POST['language_id'];
}
if ($pto->values($x['product_translate'])->save())
SystemMessage::factory()
->title('Record Updated')
->type('success')
->body(sprintf('Translation for Record %s Updated',$this->id));
$to->values($x['translate'])->save();
}
return $this;
}
/**
@@ -143,7 +138,7 @@ class Model_Product extends ORM_OSB {
}
private function translate() {
return $this->product_translate->where('language_id','=',Config::language())->find();
return $this->translate->where('language_id','=',Config::language())->find();
}
/**