Skip to content

Commit

Permalink
Fis styling
Browse files Browse the repository at this point in the history
  • Loading branch information
ah-net committed Dec 10, 2024
1 parent 696c2f0 commit 11ec0a6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Controller/Ajax/Analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function execute()
{
$result = $this->resultJsonFactory->create();
if ($this->config->isAnalyticsEnabled()) {

$type = $this->getRequest()->getParam('type');
$profileKey = $this->config->getProfileKey();

Expand All @@ -63,6 +62,7 @@ public function execute()
$result->setData(['success' => false, 'message' => $e->getMessage()]);
}
}

return $result;
}
}
16 changes: 16 additions & 0 deletions Model/Client/Request/AnalyticsRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,49 @@ class AnalyticsRequest extends Request

protected $apiUrl = 'https://navigator-analytics.tweakwise.com/api';

/**
* @return string
*/
public function isPostRequest()
{
return true;
}

/**
* @return string
*/
public function getApiurl()
{
return $this->apiUrl;
}

/**
* @return string
*/
public function setProfileKey(string $profileKey)
{
$this->setParameter('ProfileKey', $profileKey);
}

/**
* @return string
*/
public function setPath($path)
{
$this->path = $path;
}

/**
* @return string
*/
public function getProfileKey()
{
$profileKey = $this->getCookie($this->config->getPersonalMerchandisingCookieName());
if (!$profileKey) {
$profileKey = $this->generateProfileKey();
$this->setCookie('profileKey', $profileKey);
}

return $profileKey;
}
}
15 changes: 12 additions & 3 deletions Model/PersonalMerchandisingConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function __construct(
private CookieManagerInterface $cookieManager,
private CookieMetadataFactory $cookieMetadataFactory
) {
parent::__construct($config, $jsonSerializer, $request, $state,
$configWriter, $cacheTypeList);
parent::__construct($config, $jsonSerializer, $request, $state, $configWriter, $cacheTypeList);
}

/**
Expand All @@ -36,14 +35,17 @@ public function isAnalyticsEnabled(Store $store = null)
return (bool)$this->getStoreConfig('tweakwise/personal_merchandising/analytics_enabled', $store);
}

/**
* @return string|null
*/
public function getProfileKey()
{
$profileKey = $this->cookieManager->getCookie(
$this->getPersonalMerchandisingCookieName(),
null
);

if($this->isAnalyticsEnabled()) {
if ($this->isAnalyticsEnabled()) {
if ($profileKey === null) {
$profileKey = $this->generateProfileKey();
$this->cookieManager->setPublicCookie(
Expand All @@ -53,9 +55,13 @@ public function getProfileKey()
);
}
}

return $profileKey;
}

/**
* @return string
*/
private function getCookieMetadata()
{
return $this->cookieMetadataFactory
Expand All @@ -65,6 +71,9 @@ private function getCookieMetadata()
->setSecure(true);
}

/**
* @return string
*/
private function generateProfileKey()
{
return uniqid('', true);
Expand Down
3 changes: 1 addition & 2 deletions Observer/TweakwiseCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class TweakwiseCheckout implements ObserverInterface
* @param Helper $helper
* @param StoreManagerInterface $storeManager
* @param PersonalMerchandisingConfig $config
* @param CookieManagerInterface $cookieManager
*/
public function __construct(
private readonly RequestFactory $requestFactory,
Expand All @@ -51,7 +50,6 @@ public function execute(Observer $observer)
$items = $order->getAllItems();

$this->sendCheckout($items);

}
}

Expand Down Expand Up @@ -79,6 +77,7 @@ private function sendCheckout($items)
try {
$this->client->request($tweakwiseRequest);
} catch (\Exception $e) {
// @phpcs:ignore
// Do nothing
}
}
Expand Down
8 changes: 1 addition & 7 deletions view/frontend/templates/product/page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@

use Magento\Framework\Escaper;

$tweakwiseCookieName = $block->getCookieName();
$apiUrl = $block->getApiUrl();
$productKey = $block->getProductKey();
$instanceKey = $block->getInstanceKey();
?>

<script type="text/x-magento-init">
{
"*": {
"Tweakwise_Magento2Tweakwise/js/product-page": {
"apiUrl": "<?= $escaper->escapeUrl($apiUrl); ?>pageview",
"tweakwiseCookieName": "<?= $escaper->escapeHtmlAttr($tweakwiseCookieName); ?>",
"productKey": "<?= $escaper->escapeHtmlAttr($productKey); ?>",
"instanceKey": "<?= $escaper->escapeHtmlAttr($instanceKey); ?>"
"productKey": "<?= $escaper->escapeHtmlAttr($productKey); ?>"
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions view/frontend/templates/search/page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@
use Magento\Framework\Escaper;

/** @var \Tweakwise\Magento2Tweakwise\Block\Catalog\PersonalMerchandisingAnalytics $block */
/** @var Escaper $escaper */
$tweakwiseCookieName = $block->getCookieName();
$apiUrl = $block->getApiUrl();

$searchQuery = $block->getSearchQuery();
$instanceKey = $block->getInstanceKey();
?>

<script type="text/x-magento-init">
{
"*": {
"Tweakwise_Magento2Tweakwise/js/search-page": {
"apiUrl": "<?= $escaper->escapeUrl($apiUrl); ?>search",
"tweakwiseCookieName": "<?= $escaper->escapeHtmlAttr($tweakwiseCookieName); ?>",
"searchQuery": "<?= $escaper->escapeHtmlAttr($searchQuery); ?>",
"instanceKey": "<?= $escaper->escapeHtmlAttr($instanceKey); ?>"
"instanceKey": "<?= $escaper->escapeHtmlAttr($instanceKey); ?>"
}
}
}
Expand Down

0 comments on commit 11ec0a6

Please sign in to comment.