class SolidusDrip::ShopperActivity::Product

Attributes

variant[RW]

Public Class Methods

new(variant) click to toggle source

ShopperActivity::Product relies on Spree::Variant data to be useful. We call super to initialize the client and then we set the variant attribute to be used in the API calls.

@param variant [Spree::Variant] the variant to be recorded

Calls superclass method SolidusDrip::Base::new
# File lib/solidus_drip/shopper_activity/product.rb, line 15
def initialize(variant)
  super
  @variant = variant
end

Public Instance Methods

product_activity(action) click to toggle source

Product Activity helps identify variant updates.

@param action [String] the product action, `created`, `updated`, or `deleted` @see developer.drip.com/#product-activity

# File lib/solidus_drip/shopper_activity/product.rb, line 26
def product_activity(action)
  response = client.create_product_activity_event(product_data(action))
  handle_error_response(response) if !response.success?

  response.success?
end

Private Instance Methods

product_data(action) click to toggle source

Formats data to be used in Drip product calls

# File lib/solidus_drip/shopper_activity/product.rb, line 38
def product_data(action)
  {
    provider: 'solidus',
    action: action,
    product_id: variant.product_id.to_s,
    product_variant_id: variant.id.to_s,
    sku: variant.sku,
    name: variant.name,
    categories: variant.product.taxons.pluck(:name),
    price: variant.price.to_f,
    inventory: variant.total_on_hand,
    product_url: product_url(variant.product)
  }.compact
end