├── view ├── base │ ├── web │ │ ├── images │ │ │ └── sms-notifications-logo.png │ │ └── js │ │ │ └── grid │ │ │ └── massactions-mixin.js │ ├── requirejs-config.js │ └── ui_component │ │ └── customer_form.xml ├── adminhtml │ ├── web │ │ └── css │ │ │ └── source │ │ │ ├── _module.less │ │ │ └── system │ │ │ └── config │ │ │ └── form │ │ │ └── fieldset │ │ │ └── _info.less │ └── templates │ │ └── system │ │ └── config │ │ └── form │ │ └── fieldset │ │ └── info.phtml └── frontend │ ├── web │ ├── css │ │ └── source │ │ │ ├── _module.less │ │ │ ├── _sms-subscription-preferences.less │ │ │ └── customer │ │ │ ├── smsnotifications │ │ │ └── _manage.less │ │ │ └── account │ │ │ └── create │ │ │ └── _mobile-telephone-field.less │ ├── template │ │ ├── sms-terms-conditions.html │ │ ├── sms-notification-subscription.html │ │ ├── sms-subscription-preferences.html │ │ └── mobile-telephone-field.html │ └── js │ │ ├── model │ │ ├── sms-notifications.js │ │ ├── sms-subscription-preferences-modal.js │ │ └── sms-terms-conditions-modal.js │ │ ├── clear-storage.js │ │ ├── view │ │ ├── sms-terms-conditions.js │ │ └── mobile-telephone-field.js │ │ └── checkbox-toggler.js │ ├── requirejs-config.js │ ├── templates │ ├── clear-storage.phtml │ ├── customer │ │ └── account │ │ │ ├── link.phtml │ │ │ └── create │ │ │ ├── subscribe-field.phtml │ │ │ └── mobile-telephone-field.phtml │ ├── sms-terms-conditions.phtml │ └── sms-subscription-preferences.phtml │ └── layout │ ├── sms_terms_conditions.xml │ ├── sms_subscription_preferences.xml │ ├── customer_account_create.xml │ ├── customer_smsnotifications_manage.xml │ └── customer_account.xml ├── Test ├── Integration │ ├── _files │ │ ├── invoice_guest.php │ │ ├── shipment_guest.php │ │ ├── creditmemo_guest.php │ │ ├── order_guest.php │ │ ├── order_new.php │ │ ├── order_holded.php │ │ ├── order_canceled.php │ │ ├── order_released.php │ │ ├── create_sms_subscription.php │ │ ├── invoice.php │ │ ├── create_sms_subscriptions_from_source.php │ │ ├── shipment.php │ │ ├── product_simple.php │ │ └── creditmemo.php │ ├── RegistrationTest.php │ ├── _stubs │ │ └── Model │ │ │ └── SmsSender.php │ ├── Model │ │ └── SmsSender │ │ │ └── WelcomeSenderTest.php │ ├── Setup │ │ └── CustomerAttributesTest.php │ └── Plugin │ │ └── Sales │ │ └── Model │ │ └── OrderPluginTest.php ├── Mftf │ ├── Page │ │ ├── AdminConfigPage.xml │ │ ├── AdminEditCustomerPage.xml │ │ └── StorefrontSmsTermsConditionsModalPage.xml │ ├── Data │ │ ├── SmsSubscriptionData.xml │ │ └── SystemConfigData.xml │ ├── Section │ │ ├── AdminConfigSmsNotificationsSection.xml │ │ ├── AdminCustomerSmsSubscriptionsSection.xml │ │ ├── StorefrontSmsSubscriptionPreferencesModalSection.xml │ │ ├── StorefrontCreateCustomerFormSection.xml │ │ ├── StorefrontSmsSubscriptionPreferencesSection.xml │ │ └── StorefrontSmsTermsConditionsModalSection.xml │ ├── Metadata │ │ ├── sms_subscription-meta.xml │ │ └── system_config-meta.xml │ ├── ActionGroup │ │ ├── ConfigSmsNotificationsEnabledActionGroup.xml │ │ └── ConfigSmsNotificationsRequireOptinActionGroup.xml │ └── Test │ │ ├── StorefrontCreateCustomerSmsSubscribeVisibleTest.xml │ │ ├── StorefrontCreateCustomerSmsSubscribeNotVisibleTest.xml │ │ ├── StorefrontCreateCustomerSmsSubscriptionPreferencesModalTest.xml │ │ ├── StorefrontCustomerAccountSmsPreferencesLinkVisibilityTest.xml │ │ ├── StorefrontCreateCustomerSmsTermsConditionsModalTest.xml │ │ ├── StorefrontCreateCustomerMobilePhoneNotVisibleTest.xml │ │ ├── AdminCustomerSmsSubscriptionsFieldsetDisabledTest.xml │ │ ├── StorefrontCreateCustomerMobilePhoneVisibleTest.xml │ │ └── AdminViewCustomerSmsSubscriptionsTest.xml └── Unit │ └── Logger │ └── Processor │ └── SensitiveDataProcessorTest.php ├── registration.php ├── etc ├── db_schema_whitelist.json ├── frontend │ ├── routes.xml │ ├── events.xml │ └── di.xml ├── module.xml ├── adminhtml │ ├── routes.xml │ └── di.xml ├── extension_attributes.xml ├── acl.xml └── db_schema.xml ├── Logger ├── Logger.php └── Handler │ └── FileHandler.php ├── Api ├── ValidationRulesInterface.php ├── MessageVariablesInterface.php ├── MobileTelephoneNumberManagementInterface.php ├── ValidatorInterface.php ├── Data │ └── TelephonePrefixInterface.php ├── SmsSubscriptionManagementInterface.php └── SmsSubscriptionRepositoryInterface.php ├── Block ├── SmsTermsConditions.php ├── SmsSubscriptionPreferences.php ├── Customer │ └── Account │ │ └── Create │ │ ├── MobileTelephoneField.php │ │ └── SubscribeField.php ├── System │ └── Config │ │ └── Form │ │ └── Fieldset │ │ └── Info.php └── AbstractBlock.php ├── Gateway ├── Hydrator │ ├── MessageEntity.php │ └── Strategy │ │ └── Enum.php ├── Factory │ ├── ClientFactory.php │ ├── MessageFactory.php │ ├── ResultFactory.php │ └── MessageEntityHydratorFactory.php ├── Entity │ ├── ResultInterface.php │ ├── ErrorResultInterface.php │ ├── DCS.php │ ├── TON.php │ └── SuccessResultInterface.php ├── ApiException.php └── ApiClientInterface.php ├── Util └── TemplateProcessorInterface.php ├── Traits └── DataObjectMagicMethods.php ├── composer.json ├── Model ├── ResourceModel │ ├── TelephonePrefix │ │ └── Collection.php │ ├── TelephonePrefix.php │ └── SmsSubscription │ │ └── Collection.php ├── Config │ ├── Source │ │ └── SourceType.php │ └── Backend │ │ └── Source.php ├── Data │ └── TelephonePrefix.php ├── SmsSender │ └── WelcomeSender.php ├── SmsSubscriptionValidator.php └── SourceValidator.php ├── Plugin └── Sales │ ├── Model │ ├── Order │ │ └── InvoicePlugin.php │ ├── OrderPlugin.php │ └── ResourceModel │ │ └── Order │ │ └── ShipmentPlugin.php │ └── Api │ ├── OrderRepositoryInterfacePlugin.php │ └── CreditmemoRepositoryInterfacePlugin.php ├── ViewModel ├── TermsConditions.php ├── MobileTelephone.php └── SmsTypes.php ├── Ui └── Component │ ├── Listing │ └── Column │ │ └── SmsSubscriptionStatus.php │ └── Form │ └── Fieldset │ └── SmsSubscriptionListingFieldset.php ├── Setup └── Patch │ └── Data │ └── RemoveConfigData.php ├── Controller └── SmsNotifications │ └── Manage.php └── CONTRIBUTING.md /view/base/web/images/sms-notifications-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wagento/sms-notifications/HEAD/view/base/web/images/sms-notifications-logo.png -------------------------------------------------------------------------------- /view/adminhtml/web/css/source/_module.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @package Wagento\SMSNotifications\Block\System\Config\Form\Fieldset 8 | * @author Joseph Leedy 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | @import "system/config/form/fieldset/_info"; 15 | -------------------------------------------------------------------------------- /Test/Integration/_files/invoice_guest.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | require __DIR__ . '/invoice.php'; 15 | 16 | $invoice->getOrder()->setCustomerId(null)->setCustomerIsGuest(true)->save(); 17 | -------------------------------------------------------------------------------- /Test/Integration/_files/shipment_guest.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | require __DIR__ . '/shipment.php'; 15 | 16 | $shipment->getOrder()->setCustomerId(null)->setCustomerIsGuest(true)->save(); 17 | -------------------------------------------------------------------------------- /Test/Integration/_files/creditmemo_guest.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | require __DIR__ . '/creditmemo.php'; 15 | 16 | $creditmemo->getOrder()->setCustomerId(null)->setCustomerIsGuest(true)->save(); 17 | -------------------------------------------------------------------------------- /view/frontend/web/css/source/_module.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | @import "_sms-subscription-preferences"; 14 | @import "customer/account/create/_mobile-telephone-field"; 15 | @import "customer/smsnotifications/_manage"; 16 | -------------------------------------------------------------------------------- /Test/Integration/_files/order_guest.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | $order = require __DIR__ . '/order.php'; 15 | 16 | $order->setCustomerId(null); 17 | $order->setCustomerIsGuest(true); 18 | $order->save(); 19 | 20 | return $order; 21 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | \Magento\Framework\Component\ComponentRegistrar::register( 15 | \Magento\Framework\Component\ComponentRegistrar::MODULE, 16 | 'Wagento_SMSNotifications', 17 | __DIR__ 18 | ); 19 | -------------------------------------------------------------------------------- /view/base/requirejs-config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | var config = { 13 | config: { 14 | mixins: { 15 | 'Magento_Ui/js/grid/massactions': { 16 | 'Wagento_SMSNotifications/js/grid/massactions-mixin': true 17 | } 18 | } 19 | } 20 | }; -------------------------------------------------------------------------------- /view/frontend/web/template/sms-terms-conditions.html: -------------------------------------------------------------------------------- 1 | 14 |
15 |

