PMunoz92 Posted October 25, 2018 Share Posted October 25, 2018 Hello, I need some help, I've following PS1.7 Documentation with no successful results I'm trying to do this And getting this This is my foo.php file: <?php // foo.php /* ... */ /** * Module installation. * * @return bool Success of the installation */ if (!defined('_PS_VERSION_')) { exit; } class Foo extends Module { public function __construct() { $this->name = 'foo'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'Patricio Munoz'; $this->need_instance = 0; $this->ps_version_compliancy = array( 'min' => '1.6', 'max' => _PS_VERSION_, ); parent::__construct(); $this->displayName = $this->l('Dumping products Module'); $this->description = $this->l('Display an array of products'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); $this->install(); } public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } if (!parent::install() || !$this->registerHook('displayDashboardToolbarIcons') //!$this->registerHook('displayDashboardTop') ) { return false; } return true; } public function uninstall() { return parent::uninstall(); } /** * Add an "XML export" action in Product Catalog page. * * @return bool Success of the installation */ public function hookDisplayDashboardToolbarIcons($hookParams) { if ($this->isSymfonyContext() && $hookParams['route'] === 'admin_product_catalog') { $products = $this->get('product_repository')->findAllByLangId(1); dump($products); } } // public function hookDisplayDashboardTop($hookParams) // { // if ($this->isSymfonyContext() && $hookParams['route'] === 'admin_product_catalog') { // $products = $this->get('product_repository')->findAllByLangId(1); // dump($products); // } // } } This is my services.yml # modules/foo/config/services.yml services: _defaults: # automatically injects dependencies in your services autowire: true # automatically registers your services as commands, event subscribers, etc. autoconfigure: true # this means you cannot fetch services directly from the container via $container->get() # if you need to do this, you can override this setting on individual services public: true product_repository: class: Foo\Repository\ProductRepository arguments: ['@doctrine.dbal.default_connection', '%database_prefix%'] # services: # Foo\Repository\: # resource: '../../src/Repository/*' # public: true and this is my ProductRepository.php file: <?php // src/Repository/ProductRepository.php namespace Foo\Repository; use Doctrine\DBAL\Connection; class ProductRepository { /** * @var Connection the Database connection. */ private $connection; /** * @var string the Database prefix. */ private $databasePrefix; public function __construct(Connection $connection, $databasePrefix) { $this->connection = $connection; $this->databasePrefix = $databasePrefix; } /** * @param int $langId the lang id * @return array the list of products */ public function findAllbyLangId(int $langId) { $prefix = $this->databasePrefix; $productTable = "${prefix}product"; $productLangTable = "${prefix}product_lang"; $query = "SELECT p.* FROM ${productTable} p LEFT JOIN ${productLangTable} pl ON (p.`id_product` = pl.`id_product`) WHERE pl.`id_lang` = :langId"; $statement = $this->connection->prepare($query); $statement->bindValue('langId', $langId); $statement->execute(); return $statement->fetchAll(); } } this is my directory tree: foo ├── config │ └── services.yml ├── foo.php └── src └── Repository └── ProductRepository.php I hope someone can help me, thanks Link to comment Share on other sites More sharing options...
PMunoz92 Posted October 25, 2018 Author Share Posted October 25, 2018 fixed adding at the top require_once _PS_MODULE_DIR_.'test/Repository/ProductRepository.php'; 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