GaimZz Posted March 5, 2019 Share Posted March 5, 2019 Hi, I was reading the official docs and i saw that the encouraged way for interacting with the DB on a module is by creating a repository and declare it as a service. https://devdocs.prestashop.com/1.7/modules/concepts/hooks/use-hooks-on-modern-pages/#using-doctrine-dbal-to-retrieve-data My doubt is in which folder should this repostiory be created, I assume I can do it within my module folder right? Docs code declares that it should be created on '/src/Repository', and this may seem dumb but, I assume it's reffering to create a folder inside my module called 'src'? I'm confused since on the doc about folder module structure that isn't a common option (https://devdocs.prestashop.com/1.7/modules/creation/module-file-structure/). Can someone give some insight as to what does the documentation mean? Thanks Link to comment Share on other sites More sharing options...
Mickaël Andrieu Posted March 5, 2019 Share Posted March 5, 2019 (edited) Hi @GaimZz, the docs are a little bit outdated on this point, it depends whether you plan to use Composer to manage your classes or not. If you don't, it's almost impossible to declare and/or use the PrestaShop 1.7 services in your module. If you do... well, we don't have docs "yet" to help you, but you can take a look at this module: https://github.com/friends-of-prestashop/masterclass Hope it helps, Edit: some docs here => https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/#example-using-psr-4-namespacing Mickaël Edited March 5, 2019 by Mickaël Andrieu (see edit history) Link to comment Share on other sites More sharing options...
GaimZz Posted March 5, 2019 Author Share Posted March 5, 2019 Thank you for your insight! I'd like to ask another question about managing my classes with composer. Once I have the composer.json file declared as docs explain, is there anything else needed or will it be ready to install? Thanks Link to comment Share on other sites More sharing options...
Mickaël Andrieu Posted March 5, 2019 Share Posted March 5, 2019 You have one extra task to do: generate the autoloader and the dependencies (if you have some). 0 dependencies: composer dump-autoload (at the root of your module) x dependencies: composer install (at the root of your module) Or, if you plan to manage your module itself as a dependency of your project: composer require your/module (will be installed in modules folder with its autoloader and dependencies) When you ship your module with a release of this module, you can optimize the generated autoloader: take a look at the Composer's documentation => https://getcomposer.org/doc/articles/autoloader-optimization.md Mickaël Link to comment Share on other sites More sharing options...
GaimZz Posted April 17, 2019 Author Share Posted April 17, 2019 On 3/5/2019 at 9:11 PM, Mickaël Andrieu said: You have one extra task to do: generate the autoloader and the dependencies (if you have some). 0 dependencies: composer dump-autoload (at the root of your module) x dependencies: composer install (at the root of your module) Hi Mickaël, Sorry for the late question but, doesn't this mean that if I want to distribute this module it wouldn't work unless 'composer dump-autoload' is done, therefore modules using this feature wouldn't be able to be distributed right? Is this just ignored or does prestashop automatically regenerate if needed on install or something like that? Link to comment Share on other sites More sharing options...
Mickaël Andrieu Posted April 29, 2019 Share Posted April 29, 2019 Hi @GaimZz, you need to provide the vendor folder inside your module archive: for now, there is no mechanism from PrestaShop able to build the dependencies and the autoloader. Sorry for the delay, 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