Skip to content

Commit

Permalink
Adds StoreID field to Added to Cart and Viewed Product events (#303)
Browse files Browse the repository at this point in the history
* updates storeId

* updates Changelog

* ECOS-6563
  • Loading branch information
cykolln authored Jun 13, 2024
1 parent b43e681 commit 5344d12
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
<!-- BEGIN RELEASE NOTES -->
### [Unreleased]

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

#### Changed
- Updates StoreId field to StoreID for Added to Cart events

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

#### Changed
Expand Down
4 changes: 2 additions & 2 deletions Cron/KlSyncs.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ private function sendUpdatesToApp(array $groupedRows, bool $isRetry = false)

//TODO: if conditional for backward compatibility, needs to be removed in future versions
$storeId = '';
if (isset($decodedPayload['StoreId'])) {
$storeId = $decodedPayload['StoreId'];
if (isset($decodedPayload['StoreID'])) {
$storeId = $decodedPayload['StoreID'];
}

$response = $this->_dataHelper->klaviyoTrackEvent(
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 Observer/SalesQuoteSaveAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function execute(Observer $observer)
// Setting QuoteId at this point since the MaskedQuoteId is not updated when this event is dispatched,
$klAddedToCartPayload['QuoteId'] = isset($encodedCustomerId) ? "kx_identifier_$encodedCustomerId" : $quote->getId();
// Setting StoreId in payload
$klAddedToCartPayload['StoreId'] = $quote->getStoreId();
$klAddedToCartPayload['StoreID'] = $quote->getStoreId();

$stringifiedPayload = json_encode($klAddedToCartPayload);

Expand Down

0 comments on commit 5344d12

Please sign in to comment.