2

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!

1 Answer 1

1

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

2
  • 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. Commented Aug 21, 2016 at 16:54
  • 1
    If you add your full code we can probably help with that... Commented Nov 18, 2016 at 0:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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