16 |
-------------------------------------------------------------------------------- /etc/db_schema_whitelist.json: -------------------------------------------------------------------------------- 1 | { 2 | "sms_subscription": { 3 | "column": { 4 | "sms_subscription_id": true, 5 | "customer_id": true, 6 | "sms_type": true 7 | }, 8 | "constraint": { 9 | "PRIMARY": true, 10 | "SMS_SUBSCRIPTION_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID": true 11 | } 12 | }, 13 | "directory_telephone_prefix": { 14 | "column": { 15 | "country_code": true, 16 | "country_name": true, 17 | "prefix": true 18 | }, 19 | "constraint": { 20 | "PRIMARY": true, 21 | "DIRECTORY_TELEPHONE_PREFIX_COUNTRY_CODE": true 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /view/frontend/requirejs-config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | var config = { 14 | map: { 15 | '*': { 16 | wagentoCheckboxToggler: 'Wagento_SMSNotifications/js/checkbox-toggler', 17 | smsNotifications: 'Wagento_SMSNotifications/js/model/sms-notifications' 18 | } 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /view/frontend/templates/clear-storage.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | /** @var \Magento\Framework\View\Element\Template $block */ 15 | ?> 16 | 23 | -------------------------------------------------------------------------------- /view/adminhtml/web/css/source/system/config/form/fieldset/_info.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @package Wagento\SMSNotifications\Block\System\Config\Form\Fieldset 8 | * @author Joseph Leedy 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | #sms-notifications-info main { 15 | p, ul { 16 | margin: @indent__base 0; 17 | } 18 | 19 | ul { 20 | padding-left: @indent__xl; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Test/Integration/_files/order_new.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Sales\Model\Order; 15 | 16 | $order = require __DIR__ . '/order.php'; 17 | 18 | $order->setState(Order::STATE_NEW); 19 | $order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_NEW)); 20 | $order->save(); 21 | 22 | return $order; 23 | -------------------------------------------------------------------------------- /Test/Integration/_files/order_holded.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Sales\Model\Order; 15 | 16 | $order = require __DIR__ . '/order.php'; 17 | 18 | $order->setState(Order::STATE_HOLDED); 19 | $order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_HOLDED)); 20 | $order->save(); 21 | 22 | return $order; 23 | -------------------------------------------------------------------------------- /Test/Integration/_files/order_canceled.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Sales\Model\Order; 15 | 16 | $order = require __DIR__ . '/order.php'; 17 | 18 | $order->setState(Order::STATE_CANCELED); 19 | $order->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CANCELED)); 20 | $order->save(); 21 | 22 | return $order; 23 | -------------------------------------------------------------------------------- /view/frontend/web/css/source/_sms-subscription-preferences.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | #sms-subscription-preferences-modal { 14 | display: none; 15 | 16 | p { 17 | font-size: 16px; 18 | } 19 | 20 | .field.sms-type.select-all { 21 | margin: 2rem 0; 22 | } 23 | 24 | .sms-type-list { 25 | list-style: none; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Logger/Logger.php: -------------------------------------------------------------------------------- 1 | 11 | * @author Yair García Torres 12 | * @copyright Copyright (c) Wagento (https://wagento.com/) 13 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 14 | */ 15 | 16 | declare(strict_types=1); 17 | 18 | namespace Wagento\SMSNotifications\Logger; 19 | 20 | /** 21 | * Logger 22 | * 23 | * @package Wagento\SMSNotifications\Logger 24 | * @author Joseph Leedy 25 | */ 26 | class Logger extends \Monolog\Logger 27 | { 28 | } 29 | -------------------------------------------------------------------------------- /Api/ValidationRulesInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api; 18 | 19 | /** 20 | * Validation Rules Interface 21 | * 22 | * @package Wagento\SMSNotifications\Api 23 | * @author Joseph Leedy 24 | * @api 25 | */ 26 | interface ValidationRulesInterface 27 | { 28 | } 29 | -------------------------------------------------------------------------------- /Block/SmsTermsConditions.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Block; 18 | 19 | /** 20 | * SMS Terms & Conditions Block 21 | * 22 | * @package Wagento\SMSNotifications\Block 23 | * @author Joseph Leedy 24 | */ 25 | class SmsTermsConditions extends AbstractBlock 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /etc/frontend/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /view/frontend/web/css/source/customer/smsnotifications/_manage.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | #manage-sms-notification-subscriptions-content { 14 | p { 15 | font-size: 1.6rem; 16 | margin-bottom: 2rem; 17 | } 18 | 19 | form[data-hasrequired] { 20 | .lib-form-hasrequired(bottom); 21 | } 22 | 23 | .fieldset.notification-preferences .fieldset legend { 24 | padding-bottom: 0; 25 | border: none; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Block/SmsSubscriptionPreferences.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Block; 18 | 19 | /** 20 | * SMS Subscription Preferences Block 21 | * 22 | * @package Wagento\SMSNotifications\Block 23 | * @author Joseph Leedy 24 | */ 25 | class SmsSubscriptionPreferences extends AbstractBlock 26 | { 27 | } 28 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /etc/frontend/events.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Api/MessageVariablesInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api; 18 | 19 | /** 20 | * Message Variables 21 | * 22 | * @package Wagento\SMSNotifications\Api 23 | * @author Joseph Leedy 24 | * @api 25 | */ 26 | interface MessageVariablesInterface 27 | { 28 | public function getVariables(): array; 29 | } 30 | -------------------------------------------------------------------------------- /etc/adminhtml/routes.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Test/Mftf/Page/AdminConfigPage.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 |
18 | 19 | -------------------------------------------------------------------------------- /Gateway/Hydrator/MessageEntity.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Hydrator; 18 | 19 | use Zend\Hydrator\Reflection; 20 | 21 | /** 22 | * Message Entity Hydrator 23 | * 24 | * @package Wagento\SMSNotifications\Gateway\Hydrator 25 | * @author Joseph Leedy 26 | */ 27 | class MessageEntity extends Reflection 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /view/frontend/web/css/source/customer/account/create/_mobile-telephone-field.less: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | #mobile-telephone-number-field { 14 | margin-bottom: 0; 15 | 16 | .fields { 17 | .lib-clearfix(); 18 | .field { 19 | box-sizing: border-box; 20 | float: left; 21 | 22 | &:first-child { 23 | width: 33%; 24 | margin-right: 1%; 25 | } 26 | 27 | &:last-child { 28 | width: 66%; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Test/Mftf/Page/AdminEditCustomerPage.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 |
18 | 19 | -------------------------------------------------------------------------------- /view/frontend/web/js/model/sms-notifications.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define(['ko'], function (ko) { 14 | let isSubscribed = ko.observable(false), 15 | isSubscribing = ko.observable(false), 16 | selectedSmsTypes = ko.observableArray(); 17 | 18 | isSubscribed.extend({ notify: 'always' }); 19 | 20 | return { 21 | isSubscribed: isSubscribed, 22 | isSubscribing: isSubscribing, 23 | selectedSmsTypes: selectedSmsTypes 24 | }; 25 | }); 26 | -------------------------------------------------------------------------------- /Test/Mftf/Page/StorefrontSmsTermsConditionsModalPage.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 |
18 | 19 | -------------------------------------------------------------------------------- /Test/Mftf/Data/SmsSubscriptionData.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | order_placed 19 | Simple_US_Customer 20 | 21 | -------------------------------------------------------------------------------- /Test/Integration/_files/order_released.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Sales\Api\Data\OrderExtensionInterface; 15 | 16 | $order = require __DIR__ . '/order.php'; 17 | 18 | /** @var \Magento\Sales\Api\Data\OrderExtensionInterface $orderExtensionAttributes */ 19 | $orderExtensionAttributes = $order->getExtensionAttributes() ?? $objectManager->create(OrderExtensionInterface::class); 20 | 21 | $orderExtensionAttributes->setIsOrderHoldReleased(true); 22 | 23 | $order->setExtensionAttributes($orderExtensionAttributes); 24 | $order->save(); 25 | 26 | return $order; 27 | -------------------------------------------------------------------------------- /Block/Customer/Account/Create/MobileTelephoneField.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Block\Customer\Account\Create; 18 | 19 | use Wagento\SMSNotifications\Block\AbstractBlock; 20 | 21 | /** 22 | * SMS Notifications Mobile Telephone Block 23 | * 24 | * @package Wagento\SMSNotifications\Block\Customer\Account\Create 25 | * @author Joseph Leedy 26 | */ 27 | class MobileTelephoneField extends AbstractBlock 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /Gateway/Factory/ClientFactory.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Factory; 18 | 19 | use GuzzleHttp\Client; 20 | use GuzzleHttp\ClientInterface; 21 | 22 | /** 23 | * Client Factory 24 | * 25 | * @package Wagento\SMSNotifications\Gateway\Factory 26 | * @author Joseph Leedy 27 | */ 28 | class ClientFactory 29 | { 30 | public function create(array $config): ClientInterface 31 | { 32 | return new Client($config); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Gateway/Entity/ResultInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Entity; 18 | 19 | /** 20 | * Result Entity Interface 21 | * 22 | * @package Wagento\SMSNotifications\Gateway\Entity 23 | * @author Joseph Leedy 24 | */ 25 | interface ResultInterface 26 | { 27 | public function getType(): string; 28 | 29 | public function getCode(): int; 30 | 31 | public function getMessage(): string; 32 | 33 | public function toArray(): array; 34 | } 35 | -------------------------------------------------------------------------------- /view/adminhtml/templates/system/config/form/fieldset/info.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | /** @var \Magento\Backend\Block\Template $block */ 15 | ?> 16 |
17 |
18 | 19 |
20 |
21 | escapeHtml($block->getData('info_text'), ['p', 'ul', 'li', 'a', 'strong', 'em']) ?> 22 |
23 |
24 | -------------------------------------------------------------------------------- /Api/MobileTelephoneNumberManagementInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api; 18 | 19 | use Magento\Customer\Api\Data\CustomerInterface; 20 | 21 | /** 22 | * Mobile Telephone Number Management Service Interface 23 | * 24 | * @package Wagento\SMSNotifications\Api 25 | * @author Joseph Leedy 26 | * @api 27 | */ 28 | interface MobileTelephoneNumberManagementInterface 29 | { 30 | public function updateNumber(string $newPrefix, string $newNumber, CustomerInterface $customer): ?bool; 31 | } 32 | -------------------------------------------------------------------------------- /Test/Integration/_files/create_sms_subscription.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | use Wagento\SMSNotifications\Model\SmsSubscription; 16 | use Magento\TestFramework\Helper\Bootstrap; 17 | 18 | $objectManager = Bootstrap::getObjectManager(); 19 | 20 | /** @var \Wagento\SMSNotifications\Model\SmsSubscription $smsSubscription */ 21 | $smsSubscription = $objectManager->create(SmsSubscription::class); 22 | 23 | $smsSubscription->setData([ 24 | 'customer_id' => 1, 25 | 'sms_type' => 'order_placed', 26 | ]); 27 | $smsSubscription->isObjectNew(true); 28 | $smsSubscription->save(); 29 | 30 | return $smsSubscription; 31 | -------------------------------------------------------------------------------- /Test/Mftf/Section/AdminConfigSmsNotificationsSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 |
17 | 18 | 19 | 20 |
21 |
-------------------------------------------------------------------------------- /Test/Mftf/Section/AdminCustomerSmsSubscriptionsSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 |
17 | 18 | 19 | 20 |
21 |
-------------------------------------------------------------------------------- /view/frontend/web/js/clear-storage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define(['Magento_Ui/js/lib/core/storage/local'], function (storage) { 14 | "use strict"; 15 | 16 | return function () { 17 | if (storage.get('sms-notification-subscription.isSubscribeChecked') !== undefined) { 18 | storage.remove('sms-notification-subscription.isSubscribeChecked'); 19 | } 20 | 21 | if (storage.get('sms-notification-subscription.selectedSmsTypes') !== undefined) { 22 | storage.remove('sms-notification-subscription.selectedSmsTypes'); 23 | } 24 | 25 | if (storage.get('sms-mobile-telephone') !== undefined) { 26 | storage.remove('sms-mobile-telephone'); 27 | } 28 | }; 29 | }); 30 | -------------------------------------------------------------------------------- /Test/Mftf/Section/StorefrontSmsSubscriptionPreferencesModalSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 |
17 | 18 | 19 | 20 |
21 |
-------------------------------------------------------------------------------- /Util/TemplateProcessorInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Util; 18 | 19 | /** 20 | * Template Processor Interface 21 | * 22 | * @package Wagento\SMSNotifications\Util 23 | * @author Joseph Leedy 24 | */ 25 | interface TemplateProcessorInterface 26 | { 27 | /** 28 | * Replaces variables in a template with their real values 29 | * 30 | * @param string $template 31 | * @param string[] $data Key-value pairs to replace in template (key is variable, value is replacement) 32 | * @return string 33 | */ 34 | public function process(string $template, array $data, string $listSeparator = ', '): string; 35 | } 36 | -------------------------------------------------------------------------------- /Gateway/Entity/ErrorResultInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Entity; 18 | 19 | /** 20 | * Error Result Entity Interface 21 | * 22 | * @package Wagento\SMSNotifications\Gateway\Entity 23 | */ 24 | interface ErrorResultInterface extends ResultInterface 25 | { 26 | public function setStatus(int $status): void; 27 | 28 | public function getStatus(): int; 29 | 30 | public function setDescription(string $description): void; 31 | 32 | public function getDescription(): string; 33 | 34 | public function setTranslatedDescription(?string $translatedDescription): void; 35 | 36 | public function getTranslatedDescription(): ?string; 37 | } 38 | -------------------------------------------------------------------------------- /Test/Mftf/Section/StorefrontCreateCustomerFormSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 |
17 | 18 | 19 | 20 | 21 |
22 |
-------------------------------------------------------------------------------- /Gateway/Entity/DCS.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Entity; 18 | 19 | use MyCLabs\Enum\Enum; 20 | 21 | /** 22 | * DCS Entity 23 | * 24 | * @package Wagento\SMSNotifications\Gateway\Entity 25 | * @author Joseph Leedy 26 | */ 27 | class DCS extends Enum 28 | { 29 | /** 30 | * GSM-7 default alphabet encoding 31 | */ 32 | public const GSM = 'GSM'; 33 | /** 34 | * 8-bit binary data 35 | */ 36 | public const BINARY = 'BINARY'; 37 | /** 38 | * UCS-2 encoding 39 | */ 40 | public const UCS2 = 'UCS2'; 41 | /** 42 | * Server side handling of encoding and segmenting 43 | */ 44 | public const TEXT = 'TEXT'; 45 | } 46 | -------------------------------------------------------------------------------- /Gateway/Entity/TON.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Entity; 18 | 19 | use MyCLabs\Enum\Enum; 20 | 21 | /** 22 | * TON (Type of Number) Entity 23 | * 24 | * @package Wagento\SMSNotifications\Gateway\Entity 25 | */ 26 | class TON extends Enum 27 | { 28 | /** 29 | * Short number; 1-14 digits depending on country. 30 | */ 31 | public const SHORTNUMBER = 'SHORTNUMBER'; 32 | /** 33 | * Up to 11 valid GSM characters in the range a-z, A-Z, 0-9. 34 | */ 35 | public const ALPHANUMERIC = 'ALPHANUMERIC'; 36 | /** 37 | * Mobile number in international format beginning with a + (i.e. +1-555-555-1234) 38 | */ 39 | public const MSISDN = 'MSISDN'; 40 | } 41 | -------------------------------------------------------------------------------- /view/frontend/layout/sms_terms_conditions.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | Wagento\SMSNotifications\ViewModel\TermsConditions 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Gateway/ApiException.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway; 18 | 19 | /** 20 | * API Exception 21 | * 22 | * @package Wagento\SMSNotifications\Gateway 23 | */ 24 | class ApiException extends \Exception 25 | { 26 | private $responseData = []; 27 | 28 | /** 29 | * @phpcs:disable Generic.Files.LineLength.TooLong 30 | */ 31 | public function __construct(string $message = '', int $code = 0, \Throwable $previous = null, array $responseData = []) 32 | { 33 | parent::__construct($message, $code, $previous); 34 | 35 | $this->responseData = $responseData; 36 | } 37 | 38 | public function getResponseData(): array 39 | { 40 | return $this->responseData; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /view/frontend/layout/sms_subscription_preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | Wagento\SMSNotifications\ViewModel\SmsTypes 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Api/ValidatorInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api; 18 | 19 | use Magento\Framework\Model\AbstractModel; 20 | 21 | /** 22 | * SMS Subscription Validator Interface 23 | * 24 | * @package Wagento\SMSNotifications\Model 25 | * @author Joseph Leedy 26 | * @api 27 | */ 28 | interface ValidatorInterface 29 | { 30 | /** 31 | * @throws \Exception 32 | * @throws \Zend_Validate_Exception 33 | */ 34 | public function validate(AbstractModel $model): void; 35 | 36 | public function isValid(): bool; 37 | 38 | public function getMessages(): array; 39 | 40 | /** 41 | * @throws \Zend_Validate_Exception 42 | */ 43 | public function getValidator(): \Zend_Validate_Interface; 44 | } 45 | -------------------------------------------------------------------------------- /Block/Customer/Account/Create/SubscribeField.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Block\Customer\Account\Create; 18 | 19 | use Wagento\SMSNotifications\Block\AbstractBlock; 20 | 21 | /** 22 | * Subscribe Form Field Block 23 | * 24 | * @package Wagento\SMSNotifications\Block\Customer\Account\Create 25 | * @author Joseph Leedy 26 | */ 27 | class SubscribeField extends AbstractBlock 28 | { 29 | public function isOptinRequired(): bool 30 | { 31 | return $this->config->isOptinRequired($this->getWebsiteId()); 32 | } 33 | 34 | public function isTermsAndConditionsShownAfterOptin(): bool 35 | { 36 | return $this->config->isTermsAndConditionsShownAfterOptin($this->getWebsiteId()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /view/frontend/templates/customer/account/link.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | /** @var \Magento\Framework\View\Element\Html\Link\Current $block */ 15 | ?> 16 | 31 | -------------------------------------------------------------------------------- /Gateway/Factory/MessageFactory.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Factory; 18 | 19 | use Wagento\SMSNotifications\Gateway\Entity\Message; 20 | use Wagento\SMSNotifications\Gateway\Entity\MessageInterface; 21 | 22 | /** 23 | * Message Entity Factory 24 | * 25 | * @package Wagento\SMSNotifications\Gateway\Factory 26 | * @author Joseph Leedy 27 | */ 28 | class MessageFactory 29 | { 30 | public function create( 31 | string $source = null, 32 | string $destination = null, 33 | string $userData = null, 34 | string $platformId = null, 35 | string $platformPartnerId = null 36 | ): MessageInterface { 37 | return new Message($source, $destination, $userData, $platformId, $platformPartnerId); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Test/Mftf/Section/StorefrontSmsSubscriptionPreferencesSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 |
23 |
-------------------------------------------------------------------------------- /view/base/ui_component/customer_form.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 |
16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 | true 24 | sms_subscriptions_listing 25 | 26 | 27 | 28 |
29 |
-------------------------------------------------------------------------------- /Gateway/Entity/SuccessResultInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Entity; 18 | 19 | /** 20 | * Success Result Entity Interface 21 | * 22 | * @package Wagento\SMSNotifications\Gateway\Entity 23 | * @author Joseph Leedy 24 | */ 25 | interface SuccessResultInterface extends ResultInterface 26 | { 27 | public function setMessageId(string $messageId): void; 28 | 29 | public function getMessageId(): string; 30 | 31 | public function setResultCode(int $resultCode): void; 32 | 33 | public function getResultCode(): int; 34 | 35 | public function setDescription(string $description): void; 36 | 37 | public function getDescription(): string; 38 | 39 | public function setSmsCount(int $smsCount): void; 40 | 41 | public function getSmsCount(): int; 42 | } 43 | -------------------------------------------------------------------------------- /Test/Integration/_files/invoice.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Framework\DB\Transaction; 15 | use Magento\Sales\Api\InvoiceManagementInterface; 16 | 17 | require BP . '/dev/tests/integration/testsuite/Magento/Sales/_files/default_rollback.php'; 18 | require __DIR__ . '/order.php'; 19 | 20 | /** @var \Magento\Framework\ObjectManagerInterface $objectManager */ 21 | 22 | $orderService = $objectManager->create(InvoiceManagementInterface::class); 23 | /** @var \Magento\Sales\Model\Order\Invoice $invoice */ 24 | $invoice = $orderService->prepareInvoice($order); 25 | 26 | $invoice->register(); 27 | 28 | /** @var \Magento\Sales\Model\Order $order */ 29 | $order = $invoice->getOrder(); 30 | 31 | $order->setIsInProcess(true); 32 | 33 | /** @var \Magento\Framework\DB\Transaction $transactionSave */ 34 | $transactionSave = $objectManager->create(Transaction::class); 35 | 36 | $transactionSave->addObject($invoice)->addObject($order)->save(); 37 | -------------------------------------------------------------------------------- /Test/Mftf/Section/StorefrontSmsTermsConditionsModalSection.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 |
23 |
-------------------------------------------------------------------------------- /Traits/DataObjectMagicMethods.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Traits; 18 | 19 | /** 20 | * Data Object Magic Methods 21 | * 22 | * @package Wagento\SMSNotifications\Traits 23 | * @author Joseph Leedy 24 | */ 25 | trait DataObjectMagicMethods 26 | { 27 | /** 28 | * @param mixed $value 29 | */ 30 | public function __set(string $key, $value): void 31 | { 32 | $this->setData($key, $value); 33 | } 34 | 35 | /** 36 | * @return mixed 37 | */ 38 | public function __get(string $key) 39 | { 40 | return $this->getData($key); 41 | } 42 | 43 | public function __isset(string $key): bool 44 | { 45 | return $this->hasData($key); 46 | } 47 | 48 | public function __unset(string $key): void 49 | { 50 | $this->unsetData($key); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Api/Data/TelephonePrefixInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api\Data; 18 | 19 | /** 20 | * Telephone Prefix Entity Interface 21 | * 22 | * @package Wagento\SMSNotifications\Api\Data 23 | * @author Joseph Leedy 24 | * @api 25 | */ 26 | interface TelephonePrefixInterface 27 | { 28 | public const COUNTRY_CODE = 'country_code'; 29 | public const COUNTRY_NAME = 'country_name'; 30 | public const PREFIX = 'prefix'; 31 | 32 | public function setCountryCode(string $countryCode): TelephonePrefixInterface; 33 | 34 | public function getCountryCode(): string; 35 | 36 | public function setCountryName(string $countryName): TelephonePrefixInterface; 37 | 38 | public function getCountryName(): string; 39 | 40 | public function setPrefix(int $prefix): TelephonePrefixInterface; 41 | 42 | public function getPrefix(): int; 43 | } 44 | -------------------------------------------------------------------------------- /view/frontend/templates/sms-terms-conditions.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | /** @var \Magento\Framework\View\Element\Template $block */ 15 | 16 | $modalContent = $block->getData('terms_conditions_view_model')->getContent(); 17 | ?> 18 |
19 | 20 |
21 | 36 | -------------------------------------------------------------------------------- /etc/frontend/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | Wagento\SMSNotifications\Logger\Logger 19 | Magento\Customer\Model\Session\Proxy 20 | Wagento\SMSNotifications\Model\SmsSender\WelcomeSender 21 | 22 | 23 | 24 | 25 | Wagento\SMSNotifications\Model\SmsSender\WelcomeSender 26 | 27 | 28 | -------------------------------------------------------------------------------- /Test/Mftf/Metadata/sms_subscription-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | application/json 18 | 19 | integer 20 | string 21 | string 22 | 23 | 24 | 25 | application/json 26 | 27 | 28 | -------------------------------------------------------------------------------- /etc/extension_attributes.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wagento/module-sms-notifications", 3 | "description": "Sends transactional SMS notifications through the LINK Mobility messaging service", 4 | "type": "magento2-module", 5 | "version": "1.1.2", 6 | "license": [ 7 | "OSL-3.0" 8 | ], 9 | "require": { 10 | "php": "^7.3", 11 | "ext-json": "*", 12 | "magento/framework": "102.0.* || 103.0.*", 13 | "magento/module-backend": "101.0.* || 102.0.*", 14 | "magento/module-config": "101.1.* || 101.2.*", 15 | "magento/module-customer": "102.0.* || 103.0.*", 16 | "magento/module-sales": "102.0.* || 103.0.*", 17 | "magento/module-store": "101.0.* || 101.1.*", 18 | "magento/module-theme": "101.0.* || 101.1.*", 19 | "magento/module-translation": "100.3.* || 100.4.*", 20 | "magento/module-ui": "101.1.* || 101.2.*", 21 | "guzzlehttp/guzzle": "^6.0 || ^7.0", 22 | "myclabs/php-enum": "^1.6", 23 | "laminas/laminas-hydrator": "^3.2" 24 | }, 25 | "require-dev": { 26 | "wagento/module-sms-notifications-webapi": "1.0.0", 27 | "phpunit/phpunit": "^6.5", 28 | "magento/magento2-functional-testing-framework": "~2.3.12" 29 | }, 30 | "autoload": { 31 | "files": [ 32 | "registration.php" 33 | ], 34 | "psr-4": { 35 | "Wagento\\SMSNotifications\\": "" 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Model/ResourceModel/TelephonePrefix/Collection.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\ResourceModel\TelephonePrefix; 18 | 19 | use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; 20 | use Wagento\SMSNotifications\Model\TelephonePrefix as TelephonePrefixModel; 21 | use Wagento\SMSNotifications\Model\ResourceModel\TelephonePrefix as TelephonePrefixResource; 22 | 23 | /** 24 | * Telephone Prefix Data Collection 25 | * 26 | * @package Wagento\SMSNotifications\Model\ResourceModel\TelephonePrefix 27 | * @author Joseph Leedy 28 | */ 29 | class Collection extends AbstractCollection 30 | { 31 | /** 32 | * {@inheritdoc} 33 | */ 34 | protected $_idFieldName = 'country_code'; 35 | 36 | protected function _construct() 37 | { 38 | $this->_init(TelephonePrefixModel::class, TelephonePrefixResource::class); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Test/Integration/RegistrationTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Test\Integration; 18 | 19 | use Magento\Framework\Component\ComponentRegistrar; 20 | use Magento\TestFramework\Helper\Bootstrap; 21 | use PHPUnit\Framework\TestCase; 22 | 23 | /** 24 | * Module Registration Test 25 | * 26 | * @package Wagento\SMSNotifications\Test\Integration 27 | * @author Joseph Leedy 28 | */ 29 | class RegistrationTest extends TestCase 30 | { 31 | public function testModuleIsRegistered(): void 32 | { 33 | $objectManager = Bootstrap::getObjectManager(); 34 | /** @var \Magento\Framework\Component\ComponentRegistrar $componentRegistrar */ 35 | $componentRegistrar = $objectManager->get(ComponentRegistrar::class); 36 | $paths = $componentRegistrar->getPaths(ComponentRegistrar::MODULE); 37 | 38 | $this->assertArrayHasKey('Wagento_SMSNotifications', $paths); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /view/frontend/templates/sms-subscription-preferences.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | /** @var \Magento\Framework\View\Element\Template $block */ 15 | 16 | $groupedSmsTypes = $block->getData('sms_types_view_model')->getGroupedSmsTypes(); 17 | ?> 18 |
19 | 20 |
21 | 36 | -------------------------------------------------------------------------------- /Model/ResourceModel/TelephonePrefix.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\ResourceModel; 18 | 19 | use Magento\Framework\Model\AbstractModel; 20 | use Magento\Framework\Model\ResourceModel\Db\AbstractDb; 21 | 22 | /** 23 | * Telephone Prefix Data Resource Model 24 | * 25 | * @package Wagento\SMSNotifications\Model\ResourceModel 26 | * @author Joseph Leedy 27 | */ 28 | class TelephonePrefix extends AbstractDb 29 | { 30 | public const TABLE_NAME = 'directory_telephone_prefix'; 31 | public const IDENTITY_COLUMN = 'country_code'; 32 | 33 | protected function _construct() 34 | { 35 | $this->_init(self::TABLE_NAME, self::IDENTITY_COLUMN); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | * 41 | * Prevent data from being saved as this entity is read-only. 42 | */ 43 | public function save(AbstractModel $object) 44 | { 45 | return $this; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Model/Config/Source/SourceType.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\Config\Source; 18 | 19 | use Magento\Framework\Option\ArrayInterface; 20 | 21 | /** 22 | * Source Type Configuration Field Source Model 23 | * 24 | * @package Wagento\SMSNotifications\Model\Config\Source 25 | * @author Joseph Leedy 26 | */ 27 | class SourceType implements ArrayInterface 28 | { 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | public function toOptionArray() 33 | { 34 | return [ 35 | [ 36 | 'value' => 'SHORTNUMBER', 37 | 'label' => __('Short Number') 38 | ], 39 | [ 40 | 'value' => 'ALPHANUMERIC', 41 | 'label' => __('Alphanumeric') 42 | ], 43 | [ 44 | 'value' => 'MSISDN', 45 | 'label' => __('Phone Number') 46 | ] 47 | ]; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /view/frontend/web/js/view/sms-terms-conditions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define([ 14 | 'jquery', 15 | 'uiComponent', 16 | 'Wagento_SMSNotifications/js/model/sms-terms-conditions-modal', 17 | 'smsNotifications' 18 | ], function ($, Component, termsConditionsModal, smsNotifications) { 19 | 'use strict'; 20 | 21 | return Component.extend({ 22 | defaults: { 23 | template: 'Wagento_SMSNotifications/sms-terms-conditions', 24 | modalTitle: null, 25 | modalContent: null 26 | }, 27 | initObservable: function () { 28 | this._super(); 29 | 30 | smsNotifications.isSubscribing.subscribe(this.showModal); 31 | 32 | return this; 33 | }, 34 | initModal: function(element) { 35 | termsConditionsModal.createModal(element, this.modalTitle); 36 | }, 37 | showModal: function () { 38 | if (!smsNotifications.isSubscribing()) { 39 | return; 40 | } 41 | 42 | termsConditionsModal.showModal(); 43 | } 44 | }); 45 | }); 46 | -------------------------------------------------------------------------------- /Gateway/Factory/ResultFactory.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Factory; 18 | 19 | use Wagento\SMSNotifications\Gateway\Entity\ErrorResult; 20 | use Wagento\SMSNotifications\Gateway\Entity\ResultInterface; 21 | use Wagento\SMSNotifications\Gateway\Entity\SuccessResult; 22 | 23 | /** 24 | * Result Factory 25 | * 26 | * @package Wagento\SMSNotifications\Gateway\Factory 27 | * @author Joseph Leedy 28 | */ 29 | class ResultFactory 30 | { 31 | public function create(string $type, array $data = []): ResultInterface 32 | { 33 | switch ($type) { 34 | case 'success': 35 | $class = SuccessResult::class; 36 | break; 37 | case 'error': 38 | $class = ErrorResult::class; 39 | break; 40 | default: 41 | throw new \InvalidArgumentException('Invalid result type.'); 42 | } 43 | 44 | return new $class($data); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /view/frontend/web/template/sms-notification-subscription.html: -------------------------------------------------------------------------------- 1 | 14 |
15 | 16 | 17 | 18 | ( | ) 19 |
-------------------------------------------------------------------------------- /Plugin/Sales/Model/Order/InvoicePlugin.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Plugin\Sales\Model\Order; 18 | 19 | use Wagento\SMSNotifications\Model\SmsSender; 20 | use Magento\Sales\Model\Order\Invoice; 21 | 22 | /** 23 | * Plug-in for {@see \Magento\Sales\Model\Order\Invoice} 24 | * 25 | * @package Wagento\SMSNotifications\Plugin\Sales\Model\Order 26 | * @author Joseph Leedy 27 | */ 28 | class InvoicePlugin 29 | { 30 | /** 31 | * @var \Wagento\SMSNotifications\Model\SmsSender|\Wagento\SMSNotifications\Model\SmsSender\InvoiceSender 32 | */ 33 | private $smsSender; 34 | 35 | public function __construct(SmsSender $smsSender) 36 | { 37 | $this->smsSender = $smsSender; 38 | } 39 | 40 | /** 41 | * @see \Magento\Sales\Model\Order\Invoice::register() 42 | */ 43 | public function afterRegister(Invoice $subject): Invoice 44 | { 45 | $this->smsSender->send($subject); 46 | 47 | return $subject; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /view/frontend/templates/customer/account/create/subscribe-field.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | ?> 14 | 15 |
16 | 17 |
18 | -------------------------------------------------------------------------------- /Plugin/Sales/Api/OrderRepositoryInterfacePlugin.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Plugin\Sales\Api; 18 | 19 | use Wagento\SMSNotifications\Model\SmsSender; 20 | use Magento\Sales\Api\Data\OrderInterface; 21 | use Magento\Sales\Api\OrderRepositoryInterface; 22 | 23 | /** 24 | * Plug-in for {@see \Magento\Sales\Api\OrderRepositoryInterface} 25 | * 26 | * @package Wagento\SMSNotifications\Plugin\Sales\Api 27 | * @author Joseph Leedy 28 | */ 29 | class OrderRepositoryInterfacePlugin 30 | { 31 | /** 32 | * @var \Wagento\SMSNotifications\Model\SmsSender|\Wagento\SMSNotifications\Model\SmsSender\OrderSender 33 | */ 34 | private $smsSender; 35 | 36 | public function __construct(SmsSender $smsSender) 37 | { 38 | $this->smsSender = $smsSender; 39 | } 40 | 41 | public function afterSave(OrderRepositoryInterface $subject, OrderInterface $order): OrderInterface 42 | { 43 | $this->smsSender->send($order); 44 | 45 | return $order; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Gateway/Factory/MessageEntityHydratorFactory.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Factory; 18 | 19 | use Wagento\SMSNotifications\Gateway\Entity\DCS; 20 | use Wagento\SMSNotifications\Gateway\Entity\TON; 21 | use Wagento\SMSNotifications\Gateway\Hydrator\MessageEntity as MessageEntityHydrator; 22 | use Wagento\SMSNotifications\Gateway\Hydrator\Strategy\Enum as EnumStrategy; 23 | 24 | /** 25 | * Message Entity Hydrator Factory 26 | * 27 | * @package Wagento\SMSNotifications\Gateway\Factory 28 | * @author Joseph Leedy 29 | */ 30 | class MessageEntityHydratorFactory 31 | { 32 | public function create(): MessageEntityHydrator 33 | { 34 | $messageHydrator = new MessageEntityHydrator(); 35 | 36 | $messageHydrator->addStrategy('sourceTON', new EnumStrategy(TON::class)); 37 | $messageHydrator->addStrategy('destinationTON', new EnumStrategy(TON::class)); 38 | $messageHydrator->addStrategy('dcs', new EnumStrategy(DCS::class)); 39 | 40 | return $messageHydrator; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Test/Integration/_files/create_sms_subscriptions_from_source.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | use Wagento\SMSNotifications\Model\SmsSubscription; 16 | use Wagento\SMSNotifications\Model\Source\SmsType as SmsTypeSource; 17 | use Magento\TestFramework\Helper\Bootstrap; 18 | 19 | $objectManager = Bootstrap::getObjectManager(); 20 | $smsTypes = array_column((new SmsTypeSource())->toArray(), 'code'); 21 | $i = 0; 22 | $count = $count ?? -1; 23 | $createdSubscriptions = []; 24 | 25 | foreach ($smsTypes as $smsType) { 26 | if ($i++ === $count) { 27 | break; 28 | } 29 | 30 | try { 31 | /** @var \Wagento\SMSNotifications\Model\SmsSubscription $smsSubscription */ 32 | $smsSubscription = $objectManager->create(SmsSubscription::class); 33 | $smsSubscription->setData([ 34 | 'customer_id' => 1, 35 | 'sms_type' => $smsType, 36 | ]); 37 | $smsSubscription->isObjectNew(true); 38 | $smsSubscription->save(); 39 | $createdSubscriptions[] = $smsSubscription; 40 | } catch (\Exception $e) { 41 | } 42 | } 43 | 44 | return $createdSubscriptions; 45 | -------------------------------------------------------------------------------- /Plugin/Sales/Model/OrderPlugin.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Plugin\Sales\Model; 18 | 19 | use Magento\Sales\Api\Data\OrderExtensionFactory; 20 | use Magento\Sales\Model\Order; 21 | 22 | /** 23 | * Plug-in for {@see \Magento\Sales\Model\Order} 24 | * 25 | * @package Wagento\SMSNotifications\Plugin\Sales\Model 26 | * @author Joseph Leedy 27 | */ 28 | class OrderPlugin 29 | { 30 | /** 31 | * @var \Magento\Sales\Api\Data\OrderExtensionFactory 32 | */ 33 | private $orderExtensionFactory; 34 | 35 | public function __construct(OrderExtensionFactory $orderExtensionFactory) 36 | { 37 | $this->orderExtensionFactory = $orderExtensionFactory; 38 | } 39 | 40 | public function afterUnhold(Order $subject): Order 41 | { 42 | $orderExtension = $subject->getExtensionAttributes() ?? $this->orderExtensionFactory->create(); 43 | 44 | $orderExtension->setIsOrderHoldReleased(true); 45 | 46 | $subject->setExtensionAttributes($orderExtension); 47 | 48 | return $subject; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Test/Mftf/Metadata/system_config-meta.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | integer 22 | 23 | 24 | integer 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Api/SmsSubscriptionManagementInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api; 18 | 19 | /** 20 | * SMS Subscription Management Service Interface 21 | * 22 | * @package Wagento\SMSNotifications\Api 23 | * @author Joseph Leedy 24 | * @api 25 | */ 26 | interface SmsSubscriptionManagementInterface 27 | { 28 | public function createSubscription(string $smsType, int $customerId): bool; 29 | 30 | /** 31 | * @param string[] $smsTypes 32 | * @param string[] $messages 33 | */ 34 | public function createSubscriptions(array $smsTypes, int $customerId, array $messages = []): int; 35 | 36 | public function removeSubscription(int $subscriptionId, int $customerId): bool; 37 | 38 | /** 39 | * @param \Wagento\SMSNotifications\Model\SmsSubscription[] $subscribedSmsTypes 40 | * @param string[] $selectedSmsTypes 41 | * @param string[] $messages 42 | */ 43 | public function removeSubscriptions( 44 | array &$subscribedSmsTypes, 45 | array $selectedSmsTypes, 46 | int $customerId, 47 | array $messages = [] 48 | ): int; 49 | } 50 | -------------------------------------------------------------------------------- /Gateway/ApiClientInterface.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway; 18 | 19 | use Wagento\SMSNotifications\Gateway\Entity\ResultInterface; 20 | 21 | /** 22 | * API Client Interface 23 | * 24 | * @package Wagento\SMSNotifications\Gateway 25 | * @author Joseph Leedy 26 | */ 27 | interface ApiClientInterface 28 | { 29 | public const HTTP_METHOD_GET = 'GET'; 30 | public const HTTP_METHOD_POST = 'POST'; 31 | 32 | public function setUri(string $uri): void; 33 | 34 | public function setUsername(string $username): void; 35 | 36 | public function setPassword(string $password): void; 37 | 38 | /** 39 | * @param string[]|\Wagento\SMSNotifications\Gateway\Entity\MessageInterface $data 40 | */ 41 | public function setData($data): void; 42 | 43 | public function setHeaders(array $headers): void; 44 | 45 | public function setHttpMethod(string $httpMethod): void; 46 | 47 | /** 48 | * @throws \Wagento\SMSNotifications\Gateway\ApiException 49 | */ 50 | public function sendRequest(): void; 51 | 52 | public function getResult(): ResultInterface; 53 | } 54 | -------------------------------------------------------------------------------- /view/frontend/web/js/checkbox-toggler.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define([ 14 | 'jquery' 15 | ], 16 | function ($) { 17 | $.widget('wagento.checkboxToggler', { 18 | options: { 19 | checkboxSelector: '[data-role-toggleable-checkbox]' 20 | }, 21 | checkboxElements: null, 22 | _create: function () { 23 | this.checkboxElements = $(this.options.checkboxSelector); 24 | 25 | this._registerEvents(); 26 | }, 27 | _registerEvents: function () { 28 | this.element.on('click', this.toggleCheckboxes.bind(this)); 29 | this.checkboxElements.on('click', this.toggleSelectAll.bind(this)); 30 | }, 31 | toggleCheckboxes: function () { 32 | const self = this; 33 | 34 | this.checkboxElements.each(function () { 35 | $(this).prop('checked', self.element.prop('checked')); 36 | }); 37 | }, 38 | toggleSelectAll: function () { 39 | this.element.prop('checked', this.checkboxElements.filter(':checked').length === this.checkboxElements.length); 40 | } 41 | }); 42 | 43 | return { 44 | 'wagentoCheckboxToggler': $.wagento.checkboxToggler 45 | }; 46 | }); 47 | -------------------------------------------------------------------------------- /Plugin/Sales/Model/ResourceModel/Order/ShipmentPlugin.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Plugin\Sales\Model\ResourceModel\Order; 18 | 19 | use Wagento\SMSNotifications\Model\SmsSender; 20 | use Magento\Sales\Model\Order\Shipment; 21 | use Magento\Sales\Model\ResourceModel\Order\Shipment as ShipmentResource; 22 | 23 | /** 24 | * Plug-in for {@see \Magento\Sales\Model\ResourceModel\Order\Shipment} 25 | * 26 | * @package Wagento\SMSNotifications\Plugin\Sales\Model\ResourceModel\Order 27 | * @author Joseph Leedy 28 | */ 29 | class ShipmentPlugin 30 | { 31 | /** 32 | * @var \Wagento\SMSNotifications\Model\SmsSender|\Wagento\SMSNotifications\Model\SmsSender\ShipmentSender 33 | */ 34 | private $smsSender; 35 | 36 | public function __construct(SmsSender $smsSender) 37 | { 38 | $this->smsSender = $smsSender; 39 | } 40 | 41 | public function afterSave(ShipmentResource $subject, ShipmentResource $result, Shipment $shipment): ShipmentResource 42 | { 43 | $this->smsSender->send($shipment); 44 | 45 | return $result; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Plugin/Sales/Api/CreditmemoRepositoryInterfacePlugin.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Plugin\Sales\Api; 18 | 19 | use Wagento\SMSNotifications\Model\SmsSender; 20 | use Magento\Sales\Api\CreditmemoRepositoryInterface; 21 | use Magento\Sales\Api\Data\CreditmemoInterface; 22 | 23 | /** 24 | * Plug-in for {@see \Magento\Sales\Api\CreditmemoRepositoryInterface} 25 | * 26 | * @package Wagento\SMSNotifications\Plugin\Sales\Api 27 | * @author Joseph Leedy 28 | * 29 | * @phpcs:disable Generic.Files.LineLength.TooLong 30 | */ 31 | class CreditmemoRepositoryInterfacePlugin 32 | { 33 | /** 34 | * @var \Wagento\SMSNotifications\Model\SmsSender|\Wagento\SMSNotifications\Model\SmsSender\CreditmemoSender 35 | */ 36 | private $smsSender; 37 | 38 | public function __construct(SmsSender $smsSender) 39 | { 40 | $this->smsSender = $smsSender; 41 | } 42 | 43 | public function afterSave(CreditmemoRepositoryInterface $subject, CreditmemoInterface $creditmemo): CreditmemoInterface 44 | { 45 | $this->smsSender->send($creditmemo); 46 | 47 | return $creditmemo; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Test/Integration/_stubs/Model/SmsSender.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Test\Integration\_stubs\Model; 18 | 19 | use Magento\Customer\Api\Data\CustomerInterface; 20 | use Magento\Framework\Model\AbstractModel; 21 | 22 | /** 23 | * Concrete Implementation of SMS Sender 24 | * 25 | * @package Wagento\SMSNotifications\Test\Integration\_stubs\Model 26 | * @author Joseph Leedy 27 | * 28 | * @codeCoverageIgnore 29 | */ 30 | class SmsSender extends \Wagento\SMSNotifications\Model\SmsSender 31 | { 32 | public function send(AbstractModel $entity): bool 33 | { 34 | return true; 35 | } 36 | 37 | public function getCustomerById(int $customerId): ?CustomerInterface 38 | { 39 | return parent::getCustomerById($customerId); 40 | } 41 | 42 | public function getCustomerMobilePhoneNumber(CustomerInterface $customer): ?string 43 | { 44 | return parent::getCustomerMobilePhoneNumber($customer); 45 | } 46 | 47 | public function getCustomerSmsSubscriptions(int $customerId): array 48 | { 49 | return parent::getCustomerSmsSubscriptions($customerId); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /view/frontend/web/template/sms-subscription-preferences.html: -------------------------------------------------------------------------------- 1 | 14 |
15 |

16 |
17 | 18 | 19 |
20 | 21 |
22 |

23 |
    24 | 25 |
  • 26 | 27 | 28 |
  • 29 | 30 |
31 |
32 | 33 |
-------------------------------------------------------------------------------- /Block/System/Config/Form/Fieldset/Info.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Block\System\Config\Form\Fieldset; 18 | 19 | use Magento\Backend\Block\Template; 20 | use Magento\Config\Block\System\Config\Form\Fieldset; 21 | use Magento\Framework\Data\Form\Element\AbstractElement; 22 | 23 | /** 24 | * Extension Information Configuration Fieldset Block 25 | * 26 | * @package Wagento\SMSNotifications\Block\System\Config\Form\Fieldset 27 | * @author Joseph Leedy 28 | */ 29 | class Info extends Fieldset 30 | { 31 | private const TEMPLATE = 'Wagento_SMSNotifications::system/config/form/fieldset/info.phtml'; 32 | 33 | /** 34 | * {@inheritdoc} 35 | * @throws \Magento\Framework\Exception\LocalizedException 36 | */ 37 | public function render(AbstractElement $element) 38 | { 39 | $block = $this->getLayout() 40 | ->createBlock(Template::class, 'sms_notifications_config_header') 41 | ->setTemplate(self::TEMPLATE) 42 | ->setData([ 43 | 'info_text' => $element->getComment() ?? '' 44 | ]); 45 | 46 | return $block->_toHtml(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /view/base/web/js/grid/massactions-mixin.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy 8 | * @author Yair García Torres 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | define([ 13 | 'underscore', 14 | 'mageUtils' 15 | ], function (_, utils) { 16 | 'use strict'; 17 | 18 | return function (target) { 19 | return target.extend({ 20 | /** 21 | * @inheritDoc 22 | * @todo: Figure out how to use callback in listing XML instead of overriding default callback. 23 | */ 24 | defaultCallback: function (action, data) { 25 | if (data.params.namespace !== 'sms_subscriptions_listing') { 26 | this._super(action, data); 27 | return; 28 | } 29 | 30 | let itemsType = 'selected', 31 | selections = {}; 32 | 33 | data[itemsType] = _.difference(data.selected, data.excluded); 34 | selections[itemsType] = data[itemsType]; 35 | 36 | if (!selections[itemsType].length) { 37 | selections[itemsType] = false; 38 | } 39 | 40 | _.extend(selections, data.params || {}); 41 | 42 | utils.submit({ 43 | url: action.url, 44 | data: selections 45 | }); 46 | } 47 | }); 48 | }; 49 | }); -------------------------------------------------------------------------------- /view/frontend/layout/customer_account_create.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | Wagento\SMSNotifications\ViewModel\TelephonePrefixes 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /view/frontend/templates/customer/account/create/mobile-telephone-field.phtml: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | /** @var \Wagento\SMSNotifications\Block\Customer\Account\Create\MobileTelephoneField $block */ 15 | 16 | /** @var \Wagento\SMSNotifications\ViewModel\TelephonePrefixes $telephonePrefixesViewModel */ 17 | $telephonePrefixesViewModel = $block->getData('telephone_prefixes_view_model'); 18 | ?> 19 |
20 | 21 |
22 | -------------------------------------------------------------------------------- /Test/Integration/_files/shipment.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Payment\Helper\Data as PaymentDataHelper; 15 | use Magento\Sales\Api\Data\ShipmentExtensionInterface; 16 | use Magento\Sales\Model\Order\Shipment; 17 | use Magento\Sales\Model\Order\ShipmentFactory; 18 | 19 | require BP . '/dev/tests/integration/testsuite/Magento/Sales/_files/default_rollback.php'; 20 | require __DIR__ . '/order.php'; 21 | 22 | $payment = $order->getPayment(); 23 | $paymentInfoBlock = $objectManager->get(PaymentDataHelper::class)->getInfoBlock($payment); 24 | $items = []; 25 | 26 | $payment->setBlockMock($paymentInfoBlock); 27 | 28 | /** @var \Magento\Sales\Model\Order\Item $orderItem */ 29 | foreach ($order->getItems() as $orderItem) { 30 | $items[$orderItem->getId()] = $orderItem->getQtyOrdered(); 31 | } 32 | 33 | /** @var \Magento\Sales\Api\Data\ShipmentInterface $shipment */ 34 | $shipment = $objectManager->get(ShipmentFactory::class)->create($order, $items); 35 | $shipmentExtensionAttributes = $shipment->getExtensionAttributes() 36 | ?? $objectManager->create(ShipmentExtensionInterface::class); 37 | 38 | $shipment->setPackages([['1'], ['2']]); 39 | $shipment->setShipmentStatus(Shipment::STATUS_NEW); 40 | 41 | $shipmentExtensionAttributes->setIsSmsNotificationSent(true); 42 | 43 | $shipment->setExtensionAttributes($shipmentExtensionAttributes); 44 | $shipment->save(); 45 | 46 | return $shipment; 47 | -------------------------------------------------------------------------------- /etc/acl.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Test/Integration/_files/product_simple.php: -------------------------------------------------------------------------------- 1 | 9 | * @author Yair García Torres 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Catalog\Model\Product; 15 | use Magento\Catalog\Model\Product\Attribute\Source\Status; 16 | use Magento\Catalog\Model\Product\Type; 17 | use Magento\Catalog\Model\Product\Visibility; 18 | use Magento\TestFramework\Helper\Bootstrap; 19 | 20 | Bootstrap::getInstance()->reinitialize(); 21 | 22 | /** @var \Magento\TestFramework\ObjectManager $objectManager */ 23 | $objectManager = Bootstrap::getObjectManager(); 24 | $product = $objectManager->create(Product::class); 25 | 26 | $product->isObjectNew(true); 27 | $product->setTypeId(Type::TYPE_SIMPLE) 28 | ->setId(1) 29 | ->setAttributeSetId(4) 30 | ->setWebsiteIds([1]) 31 | ->setName('Simple Product') 32 | ->setSku('simple') 33 | ->setPrice(10) 34 | ->setWeight(1) 35 | ->setShortDescription("Short description") 36 | ->setTaxClassId(0) 37 | ->setDescription('Description with html tag') 38 | ->setMetaTitle('meta title') 39 | ->setMetaKeyword('meta keyword') 40 | ->setMetaDescription('meta description') 41 | ->setVisibility(Visibility::VISIBILITY_BOTH) 42 | ->setStatus(Status::STATUS_ENABLED) 43 | ->setStockData( 44 | [ 45 | 'use_config_manage_stock' => 1, 46 | 'qty' => 100, 47 | 'is_qty_decimal' => 0, 48 | 'is_in_stock' => 1, 49 | ] 50 | )->save(); 51 | -------------------------------------------------------------------------------- /ViewModel/TermsConditions.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\ViewModel; 18 | 19 | use Wagento\SMSNotifications\Api\ConfigInterface; 20 | use Magento\Framework\Exception\NoSuchEntityException; 21 | use Magento\Framework\View\Element\Block\ArgumentInterface; 22 | use Magento\Store\Model\StoreManagerInterface; 23 | 24 | /** 25 | * Terms & Conditions View Model 26 | * 27 | * @package Wagento\SMSNotifications\ViewModel 28 | * @author Joseph Leedy 29 | */ 30 | class TermsConditions implements ArgumentInterface 31 | { 32 | /** 33 | * @var \Magento\Store\Model\StoreManagerInterface 34 | */ 35 | private $storeManager; 36 | /** 37 | * @var \Wagento\SMSNotifications\Api\ConfigInterface 38 | */ 39 | private $config; 40 | 41 | public function __construct(StoreManagerInterface $storeManager, ConfigInterface $config) 42 | { 43 | $this->storeManager = $storeManager; 44 | $this->config = $config; 45 | } 46 | 47 | public function getContent(): string 48 | { 49 | try { 50 | $websiteId = (int)$this->storeManager->getStore()->getWebsiteId(); 51 | } catch (NoSuchEntityException $e) { 52 | $websiteId = null; 53 | } 54 | 55 | return $this->config->getTermsAndConditions($websiteId) ?? ''; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Model/Data/TelephonePrefix.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\Data; 18 | 19 | use Wagento\SMSNotifications\Api\Data\TelephonePrefixInterface; 20 | use Magento\Framework\Api\AbstractSimpleObject; 21 | 22 | /** 23 | * Telephone Prefix Entity 24 | * 25 | * @package Wagento\SMSNotifications\Model\Data 26 | * @author Joseph Leedy 27 | */ 28 | class TelephonePrefix extends AbstractSimpleObject implements TelephonePrefixInterface 29 | { 30 | public function setCountryCode(string $countryCode): TelephonePrefixInterface 31 | { 32 | return $this->setData(self::COUNTRY_CODE, $countryCode); 33 | } 34 | 35 | public function getCountryCode(): string 36 | { 37 | return (string)$this->_get(self::COUNTRY_CODE); 38 | } 39 | 40 | public function setCountryName(string $countryName): TelephonePrefixInterface 41 | { 42 | return $this->setData(self::COUNTRY_NAME, $countryName); 43 | } 44 | 45 | public function getCountryName(): string 46 | { 47 | return (string)$this->_get(self::COUNTRY_NAME); 48 | } 49 | 50 | public function setPrefix(int $prefix): TelephonePrefixInterface 51 | { 52 | return $this->setData(self::PREFIX, $prefix); 53 | } 54 | 55 | public function getPrefix(): int 56 | { 57 | return (int)$this->_get(self::PREFIX); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ViewModel/MobileTelephone.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\ViewModel; 18 | 19 | use Magento\Customer\Model\Session as CustomerSession; 20 | use Magento\Framework\View\Element\Block\ArgumentInterface; 21 | 22 | /** 23 | * Mobile Telephone View Model 24 | * 25 | * @package Wagento\SMSNotifications\ViewModel 26 | * @author Joseph Leedy 27 | */ 28 | class MobileTelephone implements ArgumentInterface 29 | { 30 | /** 31 | * @var \Magento\Customer\Model\Session 32 | */ 33 | private $customerSession; 34 | 35 | public function __construct(CustomerSession $customerSession) 36 | { 37 | $this->customerSession = $customerSession; 38 | } 39 | 40 | public function getPrefix(): ?string 41 | { 42 | $mobilePrefixAttribute = $this->customerSession->getCustomerData() 43 | ->getCustomAttribute('sms_mobile_phone_prefix'); 44 | 45 | if ($mobilePrefixAttribute === null) { 46 | return null; 47 | } 48 | 49 | return $mobilePrefixAttribute->getValue(); 50 | } 51 | 52 | public function getNumber(): ?string 53 | { 54 | $mobileNumberAttribute = $this->customerSession->getCustomerData() 55 | ->getCustomAttribute('sms_mobile_phone_number'); 56 | 57 | if ($mobileNumberAttribute === null) { 58 | return null; 59 | } 60 | 61 | return $mobileNumberAttribute->getValue(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Block/AbstractBlock.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Block; 18 | 19 | use Wagento\SMSNotifications\Api\ConfigInterface; 20 | use Magento\Framework\Exception\NoSuchEntityException; 21 | use Magento\Framework\View\Element\Template\Context; 22 | use Magento\Framework\View\Element\Template; 23 | 24 | /** 25 | * SMS Notifications Base Block 26 | * 27 | * @package Wagento\SMSNotifications\Block 28 | * @author Joseph Leedy 29 | */ 30 | abstract class AbstractBlock extends Template 31 | { 32 | /** 33 | * @var \Wagento\SMSNotifications\Api\ConfigInterface 34 | */ 35 | protected $config; 36 | 37 | public function __construct( 38 | Context $context, 39 | ConfigInterface $config, 40 | array $data = [] 41 | ) { 42 | parent::__construct($context, $data); 43 | 44 | $this->config = $config; 45 | } 46 | 47 | /** 48 | * {@inheritdoc} 49 | */ 50 | public function toHtml() 51 | { 52 | if (!$this->config->isEnabled($this->getWebsiteId())) { 53 | return ''; 54 | } 55 | 56 | return parent::toHtml(); 57 | } 58 | 59 | protected function getWebsiteId(): ?int 60 | { 61 | try { 62 | $websiteId = (int)$this->_storeManager->getStore()->getWebsiteId(); 63 | } catch (NoSuchEntityException $e) { 64 | $websiteId = null; 65 | } 66 | 67 | return $websiteId; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Test/Mftf/ActionGroup/ConfigSmsNotificationsEnabledActionGroup.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Model/SmsSender/WelcomeSender.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\SmsSender; 18 | 19 | use Wagento\SMSNotifications\Model\SmsSender; 20 | use Magento\Framework\Model\AbstractModel; 21 | 22 | /** 23 | * Welcome SMS Sender 24 | * 25 | * @package Wagento\SMSNotifications\Model\SmsSender 26 | * @author Joseph Leedy 27 | * @api 28 | */ 29 | class WelcomeSender extends SmsSender 30 | { 31 | /** 32 | * @phpcs:disable Generic.Files.LineLength.TooLong 33 | * 34 | * @param \Magento\Framework\Model\AbstractModel|\Magento\Customer\Api\Data\CustomerInterface|\Magento\Customer\Model\Customer $customer 35 | */ 36 | public function send(AbstractModel $customer): bool 37 | { 38 | $websiteId = (int)$customer->getWebsiteId(); 39 | 40 | if (!$this->isModuleEnabled($websiteId) || !$this->config->sendWelcomeMessage($websiteId)) { 41 | return false; 42 | } 43 | 44 | $customerData = $customer->getDataModel(); 45 | $messageRecipient = $this->getCustomerMobilePhoneNumber($customerData); 46 | 47 | if ($messageRecipient === null) { 48 | return false; 49 | } 50 | 51 | $messageTemplate = $this->config->getWelcomeMessageTemplate((int)$customer->getStoreId()); 52 | 53 | $this->messageService->setCustomer($customerData); 54 | 55 | return $this->messageService->sendMessage($messageTemplate, $messageRecipient, 'customer'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Ui/Component/Listing/Column/SmsSubscriptionStatus.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Ui\Component\Listing\Column; 18 | 19 | use Magento\Framework\Data\OptionSourceInterface; 20 | use Magento\Ui\Component\Listing\Columns\Column; 21 | 22 | /** 23 | * SMS Subscription Status Column 24 | * 25 | * @package Wagento\SMSNotifications\Ui\Component\Listing\Column 26 | * @author Joseph Leedy 27 | */ 28 | class SmsSubscriptionStatus extends Column implements OptionSourceInterface 29 | { 30 | /** 31 | * {@inheritdoc} 32 | */ 33 | public function prepareDataSource(array $dataSource): array 34 | { 35 | $dataSource = parent::prepareDataSource($dataSource); 36 | 37 | if (!isset($dataSource['data']['items'])) { 38 | return $dataSource; 39 | } 40 | 41 | foreach ($dataSource['data']['items'] as &$item) { 42 | $item['status'] = $item['is_active'] ? __('Subscribed') : __('Not Subscribed'); 43 | } 44 | 45 | return $dataSource; 46 | } 47 | 48 | /** 49 | * {@inheritdoc} 50 | */ 51 | public function toOptionArray(): array 52 | { 53 | return [ 54 | [ 55 | 'value' => '0', 56 | 'label' => __('Subscribed') 57 | ], 58 | [ 59 | 'value' => '1', 60 | 'label' => __('Not Subscribed') 61 | ] 62 | ]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /view/frontend/layout/customer_smsnotifications_manage.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | My Text Notifications 21 | 22 | 23 | 24 | 25 | 26 | Wagento\SMSNotifications\ViewModel\SmsTypes 27 | Wagento\SMSNotifications\ViewModel\CustomerSmsSubscriptions 28 | Wagento\SMSNotifications\ViewModel\MobileTelephone 29 | Wagento\SMSNotifications\ViewModel\TelephonePrefixes 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Test/Integration/Model/SmsSender/WelcomeSenderTest.php: -------------------------------------------------------------------------------- 1 | 10 | * @author Yair García Torres 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Test\Integration\Model\SmsSender; 18 | 19 | use Wagento\SMSNotifications\Model\SmsSender\WelcomeSender; 20 | use Wagento\SMSNotifications\Test\Integration\SmsSenderTestCase; 21 | use Magento\Customer\Model\Customer; 22 | 23 | /** 24 | * Welcome SMS Sender Test 25 | * 26 | * @package Wagento\SMSNotifications\Test\Integration\Model\SmsSender 27 | * @author Joseph Leedy 28 | */ 29 | class WelcomeSenderTest extends SmsSenderTestCase 30 | { 31 | /** 32 | * @magentoAppArea frontend 33 | * @magentoDataFixture Magento/Customer/_files/customer.php 34 | * @magentoDataFixture smsMobileNumberFixtureProvider 35 | */ 36 | public function testSendWelcomeSmsForCustomer(): void 37 | { 38 | $configMock = $this->getConfigMock(); 39 | $welcomeSender = $this->objectManager->create( 40 | WelcomeSender::class, 41 | [ 42 | 'config' => $configMock, 43 | 'messageService' => $this->getMessageServiceMock() 44 | ] 45 | ); 46 | $customer = $this->objectManager->create(Customer::class)->load(1); 47 | 48 | $configMock->expects($this->once()) 49 | ->method('getWelcomeMessageTemplate') 50 | ->with(1) 51 | ->willReturn('Welcome to our store!'); 52 | 53 | $this->assertTrue($welcomeSender->send($customer)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Test/Mftf/ActionGroup/ConfigSmsNotificationsRequireOptinActionGroup.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /view/frontend/web/template/mobile-telephone-field.html: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 |
17 |
18 |
19 |
20 | 21 |
22 | 24 |
25 |
26 |
27 | 28 |
29 | 30 |
31 |
32 |
33 |
34 |
35 | -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCreateCustomerSmsSubscribeVisibleTest.xml: -------------------------------------------------------------------------------- 1 | 2 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | <description value="Verifies that the SMS subscription checkbox is visible on the storefront registration page if module is enabled."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-73"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | <group value="create"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 32 | </before> 33 | <amOnPage stepKey="amOnStorefrontPage" url="/"/> 34 | <waitForPageLoad stepKey="waitForStorefrontPage"/> 35 | <click selector="{{StorefrontPanelHeaderSection.createAnAccountLink}}" stepKey="clickOnCreateAccountLink"/> 36 | <seeElement selector="{{StorefrontCustomerCreateFormSection.smsSubscribeCheckbox}}" stepKey="smsSubscribeCheckboxRendered"/> 37 | </test> 38 | </tests> -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCreateCustomerSmsSubscribeNotVisibleTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="StorefrontCreateCustomerSmsSubscribeNotVisibleTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="Subscribe customer to SMS notifications during registration on storefront"/> 20 | <title value="SMS subscription checkbox not visible on storefront customer registration"/> 21 | <description value="Verifies that the SMS subscription checkbox is not visible on the storefront registration page if module is not enabled."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-73"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | <group value="create"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="DisableSmsNotificationsActionGroup" stepKey="disableSmsNotifications"/> 32 | </before> 33 | <amOnPage stepKey="amOnStorefrontPage" url="/"/> 34 | <waitForPageLoad stepKey="waitForStorefrontPage"/> 35 | <click selector="{{StorefrontPanelHeaderSection.createAnAccountLink}}" stepKey="clickOnCreateAccountLink"/> 36 | <dontSeeElement selector="{{StorefrontCustomerCreateFormSection.smsSubscribeCheckbox}}" stepKey="smsSubscribeCheckboxNotRendered"/> 37 | </test> 38 | </tests> -------------------------------------------------------------------------------- /Setup/Patch/Data/RemoveConfigData.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Setup\Patch\Data 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Setup\Patch\Data; 18 | 19 | use Magento\Framework\Setup\ModuleDataSetupInterface; 20 | use Magento\Framework\Setup\Patch\DataPatchInterface; 21 | use Magento\Framework\Setup\Patch\PatchRevertableInterface; 22 | 23 | /** 24 | * SMS Notification Settings Uninstaller 25 | * 26 | * @package Wagento\SMSNotifications\Setup\Patch\Data 27 | * @author Joseph Leedy <joseph@wagento.com> 28 | * 29 | * @codeCoverageIgnore 30 | */ 31 | class RemoveConfigData implements DataPatchInterface, PatchRevertableInterface 32 | { 33 | /** 34 | * @var \Magento\Framework\Setup\ModuleDataSetupInterface 35 | */ 36 | private $setup; 37 | 38 | public function __construct(ModuleDataSetupInterface $setup) 39 | { 40 | $this->setup = $setup; 41 | } 42 | 43 | /** 44 | * {@inheritdoc} 45 | */ 46 | public static function getDependencies(): array 47 | { 48 | return []; 49 | } 50 | 51 | /** 52 | * {@inheritdoc} 53 | */ 54 | public function getAliases(): array 55 | { 56 | return []; 57 | } 58 | 59 | /** 60 | * {@inheritdoc} 61 | */ 62 | public function apply(): self 63 | { 64 | return $this; 65 | } 66 | 67 | /** 68 | * {@inheritdoc} 69 | */ 70 | public function revert(): void 71 | { 72 | $this->setup->getConnection()->delete( 73 | $this->setup->getTable('core_config_data'), 74 | '`path` LIKE \'sms_notifications/%\'' 75 | ); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /view/frontend/web/js/model/sms-subscription-preferences-modal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy <joseph@wagento.com> 8 | * @author Yair García Torres <yair.garcia@wagento.com> 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define([ 14 | 'jquery', 15 | 'ko', 16 | 'Magento_Ui/js/modal/modal', 17 | 'mage/translate' 18 | ], function ($, ko, modal, $t) { 19 | 'use strict'; 20 | 21 | return { 22 | open: ko.observable(false).extend({notify: 'always'}), 23 | modalWindow: null, 24 | /** 25 | * Create pop-up window for provided element. 26 | * 27 | * @param {HTMLElement} element 28 | * @param {string} title 29 | * @param {function(Object)} onClose 30 | */ 31 | createModal: function (element, title, onClose) { 32 | this.modalWindow = element; 33 | 34 | const options = { 35 | title: title, 36 | modalClass: 'modal-popup-sms-subscription-preferences', 37 | responsive: true, 38 | buttons: [ 39 | { 40 | text: $t('Save'), 41 | class: 'action primary', 42 | /** @inheritdoc */ 43 | click: function () { 44 | if (onClose && typeof onClose === 'function') { 45 | onClose(this); 46 | } 47 | 48 | this.closeModal(); 49 | } 50 | } 51 | ] 52 | }; 53 | 54 | modal(options, $(this.modalWindow)); 55 | }, 56 | showModal: function () { 57 | $(this.modalWindow).modal('openModal'); 58 | } 59 | }; 60 | }); 61 | -------------------------------------------------------------------------------- /Test/Integration/Setup/CustomerAttributesTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Test\Integration\Setup 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Test\Integration\Setup; 18 | 19 | use Magento\Eav\Api\AttributeRepositoryInterface; 20 | use Magento\Eav\Api\Data\AttributeInterface; 21 | use Magento\Framework\Exception\NoSuchEntityException; 22 | use Magento\TestFramework\Helper\Bootstrap; 23 | use PHPUnit\Framework\TestCase; 24 | 25 | /** 26 | * Customer Attribute Creation Test 27 | * 28 | * @package Wagento\SMSNotifications\Test\Integration\Setup 29 | * @author Joseph Leedy <joseph@wagento.com> 30 | */ 31 | class CustomerAttributesTest extends TestCase 32 | { 33 | /** 34 | * @dataProvider mobilePhoneAttributeProvider 35 | */ 36 | public function testMobilePhoneAttributeIsCreated(string $attributeName): void 37 | { 38 | /** @var \Magento\Eav\Api\AttributeRepositoryInterface $attributeRepository */ 39 | $attributeRepository = Bootstrap::getObjectManager()->create(AttributeRepositoryInterface::class); 40 | 41 | try { 42 | $attribute = $attributeRepository->get('customer', $attributeName); 43 | } catch (NoSuchEntityException $e) { 44 | $this->fail($e->getMessage()); 45 | } 46 | 47 | $this->assertInstanceOf(AttributeInterface::class, $attribute); 48 | } 49 | 50 | public static function mobilePhoneAttributeProvider(): array 51 | { 52 | return [ 53 | [ 54 | 'sms_mobile_phone_prefix' 55 | ], 56 | [ 57 | 'sms_mobile_phone_number' 58 | ] 59 | ]; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /view/frontend/layout/customer_account.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd" design_abstraction="custom"> 16 | <body> 17 | <referenceBlock name="customer_account_navigation"> 18 | <block class="Magento\Customer\Block\Account\Delimiter" name="customer-account-navigation-sms-notifications-delimiter" template="Magento_Customer::account/navigation-delimiter.phtml" ifconfig="sms_notifications/general/enabled"> 19 | <arguments> 20 | <argument name="sortOrder" xsi:type="number">20</argument> 21 | </arguments> 22 | </block> 23 | <block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-sms-notifications-link" template="Wagento_SMSNotifications::customer/account/link.phtml" ifconfig="sms_notifications/general/enabled"> 24 | <arguments> 25 | <argument name="label" xsi:type="string" translate="true">My Text Notifications</argument> 26 | <argument name="path" xsi:type="string">customer/smsnotifications/manage</argument> 27 | <argument name="sortOrder" xsi:type="number">10</argument> 28 | </arguments> 29 | </block> 30 | </referenceBlock> 31 | <referenceContainer name="content"> 32 | <block name="sms-notifications-clear-storage" template="Wagento_SMSNotifications::clear-storage.phtml" ifconfig="sms_notifications/general/enabled"/> 33 | </referenceContainer> 34 | </body> 35 | </page> -------------------------------------------------------------------------------- /Test/Mftf/Data/SystemConfigData.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd"> 16 | <entity name="SmsNotificationsEnabledYes" type="sms_notifications_enabled_value"> 17 | <data key="value">1</data> 18 | </entity> 19 | <entity name="SmsNotificationsEnabledNo" type="sms_notifications_enabled_value"> 20 | <data key="value">0</data> 21 | </entity> 22 | <entity name="EnableSmsNotifications" type="sms_notifications_config"> 23 | <requiredEntity type="sms_notifications_enabled_value">SmsNotificationsEnabledYes</requiredEntity> 24 | </entity> 25 | <entity name="DisableSmsNotifications" type="sms_notifications_config"> 26 | <requiredEntity type="sms_notifications_enabled_value">SmsNotificationsEnabledNo</requiredEntity> 27 | </entity> 28 | <entity name="SmsNotificationsRequireOptinYes" type="sms_notifications_require_optin_value"> 29 | <data key="value">1</data> 30 | </entity> 31 | <entity name="SmsNotificationsRequireOptinNo" type="sms_notifications_require_optin_value"> 32 | <data key="value">0</data> 33 | </entity> 34 | <entity name="AllowSmsNotificationsOptin" type="sms_notifications_config"> 35 | <requiredEntity type="sms_notifications_require_optin_value">SmsNotificationsRequireOptinYes</requiredEntity> 36 | </entity> 37 | <entity name="DisallowSmsNotificationsOptin" type="sms_notifications_config"> 38 | <requiredEntity type="sms_notifications_require_optin_value">SmsNotificationsRequireOptinNo</requiredEntity> 39 | </entity> 40 | </entities> -------------------------------------------------------------------------------- /Test/Integration/_files/creditmemo.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @author Joseph Leedy <joseph@wagento.com> 9 | * @author Yair García Torres <yair.garcia@wagento.com> 10 | * @copyright Copyright (c) Wagento (https://wagento.com/) 11 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 12 | */ 13 | 14 | use Magento\Sales\Api\Data\CreditmemoExtensionInterface; 15 | use Magento\Sales\Model\Order\Creditmemo; 16 | use Magento\Sales\Model\Order\CreditmemoFactory; 17 | 18 | require BP . '/dev/tests/integration/testsuite/Magento/Sales/_files/default_rollback.php'; 19 | require __DIR__ . '/order.php'; 20 | 21 | /** @var \Magento\Sales\Model\Order\CreditmemoFactory $creditmemoFactory */ 22 | $creditmemoFactory = $objectManager->get(CreditmemoFactory::class); 23 | /** @var \Magento\Sales\Model\Order\Creditmemo $creditmemo */ 24 | $creditmemo = $creditmemoFactory->createByOrder($order, $order->getData()); 25 | $creditmemoExtensionAttributes = $creditmemo->getExtensionAttributes() 26 | ?? $objectManager->create(CreditmemoExtensionInterface::class); 27 | 28 | $creditmemo->setOrder($order); 29 | $creditmemo->setState(Creditmemo::STATE_OPEN); 30 | $creditmemo->setIncrementId('100000001'); 31 | 32 | $creditmemoExtensionAttributes->setIsSmsNotificationSent(true); 33 | 34 | $creditmemo->setExtensionAttributes($creditmemoExtensionAttributes); 35 | $creditmemo->save(); 36 | 37 | /** @var \Magento\Sales\Model\Order\Item $orderItem */ 38 | $orderItem = current($order->getAllItems()); 39 | 40 | $orderItem->setName('Test item') 41 | ->setQtyRefunded(1) 42 | ->setQtyInvoiced(10) 43 | ->setOriginalPrice(20); 44 | 45 | /** @var \Magento\Sales\Model\Order\Creditmemo\Item $creditItem */ 46 | $creditItem = $objectManager->get(\Magento\Sales\Model\Order\Creditmemo\Item::class); 47 | 48 | $creditItem->setCreditmemo($creditmemo) 49 | ->setName('Creditmemo item') 50 | ->setOrderItemId($orderItem->getId()) 51 | ->setQty(1) 52 | ->setPrice(20) 53 | ->save(); 54 | 55 | return $creditmemo; 56 | -------------------------------------------------------------------------------- /Logger/Handler/FileHandler.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Logger\Handler 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Logger\Handler; 18 | 19 | use Wagento\SMSNotifications\Api\ConfigInterface; 20 | use Magento\Framework\Exception\NoSuchEntityException; 21 | use Magento\Framework\Filesystem\DriverInterface; 22 | use Magento\Framework\Logger\Handler\Base; 23 | use Magento\Store\Model\StoreManagerInterface; 24 | 25 | /** 26 | * Log File Handler 27 | * 28 | * @package Wagento\SMSNotifications\Logger\Handler 29 | * @author Joseph Leedy <joseph@wagento.com> 30 | */ 31 | class FileHandler extends Base 32 | { 33 | /** 34 | * @var \Magento\Store\Model\StoreManagerInterface 35 | */ 36 | private $storeManager; 37 | /** 38 | * @var \Wagento\SMSNotifications\Api\ConfigInterface 39 | */ 40 | private $config; 41 | 42 | public function __construct( 43 | DriverInterface $filesystem, 44 | StoreManagerInterface $storeManager, 45 | ConfigInterface $config, 46 | $filePath = null 47 | ) { 48 | $this->config = $config; 49 | $fileName = '/var/log/sms_notifications.log'; 50 | 51 | parent::__construct($filesystem, $filePath, $fileName); 52 | 53 | $this->storeManager = $storeManager; 54 | } 55 | 56 | /** 57 | * {@inheritdoc} 58 | */ 59 | public function isHandling(array $record) 60 | { 61 | try { 62 | $websiteId = (int)$this->storeManager->getStore()->getWebsiteId(); 63 | } catch (NoSuchEntityException $e) { 64 | $websiteId = null; 65 | } 66 | 67 | return !(!$this->config->isEnabled($websiteId) || !$this->config->isLoggingEnabled()); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /view/frontend/web/js/view/mobile-telephone-field.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy <joseph@wagento.com> 8 | * @author Yair García Torres <yair.garcia@wagento.com> 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define([ 14 | 'ko', 15 | 'uiComponent', 16 | 'mage/translate', 17 | 'smsNotifications' 18 | ], function (ko, Component, $t, smsNotifications) { 19 | 'use strict'; 20 | 21 | return Component.extend({ 22 | defaults: { 23 | template: 'Wagento_SMSNotifications/mobile-telephone-field', 24 | mobileTelephonePrefixOptions: [], 25 | defaultMobileTelephonePrefix: '', 26 | mobileTelephonePrefix: '', 27 | mobileTelephoneNumber: '', 28 | tracks: { 29 | mobileTelephonePrefix: true, 30 | mobileTelephoneNumber: true 31 | }, 32 | statefull: { 33 | mobileTelephonePrefix: true, 34 | mobileTelephoneNumber: true 35 | } 36 | }, 37 | showField: ko.observable(false), 38 | initialize: function () { 39 | this._super(); 40 | 41 | if (this.mobileTelephonePrefix.length === 0 && this.defaultMobileTelephonePrefix.length > 0) { 42 | this.mobileTelephonePrefix = this.defaultMobileTelephonePrefix; 43 | } 44 | }, 45 | initObservable: function () { 46 | this._super(); 47 | 48 | smsNotifications.isSubscribed.subscribe(this.toggleFieldVisibility, this); 49 | 50 | return this; 51 | }, 52 | toggleFieldVisibility: function (isSubscribed) { 53 | this.showField(isSubscribed); 54 | 55 | if (!isSubscribed) { 56 | this.mobileTelephonePrefix = this.defaultMobileTelephonePrefix; 57 | this.mobileTelephoneNumber = ''; 58 | } 59 | } 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /Model/ResourceModel/SmsSubscription/Collection.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Model\ResourceModel\SmsSubscription 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\ResourceModel\SmsSubscription; 18 | 19 | use Wagento\SMSNotifications\Model\ResourceModel\SmsSubscription as SmsSubscriptionResourceModel; 20 | use Wagento\SMSNotifications\Model\SmsSubscription as SmsSubscriptionModel; 21 | use Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection; 22 | 23 | /** 24 | * SMS Subscription Collection 25 | * 26 | * @package Wagento\SMSNotifications\Model\ResourceModel\SmsSubscription 27 | * @author Yair García Torres <yair.garcia@wagento.com> 28 | * @author Joseph Leedy <joseph@wagento.com> 29 | */ 30 | class Collection extends AbstractCollection 31 | { 32 | /** 33 | * {@inheritdoc} 34 | */ 35 | protected $_idFieldName = 'sms_subscription_id'; 36 | 37 | /** 38 | * @return string[] 39 | */ 40 | public function getAllSmsTypes(): array 41 | { 42 | $smsTypesSelect = clone $this->getSelect(); 43 | 44 | $smsTypesSelect->reset(\Magento\Framework\DB\Select::ORDER); 45 | $smsTypesSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT); 46 | $smsTypesSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET); 47 | $smsTypesSelect->reset(\Magento\Framework\DB\Select::COLUMNS); 48 | $smsTypesSelect->columns('sms_type', 'main_table'); 49 | 50 | return $this->getConnection()->fetchCol($smsTypesSelect, $this->_bindParams); 51 | } 52 | 53 | /** 54 | * {@inheritdoc} 55 | */ 56 | protected function _construct() 57 | { 58 | $this->_init(SmsSubscriptionModel::class, SmsSubscriptionResourceModel::class); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCreateCustomerSmsSubscriptionPreferencesModalTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="StorefrontCreateCustomerSmsSubscriptionPreferencesModalTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="Subscribe customer to SMS notifications during registration on storefront"/> 20 | <title value="SMS subscription preferences link opens SMS Subscription Preferences Modal"/> 21 | <description value="Ensures that clicking the Preferences link opens the Subscription Preferences modal."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-73"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | <group value="create"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 32 | </before> 33 | <amOnPage url="/" stepKey="amOnStorefrontPage"/> 34 | <waitForPageLoad stepKey="waitForStorefrontPage"/> 35 | <click selector="{{StorefrontPanelHeaderSection.createAnAccountLink}}" stepKey="clickOnCreateAccountLink"/> 36 | <click selector="{{StorefrontCustomerCreateFormSection.smsSubscriptionPreferencesLink}}" stepKey="clickSmsSubscriptionPreferencesLink"/> 37 | <seeElement selector="{{StorefrontSmsSubscriptionPreferencesModalSection.smsSubscriptionPreferencesModal}}" stepKey="smsSubscriptionPreferencesModalOpened"/> 38 | </test> 39 | </tests> -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCustomerAccountSmsPreferencesLinkVisibilityTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="StorefrontCustomerAccountSmsPreferencesLinkVisibilityTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="Update customer SMS notification preferences from storefront"/> 20 | <title value="SMS Subscription Preferences link not visible"/> 21 | <description value="Ensures that the SMS Subscription Preferences link is not added to the Customer Account links if module is disabled."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-109"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | <group value="manage"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="DisableSmsNotificationsActionGroup" stepKey="disableSmsNotifications"/> 32 | <createData entity="Simple_US_Customer" stepKey="customer"/> 33 | </before> 34 | <after> 35 | <deleteData createDataKey="customer" stepKey="deleteCustomer"/> 36 | </after> 37 | <actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount"> 38 | <argument name="Customer" value="$$customer$$"/> 39 | </actionGroup> 40 | <amOnPage url="customer/account/index" stepKey="navigateToCustomerAccountPage"/> 41 | <dontSeeElement selector="{{StorefrontSmsSubscriptionPreferencesSection.accountLink}}" stepKey="smsPreferencesAccountLinkNotVisible"/> 42 | </test> 43 | </tests> -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCreateCustomerSmsTermsConditionsModalTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="StorefrontCreateCustomerSmsTermsConditionsModalTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="Subscribe customer to SMS notifications during registration on storefront"/> 20 | <title value="SMS subscription checkbox opens SMS Terms & Conditions Modal"/> 21 | <description value="Ensures that checking the SMS subscription checkbox opens the Terms and Conditions modal."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-73"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | <group value="create"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 32 | <actionGroup ref="AllowSmsNotificationsOptinActionGroup" stepKey="allowSmsNotificationOptin"/> 33 | </before> 34 | <amOnPage url="/" stepKey="amOnStorefrontPage"/> 35 | <waitForPageLoad stepKey="waitForStorefrontPage"/> 36 | <click selector="{{StorefrontPanelHeaderSection.createAnAccountLink}}" stepKey="clickOnCreateAccountLink"/> 37 | <click selector="{{StorefrontCustomerCreateFormSection.smsSubscribeCheckbox}}" stepKey="clickSubscribeSmsNotificationsCheckbox"/> 38 | <seeElement selector="{{StorefrontSmsTermsConditionsModalSection.smsTermsConditionsModal}}" stepKey="smsTermsConditionsModalOpened"/> 39 | </test> 40 | </tests> -------------------------------------------------------------------------------- /Controller/SmsNotifications/Manage.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Controller\SmsNotifications 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Controller\SmsNotifications; 18 | 19 | use Magento\Customer\Controller\AbstractAccount; 20 | use Magento\Framework\App\Action\Context; 21 | use Magento\Framework\Exception\NoSuchEntityException; 22 | use Magento\Framework\Exception\NotFoundException; 23 | use Magento\Store\Model\StoreManagerInterface; 24 | use Wagento\SMSNotifications\Model\Config; 25 | 26 | /** 27 | * Manage SMS Subscriptions Controller 28 | * 29 | * @package Wagento\SMSNotifications\Controller\SmsNotifications 30 | * @author Yair García Torres <yair.garcia@wagento.com> 31 | * @author Joseph Leedy <joseph@wagento.com> 32 | */ 33 | class Manage extends AbstractAccount 34 | { 35 | /** 36 | * @var \Magento\Store\Api\StoreManagementInterface 37 | */ 38 | private $storeManager; 39 | /** 40 | * @var \Wagento\SMSNotifications\Model\Config 41 | */ 42 | private $config; 43 | 44 | public function __construct(Context $context, StoreManagerInterface $storeManager, Config $config) 45 | { 46 | parent::__construct($context); 47 | 48 | $this->storeManager = $storeManager; 49 | $this->config = $config; 50 | } 51 | 52 | /** 53 | * {@inheritdoc} 54 | */ 55 | public function execute() 56 | { 57 | try { 58 | $websiteId = (int)$this->storeManager->getStore()->getWebsiteId(); 59 | } catch (NoSuchEntityException $e) { 60 | $websiteId = null; 61 | } 62 | 63 | if (!$this->config->isEnabled($websiteId)) { 64 | throw new NotFoundException(__('SMS Notifications is not enabled.')); 65 | } 66 | 67 | $this->_view->loadLayout(); 68 | $this->_view->renderLayout(); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Ui/Component/Form/Fieldset/SmsSubscriptionListingFieldset.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Ui\Component\Form\Fieldset 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Ui\Component\Form\Fieldset; 18 | 19 | use Wagento\SMSNotifications\Api\ConfigInterface; 20 | use Magento\Framework\Exception\NoSuchEntityException; 21 | use Magento\Framework\View\Element\UiComponent\ContextInterface; 22 | use Magento\Store\Model\StoreManagerInterface; 23 | use Magento\Ui\Component\Form\Fieldset; 24 | 25 | /** 26 | * SMS Subscription Listing Fieldset UI Component 27 | * 28 | * @package Wagento\SMSNotifications\Ui\Component\Form\Fieldset 29 | * @author Joseph Leedy <joseph@wagento.com> 30 | */ 31 | class SmsSubscriptionListingFieldset extends Fieldset 32 | { 33 | /** 34 | * @var \Magento\Store\Model\StoreManagerInterface 35 | */ 36 | private $storeManager; 37 | /** 38 | * @var \Wagento\SMSNotifications\Api\ConfigInterface 39 | */ 40 | private $config; 41 | 42 | public function __construct( 43 | ContextInterface $context, 44 | StoreManagerInterface $storeManager, 45 | ConfigInterface $config, 46 | $components = [], 47 | array $data = [] 48 | ) { 49 | parent::__construct($context, $components, $data); 50 | 51 | $this->storeManager = $storeManager; 52 | $this->config = $config; 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | public function prepare() 59 | { 60 | parent::prepare(); 61 | 62 | try { 63 | $websiteId = (int)$this->storeManager->getStore()->getWebsiteId(); 64 | } catch (NoSuchEntityException $e) { 65 | $websiteId = null; 66 | } 67 | 68 | if (!$this->config->isEnabled($websiteId)) { 69 | $this->_data['config']['componentDisabled'] = true; 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCreateCustomerMobilePhoneNotVisibleTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="StorefrontCreateCustomerMobilePhoneNotVisibleTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="Subscribe customer to SMS notifications during registration on storefront"/> 20 | <title value="Mobile phone fields not visible on storefront customer registration page"/> 21 | <description value="Verifies that the mobile phone fields are not visible on the storefront registration page if customer has not subscribed to SMS."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-94"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_attributes"/> 27 | <group value="customer"/> 28 | <group value="create"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 32 | <actionGroup ref="AllowSmsNotificationsOptinActionGroup" stepKey="allowSmsNotificationOptin"/> 33 | </before> 34 | <amOnPage stepKey="amOnStorefrontPage" url="/"/> 35 | <waitForPageLoad stepKey="waitForStorefrontPage"/> 36 | <click selector="{{StorefrontPanelHeaderSection.createAnAccountLink}}" stepKey="clickOnCreateAccountLink"/> 37 | <dontSeeElement selector="{{StorefrontCustomerCreateFormSection.smsMobilePhonePrefixDropdown}}" stepKey="dontSeeMobilePrefixDropdown"/> 38 | <dontSeeElement selector="{{StorefrontCustomerCreateFormSection.smsMobilePhoneNumberField}}" stepKey="dontSeeMobileNumberField"/> 39 | </test> 40 | </tests> -------------------------------------------------------------------------------- /etc/adminhtml/di.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> 16 | <type name="Wagento\SMSNotifications\Controller\Adminhtml\Subscription\MassCreate"> 17 | <arguments> 18 | <argument name="logger" xsi:type="object">Wagento\SMSNotifications\Logger\Logger</argument> 19 | </arguments> 20 | </type> 21 | <type name="Wagento\SMSNotifications\Controller\Adminhtml\Subscription\MassDelete"> 22 | <arguments> 23 | <argument name="logger" xsi:type="object">Wagento\SMSNotifications\Logger\Logger</argument> 24 | </arguments> 25 | </type> 26 | <type name="Wagento\SMSNotifications\Model\MessageVariables\InvoiceVariables"> 27 | <arguments> 28 | <argument name="urlBuilder" xsi:type="object">Magento\Framework\Url</argument> 29 | </arguments> 30 | </type> 31 | <type name="Wagento\SMSNotifications\Model\MessageVariables\OrderVariables"> 32 | <arguments> 33 | <argument name="urlBuilder" xsi:type="object">Magento\Framework\Url</argument> 34 | </arguments> 35 | </type> 36 | <type name="Wagento\SMSNotifications\Model\MessageVariables\ShipmentVariables"> 37 | <arguments> 38 | <argument name="urlBuilder" xsi:type="object">Magento\Framework\Url</argument> 39 | </arguments> 40 | </type> 41 | <type name="Wagento\SMSNotifications\Ui\DataProvider\SmsSubscriptions"> 42 | <arguments> 43 | <argument name="backendSession" xsi:type="object">Magento\Backend\Model\Session\Proxy</argument> 44 | </arguments> 45 | </type> 46 | <type name="Magento\Ui\Component\MassAction\Filter"> 47 | <plugin name="smsTypeFilter" type="Wagento\SMSNotifications\Plugin\Component\MassAction\FilterPlugin"/> 48 | </type> 49 | </config> -------------------------------------------------------------------------------- /Test/Mftf/Test/AdminCustomerSmsSubscriptionsFieldsetDisabledTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="AdminCustomerSmsSubscriptionsFieldsetDisabledTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="View SMS subscriptions in Admin"/> 20 | <title value="SMS subscriptions tab not visible"/> 21 | <description value="Logs into Admin, selects a customer, and verifies that the SMS Subscriptions tab is not added if SMS notifications are disabled."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-77"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | </annotations> 29 | <before> 30 | <createData entity="Simple_US_Customer" stepKey="createCustomer"/> 31 | <actionGroup ref="LoginAsAdmin" stepKey="login"/> 32 | <actionGroup ref="DisableSmsNotificationsActionGroup" stepKey="disableSmsNotifications"/> 33 | </before> 34 | <after> 35 | <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> 36 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 37 | <actionGroup ref="logout" stepKey="logout"/> 38 | </after> 39 | <actionGroup ref="OpenEditCustomerFromAdminActionGroup" stepKey="OpenEditCustomerFrom"> 40 | <argument name="customer" value="$$createCustomer$$"/> 41 | </actionGroup> 42 | <dontSeeElement selector="{{AdminCustomerSmsSubscriptionsSection.smsSubscriptionsTab}}" stepKey="smsSubscriptionsTabNotVisible"/> 43 | </test> 44 | </tests> -------------------------------------------------------------------------------- /view/frontend/web/js/model/sms-terms-conditions-modal.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Wagento SMS Notifications powered by LINK Mobility 3 | * 4 | * Sends transactional SMS notifications through the LINK Mobility messaging 5 | * service. 6 | * 7 | * @author Joseph Leedy <joseph@wagento.com> 8 | * @author Yair García Torres <yair.garcia@wagento.com> 9 | * @copyright Copyright (c) Wagento (https://wagento.com/) 10 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 11 | */ 12 | 13 | define([ 14 | 'jquery', 15 | 'Magento_Ui/js/modal/modal', 16 | 'mage/translate', 17 | 'smsNotifications' 18 | ], function ($, modal, $t, smsNotifications) { 19 | 'use strict'; 20 | 21 | return { 22 | modalWindow: null, 23 | /** 24 | * Create pop-up window for provided element. 25 | * 26 | * @param {HTMLElement} element 27 | * @param {string} title 28 | */ 29 | createModal: function (element, title) { 30 | this.modalWindow = element; 31 | 32 | const options = { 33 | title: title, 34 | modalClass: 'modal-popup-sms-terms-conditions', 35 | responsive: true, 36 | buttons: [ 37 | { 38 | text: $t('I Agree'), 39 | class: 'action primary', 40 | click: function () { 41 | smsNotifications.isSubscribed(true); 42 | smsNotifications.isSubscribing(false); 43 | 44 | this.closeModal(); 45 | } 46 | }, 47 | { 48 | text: $t('Cancel'), 49 | class: 'action secondary', 50 | click: this.handleDisagree 51 | } 52 | ], 53 | modalCloseBtnHandler: this.handleDisagree 54 | }; 55 | 56 | modal(options, $(this.modalWindow)); 57 | }, 58 | showModal: function () { 59 | $(this.modalWindow).modal('openModal'); 60 | }, 61 | handleDisagree: function () { 62 | smsNotifications.isSubscribed(false); 63 | smsNotifications.isSubscribing(false); 64 | 65 | this.closeModal(); 66 | } 67 | }; 68 | }); 69 | -------------------------------------------------------------------------------- /ViewModel/SmsTypes.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\ViewModel 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\ViewModel; 18 | 19 | use Wagento\SMSNotifications\Model\Source\SmsType as SmsTypeSource; 20 | use Magento\Framework\View\Element\Block\ArgumentInterface; 21 | 22 | /** 23 | * SMS Types View Model 24 | * 25 | * @package Wagento\SMSNotifications\ViewModel 26 | * @author Joseph Leedy <joseph@wagento.com> 27 | */ 28 | class SmsTypes implements ArgumentInterface 29 | { 30 | /** 31 | * @var \Wagento\SMSNotifications\Model\Source\SmsType 32 | */ 33 | private $smsTypeSource; 34 | 35 | public function __construct(SmsTypeSource $smsTypeSource) 36 | { 37 | $this->smsTypeSource = $smsTypeSource; 38 | } 39 | 40 | public function getSmsTypes(string $field = ''): array 41 | { 42 | $smsTypes = $this->smsTypeSource->toArray(); 43 | 44 | if (trim($field) !== '') { 45 | $smsTypes = array_column($smsTypes, $field); 46 | } 47 | 48 | return $smsTypes; 49 | } 50 | 51 | public function getGroupedSmsTypes(): array 52 | { 53 | $groupedSmsTypes = []; 54 | $i = 0; 55 | 56 | foreach ($this->smsTypeSource->toArray() as $smsType) { 57 | $key = array_search($smsType['group'], array_column($groupedSmsTypes, 'groupName')); 58 | 59 | if ($key === false) { 60 | $key = $i++; 61 | $groupedSmsTypes[$key] = [ 62 | 'groupName' => $smsType['group'], 63 | 'title' => ucwords(str_replace('_', ' ', $smsType['group'])), 64 | 'smsTypes' => [] 65 | ]; 66 | } 67 | 68 | $groupedSmsTypes[$key]['smsTypes'][] = [ 69 | 'code' => $smsType['code'], 70 | 'description' => $smsType['description'] 71 | ]; 72 | } 73 | 74 | return $groupedSmsTypes; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Model/SmsSubscriptionValidator.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Model 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model; 18 | 19 | use Wagento\SMSNotifications\Api\ValidationRulesInterface; 20 | use Magento\Framework\Model\AbstractModel; 21 | use Magento\Framework\Validator\DataObject as ValidatorObject; 22 | use Magento\Framework\Validator\DataObjectFactory as ValidatorObjectFactory; 23 | 24 | /** 25 | * SMS Subscription Model Validator 26 | * 27 | * @package Wagento\SMSNotifications\Model 28 | * @author Joseph Leedy <joseph@wagento.com> 29 | */ 30 | class SmsSubscriptionValidator extends Validator 31 | { 32 | public function __construct( 33 | ValidatorObjectFactory $validatorObjectFactory, 34 | ValidationRulesInterface $validationRules 35 | ) { 36 | if (!$validationRules instanceof SmsSubscriptionValidationRules) { 37 | throw new \InvalidArgumentException( 38 | (string)__('Validation Rules object must be an instance of SmsSubscriptionValidationRules.') 39 | ); 40 | } 41 | 42 | parent::__construct($validatorObjectFactory, $validationRules); 43 | } 44 | 45 | /** 46 | * @throws \InvalidArgumentException 47 | * @throws \Exception 48 | * @throws \Zend_Validate_Exception 49 | */ 50 | public function validate(AbstractModel $model): void 51 | { 52 | if (!$model instanceof SmsSubscription) { 53 | throw new \InvalidArgumentException( 54 | (string)__('Model to validate must be an instance of SmsSubscription.') 55 | ); 56 | } 57 | 58 | parent::validate($model); 59 | } 60 | 61 | /** 62 | * @throws \Zend_Validate_Exception 63 | */ 64 | protected function addValidationRules(ValidatorObject $validator): void 65 | { 66 | $this->validationRules->addRequiredFieldRules($validator); 67 | $this->validationRules->addSmsTypeIsValidRule($validator); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /etc/db_schema.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd"> 16 | <table name="sms_subscription" resource="default" engine="innodb" comment="SMS Notification Subscriptions"> 17 | <column xsi:type="int" name="sms_subscription_id" padding="10" unsigned="true" nullable="false" identity="true" comment="SMS Subscription ID"/> 18 | <column xsi:type="int" name="customer_id" padding="10" unsigned="true" nullable="false" identity="false" comment="Customer ID"/> 19 | <column xsi:type="varchar" name="sms_type" nullable="false" length="50" comment="SMS Type Code (e.g. \"order_placed\")"/> 20 | <constraint xsi:type="primary" referenceId="PRIMARY"> 21 | <column name="sms_subscription_id"/> 22 | </constraint> 23 | <constraint xsi:type="foreign" referenceId="SMS_SUBSCRIPTION_CUSTOMER_ID_CUSTOMER_ENTITY_ENTITY_ID" table="sms_subscription" column="customer_id" referenceTable="customer_entity" referenceColumn="entity_id" onDelete="CASCADE"/> 24 | </table> 25 | <table name="directory_telephone_prefix" resource="default" engine="innodb" comment="Telephone Prefix Directory for SMS Notifications"> 26 | <column xsi:type="varchar" name="country_code" nullable="false" length="2" comment="Country Code, in ISO-2 Format"/> 27 | <column xsi:type="varchar" name="country_name" nullable="false" length="255" comment="Country Name"/> 28 | <column xsi:type="smallint" name="prefix" padding="5" unsigned="true" nullable="false" identity="false" comment="Numeric Telephone Prefix"/> 29 | <constraint xsi:type="primary" referenceId="PRIMARY"> 30 | <column name="country_code"/> 31 | </constraint> 32 | <constraint xsi:type="unique" referenceId="DIRECTORY_TELEPHONE_PREFIX_COUNTRY_CODE"> 33 | <column name="country_code"/> 34 | </constraint> 35 | </table> 36 | </schema> -------------------------------------------------------------------------------- /Gateway/Hydrator/Strategy/Enum.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Gateway\Hydrator\Strategy 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Gateway\Hydrator\Strategy; 18 | 19 | use Zend\Hydrator\Exception\InvalidArgumentException; 20 | use Zend\Hydrator\Strategy\StrategyInterface; 21 | 22 | /** 23 | * ENUM Hydrator Strategy 24 | * 25 | * @package Wagento\SMSNotifications\Gateway\Hydrator\Strategy 26 | * @author Joseph Leedy <joseph@wagento.com> 27 | */ 28 | class Enum implements StrategyInterface 29 | { 30 | /** 31 | * @var string 32 | */ 33 | private $enumClass; 34 | 35 | public function __construct(string $enumClass) 36 | { 37 | if (!\is_subclass_of($enumClass, \MyCLabs\Enum\Enum::class)) { 38 | throw new InvalidArgumentException('Parameter enumClass must be an instance of \MyCLabs\Enum\Enum.'); 39 | } 40 | 41 | $this->enumClass = $enumClass; 42 | } 43 | 44 | /** 45 | * {@inheritdoc} 46 | */ 47 | public function extract($value) 48 | { 49 | if ($value === null) { 50 | return $value; 51 | } 52 | 53 | if (!$value instanceof \MyCLabs\Enum\Enum) { 54 | throw new InvalidArgumentException(\sprintf( 55 | 'Unable to extract. Expected instance of \MyCLabs\Enum\Enum. %s was given.', 56 | is_object($value) ? get_class($value) : gettype($value) 57 | )); 58 | } 59 | 60 | return $value->__toString(); 61 | } 62 | 63 | /** 64 | * {@inheritdoc} 65 | */ 66 | public function hydrate($value) 67 | { 68 | try { 69 | $enum = new $this->enumClass($value); 70 | } catch (\UnexpectedValueException $e) { 71 | throw new InvalidArgumentException( 72 | \sprintf('Unable to hydrate. Received error: %s', $e->getMessage()), 73 | 0, 74 | $e 75 | ); 76 | } 77 | 78 | return $enum; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Wagento SMS Notifications 2 | 3 | Thank you for your interest in helping Wagento improve this extension. We 4 | welcome any enhancements or bug fixes that you might wish to contribute. 5 | 6 | **Note**: If you have a security concern or an issue that you cannot resolve 7 | yourself, please send an e-mail to [support@wagento.com] instead of opening a 8 | GitHub ticket. 9 | 10 | ## Things to Know 11 | 12 | * At Wagento, we follow the [Git Flow] methodology when adding new features. 13 | * We follow the [PSR-1], [PSR-2], and [PSR-12] coding standards. 14 | * Please be civil and do not harass or abuse any members of the Wagento staff 15 | or other contributors. 16 | * Wagento reserves the right to decline any contributions which do not fit 17 | our guidelines or vision for the extension. 18 | * All code submitted becomes the sole property of Wagento and is subject to our 19 | copyright with or without attribution. 20 | 21 | ## Important Steps to Follow 22 | 23 | 1. [Open a GitHub issue][issue] describing the enhancement or fix that you are 24 | contributing. 25 | 2. Create a fork of [our GitHub repository][repository] in your GitHub account. 26 | 3. Create a feature branch to contain your contribution. 27 | 4. Develop your contribution and test it thoroughly under the Magento versions 28 | supported by the extension (see the [README] for a list). 29 | 5. Add unit tests, integration tests, and functional tests to prove that your 30 | contribution functions properly and does not break anything. 31 | 6. [Submit a Pull Request][pr] referencing the ticket you created in Step 1. 32 | 33 | ## Follow-up 34 | 35 | After you submit your contribution, we will review it when time permits. Once we 36 | do so, we will add a comment to the Pull Request letting you know what needs to 37 | be added, corrected, or otherwise changed. When we are satisfied, we will merge 38 | your changes and add your name to the Credits section of the [README] if 39 | merited. 40 | 41 | [support@wagento.com]: mailto:support@wagento.com?subject=[SMS%20Notifications]%20 42 | [Git Flow]: http://nvie.com/posts/a-successful-git-branching-model/ 43 | [PSR-1]: https://www.php-fig.org/psr/psr-1/ 44 | [PSR-2]: https://www.php-fig.org/psr/psr-2/ 45 | [PSR-12]: https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md 46 | [repository]: https://github.com/wagento/sms-notifications 47 | [issue]: https://github.com/wagento/sms-notifications/issues 48 | [pr]: https://github.com/wagento/sms-notifications/compare 49 | [README]: ./README.md -------------------------------------------------------------------------------- /Test/Unit/Logger/Processor/SensitiveDataProcessorTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Test\Unit\Logger\Processor 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Test\Unit\Logger\Processor; 18 | 19 | use Wagento\SMSNotifications\Logger\Processor\SensitiveDataProcessor; 20 | use PHPUnit\Framework\TestCase; 21 | 22 | /** 23 | * Sensitive Log Data Processor Test 24 | * 25 | * @package Wagento\SMSNotifications\Test\Unit\Logger\Processor 26 | * @author Joseph Leedy <joseph@wagento.com> 27 | */ 28 | class SensitiveDataProcessorTest extends TestCase 29 | { 30 | public function testProcessorIsCallable() 31 | { 32 | $sensitiveDataProcessor = new SensitiveDataProcessor(); 33 | 34 | $this->assertTrue(is_callable($sensitiveDataProcessor)); 35 | } 36 | 37 | public function testRedactsSensitiveDataInRecordContext(): void 38 | { 39 | $testObject = new \stdClass(); 40 | $testObject->field0 = 'foo'; 41 | $testObject->field1 = 'bar'; 42 | $testObject->field2 = 'sensitive'; 43 | $testObject->field3 = new \stdClass(); 44 | $testObject->field3->subfield0 = 'foo'; 45 | 46 | $resultObject = clone $testObject; 47 | $resultObject->field2 = '*********'; 48 | 49 | $record = [ 50 | 'context' => [ 51 | 'password' => 'foobar123', 52 | 'fruits' => [ 53 | 'apple', 54 | 'orange', 55 | 'cherry' 56 | ], 57 | 'object' => $testObject 58 | ], 59 | 'extra' => [], 60 | ]; 61 | $expected = array_replace_recursive($record, [ 62 | 'context' => [ 63 | 'password' => '*********', 64 | 'object' => $resultObject 65 | ] 66 | ]); 67 | $sensitiveDataProcessor = new SensitiveDataProcessor(['field2']); 68 | $actual = call_user_func($sensitiveDataProcessor, $record); 69 | 70 | $this->assertEquals($expected, $actual); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Model/SourceValidator.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Model 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model; 18 | 19 | use Wagento\SMSNotifications\Api\ValidationRulesInterface; 20 | use Wagento\SMSNotifications\Model\Config\Backend\Source; 21 | use Magento\Framework\Model\AbstractModel; 22 | use Magento\Framework\Validator\DataObject as ValidatorObject; 23 | use Magento\Framework\Validator\DataObjectFactory as ValidatorObjectFactory; 24 | 25 | /** 26 | * Source Configuration Field Validator 27 | * 28 | * @package Wagento\SMSNotifications\Model 29 | * @author Joseph Leedy <joseph@wagento.com> 30 | */ 31 | class SourceValidator extends Validator 32 | { 33 | /** 34 | * @var string 35 | */ 36 | private $sourceType; 37 | 38 | public function __construct( 39 | ValidatorObjectFactory $validatorObjectFactory, 40 | ValidationRulesInterface $validationRules 41 | ) { 42 | if (!$validationRules instanceof SourceValidationRules) { 43 | throw new \InvalidArgumentException( 44 | (string)__('Validation Rules object must be an instance of SourceValidationRules.') 45 | ); 46 | } 47 | 48 | parent::__construct($validatorObjectFactory, $validationRules); 49 | } 50 | 51 | /** 52 | * @throws \InvalidArgumentException 53 | * @throws \Exception 54 | * @throws \Zend_Validate_Exception 55 | */ 56 | public function validate(AbstractModel $model): void 57 | { 58 | if (!$model instanceof Source) { 59 | throw new \InvalidArgumentException((string)__('Model to validate must be an instance of Source.')); 60 | } 61 | 62 | parent::validate($model); 63 | } 64 | 65 | public function setSourceType(string $sourceType): self 66 | { 67 | $this->sourceType = $sourceType; 68 | 69 | return $this; 70 | } 71 | 72 | /** 73 | * @throws \Zend_Validate_Exception 74 | */ 75 | protected function addValidationRules(ValidatorObject $validator): void 76 | { 77 | $this->validationRules->addSourceIsValidRules($validator, $this->sourceType); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Test/Mftf/Test/StorefrontCreateCustomerMobilePhoneVisibleTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="StorefrontCreateCustomerMobilePhoneVisibleTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="Subscribe customer to SMS notifications during registration on storefront"/> 20 | <title value="Mobile phone fields visible on storefront customer registration page"/> 21 | <description value="Verifies that the mobile phone fields are visible on the storefront registration page if customer subscribes to SMS."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-94"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_attributes"/> 27 | <group value="customer"/> 28 | <group value="create"/> 29 | </annotations> 30 | <before> 31 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 32 | <actionGroup ref="AllowSmsNotificationsOptinActionGroup" stepKey="allowSmsNotificationOptin"/> 33 | </before> 34 | <amOnPage stepKey="amOnStorefrontPage" url="/"/> 35 | <waitForPageLoad stepKey="waitForStorefrontPage"/> 36 | <click selector="{{StorefrontPanelHeaderSection.createAnAccountLink}}" stepKey="clickOnCreateAccountLink"/> 37 | <checkOption selector="{{StorefrontCustomerCreateFormSection.smsSubscribeCheckbox}}" stepKey="subscribeToSmsNotifications"/> 38 | <wait time="5" stepKey="wait1"/> 39 | <click selector="{{StorefrontSmsTermsConditionsModalSection.agreeButton}}" stepKey="clickAgreeButton"/> 40 | <wait time="5" stepKey="wait2"/> 41 | <seeElement selector="{{StorefrontCustomerCreateFormSection.smsMobilePhonePrefixDropdown}}" stepKey="seeMobilePrefixDropdown"/> 42 | <seeElement selector="{{StorefrontCustomerCreateFormSection.smsMobilePhoneNumberField}}" stepKey="seeMobileNumberField"/> 43 | </test> 44 | </tests> -------------------------------------------------------------------------------- /Test/Mftf/Test/AdminViewCustomerSmsSubscriptionsTest.xml: -------------------------------------------------------------------------------- 1 | <?xml version="1.0" encoding="UTF-8"?> 2 | <!-- 3 | /** 4 | * Wagento SMS Notifications powered by LINK Mobility 5 | * 6 | * Sends transactional SMS notifications through the LINK Mobility messaging 7 | * service. 8 | * 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | --> 15 | <tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd"> 16 | <test name="AdminViewCustomerSmsSubscriptionsTest"> 17 | <annotations> 18 | <features value="Customer"/> 19 | <stories value="View SMS subscriptions in Admin"/> 20 | <title value="View customer's SMS subscriptions"/> 21 | <description value="Logs into Admin, selects a customer, and views their SMS subscriptions."/> 22 | <severity value="CRITICAL"/> 23 | <testCaseId value="REED-77"/> 24 | <group value="wagento"/> 25 | <group value="sms_notifications"/> 26 | <group value="sms_subscriptions"/> 27 | <group value="customer"/> 28 | </annotations> 29 | <before> 30 | <createData entity="Simple_US_Customer" stepKey="createCustomer"/> 31 | <createData entity="SMS_Subscription" stepKey="createSmsSubscription"> 32 | <requiredEntity createDataKey="createCustomer"/> 33 | </createData> 34 | <actionGroup ref="LoginAsAdmin" stepKey="login"/> 35 | <actionGroup ref="EnableSmsNotificationsActionGroup" stepKey="enableSmsNotifications"/> 36 | </before> 37 | <after> 38 | <deleteData createDataKey="createSmsSubscription" stepKey="deleteSmsSubscription"/> 39 | <deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/> 40 | <actionGroup ref="logout" stepKey="logout"/> 41 | </after> 42 | <actionGroup ref="OpenEditCustomerFromAdminActionGroup" stepKey="OpenEditCustomerFrom"> 43 | <argument name="customer" value="$$createCustomer$$"/> 44 | </actionGroup> 45 | <click selector="{{AdminCustomerSmsSubscriptionsSection.smsSubscriptionsTab}}" stepKey="openSmsSubscriptionsTab"/> 46 | <waitForAjaxLoad stepKey="waitForLoadAjax"/> 47 | <seeElement selector="{{AdminCustomerSmsSubscriptionsSection.smsSubscriptionsListing}}" stepKey="smsSubscriptionGridIsRendered"/> 48 | </test> 49 | </tests> 50 | -------------------------------------------------------------------------------- /Model/Config/Backend/Source.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Model\Config\Backend 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Model\Config\Backend; 18 | 19 | use Wagento\SMSNotifications\Api\ValidatorInterface; 20 | use Wagento\SMSNotifications\Model\SourceValidator; 21 | use Magento\Framework\App\Cache\TypeListInterface; 22 | use Magento\Framework\App\Config\ScopeConfigInterface; 23 | use Magento\Framework\App\Config\Value; 24 | use Magento\Framework\Data\Collection\AbstractDb; 25 | use Magento\Framework\Model\Context; 26 | use Magento\Framework\Model\ResourceModel\AbstractResource; 27 | use Magento\Framework\Registry; 28 | 29 | /** 30 | * Source Configuration Field Backend Model 31 | * 32 | * @package Wagento\SMSNotifications\Model\Config\Backend 33 | * @author Joseph Leedy <joseph@wagento.com> 34 | */ 35 | class Source extends Value 36 | { 37 | /** 38 | * @var \Wagento\SMSNotifications\Api\ValidatorInterface 39 | */ 40 | private $validator; 41 | 42 | public function __construct( 43 | Context $context, 44 | Registry $registry, 45 | ScopeConfigInterface $config, 46 | TypeListInterface $cacheTypeList, 47 | ValidatorInterface $validator, 48 | AbstractResource $resource = null, 49 | AbstractDb $resourceCollection = null, 50 | array $data = [] 51 | ) { 52 | if (!$validator instanceof SourceValidator) { 53 | throw new \InvalidArgumentException((string)__('Validator must be an instance of SourceValidator.')); 54 | } 55 | 56 | parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); 57 | 58 | $this->validator = $validator; 59 | } 60 | 61 | public function getSource(): string 62 | { 63 | return $this->getValue(); 64 | } 65 | 66 | /** 67 | * {@inheritdoc} 68 | * @throws \Zend_Validate_Exception 69 | */ 70 | protected function _getValidationRulesBeforeSave() 71 | { 72 | $sourceType = $this->getFieldsetDataValue('source_type') ?? 'MSISDN'; 73 | 74 | $this->validator->setSourceType($sourceType); 75 | 76 | return $this->validator->getValidator(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Api/SmsSubscriptionRepositoryInterface.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Api 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Api; 18 | 19 | use Wagento\SMSNotifications\Api\Data\SmsSubscriptionInterface; 20 | use Magento\Framework\Api\SearchCriteriaInterface; 21 | use Magento\Framework\Api\SearchResultsInterface; 22 | 23 | /** 24 | * SMS Subscription Repository Interface 25 | * 26 | * @package Wagento\SMSNotifications\Api 27 | * @author Joseph Leedy <joseph@wagento.com> 28 | * @api 29 | */ 30 | interface SmsSubscriptionRepositoryInterface 31 | { 32 | /** 33 | * @param int $id 34 | * @return \Wagento\SMSNotifications\Api\Data\SmsSubscriptionInterface 35 | * @throws \Magento\Framework\Exception\NoSuchEntityException 36 | */ 37 | public function get(int $id): SmsSubscriptionInterface; 38 | 39 | /** 40 | * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria 41 | * @return \Magento\Framework\Api\SearchResultsInterface 42 | */ 43 | public function getList(SearchCriteriaInterface $searchCriteria): SearchResultsInterface; 44 | 45 | /** 46 | * @param int $customerId 47 | * @return \Magento\Framework\Api\SearchResultsInterface 48 | */ 49 | public function getListByCustomerId(int $customerId): SearchResultsInterface; 50 | 51 | /** 52 | * @param \Wagento\SMSNotifications\Api\Data\SmsSubscriptionInterface $smsSubscription 53 | * @return \Wagento\SMSNotifications\Api\Data\SmsSubscriptionInterface 54 | * @throws \Magento\Framework\Exception\CouldNotSaveException 55 | */ 56 | public function save(SmsSubscriptionInterface $smsSubscription): SmsSubscriptionInterface; 57 | 58 | /** 59 | * @param \Wagento\SMSNotifications\Api\Data\SmsSubscriptionInterface $smsSubscription 60 | * @return bool 61 | * @throws \Magento\Framework\Exception\CouldNotDeleteException 62 | */ 63 | public function delete(SmsSubscriptionInterface $smsSubscription): bool; 64 | 65 | /** 66 | * @param int $id 67 | * @return bool 68 | * @throws \Magento\Framework\Exception\NoSuchEntityException 69 | * @throws \Magento\Framework\Exception\CouldNotDeleteException 70 | */ 71 | public function deleteById(int $id): bool; 72 | } 73 | -------------------------------------------------------------------------------- /Test/Integration/Plugin/Sales/Model/OrderPluginTest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Wagento SMS Notifications powered by LINK Mobility 4 | * 5 | * Sends transactional SMS notifications through the LINK Mobility messaging 6 | * service. 7 | * 8 | * @package Wagento\SMSNotifications\Test\Integration\Plugin\Sales\Model 9 | * @author Joseph Leedy <joseph@wagento.com> 10 | * @author Yair García Torres <yair.garcia@wagento.com> 11 | * @copyright Copyright (c) Wagento (https://wagento.com/) 12 | * @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 13 | */ 14 | 15 | declare(strict_types=1); 16 | 17 | namespace Wagento\SMSNotifications\Test\Integration\Plugin\Sales\Model; 18 | 19 | use Wagento\SMSNotifications\Plugin\Sales\Model\OrderPlugin; 20 | use Magento\Framework\Interception\PluginList\PluginList; 21 | use Magento\Sales\Model\Order; 22 | use Magento\TestFramework\ObjectManager; 23 | use PHPUnit\Framework\TestCase; 24 | 25 | /** 26 | * Order Plug-in Test 27 | * 28 | * @package Wagento\SMSNotifications\Test\Integration\Plugin\Sales\Model 29 | * @author Joseph Leedy <joseph@wagento.com> 30 | */ 31 | class OrderPluginTest extends TestCase 32 | { 33 | /** 34 | * @var \Magento\TestFramework\ObjectManager 35 | */ 36 | private $objectManager; 37 | 38 | /** 39 | * @magentoAppArea frontend 40 | */ 41 | public function testPluginIsConfigured(): void 42 | { 43 | $pluginList = $this->objectManager->create(PluginList::class); 44 | $plugins = $pluginList->get(Order::class, []); 45 | 46 | $this->assertArrayHasKey('sms_notifications_add_order_extension_attribute', $plugins); 47 | $this->assertSame(OrderPlugin::class, $plugins['sms_notifications_add_order_extension_attribute']['instance']); 48 | } 49 | 50 | /** 51 | * @magentoAppArea frontend 52 | * @magentoDataFixture orderDataFixtureProvider 53 | */ 54 | public function testAfterUnholdSetsExtensionAttribute(): void 55 | { 56 | $order = $this->objectManager->create(Order::class); 57 | 58 | $order->loadByIncrementId('100000001'); 59 | $order->hold(); 60 | $order->unhold(); 61 | 62 | $this->assertTrue($order->getExtensionAttributes()->getIsOrderHoldReleased()); 63 | } 64 | 65 | public static function orderDataFixtureProvider(): void 66 | { 67 | require __DIR__ . '/../../../_files/order.php'; 68 | } 69 | 70 | protected function setUp() 71 | { 72 | parent::setUp(); 73 | 74 | $this->objectManager = ObjectManager::getInstance(); 75 | } 76 | 77 | protected function tearDown() 78 | { 79 | parent::tearDown(); 80 | 81 | $this->objectManager = null; 82 | } 83 | } 84 | --------------------------------------------------------------------------------