Jump to content

Invalid argument foreach() - translation


Recommended Posts

Hello,

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

trans-error.thumb.png.714ac278356373ce3b08e594ac9cfa0f.png

 

 

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.

image.thumb.png.a2bda1fae5f7e67f83debf3c3d8afa41.png

 

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))
        	->assembleProduct($product);
		$presenterFactory = new ProductPresenterFactory($this->context);
        $presentationSettings = $presenterFactory->getPresentationSettings();
        $presenter = new ProductListingPresenter(
        	new ImageRetriever(
            	$this->context->link
			),
            $this->context->link,
            new PriceFormatter(),
            new ProductColorsRetriever(),
            $this->context->getTranslator()
		);
        $template_products[] = $presenter->present(
			$presentationSettings,
            $product,
            $this->context->language
		);
	}

    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.

https://github.com/PrestaShop/PrestaShop/issues/12295

 

Thanks for any help

Edited by sakonn
Specifing problem (see edit history)
Link to comment
Share on other sites

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

if(is_array($products)){
	foreach($products as $product){
	...	
	}
}

This fixed the back end translation page also.

Link to comment
Share on other sites

  • 2 years later...
On 2/7/2020 at 4:35 PM, JBW said:

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

I believe he buy the theme from templatemonster, Cuz I had purchased from it as well, same thing happened , after sales may not help him to fix for their responsibility @sakonn

Edited by weasam (see edit history)
Link to comment
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...