Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
[FACTFINDER-162] Fix checkout tracking for different configurations #125
Browse files Browse the repository at this point in the history
  • Loading branch information
xpoback committed May 8, 2016
1 parent 1381e7c commit dd7adb1
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,29 @@ protected function _configureFacade()
{
}


/**
* Set store id for facade
*
* @param int $storeId
*
* @return $this
*/
public function setStoreId($storeId = 0)
{
$this->_getFacade()->setStoreId($storeId);

return $this;
}


/**
* Track login of a user
*
* @param string $sid session id (if empty, then try to set using the function session_id() )
* @param string $sid session id (if empty, then try to set using the function session_id() )
* @param string $cookieId cookie id (optional)
* @param string $userid id of user who logged in
* @param string $userid id of user who logged in
*
* @return boolean $success
*/
public function trackLogin(
Expand Down Expand Up @@ -204,4 +221,20 @@ public function applyTracking($instance = null)
}


/**
* Get an instance of FACT-Finder facade
*
* @return FACTFinder_Core_Model_Facade
*/
protected function _getFacade()
{
if ($this->_facade === null) {
// get new model, not singleton
$this->_facade = Mage::getModel($this->_facadeModel);
}

return $this->_facade;
}


}
41 changes: 23 additions & 18 deletions src/app/code/community/FACTFinder/Tracking/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ public function addOrderDetailsToQueue($observer)
$customerId = md5('customer_' . $customerId);
}

$searchHelper = Mage::helper('factfinder/search');
$idFieldName = Mage::helper('factfinder_tracking')->getIdFieldName();
if ($idFieldName == 'entity_id') {
$idFieldName = 'product_id'; // sales_order_item does not contain a entity_id
Expand All @@ -191,6 +190,7 @@ public function addOrderDetailsToQueue($observer)
->setUserid($customerId)
->setPrice($item->getPrice())
->setCount($item->getQtyOrdered())
->setStoreId($order->getStoreId())
->save();
}
catch (Exception $e) {
Expand All @@ -215,27 +215,32 @@ public function processOrderQueue()
$queue = Mage::getModel('factfinder_tracking/queue');

try {
$collectionSize = $queue->getCollection()->getSize();
$itemsByStore = array();
foreach ($queue->getCollection() as $item) {
$itemsByStore[$item->getStoreId()][] = $item;
}

foreach ($itemsByStore as $storeId => $items) {
/** @var FACTFinder_Tracking_Model_Handler_Tracking $tracking */
$tracking = Mage::getModel('factfinder_tracking/handler_tracking');
$tracking->setupCheckoutTracking(
$item->getProductId(),
$item->getProductId(),
$item->getProductName(),
null,
$item->getSid(),
null,
$item->getCount(),
$item->getPrice(),
$item->getUserid()
);

$item->delete($item);
}
$tracking->setStoreId($storeId);

foreach ($items as $item) {
$tracking->setupCheckoutTracking(
$item->getProductId(),
$item->getProductId(),
$item->getProductName(),
null,
$item->getSid(),
null,
$item->getCount(),
$item->getPrice(),
$item->getUserid()
);

$item->delete($item);
}

if ($collectionSize > 0) {
// We use the last adapter instance to start the parallel request
$tracking->applyTracking($item->getProductId());
}
} catch (Exception $e) {
Expand Down
6 changes: 3 additions & 3 deletions src/app/code/community/FACTFinder/Tracking/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<config>
<modules>
<FACTFinder_Tracking>
<version>4.0.1</version>
<version>4.1.2</version>
</FACTFinder_Tracking>
</modules>
<global>
Expand Down Expand Up @@ -130,7 +130,7 @@
<clicktracking>1</clicktracking>
<track_carts>1</track_carts>
<track_checkout>1</track_checkout>
</export>
</export>
<config>
<tracking_identifier>entity_id</tracking_identifier>
</config>
Expand All @@ -140,7 +140,7 @@
<jobs>
<factfinder_tracking_queue_processing>
<schedule>
<cron_expr>*/5 * * * *</cron_expr>
<cron_expr>*/1 * * * *</cron_expr>
</schedule>
<run>
<model>factfinder_tracking/observer::processOrderQueue</model>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* FACTFinder_Tracking
*
* @category Mage
* @package FACTFinder_Tracking
* @author Flagbit Magento Team <[email protected]>
* @copyright Copyright (c) 2015 Flagbit GmbH & Co. KG
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link http://www.flagbit.de
*
*/
/**
* Install script
*
* Install script for Tracking queue. Orders are sent to FACT-Finder asynchronously by cronjobs.
*/

$installer = $this;
$installer->startSetup();

$table = $installer->getConnection()
->addColumn(
$installer->getTable('factfinder_tracking/queue'),
'store_id',
array(
'type' => Varien_Db_Ddl_Table::TYPE_INTEGER,
'nullable' => true,
'default' => null,
'comment' => 'Store ID'
)
);
$installer->endSetup();

0 comments on commit dd7adb1

Please sign in to comment.