# Multiple Pricing Channels

Some retailers sell their products via multiple channels or outlets, each with different pricing logic and constraints.

A prime example of multiple retail channels is a retailer that sells the same inventory both online via an eCommerce store and offline in a physical location.

Another such example is a retailer that sells its inventory online with locale-specific pricing logic and constraints based on the geographic location of the end-user. In this example a retailer might have an EU pricing channel for EU-based users, and a US pricing channel for USA-based users.

In QL parlance a support for retailers with multiple pricing channels is called Omni-Channels. Please contact our Customer Success team if you want to enable support for multiple pricing channels on your account.

# SDK events in omni-channel capable systems

If the omni-channel support is already setup and enabled on your QL account, then using the SDK to send us views and conversions from your online store only requires you to add another parameter to the SDK event arguments object.

The examples below are based on the Basic integration example, with server-side code written in Ruby. You may adapt it to your use-case and backend stack.

# Product Page

app/controllers/products_controller.rb

class ProductsController < ApplicationController
  
  # GET /products/:id - renders product page
  def show
    @product = Product.find(params[:id]) # find product in DB
    # set view variables for SDK
    @productId = @product.ean # use the product's ean as the productId variable
    @shelfPrice = @product.shelfPrice
    @clientKey = 'myvirtualstore'
    @channels = ['online'] # pricing channels associated with this product
    
    render('show') # explicit call to render the product page view
  end
  
end

app/views/products/show.erb

<div>
  <h1><%= @product.name %></h1>
  <!-- rest of HTML is redacted for simplicity --> 
</div>
<!-- ADD QL's SDK at the bottom of the page template -->
<script>
  window.QLAsync = function(QL){
    var clientKey  = '<%= @clientKey %>',
        productId  = '<%= @productId %>',
        shelfPrice = '<%= @shelfPrice %>',
        channels = <%= @channels.to_json.html_safe %>,
        permalink = '<%= product_url(@product.id) %>'; // product_url is a function provided by Rails to get the product's permalink
    QL.init(clientKey).setSDKPrefix('SDK_PREFIX'); // replace SDK_PREFIX with the correct value
    QL.sendProductEvent(productId, {
      price: parseFloat(shelfPrice, 10),
      permalink: permalink,
      channels: channels
    });
  }
</script>
<script src="//d3jdlwnuo8nsnr.cloudfront.net/sdk/v3.0/ql.js"></script>

# Payment Confirmation Page

app/controllers/checkout_controller.rb

class CheckoutController < ApplicationController
 
  # GET /checkout/finish - renders successful checkout
  def finish
    id = session[:productId] # read checked-out product id from session
    @product = Product.find(id) # find product in DB
    # set view variables for SDK
    @productId = @product.ean
    @salePrice = session[:salePrice] #read product sale price from session
    @clientKey = 'myvirtualstore'
    @channel = 'online' # pricing channel associated with this purchase
    
    render('finish') # explicit call to render the payment confirmation view
  end
 
end

app/views/checkout/finish.erb

<div>
  <p>Your payment has been received!</p>
  <!-- rest of HTML is redacted for simplicity --> 
</div>
<!-- ADD QL's SDK at the bottom of the page template -->
<script>
  window.QLAsync = function(QL){
    var clientKey  = '<%= @clientKey %>',
        channel  = '<%= @channel %>',
        productId  = '<%= @productId %>',
        salePrice  = '<%= @salePrice %>';
    QL.init(clientKey).setSDKPrefix('SDK_PREFIX'); // replace SDK_PREFIX with the correct value
    QL.sendConfirmationEvent(productId, {
      price: parseFloat(salePrice, 10),
      channel: channel
    });
  }
</script>
<script src="//d3jdlwnuo8nsnr.cloudfront.net/sdk/v3.0/ql.js"></script>

# Channels vs. Channel - Views vs. Conversions

You will note that the SDK sendProductEvent function accepts an array of pricing channels, while the sendConfirmationEvent accepts a single pricing channel.

This is intentional and merits extra care and attention.

It's quite possible that one or more of your pricing channels are not directly connected to the SDK. For example, a physical store or a legacy mobile application.

If (and only if) you want to use product page views from one pricing channel in another pricing channel (like online vs. physical stores) you may pass a list all the pricing channels that should be associated with a particular product page view. Otherwise, you should only pass the relevant (current) pricing channel the product page view is associated with.

Conversion events are different - A sale in your online store, is not the same as a sale in your physical store. For that reason, the sendConfirmationEvent only accepts a single channel parameter, rather than a list.