Merge pull request #13151 from mkllnk/dfc-stock-limit

Fix reset stock when importing DFC products
This commit is contained in:
Maikel
2025-02-24 15:47:12 +11:00
committed by GitHub
2 changed files with 20 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ class CatalogItemBuilder < DfcBuilder
if limit.to_i.negative?
variant.stock_items[0].backorderable = true
else
variant.stock_items[0].backorderable = false
variant.stock_items[0].count_on_hand = limit
end
end

View File

@@ -28,4 +28,23 @@ RSpec.describe DfcBuilder do
)
end
end
describe ".apply_stock" do
let(:item) { CatalogItemBuilder.catalog_item(variant) }
it "updates from on-demand to out-of-stock" do
variant.save!
variant.on_demand = true
variant.on_hand = -3
item.stockLimitation = 0
expect {
CatalogItemBuilder.apply_stock(item, variant)
variant.save!
}
.to change { variant.on_demand }.to(false)
.and change { variant.on_hand }.to(0)
end
end
end