From 4c451985ee2dc24cd709bfddcdad62a81fd55620 Mon Sep 17 00:00:00 2001 From: Harshita Gupta Date: Mon, 24 Jun 2024 15:25:56 +0530 Subject: [PATCH 1/3] Added stock to descrepancies --- lib/spree_apfusion/product.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/spree_apfusion/product.rb b/lib/spree_apfusion/product.rb index 7a9f666..5376422 100644 --- a/lib/spree_apfusion/product.rb +++ b/lib/spree_apfusion/product.rb @@ -80,11 +80,13 @@ def self.compared_rrw_items_with_apfs next if rrw_element.nil? if product['name'] != rrw_element.name - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], 'NAME', rrw_element.name] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'NAME', rrw_element.name] elsif product['master']['sku'] != rrw_element.sku - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], 'SKU', rrw_element.sku] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'SKU', rrw_element.sku] elsif product['meta_description'] != rrw_element.meta_description - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], 'META_DESCRIPTION', rrw_element.meta_description] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'META_DESCRIPTION', rrw_element.meta_description] + elsif product['total_on_hand'] != rrw_element.total_on_hand + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'STOCKS', rrw_element.total_on_hand] end end end From f9251a0a7ef01338a1834ff822084f942d75c894 Mon Sep 17 00:00:00 2001 From: Harshita Gupta Date: Wed, 26 Jun 2024 17:28:06 +0530 Subject: [PATCH 2/3] Recording errors --- lib/spree_apfusion/product.rb | 8 +++++++- lib/spree_apfusion/stock_item.rb | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/spree_apfusion/product.rb b/lib/spree_apfusion/product.rb index 5376422..2f8509b 100644 --- a/lib/spree_apfusion/product.rb +++ b/lib/spree_apfusion/product.rb @@ -2,7 +2,7 @@ module SpreeApfusion class Product def self.fetch ids - SpreeApfusion::OAuth.send(:get, "/api/v2/products.json", { ids: ids }) + SpreeApfusion::OAuth.send(:get, "/api/v2/products.json", { ids: ids, per_page: 100 }) end def self.create product @@ -11,6 +11,10 @@ def self.create product if response[:success] == true && response[:response].present? && response[:response]["id"].present? product.update_attributes(apfusion_product_id: response[:response]["id"], last_sync_to_apf_at: Time.current) product.master.update_attributes(apfusion_variant_id: response[:response]["master"]["id"]) + elsif response[:success] == true && response[:response].present? && response[:response]["errors"].present? + product.update_column('apfusion_response', response[:response]["errors"].to_s) + else + product.update_column('apfusion_response', response.to_s) end end @@ -21,6 +25,8 @@ def self.update product response = SpreeApfusion::OAuth.send(:PUT, '/api/v2/products/'+product.apfusion_product_id.to_s+'.json', {product: product_hash,filter_type: "id"}) if response[:success] == true product.update_attributes(last_sync_to_apf_at: Time.current) + else + product.update_column('apfusion_response', response.to_s) end response end diff --git a/lib/spree_apfusion/stock_item.rb b/lib/spree_apfusion/stock_item.rb index e9eb144..9f55d0a 100644 --- a/lib/spree_apfusion/stock_item.rb +++ b/lib/spree_apfusion/stock_item.rb @@ -13,6 +13,8 @@ def self.create stock_item if response[:success] == true && response[:response].present? if response[:response].is_a?(Hash) && response[:response]["id"].present? @stock_item.update_attributes(apfusion_stock_item_id: response[:response]["id"]) + elsif response[:response].is_a?(Hash) && response[:response]["errors"].present? + @stock_item.update_column('apfusion_response', response[:response]["errors"]) elsif response[:response].is_a?(Array) @stock_item.update_attributes(apfusion_stock_item_id: response[:response][0]["id"]) end @@ -26,8 +28,17 @@ def self.update stock_item response = SpreeApfusion::OAuth.send(:PUT, '/api/v2/stock_locations/'+@stock_item.stock_location.apfusion_stock_location_id.to_s+'/stock_items/'+@stock_item.apfusion_stock_item_id.to_s+'.json', {stock_item: @stock_item_hash,filter_type: "id"}) - if response[:success] == true - @stock_item.product.update_attributes(last_sync_to_apf_at: Time.current) + if response.is_a?(String) + @stock_item.update_column('apfusion_response', response) + elsif response[:success] == true + if response[:response].present? && response[:response]["errors"].present? + @stock_item.update_column('apfusion_response', response[:response]["errors"].to_s) + else + @stock_item.product.update_attributes(last_sync_to_apf_at: Time.current) + @stock_item.update_column('apfusion_response', nil) + end + else + @stock_item.update_column('apfusion_response', response.to_s) end response From 9d3216b3f7eee3a2c9385b57d6e1f6c9a1f27ddb Mon Sep 17 00:00:00 2001 From: Harshita Gupta Date: Wed, 4 Sep 2024 14:47:26 +0530 Subject: [PATCH 3/3] APF descrepancy | is_block_whole_sale? --- lib/spree_apfusion/product.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/spree_apfusion/product.rb b/lib/spree_apfusion/product.rb index 2f8509b..c34b463 100644 --- a/lib/spree_apfusion/product.rb +++ b/lib/spree_apfusion/product.rb @@ -86,13 +86,13 @@ def self.compared_rrw_items_with_apfs next if rrw_element.nil? if product['name'] != rrw_element.name - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'NAME', rrw_element.name] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'NAME', rrw_element.name, rrw_element.is_block_whole_sale?] elsif product['master']['sku'] != rrw_element.sku - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'SKU', rrw_element.sku] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'SKU', rrw_element.sku, rrw_element.is_block_whole_sale?] elsif product['meta_description'] != rrw_element.meta_description - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'META_DESCRIPTION', rrw_element.meta_description] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'META_DESCRIPTION', rrw_element.meta_description, rrw_element.is_block_whole_sale?] elsif product['total_on_hand'] != rrw_element.total_on_hand - @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'STOCKS', rrw_element.total_on_hand] + @unmatched_row << [product['name'], product['master']['sku'], product['meta_description'], product['total_on_hand'], 'STOCKS', rrw_element.total_on_hand, rrw_element.is_block_whole_sale?] end end end