This question has been asked before but I'm trying to do this with Magento 2.1.

Would the correct approach be to create an observer for the "sales_model_service_quote_submit_success" event? and then look up the ordered Item's SKU's/IDs and if one matches my special product then lookup and update the customer group?

And would this approach also work with orders created in the backend by an admin?

Here's a snippet from my observer code (be gentle, this is the first PHP I've ever written let alone the first Magento 2.1 module)

     * @param Observer $observer
     * @return void
    public function execute( Observer $observer ) {



        if ( $this->isCustomerLoggedIn() ) {

            $order = $observer->getEvent()->getOrder();

            $ledenProduct = $this->scopeConfiguration->getValue('marviq_checkout_config/product/product', ScopeInterface::SCOPE_STORE);
            $groupId = $this->scopeConfiguration->getValue('marviq_checkout_config/product/customer_group', ScopeInterface::SCOPE_STORE);

            $customerId    = $order->getCustomerId();
            $customer      = $this->customerRepository->getById( $customerId );

            $items = $order->getAllItems();
            foreach ($items as $item) {
                $itemId = $item->getItemId();
                if ($itemId == "Special") {


     * Check if customer is logged in
     * @return bool
     * @codeCoverageIgnore
    private function isCustomerLoggedIn() {
        return (bool) $this->httpContext->getValue( CustomerContext::CONTEXT_AUTH );
  • Do you want to change this after place order? – Sohel Rana Feb 4 '17 at 15:01
  • Correct, after an order has been successfully made, i.e. after they have paid at the payment-service-provider and have come back to my Magento application. – Duncan Campbell Feb 4 '17 at 17:54

Your Answer

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

Browse other questions tagged or ask your own question.