Send email to notify customer that files for virtual products are available

@param OrderEvent $event
@throws \Exception
769284
public function sendEmail(OrderEvent $event)
    {
        $order = $event->getOrder();

        // Be sure that we have a document to download
        $virtualProductCount = OrderProductQuery::create()
            ->filterByOrderId($order->getId())
            ->filterByVirtual(true)
            ->filterByVirtualDocument(null, Criteria::NOT_EQUAL)
            ->count();

        if ($virtualProductCount > 0) {
            $customer = $order->getCustomer();

            $this->mailer->sendEmailToCustomer(
                'mail_virtualproduct',
                $customer,
                [
                    'customer_id' => $customer->getId(),
                    'order_id' => $order->getId(),
                    'order_ref' => $order->getRef(),
                    'order_date' => $order->getCreatedAt(),
                    'update_date' => $order->getUpdatedAt()
                ]
            );
        } else {
            Tlog::getInstance()->warning(
                "Virtual product download message not sent to customer: there's nothing to downnload"
            );
        }
    }
634888
public function handleReorder(ReorderEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof RoutablePageBehavior || !$document instanceof ParentBehavior) {
            return;
        }

        $parentDocument = $document->getParent();
        if (!$parentDocument instanceof ChildrenBehavior) {
            return;
        }

        $locale = $this->documentInspector->getLocale($parentDocument);
        $propertyName = $this->getRoutePathPropertyName($parentDocument->getStructureType(), $locale);
        foreach ($parentDocument->getChildren() as $childDocument) {
            $node = $this->documentInspector->getNode($childDocument);

            $route = $this->chainRouteGenerator->generate($childDocument);
            $childDocument->setRoutePath($route->getPath());

            $node->setProperty($propertyName, $route->getPath());
        }
    }
845532
public function onModelAfterSave(Event $event)
    {
        /** @var User|bool $user */
        $user = $event->getData('user');

        if ($user instanceof EntityInterface) {
            if ($user->isNew() && Filter::bool($user->get('notify'))) {
                $this->_getMailer($user)->sendCreateMessage();
            }
        }
    }
1330078
public function onPostStateChange(OrderEvent $event)
    {
        $order = $event->getOrder();
        $cart  = $this->provider->getCart();
        if ($order->getId() === $cart->getId() && $order->getType() !== OrderTypes::TYPE_CART) {
            $this->provider->clearCart();
        }
    }
950414
protected function performAdditionalUpdateAction($updateEvent)
    {
        // Associate the file if it's a virtual product
        // and with only 1 PSE
        $virtualDocumentId = \intval($updateEvent->getVirtualDocumentId());

        if ($virtualDocumentId >= 0) {
            $defaultPSE = ProductSaleElementsQuery::create()
                ->filterByProductId($updateEvent->getProductId())
                ->filterByIsDefault(true)
                ->findOne();

            if (null !== $defaultPSE) {
                if ($virtualDocumentId !== 0) {
                    $assocEvent = new MetaDataCreateOrUpdateEvent('virtual', MetaData::PSE_KEY, $defaultPSE->getId(), $virtualDocumentId);
                    $this->dispatch(TheliaEvents::META_DATA_UPDATE, $assocEvent);
                } else {
                    $assocEvent = new MetaDataDeleteEvent('virtual', MetaData::PSE_KEY, $defaultPSE->getId());
                    $this->dispatch(TheliaEvents::META_DATA_DELETE, $assocEvent);
                }
            }
        }

        return null;
    }
1310731
public function persistPageDataOnReorder(ReorderEvent $event)
    {
        $document = $event->getDocument();
        if (!$document instanceof ArticlePageDocument) {
            return;
        }

        $document = $document->getParent();
        $node = $this->documentInspector->getNode($document);

        $this->setPageData($document, $node, $document->getLocale());

        $document->setWorkflowStage(WorkflowStage::TEST);
        $this->documentManager->persist($document, $this->documentInspector->getLocale($document));

        $this->documents[$document->getUuid()] = [
            'uuid' => $document->getUuid(),
            'locale' => $document->getLocale(),
        ];
    }
