Page 1 of 1

Overriding includes/modules/notifications/n_checkout.php

Posted: Fri Jan 27, 2023 11:40 am
by Moxamint
Hi,

I was trying to override includes/modules/notifications/n_checkout.php with templates/override/includes/modules/notifications/n_checkout.php without success. The former file does not seem overridden by the latter.

I'm doing so to change the subject of the order notification e-mail, in which I'd like to include the order number. Therefore, it wouldn't be enough to revise the language file.

Any advice will be highly appreciated.

Thanks, Eddy

Re: Overriding includes/modules/notifications/n_checkout.php

Posted: Fri Jan 27, 2023 11:57 am
by Kofod95
PWA does it with hooks, I don't remember exactly how, but I could dig it up, next time I'm at my PC :)

//Daniel

Re: Overriding includes/modules/notifications/n_checkout.php

Posted: Fri Jan 27, 2023 12:06 pm
by Moxamint
Kofod95 wrote: Fri Jan 27, 2023 11:57 am PWA does it with hooks, I don't remember exactly how, but I could dig it up, next time I'm at my PC :)

//Daniel
Please - thank you!

Re: Overriding includes/modules/notifications/n_checkout.php

Posted: Fri Jan 27, 2023 1:02 pm
by raiwa
Hook snippet from PWA:

Code: Select all

class hook_shop_siteWide_pwa {

  public $version = '4.6.0.';

  public function listen_orderMail($parameters) {

    $products_review_links = HOOK_PWA_EMAIL_REVIEWS . "\n";
    $email_order = &$parameters['email'];
    $order = $parameters['order'];

    $link = Guarantor::ensure_global('Linker')->build('ext/modules/content/reviews/write.php');
    if (isset($_SESSION['customer_is_guest'])) {
      $email_order = str_replace(MODULE_NOTIFICATIONS_CHECKOUT_TEXT_INVOICE_URL . ' ' . Guarantor::ensure_global('Linker')->build('account_history_info.php', ['order_id' => $order->get_id()]) . "\n", '', $email_order);
      $email_order .= HOOK_PWA_EMAIL_WARNING . "\n\n" .
                      MODULE_NOTIFICATIONS_CHECKOUT_SEPARATOR . "\n";
      if ($order->content_type !== 'physical') {
        $email_order .= sprintf(HOOK_PWA_EMAIL_DOWNLOAD, Guarantor::ensure_global('Linker')->build('contact_us.php')) . "\n" .
                        MODULE_NOTIFICATIONS_CHECKOUT_SEPARATOR . "\n";
      }

      $reviews_key = Password::create_random(12);
      $GLOBALS['db']->query(sprintf(<<<'EOSQL'
UPDATE orders
  SET reviews_key = '%s'
  WHERE customers_id = %d
    AND orders_id = %d
EOSQL
      , $GLOBALS['db']->escape($reviews_key), (int)$_SESSION['customer_id'], (int)$order->get_id()));

      $link->set_parameter('pwa_id', $reviews_key);
    }

    if (MODULE_CONTENT_PWA_LOGIN_CHECKOUT_REGISTERED_REVIEW_LINKS === 'True') {
      foreach ($order->products as $p) {
        $products_review_links .= '<a href="' . $link->set_parameter('products_id', Product::build_prid($p['id'])) . '">' . $p['name'] . '</a>' . "\n";
      }
      $email_order .= $products_review_links . "\n" .
                      MODULE_NOTIFICATIONS_CHECKOUT_SEPARATOR . "\n";
    }

  }

If you need more modifications, you can make a renamed copy of the core module. You just need to leave in place line 17-18 to get it used on checkout:

Code: Select all

    const TRIGGERS = [ 'checkout' ];
    const REQUIRES = [ 'address', 'greeting', 'name', 'email_address' ];

Re: Overriding includes/modules/notifications/n_checkout.php

Posted: Fri Jan 27, 2023 1:44 pm
by Moxamint
raiwa wrote: Fri Jan 27, 2023 1:02 pm Hook snippet from PWA:

Code: Select all

class hook_shop_siteWide_pwa {

  public $version = '4.6.0.';

  public function listen_orderMail($parameters) {

    $products_review_links = HOOK_PWA_EMAIL_REVIEWS . "\n";
    $email_order = &$parameters['email'];
    $order = $parameters['order'];

    $link = Guarantor::ensure_global('Linker')->build('ext/modules/content/reviews/write.php');
    if (isset($_SESSION['customer_is_guest'])) {
      $email_order = str_replace(MODULE_NOTIFICATIONS_CHECKOUT_TEXT_INVOICE_URL . ' ' . Guarantor::ensure_global('Linker')->build('account_history_info.php', ['order_id' => $order->get_id()]) . "\n", '', $email_order);
      $email_order .= HOOK_PWA_EMAIL_WARNING . "\n\n" .
                      MODULE_NOTIFICATIONS_CHECKOUT_SEPARATOR . "\n";
      if ($order->content_type !== 'physical') {
        $email_order .= sprintf(HOOK_PWA_EMAIL_DOWNLOAD, Guarantor::ensure_global('Linker')->build('contact_us.php')) . "\n" .
                        MODULE_NOTIFICATIONS_CHECKOUT_SEPARATOR . "\n";
      }

      $reviews_key = Password::create_random(12);
      $GLOBALS['db']->query(sprintf(<<<'EOSQL'
UPDATE orders
  SET reviews_key = '%s'
  WHERE customers_id = %d
    AND orders_id = %d
EOSQL
      , $GLOBALS['db']->escape($reviews_key), (int)$_SESSION['customer_id'], (int)$order->get_id()));

      $link->set_parameter('pwa_id', $reviews_key);
    }

    if (MODULE_CONTENT_PWA_LOGIN_CHECKOUT_REGISTERED_REVIEW_LINKS === 'True') {
      foreach ($order->products as $p) {
        $products_review_links .= '<a href="' . $link->set_parameter('products_id', Product::build_prid($p['id'])) . '">' . $p['name'] . '</a>' . "\n";
      }
      $email_order .= $products_review_links . "\n" .
                      MODULE_NOTIFICATIONS_CHECKOUT_SEPARATOR . "\n";
    }

  }

If you need more modifications, you can make a renamed copy of the core module. You just need to leave in place line 17-18 to get it used on checkout:

Code: Select all

    const TRIGGERS = [ 'checkout' ];
    const REQUIRES = [ 'address', 'greeting', 'name', 'email_address' ];
Thank you very much Rainer!