Sha256: a26ffb9f4c9291bfc8469ca886dabe7fe50e7aec580ff87d9685afa4a5b68e58

Contents?: true

Size: 908 Bytes

Versions: 8

Compression:

Stored size: 908 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

8 entries across 8 versions & 2 rubygems

Version Path
ruby_shopify_api-1.2.0 lib/ruby_shopify_api/resources/discount_code_batch.rb
ruby_shopify_api-1.1.0 lib/shopify_api/resources/discount_code_batch.rb
ruby_shopify_api-1.0.0 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.5.1 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.5 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.4.1 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.4.0 lib/shopify_api/resources/discount_code_batch.rb
shopify_api-9.3.0 lib/shopify_api/resources/discount_code_batch.rb