Announcement Bar Methods
SmartCart.getAnnouncementBarsInCart ⇒ Array
Get announcement bar instances used in the cart
Returns: Array - The announcement bar instances
Example
// Get all announcement bars currently in the cart
const bars = SmartCart.getAnnouncementBarsInCart();
// Log the number of active announcement bars
console.log(`${bars.length} announcement bar(s) active`);
// Iterate through bars to check their state
bars.forEach((bar, index) => {
console.log(`Bar ${index + 1}:`, bar);
});
SmartCart.getAnnouncementsByComponentId ⇒ Array
Get announcements by component ID
Returns: Array - The announcements for the component
| Param |
Type |
Description |
| id |
string |
The component ID |
Example
// Get announcements for a specific component
const componentId = 'my-announcement-component';
const announcements = SmartCart.getAnnouncementsByComponentId(componentId);
// Display announcements in a custom container
announcements.forEach(announcement => {
console.log('Announcement:', announcement);
});
---
title: Announcement Bar Methods
excerpt: Access and manage announcement bar instances in Smart Cart
deprecated: false
hidden: false
metadata:
title: ''
description: ''
robots: index
next:
description: Return to the New Methods Overview Page to see other available methods.
pages:
- type: endpoint
slug: smart-cart-methods
title: Methods Overview - New
---
## `SmartCart.getAnnouncementBarsInCart` ⇒ `Array`
Get announcement bar instances used in the cart
**Returns**: `Array` - The announcement bar instances
**Example**
```javascript
// Get all announcement bars currently in the cart
const bars = SmartCart.getAnnouncementBarsInCart();
// Log the number of active announcement bars
console.log(`${bars.length} announcement bar(s) active`);
// Iterate through bars to check their state
bars.forEach((bar, index) => {
console.log(`Bar ${index + 1}:`, bar);
});
```
## `SmartCart.getAnnouncementsByComponentId` ⇒ `Array`
Get announcements by component ID
**Returns**: `Array` - The announcements for the component
| Param | Type | Description |
| --- | --- | --- |
| id | `string` | The component ID |
**Example**
```javascript
// Get announcements for a specific component
const componentId = 'my-announcement-component';
const announcements = SmartCart.getAnnouncementsByComponentId(componentId);
// Display announcements in a custom container
announcements.forEach(announcement => {
console.log('Announcement:', announcement);
});
```