Skip to content
Advertisement

Problem exporting XML multiple values on PHP 7.2 & Prestashop 1.7

I’m trying to export products from Prestashop 1.7 to an XML. Everything works great, but the script exports a product multiple times, depending on the categories that belongs to. For example Product1 is in All products – Clothes – Men , in this situation will be exported 3 times in XML.

I tried to use array_unique based on product ID but it doesn`t work. Can someone, please, point me to the right direction?

The full code can be found here: https://pastebin.com/MQxfYSj2

On this part of the code i tried to use array_unique with no result:

JavaScript

I also tried on the top of the script to get only unique products based on product ID, not working as well.

Other usefull info: PHP 7.2, Prestashop 1.7.6.5

Advertisement

Answer

Try to create an attribute in the very beginning of the class like

private $exportedProductsIds = [];

and then after each iteration put exported product id into it just before the return

JavaScript

and then add a verification before run if the id is already in the $exportedProductsIds then skip the iteration

JavaScript

But I think the best place to put this code would be that one where you call getProductFromArray method from.

I assume like this

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement