├── .gitattributes ├── .github └── FUNDING.yml ├── CHANGELOG.md ├── Observer └── SendOrderNotification.php ├── README.md ├── composer.json ├── etc ├── acl.xml ├── adminhtml │ └── system.xml ├── config.xml ├── events.xml └── module.xml └── registration.php /.gitattributes: -------------------------------------------------------------------------------- 1 | /docs export-ignore 2 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: markshust 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). 7 | 8 | ## [1.0.2] - 2019-10-18 9 | 10 | ### Fixed 11 | - Updated composer version constraints to support newer versions of Magento. 12 | 13 | ## [1.0.1] - 2019-05-10 14 | 15 | ### Fixed 16 | - Fixes suggested by Magento Coding Standard. 17 | 18 | ## [1.0.0] - 2019-02-12 19 | 20 | ### Added 21 | - Initial release. 22 | -------------------------------------------------------------------------------- /Observer/SendOrderNotification.php: -------------------------------------------------------------------------------- 1 | clientFactory = $clientFactory; 44 | $this->logger = $logger; 45 | $this->scopeConfig = $scopeConfig; 46 | $this->encryptor = $encryptor; 47 | } 48 | 49 | /** 50 | * Send an order notification in response to an observer object containing an 'order' property. 51 | * 52 | * @param Observer $observer 53 | */ 54 | public function execute(Observer $observer) 55 | { 56 | if (!$this->getGeneralConfig('enabled')) { 57 | return; 58 | } 59 | 60 | $order = $observer->getData('order'); 61 | $client = $this->clientFactory->create([ 62 | 'username' => $this->getGeneralConfig('account_sid'), 63 | 'password' => $this->encryptor->decrypt($this->getGeneralConfig('auth_token')), 64 | ]); 65 | $params = [ 66 | 'from' => $this->getGeneralConfig('send_from_number'), 67 | 'body' => $this->getBody($order), 68 | ]; 69 | 70 | try { 71 | $client->messages->create($this->getGeneralConfig('send_to_number'), $params); 72 | } catch (\Exception $e) { 73 | $this->logger->critical('Error message', ['exception' => $e]); 74 | } 75 | } 76 | 77 | /** 78 | * Construct the message of the body to send from a given order object. 79 | * 80 | * @param $order 81 | * @return string 82 | */ 83 | public function getBody($order) 84 | { 85 | $incrementId = $order->getData('increment_id'); 86 | $shippingDescription = $order->getData('shipping_description'); 87 | $result = "New order: #$incrementId" . PHP_EOL; 88 | $result .= PHP_EOL; 89 | $result .= "Shipping method: $shippingDescription" . PHP_EOL; 90 | $result .= PHP_EOL; 91 | 92 | foreach ($order->getData('items') as $item) { 93 | $qty = $item->getData('qty_ordered'); 94 | $sku = $item->getData('sku'); 95 | $name = $item->getData('name'); 96 | $result .= "[$qty x $sku] $name" . PHP_EOL; 97 | } 98 | 99 | return $result; 100 | } 101 | 102 | /** 103 | * Get the scoped config value. 104 | * 105 | * @param $value 106 | * @return mixed 107 | */ 108 | public function getGeneralConfig($value) 109 | { 110 | return $this->scopeConfig->getValue( 111 | "markshust_twilio/general/$value", 112 | ScopeInterface::SCOPE_STORE 113 | ); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |