<?php

namespace Leadlion\Autogedal\Block\Product\View;

class GalleryPlugin
{
    /**
     * Retrieve product images in JSON format
     *
     * @return string
     */
    public function afterGetGalleryImagesJson(
        \Magento\Catalog\Block\Product\View\Gallery $subject,
        $result
    ) {
        $result = json_decode($result);
        $counter = 1;
        foreach ($result as $image) {
            $image->caption .= ' '.$counter;
            $counter++;
        }
        return json_encode($result);
    }
}
