Skip to content
This repository has been archived by the owner on Jun 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #9 from pmclain/feature/customer-address-management
Browse files Browse the repository at this point in the history
Feature/customer address management
  • Loading branch information
pmclain authored Jun 11, 2017
2 parents 82deddb + c1b4c20 commit da4143a
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 11 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,12 @@ In your Magento 2 root directory run:
Module settings are found in the Magento 2 admin panel under
Stores->Configuration->Sales->Sales SMS

## Customer Address Templates
If the system HTML Address Template has been edited the SMS notification value
will not appear in the customer dashboard address book. Add the following to
Stores->Configuration->Customer->Customer Configuration->Address Templates->HTML
where you wish this data to appear:
`{{depend sms_alert}}<br/>SMS Enabled: {{var sms_alert}}{{/depend}}`

## License
GNU GENERAL PUBLIC LICENSE Version 3
38 changes: 38 additions & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0"?>
<!--
/**
* Pmclain_Twilio extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the GPL v3 License
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://www.gnu.org/licenses/gpl.txt
*
* @category Pmclain
* @package Twilio
* @copyright Copyright (c) 2017
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<customer>
<address_templates>
<html><![CDATA[{{depend prefix}}{{var prefix}} {{/depend}}{{var firstname}} {{depend middlename}}{{var middlename}} {{/depend}}{{var lastname}}{{depend suffix}} {{var suffix}}{{/depend}}{{depend firstname}}<br/>{{/depend}}
{{depend company}}{{var company}}<br />{{/depend}}
{{if street1}}{{var street1}}<br />{{/if}}
{{depend street2}}{{var street2}}<br />{{/depend}}
{{depend street3}}{{var street3}}<br />{{/depend}}
{{depend street4}}{{var street4}}<br />{{/depend}}
{{if city}}{{var city}}, {{/if}}{{if region}}{{var region}}, {{/if}}{{if postcode}}{{var postcode}}{{/if}}<br/>
{{var country}}<br/>
{{depend telephone}}T: {{var telephone}}{{/depend}}
{{depend sms_alert}}<br/>SMS Enabled: {{var sms_alert}}{{/depend}}
{{depend fax}}<br/>F: {{var fax}}{{/depend}}
{{depend vat_id}}<br/>VAT: {{var vat_id}}{{/depend}}]]></html>
</address_templates>
</customer>
</default>
</config>
6 changes: 6 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ var config = {
'Magento_Checkout/js/action/set-shipping-information': {
'Pmclain_Twilio/js/action/set-shipping-information-mixin': true
},
'Magento_Checkout/js/action/create-shipping-address': {
'Pmclain_Twilio/js/action/create-shipping-address-mixin': true
},
'Magento_Checkout/js/action/create-billing-address': {
'Pmclain_Twilio/js/action/create-billing-address-mixin': true
},
'Magento_Checkout/js/action/place-order': {
'Pmclain_Twilio/js/action/place-order-mixin': true
},
'Magento_Customer/js/model/customer/address': {
'Pmclain_Twilio/js/model/customer/address-mixin': true
}
}
}
Expand Down
22 changes: 13 additions & 9 deletions view/frontend/web/js/action/create-billing-address-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,25 @@
*/

