I'm trying to access a custom variant dropdown field in a plugin inside the commerce_lineItems.onPopulateLineItem
event. How would I access the value of the dropdown, in order to do a comparison on it?
Thanks!
Something like this should work:
public function init()
{
craft()->on('commerce_lineItems.onPopulateLineItem', function(Event $event) {
$purchasable = $event->params['purchasable'];
$myDropdownFieldValue = $purchasable->getProduct()->getContent()->myDropdownField;
});
}
Relevant event docs: https://craftcommerce.com/docs/events-reference#commerce_lineitems.onpopulatelineitem
if($myDropdownFieldValue == 'xxx'){ $lineItem->price = 25; }
But it seems to apply it to every variant, regardless of the option chosen.
Commented
Aug 21, 2016 at 16:54