bourdux Posted August 4, 2012 Share Posted August 4, 2012 (edited) Dear all, I am currently developing a website for an art gallery which sells artworks online. I need to develop some code to gather and display information about artists (bio, mail, email, dates of exhibition,...). I first tried to use the manufacturers function and to only adapt the translations, replacing "manufacturer" by "artist" but I soon realized that I was limited. I do not need to associate an artist with its address and I need additional information. The problem is I do not know what would be the best way to implement this, while keeping my code clean and make prestashop upgrades easy to do. I think I will need to make new database tables, as follows (exhibition dates, not implemented yet): CREATE TABLE `artist` ( `id_artist` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(64) NOT NULL, `date_add` datetime NOT NULL, `date_upd` datetime NOT NULL, `active` tinyint(4) NOT NULL DEFAULT '0', `email` varchar(255) DEFAULT NULL, `phone` varchar(255) DEFAULT NULL, PRIMARY KEY (`id_artist`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE `artist_lang` ( `id_artist` int(11) NOT NULL, `id_lang` int(11) NOT NULL, `name` varchar(255) NOT NULL, `description` text NOT NULL, `short_description` text NOT NULL, `meta_title` varchar(128) NOT NULL, `meta_keywords` varchar(255) NOT NULL, `meta_description` varchar(255) NOT NULL, PRIMARY KEY (`id_artist`,`id_lang`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; Should I make this a module, or directly add an artist module and controllers in the core classes? If I do so, I will have to override the product class. Since I do not need the manufacturers, should I override the manufacturer class? Thank you in advance for your answers. Julien. Edited August 4, 2012 by bourdux (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted August 4, 2012 Share Posted August 4, 2012 i did something similar for a Distributor, which I used the supplier as a model (doesn't require address if I recall properly). No way to get around changing some core classes, but do so using overrides the best you can. The only module you can create is the block, which can include the AdminTab if you wish. But any new classes you create will have to be created in the core class folder. Only extends of existing core classes can be placed in the override folder If things get too complex and you would like to hire someone, send me a PM and we can discuss in more detail. Link to comment Share on other sites More sharing options...
bourdux Posted August 5, 2012 Author Share Posted August 5, 2012 (edited) Thank you very much. I'll then create a new class to suit my needs. I guess I'll have to add an "artist.php" file including the following code in the root directory then: require(dirname(__FILE__).'/config/config.inc.php'); ControllerFactory::getController('ArtistController')->run(); Then I'll create an ArtistCore class in the classes folder as well as ArtistControllerCore in the controllers folder. I will also override the product class so it can refer to the associated artists. Did I miss anything? P.S. I'm doing fine at the moment but I'll be sure to PM you if things get out of hand Edited August 5, 2012 by bourdux (see edit history) Link to comment Share on other sites More sharing options...
bourdux Posted August 5, 2012 Author Share Posted August 5, 2012 And I forgot, I might as well include it for future visitors. I also needed to modify config/defines.inc.php by adding these two lines for artist images: define('_ARTI_DIR_', _PS_IMG_.'ar/'); define('_PS_ARTI_IMG_DIR_', _PS_IMG_DIR_.'ar/'); Then an "ar" directory with writing permissions must be created in "/img" Link to comment Share on other sites More sharing options...
bellini13 Posted August 5, 2012 Share Posted August 5, 2012 ah yes, good point on the image. The distributor requirements did not need images, so I skipped doing that. I agree with everything else you mentioned, you have to create the core files (page, controller and classes) also if making an admin page, you will want an image in the /img/admin, like artist.gif and if you want to display the artist on the product page, you could also create a module that hooks extraRight, or one or more of the product page hooks other overrides I had to create are Link: a function called getDistributorLink that models the getSupplierLink Tools: update the generateHtaccess function to include redirects for the distributor that models the suppler redirects. I used 3 underscores (___), where the manufacturer uses 1 underscore (_) and supplier uses 2 underscores (__). Look at you will see what I mean admin/ajax.php: code to support ajax style queries from the back office. theme files (templates, css) to support the new core files. good luck! 1 Link to comment Share on other sites More sharing options...
bourdux Posted August 5, 2012 Author Share Posted August 5, 2012 I just finished to program this and it works perfectly, at least for the back-office parts. I woke up as a prestashop newbie and I will go to bed as a prestashop beginner. Anyway, I figured out for ajax and the theme by myself but forgot the link and redirect tools, thank you for mentioning it. It certainly would have given me headaches when I will debug the front-office parts. One more thing: I had to modify the AdminProducts.php file (tab) to add a drop-down list to select the artist when adding a new product/editing. Too bad the tabs can't be overridden, I'll have to be careful whenever I upgrade prestashop. Link to comment Share on other sites More sharing options...
bourdux Posted August 5, 2012 Author Share Posted August 5, 2012 Also, I took the liberty to use your replies to answer a StackOverflow question I asked about this problem: http://stackoverflow.com/questions/11810760/code-structure-choice-for-a-manufacturer-like-function-in-prestashop/ I linked back here so people can find you if they want to hire your services That would make good tutorial material but alas I'm too busy making this website Thanks again, it really helped! Link to comment Share on other sites More sharing options...
fernandokerber Posted August 5, 2012 Share Posted August 5, 2012 could you post your results here? Link to comment Share on other sites More sharing options...
bellini13 Posted August 5, 2012 Share Posted August 5, 2012 you can "override" the admin tab, by placing a copy in a module folder. You can name the module folder anything you want, I would suggest adminoverrides. you then update the admin record to state what the module folder name is. that way you leave the core admin tab alone, and by having a module folder that contains all your admintab overrides, gives you the upgrade reminder Link to comment Share on other sites More sharing options...
bourdux Posted August 6, 2012 Author Share Posted August 6, 2012 you can "override" the admin tab, by placing a copy in a module folder. You can name the module folder anything you want, I would suggest adminoverrides. you then update the admin record to state what the module folder name is. that way you leave the core admin tab alone, and by having a module folder that contains all your admintab overrides, gives you the upgrade reminder I tried but I don't know what I did wrong, the catalog tab is blank (probably because of a bad include): So I created adminoverrides folder in modules and copied both AdminCatalog.php and AdminProducts.php in it. I changed the includes of adminoverrides/AdminCatalog.php as follows: include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php'); include(PS_ADMIN_DIR.'/tabs/AdminCategories.php'); include(PS_ADMIN_DIR.'/../modules/adminoverrides/AdminProducts.php'); And it doesn't work (which although proves that the overriden class is used). I kind of understood how to override classic admin tabs but AdminProducts is not a tab by itself and is used in AdminCatalog. What am I doing wrong? could you post your results here? I will post the complete procedure, once I have debugged the front-office part as well. Link to comment Share on other sites More sharing options...
bourdux Posted August 6, 2012 Author Share Posted August 6, 2012 (edited) Nevermind I found how to activate the debug options in config.inc.php: @ini_set('display_errors', 'on'); define('_PS_DEBUG_SQL_', true); and I replaced: include(PS_ADMIN_DIR.'/../modules/adminoverrides/AdminProducts.php') by: include(_PS_ROOT_DIR_.'/modules/adminoverrides/AdminProducts.php'); and it worked. I'll now move onto the Front-Office debug and update this thread, in the case someone was developing the same kind of stuff. Edited August 6, 2012 by bourdux (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now