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
            //->setPageSize(700) //Selecting 500 products pour TEST plus rapide
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();


Try this:

$productImages = $this->helper('Magento\Catalog\Helper\Image')->init($product, 'product_page_image_large')->getUrl();

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.