AfterGlow93 Posted April 5, 2023 Share Posted April 5, 2023 Hello, I am working on my car parts retail shop. To get prices and stock available in realtime, i built a script which process suppliers page and scrape live data from suppliers (they don't have any api or way to retrieve it by another way). Script generates a combination by suppliers with quantity and prices if it doesn't exists, else, updates existing combination with price and quantity available. Script is working perfectly. What i am looking to do now, is to pass product_id when product_details page is loading, and execute script for a given product_id. I already built the function using $_GET['productid']. But i can't find a hook which can be used before product is loaded. Does the actionPresentProduct hook can do the job for it ? Or should i override product presenter to include call of the function i need ? I want to avoid script to launch while browsing on product lists, i want it only on product details. Thanks for help Link to comment Share on other sites More sharing options...
WebDesk Solution Posted May 22 Share Posted May 22 Hello @AfterGlow93, To load a script before the product details page in PrestaShop, follow these steps: Navigate to the root directory of your project, then go to "themes/{{your_theme}}/assets/js". Place your JavaScript file in this location Navigate to the "themes/{{your_theme}}/templates/catalog" directory and find the "product.tpl" file. Add the following code: {if isset($page.page_name) && $page.page_name == 'product'} <script src="{$urls.js_url}{{your_script_name}}"></script> {/if} Make sure to replace "{{your_script_name}}" with the name of your JavaScript file. After making these changes, you may need to clear the cache. I hope this helps! 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