Class: Edi::Wayfair::CatalogItemInformationUpdater

Inherits:
BaseEdiService show all
Defined in:
app/services/edi/wayfair/catalog_item_information_updater.rb

Overview

Updates catalog item information on the Wayfair API via the inventory mutation

IMPORTANT: The Wayfair inventory API has LIMITED update capabilities.
You can update:

  • quantityOnHand
  • quantityBackorder
  • quantityOnOrder
  • itemNextAvailabilityDate
  • discontinued
  • productNameAndOptions

You CANNOT update via this API:

  • dimensions (read-only from Catalog API)
  • retailPrice (Wayfair controls pricing)
  • images (managed via Wayfair portal)
  • product category/class

API Documentation: https://developer.wayfair.io/docs/

Defined Under Namespace

Classes: UpdateResult

Constant Summary collapse

INVENTORY_API_URL =

Inventory mutation endpoint (uses wayfair.com, not wayfair.io)

'https://api.wayfair.com/v1/graphql'
SANDBOX_INVENTORY_API_URL =
'https://sandbox.api.wayfair.com/v1/graphql'
INVENTORY_UPDATE_MUTATION =

GraphQL mutation to update inventory/product data

<<~GRAPHQL.squish
  mutation UpdateInventory($inventory: [inventoryInput]!) {
    inventory {
      save(
        inventory: $inventory,
        feedKind: DIFFERENTIAL
      ) {
        id
        handle
        status
        submittedAt
        completedAt
        errors {
          key
          message
        }
      }
    }
  }
GRAPHQL

Constants included from AddressAbbreviator

AddressAbbreviator::MAX_LENGTH

Instance Attribute Summary

Attributes inherited from BaseEdiService

#orchestrator

Instance Method Summary collapse

Methods inherited from BaseEdiService

#duplicate_po_already_notified?, #initialize, #mark_duplicate_po_as_notified, #report_order_creation_issues, #safe_process_edi_communication_log

Methods included from AddressAbbreviator

#abbreviate_street, #collect_street_originals, #record_address_abbreviation_notes

Methods inherited from BaseService

#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger

Constructor Details

This class inherits a constructor from Edi::BaseEdiService

Instance Method Details

#process(supplier_part_number:, inventory_data:, dry_run: false) ⇒ UpdateResult

Update inventory data for a single product

Parameters:

  • supplier_part_number (String)

    Our internal SKU

  • inventory_data (Hash)

    { quantity_on_hand:, discontinued:, product_name_and_options: }

  • dry_run (Boolean) (defaults to: false)

    If true, just build and log the mutation without sending

Returns:

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/services/edi/wayfair/catalog_item_information_updater.rb', line 56

def process(supplier_part_number:, inventory_data:, dry_run: false)
  supplier_id = orchestrator.try(:warehouse_code)&.to_i
  raise ArgumentError, "Warehouse code (supplier_id) not configured for #{orchestrator.partner}" if supplier_id.blank? || supplier_id.zero?

  inventory_input = build_inventory_input(
    supplier_id: supplier_id,
    supplier_part_number: supplier_part_number,
    inventory_data: inventory_data
  )

  variables = { inventory: [inventory_input] }

  if dry_run
    logger.info "Wayfair Inventory Update (DRY RUN): Would send mutation for #{supplier_part_number}"
    logger.info "Wayfair Inventory Update (DRY RUN): Variables: #{variables.to_json}"
    return UpdateResult.new(success: true, handle: nil, errors: [], ecl: nil)
  end

  send_mutation(variables: variables, supplier_part_number: supplier_part_number)
end

#process_batch(updates:, dry_run: false) ⇒ UpdateResult

Update inventory data for multiple products

Parameters:

  • updates (Array<Hash>)

    Array of { supplier_part_number:, inventory_data: }

  • dry_run (Boolean) (defaults to: false)

Returns:

Raises:

  • (ArgumentError)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'app/services/edi/wayfair/catalog_item_information_updater.rb', line 81

def process_batch(updates:, dry_run: false)
  supplier_id = orchestrator.try(:warehouse_code)&.to_i
  raise ArgumentError, "Warehouse code (supplier_id) not configured for #{orchestrator.partner}" if supplier_id.blank? || supplier_id.zero?

  inventory_inputs = updates.map do |update|
    build_inventory_input(
      supplier_id: supplier_id,
      supplier_part_number: update[:supplier_part_number],
      inventory_data: update[:inventory_data]
    )
  end

  variables = { inventory: inventory_inputs }

  if dry_run
    logger.info "Wayfair Inventory Update (DRY RUN): Would send batch mutation for #{updates.size} products"
    logger.info "Wayfair Inventory Update (DRY RUN): Variables: #{variables.to_json}"
    return UpdateResult.new(success: true, handle: nil, errors: [], ecl: nil)
  end

  send_mutation(variables: variables, supplier_part_number: updates.map { |u| u[:supplier_part_number] }.join(','))
end