Back to PhocacartImage class

Method getImageChangedByAttributes

public static
getImageChangedByAttributes
(mixed $attributes, mixed $imageSize)

Method getImageChangedByAttributes - Source code

/*
 * Attribute was selected by vendor in administration - it is default attribute
 * Displayed in category or item view when the page is loaded, the default attribute image is displayed
 */
public static function getImageChangedByAttributes($attributes, $imageSize)
{
    $paramsC = PhocacartUtils::getComponentParameters();
    $display_attribute_image = $paramsC->get('display_attribute_image', 1);
    if ($display_attribute_image == 0) {
        return '';
    }
    $image = '';
    if (!empty($attributes)) {
        foreach ($attributes as $k => $v) {
            if (!empty($v->options)) {
                foreach ($v->options as $k2 => $v2) {
                    // Is the options set as default
                    if (isset($v2->default_value) && $v2->default_value == 1) {
                        switch ($imageSize) {
                            case 'small':
                                if (isset($v2->image_small) && $v2->image_small != '') {
                                    $image = $v2->image_small;
                                    break 2;
                                }
                                break;
                            case 'medium':
                            // !!!!
                            // In options when we select image, it has 3 thumbnails
                            // so $v2->image has three thumbnails, we ask for image and then we transform to thumbnail we need
                            /*case 'medium':
                                  if (isset($v2->image_medium) &&  $v2->image_medium != '') {
                                      $image = $v2->image_medium;
                                      break 2;
                                  }
                              break;*/
                            case 'large':
                            default:
                                if (isset($v2->image) && $v2->image != '') {
                                    $image = $v2->image;
                                    break 3;
                                }
                                break;
                        }
                    }
                }
            }
        }
    }
    return $image;
}