Spring '21 リリースにより、ユーザは Lightning Message Service (LMS) チャネルを使用して、Commerce カートの状態の変更に関する通知を一律に公開および登録できます。LMS チャネル「lightning__commerce_cartChanged」を使用すると、ユーザはカートの変更時にすべての標準 Commerce コンポーネントに通知できます。この通知により、関連するすべてのコンポーネントがトリガされ、それに合わせてデータが更新されます。LMS チャネルは、カスタムコンポーネントと OOTB のインテグレーションの推奨される長期的なソリューションです。
「cartchanged」DOM イベントは、今後のリリース (セーフハーバー) でサポートされなくなります。
詳細や詳しいガイダンスは、Lightning Message Service ドキュメントを参照してください。
import { LightningElement, wire } from "lwc";
import {
publish,
MessageContext
} from "lightning/messageService";
import cartChanged from "@salesforce/messageChannel/lightning__commerce_cartChanged";
export default class CartUpdatingComponent extends LightningElement {
@wire(MessageContext)
messageContext;
/**
* Handles a user button click to add a product to their cart.
*/
addToCart(event) {
addToCartAsync(...)
.then(() => {
publish(this.messageContext, cartChanged);
});
}
}
this.dispatchEvent(new CustomEvent("cartchanged", {
bubbles: true,
composed: true
}));
カートのバッジの Lightning Web Component (LWC) での更新イベントのトリガは、すでにサポートされています。そのため、(このスニペットで行われている) イベントの起動により、目的の更新がトリガされます。
ストアでは、ブラウザのデバッガコンソールから直接コードスニペットを実行できます。カート情報を取得するためのネットワークコールがコンソールに表示されていれば、スニペットは機能しています。
今後 (セーフハーバーの適用)、Salesforce は、ユーザがこのような更新をネイティブにトリガできるように作業を進めていきます。
/**
* Handles a user button click to add a product to their cart.
*/
addtoCart() {
addToCartAsync(...)
.then(result => {
this.dispatchEvent(new CustomEvent("cartchanged", {
bubbles: true,
composed: true
}));
});
}
000389948

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.