2013-05-15 2 views
1

당신의 도움이 필요합니다! 제품 ID로 이미지 경로를 얻으려면 어떻게해야합니까?이미지 경로 받기 prestashop 1.5

Link :: getImageLink() - $ name의 첫 번째 매개 변수는 무엇입니까?

$searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); 
foreach ($searchResults as &$product) 
{ 
    $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); 
    $imageid = Product::getCover($product['id_product']); 
    // there i have image ID, how get image path $imagepath? 
    $product['image'] = $imagepath; 
} 
die(Tools::jsonEncode($searchResults)); 

답변

3

Link::getImageLink()을 살펴보십시오. 이것은 제품 이미지의 URL을 가지고 사용해야하는 방법입니다. 같은 구문

{$link->getImageLink($product.link_rewrite, $product.id_product, 'home_default')}` 

편집 내가 질문을 다시 읽고 당신이 그것을 알고 실현에 필요하면

$imagePath = Link::getImageLink($product['link_rewrite'], $product['id_product'], 'home_default'); // change the last parameters to get the size you need 

이 방법

또한 템플릿에서 사용할 수 있습니다. 그래서 첫 번째 매개 변수는 link_rewrite입니다. 희망이 도움이

0

& 올바르게 매개 변수를 전달하십시오 (이 코드를 따르면 URL 재 작성이 활성화되었을 때 문제가 발생하지 않습니다). 매개 변수의

{$link->getImageLink($name, $ids, $type = NULL) } 

세부

@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 

예처럼에 대한 당신

<img src="{$link->getImageLink($product.link_rewrite, $image.id_image, 'large_default')}" /> 
0

1 단계 : 당신이 id_product이있는 경우, 다음과 같이 당신에게 id_image 속성을 가져 오는 함수를 작성 :

private static function getCover($product_id) { 
    $sql = 'SELECT id_image FROM '._DB_PREFIX_.'image WHERE cover = 1 AND id_product='.$product_id; 
    $result = Db::getInstance()->getRow($sql); 
    return $result['id_image']; 
} 

STEP 2 :

$id_image = self::getCover($product['id_product']); 
$image_path = $id_image.'-home_default/'.$product['link_rewrite'].'.jpg'; 

NB : : 다음과 같은 코드 이미지 경로를 얻을 $ 생성물은 SQL 명령문을 실행

로부터 입수 어레이 A는
관련 문제