Tích hợp / Thêm vào giỏ tùy chỉnh

Thêm vào giỏ cho cửa hàng tùy chỉnh

Cửa hàng Shopify có hỗ trợ Ajax cart tích hợp. Trên trang tự host hoặc headless, triển khai RivetChat.onAddToCart để thẻ sản phẩm thêm vào giỏ của bạn và mở drawer hoặc badge túi.

Cách hoạt động

  1. 1Trong Dashboard Rivet, thêm sản phẩm với link sản phẩmURL ảnh để chat hiển thị thẻ.
  2. 2Tùy chọn đặt external_id thành SKU/variant id để callback thêm đúng dòng.
  3. 3Định nghĩa window.RivetChat.onAddToCart trước SmartReply.init, gọi API giỏ bên trong.

Ví dụ nhúng script

Dán vào footer hoặc layout trang. Thay tenant id và endpoint giỏ bằng của bạn.

<!-- Rivet AI customer service widget -->
<link rel="stylesheet" href="https://rivet-chat.com/static/chat.css?v=39">
<script src="https://rivet-chat.com/static/chat.js?v=39" defer></script>
<script>
// Hook Add to cart before SmartReply.init
window.RivetChat = {
  onAddToCart: function (item) {
    // item: name, price, product_url, image_url, external_id, handle, variants…
    return fetch("/api/cart/add", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      credentials: "same-origin",
      body: JSON.stringify({
        id: item.external_id || item.id,
        url: item.product_url,
        quantity: 1
      })
    }).then(function (r) {
      if (!r.ok) throw new Error("cart failed");
      // Open your side cart / update bag badge here
      if (window.MyStore && typeof window.MyStore.openCart === "function") {
        window.MyStore.openCart();
      }
    });
  }
};

window.addEventListener("DOMContentLoaded", function () {
  SmartReply.init({
    server: "https://rivet-chat.com",
    tenantId: "t-xxxxxxxx",
    platform: "custom"
  });
});
</script>

Ví dụ React / Next.js

Chỉ chạy trong client component. Trả Promise từ hook để Rivet hiển thị toast thành công/lỗi.

// Client component (Next.js / React)
useEffect(() => {
  window.RivetChat = {
    onAddToCart: async (item) => {
      await yourCart.add({
        id: item.external_id || item.id,
        url: item.product_url,
        qty: 1,
      });
      yourCart.openDrawer();
    },
  };

  SmartReply.init({
    server: 'https://rivet-chat.com',
    tenantId: 'your-tenant-id',
    platform: 'custom',
  });
}, []);

Shopify vs tùy chỉnh

  • Shopify: tích hợp /cart/add.js — không cần callback. Link + ảnh (hoặc App sync) đủ cho thẻ và thêm vào giỏ.
  • Tùy chỉnh / Woo / headless: triển khai onAddToCart. Không có, nút mở trang sản phẩm thay vì thêm vào giỏ.

Quay lại nhúng trang tùy chỉnh · Cài đặt Shopify

Biến trang sản phẩm thành quầy bán

Giới thiệu sản phẩm khách đang xem, trả lời từ dữ liệu thực, để họ thêm vào giỏ ngay trong chat.

Dùng thử miễn phí