You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Magento 2结账侧边栏需求:为vecocraft-ebikes.de产品添加详情页链接

Hey there! Let's walk through how to add clickable links to the product thumbnails and names in your Magento 2 checkout sidebar. Here's a practical, step-by-step approach:

1. Locate the Checkout Sidebar Template

First, find the template that renders the checkout sidebar items. By default, this lives at:
vendor/magento/module-checkout/view/frontend/web/template/summary/item/details.html

Open the details.html file and modify the thumbnail and product name sections to include anchor tags. We'll bind these tags to a product URL we'll add next.

For the Product Thumbnail:

Replace the existing image code with this:

<a data-bind="attr: { href: item_data.product_url }">
    <img data-bind="attr: {src: item_data.product_image.src, alt: item_data.product_image.alt}" />
</a>

For the Product Name:

Update the name element to be wrapped in a link:

<a data-bind="attr: { href: item_data.product_url }, text: item_data.name"></a>

3. Add the Product URL to Checkout Item Data

The product_url we referenced in the template isn't available by default, so we need to extend the checkout config provider to include it. We'll use a plugin for this (best practice to avoid core file edits).

Create a Custom Module (if you don't have one)

If you don't already have a custom module, create one first. Then add these files:

1. etc/frontend/di.xml

This file registers our plugin:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\DefaultConfigProvider">
        <plugin name="add_product_url_to_checkout_summary" type="YourVendor\YourModule\Plugin\Checkout\DefaultConfigProviderPlugin" />
    </type>
</config>

2. Plugin/Checkout/DefaultConfigProviderPlugin.php

This plugin adds the product URL to each checkout item:

<?php
namespace YourVendor\YourModule\Plugin\Checkout;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\UrlInterface;

class DefaultConfigProviderPlugin
{
    protected $productRepository;
    protected $urlBuilder;

    public function __construct(
        ProductRepositoryInterface $productRepository,
        UrlInterface $urlBuilder
    ) {
        $this->productRepository = $productRepository;
        $this->urlBuilder = $urlBuilder;
    }

    public function afterGetConfig(\Magento\Checkout\Model\DefaultConfigProvider $subject, $result)
    {
        foreach ($result['totalsData']['items'] as &$item) {
            try {
                $product = $this->productRepository->getById($item['product_id']);
                $item['product_url'] = $this->urlBuilder->getUrl('catalog/product/view', ['id' => $product->getId()]);
            } catch (\Exception $e) {
                // Fallback if product isn't found
                $item['product_url'] = '#';
            }
        }
        return $result;
    }
}

4. Deploy Static Content and Clear Cache

Run these commands to apply your changes:

php bin/magento setup:static-content:deploy
php bin/magento cache:clean
php bin/magento cache:flush

5. Test the Changes

Head over to your checkout page, add a product to the cart, and check the sidebar. You should now be able to click either the product thumbnail or name to navigate straight to the product detail page!

Quick Notes:

  • Never edit core Magento files directly—using a custom module ensures your changes survive Magento updates.
  • Always test these changes in a staging environment first before pushing to production.

内容的提问来源于stack exchange,提问作者Sanjeev Kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:45:46