cancel
Showing results for 
Search instead for 
Did you mean: 

Send mail notification

Send mail notification

Hi, I need to email the customer when his account expires, can you help me complete this code?

 

    /**
     * Execute process membership expired
     *
     * @throws \Exception
     */
    public function execute()
    {
        // Check that the module functionality is enabled.
        if (!$this->configHelper->isEnabled()) {
            return;
        }

        /** @var \Magento\Customer\Model\ResourceModel\Customer\Collection $customerCollection */
        $customers = $this->customerCollectionFactory->create();
        $customers
            ->addFieldToFilter('group_id', [
                'neq' => $this->configHelper->getRevokeGroup()
            ])
            ->addAttributeToFilter('membership_expiry', [
                'lteq' => $this->dateTime->gmtDate(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT)
            ]);

        /** @var Customer $customer */
        foreach ($customers as $customer) {
            $this->customerManagement->revokeMembership($customer);
        }

        // Could be used for dispatching emails to inform the customer of their expired membership.
        $this->eventManager->dispatch(
            'membership_expired_customers',
            [
                'customers' => $customers
            ]
        );
    }