Zend certified PHP/Magento developer

Store wih diferent languages have broken images after programmatically product import

I have a script running in cron to import products.

This import creates simple products and then creates a configurable one with all these simple ones as children of that.

During this process, I insert images into the simple and configurable products and on the store’s home page I list some of the products in a carrousel.

My store has three languages. EN, PT and FR. I created a controller where I can access the import script via a browser. When I run the script with the language in PT at the store’s home, the images appear only in the PT language and in FR and EN the images are broken. If I run the script in EN, the images are broken in PT and FR and so on.

I tried using $magentoProduct->setStoresIds($storesIds) by passing an array of store ids to the products, but got no results.

I fetch my stores with:

$storesManager = $this->_objectManager->create(StoreManagerInterface::class);
/**
* @var $stores MagentoStoreModelStoreInterceptor
*/
$stores = $storesManager->getStores();
if($stores){
   foreach ($stores as $store){
      $this->storesId[] = $store->getEntityId();
   }
}