Jump to content

How to get a product list inside product form?


warlocker
 Share

Recommended Posts

One of my clientes wants to avoid duplicate names. I know that some solution to do this would be complex but I had a simpler solution on mind.

 

My idea for this would be a foreach on form.tpl that would allow me to put every added product name as a item of a javascript array, so I could make jquery check on form.tpl to check if the "name" text input has the same content of any item of the javascript array.

 

But I am new to prestashop... I still do not know exactly which file, controller or class I should edit to allow me to put a {foreach} on the backend form using prestashop syntax. 

 
I believe its controllers/admin/AdminProductsController.php but I am not sure.
 
I found this code as example.
 
$products = Product::getProducts($this->context->language->id, 0, 100);
$products_all = Product::getProductsProperties($this->context->language->id, $products);
$this->context->smarty->assign(array(
        'products' => $products_all
));

To avoid messing with existing vars I even tried to change it:

$productz = Product::getProducts($this->context->language->id, 0, 100);
$productz_all = Product::getProductsProperties($this->context->language->id, $productz);
$this->context->smarty->assign(array(
        'productz' => $productz_all
));
This dont work so far. If I put it as a function I do not have idea about how to call it on .tpl.. and if I put it inside a existing function it breaks the backend....
 
Could anyone please help me to make my code work? how the PHP should be? And where I should put it?
 
And how the foreach should be on .tpl? I saw several different examples of foreach using smarty syntax.
 
Thank you for your help.
Edited by warlocker (see edit history)

Share this post


Link to post
Share on other sites

There are many examples on how to integrate javascript with a module or code. Just look into your modules folder. However I have doubts this will still work once you have a higher number of products. Every product would add to processing time and it could then be a show stopper.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

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