396900
public function updateOrderStatus(OrderEvent $event)
    {
        $paybox = new Paybox();

        if ($event->getOrder()->isPaid() && $paybox->isPaymentModuleFor($event->getOrder())) {
            $contact_email = ConfigQuery::read('store_email', false);

            Tlog::getInstance()->debug(
                "Order ".$event->getOrder()->getRef().": sending confirmation email from store contact e-mail $contact_email"
            );

            if ($contact_email) {
                $order = $event->getOrder();

                $this->getMailer()->sendEmailToCustomer(
                    Paybox::CONFIRMATION_MESSAGE_NAME,
                    $order->getCustomer(),
                    [
                        'order_id' => $order->getId(),
                        'order_ref' => $order->getRef()
                    ]
                );

                Tlog::getInstance()->debug("Order ".$order->getRef().": confirmation email sent to customer.");

                if (Paybox::getConfigValue('send_confirmation_email_on_successful_payment', false)) {
                    // Send now the order confirmation email to the customer
                    $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
                }
            }
        } else {
            Tlog::getInstance()->debug(
                "Order ".$event->getOrder()->getRef().": no confirmation email sent (order not paid, or not the proper payment module)."
            );
        }
    }
779304
public function onPaymentNotify(PaymentEvent $event)
    {
        $payment = $event->getPayment();
        if (!$payment instanceof OrderPayment) {
            return;
        }

        $order = $payment->getOrder();

        if ($order->getLocked()) {
            $order->setLocked(false);
            $this->updateOrder($order, $event);
        }
    }
10071
public function beforeRender(Event $event)
    {

        parent::beforeRender($event);

        // when a shop order was placed, the pdfs that are rendered for the order confirmation email
        // called this method and therefore called resetOriginalLoggedCustomer() => email was sent t
        // the user who placed the order for a member and not to the member
        if ($this->getResponse()->getType() != 'text/html') {
            return;
        }

        $this->resetOriginalLoggedCustomer();

        $categoriesForMenu = [];
        if (Configure::read('appDb.FCS_SHOW_PRODUCTS_FOR_GUESTS') || $this->AppAuth->user()) {
            $this->Category = TableRegistry::getTableLocator()->get('Categories');
            $allProductsCount = $this->Category->getProductsByCategoryId(Configure::read('app.categoryAllProducts'), false, '', 0, true);
            $newProductsCount = $this->Category->getProductsByCategoryId(Configure::read('app.categoryAllProducts'), true, '', 0, true);
            $categoriesForMenu = $this->Category->getForMenu();
            array_unshift($categoriesForMenu, [
                'slug' => Configure::read('app.slugHelper')->getNewProducts(),
                'name' => __('New_products') . ' <span class="additional-info"> (' . $newProductsCount . ')</span>',
                'options' => [
                    'fa-icon' => 'fa-star' . ($newProductsCount > 0 ? ' gold' : '')
                ]
            ]);
            array_unshift($categoriesForMenu, [
                'slug' => Configure::read('app.slugHelper')->getAllProducts(),
                'name' => __('All_products') . ' <span class="additional-info"> (' . $allProductsCount . ')</span>',
                'options' => [
                    'fa-icon' => 'fa-tags'
                ]
            ]);
        }
        $this->set('categoriesForMenu', $categoriesForMenu);

        $this->Manufacturer = TableRegistry::getTableLocator()->get('Manufacturers');
        $manufacturersForMenu = $this->Manufacturer->getForMenu($this->AppAuth);
        $this->set('manufacturersForMenu', $manufacturersForMenu);

        $this->Page = TableRegistry::getTableLocator()->get('Pages');
        $conditions = [];
        $conditions['Pages.active'] = APP_ON;
        $conditions[] = 'Pages.position > 0';
        if (! $this->AppAuth->user()) {
            $conditions['Pages.is_private'] = APP_OFF;
        }

        $pages = $this->Page->getThreaded($conditions);
        $pagesForHeader = [];
        $pagesForFooter = [];
        foreach ($pages as $page) {
            if ($page->menu_type == 'header') {
                $pagesForHeader[] = $page;
            }
            if ($page->menu_type == 'footer') {
                $pagesForFooter[] = $page;
            }
        }
        $this->set('pagesForHeader', $pagesForHeader);
        $this->set('pagesForFooter', $pagesForFooter);
    }
1239387
public static function EnsureFileExists(Event $event, $path)
	{
		if (!is_dir(dirname($path))) {
			mkdir(dirname($path), 0777, true);
			touch($path);
			if (!file_exists($path)) {
				throw new \Exception('File Not Found: '.$path);
			}
			if ($event->getIO()->isVerbose() === true) {
				$event->getIO()->write(sprintf('Created File <info>%s</info>', $path));
			}
		}
	}
