From d056a5e766c12abf7e431a8e275fda25be4468fd Mon Sep 17 00:00:00 2001 From: Emi Matchu Date: Fri, 27 Sep 2024 18:27:12 -0700 Subject: [PATCH] Oops, don't show not-directly-for-sale items as being "0 NC" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Fall Woodland Leaves Filter" is an example, it's part of the two-item *pack* named "Fall Woodland Minitheus Petpet Foreground". The NC Mall page for it will include the secondary items in `object_data`, but it's not part of the storefront itself—and the only thing indicating that is the `render` list. Theoretically, we could use this to construct more data about like, packs and stuff, automatically? But also, I don't want to backfill it for everything historically, so like. Whatever. --- app/services/nc_mall.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/services/nc_mall.rb b/app/services/nc_mall.rb index 9c914af3..e42df5d0 100644 --- a/app/services/nc_mall.rb +++ b/app/services/nc_mall.rb @@ -76,11 +76,20 @@ module NCMall raise UnexpectedResponseFormat, "missing field object_data in NC page" end + object_data = nc_page["object_data"] + # NOTE: When there's no object data, it will be an empty array instead of # an empty hash. Weird API thing to work around! - nc_page["object_data"] = {} if nc_page["object_data"] == [] + object_data = {} if object_data == [] - items = nc_page["object_data"].values.map do |item_info| + # Only the items in the `render` list are actually listed as directly for + # sale in the shop. `object_data` might contain other items that provide + # supporting information about them, but aren't actually for sale. + visible_object_data = (nc_page["render"] || []). + map { |id| object_data[id.to_s] }. + filter(&:present?) + + items = visible_object_data.map do |item_info| { id: item_info["id"], name: item_info["name"],