The Product Offered Countries Sync (ProductOfferedCountriesSync) Data Block is part of the Assette initial set up and is not normally edited by end user. To update the offered product, see the Source Product Offer Countries Data Block instead.
The Product Offered Countries Sync (ProductOfferedCountriesSync) Data Block is used to update and synchronize the offered product and countries with Assette. The Product Offered Countries Sync (ProductOfferedCountriesSync) Data Block is not normally edited by end user. If updating the product’s countries, see Source Product Offer Countries (Source_ProductOfferCountries) Data Block instead
General Info
Field | Value |
---|---|
Name | ProductOfferedCountriesSync |
Block Category | Transform |
Block Type | Python |
Data Category | None |
Output Type | Data Table |
Example Definition
# Retrieve data from dependant blocks
ProductMaster_df = pd.DataFrame(read("Source_ProductOfferCountries", {})["data"])
ProductMaster_Local_df = pd.DataFrame(read("ProductMasterLocal", {})["data"])
Countries_Local_df = pd.DataFrame(read("CountriesLocaldb", {})["data"])
# Creating a DataFrame for Distinct Products and Associated Countries
Distinct_Products_df = ProductMaster_df[['PRODUCTCODE', 'COUNTRYCODE']].drop_duplicates()
# Merge DataFrames to get ProductID and filter the common records available in two DataFrames
ProductMaster_Merged_df = pd.merge(Distinct_Products_df, ProductMaster_Local_df, left_on="PRODUCTCODE", right_on="Code", how="inner")
# Merge DataFrames to get CountryId available in Local DB and append it into Distinct_Products_df
ProductMaster_Merged_df['CountryId'] = pd.merge(ProductMaster_Merged_df, Countries_Local_df, left_on="COUNTRYCODE", right_on="Key", how="left")["Id"]
# Convert dataframe into a dictionary
output_list = []
for index, row in ProductMaster_Merged_df.iterrows():
output_list.append({
"ProductId": int(row["ProductID"]) if pd.notnull(row["ProductID"]) else None,
"CountryId": int(row["CountryId"]) if pd.notnull(row["CountryId"]) else None
})
# Data response
response["data"] = output_list
Example Request
{}
Example Response
{
"data": [
{
"ProductId": 1,
"CountryId": 34
}
],
"errors": [],
"success": true,
"logs": []
}