Class: Edi::Wayfair::VariantGrouping

Inherits:
Object
  • Object
show all
Defined in:
app/services/edi/wayfair/variant_grouping.rb

Overview

Wayfair Product Addition variant-grouping directive: which group a proposed
product belongs to and which option axes distinguish its variants.

Phase 0 of the variant-grouping unification
(doc/tasks/202607051428_VARIANT_GROUPING_UNIFICATION.md): instead of
submitting every product as Not Variant and asking Wayfair Merchandising to
merge the listings after the fact (Consolidate Products tickets), new
products are born grouped — variantType Primary/Non-Primary, a shared
groupReferenceId per family, and option category/value pairs derived from
the item's VariantGroup axes (the canonical variant-axis source; see
VariantGroup#to_wayfair_variant_grouping).

Examples:

Explicit axes

Edi::Wayfair::VariantGrouping.new(group_reference_id: 'tct-kit-ot',
                                  categories: { 'Voltage' => '240V', 'Size' => '118 sq.ft.' })

Constant Summary collapse

TOKEN_CATEGORY_MAP =

VariantGroup axis_tokens → Wayfair option-category names. coverage
maps to Size because floor-heating SKU ladders are merchandised by area.

{ 'voltage' => 'Voltage', 'size' => 'Size', 'coverage' => 'Size' }.freeze
ORDINALS =

Wayfair supports up to three option categories per group.

%w[One Two Three].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group_reference_id:, categories:, primary: false) ⇒ VariantGrouping

Returns a new instance of VariantGrouping.

Parameters:

  • group_reference_id (String)

    shared id for the family

  • categories (Hash{String=>String})

    ordered option-category => value

  • primary (Boolean) (defaults to: false)

    whether this product is the group's Primary variant



37
38
39
40
41
42
43
44
# File 'app/services/edi/wayfair/variant_grouping.rb', line 37

def initialize(group_reference_id:, categories:, primary: false)
  @group_reference_id = group_reference_id.to_s
  @categories = categories.to_h
                          .transform_keys(&:to_s).transform_values(&:to_s)
                          .reject { |key, value| key.blank? || value.blank? }
                          .first(ORDINALS.size).to_h
  @variant_type = primary ? 'Primary' : 'Non-Primary'
end

Instance Attribute Details

#categoriesHash{String=>String} (readonly)

Returns ordered option-category => this product's value.

Returns:

  • (Hash{String=>String})

    ordered option-category => this product's value



32
33
34
# File 'app/services/edi/wayfair/variant_grouping.rb', line 32

def categories
  @categories
end

#group_reference_idString (readonly)

Returns shared id tying the family's products into one group.

Returns:

  • (String)

    shared id tying the family's products into one group



28
29
30
# File 'app/services/edi/wayfair/variant_grouping.rb', line 28

def group_reference_id
  @group_reference_id
end

#variant_typeString (readonly)

Returns Primary or Non-Primary.

Returns:

  • (String)

    Primary or Non-Primary



30
31
32
# File 'app/services/edi/wayfair/variant_grouping.rb', line 30

def variant_type
  @variant_type
end

Instance Method Details

#to_attributesArray<Hash>

Returns the namespaced variantGrouping::* attributes for a
submitV2 proposed product.

Returns:

  • (Array<Hash>)

    the namespaced variantGrouping::* attributes for a
    submitV2 proposed product



48
49
50
51
52
53
54
55
56
57
# File 'app/services/edi/wayfair/variant_grouping.rb', line 48

def to_attributes
  # Only these two are valid submitV2 inputs — Wayfair derives the option
  # axes from class standards, and no category attribute id exists (probe
  # details in doc/tasks/202607051428_VARIANT_GROUPING_UNIFICATION.md).
  # #categories feeds only our side (axis derivation, future adapters).
  [
    { attributeId: 'variantGrouping::variantType', value: variant_type },
    { attributeId: 'variantGrouping::groupReferenceId', value: group_reference_id }
  ]
end