Jump to content


New Members
  • Posts

  • Joined

  • Last visited

Everything posted by Archalia

  1. ok it seems the proper way to do this is: $product = new Product($id, false, $lang); $img = $product->getCover($id); $url = Context::getContext()->link->getImageLink(isset($product->link_rewrite) ? $product->link_rewrite : $product->name, (int) $img['id_image'], 'small_default');
  2. Hello guys, I want to display the thumbnail of a given Product within an Admin page built with symfony. I am doing it this way: $product = new Product($id, false, $lang); $imageProduct = new Image($product->getCover($id)['id_image']); $img = ImageManager::thumbnail( _PS_IMG_DIR_ . 'p/' . $imageProduct->getExistingImgPath() . '.jpg', 'product_small_' . $id . '.jpg', 45, 'jpg' ); the result is: <img src="../img/tmp/product_small_1.jpg?time=1599958131" alt="" class="imgm img-thumbnail"> but the path is invalid, this one works : /img/tmp/product_small_1.jpg?time=1599958131 Do you know why I don't get the correct path in the first place ? Am I doing it wrong ?
  3. Hello guys, I am trying to create a custom Grid ColumnType. But I have an error explaining symfony can't find my new template inside my module's code. (An exception has been thrown during the rendering of a template ("Content template for column type "likes" was not found")). But the thing is, it works fine locally, but not on my remote test server. I tried to clear cache but can't manage to make it work over there. When I manually return : "return '@Modules/mymodule/views/Prestashop/Admin/Common/Grid/Columns/Content/likes.html.twig';" in GridExtension::getTemplatePath() it works... I don't understand what's going on, why twig can't find my override ? namespace XXXX\YYY\Grid\Column\Type\Common; use PrestaShop\PrestaShop\Core\Grid\Column\AbstractColumn; use Symfony\Component\OptionsResolver\OptionsResolver; final class LikesColumn extends AbstractColumn { /** * {@inheritdoc} */ public function getType() { return 'likes'; } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver ->setRequired([ 'field', ]) ->setDefaults([ 'clickable' => true, ]) ->setAllowedTypes('field', 'string') ; } } in: /modules/mymodule/views/Prestashop/Admin/Common/Grid/Columns/Content/likes.html.twig <div class="col-md-6"> <i class="material-icons">favorite</i> {{ record[column.options.field] }} </div>
  4. Hello guys, While creating a multishop module, I faced some troubles with the database queries. I wonder if there is any kind of helper that ease the process of retrieving data from a table that contains a shop_id column. What I do for now is something like: $qb = $this->connection ->createQueryBuilder() ->from($this->dbPrefix . 'gallery', 'g') ->where('g.shop_id = :id') ->setParameter('id', $this->context->getContext()->shop->id) ; So I inject the legacy context, and retrieve the currently selected shop. But the issue is, it does not work properly when the user selects "All shops" or an entire shop group because it will only select the default shop data. I saw some kind of helper tools that you can plug directly in your sql query but it does not work using query builder. Whats is the best way to do this ?
  5. Hello guys, I had trouble using this part of the documentation: https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/tabs/#automatic-tab-registration Because for me it just does not work for some reason. And IMO the example given in the documentation does not make any sense, why would you use the "AdminLinkWidget" as a legacy controller ? When we create a tab we want to create a specific link linked to a specific custom controller. So the automatic registration did not work, I had to create the tab manually private function installTab(): bool { $tabId = (int) Tab::getIdFromClassName('MyAdminController'); if (!$tabId) { $tabId = null; } $tab = new Tab($tabId); $tab->active = 1; $tab->class_name = 'MyAdminController'; $tab->route_name = 'instaev_admin_gallery_index'; $tab->name = []; foreach (Language::getLanguages() as $lang) { $tab->name[$lang['id_lang']] = 'Instaev'; } $tab->id_parent = (int) Tab::getIdFromClassName('CONFIGURE'); return $tab->save(); } instaev_admin_gallery_index: path: /instaev/home defaults: _controller: Hdclic\Instaev\Controller\GalleryController::indexAction _legacy_controller: MyAdminController _legacy_link: MyAdminController So instead of the AdminLinkWidget, I used my own. (MyAdminController). But I really would like to understand why the automatic registration does not work for me, and I want to implement it. The main issues I have triying to do it is @AdminSecurity("is_granted('read', request.get('_legacy_controller'))", message="Access denied.") which triggers an error because it seems I do not have the access it seems eventhough the install went well all the time. And the tab is not created on the side. Do you guys have the same issue ?
  6. Hello guys, I would like to register a new hook from a symfony service or controller of my module. To do this I need the Module instance. I tried this code: $module = $this->get('prestashop.adapter.legacy.module')->getInstance(); $module->registerHook(....); But for some reason the getInstance() method returns null. Am I doing something wrong ? I saw a ->getInstanceById method but it feels weird to me that the symfony code knows the module id I found a workaround using hooks. I dispatch a custom hook in my symfony code, and in my main module class, I register a new hook within the hook method because I have access to the module right here. But I don't like this solution very much I would rather register the hook directly from symfony. Thank you
  7. Hello guys, I am creating a module on the backoffice I wanted to display a page with the grid system but I cannot manage to make the filters and pagination work. So the grid displays itself quite well, but no button using javascript seems to work, ie seems to be triggered. None of the actions within the GridActionCollection work when I click on it, when I type stuff on the filters input and click Search it just refreshes my grid page with no filter in it. The delete option does not work neither. Weird stuff is when I edit in database directly the corresponding admin filter with a filter parameter or editing the limit value. Those filters are applied, meaning I can see the filter in the input, the grid is updated and the result count is the same as the limit. But the reset button does not do anything and the pagination is not triggered. I don't understand what is going on because I literally did exactly the same as the documentation says but does not work. I tried to duplicate an example from prestashop admin also, the log page for instance. Same result. It really seems to me that no js is linked to my grid template so nothing is triggered. Moreover in the documentation, you describe a search action to be implemented. But nowhere is described how this route is called and when. So I really don't understand the process of Grid filters. And for the admin_common_reset_search, it uses a controller value and action. It does not say where should we configure or set this controller value so it can match... class GalleryController extends FrameworkBundleAdminController { public function indexAction(GalleryFilters $filters) { return $this->render( '@Modules/instaev/views/templates/admin/index.html.twig', [ 'grid' => $this->presentGrid($this->get('hdclic.instaev.grid.factory.galleries')->getGrid($filters)), ] ); } public function searchAction(Request $request) { $definitionFactory = $this->get('hdclic.instaev.grid.definition.factory.galleries'); $galleriesDefinition = $definitionFactory->getDefinition(); $gridFilterFormFactory = $this->get('prestashop.core.grid.filter.form_factory'); $searchParametersForm = $gridFilterFormFactory->create($galleriesDefinition); $searchParametersForm->handleRequest($request); $filters = []; if ($searchParametersForm->isSubmitted()) { $filters = $searchParametersForm->getData(); } return $this->redirectToRoute('instaev_admin_gallery_index', ['filters' => $filters]); } ->add( (new Filter('actions', SearchAndResetType::class)) ->setTypeOptions([ 'attr' => [ 'data-url' => $this->resetActionUrl, 'data-redirect' => $this->redirectionUrl, ], ]) ->setAssociatedColumn('actions') ) please help ­čśó
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More