Skip to content

Commit

Permalink
M2 Version 4.2.0 release (#310)
Browse files Browse the repository at this point in the history
* updates M2 klaviyo.js url

* Fixes Area Code is already set bug

* updates changelog

* Adds Viewed Product storeId field
  • Loading branch information
cykolln authored Sep 24, 2024
1 parent 81db8a1 commit 10b5c10
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 17 deletions.
6 changes: 4 additions & 2 deletions Block/Catalog/Product/ViewedProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public function getViewedProductJson()
'URL' => $_product->getProductUrl(),
'Price' => $this->getPrice(),
'FinalPrice' => $this->getFinalPrice(),
'Categories' => $this->getProductCategories()
'Categories' => $this->getProductCategories(),
'StoreId' => $this->_klaviyoScopeSetting->storeId
];

if ($this->getProductImage()) {
Expand All @@ -224,7 +225,8 @@ public function getViewedItemJson()
'Categories' => $this->getProductCategories(),
'Metadata' => array(
'Price' => $this->getPrice()
)
),
'StoreId' => $this->_klaviyoScopeSetting->storeId
];

if ($this->getProductImage()) {
Expand Down
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- BEGIN RELEASE NOTES -->
### [Unreleased]

### [4.2.0] - 2024-09-17

#### Added
- Adds StoreId field to Viewed Product events

#### Changed
- Updated the klaviyo onsite javascript to the new url format

#### Fixed
- Removes call to isLoggerEnabled() in Logger __construct to address "Area Code is already set" issue when running consumer-based jobs

### [4.1.4] - 2024-05-22

#### Changed
Expand Down Expand Up @@ -287,7 +298,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- END RELEASE NOTES -->
<!-- BEGIN LINKS -->
[Unreleased]: https://github.com/klaviyo/magento2-klaviyo/compare/4.1.4...HEAD
[Unreleased]: https://github.com/klaviyo/magento2-klaviyo/compare/4.2.0...HEAD
[4.2.0]: https://github.com/klaviyo/magento2-klaviyo/compare/4.1.4...4.2.0
[4.1.4]: https://github.com/klaviyo/magento2-klaviyo/compare/4.1.3...4.1.4
[4.1.3]: https://github.com/klaviyo/magento2-klaviyo/compare/4.1.2...4.1.3
[4.1.2]: https://github.com/klaviyo/magento2-klaviyo/compare/4.1.1...4.1.2
Expand Down
10 changes: 5 additions & 5 deletions Helper/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class Logger
protected $_klaviyoLogger;

/**
* is the logger enabled?
* @var boolean
* Klaviyo Scope setting Helper
* @var ScopeSetting
*/
protected $_loggerEnabled;
protected $_scopeSetting;

public function __construct(
DirectoryList $dir,
Expand All @@ -41,7 +41,7 @@ public function __construct(
) {
$this->_dir = $dir;
$this->_klaviyoLogger = $klaviyoLogger;
$this->_loggerEnabled = $klaviyoScopeSetting->isLoggerEnabled();
$this->_scopeSetting = $klaviyoScopeSetting;
$this->_logPath = (!empty($logPath)) ? $logPath : $this->_dir->getPath('log') . '/klaviyo.log';
}

Expand All @@ -60,7 +60,7 @@ public function getPath()
*/
public function log($message)
{
if ($this->_loggerEnabled) {
if ($this->_scopeSetting->isLoggerEnabled()) {
$this->_klaviyoLogger->info($message);
}
}
Expand Down
8 changes: 4 additions & 4 deletions Helper/ScopeSetting.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ScopeSetting extends \Magento\Framework\App\Helper\AbstractHelper
/**
* @var int
*/
protected $_storeId;
public $storeId;

/**
* @var \Magento\Framework\Module\ModuleListInterface
Expand All @@ -75,7 +75,7 @@ public function __construct(
$this->_scopeConfig = $context->getScopeConfig();
$this->_request = $context->getRequest();
$this->_state = $state;
$this->_storeId = $storeManager->getStore()->getId();
$this->storeId = $storeManager->getStore()->getId();
$this->_moduleList = $moduleList;
$this->_configWriter = $configWriter;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ protected function getScopeSetting($path, $storeId = null)
$scopedWebsiteCode = $this->_request->getParam('website');
} else {
// In frontend area. Only concerned with store for frontend.
$scopedStoreCode = $this->_storeId;
$scopedStoreCode = $this->storeId;
}

if (isset($scopedStoreCode)) {
Expand Down Expand Up @@ -142,7 +142,7 @@ protected function setScopeSetting($path, $value)
$scopedWebsiteCode = $this->_request->getParam('website');
} else {
// In frontend area. Only concerned with store for frontend.
$scopedStoreCode = $this->_storeId;
$scopedStoreCode = $this->storeId;
}

if (isset($scopedStoreCode)) {
Expand Down
2 changes: 1 addition & 1 deletion composer.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "klaviyo/magento2-extension-dev",
"description": "The local development composer file. This is used for local and continuous integration setup/testing.",
"type": "magento2-module",
"version": "4.1.4",
"version": "4.2.0",
"autoload": {
"psr-4": {
"Klaviyo\\Reclaim\\": ""
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": "4.1.4",
"version": "4.2.0",
"autoload": {
"files": [
"registration.php"
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="4.1.4" schema_version="4.1.4">
<module name="Klaviyo_Reclaim" setup_version="4.2.0" schema_version="4.2.0">
<sequence>
<module name="Magento_Customer"/>
<module name="Magento_Checkout"/>
Expand Down
5 changes: 3 additions & 2 deletions view/frontend/templates/analytics/initialize.phtml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php $klaviyoKey = $this->getPublicApiKey(); ?>
<?php if ( $this->isKlaviyoEnabled() && $klaviyoKey ): ?>
<script type="application/javascript" async
src="https://static.klaviyo.com/onsite/js/klaviyo.js?company_id=<?= $block->escapeHtml($klaviyoKey); ?>"></script>
<?php $escapedKey = $block->escapeHtml($klaviyoKey); $klaviyoSrc = 'https://static.klaviyo.com/onsite/js/'. $escapedKey . '/klaviyo.js'?>
<script type="application/javascript" async
src=<?php echo $klaviyoSrc ?> ></script>

<script type="text/x-magento-init">
{
Expand Down

0 comments on commit 10b5c10

Please sign in to comment.