Sha256: 72f218ffead9ebca0d026cd61c3b15208a08e50d86cb39755fe880f4e035c991
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
# frozen_string_literal: true module SolidusDrip module ShopperActivity class Product < SolidusDrip::Base attr_accessor :variant ## # 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 # def initialize(variant) super @variant = variant end ## # Product Activity helps identify variant updates. # # @param action [String] the product action, `created`, `updated`, or `deleted` # @see https://developer.drip.com/#product-activity # def product_activity(action) response = client.create_product_activity_event(product_data(action)) handle_error_response(response) if !response.success? response.success? end private ## # Formats data to be used in Drip product calls # 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 end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
solidus_drip-0.1.0 | lib/solidus_drip/shopper_activity/product.rb |
solidus_drip-0.0.1 | lib/solidus_drip/shopper_activity/product.rb |