Skip to content

Commit

Permalink
force placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
Stubbe committed Oct 14, 2024
1 parent b947eb4 commit 50ae03b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions helpers/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,11 @@ private static function getImageUrl($product, $product_id, $shop_id, $language_i
$image_instance = Image::getCover($product_id);
$size = ProductHelper::getImageSize($shop_id, $language_id);
$link_rewrite = ProductHelper::getFieldMultiLang($product->link_rewrite, $language_id);
$product_image = $context->link->getImageLink($link_rewrite, $image_instance['id_image'], $size);

// Run through placeholder function to fix bad paths before return
return ProductHelper::getPlaceholderImageUrl($context, $product_image, $size);
if(is_array($image_instance) && array_key_exists('id_image', $image_instance)){
$product_image = $context->link->getImageLink($link_rewrite, $image_instance['id_image'], $size);
return ProductHelper::getPlaceholderImageUrl($context, $product_image, $size, false);
}
return ProductHelper::getPlaceholderImageUrl($context, "", $size, true);
}

/**
Expand Down Expand Up @@ -170,13 +171,18 @@ private static function getImageSize($shop_id, $language_id){
}
}

private static function getPlaceholderImageUrl($context, $product_image, $image_type)
private static function getPlaceholderImageUrl($context, $product_image, $image_type, $force_placeholder = false)
{
$placeholder_image = _PS_BASE_URL_ . '/img/p/' . $context->language->iso_code . '-default-' . $image_type . '.jpg';
if($force_placeholder){
return $placeholder_image;
}

// Set placeholder image if bad pattern
$base_domain = explode('//', _PS_BASE_URL_)[1];
$image_check = substr(explode($base_domain, $product_image)[1], 0, 2);
if ('/-' === $image_check) {
$product_image = _PS_BASE_URL_ . '/img/p/' . $context->language->iso_code . '-default-' . $image_type . '.jpg';
$product_image = $placeholder_image;
}
return $product_image;
}
Expand Down

0 comments on commit 50ae03b

Please sign in to comment.