Class: FlowcommerceSpree::Webhooks::LocalItemUpserted
- Inherits:
-
Object
- Object
- FlowcommerceSpree::Webhooks::LocalItemUpserted
- Defined in:
- app/services/flowcommerce_spree/webhooks/local_item_upserted.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
(also: #full_messages)
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, opts = {}) ⇒ LocalItemUpserted
constructor
A new instance of LocalItemUpserted.
- #process ⇒ Object
Constructor Details
#initialize(data, opts = {}) ⇒ LocalItemUpserted
Returns a new instance of LocalItemUpserted.
13 14 15 16 17 |
# File 'app/services/flowcommerce_spree/webhooks/local_item_upserted.rb', line 13 def initialize(data, opts = {}) @data = data @opts = opts @errors = [] end |
Instance Attribute Details
#errors ⇒ Object Also known as: full_messages
Returns the value of attribute errors.
6 7 8 |
# File 'app/services/flowcommerce_spree/webhooks/local_item_upserted.rb', line 6 def errors @errors end |
Class Method Details
.process(data, opts = {}) ⇒ Object
9 10 11 |
# File 'app/services/flowcommerce_spree/webhooks/local_item_upserted.rb', line 9 def self.process(data, opts = {}) new(data, opts).process end |
Instance Method Details
#process ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/flowcommerce_spree/webhooks/local_item_upserted.rb', line 19 def process errors << { message: 'Local item param missing' } && (return self) unless (local_item = @data['local_item']) errors << { message: 'SKU param missing' } && (return self) unless (flow_sku = local_item.dig('item', 'number')) if (variant = Spree::Variant.find_by(sku: flow_sku)) variant.add_flow_io_experience_data( local_item.dig('experience', 'key'), 'prices' => [local_item.dig('pricing', 'price')], 'status' => local_item['status'] ) variant.update_column(:meta, variant..to_json) return variant else errors << { message: "Variant with sku [#{flow_sku}] not found!" } end self end |