-
Notifications
You must be signed in to change notification settings - Fork 117
Update search-insights and compatibility #1129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
54af3cf
update search-insights version and update click analytics file to be …
bsuravech f86bbcb
Merge branch 'develop' into update-search-insights
bsuravech a9836e2
update search-insights.js to v1.3.0
bsuravech 37d065b
fix: add conversion sending from url params
tkrugg 450a668
add order conversion logic to insights
bsuravech b121c29
clean up for styling and logging
bsuravech 588f8cb
updates from review
bsuravech 2212a79
update the controller observer for parameter check and add insights U…
bsuravech b8d3209
unify indexName parameter key
bsuravech 280d52e
psr spacing
bsuravech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
app/code/community/Algolia/Algoliasearch/Block/Checkout/Success/Conversion.php
This file contains hidden or 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,46 @@ | ||
<?php | ||
|
||
class Algolia_Algoliasearch_Block_Checkout_Success_Conversion extends Mage_Core_Block_Template | ||
{ | ||
/** @var Mage_Sales_Model_Order */ | ||
protected $_order; | ||
|
||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
|
||
if ($orderId = Mage::getSingleton('checkout/session')->getLastOrderId()) { | ||
$this->_order = Mage::getModel('sales/order')->load($orderId); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOrderItemsConversionJson() | ||
{ | ||
$orderItemsData = array(); | ||
$orderItems = $this->_order->getAllVisibleItems(); | ||
|
||
/** @var Item $item */ | ||
foreach ($orderItems as $item) { | ||
if ($item->getData('algoliasearch_query_param') !== '') { | ||
$orderItemsData[$item->getProductId()] = json_decode($item->getData('algoliasearch_query_param')); | ||
} | ||
} | ||
|
||
return Mage::helper('core')->jsonEncode($orderItemsData); | ||
} | ||
|
||
public function _toHtml() | ||
{ | ||
if ($this->_order | ||
&& Mage::helper('algoliasearch/config')->isClickConversionAnalyticsEnabled($this->_order->getStoreId()) | ||
&& Mage::helper('algoliasearch/config')->getConversionAnalyticsMode($this->_order->getStoreId()) === 'place_order' | ||
) { | ||
return parent::_toHtml(); | ||
} | ||
|
||
return ''; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
app/code/community/Algolia/Algoliasearch/Model/Observer/Conversion.php
This file contains hidden or 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,80 @@ | ||
<?php | ||
|
||
class Algolia_Algoliasearch_Model_Observer_Conversion | ||
{ | ||
protected $_analyticsParams = array( | ||
'queryID', | ||
'indexName', | ||
'objectID', | ||
); | ||
|
||
/** | ||
* @param null $storeId | ||
* @return bool | ||
*/ | ||
protected function _isOrderConversionTrackingEnabled($storeId = null) | ||
{ | ||
return Mage::helper('algoliasearch/config')->isClickConversionAnalyticsEnabled($storeId) | ||
&& Mage::helper('algoliasearch/config')->getConversionAnalyticsMode($storeId) === 'place_order'; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
* @return bool | ||
*/ | ||
protected function _hasRequiredParameters($params = array()) | ||
{ | ||
foreach ($this->_analyticsParams as $requiredParam) { | ||
if (!isset($params[$requiredParam])) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @event catalog_controller_product_init_before | ||
*/ | ||
public function setAlgoliaParamsToSession(Varien_Event_Observer $observer) | ||
{ | ||
$checkoutSession = Mage::getSingleton('checkout/session'); | ||
if (!$this->_isOrderConversionTrackingEnabled($checkoutSession->getQuote()->getStoreId())) { | ||
return; | ||
} | ||
|
||
/** @var Mage_Core_Controller_Front_Action $controllerAction */ | ||
$controllerAction = $observer->getEvent()->getControllerAction(); | ||
$params = $controllerAction->getRequest()->getParams(); | ||
|
||
if (!$this->_hasRequiredParameters($params)) { | ||
return; | ||
} | ||
|
||
$conversionData = array( | ||
'queryID' => $params['queryID'], | ||
'indexName' => $params['indexName'], | ||
'objectID' => $params['objectID'], | ||
); | ||
|
||
$session = Mage::getSingleton('core/session', array('name' => 'frontend')); | ||
$session->setData('algolia_conversion_parameters', Mage::helper('core')->jsonEncode($conversionData)); | ||
} | ||
|
||
/** | ||
* @event checkout_cart_product_add_after | ||
*/ | ||
public function saveAlgoliaParamToQuoteItem(Varien_Event_Observer $observer) | ||
{ | ||
/** @var Mage_Sales_Model_Quote_Item $quoteItem */ | ||
$quoteItem = $observer->getEvent()->getQuoteItem(); | ||
/** @var Mage_Catalog_Model_Product $product */ | ||
$product = $observer->getEvent()->getProduct(); | ||
|
||
if ($this->_isOrderConversionTrackingEnabled($product->getStoreId())) { | ||
$session = Mage::getSingleton('core/session'); | ||
$quoteItem->setData('algoliasearch_query_param', $session->getData('algolia_conversion_parameters')); | ||
$session->unsetData('algolia_conversion_parameters'); | ||
} | ||
} | ||
} |
This file contains hidden or 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
28 changes: 28 additions & 0 deletions
28
.../community/Algolia/Algoliasearch/sql/algoliasearch_setup/mysql4-upgrade-1.16.0-1.17.0.php
This file contains hidden or 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,28 @@ | ||
<?php | ||
/** @var Mage_Core_Model_Resource_Setup $installer */ | ||
$installer = $this; | ||
$installer->startSetup(); | ||
|
||
$setup = new Mage_Sales_Model_Resource_Setup('core_setup'); | ||
|
||
$setup->addAttribute( | ||
'quote_item', | ||
'algoliasearch_query_param', | ||
array( | ||
'type' => Varien_Db_Ddl_Table::TYPE_TEXT, | ||
'grid' => false, | ||
'comment' => 'AlgoliaSearch Conversion Query Parameters' | ||
) | ||
); | ||
|
||
$setup->addAttribute( | ||
'order_item', | ||
'algoliasearch_query_param', | ||
array( | ||
'type' => Varien_Db_Ddl_Table::TYPE_TEXT, | ||
'grid' => false, | ||
'comment' => 'AlgoliaSearch Conversion Query Parameters' | ||
) | ||
); | ||
|
||
$installer->endSetup(); |
This file contains hidden or 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 hidden or 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
8 changes: 8 additions & 0 deletions
8
app/design/frontend/base/default/template/algoliasearch/checkout/success/conversion.phtml
This file contains hidden or 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 @@ | ||
<?php | ||
/** @var Algolia_Algoliasearch_Block_Checkout_Success_Conversion $this */ | ||
$orderItemsJson = $this->getOrderItemsConversionJson(); | ||
?> | ||
|
||
<script type="text/javascript"> | ||
var algoliaOrderConversionJson = <?php echo $orderItemsJson ?>; | ||
</script> |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.