Skip to content

Commit c1a7b1f

Browse files
authored
Develop (#1145)
* Apply ruleContexts in autocomplete (#1133) * Update search-insights and compatibility (#1129) * Admin indexing queue remove uppercase on renderer's column (#1132) * GA configuration update the depends node to the correct field name (#1143) * remove ordered_qty as a default option for product attr and ranking (#1142) * Update CMS Page Indexing (#1141)
1 parent 443f861 commit c1a7b1f

File tree

16 files changed

+353
-95
lines changed

16 files changed

+353
-95
lines changed

app/code/community/Algolia/Algoliasearch/Block/Adminhtml/Indexingqueue/Grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function _prepareColumns()
6565
$this->addColumn('data', array(
6666
'header' => Mage::helper('algoliasearch')->__('Data'),
6767
'index' => 'data',
68-
'renderer' => 'Algolia_Algoliasearch_Block_Adminhtml_IndexingQueue_Grid_Renderer_Json'
68+
'renderer' => 'Algolia_Algoliasearch_Block_Adminhtml_Indexingqueue_Grid_Renderer_Json'
6969
));
7070

7171
$this->addColumn('max_retries', array(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
class Algolia_Algoliasearch_Block_Checkout_Success_Conversion extends Mage_Core_Block_Template
4+
{
5+
/** @var Mage_Sales_Model_Order */
6+
protected $_order;
7+
8+
protected function _construct()
9+
{
10+
parent::_construct();
11+
12+
if ($orderId = Mage::getSingleton('checkout/session')->getLastOrderId()) {
13+
$this->_order = Mage::getModel('sales/order')->load($orderId);
14+
}
15+
}
16+
17+
/**
18+
* @return string
19+
*/
20+
public function getOrderItemsConversionJson()
21+
{
22+
$orderItemsData = array();
23+
$orderItems = $this->_order->getAllVisibleItems();
24+
25+
/** @var Item $item */
26+
foreach ($orderItems as $item) {
27+
if ($item->getData('algoliasearch_query_param') !== '') {
28+
$orderItemsData[$item->getProductId()] = json_decode($item->getData('algoliasearch_query_param'));
29+
}
30+
}
31+
32+
return Mage::helper('core')->jsonEncode($orderItemsData);
33+
}
34+
35+
public function _toHtml()
36+
{
37+
if ($this->_order
38+
&& Mage::helper('algoliasearch/config')->isClickConversionAnalyticsEnabled($this->_order->getStoreId())
39+
&& Mage::helper('algoliasearch/config')->getConversionAnalyticsMode($this->_order->getStoreId()) === 'place_order'
40+
) {
41+
return parent::_toHtml();
42+
}
43+
44+
return '';
45+
}
46+
}

app/code/community/Algolia/Algoliasearch/Helper/Entity/Pagehelper.php

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,33 @@ public function getIndexSettings($storeId)
2323

2424
public function getPages($storeId, $pageIds = null)
2525
{
26-
/** @var Mage_Cms_Model_Page $cmsPage */
27-
$cmsPage = Mage::getModel('cms/page');
28-
2926
/** @var Mage_Cms_Model_Resource_Page_Collection $pages */
30-
$pages = $cmsPage->getCollection()->addStoreFilter($storeId)->addFieldToFilter('is_active', 1);
27+
$pageCollection = Mage::getModel('cms/page')->getCollection()
28+
->addStoreFilter($storeId)
29+
->addFieldToFilter('is_active', 1);
3130

3231
if ($pageIds && count($pageIds) > 0) {
33-
$pages = $pages->addFieldToFilter('page_id', array('in' => $pageIds));
32+
$pageCollection->addFieldToFilter('page_id', array('in' => $pageIds));
3433
}
3534

36-
Mage::dispatchEvent('algolia_after_pages_collection_build', array('store' => $storeId, 'collection' => $pages));
37-
38-
$ids = $pages->toOptionArray();
39-
40-
$exludedPages = array_values($this->config->getExcludedPages());
35+
Mage::dispatchEvent('algolia_after_pages_collection_build', array('store' => $storeId, 'collection' => $pageCollection));
4136

42-
foreach ($exludedPages as &$excludedPage) {
37+
$excludedPages = array_values($this->config->getExcludedPages());
38+
foreach ($excludedPages as &$excludedPage) {
4339
$excludedPage = $excludedPage['pages'];
4440
}
4541

4642
$pages = array();
47-
48-
foreach ($ids as $key => $value) {
49-
if (in_array($value['value'], $exludedPages)) {
43+
/** @var Mage_Cms_Model_Page $page */
44+
foreach ($pageCollection as $page) {
45+
if (in_array($page->getIdentifier(), $excludedPages)) {
5046
continue;
5147
}
5248

5349
$pageObject = array();
5450

55-
$pageObject['slug'] = $value['value'];
56-
$pageObject['name'] = $value['label'];
57-
58-
/** @var Mage_Cms_Model_Page $page */
59-
$page = Mage::getModel('cms/page');
60-
61-
$page->setStoreId($storeId);
62-
$page->load($pageObject['slug'], 'identifier');
63-
64-
if (!$page->getId()) {
65-
continue;
66-
}
51+
$pageObject['slug'] = $page->getIdentifier();
52+
$pageObject['name'] = $page->getTitle();
6753

6854
$content = $page->getContent();
6955
if ($this->config->getRenderTemplateDirectives()) {

app/code/community/Algolia/Algoliasearch/Model/Observer.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public function saveProduct(Varien_Event_Observer $observer)
106106
Algolia_Algoliasearch_Model_Indexer_Algolia::$product_categories[$product->getId()] = $product->getCategoryIds();
107107
}
108108

109+
/**
110+
* @event cms_page_save_commit_after
111+
* @param Varien_Event_Observer $observer
112+
*/
109113
public function savePage(Varien_Event_Observer $observer)
110114
{
111115
if (!$this->config->getApplicationID()
@@ -115,15 +119,18 @@ public function savePage(Varien_Event_Observer $observer)
115119
}
116120

117121
/** @var Mage_Cms_Model_Page $page */
118-
$page = $observer->getDataObject();
119-
$page = Mage::getModel('cms/page')->load($page->getId());
120-
121-
$storeIds = $page->getStoreId();
122+
$page = $observer->getEvent()->getDataObject();
123+
$storeIds = $page->getStores();
122124

123125
/** @var Algolia_Algoliasearch_Model_Resource_Engine $engine */
124126
$engine = Mage::getResourceModel('algoliasearch/engine');
125127

126-
$engine->rebuildPages($storeIds, $page->getId());
128+
foreach ($storeIds as $storeId) {
129+
if ($storeId == 0) {
130+
$storeId = null;
131+
}
132+
$engine->rebuildPages($storeId, array($page->getPageId()));
133+
}
127134
}
128135

129136
public function deleteProductsStoreIndices(Varien_Object $event)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
3+
class Algolia_Algoliasearch_Model_Observer_Conversion
4+
{
5+
protected $_analyticsParams = array(
6+
'queryID',
7+
'indexName',
8+
'objectID',
9+
);
10+
11+
/**
12+
* @param null $storeId
13+
* @return bool
14+
*/
15+
protected function _isOrderConversionTrackingEnabled($storeId = null)
16+
{
17+
return Mage::helper('algoliasearch/config')->isClickConversionAnalyticsEnabled($storeId)
18+
&& Mage::helper('algoliasearch/config')->getConversionAnalyticsMode($storeId) === 'place_order';
19+
}
20+
21+
/**
22+
* @param array $params
23+
* @return bool
24+
*/
25+
protected function _hasRequiredParameters($params = array())
26+
{
27+
foreach ($this->_analyticsParams as $requiredParam) {
28+
if (!isset($params[$requiredParam])) {
29+
return false;
30+
}
31+
}
32+
33+
return true;
34+
}
35+
36+
/**
37+
* @event catalog_controller_product_init_before
38+
*/
39+
public function setAlgoliaParamsToSession(Varien_Event_Observer $observer)
40+
{
41+
$checkoutSession = Mage::getSingleton('checkout/session');
42+
if (!$this->_isOrderConversionTrackingEnabled($checkoutSession->getQuote()->getStoreId())) {
43+
return;
44+
}
45+
46+
/** @var Mage_Core_Controller_Front_Action $controllerAction */
47+
$controllerAction = $observer->getEvent()->getControllerAction();
48+
$params = $controllerAction->getRequest()->getParams();
49+
50+
if (!$this->_hasRequiredParameters($params)) {
51+
return;
52+
}
53+
54+
$conversionData = array(
55+
'queryID' => $params['queryID'],
56+
'indexName' => $params['indexName'],
57+
'objectID' => $params['objectID'],
58+
);
59+
60+
$session = Mage::getSingleton('core/session', array('name' => 'frontend'));
61+
$session->setData('algolia_conversion_parameters', Mage::helper('core')->jsonEncode($conversionData));
62+
}
63+
64+
/**
65+
* @event checkout_cart_product_add_after
66+
*/
67+
public function saveAlgoliaParamToQuoteItem(Varien_Event_Observer $observer)
68+
{
69+
/** @var Mage_Sales_Model_Quote_Item $quoteItem */
70+
$quoteItem = $observer->getEvent()->getQuoteItem();
71+
/** @var Mage_Catalog_Model_Product $product */
72+
$product = $observer->getEvent()->getProduct();
73+
74+
if ($this->_isOrderConversionTrackingEnabled($product->getStoreId())) {
75+
$session = Mage::getSingleton('core/session');
76+
$quoteItem->setData('algoliasearch_query_param', $session->getData('algolia_conversion_parameters'));
77+
$session->unsetData('algolia_conversion_parameters');
78+
}
79+
}
80+
}

app/code/community/Algolia/Algoliasearch/etc/config.xml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<config>
33
<modules>
44
<Algolia_Algoliasearch>
5-
<version>1.16.0</version>
5+
<version>1.17.0</version>
66
</Algolia_Algoliasearch>
77
</modules>
88
<frontend>
@@ -140,14 +140,35 @@
140140
</observers>
141141
</catalog_product_save_before>
142142

143-
<cms_page_save_before>
143+
<cms_page_save_commit_after>
144144
<observers>
145145
<algolia_savepage>
146146
<class>algoliasearch/observer</class>
147147
<method>savePage</method>
148148
</algolia_savepage>
149149
</observers>
150-
</cms_page_save_before>
150+
</cms_page_save_commit_after>
151+
152+
<catalog_controller_product_init_before>
153+
<observers>
154+
<algolia_conversion_save_request_to_session>
155+
<type>singleton</type>
156+
<class>algoliasearch/observer_conversion</class>
157+
<method>setAlgoliaParamsToSession</method>
158+
</algolia_conversion_save_request_to_session>
159+
</observers>
160+
</catalog_controller_product_init_before>
161+
162+
<checkout_cart_product_add_after>
163+
<observers>
164+
<algolia_conversion_save_quote_item>
165+
<type>singleton</type>
166+
<class>algoliasearch/observer_conversion</class>
167+
<method>saveAlgoliaParamToQuoteItem</method>
168+
</algolia_conversion_save_quote_item>
169+
</observers>
170+
</checkout_cart_product_add_after>
171+
151172
</events>
152173
<resources>
153174
<algoliasearch_setup>
@@ -181,6 +202,13 @@
181202
</algolia_delete_products>
182203
</indexer>
183204
</index>
205+
<fieldsets>
206+
<sales_convert_quote_item>
207+
<algoliasearch_query_param>
208+
<to_order_item>*</to_order_item>
209+
</algoliasearch_query_param>
210+
</sales_convert_quote_item>
211+
</fieldsets>
184212
</global>
185213
<default>
186214
<algoliasearch>
@@ -198,8 +226,7 @@
198226
</credentials>
199227
<products>
200228
<number_product_results>9</number_product_results>
201-
<product_additional_attributes>a:10:{s:18:"_1427959997377_377";a:4:{s:9:"attribute";s:4:"name";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";}s:18:"_1427960012597_597";a:4:{s:9:"attribute";s:4:"path";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";}s:18:"_1427961262735_735";a:4:{s:9:"attribute";s:10:"categories";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";}s:18:"_1447846016385_385";a:5:{s:9:"attribute";s:5:"color";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"0";}s:18:"_1427961324936_936";a:4:{s:9:"attribute";s:3:"sku";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";}s:18:"_1427962021621_621";a:4:{s:9:"attribute";s:5:"price";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";}s:18:"_1427977839554_554";a:4:{s:9:"attribute";s:11:"ordered_qty";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"0";s:5:"order";s:9:"unordered";}s:18:"_1428566173508_508";a:4:{s:9:"attribute";s:9:"stock_qty";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"0";s:5:"order";s:9:"unordered";}s:17:"_1433929490023_23";a:4:{s:9:"attribute";s:14:"rating_summary";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";}s:18:"_1436178594492_492";a:4:{s:9:"attribute";s:10:"created_at";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"0";s:5:"order";s:9:"unordered";}}</product_additional_attributes>
202-
<custom_ranking_product_attributes>a:1:{s:18:"_1427960305274_274";a:2:{s:9:"attribute";s:11:"ordered_qty";s:5:"order";s:4:"desc";}}</custom_ranking_product_attributes>
229+
<product_additional_attributes>a:9:{s:18:"_1427959997377_377";a:5:{s:9:"attribute";s:4:"name";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:18:"_1427960012597_597";a:5:{s:9:"attribute";s:4:"path";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:18:"_1427961262735_735";a:5:{s:9:"attribute";s:10:"categories";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:18:"_1447846016385_385";a:5:{s:9:"attribute";s:5:"color";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"0";}s:18:"_1427961324936_936";a:5:{s:9:"attribute";s:3:"sku";s:10:"searchable";s:1:"1";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:18:"_1427962021621_621";a:5:{s:9:"attribute";s:5:"price";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:18:"_1428566173508_508";a:5:{s:9:"attribute";s:9:"stock_qty";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"0";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:17:"_1433929490023_23";a:5:{s:9:"attribute";s:14:"rating_summary";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"1";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}s:18:"_1436178594492_492";a:5:{s:9:"attribute";s:10:"created_at";s:10:"searchable";s:1:"0";s:11:"retrievable";s:1:"0";s:5:"order";s:9:"unordered";s:14:"index_no_value";s:1:"1";}}</product_additional_attributes>
203230
<results_limit>1000</results_limit>
204231
<show_suggestions_on_no_result_page>1</show_suggestions_on_no_result_page>
205232
<index_visibility>all</index_visibility>

app/code/community/Algolia/Algoliasearch/etc/system.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@
10151015
<p>Default value: 3000</p>
10161016
]]>
10171017
</comment>
1018-
<depends><enable_analytics>1</enable_analytics></depends>
1018+
<depends><enable>1</enable></depends>
10191019
</delay>
10201020
<trigger_on_ui_interaction translate="label comment">
10211021
<label>Trigger the push function before the the delay on UI interaction</label>
@@ -1031,7 +1031,7 @@
10311031
<p>Default value: Yes</p>
10321032
]]>
10331033
</comment>
1034-
<depends><enable_analytics>1</enable_analytics></depends>
1034+
<depends><enable>1</enable></depends>
10351035
</trigger_on_ui_interaction>
10361036
<push_initial_search translate="label comment">
10371037
<label>Trigger the push function after the initial search</label>
@@ -1047,7 +1047,7 @@
10471047
<p>Default value: No</p>
10481048
]]>
10491049
</comment>
1050-
<depends><enable_analytics>1</enable_analytics></depends>
1050+
<depends><enable>1</enable></depends>
10511051
</push_initial_search>
10521052
</fields>
10531053
</analytics>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/** @var Mage_Core_Model_Resource_Setup $installer */
3+
$installer = $this;
4+
$installer->startSetup();
5+
6+
$setup = new Mage_Sales_Model_Resource_Setup('core_setup');
7+
8+
$setup->addAttribute(
9+
'quote_item',
10+
'algoliasearch_query_param',
11+
array(
12+
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
13+
'grid' => false,
14+
'comment' => 'AlgoliaSearch Conversion Query Parameters'
15+
)
16+
);
17+
18+
$setup->addAttribute(
19+
'order_item',
20+
'algoliasearch_query_param',
21+
array(
22+
'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
23+
'grid' => false,
24+
'comment' => 'AlgoliaSearch Conversion Query Parameters'
25+
)
26+
);
27+
28+
$installer->endSetup();

app/design/frontend/base/default/layout/algoliasearch.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,10 @@
101101
</reference>
102102
</algolia_search_handle_click_conversion_analytics>
103103

104+
<checkout_onepage_success>
105+
<reference name="before_body_end">
106+
<block type="algoliasearch/checkout_success_conversion" name="algolia.order.conversion" template="algoliasearch/checkout/success/conversion.phtml" />
107+
</reference>
108+
</checkout_onepage_success>
109+
104110
</layout>

app/design/frontend/base/default/template/algoliasearch/autocomplete/product.phtml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ if ($config->isCustomerGroupsEnabled($storeId)) {
1919

2020
<!-- Product hit template -->
2121
<script type="text/template" id="autocomplete_products_template">
22-
<a class="algoliasearch-autocomplete-hit" href="{{url}}">
22+
<a class="algoliasearch-autocomplete-hit"
23+
{{^__queryID}} href="{{url}}" {{/__queryID}}
24+
{{#__queryID}} href="{{urlForInsights}}" {{/__queryID}}
25+
data-objectid="{{objectID}}"
26+
data-position="{{__position}}"
27+
data-queryid="{{__queryID}}"
28+
>
2329
{{#thumbnail_url}}
2430
<div class="thumb"><img src="{{thumbnail_url}}" /></div>
2531
{{/thumbnail_url}}

0 commit comments

Comments
 (0)