Skip to main content
19 votes

Best Way Of Getting Base URL Inside KnockoutJS .html File

I managed to do this in app/design/frontend/<Vendor>/<Theme>/Magento_OfflinePayments/web/template/<Filename>.html, but the solution should work in the Magento_Checkout as well. When ...
simonthesorcerer's user avatar
18 votes

Magento 2 - Add new attribute (delivery_time) to recently viewed widget

I managed to figure this out (albeit using reviews as a source of inspiration). This has been tested and is working on Magento 2.3.3 Namespace/Module/etc/di.xml <?xml version="1.0"?> <...
Dan Norris's user avatar
15 votes
Accepted

magento2 check if customer is logged in or not in knockout template

You need to pass dependency of customer object, 'Magento_Customer/js/model/customer', define( [ 'ko', 'jquery', 'Magento_Customer/js/model/customer', 'mage/translate' ], function (...
Rakesh Jesadiya's user avatar
15 votes

Magento 2 : External link in admin order grid not linking when click

If You are using custom class for rendering column ( for example <column name="link" class="My\Module\Ui\Component\Listing\Column\Link">) which convert your column value to link html along with ...
Pavel  Sidorenko's user avatar
14 votes

Magento 2.4.3 - Checkout JS knockout error - renderReCaptcha

This is a known core bug. Please see here: https://github.com/magento/magento2/issues/33741 The fix itself: https://github.com/magento/security-package/pull/302/files
Roman Snitko's user avatar
12 votes
Accepted

Best Way Of Getting Base URL Inside KnockoutJS .html File

There are three parts to this, I will use the checkout authentication as an example but this should work in any KO/JS file that has mage/url as a dependency. vendor/magento/module-checkout/view/...
Ben Crook's user avatar
  • 15.7k
10 votes
Accepted

Magento 2 custom module override knockout template

Yes you can override a knockout template in a custom module, just did it, in your module create a requirejs-config.js file and place it in your module: app/code/Namespace/Module/view/frontend/...
SantiBM's user avatar
  • 1,361
8 votes
Accepted

Add custom javascript in afterRender in Magento 2 with knockout

The afterRender method calls the specified method (test) of your component. So for your case you must define the test method inside the minicart component. You must add a mixin for the vendor/magento/...
Siarhey Uchukhlebau's user avatar
7 votes

Magento 2 : External link in admin order grid not linking when click

I had the same issue for UI grid and resolved it by rewriting component for current cell: Vendor/MyModule/view/adminhtml/ui_component/my_grid_listing.xml file: <column name="link"> <...
Maria Baraulia's user avatar
5 votes

Magento 2 : From where and how does knockout retrieve data on checkout

Here are answers to your query: What/Where is this persistence storage: If we look at dependancy injection of current model, "storage" is an alias of "Magento_Customer/js/customer-data" js model. By ...
PROGOSTECH's user avatar
5 votes
Accepted

Magento 2 : Access ko observable variable into other js file

Quick solution Change kotemplate.temp to kotemplate.temp(), when getting the value from a KO observable you need to include the parenthesis. This method is much shorter but isn't quite as easy to ...
Ben Crook's user avatar
  • 15.7k
4 votes

How to make observable array in knockout js model and bind it to html via view js in magento2

In your model file declare a variable like this. define(['ko'], function(ko) { 'use strict'; var array1 = ko.observable([]); var array2 = ko.observable([]); return { array1: ...
Rakesh Varma's user avatar
  • 2,226
4 votes

Magento 2.4.3 - Checkout JS knockout error - renderReCaptcha

Update answer for Zankar and jkulig: This is correct and full answer: Create new module: app/code/Vendor/ReCaptchaFrontendUi/registration.php <?php \Magento\Framework\Component\ComponentRegistrar:...
fudu's user avatar
  • 1,288
3 votes
Accepted

How to understand KnowkOutJs in Magento 2?

You can refer following link and videos using these you can get basic idea of how to use knockout js and also require js in magento 2. https://www.mage2.tv/content/javascript/
Pragnadeep Pitroda's user avatar
3 votes
Accepted

Can anyone explain <item name="customEntry" xsi:type="string">shippingAddress.region</item> this line how workin checkout page in magento2?

This line is part of the checkout layout handle (checkout_index_index.xml): <!-- code above --> <item name="region_id" xsi:type="array"> <item name="component" xsi:type="string">...
Marjan's user avatar
  • 1,139
3 votes

Magento 2 Knockout variable from response in controller via ajax

If your create your custom uicomponent like below <script type="text/x-magento-init"> { "*":{ "Magento_Ui/js/core/app": { "...
Herve Tribouilloy's user avatar
3 votes
Accepted

Magento 2 : Knockoutjs data-bind not Working in Inner Loop

That's because you have added an additional layer, so $parent is now referencing the inner loop not the outer loop. To access the outer loop again try $parents[1]. See https://stackoverflow.com/...
Ben Crook's user avatar
  • 15.7k
2 votes

Best Way Of Getting Base URL Inside KnockoutJS .html File

Using checkout and checkoutConfig global variable, I couldn't able to get the baseUrl. What I did was, I just added new global variable for baseUrl in my custom module overriding \Magento\Checkout\...
TS Guhan's user avatar
  • 369
2 votes
Accepted

How to change a qty text in Minicart?

Override default.html to your theme From vendor/magento/module-checkout/view/frontend/web/template/minicart/item/default.html TOapp/design/frontend/Vendor/theme/Magento_Checkout/web/template/...
Prince Patel's user avatar
  • 22.8k
2 votes

Magento2 : How to display custom values in checkout page

You want to add window.checkoutConfig then you need to create a plugin on Magento\Checkout\Model\DefaultConfigProvider. Create after method on getConfig() afterGetConfig and add pass you array as ...
Amit Bera's user avatar
  • 77.6k
2 votes

Can anyone explain <item name="customEntry" xsi:type="string">shippingAddress.region</item> this line how workin checkout page in magento2?

Motivation for customEntry Marjan's answer is excellent, but I was also curious about the functional purpose of the customEntry property within UI component configuration. As it turns out, UI dropdown ...
RNanoware's user avatar
  • 471
2 votes
Accepted

Magento2 - How to apply new field without page refresh in checkout summary page?

I was solved that issue using below code. jQuery( "#radio-button-id" ).change(function() { var id = this.id; require([ 'jquery', 'Magento_Checkout/js/action/get-totals' ...
Anas Mansuri's user avatar
  • 2,627
2 votes
Accepted

Magento 2: Knockout js dynamic content binding issue

You need to rebind knockout events by applyBindings before setting HTML content getDealers: function () { var dist = jQuery("#distance").val(); jQuery.ajax({ showLoader: true, ...
Prince Patel's user avatar
  • 22.8k
2 votes

Get config value in html using knockoutjs

Create Helper For Accessing System Configuration Values Here you would just create a helper that has some methods for fetching the system config values you want. \Magento\Framework\App\Helper\...
sdaugherty's user avatar
  • 1,231
2 votes

Magento 2.3 display logged in/out message using private content

Narendra certainly pointed me in the right direction. Here is a complete example. https://github.com/DominicWatts/CustomerLogin/blob/master/view/frontend/templates/index/index.phtml <div class="...
Dominic Pixie's user avatar
2 votes
Accepted

How to call knockout functions from html (Magento 2)

I think a ko tags must be closed, like: <!-- ko rvStorage() --><!-- /ko --> <!-- ko foreach: { data: recently(), as: 'productView' } --> <li class="product-item" >...
Siarhey Uchukhlebau's user avatar
2 votes
Accepted

How to translate text in shipping-estimation.html

I think I found a solution that works for me at least. My translation file is in: app/design/frontend/**MyPackage**/**MyTheme**/i18n/XX_XX.csv I added the string there. Then I copied this file to ...
Webninja's user avatar
  • 1,593
2 votes

Get subtotals excluding tax for each Tax Rate in Cart summary - Magento 2

Hay yesss, I found a solution so I'm answering to myself, maybe this will be usefull to someone else with the same needing. N.B. Sorry if the code is not too much pretty, since I'm not a developer... ...
vvave vvave's user avatar
2 votes
Accepted

Magento 2: I want to get product id from getCartItems function in minicart.js

You can use undescore each function to get product id from items. _.each(items, function (item, key) { console.log(item.product_id); }, this); So you final code looks like: define([ '...
Prince Patel's user avatar
  • 22.8k

Only top scored, non community-wiki answers of a minimum length are eligible