I'm using this code to retrieve all products "out of stock" and export them in a csv so I can use the "import" tab (behavior delete) to clean old products.
$productCollection = $obj->create('Magento\Catalog\Model\ResourceModel\Product\Collection');
$collection = $productCollection
->addAttributeToSelect('*')
//->setPageSize(700) //Selecting 500 products pour TEST plus rapide
->load();
echo "sku" . ';' . "name" . ';' . "mgs_brand" . ';' . "urbmag_season" . "\n";
foreach($collection as $product){
$productType = $product->getTypeId(); // regarde si CONFIGURABLE
if ($productType == "configurable" AND !$product->isAvailable()) { // CONF + OUT OF STOCK
$productSku = $product->getSku();
$productName = $product->getName();
$productBrand = $product->getAttributeText('mgs_brand');
$productSeason = $product->getAttributeText('urbmag_season');
echo $productSku.';'.$productName.';'.$productBrand.';'.$productSeason."\n";
$children = $product->getTypeInstance()->getUsedProducts($product); // simple associés
foreach ($children as $child) {
$childSku = $child->getSku();
$childName = $child->getName();
echo $childSku.';'.$childName.';'.$productBrand.';'.$productSeason."\n";
}
}
}
I like to add a column with the media path so I can delete images associated to the product. I'm looking for the command like $productImages = $product->getXXXXXXXXXXX();