THELIA Forum

Welcome to the THELIA support and discusssion forum

Announcement

Rejoignez la communauté sur le Discord Thelia : https://discord.gg/YgwpYEE3y3

Offline


Bonjour,

J'essaye de ne pas envoyer de mail de confirmation de commande avant que la commande soit considérée comme payé. Je suis allé voir dans les fichiers du module Atos et le fichier dans Atos/EventListeners/SendConfirmationEmail.php à la class SendConfirmationEmail
La class d'origine est :

class SendConfirmationEmail implements EventSubscriberInterface
{
    /**
     * @var ParserInterface
     */
    protected $parser;

    /**
     * @var MailerFactory
     */
    protected $mailer;

    public function __construct(ParserInterface $parser, MailerFactory $mailer)
    {
        $this->parser = $parser;
        $this->mailer = $mailer;
    }

    public function updateStatus(OrderEvent $event)
    {
        $atos = new Atos();
        $order = $event->getOrder();
        
        if ($order->isPaid() && $atos->isPaymentModuleFor($order)) {
            $this->mailer->sendEmailToCustomer(
                Atos::CONFIRMATION_MESSAGE_NAME,
                $order->getCustomer(),
                [
                    'order_id' => $order->getId(),
                    'order_ref' => $order->getRef()
                ]
            );

            Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
        }
    }

    /**
     * Returns an array of event names this subscriber wants to listen to.
     *
     * The array keys are event names and the value can be:
     *
     *  * The method name to call (priority defaults to 0)
     *  * An array composed of the method name to call and the priority
     *  * An array of arrays composed of the method names to call and respective
     *    priorities, or 0 if unset
     *
     * For instance:
     *
     *  * array('eventName' => 'methodName')
     *  * array('eventName' => array('methodName', $priority))
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
     *
     * @return array The event names to listen to
     *
     * @api
     */
    public static function getSubscribedEvents()
    {
        return [
            TheliaEvents::ORDER_UPDATE_STATUS => ["updateStatus", 128]
        ];
    }
}

Apaprement le mail ne devrait s'envoyer que si on a la condition ispaid. MAis ce n'est pas le cas.
J'ai tenté une modification mais il n'y a pas eu de changement de comportement :

class SendConfirmationEmail implements EventSubscriberInterface
{
    /**
     * @var ParserInterface
     */
    protected $parser;

    /**
     * @var MailerFactory
     */
    protected $mailer;

    public function __construct(ParserInterface $parser, MailerFactory $mailer)
    {
        $this->parser = $parser;
        $this->mailer = $mailer;
    }

    public function updateStatus(OrderEvent $event)
    {
        $atos = new Atos();
        $order = $event->getOrder();
        if (! $order->isPaid()) {
                $event->stopPropagation();
            }

        elseif ($order->isPaid() && $atos->isPaymentModuleFor($order)) {
            $this->mailer->sendEmailToCustomer(
                Atos::CONFIRMATION_MESSAGE_NAME,
                $order->getCustomer(),
                [
                    'order_id' => $order->getId(),
                    'order_ref' => $order->getRef()
                ]
            );

            Tlog::getInstance()->debug("Confirmation email sent to customer " . $order->getCustomer()->getEmail());
        }
    }

    /**
     * Returns an array of event names this subscriber wants to listen to.
     *
     * The array keys are event names and the value can be:
     *
     *  * The method name to call (priority defaults to 0)
     *  * An array composed of the method name to call and the priority
     *  * An array of arrays composed of the method names to call and respective
     *    priorities, or 0 if unset
     *
     * For instance:
     *
     *  * array('eventName' => 'methodName')
     *  * array('eventName' => array('methodName', $priority))
     *  * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
     *
     * @return array The event names to listen to
     *
     * @api
     */
    public static function getSubscribedEvents()
    {
        return [
            TheliaEvents::ORDER_UPDATE_STATUS => ["updateStatus", 128]
        ];
    }
}

JE dois mal m'y prendre et peut être que je ne regarde pas au bon endroit ?

Last edited by Milo1986 (27-11-2015 19:31:53)

Offline


C'est l'event ORDER_SEND_CONFIRMATION_EMAIL qu'il te faut intercepter, genre :

    /**
     * Send the confirmation message only if the order is paid.
     *
     * @param OrderEvent $event
     */
    public function checkSendOrderConfirmationMessageToCustomer(OrderEvent $event)
    {
        $atos= new Atos();

        if ($atos->isPaymentModuleFor($event->getOrder())) {
            if (! $event->getOrder()->isPaid()) {
                $event->stopPropagation();
            }
        }
    }

    public static function getSubscribedEvents()
    {
        return array(
            TheliaEvents::ORDER_UPDATE_STATUS => array("updateStatus", 128),
            TheliaEvents::ORDER_SEND_CONFIRMATION_EMAIL => array("checkSendOrderConfirmationMessageToCustomer", 130)
        );
    }

OpenStudio Toulouse

Offline


Super merci ça fonctionne !