All Projects → the-couch → richer

the-couch / richer

Licence: other
jquery free ajax cart for shopify

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to richer

Theme Scripts
Theme Scripts is a collection of utility libraries which help theme developers with problems unique to Shopify Themes.
Stars: ✭ 337 (+862.86%)
Mutual labels:  slate, shopify
shopify-wishlist
💙 A set of files used to implement a simple customer wishlist on a Shopify store
Stars: ✭ 115 (+228.57%)
Mutual labels:  ajax, shopify
Ajaxinate
🎡 Ajax pagination plugin for Shopify themes
Stars: ✭ 107 (+205.71%)
Mutual labels:  ajax, shopify
7cart
7cart is a php7 project for building online shops, catalogs or service platforms. 7cart built with simple code and database schema. It is easy to support and fast.
Stars: ✭ 27 (-22.86%)
Mutual labels:  shopify, cart
front-end-notes
前端课程学习笔记汇总
Stars: ✭ 57 (+62.86%)
Mutual labels:  ajax
publikator-frontend
[DEPRECATED] moved to https://github.com/republik/plattform Our CMS frontend, including a rich text editor implemented with Slate.
Stars: ✭ 16 (-54.29%)
Mutual labels:  slate
simple-page-ordering
Order your pages and other hierarchical post types with simple drag and drop right from the standard page list.
Stars: ✭ 88 (+151.43%)
Mutual labels:  ajax
jaxon-core
The Jaxon core library
Stars: ✭ 53 (+51.43%)
Mutual labels:  ajax
slate-react-dnd-plugin
No description or website provided.
Stars: ✭ 35 (+0%)
Mutual labels:  slate
mihdan-disable-aggressive-updates
Плагин под WordPress для ускорения админки путём отключения агрессивных проверок обновлений
Stars: ✭ 21 (-40%)
Mutual labels:  ajax
shopify-node-react-app
Shopify paid app in Node.js & React.js that connects to a store and lets merchants select products to automatically discount them in the Shopify admin interface.
Stars: ✭ 29 (-17.14%)
Mutual labels:  shopify
cpms-php
使用thinkPHP5.0开发的后台简洁管理系统脚手架,cpms-php是采用TP5.0开发的一个简单的后台脚手架管理系统(包括前台展示和后台管理部分)。主要模块有:用户登入验证、后台管理员增删改查、文章发布、RBAC权限管理、socketIO在线即时聊天
Stars: ✭ 20 (-42.86%)
Mutual labels:  ajax
lpmj6
Examples from Learning PHP, MySQL & JavaScript Ed 6 by Robin Nixon (plus all examples from previous editions)
Stars: ✭ 186 (+431.43%)
Mutual labels:  ajax
slate-cli
This repo has been deprecated. Please open any new issues or PRs in the Shopify/slate repo.
Stars: ✭ 19 (-45.71%)
Mutual labels:  slate
sinatra-api-server-toolbox
Sinatra API Server Toolbox (Ruby, Sinatra, ActiveRecord, postgreSQL, JSON, jQuery, AJAX)
Stars: ✭ 21 (-40%)
Mutual labels:  ajax
go-slate
A CLI tool to generate API documentation using Slate layout by Robert Lord
Stars: ✭ 19 (-45.71%)
Mutual labels:  slate
shopapp-shopify-ios
A Shopify provider for a ShopApp for iOS application
Stars: ✭ 49 (+40%)
Mutual labels:  shopify
gulp-shopify
Blank slate Shopify theme for Developers, packaged with Gulp.js for processing SCSS, JavaScript (ES6), images and fonts. Made to support Online Store 2.0 features and Shopify CLI.
Stars: ✭ 142 (+305.71%)
Mutual labels:  shopify
react-sync
A declarative approach to fetching data via a React higher order component
Stars: ✭ 18 (-48.57%)
Mutual labels:  ajax
dotfiles
Dotfiles. Mac and *nix. Handy scripts, configurations for bash, zsh, git, asdf, Sublime Text, Karabiner-Elements, BetterTouchTool and more.
Stars: ✭ 15 (-57.14%)
Mutual labels:  slate

Richer

js-standard-style

What is it?

This library is built on top of slater (which is a fork of shopify slate). It is based on the old implementation of the Timber depreciated richcart. The idea behind this comes from Slate and Timber both being tied to jQuery and wanting to build something that could be used independent of that.

Using It

We use richer to handle API requests to the shopify AJAX cart. How you implement it is entirely up to you. We expose a couple of common routes that allow you to easily handle updating/refreshing/generating your ajax cart.

I'll outline a number of examples in YOYO below

Initialize a cart

import RicherAPI from 'richer'

