<?php

class Link extends LinkCore
{
    /**
     * Returns a link to a product image for display
     * Note: the new image filesystem stores product images in subdirectories of img/p/
     *
     * @param string $name rewrite link of the image
     * @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new)
     * @param string $type
     * @return string
     */
    public function getImageLink($name, $ids, $type = null)
    {
        $sizes = Image::getSize($type);

        $split_ids = explode('-', $ids);
        $id_image = end($split_ids);
        $customized_images = SwissStyle\Builder\Controller\Builder::getCustomizedImages( [$id_image], $sizes['width'], $sizes['height']);

        if ($customized_images[$id_image]) {
            return $customized_images[$id_image];
        } else {
            return parent::getImageLink($name, $ids, $type);
        }
    }
}