From f5d44f4b7dd750ae7328a7fe41cefb0036f1d224 Mon Sep 17 00:00:00 2001 From: Wojciech Kamiski Date: Wed, 6 Sep 2017 15:28:04 +0200 Subject: [PATCH 01/12] create feature configuration --- .../community/Riskified/Full/Helper/Data.php | 69 +++++++++++++++++ .../community/Riskified/Full/etc/system.xml | 77 +++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/app/code/community/Riskified/Full/Helper/Data.php b/app/code/community/Riskified/Full/Helper/Data.php index 6d2db63..7e26505 100644 --- a/app/code/community/Riskified/Full/Helper/Data.php +++ b/app/code/community/Riskified/Full/Helper/Data.php @@ -151,4 +151,73 @@ public function getDateTime($time = 'now') return $dateTime->format($dateTime::ATOM); } + + + /** + * Retrieve configuration of decline notification + * + * @return bool + */ + public function isDeclineNotificationEnabled() + { + return Mage::getStoreConfig('fullsection/decline_notification/enable', $this->getStoreId()); + } + + /** + * Retrieve declination email sender configuration + * + * @return string + */ + public function getDeclineNotificationSender() + { + return Mage::getStoreConfig('fullsection/decline_notification/email_identity', $this->getStoreId()); + + } + + /** + * Retrieve declination email subject set in admin panel + * + * @return string + */ + public function getDeclineNotificationSubject() + { + return Mage::getStoreConfig('fullsection/decline_notification/title', $this->getStoreId()); + } + + /** + * Retrieve declination email content set in admin panel + * + * @return string + */ + public function getDeclineNotificationContent() + { + return Mage::getStoreConfig('fullsection/decline_notification/content', $this->getStoreId()); + } + + /** + * Retrieve declination email sender email based on configuration in admin panel + * + * @return string + */ + public function getDeclineNotificationSenderEmail() + { + + return Mage::getStoreConfig( + 'trans_email/ident_' . $this->getDeclineNotificationSender() . '/email', + $this->getStoreId() + ); + } + + /** + * Retrieve declination email sender name based on configuration in admin panel + * + * @return string + */ + public function getDeclineNotificationSenderName() + { + return Mage::getStoreConfig( + 'trans_email/ident_' . $this->getDeclineNotificationSender() . '/name', + $this->getStoreId() + ); + } } diff --git a/app/code/community/Riskified/Full/etc/system.xml b/app/code/community/Riskified/Full/etc/system.xml index f6e062f..b1d08d2 100644 --- a/app/code/community/Riskified/Full/etc/system.xml +++ b/app/code/community/Riskified/Full/etc/system.xml @@ -194,6 +194,83 @@ + + + 20 + 1 + 1 + 1 + + + + select + adminhtml/system_config_source_yesno + 10 + 1 + 1 + 1 + + + + + + + select + adminhtml/system_config_source_email_identity + 20 + 1 + 1 + 1 + + 1 + + + + <label>Email title</label> + <frontend_type>text</frontend_type> + <sort_order>30</sort_order> + <show_in_default>1</show_in_default> + <show_in_website>1</show_in_website> + <show_in_store>1</show_in_store> + <depends> + <enable>1</enable> + </depends> + <comment> + <![CDATA[ + Available shortcodes: <br /> + {{products}} - Product names comma separated <br /> + {{customer_name}} - Customer full name <br /> + {{customer_firstname}} - Customer first name <br /> + {{order_increment_id}} - Order Number <br /> + {{order_view_url}} - Order url to order detail page in customer dashboard <br /> + {{store_name}} - Store name <br /> + ]]> + </comment> + + + + textarea + 40 + 1 + 1 + 1 + + 1 + + + + {{products}} - Product names comma separated
+ {{customer_name}} - Customer full name
+ {{customer_firstname}} - Customer first name
+ {{order_increment_id}} - Order Number
+ {{order_view_url}} - Order url to order detail page in customer dashboard
+ {{store_name}} - Store name
+ ]]> +
+
+
+
From 623b9204c2771da12b353884de45c2b28dfc8481 Mon Sep 17 00:00:00 2001 From: Wojciech Kamiski Date: Wed, 6 Sep 2017 15:28:26 +0200 Subject: [PATCH 02/12] Added default config data --- .../community/Riskified/Full/etc/config.xml | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/app/code/community/Riskified/Full/etc/config.xml b/app/code/community/Riskified/Full/etc/config.xml index 4d742ac..c6bf7da 100644 --- a/app/code/community/Riskified/Full/etc/config.xml +++ b/app/code/community/Riskified/Full/etc/config.xml @@ -203,7 +203,25 @@ + + + + singleton + full/observer_order_decline + handleOrderDecline + + + + @@ -325,6 +343,11 @@ online 0 + + general + {{store_name}}: Order # {{order_increment_id}} has been declined by Riskified + We regret to inform you that your recent order #{{order_increment_id}} for {{products}} 
has been declined by Riskified service.

]]>
+
From c363d2dafb347d6f5a32320d07f9c3064b2c9e9e Mon Sep 17 00:00:00 2001 From: Wojciech Kamiski Date: Wed, 6 Sep 2017 15:28:52 +0200 Subject: [PATCH 03/12] Added base email template, content and subject is configurable in admin panel --- .../template/email/full/order/declined.html | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/locale/en_US/template/email/full/order/declined.html diff --git a/app/locale/en_US/template/email/full/order/declined.html b/app/locale/en_US/template/email/full/order/declined.html new file mode 100644 index 0000000..5b4dc86 --- /dev/null +++ b/app/locale/en_US/template/email/full/order/declined.html @@ -0,0 +1,33 @@ + + + + +{{template config_path="design/email/header"}} +{{inlinecss file="email-inline.css"}} + + + + + + +
+ {{var content}} +
+ +{{template config_path="design/email/footer"}} \ No newline at end of file From c36fd684dbdb21f071fabe2ef12f14e69af90cf7 Mon Sep 17 00:00:00 2001 From: Wojciech Kamiski Date: Wed, 6 Sep 2017 15:29:18 +0200 Subject: [PATCH 04/12] Updated modman file to handle newly created email template --- modman | 1 + 1 file changed, 1 insertion(+) diff --git a/modman b/modman index cb2009f..ac747d9 100644 --- a/modman +++ b/modman @@ -4,6 +4,7 @@ app/design/adminhtml/default/default/template/full/ app/design/adminhtml/def app/design/frontend/base/default/layout/full.xml app/design/frontend/base/default/layout/full.xml app/design/frontend/base/default/template/full/ app/design/frontend/base/default/template/full/ app/etc/modules/Riskified_Full.xml app/etc/modules/Riskified_Full.xml +app/locale/en_US/template/email/full/order/declined.html app/locale/en_US/template/email/full/order/declined.html lib/riskified_php_sdk/ lib/riskified_php_sdk/ lib/riskified_scripts/ lib/riskified_scripts/ skin/adminhtml/default/default/images/riskified/ skin/adminhtml/default/default/images/riskified/ From b4daaa4689b2fae491b28dde210d6159f5d334b6 Mon Sep 17 00:00:00 2001 From: Wojciech Kamiski Date: Wed, 6 Sep 2017 15:29:49 +0200 Subject: [PATCH 05/12] Created observer to send declination email --- .../Full/Model/Observer/Order/Decline.php | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 app/code/community/Riskified/Full/Model/Observer/Order/Decline.php diff --git a/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php new file mode 100644 index 0000000..a24b59b --- /dev/null +++ b/app/code/community/Riskified/Full/Model/Observer/Order/Decline.php @@ -0,0 +1,97 @@ +getOrder(); + $this->order = $order; + /** + * @var Riskified_Full_Helper_Data $dataHelper + */ + $dataHelper = Mage::helper("full"); + + if (!$dataHelper->isDeclineNotificationEnabled()) { + return $this; + } + if (Mage::registry("decline-email-sent")) { + return $this; + } + + Mage::register("decline-email-sent", true); + + $emailTemplate = Mage::getModel('core/email_template') + ->loadDefault('riskified_order_declined'); + + $emailTemplate->setSenderEmail( + $dataHelper->getDeclineNotificationSenderEmail() + ); + + $emailTemplate->setSenderName( + $dataHelper->getDeclineNotificationSenderName() + ); + + $subject = $dataHelper->getDeclineNotificationSubject(); + $content = $dataHelper->getDeclineNotificationContent(); + + $shortCodes = array( + "{{customer_name}}", + "{{customer_firstname}}", + "{{order_increment_id}}", + "{{order_view_url}}", + "{{products}}", + "{{store_name}}", + ); + $formattedPayload = $this->getFormattedData(); + + foreach ($shortCodes as $key => $value) { + $subject = str_replace($value, $formattedPayload[$key], $subject); + $content = str_replace($value, $formattedPayload[$key], $content); + } + + try { + if ($content == "") { + throw new Exception("Email content is empty"); + } + + if ($subject == "") { + throw new Exception("Email subject is empty"); + } + + $emailTemplate->send( + $order->getCustomerEmail(), + $order->getCustomerName(), + array( + 'store' => Mage::app()->getStore(), + 'subject' => $subject, + 'order' => $order, + 'content' => $content + ) + ); + } catch (Exception $e) { + Mage::logException($e); + } + } + + private function getFormattedData() + { + $products = array(); + + foreach ($this->order->getAllItems() as $item) { + $products[] = $item->getName(); + } + + $data = array( + $this->order->getCustomerName(), + $this->order->getCustomerFirstname(), + $this->order->getIncrementId(), + Mage::getUrl('sales/order/view', array('order_id' => $this->order->getId())), + join(', ', $products), + Mage::app()->getStore()->getFrontendName() + ); + + return $data; + } +} From 63b8229188aaae2ffea3f48d9f24277823eb2674 Mon Sep 17 00:00:00 2001 From: Wojciech Kamiski Date: Thu, 7 Sep 2017 15:32:56 +0200 Subject: [PATCH 06/12] Fixed typo in event declaration --- app/code/community/Riskified/Full/etc/config.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/community/Riskified/Full/etc/config.xml b/app/code/community/Riskified/Full/etc/config.xml index c6bf7da..599e56d 100644 --- a/app/code/community/Riskified/Full/etc/config.xml +++ b/app/code/community/Riskified/Full/etc/config.xml @@ -203,15 +203,15 @@ - + - + singleton full/observer_order_decline handleOrderDecline - + - +