define([
'jquery',
'mage/utils/wrapper',
'Magento_Checkout/js/model/quote'
], function($, wrapper, quote) {
'mage/utils/wrapper'
], function(wrapper) {
'use strict';

return function (createBillingAddressAction) {
return wrapper.wrap(createBillingAddressAction, function(originalAction, addressData) {
var result = originalAction();
if(result['customAttributes'] === undefined) {
result['customAttributes'] = {};
if (addressData.custom_attributes === undefined) {
return originalAction();
}
result.customAttributes['sms_alert'] = addressData.sms_alert;

return result;
if (addressData.custom_attributes['sms_alert']) {
addressData.custom_attributes['sms_alert'] = {
'attribute_code': 'sms_alert',
'value': 'SMS Enabled',
'status': 1
}
}

return originalAction();
});
};
});
40 changes: 40 additions & 0 deletions view/frontend/web/js/action/create-shipping-address-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Pmclain_Twilio extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the GPL v3 License
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://www.gnu.org/licenses/gpl.txt
*
* @category Pmclain
* @package Twilio
* @copyright Copyright (c) 2017
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License
*/

define([
'jquery',
'mage/utils/wrapper'
], function($, wrapper) {
'use strict';

return function (createShippingAddressAction) {
return wrapper.wrap(createShippingAddressAction, function(originalAction, addressData) {
if (addressData.custom_attributes === undefined) {
return originalAction();
}

if (addressData.custom_attributes['sms_alert']) {
addressData.custom_attributes['sms_alert'] = {
'attribute_code': 'sms_alert',
'value': 'SMS Enabled',
'status': 1
}
}

return originalAction();
});
};
});
23 changes: 22 additions & 1 deletion view/frontend/web/js/action/place-order-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@ define([
return function (placeOrderAction) {
return wrapper.wrap(placeOrderAction, function(originalAction) {
var billingAddress = quote.billingAddress();

if(billingAddress.customAttributes === undefined) {
billingAddress.customAttributes = {};
}

if(billingAddress['extension_attributes'] === undefined) {
billingAddress['extension_attributes'] = {};
}

billingAddress['extension_attributes']['sms_alert'] = billingAddress.customAttributes['sms_alert'] ? 1 : 0;
try {
var smsStatus = billingAddress.customAttributes['sms_alert'].status;
var smsValue = billingAddress.customAttributes['sms_alert'].value;

//TODO: this smells. the check for status stems from an attempt to
// non-invasively display a user friendly custom attribute value in
// the customer address-mixin.
if(smsStatus == true) {
billingAddress['extension_attributes']['sms_alert'] = smsStatus;
}else if(smsValue == true) {
billingAddress['extension_attributes']['sms_alert'] = smsValue
}else {
billingAddress['extension_attributes']['sms_alert'] = false;
}
}catch (e) {
return originalAction();
}

return originalAction();
});
Expand Down
23 changes: 22 additions & 1 deletion view/frontend/web/js/action/set-shipping-information-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,32 @@ define([
return function (setShippingInformationAction) {
return wrapper.wrap(setShippingInformationAction, function(originalAction) {
var shippingAddress = quote.shippingAddress();

if(shippingAddress.customAttributes === undefined) {
shippingAddress.customAttributes = {};
}

if(shippingAddress['extension_attributes'] === undefined) {
shippingAddress['extension_attributes'] = {};
}

shippingAddress['extension_attributes']['sms_alert'] = shippingAddress.customAttributes['sms_alert'] ? 1 : 0;
try {
var smsStatus = shippingAddress.customAttributes['sms_alert'].status;
var smsValue = shippingAddress.customAttributes['sms_alert'].value;

//TODO: this smells. the check for status stems from an attempt to
// non-invasively display a user friendly custom attribute value in
// the customer address-mixin.
if(smsStatus == true) {
shippingAddress['extension_attributes']['sms_alert'] = smsStatus;
}else if(smsValue == true) {
shippingAddress['extension_attributes']['sms_alert'] = smsValue
}else {
shippingAddress['extension_attributes']['sms_alert'] = false;
}
}catch (e) {
return originalAction();
}

return originalAction();
});
Expand Down
39 changes: 39 additions & 0 deletions view/frontend/web/js/model/customer/address-mixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Pmclain_Twilio extension
*
* NOTICE OF LICENSE
*
* This source file is subject to the GPL v3 License
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://www.gnu.org/licenses/gpl.txt
*
* @category Pmclain
* @package Twilio
* @copyright Copyright (c) 2017
* @license https://www.gnu.org/licenses/gpl.txt GPL v3 License
*/

define([
'jquery',
'mage/utils/wrapper',
'mage/translate'
], function($, wrapper) {
'use strict';

return function (addressModel) {
return wrapper.wrap(addressModel, function(originalAction) {
var address = originalAction();

if(address.customAttributes !== undefined) {
if(address.customAttributes['sms_alert']) {
var enabled = address.customAttributes['sms_alert'].value;
address.customAttributes['sms_alert'].value = $.mage.__(enabled ? 'SMS Enabled' : 'SMS Disabled');
address.customAttributes['sms_alert'].status = enabled ? 1 : 0;
}
}

return address;
});
};
});

0 comments on commit da4143a

Please sign in to comment.