Overriding includes/modules/notifications/n_checkout.php

Open to all! Ask other shopowners for help.
Post Reply
Moxamint
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 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
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 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
Certified Developer
Posts: 1640
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 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
Member
Posts: 93
Joined: Fri Nov 06, 2020 10:36 am
Phoenix Version:
Has thanked: 33 times
Been thanked: 3 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!
User avatar
martindavinci
Member
Posts: 38
Joined: Mon Mar 08, 2021 8:33 am
Phoenix Version: 1.1.0.5
Has thanked: 2 times

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

Post by martindavinci »

did it work for you? I am struggling with the same question in PC-1.0.8.19. Also here the confirmation is without the order number.


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply