Class: CatalogItem::LegacySetAmazonCatalogItemPricesFromListingsData
- Inherits:
-
BaseService
- Object
- BaseService
- CatalogItem::LegacySetAmazonCatalogItemPricesFromListingsData
- Defined in:
- app/services/catalog_item/legacy_set_amazon_catalog_item_prices_from_listings_data.rb
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#process(catalog_item_id_or_catalog_item:, force_pull_of_listing_data: false, options: {}) ⇒ Object
Processes all Amazon VC catalogs' catalog items, attempting to pull their listing item data.
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#process(catalog_item_id_or_catalog_item:, force_pull_of_listing_data: false, options: {}) ⇒ Object
Processes all Amazon VC catalogs' catalog items, attempting to pull their listing item data. Mark the catalog item as pending_onboarding if no corresponding listing item data found, also accept force_pricing_sync to:
use Catalog::UpdateCatalogItem
- Store the procurement cost price to catalog item's amount
- Store the list price to catalog item's retailer advertised price
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/services/catalog_item/legacy_set_amazon_catalog_item_prices_from_listings_data.rb', line 14 def process(catalog_item_id_or_catalog_item:, force_pull_of_listing_data: false, options: {}) raise ArgumentError, 'Deprecated, this is from a bygone era where we used amazon as master data' catalog_item = catalog_item_id_or_catalog_item if catalog_item_id_or_catalog_item.is_a? CatalogItem catalog_item ||= CatalogItem.find(catalog_item_id_or_catalog_item) = [] catalog_items_updated = [] catalog_items_failed = [] orch = catalog_item&.catalog&.load_orchestrator logger.info '==========================================================================' logger.info 'Set Amazon Catalog Item From Listings Data start.' logger.info "Processing Catalog Item SKU: #{catalog_item.sku}, ID: #{catalog_item.id}:" logger.info "force_pull_of_listing_data: #{force_pull_of_listing_data}, options: #{}" logger.info '==========================================================================' if orch && force_pull_of_listing_data res = CatalogItem::PullAmazonCatalogItemListingsData.new.process(catalog_item_id_or_catalog_item: ci, force_pricing_sync: false) unless res.catalog_item_listings_data_pulled? catalog_items_failed << ci << res..join(', ') end end err = false # if cost_price = catalog_item.extract_amazon_information(:cost_price).to_f # here we check this option to actually update the catalog item pricatalog_itemng with the cost_price returned # Argh, this is not trustable and lags behind or in any case is the old cost_price, we need to use the procurement/costPrice attribute, see https://3.basecamp.com/3233448/buckets/8400892/todos/7670717634 if cost_price = catalog_item.extract_amazon_procurement_cost_price # here we check this option to actually update the catalog item with the cost_price returned result_cost_price = Catalog::UpdateCatalogItem.new.process(catalog_item.id, { amount: cost_price }) unless result_cost_price.catalog_item_updated? err = true += result_cost_price. end end if list_price = catalog_item.extract_amazon_information(:list_price).to_f # here we check this option to actually update the catalog item pricing with the cost_price returned result_list_price = Catalog::UpdateCatalogItem.new.process(catalog_item.id, { retail_price: list_price }) unless result_list_price.catalog_item_updated? err = true += result_list_price. end end if err catalog_items_failed << catalog_item msg = "Error setting prices for catalog Item #{catalog_item.id}, error: #{.join(', ')}" logger.info '==========================================================================' logger.info "#{msg}" logger.info '==========================================================================' << msg else catalog_items_updated << catalog_item end logger.info '==========================================================================' logger.info 'Amazon Vendor Central Catalog Item Listings Data Worker processing end.' logger.info '==========================================================================' Result.new(catalog_item_price_set: catalog_items_failed.empty?, messages:, catalog_items_updated:, catalog_items_failed:) end |