Sha256: 3dfac08b547b839a9d8b44f6a1a146254f328530ec37976b1d79fedc4885d927

Contents?: true

Size: 883 Bytes

Versions: 4

Compression:

Stored size: 883 Bytes

Contents

# frozen_string_literal: true
module ShopifyAPI
  class DiscountCodeBatch < Base
    init_prefix :price_rule

    self.collection_name = 'batch'

    def price_rule_id
      @prefix_options[:price_rule_id]
    end

    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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shopify_api-9.2.0 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.1.0 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.0.4 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.0.3 lib/shopify_api/resources/discount_code_batch.rb