So I have this custom form in the back-end from which I want to save/load values from my custom table in the database.
I have set that form to use a my custom model - this is from the system.xml
file in the module:
<backend_model>myproductimporter/system_config_backend_customoptions</backend_model>
This is the class so far:
class MODULE_MyProductImporter_Model_System_Config_Backend_Customoptions extends Mage_Adminhtml_Model_System_Config_Backend_Serialized
{
/**
* Constructs an array of custom options data mapped to and organized by their template ID.
* Save actual data in custom_options_import_templeates table.
*
* (non-PHPdoc)
* @see Mage_Core_Model_Abstract::_beforeSave()
*/
protected function _beforeSave()
{
$value = $this->getValue();
if (is_array($value)) {
unset($value['__empty']);
}
/* my custom functionality */
$this->setValue($value);
parent::_beforeSave();
}
protected function _afterLoad() {
return parent::_afterLoad();
}
}
So the functionality in these 2 functions is the same as in the parent class. Only the /* my custom functionality /*
does some mapping stuff over the data. This manipulated data I want to save in my own way in my own table in the DB.
I have created a Resource model class:
class MODULE_MyProductImporter_Model_Resource_Import_Importer extends Mage_Core_Model_Resource_Db_Abstract {
protected function construct() {
$this->_init('myproductimporter/import_importer', 'id');
}
public function saveCustomOptions(array $valuesToSave) {
/* process the data given from the function from Customoptions.php
and save it in my custom table in the DB */
}
}
And I have configured the resource class:
<global>
<models>
<myproductimporter>
<class>MODULE_MyProductImporter_Model</class>
<resourceModel>myproductimporter_resource</resourceModel>
</myproductimporter>
<myproductimporter_resource>
<class>MODULE_MyhProductImporter_Model_Resource_Import_Importer</class>
<entities>
<myproductimporter>
<table>custom_options_import_templates</table>
</myproductimporter>
</entities>
</myproductimporter_resource>
</models>
What I don't understand is the process flow. Where should I call the saveCustomOptions
function? It seems to me that it should be in the _beforeSave
but that also doesn't make sense, since this function should finish its job before the save is done. I get until the end of _beforeSave()
, but then I am lost in what should I do...
Also, how is the manipulated-and-ready-to-save data (in saveCustomOptions()
) processed and saved?
The table where I want to save the data is called custom_options_import_templates