wix-restaurants-js-sdk

1.3.0 • Public • Published

Wix Restaurants JavaScript SDK

Official JavaScript client for the Wix Restaurants API.

NPM version Downloads

This package contains the following modules:

Client

See usage examples here.

Fixture

Fixtures let you create Wix Restaurants data structures using functions. Example:

import {fixtures} from 'wix-restaurants-js-sdk';

const charge = fixtures.ChargeV2().
    deliveryTypes(['delivery']).
    displayConditionDeliveryTypes(['delivery', 'pickup']).
    platforms(['mobileweb', 'web']).
    val();

List of available fixtures:

ChargeV2

Creates a ChargeV2 object

  • fixtures.ChargeV2.title(val) - Updates the title of the charge. Assumes 'en_US' locale.
  • fixtures.ChargeV2.description(val) - Updates the description of the charge. Assumes 'en_US' locale.
  • fixtures.ChargeV2.percentageDiscount({percentage, itemIds}) - Sets the charge as a percentage discount. percentage is times 100 (eg, 1234 means 12.34%). itemIds is a list of itemIds to calculate the percentage on.
  • fixtures.ChargeV2.tax({percentage, itemIds}) - Sets the charge as a tax charge. percentage is times 100 (eg, 1234 means 12.34%). itemIds is a list of itemIds to calculate the percentage on.
  • fixtures.ChargeV2.fixedDiscount({price}) - Sets the charge as a fixed discount. price is times 100 (eg, 1234 means $12.34).
  • fixtures.ChargeV2.deliveryTypes(types) - Sets the list of delivery types in the charge's condition.
  • fixtures.ChargeV2.displayConditionDeliveryTypes(types) - Sets the list of delivery types in the charge's display condition.
  • fixtures.ChargeV2.platforms(platforms) - Sets the list of platforms in the charge's condition.
  • fixtures.ChargeV2.displayConditionPlatforms(platforms) - Sets the list of platforms in the charge's display condition.
  • fixtures.ChargeV2.min(min) - Sets the minimum price in the charge's condition.
  • fixtures.ChargeV2.displayConditionMin(min) - Sets the minimum price in the charge's display condition.
  • fixtures.ChargeV2.deliveryTime(availability) - Sets the weekly availability in the charge's condition.
  • fixtures.ChargeV2.displayConditionDeliveryTime(availability) - Sets the weekly availability in the charge's display condition.
  • fixtures.ChargeV2.close() - Sets the state of the charge to 'closed'.
  • fixtures.ChargeV2.val() - Returns the final charge created.

Availability

Creates an Availability object

  • fixtures.Avalability.addWeeklyFromDate({start, end}) - Adds duration to the availability.weekly field, translating the start and end to minutes of week (mainly used for testing).

Helpers

DeliveryDispatchInfo

Helper functions to work with DeliveryDispatchInfo objects. See test for usage.

  • isActive({info}).
  • canMeetPrice({info, orderPrice}).
  • doesDeliverToLatLng({info, latLng}).
  • isAvailable({info, orderTime}).
  • canMeetDeliveryTime({info, orderTime, now}).
  • filterAndSort({infos, filter, sortBy}).

ChargeV2

Helper functions to work with ChargeV2 objects.

  • isApplicable({charge, deliveryTime, deliveryType, orderItems, source, platform}) - Checks if a charge is applicable to the current parameters.
  • isDisplayable({charge, deliveryTime, deliveryType, orderItems, source, platform}) - Checks if a charge is displayable to the current parameters.
  • calculateAmount({charge, orderItems, orderCharges, extraCost}) - Calculates the amount the matching OrderCharge should contain.

OrderItem

Helper functions to work with OrderItems objects.

  • getTotalPrice({orderItem}) - Calculates the total price of an OrderItem (including variations).

Order

Helper functions to work with Order objects.

  • getOrderCharges({order, chargesV2}) - Returns the orderCharges calculated, that should be added to the order object. Receives an existing order object that should contain order.deilvery.type, order.delivery.time, and order.orderItems to calculate correctly. chargeV2 should be from the menu.

Image

Helper functions to work with image URLs.

  • fill({url, width, height}) - Returns a URL that serves the resized image. Passing 0 for width or height means maximum size.

Readme

Keywords

Package Sidebar

Install

npm i wix-restaurants-js-sdk

Weekly Downloads

42

Version

1.3.0

License

Apache-2.0

Unpacked Size

290 kB

Total Files

91

Last publish

Collaborators

  • arielh
  • falconci
  • yurynix
  • itai.benda
  • wix-ci
  • wix-ambassador
  • shahata
  • netanelgilad
  • wix-ci-publisher
  • wix-bi-publisher