// Some DOM defaults
const defaults = {
  addToCart: '.js-add-to-cart', // classname
  addToCartForm: 'AddToCartForm', // id
  cartContainer: 'CartContainer', // id
  cartCounter: 'CartCounter', // id
  items: []
}

const config = Object.assign({}, defaults, options)

const dom = {
  addToCartForm: document.getElementById(config.addToCartForm),
  cartContainer: document.getElementById(config.cartContainer),
  cartCounter: document.getElementById(config.cartCounter)
}

RicherAPI.getCart(cartUpdateCallback)

// Updates a cart number and builds our cart
const cartUpdateCallback = (cart) => {
  updateCount(cart)
  buildCart(cart)
}

const updateCount = (cart) => {
  const counter = dom.cartCounter
  counter.innerHTML = cart.item_count
}

const buildCart = (cart) => {
  const cartContainer = dom.cartContainer
  cartContainer.innerHTML = null

  if (cart.item_count === 0) {
    cartContainer.innerHTML = `<p>We're sorry your cart is empty</p>`
    return
  }

  var el = cartBlock(cart.items, cart, update)

  function cartBlock (items, cart, qtyControl) {
    return yo`
      <div class='r-cart'>
        ${items.map((item, index) => {
          const product = cleanProduct(item, index, config)
          return yo`
            <div class="r-cart__product f jcb">
              <div>
                <img src='${product.image}' alt='${product.name}' />
              </div>
              <div class="r-cart__product_info">
                <h5><a href='${product.url}'>${product.name}</a></h5>
                ${product.variation ? yo`<span>${product.variation}</span>` : null}
                ${realPrice(product.discountsApplied, product.originalLinePrice, product.linePrice)}
                ${yo`
                  <div class="r-cart__qty f jcb">
                    <div class="r-cart__qty_control" onclick=${() => qtyControl(product, product.itemMinus)}>
                      <svg width="20" height="20" viewBox="0 0 20 20"><path fill="#444" d="M17.543 11.029H2.1A1.032 1.032 0 0 1 1.071 10c0-.566.463-1.029 1.029-1.029h15.443c.566 0 1.029.463 1.029 1.029 0 .566-.463 1.029-1.029 1.029z"/></svg>
                    </div>
                    <span>${product.itemQty}</span>
                    <div class="r-cart__qty_control" onclick=${() => qtyControl(product, product.itemAdd)}>
                      <svg width="20" height="20" viewBox="0 0 20 20" class="icon"><path fill="#444" d="M17.409 8.929h-6.695V2.258c0-.566-.506-1.029-1.071-1.029s-1.071.463-1.071 1.029v6.671H1.967C1.401 8.929.938 9.435.938 10s.463 1.071 1.029 1.071h6.605V17.7c0 .566.506 1.029 1.071 1.029s1.071-.463 1.071-1.029v-6.629h6.695c.566 0 1.029-.506 1.029-1.071s-.463-1.071-1.029-1.071z"/></svg>
                    </div>
                  </div>
                `}
              </div>
            </div>
          `
        })}
        ${subTotal(cart.total_price, cart.total_cart_discount)}
      </div>
    `
  }

  function subTotal (total, discount) {
    // TODO: handling discounts
    const totalPrice = slate.Currency.formatMoney(total)  // eslint-disable-line
    return yo`
      <div>
        <h5>Subtotal: ${totalPrice}</h5>
      </div>
    `
  }

  function realPrice (discountsApplied, originalLinePrice, linePrice) {
    if (discountsApplied) {
      return yo`
        <div>
          <small className='strike'>${originalLinePrice}</small>
          <br /><span>${linePrice}</span>
        </div>
      `
    } else {
      return yo`
        <span>${linePrice}</span>
      `
    }
  }

  function update (item, quantity) {
     RicherAPI.changeItem((item.index + 1), quantity, refreshCart)
  }

  function refreshCart (cart) {
    let newCart = cartBlock(cart.items, cart, update)
    yo.update(el, newCart)
  }

  cartContainer.appendChild(el)
}
import RicherAPI from 'richer'

const dom = {
  addToCartForm: document.getElementById('AddToCartForm'),
}

const AddToCart = () => {
  const form = dom.addToCartForm

  form.addEventListener('submit', (e) => {
    e.preventDefault()
    form.classList.remove('is-added')
    form.classList.add('is-adding')

    RicherAPI.addItemFromForm(e.target, itemAddedCallback, itemErrorCallback)
  })

  const itemAddedCallback = () => {
    RicherAPI.getCart(cartUpdateCallback)
  }

  const itemErrorCallback = (XMLHttpRequest, textStatus) => {
    console.log('error family')
  }
}

const cartUpdateCallback = (cart) => {
  updateCount(cart)
  buildCart(cart)
  RicherAPI.onCartUpdate(cart)
}

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].