0

I want to add link on the product which is showing in order summary on checkout page.

I have found HTML code in the file:

module-checkout\view\frontend\web\template\summary\item\details.html

Code:

<div class="product-item-name-block">
            <strong class="product-item-name" data-bind="text: $parent.name"></strong>
            <div class="details-qty">
                <span class="label"><!-- ko i18n: 'Qty' --><!-- /ko --></span>
                <span class="value" data-bind="text: $parent.qty"></span>
            </div>
        </div>

How to add href for the product name?

1

You need plugin for for class for class

Magento\Checkout\Block\Checkout\LayoutProcessor

On your plugin class ,you need pass product url as parameter of json object which is used at checkout summary

Please follow the folder and file from the blog http://www.blogtreat.com/magento-2-display-custom-product-attribute-checkout-summary/

Then you need to some changes at

$result['quoteItemData'][$index]['brand'] = $product->getResource()->getAttribute('brand')->getFrontend()->getValue($product);

to

$result['quoteItemData'][$index]['url'] = $product->getProductUrl().

Also on new summary.html you need to put url

<strong class="product-item-name" data-bind="text: $parent.name"></strong>
  • Hi, I have tried this but after that checkout is not working. – Vinod Kumar Mar 28 '18 at 6:16
  • Okay, i will look on it – Amit Bera Mar 28 '18 at 7:14
  • <strong class="product-item-name" data-bind="text: $parent.name"></strong> how to pass URL? – Vinod Kumar Mar 28 '18 at 9:12
  • have you got anything? – Ketan Borada Apr 26 '18 at 11:08
  • how to add custom phtml page link in checkout page..please help me.. if i am clicking that it have to redirect to another page – SUBBULAKSHMI G Oct 29 '18 at 13:33
1

It is working.

In details.js I replaced

getBrand: function(quoteItem) {
    var item = this.getItem(quoteItem.item_id);
    return item.brand;
},

with

getUrl: function(quoteItem) {
    var item = this.getItem(quoteItem.item_id);
    return item.url;
},

In details.html file changed the

<strong class="product-item-name" data-bind="text: $parent.name"></strong>

to

<a target="_blank" data-bind="attr: { href: getUrl($parent) }">
    <strong class="product-item-name" data-bind="text: $parent.name"></strong>
</a>

and removed the code

<!-- ko if: (getBrand($parent)) -->
<div class="product-item-brand">
    <span class="label"><!-- ko i18n: 'Brand:' --><!-- /ko --></span>
    <span class="value" data-bind="text: getBrand($parent)"></span>
</div>
<!-- /ko -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.