Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Example of using talkable gem in spree e-commerce platform

Notifications You must be signed in to change notification settings

talkable/talkable-spree-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

This README has step by step instructions how to integrate Talkable referral platform into your spree store.

Getting started

Add talkable gem into your Gemfile:

gem 'talkable'

Run the bundle install command to install it.

Create a file config/initializers/talkable.rb and configure gem:

Talkable.configure do |config|
  config.site_slug  = 'YOUR-SITE-SLUG-AT-TALKABLE-COM'
  config.api_key    = 'YOUR-API-KEY-AT-TALKABLE-COM'
end

by default this configuration takes from environment variables ENV["TALKABLE_SITE_SLUG"] and ENV["TALKABLE_API_KEY"].

Modify your state machine by additional action after comlete state:

Spree::Order.state_machine.after_transition to: :complete, do: :register_at_talkable

Add register_at_talkable method to your Spree::Order model:

Spree::Order.class_eval do
  def register_at_talkable
    Talkable::API::Origin.create(Talkable::API::Origin::PURCHASE, talkable_params)
  end

  protected

  def talkable_params
    {
      email: email,
      order_number: number,
      subtotal: total,

      shipping_zip: ship_address&.zipcode,
      shipping_address: [
        ship_address&.address1,
        ship_address&.address2,
        ship_address&.city,
        ship_address&.state_name,
        ship_address&.zipcode,
        ship_address&.country&.name,
      ].reject(&:blank?).join(', '),
      coupon_code: promotions.map(&:code),
      customer_id: user_id,
      order_date: completed_at.iso8601,
      ip_address: last_ip_address,

      items: line_items.map do |item|
        {
          price: item.price,
          quantity: item.quantity,
          product_id: item.variant.sku,
        }
      end
    }
  end
end

About

Example of using talkable gem in spree e-commerce platform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages