Is there a way to check if an item option or any o...
# suitecommerce
k
Is there a way to check if an item option or any option has been selected on a PDP?
I am attempting to check if there has been an item option selected by checking if there are any query string query parameters present, however it doesn't seem to be working. Is there a SC method that can help me with this?
Copy code
for (var i = 0; i < itemInfoObj.options.length; i++) {
										if (itemInfoObj.options[i].type == 'select') {
											var cartOptionId = itemInfoObj.options[i].cartOptionId;
											var firstInternalId = itemInfoObj.options[i].values[1].internalid;
											// if there are no query string parameters present
											if (window.location.search == "") {
												// set the first option via pdp.setOption
												PDP.setOption(cartOptionId, firstInternalId);
											}
										}
									}
k
I am using that already
See above post. It’s firing on page load before an item is selected
s
Sorry, do you want something that triggers every time a user makes an option selection? Use `afterOptionSelect`: https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/PDP.html#event:afterOptionSelection
l
@Kevin Carpenter, I'd try using the two follwoing events
Copy code
PDP.on('afterShowContent', function(){}
Copy code
PDP.on('afterOptionSelection', function(){}
The first one will allow you to manage the scenario if the user reloads the page... and the second one is triggered after the options are selected. Those two were a huge help when working on a customization on the product detail level and managing matrix items