-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* client-side tracking events for cart, search and category pages * POS id optional field
- Loading branch information
1 parent
f446858
commit 6f92b91
Showing
20 changed files
with
797 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
namespace Remarkety\Mgconnector\Block\Adminhtml\Settings; | ||
|
||
use Magento\Framework\View\Element\Template; | ||
use Magento\Store\Model\StoreManager; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Remarkety\Mgconnector\Helper\ConfigHelper; | ||
use \Remarkety\Mgconnector\Model\Webtracking; | ||
use Magento\Customer\Model\Session; | ||
|
||
class Form extends \Magento\Framework\View\Element\Template { | ||
private $formKey; | ||
private $attributesCollection; | ||
private $configHelper; | ||
|
||
private $current_pos_id; | ||
private $event_cart_view; | ||
private $event_search_view; | ||
private $event_category_view; | ||
|
||
public function __construct( | ||
Template\Context $context, | ||
array $data, | ||
\Magento\Framework\Data\Form\FormKey $formKey, | ||
\Magento\Customer\Model\ResourceModel\Attribute\Collection $attributesCollection, | ||
ConfigHelper $configHelper | ||
) | ||
{ | ||
parent::__construct($context, $data); | ||
$this->formKey = $formKey; | ||
$this->attributesCollection = $attributesCollection; | ||
$this->configHelper = $configHelper; | ||
$this->current_pos_id = $configHelper->getPOSAttributeCode(); | ||
$this->event_cart_view = $configHelper->isEventCartViewEnabled(); | ||
$this->event_search_view = $configHelper->isEventSearchViewEnabled(); | ||
$this->event_category_view = $configHelper->isEventCategoryViewEnabled(); | ||
} | ||
|
||
public function getFormKey() | ||
{ | ||
return $this->formKey->getFormKey(); | ||
} | ||
|
||
public function getPosIdOptions(){ | ||
$attribute_data = []; | ||
foreach ($this->attributesCollection as $item) { | ||
$name = $item->getFrontendLabel(); | ||
if(empty($name)){ | ||
continue; | ||
} | ||
$attribute_data[$item->getAttributeCode()] = $name; | ||
} | ||
return $attribute_data; | ||
} | ||
|
||
public function getCurrentPOSCode(){ | ||
return $this->current_pos_id; | ||
} | ||
|
||
public function getEnabledDisabledOptions() { | ||
$attribute_data = []; | ||
|
||
$attribute_data[0] = 'Disable'; | ||
$attribute_data[1] = 'Enable'; | ||
|
||
return $attribute_data; | ||
} | ||
|
||
/** | ||
* @return int|mixed | ||
*/ | ||
public function getEventCartView() | ||
{ | ||
return $this->event_cart_view; | ||
} | ||
|
||
/** | ||
* @return int|mixed | ||
*/ | ||
public function getEventSearchView() | ||
{ | ||
return $this->event_search_view; | ||
} | ||
|
||
/** | ||
* @return int|mixed | ||
*/ | ||
public function getEventCategoryView() | ||
{ | ||
return $this->event_category_view; | ||
} | ||
} |
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,48 @@ | ||
<?php | ||
namespace Remarkety\Mgconnector\Block\Frontend\Tracking; | ||
|
||
use Magento\Catalog\Block\Category\View; | ||
use Magento\Store\Model\StoreManager; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Remarkety\Mgconnector\Helper\ConfigHelper; | ||
use \Remarkety\Mgconnector\Model\Webtracking; | ||
use Magento\Customer\Model\Session; | ||
|
||
class Category extends View { | ||
private $config_helper; | ||
private $category; | ||
|
||
public function __construct( | ||
\Magento\Framework\View\Element\Template\Context $context, | ||
\Magento\Catalog\Model\Layer\Resolver $layerResolver, | ||
\Magento\Framework\Registry $registry, | ||
\Magento\Catalog\Helper\Category $categoryHelper, | ||
array $data = [], | ||
ConfigHelper $config_helper | ||
) { | ||
parent::__construct($context, $layerResolver, $registry, $categoryHelper, $data); | ||
$this->config_helper = $config_helper; | ||
} | ||
|
||
public function isEventCategoryViewActivated() { | ||
return $this->config_helper->isEventCategoryViewEnabled(); | ||
} | ||
|
||
public function getCategoryId() { | ||
|
||
return $this->getCategory()->getId(); | ||
} | ||
|
||
public function getCategoryName() { | ||
|
||
return $this->getCategory()->getName(); | ||
} | ||
|
||
private function getCategory() { | ||
if (!$this->category) { | ||
$this->category = $this->getCurrentCategory(); | ||
} | ||
|
||
return $this->category; | ||
} | ||
} |
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,123 @@ | ||
<?php | ||
namespace Remarkety\Mgconnector\Block\Frontend\Tracking; | ||
|
||
use Magento\Checkout\Block\Cart; | ||
use Magento\Checkout\Controller\Cart\Index; | ||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use \Magento\Framework\Registry; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Store\Model\StoreManager; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Remarkety\Mgconnector\Helper\ConfigHelper; | ||
use Remarkety\Mgconnector\Helper\Recovery; | ||
use \Remarkety\Mgconnector\Model\Webtracking; | ||
use \Magento\Customer\Model\Session; | ||
use Magento\Catalog\Model\Product as MageProduct; | ||
|
||
class Quote extends \Magento\Framework\View\Element\Template { | ||
private $quote; | ||
private $checkout_session; | ||
private $recovery_helper; | ||
private $media_path; | ||
private $config_helper; | ||
|
||
public function __construct(Template\Context $context, | ||
\Magento\Checkout\Model\Session $checkoutSession, | ||
array $data = [], | ||
Recovery $recoveryHelper, | ||
ConfigHelper $configHelper) | ||
{ | ||
parent::__construct($context, $data); | ||
$this->checkout_session = $checkoutSession; | ||
$this->recovery_helper = $recoveryHelper; | ||
$this->config_helper = $configHelper; | ||
} | ||
|
||
public function isEventCartViewActivated() { | ||
return $this->config_helper->isEventCartViewEnabled(); | ||
} | ||
|
||
public function getCart() { | ||
if (empty($this->getQuote()) || empty($this->getQuote()->getId())) { | ||
return null; | ||
} | ||
|
||
$cart = [ | ||
'abandoned_checkout_url' => $this->recovery_helper->getCartRecoveryURL( | ||
$this->getQuote()->getId(), | ||
$this->getQuote()->getStore()->getId()), | ||
'created_at' => $this->getQuote()->getCreatedAt(), | ||
'currency' => $this->getQuote()->getQuoteCurrencyCode(), | ||
'id' => $this->getQuote()->getId(), | ||
'line_items' => $this->getQuoteItems(), | ||
'total_price' => floatval($this->getQuote()->getGrandTotal()), | ||
'subtotal' => floatval($this->getQuote()->getSubtotal()), | ||
'updated_at' => $this->getQuote()->getUpdatedAt() | ||
]; | ||
|
||
$address = $this->getQuote()->getShippingAddress(); | ||
if($address){ | ||
$shipping_amount = $address->getShippingAmount(); | ||
$cart['total_shipping'] = floatval($shipping_amount); | ||
} | ||
|
||
$coupon = $this->getQuote()->getCouponCode(); | ||
if(!empty($coupon)){ | ||
$coupon_discount = $this->getQuote()->getSubtotal() - $this->getQuote()->getSubtotalWithDiscount(); | ||
$cart['discount_codes'][] = [ | ||
'code' => $coupon, | ||
'amount' => $coupon_discount | ||
]; | ||
} | ||
|
||
return $cart; | ||
} | ||
|
||
private function getQuoteItems() { | ||
$items = $this->getQuote()->getItemsCollection(); | ||
$line_items = []; | ||
|
||
foreach ($items as $item) { | ||
if ($item->getProductType() === Configurable::TYPE_CODE) { | ||
continue; | ||
} | ||
|
||
$parent_item = $item->getParentItem(); | ||
|
||
$line_items[] = [ | ||
'product_id' => $item->getProductId(), | ||
'quantity' => $parent_item ? $parent_item->getQty() : $item->getQty(), | ||
'sku' => $item->getSku(), | ||
'title' => $item->getName(), | ||
'price' => $parent_item ? floatval($parent_item->getPriceInclTax()) : floatval($item->getPriceInclTax()), | ||
'taxable' => $item->getTaxPercent() > 0, | ||
'added_at' => $item->getCreatedAt(), | ||
'url' => $item->getProduct()->getProductUrl(), | ||
'image' => $this->getMediaPath() . $item->getProduct()->getThumbnail() | ||
]; | ||
} | ||
|
||
return $line_items; | ||
} | ||
|
||
private function getQuote() { | ||
if (!$this->quote) { | ||
$this->checkout_session->getQuote(); | ||
if (!$this->hasData('quote')) { | ||
$this->setData('quote', $this->checkout_session->getQuote()); | ||
} | ||
|
||
$this->quote = $this->_getData('quote'); | ||
} | ||
|
||
return $this->quote; | ||
} | ||
|
||
private function getMediaPath() { | ||
if (!$this->media_path) { | ||
$this->media_path = $this->getQuote()->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product'; | ||
} | ||
|
||
return $this->media_path; | ||
} | ||
} |
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,95 @@ | ||
<?php | ||
|
||
|
||
namespace Remarkety\Mgconnector\Block\Frontend\Tracking; | ||
|
||
|
||
use Magento\Catalog\Model\Layer\Resolver as LayerResolver; | ||
use Magento\CatalogSearch\Block\Result; | ||
use Magento\CatalogSearch\Helper\Data; | ||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use \Magento\Framework\Registry; | ||
use Magento\Search\Model\QueryFactory; | ||
use Magento\Store\Model\StoreManager; | ||
use Magento\Framework\View\Element\Template\Context; | ||
use Remarkety\Mgconnector\Helper\ConfigHelper; | ||
use \Remarkety\Mgconnector\Model\Webtracking; | ||
use \Magento\Customer\Model\Session; | ||
|
||
class Search extends Result | ||
{ | ||
private $term; | ||
private $media_path; | ||
private $config_helper; | ||
|
||
public function __construct( | ||
Context $context, | ||
LayerResolver $layerResolver, | ||
Data $catalogSearchData, | ||
QueryFactory $queryFactory, | ||
array $data = [], | ||
ConfigHelper $config_helper | ||
) { | ||
parent::__construct($context, $layerResolver, $catalogSearchData, $queryFactory, $data); | ||
$this->config_helper = $config_helper; | ||
} | ||
|
||
public function isEventSearchViewActivated() { | ||
return $this->config_helper->isEventSearchViewEnabled(); | ||
} | ||
|
||
public function getQueryTerm() { | ||
if (!$this->term) { | ||
$this->term = $this->catalogSearchData->getEscapedQueryText(); | ||
} | ||
|
||
return $this->term; | ||
} | ||
|
||
public function getResultProducts() { | ||
$data = []; | ||
$size = 3; | ||
|
||
foreach ($this->getProducts() as $entity) { | ||
if ($size > 0) { | ||
$size--; | ||
|
||
if($entity->getTypeId() == Configurable::TYPE_CODE){ | ||
$full_price = $entity->getMinimalPrice(); | ||
$price = $entity->getMinimalPrice(); | ||
} else { | ||
$full_price = $entity->getFinalPrice(); | ||
$price = $entity->getPrice(); | ||
} | ||
|
||
$data[] = [ | ||
'product_id' => $entity->getId(), | ||
'title' => $entity->getName(), | ||
'image' => $this->getMediaPath($entity) . $entity->getThumbnail(), | ||
'full_price' => floatval($full_price), | ||
'price' => floatval($price), | ||
'url' => $entity->getProductUrl() | ||
]; | ||
} else { | ||
break; | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
private function getProducts() { | ||
$layout = $this->getLayout()->getBlock('search_result_list'); | ||
$product_collection = $layout->getLoadedProductCollection(); | ||
|
||
return $product_collection; | ||
} | ||
|
||
private function getMediaPath($entity) { | ||
if (!$this->media_path) { | ||
$this->media_path = $entity->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . 'catalog/product'; | ||
} | ||
|
||
return $this->media_path; | ||
} | ||
} |
Oops, something went wrong.