Skip to content

Commit

Permalink
202112 test develop with master (#150)
Browse files Browse the repository at this point in the history
* use magento URL builder to build URLs

* remove reference to _learnq.identify().email

* changelog update

* Remove the slash

* code cleanup

* update in version

* Changes to inject objects directly instead of ObjectManager

* formatting change

* adding rebased changes

* 202111 update sms consent lang (#145)

* Update sms consent default language

* Version bump

* version bump

Co-authored-by: Nate Paradis <[email protected]>
Co-authored-by: Nate Paradis <[email protected]>
Co-authored-by: klaviyojad <[email protected]>
Co-authored-by: klaviyojad <[email protected]>
Co-authored-by: Claire Kolln (Success Eng) <[email protected]>
  • Loading branch information
6 people authored Dec 15, 2021
1 parent c3a9261 commit 61e629a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 26 deletions.
26 changes: 23 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### [Unreleased]

### [4.0.0-beta] - 2021-12-15

#### Added
- Added to Cart metric collection

### [3.0.10] - 2021-11-10

#### Changed
- SMS Consent default language

### [3.0.9] - 2021-09-21

#### Fixed
- SMS Consent checkbox for logged in users with default address set
- URL construction works when store URL has subdirectories
- Remove reference to deprecated _learnq functionality

### [3.0.8] - 2021-09-02

#### Fixed
Expand All @@ -14,7 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### [3.0.7] - 2021-08-27

#### Fixed
- Right trim trailing slash from Custom Media Url setting from Klaviyo Extension
- Right trim trailing slash from Custom Media Url setting from Klaviyo Extension
- Properly escape the public api for onsite tag
- Handle newsletter subscriptions in all areas
- Fixing bug with newsletter subscribes for anonymous users (not registered accounts)
Expand Down Expand Up @@ -62,7 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### [3.0.0] - 2021-05-25

#### Added
- Only support Magento 2.3.* +
- Only support Magento 2.3.* +

#### Fixed
- Utilize masked quote ids.
Expand Down Expand Up @@ -122,7 +139,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- CSP now uses report-only mode


[Unreleased]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.8...HEAD
[Unreleased]: https://github.com/klaviyo/magento2-klaviyo/compare/4.0.0-beta...HEAD
[4.0.0-beta]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.10...4.0.0-beta
[3.0.10]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.9...3.0.10
[3.0.9]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.8...3.0.9
[3.0.8]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.7...3.0.8
[3.0.7]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.6...3.0.7
[3.0.6]: https://github.com/klaviyo/magento2-klaviyo/compare/3.0.5...3.0.6
Expand Down
58 changes: 51 additions & 7 deletions Plugin/CheckoutLayoutPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,37 @@
namespace Klaviyo\Reclaim\Plugin;

use Klaviyo\Reclaim\Helper\ScopeSetting;
use Magento\Customer\Model\CustomerFactory;
use Magento\Customer\Model\Session;


class CheckoutLayoutPlugin
{
public function __construct(
ScopeSetting $klaviyoScopeSetting
ScopeSetting $klaviyoScopeSetting,
Session $customerSession,
CustomerFactory $customerFactory
) {
$this->_klaviyoScopeSetting = $klaviyoScopeSetting;
$this->_customerSession = $customerSession;
$this->_customerFactory = $customerFactory;
}

/**
* Checks if logged in user has a default address set, if not returns false.
*
* @return Magento\Customer\Model\Address|false
*/
public function _getDefaultAddressIfSetForCustomer()
{
$address = false;
if ($this->_customerSession->isLoggedIn()) {
$customerData = $this->_customerSession->getCustomer()->getData();
$customerId = $customerData["entity_id"];
$customer = $this->_customerFactory->create()->load($customerId);
$address = $customer->getDefaultShippingAddress();
}
return $address;
}

public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $processor, $jsLayout)
Expand All @@ -38,14 +61,35 @@ public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $p
'id' => 'kl_sms_consent',
];

$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['kl_sms_consent'] = $smsConsentCheckbox;
$address = $this->_getDefaultAddressIfSetForCustomer();

if (!$address)
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children']['kl_sms_consent'] = $smsConsentCheckbox;
else {

// extra un-editable field with saved phone number to display to logged in users with default address set
$smsConsentTelephone = [
'component' => 'Magento_Ui/js/form/element/abstract',
'config' =>
[
'customScope' => 'shippingAddress',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/input',
],
'label' => 'Phone Number',
'provider' => 'checkoutProvider',
'sortOrder' => '120',
'disabled' => true,
'visible' => true,
'value' => $address->getTelephone()
];

$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['before-form']['children']['kl_sms_phone_number'] = $smsConsentTelephone;
$jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['before-form']['children']['kl_sms_consent'] = $smsConsentCheckbox;
}
}
// Open to ideas here, since we don't overwrite the customer-email section
// we need to distinguish if the customer is logged in or not, object manager is an easy way to do so
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');

