Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
romainruaud committed May 2, 2024
2 parents 8c17f0a + 7a79304 commit a191ce8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
44 changes: 36 additions & 8 deletions src/module-elasticsuite-tracker/Plugin/QuotePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@

namespace Smile\ElasticsuiteTracker\Plugin;

use \Magento\Quote\Model\Quote;
use \Magento\Catalog\Model\Product;
use \Magento\Catalog\Model\Product\Type\AbstractType;
use Magento\Framework\View\Layout\PageType\Config as PageTypeConfig;
use Magento\Quote\Model\Quote;

/**
* Log add to cart events into the event queue.
Expand All @@ -42,6 +41,11 @@ class QuotePlugin
*/
private $trackerHelper;

/**
* @var PageTypeConfig
*/
private $pageTypeConfig;

/**
* @var \Psr\Log\LoggerInterface
*/
Expand All @@ -50,20 +54,23 @@ class QuotePlugin
/**
* Constructor.
*
* @param \Smile\ElasticsuiteTracker\Api\CustomerTrackingServiceInterface $service Tracker service.
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager Cookie manager.
* @param \Smile\ElasticsuiteTracker\Helper\Data $trackerHelper Tracker helper.
* @param \Psr\Log\LoggerInterface $logger Logger.
* @param \Smile\ElasticsuiteTracker\Api\CustomerTrackingServiceInterface $service Tracker service.
* @param \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager Cookie manager.
* @param \Smile\ElasticsuiteTracker\Helper\Data $trackerHelper Tracker helper.
* @param \Magento\Framework\View\Layout\PageType\Config $pageTypeConfig The Page Type Configuration
* @param \Psr\Log\LoggerInterface $logger Logger.
*/
public function __construct(
\Smile\ElasticsuiteTracker\Api\CustomerTrackingServiceInterface $service,
\Magento\Framework\Stdlib\CookieManagerInterface $cookieManager,
\Smile\ElasticsuiteTracker\Helper\Data $trackerHelper,
\Magento\Framework\View\Layout\PageType\Config $pageTypeConfig,
\Psr\Log\LoggerInterface $logger
) {
$this->service = $service;
$this->cookieManager = $cookieManager;
$this->trackerHelper = $trackerHelper;
$this->pageTypeConfig = $pageTypeConfig;
$this->logger = $logger;
}

Expand Down Expand Up @@ -107,7 +114,10 @@ public function afterAddProduct(
*/
private function logEvent(int $productId, int $storeId): void
{
$pageData = [];
$pageData = [
'identifier' => 'checkout_cart_add',
'label' => stripslashes($this->getPageTypeLabel('checkout_cart_add')),
];
$pageData['store_id'] = $storeId;
$pageData['cart']['product_id'] = $productId;

Expand Down Expand Up @@ -144,4 +154,22 @@ private function readCookieValue($cookieName)
{
return $this->cookieManager->getCookie($cookieName);
}

/**
* Human readable version of the page type identifier.
*
* @param string $pageTypeIdentifier Page type identifier.
*
* @return string
*/
private function getPageTypeLabel($pageTypeIdentifier)
{
foreach ($this->pageTypeConfig->getPageTypes() as $identifier => $pageType) {
if ($pageTypeIdentifier === $identifier) {
return $pageType['label'];
}
}

return '';
}
}
4 changes: 4 additions & 0 deletions src/module-elasticsuite-tracker/etc/frontend/page_types.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0"?>
<page_types xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_types.xsd">
<type id="checkout_cart_add" label="Add Item to Cart"/>
</page_types>

0 comments on commit a191ce8

Please sign in to comment.