Wednesday, August 20, 2025
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy
T3llam
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment
No Result
View All Result
T3llam
No Result
View All Result
Home Services & Software

How one can use JS routing element in PrestaShop Backoffice

admin by admin
July 1, 2023
in Services & Software
0
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


On this weblog, we’ll discover ways to use the Javascript routing element within the PrestaShop again workplace. Because the 1.7.8.0 model, you need to use elements with out importing them. window.prestashop.element the thing is used for this objective.
These are some guidelines to grasp the JS element

i) Reusable elements in BO will probably be accessible globally by way of window.prestashop object.

ii) PrestaShop elements will probably be grouped collectively and made accessible on all pages. So you need to determine on the controller web page which elements have to initialize.

iii) Reusable elements will probably be accessible as a namespace window.prestashop.element.

iv) The namespace will include lessons like this prestashop.element.SomeComponent. If you wish to get a brand new occasion of SomeComponent, you name the brand new prestashop.element.SomeComponent(…params)

Trying to find an skilled
Prestashop Firm ?
Learn Extra


v) Reusable elements will probably be accessible as initialized cases by way of window.prestashop.occasion. These cases are initialized with default parameters by the initComponents operate.

vi) A operate initComponents accessible by way of prestashop.element is accountable for constructing window.prestashop.occasion.

Right here, we’re exhibiting the method step-by-step with an instance module ‘wkjsrouting‘

Step 1: Create the module class

Right here, now we have created the module class file “wkjsrouting/wkjsrouting.php“

On this class, we’re initializing the module and redirecting the configuration web page to fashionable web page routes.

<?php
declare(strict_types=1);

use PrestaShopModuleWkJsRoutingInstallInstaller;

if (!outlined('_PS_VERSION_')) {
    exit;
}

require_once __DIR__ . '/vendor/autoload.php';

class WkJsRouting extends Module
{
    public $tabs = [
        [
            'class_name' => 'DemoPageController',
            'visible' => true,
            'name' => 'Demo page',
            'parent_class_name' => 'CONFIGURE',
        ],
    ];

    public operate __construct()
    {
        $this->title = 'wkjsrouting';
        $this->writer = 'Webkul';
        $this->model = '1.0.0';
        $this->ps_versions_compliancy = ['min' => '1.7.7.0', 'max' => '8.99.99'];

        father or mother::__construct();

        $this->displayName = $this->l('Demo Module');
        $this->description = $this->l('Javascript element Router utilization in BO');
    }

    /**
     * @return bool
     */
    public operate set up()
    {
        if (!father or mother::set up()) {
            return false;
        }

        $installer = new Installer();

        return $installer->set up($this);
    }

    public operate getContent()
    {
        $moduleAdminLink = Context::getContext()->link->getAdminLink('DemoPageController', true);
        Instruments::redirectAdmin($moduleAdminLink);
    }
}

Step 2: Outline routes
Create routes.yml file contained in the wkjsrouting/config folder

demo_page_index:
    path: demo-page/
    strategies: [GET]
    defaults:
        _controller: PrestaShopModuleWkJsRoutingControllerDemoPageController::indexAction
        _legacy_controller: 'DemoPageController'
        _legacy_link: 'DemoPageController'

Step 3: Create a controller to deal with the JS request

Path: wkjsrouting/src/Controller/DemoPageController.php

<?php

declare(strict_types=1);

namespace PrestaShopModuleWkJsRoutingController;

use PrestaShopBundleControllerAdminFrameworkBundleAdminController;
use SymfonyComponentHttpFoundationResponse;

class DemoPageController extends FrameworkBundleAdminController
{
    public operate indexAction(): Response
    {
        return $this->render('@Modules/wkjsrouting/views/templates/admin/demo_page.html.twig');
    }
}

Step 4: Create an installer class

Path: wkjsrouting/src/Set up/Installer.php

<?php

declare(strict_types=1);

namespace PrestaShopModuleWkJsRoutingInstall;

use Module;

class Installer
{
    /**
     * Module's set up entry level.
     *
     * @param Module $module
     *
     * @return bool
     */
    public operate set up(Module $module): bool
    {
        if (!$this->registerHooks($module)) {
            return false;
        }

        return true;
    }

    /**
     * Register hooks for the module.
     *
     * @param Module $module
     *
     * @return bool
     */
    personal operate registerHooks(Module $module): bool
    {
        $hooks = [];

        return (bool) $module->registerHook($hooks);
    }
}

Step 5: Create a view

Twig file demo_page.html.twig, path: wkjsrouting/views/templates/admin/demo_page.html.twig

{% extends '@PrestaShop/Admin/format.html.twig' %}

{% block content material %}
  <div>
    <div class="form-group">
			<div class="row">
				<label class="col-lg-3 control-label text-right" for="demo_search_customer">
          {{ 'Search buyer'|trans({}, 'Modules.Wkjsrouting.Admin') }}
				</label>
				<div class="col-lg-6">
          <div class="input-group">
            <enter sort="textual content" class="form-control" id="demo_search_customer">
            <div class="input-group-addon"><button sort="button" class="btn btn-primary" id="demo_search_customer_btn"> {{ 'Search'|trans({}, 'Modules.Wkjsrouting.Admin') }}</button></div>
          </div>
				</div>
			</div>
		</div>
  </div>
  <div id="info-block" class="d-none"></div>
  <div id="customers-results" class="d-none">
    <desk class="desk table-striped">
      <thead>
        <tr>
          <th>{{ 'E-mail'|trans({}, 'Modules.Wkjsrouting.Admin') }}</th>
          <th>{{ 'Full Title'|trans({}, 'Modules.Wkjsrouting.Admin') }}</th>
        </tr>
      </thead>
      <tbody>
      </tbody>
    </desk>
  </div>
{% endblock %}

