Jump to content

Invalid argument foreach() - translation

Recommended Posts


I am on prestashop  and using custom theme which I want to translate but I am getting the error and blank translation screen.




Except that I have found that when I swich front end of my store to different language it's not working and throwing this error.



I am not sure if it's related to translations of not, but this code is causing it:

# The function itself
protected function buildTemplateProduct($products)
	$template_products = [];
    foreach ($products as $product) {
    	$product = (new ProductAssembler($this->context))
		$presenterFactory = new ProductPresenterFactory($this->context);
        $presentationSettings = $presenterFactory->getPresentationSettings();
        $presenter = new ProductListingPresenter(
        	new ImageRetriever(
            new PriceFormatter(),
            new ProductColorsRetriever(),
        $template_products[] = $presenter->present(

    return $template_products;

# The products array is deffined at different place but this is the content
$products = $category->getProducts(
	(int)$this->context->language->id, 1, (int)$block['num'], 'date_add', 'ASC'


I found the for each error resolved here but I didn't find right code to modify.



Thanks for any help

Edited by sakonn
Specifing problem (see edit history)

Share this post

Link to post
Share on other sites

Jxcategoryproducts sounds like a 3rd party Module - please contact the module deveolper. In the meantime you could try disabling the module while doing translation.

Share this post

Link to post
Share on other sites

I found the error in the module and fixed it. It was enough to check the $products variable before foreach function.

	foreach($products as $product){

This fixed the back end translation page also.

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
  • Create New...

Important Information

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