Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an option to disable the emailing of receipts #825

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docs/en/02_Customisation/Emails.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Shop emails can be customised to suit your project needs.
There are a few yaml config options that will affect which emails are sent:

```yaml
SilverShop\Model\Order:
send_receipt: false # to disable the emailing of paid invoices (default is true)

SilverShop\Checkout\OrderProcessor:
#send order confirmation when order is placed, but unpaid
send_confirmation: true
Expand All @@ -13,6 +16,7 @@ SilverShop\Checkout\OrderProcessor:
SilverShop\Checkout\OrderEmailNotifier:
bcc_confirmation_to_admin: true
bcc_receipt_to_admin: true
bcc_status_change_to_admin: true

#Specify the 'from' address to use in email correspondence
SilverShop\Extension\ShopConfigExtension:
Expand All @@ -35,7 +39,7 @@ en:
ShopEmail:
ConfirmationSubject: 'My Website Order #{OrderNo} confirmation'
ReceiptSubject: 'My Website Order #{OrderNo} receipt'
CancelSubject: 'My Website Order #{OrderNo} cancelled by member'
CancelSubject: 'My Website Order #{OrderNo} cancelled by member'
```

## Making your own Notifier
Expand All @@ -48,4 +52,3 @@ Injector:
OrderEmailNotifier:
class: MyCustomOrderEmailNotifier
```

1 change: 1 addition & 0 deletions example_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ SilverShop\Model\Order:
modifiers:
- 'SilverShop\Model\Modifiers\Shipping\Simple'
- 'SilverShop\Model\Modifiers\Tax\FlatTax'
# send_receipt: false # send paid invoice to customer (default is true)
cancel_before_payment: false
cancel_before_processing: false
cancel_before_sending: false
Expand Down
10 changes: 10 additions & 0 deletions src/Checkout/OrderProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class OrderProcessor
use Injectable;
use Configurable;

/**
* @config
*/
private static bool $send_admin_notification = false;

/**
* @config
*/
private static bool $send_confirmation = false;

/**
* @var Order
*/
Expand Down
8 changes: 7 additions & 1 deletion src/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ class Order extends DataObject
*/
private static $cancel_before_payment = true;

/**
* Email customer an invoice upon payment
* @config
*/
private static bool $send_receipt = true;

/**
* Whether or not an order can be cancelled before processing
*
Expand Down Expand Up @@ -845,7 +851,7 @@ protected function statusTransition($fromStatus, $toStatus)
//all payment is settled
$this->extend('onPaid');

if (!$this->ReceiptSent) {
if (!$this->ReceiptSent && static::config()->get('send_receipt')) {
OrderEmailNotifier::create($this)->sendReceipt();
$this->setField('ReceiptSent', DBDatetime::now()->Rfc2822());
}
Expand Down
13 changes: 13 additions & 0 deletions tests/php/Checkout/OrderEmailNotifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public function testReceipt()
$this->assertEmailSent('[email protected]', '[email protected]');
}

public function testReceiptNoEmailSent()
{
$this->clearEmails();
Config::modify()->set(Order::class, 'send_receipt', false);
$order = $this->objFromFixture(Order::class, 'unpaid');
$order->setField('Status', 'Paid');
$order->write();
$this->assertNull(
$this->findEmail('[email protected]', '[email protected]'),
'An email is not sent when the Order class send_receipt is set to false'
);
}

public function testStatusUpdate()
{
$this->notifier->sendStatusChange('test subject');
Expand Down
Loading