Jump to content

Help/Information on ObjectModel needed


leszek_zalewski

Recommended Posts

Hi everyone!

I started working on a module that will give an option to create multiple tables with clothes sizes. Something like on this image. So I have prepared equivalent table schema for it, including language support.

And now comes some trouble, because from what I can see there is special class ObjectModule witch I can extend to have easier and more manageable module. But missing technical documentation is a pain in ..., and I don't know from what to begin with to make it. Which fields should I include? What queries should I prepare? What will be accessible from outside, or what should be?

Another thing is, how can I, and what is the best way to include a field in product admin page, to link product with table?
And the last one, how can I get product Id in module class to retrieve its corresponding table ?

Regards

Link to comment
Share on other sites

Hi Leszek, sorry its late here so I'm not functioning 100% but I'll try and help as best I can!

The Public Member Functions for the ObjectModelCore class are as follows:

ObjectModelCore

getFields ()
__construct ($id=NULL, $id_lang=NULL)
save ($nullValues=false, $autodate=true)
add ($autodate=true, $nullValues=false)
update ($nullValues=false)
delete ()
deleteSelection ($selection)
toggleStatus ()
validateFields ($die=true, $errorReturn=false)
validateFieldsLang ($die=true, $errorReturn=false)
validateControler ($htmlentities=true)
validateController ($htmlentities=true)
getWebserviceParameters ($wsParamsAttributeName=NULL)
getWebserviceObjectList ($sql_join, $sql_filter, $sql_sort, $sql_limit)
getFieldsRequiredDatabase ($all=false)
addFieldsRequiredDatabase ($fields)
clearCache ($all=false)



If that helps at all?

Also as you're making a module I assume you'd want to know about ModuleCore also?


ModuleCore

__construct ($name=NULL)
install ()
uninstall ()
enable ()
disable ()
registerHook ($hook_name)
displayFlags ($languages, $defaultLanguage, $ids, $id, $return=false)
unregisterHook ($hook_id)
unregisterExceptions ($hook_id)
registerExceptions ($id_hook, $excepts)
editExceptions ($id_hook, $excepts)
l ($string, $specific=false)
updatePosition ($id_hook, $way, $position=NULL)
cleanPositions ($id_hook)
getPosition ($id_hook)
displayError ($error)
displayConfirmation ($string)
getExceptions ($id_hook)
isRegisteredInHook ($hook)
isCached ($template, $cacheId=NULL, $compileId=NULL)
isHookableOn ($hook_name)




Hopefully those will be useful to you!

As for your other questions, I'm not quite sure what you're asking entirely. All of the database is accessible, even to the point of creating your own tables (on install, and removing on uninstall) specific to the module you're developing.

I would recommend if at all possible however to use PrestaShops current methods within the classes and controllers to pull any data required, falling back on creating your own only if required.

Its often a good idea to have a look at some of the other modules included with PrestaShop to see how they go about performing similar tasks.

Apologies if I'm telling you things you already know here!


Field in product admin page
I assume you want to add a new input field/option when you're adding new products? Take a look at angora's post here for some help: http://www.prestashop.com/forums/viewthread/105303/#432812

Product ID in module class
This all depends on how you're choosing the product. Is it based on the category? Is there one specific product you will always choose? This will determine which method you would use to select it.

I'd take a close look at the Products controller, and the Products class for relevant stuff. You could also check out the Home Featured module which comes installed with Prestashop, as this pulls all the products from the Home category. See how this works, and try to adapt it to what you're trying to do.

Hope some of this helps!

Mark

Link to comment
Share on other sites

Hi Mark, thank You for Your time and reply!

First of all sry for unclear information - I know How can I use Db alone i.e. inserts, updates, etc. I also had working script to create Tables with installation and drop it with keys on uninstall of module. But I want to do it in a good way - separate objects from main module class.

Anyway thanks for lists for ObjectModel and ModuleCore, I think they were very useful when I now looked at OM again, and I don't know why I didn't do it earlier ;/

To sum up - the ObjectModel is class for holding Object structure ( public accessible fields ) and functions to work with DB (add, update, delete, get* ) yes?
Not like patterns in Java where was one class for model ( Entity/DTO ) and DAO classes for retrieving information's from database?

Now I think I understand it a little more. One more thing will be, is there are fields that I must override (except for those protected fields for validation )?


Field in product admin page
I assume you want to add a new input field/option when you’re adding new products? Take a look at angora’s post here for some help

For admin page, I think angora's post should do the job. Also if someone else would search for something like this there's another one post with fav place.

Product ID in module class
This all depends on how you’re choosing the product. Is it based on the category? Is there one specific product you will always choose? This will determine which method you would use to select it.

I need it on products page. But I think I found it. Inside smarty I could do
$smarty.get.id_product|intval


Which isn't much help for me. But there is also

Tools::getValue('id_product') 


which is what I need :)

Ok, It's time to get it done ;]

Btw. PrestaTeam - why there isn't any Real TechGuide in En or Fr? Even more relevant comments in code should do the job

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...