Module: Spree::Product::Channels

Extended by:
ActiveSupport::Concern
Included in:
Spree::Product
Defined in:
app/models/spree/product/channels.rb

Constant Summary collapse

DEPRECATED_DATE_TO_PUBLICATION_FIELD =
{
  available_on:   :published_at,
  discontinue_on: :unpublished_at
}.freeze

Instance Method Summary collapse

Instance Method Details

#product_publications=(publications_params) ⇒ void

This method returns an undefined value.

Syncs product publications from an array of hashes. Creates new publications, updates existing ones (matched by :id or :channel_id), and removes ones absent from the payload. An empty array detaches the product from every channel.

Parameters:

  • publications_params (Array<Hash>)

    array of publication attribute hashes



81
82
83
84
85
86
87
88
89
90
91
# File 'app/models/spree/product/channels.rb', line 81

def product_publications=(publications_params)
  return super if publications_params.nil?
  return super if publications_params.respond_to?(:first) && publications_params.first.is_a?(Spree::ProductPublication)

  if new_record?
    @pending_publications_params = publications_params
    return
  end

  apply_product_publications(publications_params)
end

#publication_for(channel) ⇒ Spree::ProductPublication?

Returns the publication for the given channel, or nil if the product isn’t published there.

Parameters:

  • channel (Spree::Channel)

    the channel to find the publication for

Returns:



65
66
67
68
69
70
71
72
73
# File 'app/models/spree/product/channels.rb', line 65

def publication_for(channel)
  return nil unless channel

  if product_publications.loaded?
    product_publications.find { |p| p.channel_id == channel.id }
  else
    product_publications.find_by(channel_id: channel.id)
  end
end