Sha256: 07300cf03966079980ea8398cc3f96fd6683d620238c2cd749b0c0c9932a75c4

Contents?: true

Size: 1.49 KB

Versions: 48

Compression:

Stored size: 1.49 KB

Contents

# frozen_string_literal: true

require 'spree/testing_support/factories/country_factory'
require 'spree/testing_support/factories/state_factory'
require 'spree/testing_support/factories/product_factory'

FactoryBot.define do
  factory :stock_location, class: 'Spree::StockLocation' do
    name { 'NY Warehouse' }
    address1 { '1600 Pennsylvania Ave NW' }
    city { 'Washington' }
    zipcode { '20500' }
    phone { '(202) 456-1111' }
    active { true }
    backorderable_default { true }

    country  { |stock_location| Spree::Country.first || stock_location.association(:country) }
    state do |stock_location|
      carmen_country = Carmen::Country.coded(stock_location.country.iso)
      if carmen_country.subregions?
        stock_location.country.states.first || stock_location.association(:state, country: stock_location.country)
      end
    end

    factory :stock_location_without_variant_propagation do
      propagate_all_variants { false }
    end

    factory :stock_location_with_items do
      after(:create) do |stock_location, _evaluator|
        # variant will add itself to all stock_locations in an after_create
        # creating a product will automatically create a master variant
        product_1 = create(:product)
        product_2 = create(:product)

        stock_location.stock_items.where(variant_id: product_1.master.id).first.adjust_count_on_hand(10)
        stock_location.stock_items.where(variant_id: product_2.master.id).first.adjust_count_on_hand(20)
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 2 rubygems

Version Path
solidus_core-2.10.5 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.11.3 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.11.2 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.11.1 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.10.3 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.11.0 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.10.2 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.9.6 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.8.6 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.10.1 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.9.5 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.10.0 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.9.4 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.6.6 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.7.4 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.8.5 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.9.3 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.9.2 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.10.0.beta1 lib/spree/testing_support/factories/stock_location_factory.rb
solidus_core-2.7.3 lib/spree/testing_support/factories/stock_location_factory.rb