{% block javascripts %}
  {{ father or mother() }}
  <script src="https://webkul.com/weblog/how-to-use-js-routing-component-in-prestashop-backoffice/{{ asset("../modules/wkjsrouting/views/js/admin.js') }}"></script>
{% endblock %}

Step 6: JS file for routing

This file is accountable to make use of the PrestaShop JS element

Path: wkjsrouting/views/js/admin.js

$(() => {
    // initialize the Router element in PS 1.7.8+ 
    if (typeof window.prestashop.element !== 'undefined') { window.prestashop.element.initComponents(['Router']); }

    // provoke the search on button click on
    $(doc).on('click on', '#demo_search_customer_btn', () => search($('#demo_search_customer').val()));

    /**
     * Performs ajax request to seek for clients by search phrase
     *
     * @param searchPhrase
     */
    operate search(searchPhrase) {
        var route;
        var getParams = { 'customer_search': searchPhrase };

        if (typeof window.prestashop.element !== 'undefined') {
            // use the router element to generate the present route in PS 1.7.8+
            route = window.prestashop.occasion.router.generate('admin_customers_search');
        } else {
            // use pure JS features if PS search route element is unavailable
            const locationSearch = new URLSearchParams(window.location.search);
            const locationPathname = window.location.pathname.cut up('/');

            for (const param of locationSearch) {
                if (param[0] === '_token') getParams[param[0]] = param[1];
            }
            route = `${locationPathname[0]}/${locationPathname[1]}/promote/clients/search`;
        }

        // use the ajax request to get clients
        $.get(route, getParams
            // render the purchasers
        ).then((information) => renderResults(information));
    }

    /**
     * Renders the outcomes block
     *
     * @param {Object} information
     */
    operate renderResults(information) {
        var $infoBlock = $('#info-block')
        $infoBlock.addClass('d-none').empty();
        var $resultsBlock = $('#customers-results');
        var $resultsBody = $('#customers-results tbody');

        if (information.discovered === false) {
            $infoBlock.textual content('No clients discovered').removeClass('d-none');
            $resultsBlock.addClass('d-none');
            $resultsBody.empty();

            return;
        }

        $resultsBlock.removeClass('d-none');
        $resultsBody.empty();

        for (const id in information.clients) {
            const buyer = information.clients[id];
            $resultsBody.append(`<tr><td>${buyer.e mail}</td><td>${buyer.firstname} ${buyer.lastname}</td></tr>`);
        }
    }
});

Step 7: Create a composer.json file to put in the dependency

{
    "title": "prestashop/wkjsrouting",
    "description": "Demo Module",
    "license": "AFL-3.0",
    "authors": [{
            "name": "Webkul"
        },
        {
            "name": "dev"
        }
    ],
    "autoload": {
        "psr-4": {
            "PrestaShopModuleWkJsRouting": "src/"
        },
        "config": {
            "prepend-autoloader": false
        },
        "sort": "prestashop-module"
    }
}

Step 8: Set up

Copy created a module on the modules listing of PrestaShop and run the composer command composer set up to put in all dependencies. The whole module folder construction is hooked up within the screenshot.

folder_structure

After putting in the module, click on on configure button, and you’ll capable of see the search web page and search clients by title.

output
routing_results

That’s all about this weblog.

If any points or doubts please be happy to say them within the remark part.

I’d be comfortable to assist.

Additionally, you may discover our PrestaShop Growth Companies & a wide range of high quality PrestaShop Modules.

author-thumb


Amit Kumar Tiwari
3 Badges

30 June 2023

RelatedPosts

The state of strategic portfolio administration

The state of strategic portfolio administration

June 11, 2025
You should utilize PSVR 2 controllers together with your Apple Imaginative and prescient Professional – however you’ll want to purchase a PSVR 2 headset as properly

You should utilize PSVR 2 controllers together with your Apple Imaginative and prescient Professional – however you’ll want to purchase a PSVR 2 headset as properly

June 11, 2025
Consumer Information For Magento 2 Market Limit Vendor Product

Consumer Information For Magento 2 Market Limit Vendor Product

June 11, 2025
Previous Post

Gmail spammers are successful the warfare in your inbox

Next Post

FTC vs. Microsoft: Every part to know in regards to the Xbox-Activision deal

Next Post

FTC vs. Microsoft: Every part to know in regards to the Xbox-Activision deal

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • App (3,061)
  • Computing (4,401)
  • Gaming (9,599)
  • Home entertainment (633)
  • IOS (9,534)
  • Mobile (11,881)
  • Services & Software (4,006)
  • Tech (5,315)
  • Uncategorized (4)

Recent Posts

  • WWDC 2025 Rumor Report Card: Which Leaks Had been Proper or Unsuitable?
  • The state of strategic portfolio administration
  • 51 of the Greatest TV Exhibits on Netflix That Will Maintain You Entertained
  • ‘We’re previous the occasion horizon’: Sam Altman thinks superintelligence is inside our grasp and makes 3 daring predictions for the way forward for AI and robotics
  • Snap will launch its AR glasses known as Specs subsequent 12 months, and these can be commercially accessible
  • App
  • Computing
  • Gaming
  • Home entertainment
  • IOS
  • Mobile
  • Services & Software
  • Tech
  • Uncategorized
  • Home
  • About Us
  • Disclaimer
  • Contact Us
  • Terms & Conditions
  • Privacy Policy

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • App
  • Mobile
    • IOS
  • Gaming
  • Computing
  • Tech
  • Services & Software
  • Home entertainment

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.
Cookie settingsACCEPT
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
CookieDurationDescription
cookielawinfo-checkbox-analyticsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functionalThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessaryThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-othersThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performanceThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policyThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Save & Accept