# Methods

`getLanguage()`

Returns the current language locale.

```
const locale = window.ZapietEats.getLanguage(); 
// Returns: "en"
```

`setLanguage(newLanguage)`

Sets the language for the widget.

```
window.ZapietEats.setLanguage('fr');
```

`getDeliveryOption()`

Returns the currently selected delivery option.

```
const option = window.ZapietEats.getDeliveryOption(); 
// Returns: "pickup" or "delivery"
```

\
​`setDeliveryOption(deliveryOption)`

Sets the delivery option.

1. `deliveryOption` (string): "pickup" or "delivery".

```
window.ZapietEats.setDeliveryOption('delivery');
```

`getSelectedRestaurant()`

Returns the currently selected restaurant object.

```
const restaurant = window.ZapietEats.getSelectedRestaurant();
```

`getSelectedMenu()`

Returns the currently selected menu object.

```
const menu = window.ZapietEats.getSelectedMenu();
```

`getSelectedDate()`

Returns the currently selected date as a ZapietDate object.

```
const date = window.ZapietEats.getSelectedDate();
```

`getLocationInventoryDate()`

Returns the date to be used for inventory checks, based on the selected location's timezone.

```
const inventoryDate = window.ZapietEats.getLocationInventoryDate();
// Returns: "YYYY-MM-DD"
```

`getSelectedTime()`

Returns the currently selected time as a ZapietTime object.

```
const time = window.ZapietEats.getSelectedTime();
```

`getSettings()`

Returns the account settings.

```
const settings = window.ZapietEats.getSettings();
```

`showTopBar()`

Shows the top bar of the widget.

```
window.ZapietEats.showTopBar();
```

`hideTopBar()`

Hides the top bar of the widget.

```
window.ZapietEats.hideTopBar();
```

`getZapietId()`

Generates the Zapiet ID string based on the current selection.

```
const zapietId = window.ZapietEats.getZapietId(); // Returns: "A=E&M=D&L=123&Z=456&D=2023-10-25&T=14:00"
```

`getAttributes()`

Returns an object containing the cart attributes based on the current selection.

```
const attributes = window.ZapietEats.getAttributes();
```

`addZapietId()`

Adds the Zapiet ID and attributes to the current cart.

```
window.ZapietEats.addZapietId().then((cart) => {
  console.log('Zapiet ID added to cart', cart);
});
```

\
​`getCartLineItemsWithZapietId(cart)`

Returns the cart items with the `_ZapietId` property added to them.

* `cart` (optional): The Shopify cart object. If not provided, it fetches the current cart.

```
window.ZapietEats.getCartLineItemsWithZapietId().then((items) => {
  console.log('Items with Zapiet ID', items);
});
```

`openModal()`

Opens the widget modal.

```
window.ZapietEats.openModal();
```

`closeModal()`

Closes the widget modal.

```
window.ZapietEats.closeModal();
```

`showMessage(data)`

Shows a message in the widget.

* `data` (object | string): The message data or string.
  * `message` (string): The message text.
  * `type` (string): "info" or "error".
  * `primaryAction` (object): Optional primary action button.
  * `secondaryAction` (object): Optional secondary action button.

```
window.ZapietEats.showMessage({
  message: 'Please select a location',
  type: 'error'
});
```

`closeMessage()`

Closes the currently displayed message.

```
window.ZapietEats.closeMessage();
```
