Class: ShopifyAPI::DiscountCodeBatch

Inherits:
Base
  • Object
show all
Defined in:
lib/shopify_api/resources/discount_code_batch.rb

Instance Method Summary collapse

Methods inherited from Base

activate_session, api_version, api_version=, #as_json, clear_session, early_july_pagination?, headers, init_prefix, init_prefix_explicit, #persisted?, prefix, prefix=, prefix_source, resource_prefix, resource_prefix=, version_validation!

Methods included from Countable

#count

Instance Method Details

#discount_code_jobObject


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/shopify_api/resources/discount_code_batch.rb', line 12

def discount_code_job
  @discount_codes ||= begin
    if id
      path = self.class.api_version.construct_api_path(
        "price_rules/#{price_rule_id}/batch/#{id}/discount_codes.json"
      )
      discount_codes = ShopifyAPI::DiscountCode.find(:all, from: path)
      discount_codes.each do |code|
        errors = code.attributes['errors']
        errors.attributes.each do |key, values|
          values.each { |message| code.errors.add(key, message) }
        end
      end
      discount_codes
    end
  end
end

#encode(options = {}) ⇒ Object


30
31
32
# File 'lib/shopify_api/resources/discount_code_batch.rb', line 30

def encode(options = {})
  send("to_#{self.class.format.extension}", options)
end

#price_rule_idObject


8
9
10
# File 'lib/shopify_api/resources/discount_code_batch.rb', line 8

def price_rule_id
  @prefix_options[:price_rule_id]
end