1

君の力が必要!製品 ID を使用して画像へのパスを取得するにはどうすればよいですか?

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));
4

3 に答える 3

3

をご覧くださいLink::getImageLink()。これは、製品の画像の URL を取得するために使用する必要がある方法です。

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

このメソッドは、同じ構文で必要な場合はテンプレートでも使用できます

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

編集 あなたの質問を読み直して、あなたがそれを知っていることに気づきました。そうですね、最初のパラメータは link_rewrite. お役に立てれば

于 2013-05-15T12:24:27.600 に答える
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')}"  />
于 2013-11-09T07:17:32.123 に答える
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'];
}

ステップ 2: 次に、次のようなコードでイメージ パスを取得します。

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

注意: $product は、SQL ステートメントの実行から得られる配列です。

于 2015-07-09T21:33:25.647 に答える