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?



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

  • I've tried using that followed by: if($myDropdownFieldValue == 'xxx'){ $lineItem->price = 25; } But it seems to apply it to every variant, regardless of the option chosen. – Adam Ladrach Aug 21 '16 at 16:54
  • 1
    If you add your full code we can probably help with that... – Jeremy Daalder Nov 18 '16 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.