To begin, please make sure that the pricing parameter feature is activated within your account.
Next, using the custom functions interface, you can load the parameter sheet data into a variable.
Follow these steps:
example_variable = ctx.get_pricing_parameters('parameter_sheet_name', keys_dict)Here, 'parameter_sheet_name' should be replaced with the name of your specific parameter sheet, and 'keys_dict' should contain the necessary key-value pairs for retrieval.
key_dict = {"key column label":"Value to look for", "key column label2":"Value to look for2"}
For example, if 'brand' is the key column:
This code snippet:
ctx = get_context()
key = {"brand":"Giorgio Armani"}
pricing_parameters = ctx.get_pricing_parameters('Test_Guide',key)
ctx.log(pricing_parameters)
This code will result in a variable containing the parameter sheet data, providing insights like:
{'data': [{'name': 'brand', 'value': 'Giorgio Armani'}, {'name': 'gtin', 'value': '1234567890'}], 'error': ''}
You can also use a variable as the value to look for, offering a more generic approach. For instance:
brand_value = get_attr("brand") # a function to bring back the brand value
key = {"brand": brand_value}
Tip
Ensure that you handle cases where a product lacks the attribute you are searching for to prevent errors in custom pricing functions.
With the data loaded, you can now access it as needed. To retrieve the value for 'Giorgio Armani' brand, you can use the following code snippet:
gtin_value = None # Default value if 'gtin' is not found
for item in pricing_parameters['data']: #or this
if item['name'] == 'gtin':
gtin_value = item['value']
break
Executing this code with the provided data will yield the output: 1234567890.
Limitations
- Each client key can have up to 20 parameter sheets, and each sheet's name must be unique.
- A parameter sheet can contain a maximum of 2500 rows and 30 columns.
- Each parameter sheet must include at least one key column and can have up to five.
- Values cannot exceed 255 characters.
- Ensure that your CSV file has a header row.
- The CSV file must be in UTF-8 format.
Comments
0 comments
Please sign in to leave a comment.