Git Product home page Git Product logo

cart's Introduction

Headless Shopping Cart

Overview

Web components which convert any web page into a shopping cart.

This includes components to:-

  • Dynamically update price and qty for listed items.
  • Add items to a cart and manage cart.
  • Authenticate and checkout.

Once customers are authenticated, price / qty shown and the types of payment / shipping methods available may change. This functionality is usually specific to B2B e-commerce.

For a website to use these components, it should include a single .js file and the appropriate components in the pages HTML.

Web Components

Required web components

Item Price

Displays the price of a item

<s2s-item-price 
    sku="abc" 
    format="international" 
    currency="USD" />

e.g.

<s2s-item-price >USD 1,234.56</s2s-item-price>

Item Qty

Displays the available qty

<s2s-item-qty 
    sku="abc" />

e.g.

<s2s-item-qty >10</s2s-item-qty>

Item Add

<s2s-item-add 
    sku="abc"
    over-order="false"
    dynamic-price="true"
    dynamic-qty="true"
    description="Wonderful new shiny thing"
    title="Thing One"
    img="/some/image/link.jpg" />

Should create a clickable link if the item can be ordered

Cart Checkout

<s2s-cart-checkout />

Creates a link to checkout

Cart Item Count

<s2s-cart-item-count />

Summary of items in cart

Cart Item Total

<s2s-cart-item-total />

Summary of cart total

Customer Account

<s2s-customer-account />

Login link for customer to authenticate. TBC

JSON API Models

Web components will need to communicate with an external API. The below models would need to be implemented.

User Authenticate

Fetch token for user.

Example Endpoint:

POST /users/authenticate

{
  "user": {
    "username": "string",
    "password": "string"
  }
}

Response Model Schema:

{
  "user": {
    "id": "long",
    "email": "string",
    "name": "string",
    "surname": "string",
    "token": "string",
  }
}

Items list

Verify a list of products and retrieve price / qty per product, if required.

Example Endpoint:

POST /items?token=xyz

["sku 1", "sku 2", ...]

Response Model Schema:

[
  {
    "sku": "string",
    "price": {
      "was": "number",
      "now": "number"
    },
    "qty": {
      "default": "number",
      "warehouse[x]": "number"
    }  
  }
]

Order confirm

Verify that all items in the cart can be ordered. Return shipping and payment methods.

Example Endpoint:

POST /order/confirm

{
    TBC
}

Model Schema:

{
 TBC
}

Order checkout

Post order for processing.

Example Endpoint:

POST /order/checkout
{
    TBC
}

Model Schema:

{
 TBC
}

Order checkout

Post confirmation of payment.

Example Endpoint:

POST /payment
{
    TBC
}

Model Schema:

{
 TBC
}

cart's People

Contributors

flumonion avatar

Watchers

James Cloos avatar  avatar  avatar

cart's Issues

Review 2021-02-02

@flumonion

I suggest dropping the word "Headless" from the description.
Headless software: "...capable of working on a device without a graphical user interface". This repo is intended for use in a Web Browser.

As per customelements, custom tags "...must contain a dash (-). So <x-tags>, <my-element>, and <my-awesome-app> are all valid names, while <tabs> and <foo_bar> are not". That said, it probably makes sense to keep them as short as possible (two words). I suggest the following:

  • s2s-price sku="abc" ...
  • s2s-qty sku="abc" ...
  • s2s-add sku="abc" ...
    This component consists of an input with type number, plus and minus buttons, and a button to add to cart?
  • s2s-cart
    Display list of cart items and checkout button
  • s2s-total currency="USD"
    Current total of item in cart
  • s2s-login
    Display login box

API specific framework independent store

@flumonion

There should be a Stock2ShopStore.ts object that is specific to routes defined on an API (e.g. stock2shop.com or WooCommerceStore.ts for WooCommerce), but independent from the JavaScript framework (e.g. VueJS, React or Angular).

The store

Components are isolated from the rest of the page with Shadow DOM, however they can share state via a global stores2s namespace, with services s2s.store and s2s.cart. See #5 (comment) re Javascript SDK. Side note, the components have default styling. However, since components have open shadow-root, the page can override the default styling with custom CSS (keeping in mind recent encapsulation restrictions).

At a bare minimum the user must include a JS file, and create markup with custom elements, for example

<script src="s2s-cart.js"></script>
The price for {{ product }} is <s2s-price sku="abc123"></s2s-price>

Where s2s-cart.js might be constructed like this for Stock2Shop and VueJS

cat vue-1.2.3.js > s2s-cart.js
cat s2s-store.js >> s2s-cart.js
cat vuejs/s2s-price.js >> s2s-cart.js

Or like this for WooCommerce and React

cat react-1.2.3.js > s2s-cart.js
cat s2s-store-woocommerce.js >> s2s-cart.js
cat react/s2s-price.js >> s2s-cart.js

Mock server

@flumonion

For convenience we might include pre-built mock servers to go with API specific stores as explained in #3.

The simplest possible version of this would be a fileserver , with the addition of routes to match the API being simulated (e.g. stock2shop.com or WooCommerce, but just responding with JSON stub files from local disk.

The developer can download a pre-built server from the companion website for this repo that is hosted on GitHub Pages. To develop their static site devs run server.exe, use an appropriate pre-build s2s-cart.js as per #3, and edit HTML files in their preferred text editor.

Advanced developers might opt to use their own VueJS app and npm run serve. In this case they can still make CORS requests to the mock server for the API they're targeting.

The mock server could also be used to verify a specific store and collection of components implement the spec, in combination with a WebDriver. For example the WebDriver opens a demo app, views products, adds them to the cart, and checks out. The mock server records the requests. To complete the test run we ask the mock server if the routes were called in correct order, with expected params.

Implement custom tags in TypeScript using VueJS

@flumonion

"Web components use Shadow DOM to encapsulate a widget's DOM tree from the rest of the page" as explained with this webcomponent example.

However, for the benefit of developer adoption we'd like to implement the spec using popular frameworks, first up is VueJS. To preserve sanity while maintaining software use TypeScript instead of JS.

Here is an example of a VueJS weather widget. Have a look at the source code for Weather.vue, note the <script lang="ts"> tag. To see it in action follow the steps below

git clone https://github.com/mozey/ts.git
cd ts/webcomponent
ln -s ../http/lib
open index2.html

The index2.html file should display something like this screenshot:

Screen Shot 2021-02-02 at 1 33 18 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.