-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from stape-io/feature/hyva-support
Implemented Hyva compatibility
- Loading branch information
Showing
16 changed files
with
314 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# Changelog | ||
v1.0.17 | ||
- Hyva theme compatibility added. | ||
|
||
v1.0.16 | ||
- acl.xml added. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace Stape\Gtm\Model\Data; | ||
|
||
interface DataProviderInterface | ||
{ | ||
public function get(); | ||
public function add($eventName, $data); | ||
public function clear(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Stape\Gtm\Model\Data; | ||
|
||
class SessionDataProvider implements DataProviderInterface | ||
{ | ||
|
||
private $checkoutSession; | ||
|
||
/** | ||
* Define class dependencies | ||
* | ||
* @param \Magento\Checkout\Model\Session $checkoutSession | ||
*/ | ||
public function __construct(\Magento\Checkout\Model\Session $checkoutSession) | ||
{ | ||
$this->checkoutSession = $checkoutSession; | ||
} | ||
|
||
/** | ||
* Retrieve Stape GTM events data | ||
* | ||
* @return array | ||
*/ | ||
public function get() | ||
{ | ||
return $this->checkoutSession->getStapeGtmEvents() ?? []; | ||
} | ||
|
||
/** | ||
* Add gtm events data | ||
* | ||
* @param string $eventName | ||
* @param array $data | ||
* @return void | ||
*/ | ||
public function add($eventName, $data) | ||
{ | ||
$gtmEvents = $this->get(); | ||
$gtmEvents[$eventName] = $data; | ||
$this->checkoutSession->setStapeGtmEvents($gtmEvents); | ||
} | ||
|
||
/** | ||
* Clear gtm events | ||
* | ||
* @return void | ||
*/ | ||
public function clear() | ||
{ | ||
$this->checkoutSession->setStapeGtmEvents([]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace Stape\Gtm\Observer; | ||
|
||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\Event\Observer; | ||
use Magento\Framework\Event\ObserverInterface; | ||
use Magento\Framework\Pricing\PriceCurrencyInterface; | ||
use Stape\Gtm\Model\ConfigProvider; | ||
use Stape\Gtm\Model\Data\DataProviderInterface; | ||
use Stape\Gtm\Model\Product\CategoryResolver; | ||
|
||
class AddToCartComplete implements ObserverInterface | ||
{ | ||
|
||
/** | ||
* @var CategoryResolver $categoryResolver | ||
*/ | ||
private $categoryResolver; | ||
|
||
/** | ||
* @var Session $checkoutSession | ||
*/ | ||
private $checkoutSession; | ||
|
||
/** | ||
* @var ConfigProvider $configProvider | ||
*/ | ||
private $configProvider; | ||
|
||
/** | ||
* @var DataProviderInterface $dataProvider | ||
*/ | ||
private $dataProvider; | ||
|
||
/** | ||
* @var PriceCurrencyInterface $priceCurrency | ||
*/ | ||
private $priceCurrency; | ||
|
||
/** | ||
* Define class dependencies | ||
* | ||
* @param CategoryResolver $categoryResolver | ||
* @param Session $checkoutSession | ||
* @param ConfigProvider $configProvider | ||
* @param DataProviderInterface $dataProvider | ||
* @param PriceCurrencyInterface $priceCurrency | ||
*/ | ||
public function __construct( | ||
CategoryResolver $categoryResolver, | ||
Session $checkoutSession, | ||
ConfigProvider $configProvider, | ||
DataProviderInterface $dataProvider, | ||
PriceCurrencyInterface $priceCurrency | ||
) { | ||
$this->categoryResolver = $categoryResolver; | ||
$this->checkoutSession = $checkoutSession; | ||
$this->configProvider = $configProvider; | ||
$this->dataProvider = $dataProvider; | ||
$this->priceCurrency = $priceCurrency; | ||
} | ||
|
||
/** | ||
* Execute observer logic | ||
* | ||
* @param Observer $observer | ||
* @return void | ||
*/ | ||
public function execute(Observer $observer) | ||
{ | ||
if (!$this->configProvider->isActive()) { | ||
return; | ||
} | ||
|
||
/** @var \Magento\Catalog\Model\Product $product */ | ||
$product = $observer->getData('product'); | ||
|
||
/** @var \Magento\Quote\Model\Quote\Item $quote */ | ||
$quoteItem = $this->checkoutSession->getQuote()->getItemByProduct($product); | ||
|
||
$qty = (int)$observer->getData('request')->getParam('qty'); | ||
if ($qty === 0) { | ||
$qty = 1; | ||
} | ||
$category = $this->categoryResolver->resolve($product); | ||
$this->dataProvider->add('add_to_cart_stape', [ | ||
'currency' => $this->checkoutSession->getQuote()->getBaseCurrencyCode(), | ||
'items' => [ | ||
[ | ||
'item_name' => $product->getName(), | ||
'item_id' => $product->getId(), | ||
'item_sku' => $product->getSku(), | ||
'item_category' => $category ? $category->getName() : null, | ||
'price' => $this->priceCurrency->round($quoteItem->getBasePriceInclTax()), | ||
'quantity' => $qty, | ||
'variation_id' => $quoteItem->getHasChildren() ? current($quoteItem->getChildren())->getProductId() : null | ||
] | ||
] | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Stape\Gtm\Plugin\CustomerData; | ||
|
||
use Stape\Gtm\Model\Data\DataProviderInterface; | ||
|
||
class CartPlugin | ||
{ | ||
/** | ||
* @var DataProviderInterface | ||
*/ | ||
private $dataProvider; | ||
|
||
/** | ||
* @param DataProviderInterface $dataProvider | ||
*/ | ||
public function __construct(DataProviderInterface $dataProvider) | ||
{ | ||
$this->dataProvider = $dataProvider; | ||
} | ||
|
||
/** | ||
* Add stape_gtm_events data to the cart section data | ||
* | ||
* @param $subject | ||
* @param $result | ||
* @return mixed | ||
*/ | ||
public function afterGetSectionData($subject, $result) | ||
{ | ||
$eventsData = $this->dataProvider->get(); | ||
$this->dataProvider->clear(); | ||
|
||
if (!empty($eventsData)) { | ||
$result['stape_gtm_events'] = $eventsData; | ||
} | ||
|
||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Stape\Gtm\ViewModel; | ||
|
||
interface DatalayerInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getJson(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0"?> | ||
|
||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> | ||
<event name="checkout_cart_add_product_complete"> | ||
<observer name="stape_gtm_checkout_cart_add_product_complete" instance="Stape\Gtm\Observer\AddToCartComplete" /> | ||
</event> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0"?> | ||
|
||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="stape.gtm" template="Stape_Gtm::hyva/html/gtm.phtml" /> | ||
</body> | ||
</page> |
Oops, something went wrong.