if (!$customerSession->isLoggedIn() && $this->_klaviyoScopeSetting->getConsentAtCheckoutEmailIsActive())
if (!$this->_customerSession->isLoggedIn() && $this->_klaviyoScopeSetting->getConsentAtCheckoutEmailIsActive())
{
$emailConsentCheckbox = [
'component' => 'Magento_Ui/js/form/element/abstract',
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "klaviyo/magento2-extension",
"description": "Klaviyo extension for Magento 2. Allows pushing newsletters to Klaviyo's platform and more.",
"type": "magento2-module",
"version": "3.0.8",
"version": "4.0.0-beta",
"autoload": {
"files": [
"registration.php"
Expand Down
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</klaviyo_reclaim_consent_at_checkout>
<klaviyo_reclaim_consent_at_checkout>
<sms_consent>
<consent_text>**By checking this box and entering your phone number above, you consent to receive marketing text messages at the number provided from [company name], including messages sent by autodialer. Consent is not a condition of any purchase. Message and data rates may apply. Message frequency varies. Reply HELP for help or STOP to cancel. View our Privacy Policy and Terms of Service.</consent_text>
<consent_text>**By checking this box and entering your phone number above, you consent to receive marketing text messages (such as [promotion codes] and [cart reminders]) from [company name] at the number provided, including messages sent by autodialer. Consent is not a condition of any purchase. Message and data rates may apply. Message frequency varies. You can unsubscribe at any time by replying STOP or clicking the unsubscribe link (where available) in one of our messages. View our Privacy Policy [link] and Terms of Service [link].</consent_text>
</sms_consent>
</klaviyo_reclaim_consent_at_checkout>
<klaviyo_reclaim_consent_at_checkout>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Klaviyo_Reclaim" setup_version="3.0.8" schema_version="3.0.8">
<module name="Klaviyo_Reclaim" setup_version="4.0.0-beta" schema_version="4.0.0-beta">
<sequence>
<module name="Magento_Customer"/>
<module name="Magento_Checkout"/>
Expand Down
7 changes: 4 additions & 3 deletions view/frontend/templates/checkout/cart.phtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php if ( $this->isKlaviyoEnabled() && $this->getPublicApiKey() ): ?>
<script>
require([
'jquery'
], function (jQuery) {
'jquery',
'mage/url'
], function (jQuery, url) {
jQuery.ajax({
url: window.location.protocol + '//' + window.location.hostname + '/reclaim/checkout/reload',
url: url.build('reclaim/checkout/reload'),
method: 'POST',
data: {}
});
Expand Down
14 changes: 4 additions & 10 deletions view/frontend/web/js/view/checkout/email.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
define([
'uiComponent',
'mage/url',
'jquery',
'domReady!'
], function (Component, $) {
], function (Component, url, $) {
'use strict';
// initialize the customerData prior to returning the component
var _klaviyoCustomerData = window.customerData;
Expand Down Expand Up @@ -41,7 +42,7 @@ define([
}

self._email = jQuery(this).val();
if (!window._learnq.identify().email) {
if (!window._learnq.isIdentified()) {
window._learnq.push(['identify', {
'$email': self._email
}]);
Expand All @@ -50,15 +51,8 @@ define([
});
},
postUserEmail: function (customer_email) {
var path = window.location.pathname;
if (path.slice(-1) == '/') {
path = path.slice(0, -1);
}

var url = window.location.protocol + '//' + window.location.host + path.substring(0, path.lastIndexOf("/"));

$.ajax({
url: url + '/reclaim/checkout/email',
url: url.build('reclaim/checkout/email'),
method: 'POST',
data: {
'email': customer_email
Expand Down

0 comments on commit 61e629a

Please sign in to comment.