Overriding includes/modules/notifications/n_checkout.php

Ask the community for help and support.
Post Reply
Moxamint
VIP Member
VIP Member
Posts: 85
Joined: Fri Nov 06, 2020 10:36 am
Has thanked: 22 times
Been thanked: 2 times

Overriding includes/modules/notifications/n_checkout.php

Post 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
User avatar
Kofod95
VIP Member
VIP Member
Posts: 605
Joined: Sat Feb 06, 2021 7:38 pm
Has thanked: 80 times
Been thanked: 141 times

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

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
Moxamint
VIP Member
VIP Member
Posts: 85
Joined: Fri Nov 06, 2020 10:36 am
Has thanked: 22 times
Been thanked: 2 times

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

Post 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!
raiwa
PhoenixCart Developer
PhoenixCart Developer
Posts: 1184
Joined: Sat Dec 21, 2019 8:08 am
Has thanked: 38 times
Been thanked: 102 times

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

Post 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' ];
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
Moxamint
VIP Member
VIP Member
Posts: 85
Joined: Fri Nov 06, 2020 10:36 am
Has thanked: 22 times
Been thanked: 2 times

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

Post 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!
Post Reply