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?
I asked the same question on the Prestashop forum and got good advice that I will summarize here if someone had the same problem.
There is no way around modifying core classes but override should be used as much as possible.
Back-office functions
Artistclass inoverrides/classesby copy-pasting theManufacturerCoreclass and and substituting mentions ofmanufacturerbyartistas well as specifying the additional fields as instance variables.ArtistControllerclass inoverrides/controllersand substitute mentions ofmanufacturerbyartistProductclass and addid_artistandartist_nameas instance variables. Modify the following functions so that a product is linked with its artist:__construct,getFieldsandgetProductsArtistsAdminsubclass ofAdminTabinadmin/tabsso that the back-office can be used to add new/edit artistsadmin/ajax.phpso that the artists can be queries form the back-officeProductsAdmininadmin/tabsso that the user can choose an artist when adding/editing a productimg/admin/artist.gifandimg/admin/artists.gifHandle the image folder in
config/defines.inc.php:define(‘_ARTI_DIR_’, _PS_IMG_.’ar/’);
define(‘_PS_ARTI_IMG_DIR_’, _PS_IMG_DIR_.’ar/’);
Crate the
arfolder inimgand set write permissions for everyoneFront-Office functions (not tested yet, might lack some info):
getDistributorLinkthat models thegetSupplierLink___), where the manufacturer uses 1 underscore (_) and supplier uses 2 underscores (__).