763376
public function onRemove(OrderItemEvent $event)
    {
        $order = $event->getOrder();
        $item  = $event->getItem();

        $order->removeItem($item);
    }
501778
public function onPostContentChange(OrderEvent $event)
    {
        $order = $event->getOrder();
        if ($order->getType() == OrderTypes::TYPE_CART) {
            $this->provider->setCart($order);
        }
    }
887491
public function sendorder()
    {
        parent::sendorder();
        /** @var oxOrder $oOrder */
        $oOrder = $this->_getContainer()->getObjectFactory()->createOxidObject('oxOrder');

        if ($oOrder->load($this->getEditObjectId()) === true
            && $oOrder->getFieldData('oxPaymentType') === 'bestitamazon'
        ) {
            $this->_getContainer()->getClient()->saveCapture($oOrder);
        }
    }
766769
public function updateStatus(OrderEvent $event)
    {
        $order = $event->getOrder();

        if ($order->isPaid() && $order->getPaymentModuleId() == Atos::getModuleId()) {
            if (Atos::getConfigValue('send_payment_confirmation_message')) {
                $this->mailer->sendEmailToCustomer(
                    Atos::CONFIRMATION_MESSAGE_NAME,
                    $order->getCustomer(),
                    [
                        'order_id'  => $order->getId(),
                        'order_ref' => $order->getRef()
                    ]
                );
            }

            // Send confirmation email if required.
            if (Atos::getConfigValue('send_confirmation_message_only_if_paid')) {
                $event->getDispatcher()->dispatch(TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL, $event);
            }

            Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
        }
    }
729583
public function addOrder(Order $order)
    {
        if (count($this->orders)+1 >= self::MAX_NUM_ORDERS)
        {
            throw new Exception('Cannot have more than '.self::MAX_NUM_ORDERS.' Orders in a single Order Collection');
        }

        $this->orders[] = $order;
        $order->setCollection($this);
    }
415342
public function onPackageBeforeExecute(Event $event)
    {
        if ($event['hmvc']) {
            return;
        }

        /** @var Input $input */
        $package = $event['package'];

        if (!$package instanceof DebuggerPackage) {
            return;
        }

        $controller = $event['controller'];
        $input      = $controller->getInput();
        $app        = Ioc::getApplication();
        $uri        = Ioc::getUriData();

        $noRedirect = [
            'asset',
            'mail',
        ];

        if (in_array($app->get('route.short_name'), $noRedirect)) {
            return;
        }

        /** @var Repository $model */
        $repository = $controller->getRepository('Dashboard');

        if ($input->get('refresh')) {
            $hash = $input->getString('hash');
            $hash = $hash ? '#' . $hash : '';

            $input->set('id', null);

            if (Ioc::exists('session')) {
                $session = Ioc::getSession();
                $session->set('debugger.current.id', null);
            }

            $item = $repository->getLastItem();

            if ($item) {
                $app->redirect($package->router->route($app->get('route.matched'), ['id' => $item['id']]) . $hash);

                return;
            }
        }

        if (!$id = $input->get('id')) {
            $session = Ioc::getSession();

            // Get id from session
            $id = $session->get('debugger.current.id');

            // If session not exists, get last item.
            if (!$id) {
                $item = $repository->getLastItem();

                // No item, redirect to front-end.
                if (!$item) {
                    $app->redirect($uri['base.full'] . $uri['script']);

                    return;
                }

                $id = $item['id'];
            }

            // set id to session and redirect
            $session->set('debugger.current.id', $id);

            $app->redirect($package->router->route($app->get('route.matched'), ['id' => $id]));

            return;
        }

        $itemModel = $controller->getRepository('Profiler');

        if (!$itemModel->hasItem($id)) {
            $session = Ioc::getSession();
            $session->set('debugger.current.id', null);

            $app->redirect($package->router->route('dashboard'));
        }

        if (Ioc::exists('session')) {
            $session = Ioc::getSession();
            $session->set('debugger.current.id', $id);
        }
    }
979788
public function onPostInstall(Event $event)
    {
        $lockFile = new JsonFile($this->lockFile);
        if ($lockFile->exists()) {
            $this->loadPackages($lockFile);
        } else {
            $this->scanPackages();
        }
        $this->runAction('install');
    }