Listrak_Remarketing - Version 1.1.9.4

Version Notes

Product API improvements

Download this release

Release Info

Developer Magento Core Team
Extension Listrak_Remarketing
Version 1.1.9.4
Comparing to
See all releases


Code changes from version 1.1.9.2 to 1.1.9.4

Files changed (116) hide show
  1. app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture.php +6 -0
  2. app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit.php +23 -3
  3. app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit/Form.php +12 -1
  4. app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit/Tab/Form.php +22 -7
  5. app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit/Tabs.php +13 -1
  6. app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Grid.php +45 -18
  7. app/code/community/Listrak/Remarketing/Block/Adminhtml/Notifications.php +36 -12
  8. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes.php +32 -2
  9. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit.php +11 -0
  10. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Form.php +12 -1
  11. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Tab/Form/Brand.php +10 -1
  12. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Tab/Form/Categories.php +37 -2
  13. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Tabs.php +32 -4
  14. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Grid.php +62 -31
  15. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Init/Brands.php +27 -2
  16. app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Init/Brands/Form.php +24 -4
  17. app/code/community/Listrak/Remarketing/Block/Base.php +126 -30
  18. app/code/community/Listrak/Remarketing/Block/Conversion/Abstract.php +112 -33
  19. app/code/community/Listrak/Remarketing/Block/Conversion/Cart.php +42 -11
  20. app/code/community/Listrak/Remarketing/Block/Conversion/Fingerprint.php +21 -5
  21. app/code/community/Listrak/Remarketing/Block/Conversion/Order.php +46 -16
  22. app/code/community/Listrak/Remarketing/Block/Legacy/Ecjs.php +41 -10
  23. app/code/community/Listrak/Remarketing/Block/Legacy/Modal.php +19 -2
  24. app/code/community/Listrak/Remarketing/Block/Require/Activity.php +32 -8
  25. app/code/community/Listrak/Remarketing/Block/Require/Legacy.php +31 -8
  26. app/code/community/Listrak/Remarketing/Block/Require/Onescript.php +31 -8
  27. app/code/community/Listrak/Remarketing/Block/Require/Sca.php +32 -8
  28. app/code/community/Listrak/Remarketing/Block/Tracking/Activity.php +35 -12
  29. app/code/community/Listrak/Remarketing/Block/Tracking/Click.php +15 -4
  30. app/code/community/Listrak/Remarketing/Block/Tracking/Email.php +47 -14
  31. app/code/community/Listrak/Remarketing/Block/Tracking/Sca.php +203 -57
  32. app/code/community/Listrak/Remarketing/Helper/Data.php +367 -83
  33. app/code/community/Listrak/Remarketing/Helper/Product.php +714 -184
  34. app/code/community/Listrak/Remarketing/Helper/Product/Attribute/Set/Map.php +41 -11
  35. app/code/community/Listrak/Remarketing/Helper/Review/Update.php +45 -5
  36. app/code/community/Listrak/Remarketing/Model/Abandonedcart.php +8 -27
  37. app/code/community/Listrak/Remarketing/Model/Abandonedcart/Api.php +69 -21
  38. app/code/community/Listrak/Remarketing/Model/Abandonedcart/Api/V2.php +3 -0
  39. app/code/community/Listrak/Remarketing/Model/Apiextension.php +11 -0
  40. app/code/community/Listrak/Remarketing/Model/Apiextension/Api.php +434 -135
  41. app/code/community/Listrak/Remarketing/Model/Apiextension/Api/V2.php +3 -0
  42. app/code/community/Listrak/Remarketing/Model/Cache/Sca.php +46 -9
  43. app/code/community/Listrak/Remarketing/Model/Click.php +32 -5
  44. app/code/community/Listrak/Remarketing/Model/Click/Api.php +66 -24
  45. app/code/community/Listrak/Remarketing/Model/Click/Api/V2.php +3 -0
  46. app/code/community/Listrak/Remarketing/Model/Emailcapture.php +10 -1
  47. app/code/community/Listrak/Remarketing/Model/Log.php +32 -4
  48. app/code/community/Listrak/Remarketing/Model/Log/Api.php +62 -25
  49. app/code/community/Listrak/Remarketing/Model/Log/Api/V2.php +3 -0
  50. app/code/community/Listrak/Remarketing/Model/Mysql4/Abandonedcart.php +53 -15
  51. app/code/community/Listrak/Remarketing/Model/Mysql4/Abandonedcart/Collection.php +36 -13
  52. app/code/community/Listrak/Remarketing/Model/Mysql4/Apiextension.php +44 -27
  53. app/code/community/Listrak/Remarketing/Model/Mysql4/Click.php +44 -10
  54. app/code/community/Listrak/Remarketing/Model/Mysql4/Click/Collection.php +15 -1
  55. app/code/community/Listrak/Remarketing/Model/Mysql4/Emailcapture.php +8 -7
  56. app/code/community/Listrak/Remarketing/Model/Mysql4/Emailcapture/Collection.php +8 -1
  57. app/code/community/Listrak/Remarketing/Model/Mysql4/Log.php +8 -7
  58. app/code/community/Listrak/Remarketing/Model/Mysql4/Log/Collection.php +15 -0
  59. app/code/community/Listrak/Remarketing/Model/Mysql4/Product.php +22 -0
  60. app/code/community/Listrak/Remarketing/Model/Mysql4/Product/Attribute/Set/Map.php +6 -7
  61. app/code/community/Listrak/Remarketing/Model/Mysql4/Product/Attribute/Set/Map/Collection.php +55 -10
  62. app/code/community/Listrak/Remarketing/Model/Mysql4/Product/Collection.php +185 -0
  63. app/code/community/Listrak/Remarketing/Model/Mysql4/Review/Update.php +8 -7
  64. app/code/community/Listrak/Remarketing/Model/Mysql4/Review/Update/Collection.php +39 -2
  65. app/code/community/Listrak/Remarketing/Model/Mysql4/Session.php +93 -20
  66. app/code/community/Listrak/Remarketing/Model/Mysql4/Session/Collection.php +21 -1
  67. app/code/community/Listrak/Remarketing/Model/Mysql4/Subscriberupdate.php +8 -7
  68. app/code/community/Listrak/Remarketing/Model/Mysql4/Subscriberupdate/Collection.php +8 -0
  69. app/code/community/Listrak/Remarketing/Model/Observer.php +130 -32
  70. app/code/community/Listrak/Remarketing/Model/Product.php +30 -0
  71. app/code/community/Listrak/Remarketing/Model/Product/Api.php +227 -64
  72. app/code/community/Listrak/Remarketing/Model/Product/Api/V2.php +3 -0
  73. app/code/community/Listrak/Remarketing/Model/Product/Attribute/Set/Map.php +60 -10
  74. app/code/community/Listrak/Remarketing/Model/Product/Attributes.php +20 -6
  75. app/code/community/Listrak/Remarketing/Model/Product/Category/Source.php +18 -2
  76. app/code/community/Listrak/Remarketing/Model/Product/Purchasable/Visibility.php +83 -19
  77. app/code/community/Listrak/Remarketing/Model/Review/Update.php +67 -6
  78. app/code/community/Listrak/Remarketing/Model/Review/Update/Api.php +267 -96
  79. app/code/community/Listrak/Remarketing/Model/Review/Update/Api/V2.php +3 -0
  80. app/code/community/Listrak/Remarketing/Model/Session.php +94 -23
  81. app/code/community/Listrak/Remarketing/Model/Subscriber.php +29 -8
  82. app/code/community/Listrak/Remarketing/Model/Subscriberupdate.php +10 -1
  83. app/code/community/Listrak/Remarketing/controllers/Adminhtml/AbandonedcartreportController.php +0 -47
  84. app/code/community/Listrak/Remarketing/controllers/Adminhtml/EmailcaptureController.php +0 -153
  85. app/code/community/Listrak/Remarketing/controllers/Adminhtml/ProductattributesController.php +0 -162
  86. app/code/community/Listrak/Remarketing/controllers/AjaxController.php +45 -8
  87. app/code/community/Listrak/Remarketing/controllers/CartController.php +136 -33
  88. app/code/community/Listrak/Remarketing/controllers/ConfigController.php +57 -19
  89. app/code/community/Listrak/Remarketing/controllers/EmailController.php +41 -7
  90. app/code/community/Listrak/Remarketing/controllers/Remarketing/EmailcaptureController.php +264 -0
  91. app/code/community/Listrak/Remarketing/controllers/Remarketing/ProductattributesController.php +311 -0
  92. app/code/community/Listrak/Remarketing/controllers/TroubleshootingController.php +8 -0
  93. app/code/community/Listrak/Remarketing/etc/adminhtml.xml +3 -3
  94. app/code/community/Listrak/Remarketing/etc/api.xml +4 -8
  95. app/code/community/Listrak/Remarketing/etc/cache.xml +1 -1
  96. app/code/community/Listrak/Remarketing/etc/config.xml +6 -6
  97. app/code/community/Listrak/Remarketing/etc/wsdl.xml +22 -24
  98. app/code/community/Listrak/Remarketing/etc/wsi.xml +25 -43
  99. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-install-1.0.0.php +4 -2
  100. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-install-1.1.9.php +4 -14
  101. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.0.0-1.0.1.php +8 -3
  102. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.0.8-1.0.9.php +5 -2
  103. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.0-1.1.1.php +4 -3
  104. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.3-1.1.4.php +4 -2
  105. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.4-1.1.5.php +4 -2
  106. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.5-1.1.6.php +4 -2
  107. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.6-1.1.7.php +19 -5
  108. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.7-1.1.8.php +4 -1
  109. app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.8-1.1.9.php +8 -3
  110. app/design/adminhtml/default/default/template/listrak/remarketing/productattributes.phtml +9 -5
  111. app/design/adminhtml/default/default/template/listrak/remarketing/productattributes/form/categories.phtml +101 -33
  112. app/design/frontend/base/default/layout/remarketing.xml +3 -3
  113. app/design/frontend/base/default/template/remarketing/async_wrapper.phtml +16 -3
  114. app/design/frontend/base/default/template/remarketing/onescript.phtml +20 -4
  115. app/design/frontend/base/default/template/remarketing/utils.phtml +33 -7
  116. package.xml +5 -8
app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture
16
  extends Mage_Adminhtml_Block_Widget_Grid_Container
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  $this->_controller = 'adminhtml_emailcapture';
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_EmailCapture
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture
19
  extends Mage_Adminhtml_Block_Widget_Grid_Container
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  $this->_controller = 'adminhtml_emailcapture';
app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit
16
  extends Mage_Adminhtml_Block_Widget_Form_Container
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
@@ -23,13 +29,27 @@ class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit
23
  $this->_blockGroup = 'remarketing';
24
  $this->_controller = 'adminhtml_emailcapture';
25
 
26
- $this->_updateButton('save', 'label', Mage::helper('remarketing')->__('Save Field'));
27
- $this->_updateButton('delete', 'label', Mage::helper('remarketing')->__('Delete Field'));
 
 
 
 
 
 
 
28
  }
29
 
 
 
 
 
 
30
  public function getHeaderText()
31
  {
32
- if (Mage::registry('emailcapture_data') && Mage::registry('emailcapture_data')->getId()) {
 
 
33
  return Mage::helper('remarketing')->__("Edit Field");
34
  } else {
35
  return Mage::helper('remarketing')->__('Add Field');
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit
19
  extends Mage_Adminhtml_Block_Widget_Form_Container
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
29
  $this->_blockGroup = 'remarketing';
30
  $this->_controller = 'adminhtml_emailcapture';
31
 
32
+ $this->_updateButton(
33
+ 'save', 'label',
34
+ Mage::helper('remarketing')->__('Save Field')
35
+ );
36
+
37
+ $this->_updateButton(
38
+ 'delete', 'label',
39
+ Mage::helper('remarketing')->__('Delete Field')
40
+ );
41
  }
42
 
43
+ /**
44
+ * Gets header text for block
45
+ *
46
+ * @return string
47
+ */
48
  public function getHeaderText()
49
  {
50
+ if (Mage::registry('emailcapture_data')
51
+ && Mage::registry('emailcapture_data')->getId()
52
+ ) {
53
  return Mage::helper('remarketing')->__("Edit Field");
54
  } else {
55
  return Mage::helper('remarketing')->__('Add Field');
app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit/Form.php CHANGED
@@ -12,15 +12,26 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Form
16
  extends Mage_Adminhtml_Block_Widget_Form
17
  {
 
 
 
 
 
18
  protected function _prepareForm()
19
  {
20
  $form = new Varien_Data_Form(
21
  array(
22
  'id' => 'edit_form',
23
- 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
 
 
 
24
  'method' => 'post',
25
  )
26
  );
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Form
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Form
19
  extends Mage_Adminhtml_Block_Widget_Form
20
  {
21
+ /**
22
+ * Prepare form
23
+ *
24
+ * @return Mage_Adminhtml_Block_Widget_Form
25
+ */
26
  protected function _prepareForm()
27
  {
28
  $form = new Varien_Data_Form(
29
  array(
30
  'id' => 'edit_form',
31
+ 'action' => $this->getUrl(
32
+ '*/*/save',
33
+ array('id' => $this->getRequest()->getParam('id'))
34
+ ),
35
  'method' => 'post',
36
  )
37
  );
app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit/Tab/Form.php CHANGED
@@ -12,9 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tab_Form
16
  extends Mage_Adminhtml_Block_Widget_Form
17
  {
 
 
 
 
 
18
  protected function _prepareForm()
19
  {
20
  $form = new Varien_Data_Form();
@@ -31,10 +39,10 @@ class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tab_Form
31
  'required' => true,
32
  'name' => 'page',
33
  'after_element_html' => '<p class="note"><span>For example: '
34
- . '/checkout/onepage/index. Each URL has 3 parts. If yours '
35
- . 'does not have 3 parts, fill the last with "index". You '
36
- . 'can also use wildcard character "*" to capture field on '
37
- . 'all pages in the store.</span></p>'
38
  )
39
  );
40
 
@@ -51,11 +59,18 @@ class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tab_Form
51
  );
52
 
53
  if (Mage::getSingleton('adminhtml/session')->getEmailCaptureData()) {
54
- $form->setValues(Mage::getSingleton('adminhtml/session')->getEmailCaptureData());
55
- Mage::getSingleton('adminhtml/session')->setEmailCaptureData(null);
 
 
 
56
  } elseif (Mage::registry('emailcapture_data')) {
57
- $form->setValues(Mage::registry('emailcapture_data')->getData());
 
 
 
58
  }
 
59
  return parent::_prepareForm();
60
  }
61
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tab_Form
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tab_Form
19
  extends Mage_Adminhtml_Block_Widget_Form
20
  {
21
+ /**
22
+ * Prepare form
23
+ *
24
+ * @return Mage_Adminhtml_Block_Widget_Form
25
+ */
26
  protected function _prepareForm()
27
  {
28
  $form = new Varien_Data_Form();
39
  'required' => true,
40
  'name' => 'page',
41
  'after_element_html' => '<p class="note"><span>For example: '
42
+ . '/checkout/onepage/index. Each URL has 3 parts. If yours'
43
+ . ' does not have 3 parts, fill the last with "index". '
44
+ . 'You can also use wildcard character "*" to capture '
45
+ . 'field on all pages in the store.</span></p>'
46
  )
47
  );
48
 
59
  );
60
 
61
  if (Mage::getSingleton('adminhtml/session')->getEmailCaptureData()) {
62
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
63
+ $adminSession = Mage::getSingleton('adminhtml/session');
64
+
65
+ $form->setValues($adminSession->getEmailCaptureData());
66
+ $adminSession->setEmailCaptureData(null);
67
  } elseif (Mage::registry('emailcapture_data')) {
68
+ $form->setValues(
69
+ Mage::registry('emailcapture_data')
70
+ ->getData()
71
+ );
72
  }
73
+
74
  return parent::_prepareForm();
75
  }
76
  }
app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Edit/Tabs.php CHANGED
@@ -12,10 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tabs
16
  extends Mage_Adminhtml_Block_Widget_Tabs
17
  {
18
-
 
 
19
  public function __construct()
20
  {
21
  parent::__construct();
@@ -24,6 +29,13 @@ class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tabs
24
  $this->setTitle(Mage::helper('remarketing')->__('Field Information'));
25
  }
26
 
 
 
 
 
 
 
 
27
  protected function _beforeToHtml()
28
  {
29
  $this->addTab(
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tabs
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Edit_Tabs
19
  extends Mage_Adminhtml_Block_Widget_Tabs
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
29
  $this->setTitle(Mage::helper('remarketing')->__('Field Information'));
30
  }
31
 
32
+ /**
33
+ * Before HTML output
34
+ *
35
+ * Adds necessary UI elements
36
+ *
37
+ * @return Mage_Core_Block_Abstract
38
+ */
39
  protected function _beforeToHtml()
40
  {
41
  $this->addTab(
app/code/community/Listrak/Remarketing/Block/Adminhtml/Emailcapture/Grid.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Grid
16
  extends Mage_Adminhtml_Block_Widget_Grid
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
@@ -24,43 +30,64 @@ class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Grid
24
  $this->setSaveParametersInSession(true);
25
  }
26
 
 
 
 
 
 
27
  protected function _prepareCollection()
28
  {
29
- $collection = Mage::getModel('listrak/emailcapture')->getCollection();
30
- $this->setCollection($collection);
 
31
  return parent::_prepareCollection();
32
  }
33
 
 
 
 
 
 
34
  protected function _prepareColumns()
35
  {
36
  $this->addColumn(
37
- 'emailcapture_id', array(
38
- 'header' => Mage::helper('remarketing')->__('ID'),
39
- 'align' => 'right',
40
- 'width' => '50px',
41
- 'index' => 'emailcapture_id',
42
- )
 
43
  );
44
 
45
  $this->addColumn(
46
- 'page', array(
47
- 'header' => Mage::helper('remarketing')->__('Page'),
48
- 'align' => 'left',
49
- 'index' => 'page',
50
- )
 
51
  );
52
 
53
  $this->addColumn(
54
- 'field_id', array(
55
- 'header' => Mage::helper('remarketing')->__('Field ID'),
56
- 'align' => 'left',
57
- 'index' => 'field_id',
58
- )
 
59
  );
60
 
61
  return parent::_prepareColumns();
62
  }
63
 
 
 
 
 
 
 
 
64
  public function getRowUrl($row)
65
  {
66
  return $this->getUrl('*/*/edit', array('id' => $row->getId()));
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Grid
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_EmailCapture_Grid
19
  extends Mage_Adminhtml_Block_Widget_Grid
20
  {
21
+ /**
22
+ * Initializes the object
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
30
  $this->setSaveParametersInSession(true);
31
  }
32
 
33
+ /**
34
+ * Prepare collection
35
+ *
36
+ * @return $this
37
+ */
38
  protected function _prepareCollection()
39
  {
40
+ /* @var Listrak_Remarketing_Model_Mysql4_Emailcapture_Collection $col */
41
+ $col = Mage::getModel('listrak/emailcapture')->getCollection();
42
+ $this->setCollection($col);
43
  return parent::_prepareCollection();
44
  }
45
 
46
+ /**
47
+ * Prepare grid columns
48
+ *
49
+ * @return $this
50
+ */
51
  protected function _prepareColumns()
52
  {
53
  $this->addColumn(
54
+ 'emailcapture_id',
55
+ array(
56
+ 'header' => Mage::helper('remarketing')->__('ID'),
57
+ 'align' => 'right',
58
+ 'width' => '50px',
59
+ 'index' => 'emailcapture_id',
60
+ )
61
  );
62
 
63
  $this->addColumn(
64
+ 'page',
65
+ array(
66
+ 'header' => Mage::helper('remarketing')->__('Page'),
67
+ 'align' => 'left',
68
+ 'index' => 'page',
69
+ )
70
  );
71
 
72
  $this->addColumn(
73
+ 'field_id',
74
+ array(
75
+ 'header' => Mage::helper('remarketing')->__('Field ID'),
76
+ 'align' => 'left',
77
+ 'index' => 'field_id',
78
+ )
79
  );
80
 
81
  return parent::_prepareColumns();
82
  }
83
 
84
+ /**
85
+ * Retrieve the edit page location for a row
86
+ *
87
+ * @param mixed $row Grid row
88
+ *
89
+ * @return string
90
+ */
91
  public function getRowUrl($row)
92
  {
93
  return $this->getUrl('*/*/edit', array('id' => $row->getId()));
app/code/community/Listrak/Remarketing/Block/Adminhtml/Notifications.php CHANGED
@@ -12,27 +12,51 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Notifications extends Mage_Core_Block_Text
16
  {
 
 
 
 
 
17
  protected function _toHtml()
18
  {
19
  $html = "";
20
 
21
- if (!Mage::helper('remarketing')->checkSetupStatus()) {
22
- $html .= "<div class='notification-global'>The Listrak module requires a Listrak account. Please " .
23
- "<a href='http://www.listrak.com/partners/magento-extension.aspx'>fill out our form</a> to " .
24
- "get an account. If you already have a Listrak account, please contact your account manager " .
25
- "or <a href='mailto:support@listrak.com'>support@listrak.com</a>.</div>";
 
 
 
 
 
26
  }
27
 
28
- if (strpos(Mage::helper('core/url')->getCurrentUrl(), "/adminhtml_productattributes/") === false
29
- && Mage::helper('remarketing')->displayAttributeSetNotification()
 
 
 
 
30
  ) {
31
- $html .= "<div class='notification-global'>Brand attribute has not been defined for one or more " .
32
- "attribute sets. Please <a href='" .
33
- Mage::helper('adminhtml')->getUrl('remarketing/adminhtml_productattributes/index') .
34
- "'>click here</a>, or go to Listrak > Product Attributes " .
35
- "to review your current settings.</div>";
 
 
 
 
 
36
  }
37
 
38
  return $html;
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Notifications
17
+ *
18
+ * Displays notifications in the admin portal
19
+ */
20
  class Listrak_Remarketing_Block_Adminhtml_Notifications extends Mage_Core_Block_Text
21
  {
22
+ /**
23
+ * Render block
24
+ *
25
+ * @return string
26
+ */
27
  protected function _toHtml()
28
  {
29
  $html = "";
30
 
31
+ /* @var Listrak_Remarketing_Helper_Data $helper */
32
+ $helper = Mage::helper('remarketing');
33
+ if (!$helper->checkSetupStatus()) {
34
+ $html .= "<div class='notification-global'>The Listrak module "
35
+ . "requires a Listrak account. Please "
36
+ . "<a href='http://www.listrak.com/partners/magento-extension.aspx'>"
37
+ . "fill out our form</a> to get an account. If you already have a "
38
+ . "Listrak account, please contact your account manager or "
39
+ . "<a href='mailto:support@listrak.com'>support@listrak.com</a>."
40
+ . "</div>";
41
  }
42
 
43
+ /* @var Mage_Core_Helper_Url $urlHelper */
44
+ $urlHelper = Mage::helper('core/url');
45
+
46
+ $currentUrl = $urlHelper->getCurrentUrl();
47
+ if (strpos($currentUrl, "/adminhtml_productattributes/") === false
48
+ && $helper->displayAttributeSetNotification()
49
  ) {
50
+ /* @var Mage_Adminhtml_Helper_Data $adminHelper */
51
+ $adminHelper = Mage::helper('adminhtml');
52
+
53
+ $url = $adminHelper
54
+ ->getUrl('remarketing/adminhtml_productattributes/index');
55
+
56
+ $html .= "<div class='notification-global'>Brand attribute has not been "
57
+ . "defined for one or more attribute sets. Please <a href='{$url}'>"
58
+ . "click here</a>, or go to Listrak > Product Attributes "
59
+ . "to review your current settings.</div>";
60
  }
61
 
62
  return $html;
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_ProductAttributes
16
  extends Mage_Adminhtml_Block_Widget_Container
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
@@ -24,34 +30,58 @@ class Listrak_Remarketing_Block_Adminhtml_ProductAttributes
24
  $this->setTemplate('listrak/remarketing/productattributes.phtml');
25
  }
26
 
 
 
 
 
 
27
  public function _prepareLayout()
28
  {
29
  $this->setChild(
30
  'grid',
31
- $this->getLayout()->createBlock('remarketing/adminhtml_productattributes_grid')
 
32
  );
33
  $this->setChild(
34
  'init_brands',
35
- $this->getLayout()->createBlock('remarketing/adminhtml_productattributes_init_brands')
 
36
  );
37
  return parent::_prepareLayout();
38
  }
39
 
 
 
 
 
 
40
  public function getInitBrandsHtml()
41
  {
42
  return $this->getChildHtml('init_brands');
43
  }
44
 
 
 
 
 
 
45
  public function getGridHtml()
46
  {
47
  return $this->getChildHtml('grid');
48
  }
49
 
 
 
 
 
 
50
  public function setsWithoutBrandAttribute()
51
  {
52
  $sets = array();
53
 
54
  $allSets = Mage::registry('productattribute_sets');
 
 
55
  foreach ($allSets as $set) {
56
  if ($set->getBrandAttributeCode() == null) {
57
  array_push($sets, $set);
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_ProductAttributes
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_ProductAttributes
19
  extends Mage_Adminhtml_Block_Widget_Container
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
30
  $this->setTemplate('listrak/remarketing/productattributes.phtml');
31
  }
32
 
33
+ /**
34
+ * Creates the layout in code
35
+ *
36
+ * @return Mage_Core_Block_Abstract
37
+ */
38
  public function _prepareLayout()
39
  {
40
  $this->setChild(
41
  'grid',
42
+ $this->getLayout()
43
+ ->createBlock('remarketing/adminhtml_productattributes_grid')
44
  );
45
  $this->setChild(
46
  'init_brands',
47
+ $this->getLayout()
48
+ ->createBlock('remarketing/adminhtml_productattributes_init_brands')
49
  );
50
  return parent::_prepareLayout();
51
  }
52
 
53
+ /**
54
+ * Retrieve brands block
55
+ *
56
+ * @return string
57
+ */
58
  public function getInitBrandsHtml()
59
  {
60
  return $this->getChildHtml('init_brands');
61
  }
62
 
63
+ /**
64
+ * Retrieve the grid
65
+ *
66
+ * @return string
67
+ */
68
  public function getGridHtml()
69
  {
70
  return $this->getChildHtml('grid');
71
  }
72
 
73
+ /**
74
+ * Sets that do not have the brand attribute
75
+ *
76
+ * @return array
77
+ */
78
  public function setsWithoutBrandAttribute()
79
  {
80
  $sets = array();
81
 
82
  $allSets = Mage::registry('productattribute_sets');
83
+
84
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $set */
85
  foreach ($allSets as $set) {
86
  if ($set->getBrandAttributeCode() == null) {
87
  array_push($sets, $set);
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Edit
16
  extends Mage_Adminhtml_Block_Widget_Form_Container
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
@@ -26,6 +32,11 @@ class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Edit
26
  $this->_removeButton('delete');
27
  }
28
 
 
 
 
 
 
29
  public function getHeaderText()
30
  {
31
  return Mage::registry('productattribute_data')->getAttributeSetName();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Edit
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Edit
19
  extends Mage_Adminhtml_Block_Widget_Form_Container
20
  {
21
+ /**
22
+ * Initialize the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
32
  $this->_removeButton('delete');
33
  }
34
 
35
+ /**
36
+ * Get header text
37
+ *
38
+ * @return mixed
39
+ */
40
  public function getHeaderText()
41
  {
42
  return Mage::registry('productattribute_data')->getAttributeSetName();
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Form.php CHANGED
@@ -12,15 +12,26 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Form
16
  extends Mage_Adminhtml_Block_Widget_Form
17
  {
 
 
 
 
 
18
  protected function _prepareForm()
19
  {
20
  $form = new Varien_Data_Form(
21
  array(
22
  'id' => 'edit_form',
23
- 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
 
 
 
24
  'method' => 'post',
25
  )
26
  );
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Form
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Form
19
  extends Mage_Adminhtml_Block_Widget_Form
20
  {
21
+ /**
22
+ * Prepare form
23
+ *
24
+ * @return Mage_Adminhtml_Block_Widget_Form
25
+ */
26
  protected function _prepareForm()
27
  {
28
  $form = new Varien_Data_Form(
29
  array(
30
  'id' => 'edit_form',
31
+ 'action' => $this->getUrl(
32
+ '*/*/save',
33
+ array('id' => $this->getRequest()->getParam('id'))
34
+ ),
35
  'method' => 'post',
36
  )
37
  );
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Tab/Form/Brand.php CHANGED
@@ -12,9 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Brand
16
  extends Mage_Adminhtml_Block_Widget_Form
17
  {
 
 
 
 
 
18
  protected function _prepareForm()
19
  {
20
  $form = new Varien_Data_Form();
@@ -37,7 +45,8 @@ class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Brand
37
  'label' => Mage::helper('remarketing')->__('Brand Attribute'),
38
  'name' => 'brand_attribute',
39
  'values' => $attributeCodes,
40
- 'value' => Mage::registry('productattribute_data')->getBrandAttributeCode()
 
41
  )
42
  );
43
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Brand
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Brand
19
  extends Mage_Adminhtml_Block_Widget_Form
20
  {
21
+ /**
22
+ * Prepare form
23
+ *
24
+ * @return Mage_Adminhtml_Block_Widget_Form
25
+ */
26
  protected function _prepareForm()
27
  {
28
  $form = new Varien_Data_Form();
45
  'label' => Mage::helper('remarketing')->__('Brand Attribute'),
46
  'name' => 'brand_attribute',
47
  'values' => $attributeCodes,
48
+ 'value' => Mage::registry('productattribute_data')
49
+ ->getBrandAttributeCode()
50
  )
51
  );
52
 
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Tab/Form/Categories.php CHANGED
@@ -12,17 +12,30 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Categories
16
  extends Mage_Adminhtml_Block_Widget
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
21
- $this->setTemplate('listrak/remarketing/productattributes/form/categories.phtml');
 
 
22
 
23
  $this->setModel(Mage::registry('productattribute_data'));
24
  }
25
 
 
 
 
 
 
26
  public function getCategoriesSource()
27
  {
28
  if ($this->getUseConfigCategoriesSource()) {
@@ -32,21 +45,43 @@ class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Catego
32
  return $this->getModel()->getCategoriesSource();
33
  }
34
 
 
 
 
 
 
35
  public function getConfigCategoriesSource()
36
  {
37
- return Mage::helper('remarketing')->categoriesSource();
 
 
38
  }
39
 
 
 
 
 
 
40
  public function getUseConfigCategoriesSource()
41
  {
42
  return $this->getModel()->getUseConfigCategoriesSource();
43
  }
44
 
 
 
 
 
 
45
  public function getCategoryAttributeCode()
46
  {
47
  return $this->getModel()->getCategoryAttributeCode();
48
  }
49
 
 
 
 
 
 
50
  public function getSubcategoryAttributeCode()
51
  {
52
  return $this->getModel()->getSubcategoryAttributeCode();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Categories
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tab_Form_Categories
19
  extends Mage_Adminhtml_Block_Widget
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
27
+ $this->setTemplate(
28
+ 'listrak/remarketing/productattributes/form/categories.phtml'
29
+ );
30
 
31
  $this->setModel(Mage::registry('productattribute_data'));
32
  }
33
 
34
+ /**
35
+ * Retrieve category source
36
+ *
37
+ * @return mixed
38
+ */
39
  public function getCategoriesSource()
40
  {
41
  if ($this->getUseConfigCategoriesSource()) {
45
  return $this->getModel()->getCategoriesSource();
46
  }
47
 
48
+ /**
49
+ * Retrieve stored category source
50
+ *
51
+ * @return mixed
52
+ */
53
  public function getConfigCategoriesSource()
54
  {
55
+ /* @var Listrak_Remarketing_Helper_Data $helper */
56
+ $helper = Mage::helper('remarketing');
57
+ return $helper->categoriesSource();
58
  }
59
 
60
+ /**
61
+ * Retrieve whether the config category is used
62
+ *
63
+ * @return mixed
64
+ */
65
  public function getUseConfigCategoriesSource()
66
  {
67
  return $this->getModel()->getUseConfigCategoriesSource();
68
  }
69
 
70
+ /**
71
+ * Retrieve category attribute code
72
+ *
73
+ * @return mixed
74
+ */
75
  public function getCategoryAttributeCode()
76
  {
77
  return $this->getModel()->getCategoryAttributeCode();
78
  }
79
 
80
+ /**
81
+ * Retrieve subcategory attribute code
82
+ *
83
+ * @return mixed
84
+ */
85
  public function getSubcategoryAttributeCode()
86
  {
87
  return $this->getModel()->getSubcategoryAttributeCode();
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Edit/Tabs.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tabs
16
  extends Mage_Adminhtml_Block_Widget_Tabs
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
@@ -24,14 +30,26 @@ class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tabs
24
  $this->setTitle(Mage::helper('remarketing')->__('Map Attributes'));
25
  }
26
 
 
 
 
 
 
27
  public function _prepareLayout()
28
  {
29
- $attributeCodes = $this->_attributeSetAttributes(Mage::registry('productattribute_data')->getAttributeSetId());
 
 
 
 
 
 
 
30
 
31
  $this->addTab(
32
  'productattributes_brand',
33
  array(
34
- 'label' => Mage::helper('remarketing')->__('Brand'),
35
  'content' => $this->getLayout()->createBlock(
36
  'remarketing/adminhtml_productattributes_edit_tab_form_brand'
37
  )->setAttributeOptions($attributeCodes)->toHtml()
@@ -41,14 +59,23 @@ class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tabs
41
  $this->addTab(
42
  'productattributes_categories',
43
  array(
44
- 'label' => Mage::helper('remarketing')->__('Category and Subcategory'),
45
  'content' => $this->getLayout()->createBlock(
46
  'remarketing/adminhtml_productattributes_edit_tab_form_categories'
47
  )->setAttributeOptions($attributeCodes)->toHtml()
48
  )
49
  );
 
 
50
  }
51
 
 
 
 
 
 
 
 
52
  private function _attributeSetAttributes($setId)
53
  {
54
  $collection = Mage::getResourceModel('catalog/product_attribute_collection')
@@ -57,7 +84,8 @@ class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tabs
57
 
58
  $attributes = array();
59
  foreach ($collection as $value) {
60
- $attributes[$value->getAttributeCode()] = $value->getFrontendLabel()
 
61
  . ' (' . $value->getAttributeCode() . ')';
62
  }
63
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tabs
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Edit_Tabs
19
  extends Mage_Adminhtml_Block_Widget_Tabs
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
30
  $this->setTitle(Mage::helper('remarketing')->__('Map Attributes'));
31
  }
32
 
33
+ /**
34
+ * Prepare layout
35
+ *
36
+ * @return Mage_Core_Block_Abstract
37
+ */
38
  public function _prepareLayout()
39
  {
40
+ /* @var Listrak_Remarketing_Helper_Data $helper */
41
+ $helper = Mage::helper('remarketing');
42
+
43
+ $attributeCodes = $this
44
+ ->_attributeSetAttributes(
45
+ Mage::registry('productattribute_data')
46
+ ->getAttributeSetId()
47
+ );
48
 
49
  $this->addTab(
50
  'productattributes_brand',
51
  array(
52
+ 'label' => $helper->__('Brand'),
53
  'content' => $this->getLayout()->createBlock(
54
  'remarketing/adminhtml_productattributes_edit_tab_form_brand'
55
  )->setAttributeOptions($attributeCodes)->toHtml()
59
  $this->addTab(
60
  'productattributes_categories',
61
  array(
62
+ 'label' => $helper->__('Category and Subcategory'),
63
  'content' => $this->getLayout()->createBlock(
64
  'remarketing/adminhtml_productattributes_edit_tab_form_categories'
65
  )->setAttributeOptions($attributeCodes)->toHtml()
66
  )
67
  );
68
+
69
+ return parent::_prepareLayout();
70
  }
71
 
72
+ /**
73
+ * Retrieve all attribute for am attribute set
74
+ *
75
+ * @param int $setId Set to process
76
+ *
77
+ * @return array
78
+ */
79
  private function _attributeSetAttributes($setId)
80
  {
81
  $collection = Mage::getResourceModel('catalog/product_attribute_collection')
84
 
85
  $attributes = array();
86
  foreach ($collection as $value) {
87
+ $attributes[$value->getAttributeCode()]
88
+ = $value->getFrontendLabel()
89
  . ' (' . $value->getAttributeCode() . ')';
90
  }
91
 
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Grid.php CHANGED
@@ -12,9 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Grid
16
  extends Mage_Adminhtml_Block_Widget_Grid
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
@@ -24,72 +30,97 @@ class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Grid
24
  $this->setSaveParametersInSession(false);
25
  }
26
 
 
 
 
 
 
27
  protected function _prepareCollection()
28
  {
29
  $collection = Mage::registry('productattribute_sets');
30
 
31
  // prepare visible fields
 
32
  foreach ($collection as $item) {
33
  $item->setFrontendCategoriesSource($item->frontendCategoriesSource());
34
  $item->setFrontendBrandAttribute($item->frontendBrandAttribute());
35
  $item->setFrontendCategoryAttribute($item->frontendCategoryAttribute());
36
- $item->setFrontendSubcategoryAttribute($item->frontendSubcategoryAttribute());
 
 
37
  }
38
 
39
  $this->setCollection($collection);
40
  return parent::_prepareCollection();
41
  }
42
 
 
 
 
 
 
43
  protected function _prepareColumns()
44
  {
45
  $this->addColumn(
46
- 'attribute_set', array(
47
- 'header' => Mage::helper('remarketing')->__('Attribute Set Name'),
48
- 'align' => 'left',
49
- 'index' => 'attribute_set_name',
50
- 'filter' => false
51
- )
 
52
  );
53
 
54
  $this->addColumn(
55
- 'brand_attribute', array(
56
- 'header' => Mage::helper('remarketing')->__('Brand Attribute'),
57
- 'align' => 'left',
58
- 'index' => 'frontend_brand_attribute',
59
- 'filter' => false
60
- )
 
61
  );
62
 
63
  $this->addColumn(
64
- 'categories_source', array(
65
- 'header' => Mage::helper('remarketing')->__('Category Source'),
66
- 'align' => 'left',
67
- 'index' => 'frontend_categories_source',
68
- 'filter' => false
69
- )
 
70
  );
71
 
72
  $this->addColumn(
73
- 'category_attribute', array(
74
- 'header' => Mage::helper('remarketing')->__('Category Attribute'),
75
- 'align' => 'left',
76
- 'index' => 'frontend_category_attribute',
77
- 'filter' => false
78
- )
 
79
  );
80
 
81
  $this->addColumn(
82
- 'subcategory_attribute', array(
83
- 'header' => Mage::helper('remarketing')->__('Subcategory Attribute'),
84
- 'align' => 'left',
85
- 'index' => 'frontend_subcategory_attribute',
86
- 'filter' => false
87
- )
 
88
  );
89
 
90
  return parent::_prepareColumns();
91
  }
92
 
 
 
 
 
 
 
 
93
  public function getRowUrl($row)
94
  {
95
  return $this->getUrl('*/*/edit', array('id' => $row->getId()));
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Grid
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_ProductAttributes_Grid
19
  extends Mage_Adminhtml_Block_Widget_Grid
20
  {
21
+ /**
22
+ * Initializes the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
30
  $this->setSaveParametersInSession(false);
31
  }
32
 
33
+ /**
34
+ * Prepare collection for output
35
+ *
36
+ * @return $this
37
+ */
38
  protected function _prepareCollection()
39
  {
40
  $collection = Mage::registry('productattribute_sets');
41
 
42
  // prepare visible fields
43
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $item */
44
  foreach ($collection as $item) {
45
  $item->setFrontendCategoriesSource($item->frontendCategoriesSource());
46
  $item->setFrontendBrandAttribute($item->frontendBrandAttribute());
47
  $item->setFrontendCategoryAttribute($item->frontendCategoryAttribute());
48
+ $item->setFrontendSubcategoryAttribute(
49
+ $item->frontendSubcategoryAttribute()
50
+ );
51
  }
52
 
53
  $this->setCollection($collection);
54
  return parent::_prepareCollection();
55
  }
56
 
57
+ /**
58
+ * Prepare grid columns
59
+ *
60
+ * @return $this
61
+ */
62
  protected function _prepareColumns()
63
  {
64
  $this->addColumn(
65
+ 'attribute_set',
66
+ array(
67
+ 'header' => Mage::helper('remarketing')->__('Attribute Set Name'),
68
+ 'align' => 'left',
69
+ 'index' => 'attribute_set_name',
70
+ 'filter' => false
71
+ )
72
  );
73
 
74
  $this->addColumn(
75
+ 'brand_attribute',
76
+ array(
77
+ 'header' => Mage::helper('remarketing')->__('Brand Attribute'),
78
+ 'align' => 'left',
79
+ 'index' => 'frontend_brand_attribute',
80
+ 'filter' => false
81
+ )
82
  );
83
 
84
  $this->addColumn(
85
+ 'categories_source',
86
+ array(
87
+ 'header' => Mage::helper('remarketing')->__('Category Source'),
88
+ 'align' => 'left',
89
+ 'index' => 'frontend_categories_source',
90
+ 'filter' => false
91
+ )
92
  );
93
 
94
  $this->addColumn(
95
+ 'category_attribute',
96
+ array(
97
+ 'header' => Mage::helper('remarketing')->__('Category Attribute'),
98
+ 'align' => 'left',
99
+ 'index' => 'frontend_category_attribute',
100
+ 'filter' => false
101
+ )
102
  );
103
 
104
  $this->addColumn(
105
+ 'subcategory_attribute',
106
+ array(
107
+ 'header' => Mage::helper('remarketing')->__('Subcategory Attribute'),
108
+ 'align' => 'left',
109
+ 'index' => 'frontend_subcategory_attribute',
110
+ 'filter' => false
111
+ )
112
  );
113
 
114
  return parent::_prepareColumns();
115
  }
116
 
117
+ /**
118
+ * Link to edit the information in a row
119
+ *
120
+ * @param mixed $row Grid row
121
+ *
122
+ * @return string
123
+ */
124
  public function getRowUrl($row)
125
  {
126
  return $this->getUrl('*/*/edit', array('id' => $row->getId()));
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Init/Brands.php CHANGED
@@ -12,29 +12,54 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands
16
  extends Mage_Adminhtml_Block_Template
17
  {
 
 
 
18
  public function __construct()
19
  {
20
  parent::__construct();
21
- $this->setTemplate('listrak/remarketing/productattributes/form/initbrands.phtml');
 
 
22
  }
23
 
 
 
 
 
 
24
  public function _prepareLayout()
25
  {
26
  $this->setChild(
27
  'form',
28
- $this->getLayout()->createBlock('remarketing/adminhtml_productattributes_init_brands_form')
 
 
29
  );
30
  return parent::_prepareLayout();
31
  }
32
 
 
 
 
 
 
33
  public function getFormHtml()
34
  {
35
  return $this->getChildHtml('form');
36
  }
37
 
 
 
 
 
 
38
  public function getFormElementsHtml()
39
  {
40
  return $this->getChildHtml('form-elements');
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands
19
  extends Mage_Adminhtml_Block_Template
20
  {
21
+ /**
22
+ * Initialize the block
23
+ */
24
  public function __construct()
25
  {
26
  parent::__construct();
27
+ $this->setTemplate(
28
+ 'listrak/remarketing/productattributes/form/initbrands.phtml'
29
+ );
30
  }
31
 
32
+ /**
33
+ * Prepare layout
34
+ *
35
+ * @return Mage_Core_Block_Abstract
36
+ */
37
  public function _prepareLayout()
38
  {
39
  $this->setChild(
40
  'form',
41
+ $this->getLayout()->createBlock(
42
+ 'remarketing/adminhtml_productattributes_init_brands_form'
43
+ )
44
  );
45
  return parent::_prepareLayout();
46
  }
47
 
48
+ /**
49
+ * Get the form HTML
50
+ *
51
+ * @return string
52
+ */
53
  public function getFormHtml()
54
  {
55
  return $this->getChildHtml('form');
56
  }
57
 
58
+ /**
59
+ * Get form elements
60
+ *
61
+ * @return string
62
+ */
63
  public function getFormElementsHtml()
64
  {
65
  return $this->getChildHtml('form-elements');
app/code/community/Listrak/Remarketing/Block/Adminhtml/Productattributes/Init/Brands/Form.php CHANGED
@@ -12,9 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands_Form
16
  extends Mage_Adminhtml_Block_Widget_Form
17
  {
 
 
 
 
 
18
  protected function _prepareForm()
19
  {
20
  $form = new Varien_Data_Form(
@@ -55,20 +63,32 @@ class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands_Form
55
  return parent::_prepareForm();
56
  }
57
 
 
 
 
 
 
58
  public function availableAttributes()
59
  {
60
  $everything = Mage::registry('productattribute_sets');
61
  $attributes = array();
62
 
 
63
  foreach ($everything as $item) {
64
  if ($item->getBrandAttributeCode() == null) {
65
- //get the attributes for this attribute set and add them to the attributes array
66
- $collection = Mage::getResourceModel('catalog/product_attribute_collection')
 
 
 
67
  ->setAttributeSetFilter($item->getAttributeSetId())
68
  ->addVisibleFilter();
69
  foreach ($collection as $attribute) {
70
- if (!array_key_exists($attribute->getAttributeCode(), $attributes)) {
71
- $attributes[$attribute->getAttributeCode()] = $attribute->getFrontendLabel()
 
 
 
72
  . ' (' . $attribute->getAttributeCode() . ')';
73
  }
74
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands_Form
17
+ */
18
  class Listrak_Remarketing_Block_Adminhtml_Productattributes_Init_Brands_Form
19
  extends Mage_Adminhtml_Block_Widget_Form
20
  {
21
+ /**
22
+ * Prepare form
23
+ *
24
+ * @return Mage_Adminhtml_Block_Widget_Form
25
+ */
26
  protected function _prepareForm()
27
  {
28
  $form = new Varien_Data_Form(
63
  return parent::_prepareForm();
64
  }
65
 
66
+ /**
67
+ * Attributes that could be the brand attribute
68
+ *
69
+ * @return array
70
+ */
71
  public function availableAttributes()
72
  {
73
  $everything = Mage::registry('productattribute_sets');
74
  $attributes = array();
75
 
76
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $item */
77
  foreach ($everything as $item) {
78
  if ($item->getBrandAttributeCode() == null) {
79
+ //get the attributes for this attribute set
80
+ //and add them to the attributes array
81
+ $collection = Mage::getResourceModel(
82
+ 'catalog/product_attribute_collection'
83
+ )
84
  ->setAttributeSetFilter($item->getAttributeSetId())
85
  ->addVisibleFilter();
86
  foreach ($collection as $attribute) {
87
+ if (!array_key_exists(
88
+ $attribute->getAttributeCode(), $attributes
89
+ )) {
90
+ $attributes[$attribute->getAttributeCode()]
91
+ = $attribute->getFrontendLabel()
92
  . ' (' . $attribute->getAttributeCode() . ')';
93
  }
94
  }
app/code/community/Listrak/Remarketing/Block/Base.php CHANGED
@@ -12,67 +12,163 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Base extends Mage_Core_Block_Template
 
 
 
 
16
  {
17
  private $_alwaysRenderTemplate = false;
18
  private $_lines = array();
19
 
20
- public function _toHtml() {
 
 
 
 
 
 
21
  if ($this->getTemplate()) {
22
- if (!$this->_alwaysRenderTemplate && !trim($this->getScript()))
23
  return "";
 
24
 
25
  return parent::_toHtml();
26
- }
27
- else
28
  return $this->getScript();
 
29
  }
30
 
31
- public function canRender() {
 
 
 
 
 
 
32
  return true;
33
  }
34
 
35
- public function getScript($addWhitespace = true) {
36
- $js = "";
37
- foreach($this->_lines as $line) {
38
- $js .= $line . "\n";
39
- if ($addWhitespace) $js .= " ";
 
 
 
 
 
 
 
 
 
 
40
  }
41
 
42
- return $js . $this->getChildHtml();
43
  }
44
 
45
- protected function addLine($js) {
 
 
 
 
 
 
 
 
46
  $this->_lines[] = $js;
47
  }
48
 
49
- public function jsEscape($value, $quote = "'") {
 
 
 
 
 
 
 
 
 
50
  return addcslashes($value, "\\{$quote}");
51
  }
52
 
53
- public function toJsString($value) {
 
 
 
 
 
 
 
 
54
  return "'{$this->jsEscape($value)}'";
55
  }
56
-
57
- public function setAlwaysRenderTemplate($val) {
 
 
 
 
 
 
 
 
58
  $this->_alwaysRenderTemplate = (bool)$val;
59
  }
60
 
61
- public function isProductPage() {
62
- return Mage::app()->getRequest()->getModuleName() == 'catalog' &&
63
- Mage::app()->getRequest()->getControllerName() == 'product' &&
64
- Mage::app()->getRequest()->getActionName() == 'view';
 
 
 
 
 
 
 
 
65
  }
66
 
67
- public function isCartPage() {
68
- return Mage::app()->getRequest()->getModuleName() == 'checkout' &&
69
- Mage::app()->getRequest()->getControllerName() == 'cart' &&
70
- Mage::app()->getRequest()->getActionName() == 'index';
 
 
 
 
 
 
 
 
71
  }
72
-
73
- public function isOrderConfirmationPage() {
74
- return Mage::app()->getRequest()->getModuleName() == 'checkout' &&
75
- (Mage::app()->getRequest()->getControllerName() == 'multishipping' || Mage::app()->getRequest()->getControllerName() == 'onepage') &&
76
- Mage::app()->getRequest()->getActionName() == 'success';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  }
78
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Base
17
+ */
18
+ class Listrak_Remarketing_Block_Base
19
+ extends Mage_Core_Block_Template
20
  {
21
  private $_alwaysRenderTemplate = false;
22
  private $_lines = array();
23
 
24
+ /**
25
+ * Render block
26
+ *
27
+ * @return string
28
+ */
29
+ public function _toHtml()
30
+ {
31
  if ($this->getTemplate()) {
32
+ if (!$this->_alwaysRenderTemplate && !trim($this->getScript())) {
33
  return "";
34
+ }
35
 
36
  return parent::_toHtml();
37
+ } else {
 
38
  return $this->getScript();
39
+ }
40
  }
41
 
42
+ /**
43
+ * Retrieve whether the block settings allow for rendering
44
+ *
45
+ * @return bool
46
+ */
47
+ public function canRender()
48
+ {
49
  return true;
50
  }
51
 
52
+ /**
53
+ * Retrieve the Javascript code
54
+ *
55
+ * @param bool $addWhitespace Add whitespace characters on each line
56
+ *
57
+ * @return string
58
+ */
59
+ public function getScript($addWhitespace = true)
60
+ {
61
+ $code = "";
62
+ foreach ($this->_lines as $line) {
63
+ $code .= $line . "\n";
64
+ if ($addWhitespace) {
65
+ $code .= " ";
66
+ }
67
  }
68
 
69
+ return $code . $this->getChildHtml();
70
  }
71
 
72
+ /**
73
+ * Adds a JS line to the output
74
+ *
75
+ * @param string $js Javascript line
76
+ *
77
+ * @return void
78
+ */
79
+ protected function addLine($js)
80
+ {
81
  $this->_lines[] = $js;
82
  }
83
 
84
+ /**
85
+ * Escapes special characters in a string
86
+ *
87
+ * @param string $value Value
88
+ * @param string $quote Special quote character
89
+ *
90
+ * @return string
91
+ */
92
+ public function jsEscape($value, $quote = "'")
93
+ {
94
  return addcslashes($value, "\\{$quote}");
95
  }
96
 
97
+ /**
98
+ * Make string JS-friendly
99
+ *
100
+ * @param string $value Value
101
+ *
102
+ * @return string
103
+ */
104
+ public function toJsString($value)
105
+ {
106
  return "'{$this->jsEscape($value)}'";
107
  }
108
+
109
+ /**
110
+ * Set flag to require a template
111
+ *
112
+ * @param mixed $val Value
113
+ *
114
+ * @return void
115
+ */
116
+ public function setAlwaysRenderTemplate($val)
117
+ {
118
  $this->_alwaysRenderTemplate = (bool)$val;
119
  }
120
 
121
+ /**
122
+ * Retrieve whether current page is product page
123
+ *
124
+ * @return bool
125
+ */
126
+ public function isProductPage()
127
+ {
128
+ return (
129
+ Mage::app()->getRequest()->getModuleName() == 'catalog'
130
+ && Mage::app()->getRequest()->getControllerName() == 'product'
131
+ && Mage::app()->getRequest()->getActionName() == 'view'
132
+ );
133
  }
134
 
135
+ /**
136
+ * Retrieve whether current page is cart page
137
+ *
138
+ * @return bool
139
+ */
140
+ public function isCartPage()
141
+ {
142
+ return (
143
+ Mage::app()->getRequest()->getModuleName() == 'checkout'
144
+ && Mage::app()->getRequest()->getControllerName() == 'cart'
145
+ && Mage::app()->getRequest()->getActionName() == 'index'
146
+ );
147
  }
148
+
149
+ /**
150
+ * Retrieve whether current page is order confirmation
151
+ *
152
+ * @return bool
153
+ */
154
+ public function isOrderConfirmationPage()
155
+ {
156
+ $controller = Mage::app()->getRequest()->getControllerName();
157
+
158
+ return (
159
+ Mage::app()->getRequest()->getModuleName() == 'checkout'
160
+ && ($controller == 'multishipping' || $controller == 'onepage')
161
+ && Mage::app()->getRequest()->getActionName() == 'success'
162
+ );
163
+ }
164
+
165
+ /**
166
+ * Logger
167
+ *
168
+ * @return Listrak_Remarketing_Model_Log
169
+ */
170
+ protected function getLogger()
171
+ {
172
+ return Mage::getModel('listrak/log');
173
  }
174
  }
app/code/community/Listrak/Remarketing/Block/Conversion/Abstract.php CHANGED
@@ -12,45 +12,98 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Conversion_Abstract extends Listrak_Remarketing_Block_Require_Onescript
 
 
 
 
16
  {
17
- private $_order, $_customer, $_billingAddress;
 
 
 
18
 
19
- public function _toHtml() {
 
 
 
 
 
 
 
 
 
 
 
 
20
  return parent::_toHtml();
21
  }
22
 
23
- private $_canRender = null;
24
- public function canRender() {
25
- if ($this->_canRender == null)
26
- $this->_canRender = parent::canRender() && $this->isOrderConfirmationPage();
 
 
 
 
 
 
 
27
 
28
  return $this->_canRender;
29
  }
30
 
31
- public function getOrderId() {
 
 
 
 
 
 
32
  return Mage::getSingleton('checkout/session')->getLastOrderId();
33
  }
34
 
35
- public function getOrder() {
36
- if(!$this->_order && $this->_order !== false) {
37
- $order = Mage::getModel('sales/order')->load($this->getOrderId());
38
- $this->_order = $order ? $order : false;
 
 
 
 
 
 
39
  }
40
 
41
  return $this->_order;
42
  }
43
-
44
- public function getOrderConfirmationNumber() {
 
 
 
 
 
 
45
  return $this->getOrder()->getIncrementId();
46
  }
47
 
48
- public function getOrderItems() {
 
 
 
 
 
 
49
  // fix the skus before returning the data
50
  $result = array();
51
 
 
52
  $productHelper = Mage::helper('remarketing/product');
53
- foreach($this->getOrder()->getAllVisibleItems() as $item) {
 
 
54
  $info = $productHelper->getProductInformationFromOrderItem($item);
55
  $item->setSku($info->getSku());
56
 
@@ -60,47 +113,73 @@ class Listrak_Remarketing_Block_Conversion_Abstract extends Listrak_Remarketing_
60
  return $result;
61
  }
62
 
63
- public function getBillingAddress() {
64
- if (!$this->_billingAddress && $this->_billingAddress !== false) {
65
- $addr = $this->getOrder()->getBillingAddress();
66
- $this->_billingAddress = $addr ? $addr : false;
 
 
 
 
 
67
  }
68
 
69
  return $this->_billingAddress;
70
  }
71
 
72
- public function getCustomer() {
73
- if (!$this->_customer && $this->_customer !== false) {
74
- $customer = Mage::getModel('customer/customer')->load($this->getOrder()->getCustomerId());
75
- $this->_customer = $customer ? $customer : false;
 
 
 
 
 
 
76
  }
77
 
78
  return $this->_customer;
79
  }
80
 
81
- public function getEmailAddress() {
 
 
 
 
 
 
82
  if ($this->getCustomer()->getId()) {
83
  return $this->getCustomer()->getEmail();
84
- }
85
- else {
86
  return $this->getOrder()->getCustomerEmail();
87
  }
88
  }
89
 
90
- public function getFirstName() {
 
 
 
 
 
 
91
  if ($this->getCustomer()->getId()) {
92
  return $this->getCustomer()->getFirstname();
93
- }
94
- else {
95
  return $this->getBillingAddress()->getFirstname();
96
  }
97
  }
98
 
99
- public function getLastName() {
 
 
 
 
 
 
100
  if ($this->getCustomer()->getId()) {
101
  return $this->getCustomer()->getLastname();
102
- }
103
- else {
104
  return $this->getBillingAddress()->getLastname();
105
  }
106
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Conversion_Abstract
17
+ */
18
+ class Listrak_Remarketing_Block_Conversion_Abstract
19
+ extends Listrak_Remarketing_Block_Require_Onescript
20
  {
21
+ private $_canRender = null;
22
+
23
+ /* @var Mage_Sales_Model_Order $_order */
24
+ private $_order = null;
25
 
26
+ /* @var Mage_Customer_Model_Customer $_customer */
27
+ private $_customer = null;
28
+
29
+ /* @var Mage_Sales_Model_Order_Address $_billingAddress */
30
+ private $_billingAddress = null;
31
+
32
+ /**
33
+ * Render block
34
+ *
35
+ * @return string
36
+ */
37
+ public function _toHtml()
38
+ {
39
  return parent::_toHtml();
40
  }
41
 
42
+ /**
43
+ * Can render
44
+ *
45
+ * @return bool
46
+ */
47
+ public function canRender()
48
+ {
49
+ if ($this->_canRender == null) {
50
+ $this->_canRender = parent::canRender()
51
+ && $this->isOrderConfirmationPage();
52
+ }
53
 
54
  return $this->_canRender;
55
  }
56
 
57
+ /**
58
+ * Get last order ID
59
+ *
60
+ * @return mixed
61
+ */
62
+ public function getOrderId()
63
+ {
64
  return Mage::getSingleton('checkout/session')->getLastOrderId();
65
  }
66
 
67
+ /**
68
+ * Retrieve order
69
+ *
70
+ * @return Mage_Sales_Model_Order
71
+ */
72
+ public function getOrder()
73
+ {
74
+ if (!$this->_order) {
75
+ $this->_order = Mage::getModel('sales/order')
76
+ ->load($this->getOrderId());
77
  }
78
 
79
  return $this->_order;
80
  }
81
+
82
+ /**
83
+ * Order confirmation number
84
+ *
85
+ * @return string
86
+ */
87
+ public function getOrderConfirmationNumber()
88
+ {
89
  return $this->getOrder()->getIncrementId();
90
  }
91
 
92
+ /**
93
+ * Get ordered items
94
+ *
95
+ * @return Mage_Sales_Model_Order_Item[]
96
+ */
97
+ public function getOrderItems()
98
+ {
99
  // fix the skus before returning the data
100
  $result = array();
101
 
102
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
103
  $productHelper = Mage::helper('remarketing/product');
104
+
105
+ /* @var Mage_Sales_Model_Order_Item $item */
106
+ foreach ($this->getOrder()->getAllVisibleItems() as $item) {
107
  $info = $productHelper->getProductInformationFromOrderItem($item);
108
  $item->setSku($info->getSku());
109
 
113
  return $result;
114
  }
115
 
116
+ /**
117
+ * Get billing address
118
+ *
119
+ * @return Mage_Sales_Model_Order_Address
120
+ */
121
+ public function getBillingAddress()
122
+ {
123
+ if (!$this->_billingAddress) {
124
+ $this->_billingAddress = $this->getOrder()->getBillingAddress();
125
  }
126
 
127
  return $this->_billingAddress;
128
  }
129
 
130
+ /**
131
+ * Get customer
132
+ *
133
+ * @return Mage_Customer_Model_Customer
134
+ */
135
+ public function getCustomer()
136
+ {
137
+ if (!$this->_customer) {
138
+ $this->_customer = Mage::getModel('customer/customer')
139
+ ->load($this->getOrder()->getCustomerId());
140
  }
141
 
142
  return $this->_customer;
143
  }
144
 
145
+ /**
146
+ * Get purchaser email
147
+ *
148
+ * @return string
149
+ */
150
+ public function getEmailAddress()
151
+ {
152
  if ($this->getCustomer()->getId()) {
153
  return $this->getCustomer()->getEmail();
154
+ } else {
 
155
  return $this->getOrder()->getCustomerEmail();
156
  }
157
  }
158
 
159
+ /**
160
+ * Get purchaser first name
161
+ *
162
+ * @return string
163
+ */
164
+ public function getFirstName()
165
+ {
166
  if ($this->getCustomer()->getId()) {
167
  return $this->getCustomer()->getFirstname();
168
+ } else {
 
169
  return $this->getBillingAddress()->getFirstname();
170
  }
171
  }
172
 
173
+ /**
174
+ * Get purchaser last name
175
+ *
176
+ * @return string
177
+ */
178
+ public function getLastName()
179
+ {
180
  if ($this->getCustomer()->getId()) {
181
  return $this->getCustomer()->getLastname();
182
+ } else {
 
183
  return $this->getBillingAddress()->getLastname();
184
  }
185
  }
app/code/community/Listrak/Remarketing/Block/Conversion/Cart.php CHANGED
@@ -12,32 +12,63 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Conversion_Cart extends Listrak_Remarketing_Block_Conversion_Abstract
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
  $this->addLine("_ltk.SCA.Stage = 7;");
23
- $this->addLine("_ltk.SCA.OrderNumber = {$this->toJsString($this->getOrderConfirmationNumber())};");
24
- $this->addLine("_ltk.SCA.SetCustomer("
 
 
 
 
 
 
25
  . $this->toJsString($this->getEmailAddress()) . ", "
26
  . $this->toJsString($this->getFirstName()) . ", "
27
- . $this->toJsString($this->getLastName()) . ");");
 
 
28
  $this->addLine("_ltk.SCA.Submit();");
29
 
30
  return parent::_toHtml();
31
  } catch(Exception $e) {
32
- Mage::getModel('listrak/log')->addException($e);
33
  return '';
34
  }
35
  }
36
 
37
- private $_canRender = null;
38
- public function canRender() {
39
- if ($this->_canRender == null)
40
- $this->_canRender = parent::canRender() && Mage::helper('remarketing')->scaEnabled();
 
 
 
 
 
 
 
 
 
 
41
 
42
  return $this->_canRender;
43
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Conversion_Cart
17
+ */
18
+ class Listrak_Remarketing_Block_Conversion_Cart
19
+ extends Listrak_Remarketing_Block_Conversion_Abstract
20
  {
21
+ private $_canRender = null;
22
+
23
+ /**
24
+ * Render block
25
+ *
26
+ * @return string
27
+ */
28
+ public function _toHtml()
29
+ {
30
  try {
31
+ if (!$this->canRender()) {
32
  return '';
33
+ }
34
 
35
  $this->addLine("_ltk.SCA.Stage = 7;");
36
+ $this->addLine(
37
+ "_ltk.SCA.OrderNumber = "
38
+ . $this->toJsString($this->getOrderConfirmationNumber())
39
+ . ";"
40
+ );
41
+
42
+ $this->addLine(
43
+ "_ltk.SCA.SetCustomer("
44
  . $this->toJsString($this->getEmailAddress()) . ", "
45
  . $this->toJsString($this->getFirstName()) . ", "
46
+ . $this->toJsString($this->getLastName()) . ");"
47
+ );
48
+
49
  $this->addLine("_ltk.SCA.Submit();");
50
 
51
  return parent::_toHtml();
52
  } catch(Exception $e) {
53
+ $this->getLogger()->addException($e);
54
  return '';
55
  }
56
  }
57
 
58
+ /**
59
+ * Can render
60
+ *
61
+ * @return bool
62
+ */
63
+ public function canRender()
64
+ {
65
+ if ($this->_canRender == null) {
66
+ /* @var Listrak_Remarketing_Helper_Data $helper */
67
+ $helper = Mage::helper('remarketing');
68
+
69
+ $this->_canRender = parent::canRender()
70
+ && $helper->scaEnabled();
71
+ }
72
 
73
  return $this->_canRender;
74
  }
app/code/community/Listrak/Remarketing/Block/Conversion/Fingerprint.php CHANGED
@@ -12,16 +12,32 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Conversion_Fingerprint extends Listrak_Remarketing_Block_Require_Sca
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
 
 
 
21
 
22
- return '<img src="' . Mage::helper('remarketing')->getFingerprintImageUrl() . '" width="1" height="1" style="position: absolute" />';
 
 
23
  } catch(Exception $e) {
24
- Mage::getModel('listrak/log')->addException($e);
25
  return '';
26
  }
27
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Conversion_Fingerprint
17
+ */
18
+ class Listrak_Remarketing_Block_Conversion_Fingerprint
19
+ extends Listrak_Remarketing_Block_Require_Sca
20
  {
21
+ /**
22
+ * Render block
23
+ *
24
+ * @return string
25
+ */
26
+ public function _toHtml()
27
+ {
28
  try {
29
+ if (!$this->canRender()) {
30
  return '';
31
+ }
32
+
33
+ /* @var Listrak_Remarketing_Helper_Data $helper */
34
+ $helper = Mage::helper('remarketing');
35
 
36
+ return '<img src="'
37
+ . $helper->getFingerprintImageUrl()
38
+ . '" width="1" height="1" style="position: absolute" />';
39
  } catch(Exception $e) {
40
+ $this->getLogger()->addException($e);
41
  return '';
42
  }
43
  }
app/code/community/Listrak/Remarketing/Block/Conversion/Order.php CHANGED
@@ -12,37 +12,67 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Conversion_Order extends Listrak_Remarketing_Block_Conversion_Abstract
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
- $this->addLine("_ltk.Order.SetCustomer("
 
23
  . $this->toJsString($this->getEmailAddress()) . ", "
24
  . $this->toJsString($this->getFirstName()) . ", "
25
- . $this->toJsString($this->getLastName()) . ");");
26
- $this->addLine("_ltk.Order.OrderNumber = {$this->toJsString($this->getOrderConfirmationNumber())};");
 
 
 
 
 
 
27
 
28
  $order = $this->getOrder();
29
- $this->addLine("_ltk.Order.ItemTotal = {$this->toJsString($order->getSubtotal())};");
30
- //$this->addLine("_ltk.Order.DiscountTotal = {$this->toJsString($order->getDiscountAmount())};");
31
- $this->addLine("_ltk.Order.HandlingTotal = {$this->toJsString($order->getShippingAmount())};");
32
- $this->addLine("_ltk.Order.TaxTotal = {$this->toJsString($order->getTaxAmount())};");
33
- $this->addLine("_ltk.Order.OrderTotal = {$this->toJsString($order->getGrandTotal())};");
34
-
35
- foreach($this->getOrderItems() as $item)
36
- $this->addLine("_ltk.Order.AddItem("
 
 
 
 
 
 
 
 
 
 
37
  . $this->toJsString($item->getSku()) . ", "
38
  . $this->toJsString((int)$item->getQtyOrdered()) . ", "
39
- . $this->toJsString($item->getPrice()) . ");");
 
 
40
 
41
  $this->addLine("_ltk.Order.Submit();");
42
 
43
  return parent::_toHtml();
44
  } catch(Exception $e) {
45
- Mage::getModel('listrak/log')->addException($e);
46
  return '';
47
  }
48
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Conversion_Order
17
+ */
18
+ class Listrak_Remarketing_Block_Conversion_Order
19
+ extends Listrak_Remarketing_Block_Conversion_Abstract
20
  {
21
+ /**
22
+ * Render block
23
+ *
24
+ * @return string
25
+ */
26
+ public function _toHtml()
27
+ {
28
  try {
29
+ if (!$this->canRender()) {
30
  return '';
31
+ }
32
 
33
+ $this->addLine(
34
+ "_ltk.Order.SetCustomer("
35
  . $this->toJsString($this->getEmailAddress()) . ", "
36
  . $this->toJsString($this->getFirstName()) . ", "
37
+ . $this->toJsString($this->getLastName()) . ");"
38
+ );
39
+
40
+ $this->addLine(
41
+ "_ltk.Order.OrderNumber = "
42
+ .$this->toJsString($this->getOrderConfirmationNumber())
43
+ . ";"
44
+ );
45
 
46
  $order = $this->getOrder();
47
+
48
+ $subtotal = $order->getSubtotal();
49
+ $this->addLine("_ltk.Order.ItemTotal = {$this->toJsString($subtotal)};");
50
+
51
+ $shipping = $order->getShippingAmount();
52
+ $this->addLine(
53
+ "_ltk.Order.HandlingTotal = {$this->toJsString($shipping)};"
54
+ );
55
+
56
+ $tax = $order->getTaxAmount();
57
+ $this->addLine("_ltk.Order.TaxTotal = {$this->toJsString($tax)};");
58
+
59
+ $total = $order->getGrandTotal();
60
+ $this->addLine("_ltk.Order.OrderTotal = {$this->toJsString($total)};");
61
+
62
+ foreach ($this->getOrderItems() as $item) {
63
+ $this->addLine(
64
+ "_ltk.Order.AddItem("
65
  . $this->toJsString($item->getSku()) . ", "
66
  . $this->toJsString((int)$item->getQtyOrdered()) . ", "
67
+ . $this->toJsString($item->getPrice()) . ");"
68
+ );
69
+ }
70
 
71
  $this->addLine("_ltk.Order.Submit();");
72
 
73
  return parent::_toHtml();
74
  } catch(Exception $e) {
75
+ $this->getLogger()->addException($e);
76
  return '';
77
  }
78
  }
app/code/community/Listrak/Remarketing/Block/Legacy/Ecjs.php CHANGED
@@ -12,14 +12,28 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
16
  {
17
-
 
 
 
 
18
  public function getPageName()
19
  {
20
  return $this->_getData('page_name');
21
  }
22
 
 
 
 
 
 
23
  public function getMatchingPages()
24
  {
25
  $fullMatches = array();
@@ -44,7 +58,9 @@ class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
44
  if (strtolower($action) == 'index') {
45
  $matches[] = '/' . $route . '/' . $controller;
46
  }
47
- if (strtolower($action) == 'index' && strtolower($controller) == 'index') {
 
 
48
  $matches[] = '/' . $route;
49
  }
50
 
@@ -61,16 +77,23 @@ class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
61
  return $fullMatches;
62
  }
63
 
 
 
 
 
 
64
  protected function _toHtml()
65
  {
66
- if (!Mage::helper('remarketing')->coreEnabled()) {
 
 
 
67
  return "";
68
  }
69
 
70
- $collections = Mage::getModel('listrak/emailcapture')->getCollection()->addFieldToFilter(
71
- 'page',
72
- $this->getMatchingPages()
73
- );
74
 
75
  if ($collections && $collections->count()) {
76
  $html = array();
@@ -78,7 +101,8 @@ class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
78
 
79
  $html[] = '<script type="text/javascript">';
80
  $html[] = 'arrEcjs = [];';
81
- $html[] = 'function _ecjs(ecid,email) { new Ajax.Request("' . $this->getAjaxUrl()
 
82
  . '", {parameters:{cid: ecid, email: email}}); }';
83
  $html[] = 'function ecjsInit() {' .
84
  'for(var ecjsi = 0; ecjsi < arrEcjs.length; ecjsi++) {' .
@@ -91,8 +115,10 @@ class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
91
 
92
  foreach ($collections as $observer) {
93
  if (!in_array($observer->getFieldId(), $observed)) {
94
- $html[] = 'arrEcjs.push({id:"' . $observer->getFieldId()
95
- . '", fn: function() { _ecjs(' . $observer->getEmailcaptureId()
 
 
96
  . ', $(this).value);}});';
97
  $observed[] = $observer->getFieldId();
98
  }
@@ -116,6 +142,11 @@ class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
116
  return "";
117
  }
118
 
 
 
 
 
 
119
  public function getAjaxUrl()
120
  {
121
  return Mage::getUrl(
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Legacy_Ecjs
17
+ *
18
+ * @deprecated Emails now captured through OneScript
19
+ */
20
  class Listrak_Remarketing_Block_Legacy_Ecjs extends Mage_Core_Block_Text
21
  {
22
+ /**
23
+ * Get page name
24
+ *
25
+ * @return mixed
26
+ */
27
  public function getPageName()
28
  {
29
  return $this->_getData('page_name');
30
  }
31
 
32
+ /**
33
+ * Get all routes matching the current page
34
+ *
35
+ * @return array
36
+ */
37
  public function getMatchingPages()
38
  {
39
  $fullMatches = array();
58
  if (strtolower($action) == 'index') {
59
  $matches[] = '/' . $route . '/' . $controller;
60
  }
61
+ if (strtolower($action) == 'index'
62
+ && strtolower($controller) == 'index'
63
+ ) {
64
  $matches[] = '/' . $route;
65
  }
66
 
77
  return $fullMatches;
78
  }
79
 
80
+ /**
81
+ * Render block
82
+ *
83
+ * @return string
84
+ */
85
  protected function _toHtml()
86
  {
87
+ /* @var Listrak_Remarketing_Helper_Data $helper */
88
+ $helper = Mage::helper('remarketing');
89
+
90
+ if (!$helper->coreEnabled()) {
91
  return "";
92
  }
93
 
94
+ $collections = Mage::getModel('listrak/emailcapture')
95
+ ->getCollection()
96
+ ->addFieldToFilter('page', $this->getMatchingPages());
 
97
 
98
  if ($collections && $collections->count()) {
99
  $html = array();
101
 
102
  $html[] = '<script type="text/javascript">';
103
  $html[] = 'arrEcjs = [];';
104
+ $html[] = 'function _ecjs(ecid,email) { new Ajax.Request("'
105
+ . $this->getAjaxUrl()
106
  . '", {parameters:{cid: ecid, email: email}}); }';
107
  $html[] = 'function ecjsInit() {' .
108
  'for(var ecjsi = 0; ecjsi < arrEcjs.length; ecjsi++) {' .
115
 
116
  foreach ($collections as $observer) {
117
  if (!in_array($observer->getFieldId(), $observed)) {
118
+ $html[] = 'arrEcjs.push({id:"'
119
+ . $observer->getFieldId()
120
+ . '", fn: function() { _ecjs('
121
+ . $observer->getEmailcaptureId()
122
  . ', $(this).value);}});';
123
  $observed[] = $observer->getFieldId();
124
  }
142
  return "";
143
  }
144
 
145
+ /**
146
+ * Returns AJAX postback URL
147
+ *
148
+ * @return string
149
+ */
150
  public function getAjaxUrl()
151
  {
152
  return Mage::getUrl(
app/code/community/Listrak/Remarketing/Block/Legacy/Modal.php CHANGED
@@ -12,17 +12,34 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Block_Legacy_Modal extends Mage_Core_Block_Text
16
  {
17
-
 
 
 
 
18
  public function getPageName()
19
  {
20
  return $this->_getData('page_name');
21
  }
22
 
 
 
 
 
 
23
  protected function _toHtml()
24
  {
25
- if (!Mage::helper("remarketing")->coreEnabled()) {
 
 
 
26
  return "";
27
  }
28
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Legacy_Modal
17
+ *
18
+ * @deprecated OneScript now loaded separately, displaying the modal automatically
19
+ */
20
  class Listrak_Remarketing_Block_Legacy_Modal extends Mage_Core_Block_Text
21
  {
22
+ /**
23
+ * Get page name
24
+ *
25
+ * @return mixed
26
+ */
27
  public function getPageName()
28
  {
29
  return $this->_getData('page_name');
30
  }
31
 
32
+ /**
33
+ * Render block
34
+ *
35
+ * @return string
36
+ */
37
  protected function _toHtml()
38
  {
39
+ /* @var Listrak_Remarketing_Helper_Data $helper */
40
+ $helper = Mage::helper('remarketing');
41
+
42
+ if (!$helper->coreEnabled()) {
43
  return "";
44
  }
45
 
app/code/community/Listrak/Remarketing/Block/Require/Activity.php CHANGED
@@ -12,24 +12,48 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Require_Activity extends Listrak_Remarketing_Block_Require_Onescript
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
  return parent::_toHtml();
23
  } catch(Exception $e) {
24
- Mage::getModel('listrak/log')->addException($e);
 
25
  return '';
26
  }
27
  }
28
 
29
- private $_canRender = null;
30
- public function canRender() {
31
- if ($this->_canRender == null)
32
- $this->_canRender = parent::canRender() && Mage::helper('remarketing')->activityEnabled();
 
 
 
 
 
 
 
 
 
 
33
 
34
  return $this->_canRender;
35
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Require_Activity
17
+ */
18
+ class Listrak_Remarketing_Block_Require_Activity
19
+ extends Listrak_Remarketing_Block_Require_Onescript
20
  {
21
+ private $_canRender = null;
22
+
23
+ /**
24
+ * Render block
25
+ *
26
+ * @return string
27
+ */
28
+ public function _toHtml()
29
+ {
30
  try {
31
+ if (!$this->canRender()) {
32
  return '';
33
+ }
34
 
35
  return parent::_toHtml();
36
  } catch(Exception $e) {
37
+ $this->getLogger()->addException($e);
38
+
39
  return '';
40
  }
41
  }
42
 
43
+ /**
44
+ * Can render
45
+ *
46
+ * @return bool
47
+ */
48
+ public function canRender()
49
+ {
50
+ if ($this->_canRender == null) {
51
+ /* @var Listrak_Remarketing_Helper_Data $helper */
52
+ $helper = Mage::helper('remarketing');
53
+
54
+ $this->_canRender = parent::canRender()
55
+ && $helper->activityEnabled();
56
+ }
57
 
58
  return $this->_canRender;
59
  }
app/code/community/Listrak/Remarketing/Block/Require/Legacy.php CHANGED
@@ -12,24 +12,47 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Require_Legacy extends Listrak_Remarketing_Block_Base
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
  return parent::_toHtml();
23
  } catch(Exception $e) {
24
- Mage::getModel('listrak/log')->addException($e);
 
25
  return '';
26
  }
27
  }
28
 
29
- private $_canRender = null;
30
- public function canRender() {
31
- if ($this->_canRender == null)
32
- $this->_canRender = Mage::helper('remarketing')->legacyTracking();
 
 
 
 
 
 
 
 
 
33
 
34
  return $this->_canRender;
35
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Require_Legacy
17
+ */
18
+ class Listrak_Remarketing_Block_Require_Legacy
19
+ extends Listrak_Remarketing_Block_Base
20
  {
21
+ private $_canRender = null;
22
+
23
+ /**
24
+ * Render block
25
+ *
26
+ * @return string
27
+ */
28
+ public function _toHtml()
29
+ {
30
  try {
31
+ if (!$this->canRender()) {
32
  return '';
33
+ }
34
 
35
  return parent::_toHtml();
36
  } catch(Exception $e) {
37
+ $this->getLogger()->addException($e);
38
+
39
  return '';
40
  }
41
  }
42
 
43
+ /**
44
+ * Can render
45
+ *
46
+ * @return bool
47
+ */
48
+ public function canRender()
49
+ {
50
+ if ($this->_canRender == null) {
51
+ /* @var Listrak_Remarketing_Helper_Data $helper */
52
+ $helper = Mage::helper('remarketing');
53
+
54
+ $this->_canRender = $helper->legacyTracking();
55
+ }
56
 
57
  return $this->_canRender;
58
  }
app/code/community/Listrak/Remarketing/Block/Require/Onescript.php CHANGED
@@ -12,24 +12,47 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Require_Onescript extends Listrak_Remarketing_Block_Base
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
  return parent::_toHtml();
23
  } catch(Exception $e) {
24
- Mage::getModel('listrak/log')->addException($e);
 
25
  return '';
26
  }
27
  }
28
 
29
- private $_canRender = null;
30
- public function canRender() {
31
- if ($this->_canRender == null)
32
- $this->_canRender = Mage::helper('remarketing')->onescriptTracking();
 
 
 
 
 
 
 
 
 
33
 
34
  return $this->_canRender;
35
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Require_Onescript
17
+ */
18
+ class Listrak_Remarketing_Block_Require_Onescript
19
+ extends Listrak_Remarketing_Block_Base
20
  {
21
+ private $_canRender = null;
22
+
23
+ /**
24
+ * Render block
25
+ *
26
+ * @return string
27
+ */
28
+ public function _toHtml()
29
+ {
30
  try {
31
+ if (!$this->canRender()) {
32
  return '';
33
+ }
34
 
35
  return parent::_toHtml();
36
  } catch(Exception $e) {
37
+ $this->getLogger()->addException($e);
38
+
39
  return '';
40
  }
41
  }
42
 
43
+ /**
44
+ * Can render
45
+ *
46
+ * @return bool
47
+ */
48
+ public function canRender()
49
+ {
50
+ if ($this->_canRender == null) {
51
+ /* @var Listrak_Remarketing_Helper_Data $helper */
52
+ $helper = Mage::helper('remarketing');
53
+
54
+ $this->_canRender = $helper->onescriptTracking();
55
+ }
56
 
57
  return $this->_canRender;
58
  }
app/code/community/Listrak/Remarketing/Block/Require/Sca.php CHANGED
@@ -12,24 +12,48 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Require_Sca extends Listrak_Remarketing_Block_Require_Onescript
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
  return parent::_toHtml();
23
  } catch(Exception $e) {
24
- Mage::getModel('listrak/log')->addException($e);
 
25
  return '';
26
  }
27
  }
28
 
29
- private $_canRender = null;
30
- public function canRender() {
31
- if ($this->_canRender == null)
32
- $this->_canRender = parent::canRender() && Mage::helper('remarketing')->scaEnabled();
 
 
 
 
 
 
 
 
 
 
33
 
34
  return $this->_canRender;
35
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Require_Sca
17
+ */
18
+ class Listrak_Remarketing_Block_Require_Sca
19
+ extends Listrak_Remarketing_Block_Require_Onescript
20
  {
21
+ private $_canRender = null;
22
+
23
+ /**
24
+ * Render block
25
+ *
26
+ * @return string
27
+ */
28
+ public function _toHtml()
29
+ {
30
  try {
31
+ if (!$this->canRender()) {
32
  return '';
33
+ }
34
 
35
  return parent::_toHtml();
36
  } catch(Exception $e) {
37
+ $this->getLogger()->addException($e);
38
+
39
  return '';
40
  }
41
  }
42
 
43
+ /**
44
+ * Can render
45
+ *
46
+ * @return bool
47
+ */
48
+ public function canRender()
49
+ {
50
+ if ($this->_canRender == null) {
51
+ /* @var Listrak_Remarketing_Helper_Data $helper */
52
+ $helper = Mage::helper('remarketing');
53
+
54
+ $this->_canRender = parent::canRender()
55
+ && $helper->scaEnabled();
56
+ }
57
 
58
  return $this->_canRender;
59
  }
app/code/community/Listrak/Remarketing/Block/Tracking/Activity.php CHANGED
@@ -12,32 +12,55 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Tracking_Activity extends Listrak_Remarketing_Block_Require_Activity
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
- $sku = $this->getProductSku();
23
- if ($sku)
24
- $this->addLine("_ltk.Activity.AddProductBrowse({$this->toJsString($sku)});");
25
- else
 
 
26
  $this->addLine("_ltk.Activity.AddPageBrowse(location.href);");
 
 
27
  $this->addLine("_ltk.Activity.Submit();");
28
 
29
  return parent::_toHtml();
30
  } catch(Exception $e) {
31
- Mage::getModel('listrak/log')->addException($e);
 
32
  return '';
33
  }
34
  }
35
 
36
- private function getProductSku() {
 
 
 
 
 
 
37
  if ($this->isProductPage()) {
38
- $p = Mage::registry('current_product');
39
- if ($p)
40
- return $p->getSku();
 
41
  }
42
 
43
  return null;
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Tracking_Activity
17
+ */
18
+ class Listrak_Remarketing_Block_Tracking_Activity
19
+ extends Listrak_Remarketing_Block_Require_Activity
20
  {
21
+ /**
22
+ * Render block
23
+ *
24
+ * @return string
25
+ */
26
+ public function _toHtml()
27
+ {
28
  try {
29
+ if (!$this->canRender()) {
30
  return '';
31
+ }
32
 
33
+ $sku = $this->_getProductSku();
34
+ if ($sku) {
35
+ $this->addLine(
36
+ "_ltk.Activity.AddProductBrowse({$this->toJsString($sku)});"
37
+ );
38
+ } else {
39
  $this->addLine("_ltk.Activity.AddPageBrowse(location.href);");
40
+ }
41
+
42
  $this->addLine("_ltk.Activity.Submit();");
43
 
44
  return parent::_toHtml();
45
  } catch(Exception $e) {
46
+ $this->getLogger()->addException($e);
47
+
48
  return '';
49
  }
50
  }
51
 
52
+ /**
53
+ * Retrieve browsed sku, if any
54
+ *
55
+ * @return string|null
56
+ */
57
+ private function _getProductSku()
58
+ {
59
  if ($this->isProductPage()) {
60
+ $product = Mage::registry('current_product');
61
+ if ($product) {
62
+ return $product->getSku();
63
+ }
64
  }
65
 
66
  return null;
app/code/community/Listrak/Remarketing/Block/Tracking/Click.php CHANGED
@@ -12,19 +12,30 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Tracking_Click extends Listrak_Remarketing_Block_Require_Onescript
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
  $this->addLine("_ltk.Click.Submit();");
23
 
24
  return parent::_toHtml();
25
  }
26
  catch(Exception $e) {
27
- Mage::getModel('listrak/log')->addException($e);
28
  return '';
29
  }
30
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Tracking_Click
17
+ */
18
+ class Listrak_Remarketing_Block_Tracking_Click
19
+ extends Listrak_Remarketing_Block_Require_Onescript
20
  {
21
+ /**
22
+ * Render block
23
+ *
24
+ * @return string
25
+ */
26
+ public function _toHtml()
27
+ {
28
  try {
29
+ if (!$this->canRender()) {
30
  return '';
31
+ }
32
 
33
  $this->addLine("_ltk.Click.Submit();");
34
 
35
  return parent::_toHtml();
36
  }
37
  catch(Exception $e) {
38
+ $this->getLogger()->addException($e);
39
  return '';
40
  }
41
  }
app/code/community/Listrak/Remarketing/Block/Tracking/Email.php CHANGED
@@ -12,36 +12,67 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Tracking_Email extends Listrak_Remarketing_Block_Require_Sca
 
 
 
 
16
  {
17
- public function _toHtml() {
 
 
 
 
 
 
18
  try {
19
- if (!$this->canRender())
20
  return '';
 
21
 
22
- foreach($this->getFields() as $field)
23
- $this->addLine("_ltk.SCA.CaptureEmail({$this->toJsString($field)});");
 
 
 
24
 
25
  return parent::_toHtml();
26
  } catch(Exception $e) {
27
- Mage::getModel('listrak/log')->addException($e);
28
  return '';
29
  }
30
  }
31
 
32
- public function getFields() {
33
- $collection = Mage::getModel('listrak/emailcapture')
34
- ->getCollection()
35
- ->addFieldToFilter('page', array('in' => $this->_getMatchingPages()));
 
 
 
 
 
 
 
 
 
 
36
 
37
  $result = array();
38
- foreach($collection as $field)
39
  $result[] = $field->getFieldId();
 
40
 
41
  return $result;
42
  }
43
 
44
- private function _getMatchingPages() {
 
 
 
 
 
 
45
  $fullMatches = array();
46
 
47
  try {
@@ -64,7 +95,9 @@ class Listrak_Remarketing_Block_Tracking_Email extends Listrak_Remarketing_Block
64
  if (strtolower($action) == 'index') {
65
  $matches[] = '/' . $route . '/' . $controller;
66
  }
67
- if (strtolower($action) == 'index' && strtolower($controller) == 'index') {
 
 
68
  $matches[] = '/' . $route;
69
  }
70
 
@@ -75,7 +108,7 @@ class Listrak_Remarketing_Block_Tracking_Email extends Listrak_Remarketing_Block
75
  }
76
  }
77
  } catch (Exception $ex) {
78
- Mage::getModel("listrak/log")->addException($ex);
79
  }
80
 
81
  return $fullMatches;
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Tracking_Email
17
+ */
18
+ class Listrak_Remarketing_Block_Tracking_Email
19
+ extends Listrak_Remarketing_Block_Require_Sca
20
  {
21
+ /**
22
+ * Render block
23
+ *
24
+ * @return string
25
+ */
26
+ public function _toHtml()
27
+ {
28
  try {
29
+ if (!$this->canRender()) {
30
  return '';
31
+ }
32
 
33
+ foreach ($this->getFields() as $field) {
34
+ $this->addLine(
35
+ "_ltk.SCA.CaptureEmail({$this->toJsString($field)});"
36
+ );
37
+ }
38
 
39
  return parent::_toHtml();
40
  } catch(Exception $e) {
41
+ $this->getLogger()->addException($e);
42
  return '';
43
  }
44
  }
45
 
46
+ /**
47
+ * Get fields to capture on current page
48
+ *
49
+ * @return array
50
+ */
51
+ public function getFields()
52
+ {
53
+ /* @var Listrak_Remarketing_Model_Mysql4_Emailcapture_Collection $col */
54
+ $col = Mage::getModel('listrak/emailcapture')
55
+ ->getCollection();
56
+
57
+ $col->addFieldToFilter(
58
+ 'page', array('in' => $this->_getMatchingPages())
59
+ );
60
 
61
  $result = array();
62
+ foreach ($col as $field) {
63
  $result[] = $field->getFieldId();
64
+ }
65
 
66
  return $result;
67
  }
68
 
69
+ /**
70
+ * Retrieve all routes leading to this page
71
+ *
72
+ * @return array
73
+ */
74
+ private function _getMatchingPages()
75
+ {
76
  $fullMatches = array();
77
 
78
  try {
95
  if (strtolower($action) == 'index') {
96
  $matches[] = '/' . $route . '/' . $controller;
97
  }
98
+ if (strtolower($action) == 'index'
99
+ && strtolower($controller) == 'index'
100
+ ) {
101
  $matches[] = '/' . $route;
102
  }
103
 
108
  }
109
  }
110
  } catch (Exception $ex) {
111
+ $this->getLogger()->addException($ex);
112
  }
113
 
114
  return $fullMatches;
app/code/community/Listrak/Remarketing/Block/Tracking/Sca.php CHANGED
@@ -12,75 +12,160 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Block_Tracking_Sca extends Listrak_Remarketing_Block_Require_Sca
 
 
 
 
16
  {
17
  private $_initialized = false;
 
 
18
  private $_convertSession = null;
19
 
20
- public function _toHtml() {
 
 
 
 
 
 
21
  try {
22
- if (!$this->canRender())
23
  return '';
24
-
25
- if ($this->hasAjaxScript()) {
26
- $this->addLine("document.observe('dom:loaded', function() { Listrak_Remarketing.track(); });");
27
  }
28
- else {
29
- $this->addCustomerJS();
30
- if (!$this->addCartJS())
 
 
 
 
 
 
 
 
 
31
  $this->addLine("_ltk.SCA.Submit();");
 
32
  }
33
 
34
  return parent::_toHtml();
35
  } catch(Exception $e) {
36
- Mage::getModel('listrak/log')->addException($e);
 
37
  return '';
38
  }
39
  }
40
 
41
- public function getCartJavascript() {
 
 
 
 
 
 
42
  $this->_ensureLoaded();
43
 
44
- $noSubmit = $this->addCartJS(true);
45
- if (trim($this->getScript()) && !$noSubmit)
46
  $this->addLine("_ltk.SCA.Submit();");
 
47
 
48
  return $this->getScript(false);
49
  }
50
 
51
  private $_canRender = null;
52
- public function canRender() {
 
 
 
 
 
 
 
53
  $this->_ensureLoaded();
54
- if ($this->_canRender == null)
55
- $this->_canRender = parent::canRender() && !$this->isOrderConfirmationPage() && ($this->hasAjaxScript() || $this->hasCartJS() || $this->hasCustomerJS());
 
 
 
 
 
 
 
56
 
57
  return $this->_canRender;
58
  }
59
 
60
- private function hasAjaxScript() {
61
- return $this->getFullPageRendering() && Mage::helper('remarketing')->ajaxTracking();
 
 
 
 
 
 
 
 
 
 
62
  }
63
 
64
- private function hasSessionToConvert() {
65
- return $this->_convertSession != null && $this->_convertSession->getId() && !$this->_convertSession->getConverted();
 
 
 
 
 
 
 
 
66
  }
67
 
68
- private function hasCartJS() {
69
- return $this->hasSessionToConvert()
 
 
 
 
 
 
70
  || Mage::getSingleton('checkout/session')->getListrakCartModified()
71
  || $this->isCartPage();
72
  }
73
 
74
- private function addCartJS($forceRender = false) {
 
 
 
 
 
 
 
 
75
  $noSubmit = false;
76
 
77
- if ($forceRender || $this->hasCartJS()) {
78
- if ($this->hasSessionToConvert()) {
79
- $this->addLine("_ltk.SCA.SetSessionID({$this->toJsString($this->_convertSession->getSessionId())});");
 
 
 
 
80
 
81
  $emails = $this->_convertSession->getEmails();
82
- if (count($emails) > 0 && !Mage::getSingleton('customer/session')->isLoggedIn())
83
- $this->addLine("_ltk.SCA.SetCustomer({$this->toJsString($emails[0]['email'])}, '', '');");
 
 
 
 
 
 
 
 
84
  }
85
 
86
  $chkSession = Mage::getSingleton('checkout/session');
@@ -88,21 +173,22 @@ class Listrak_Remarketing_Block_Tracking_Sca extends Listrak_Remarketing_Block_R
88
  $this->addLine("_ltk.SCA.Stage = 1;");
89
 
90
  if (Mage::getSingleton('checkout/cart')->getSummaryQty() > 0) {
91
- foreach($this->getCartItems() as $item) {
92
- $this->addLine("_ltk.SCA.AddItemWithLinks("
93
- . $this->toJsString($item->getSku()) . ", "
94
- . $this->toJsString($item->getQty()) . ", "
95
- . $this->toJsString($item->getPrice()) . ", "
96
- . $this->toJsString($item->getName()) . ", "
97
- . $this->toJsString($item->getImageUrl()) . ", "
98
- . $this->toJsString($item->getProductUrl()) . ");");
 
 
99
  }
100
 
101
- $ltksid = $this->getBasketId();
102
  $this->addLine("_ltk.SCA.Meta1 = {$this->toJsString($ltksid)};");
103
  $chkSession->setCartLtksid($ltksid);
104
- }
105
- else {
106
  $this->addLine("_ltk.SCA.ClearCart();");
107
  $noSubmit = true;
108
  // _ltk.SCA.Submit is called by _ltk.SCA.ClearCart
@@ -110,7 +196,7 @@ class Listrak_Remarketing_Block_Tracking_Sca extends Listrak_Remarketing_Block_R
110
 
111
  $chkSession->unsListrakCartModified();
112
 
113
- if ($this->hasSessionToConvert()) {
114
  $this->_convertSession->setConverted(true);
115
  $this->_convertSession->save();
116
  $this->_convertSession->deleteCookie();
@@ -120,31 +206,65 @@ class Listrak_Remarketing_Block_Tracking_Sca extends Listrak_Remarketing_Block_R
120
  return $noSubmit;
121
  }
122
 
123
- private function hasCustomerJS() {
 
 
 
 
 
 
 
124
  $custSession = Mage::getSingleton('customer/session');
125
- return $custSession->isLoggedIn() && !$custSession->getListrakCustomerTracked();
 
 
126
  }
127
 
128
- private function addCustomerJS() {
129
- if ($this->hasCustomerJS()) {
 
 
 
 
 
 
 
130
  $custSession = Mage::getSingleton('customer/session');
 
131
  $cust = $custSession->getCustomer();
132
 
133
- $this->addLine("_ltk.SCA.SetCustomer("
 
134
  . $this->toJsString($cust->getEmail()) . ", "
135
  . $this->toJsString($cust->getFirstname()) . ", "
136
- . $this->toJsString($cust->getLastname()) . ");");
 
137
 
138
  $custSession->setListrakCustomerTracked(true);
139
  }
140
  }
141
 
142
- private function getCartItems() {
 
 
 
 
 
 
143
  $result = array();
144
 
 
145
  $productHelper = Mage::helper('remarketing/product');
146
- foreach (Mage::getSingleton('checkout/cart')->getQuote()->getAllVisibleItems() as $item) {
147
- $info = $productHelper->getProductInformationFromQuoteItem($item, array('product_url', 'image_url'));
 
 
 
 
 
 
 
 
148
 
149
  $item->setSku($info->getSku());
150
  $item->setProductUrl($info->getProductUrl());
@@ -156,25 +276,51 @@ class Listrak_Remarketing_Block_Tracking_Sca extends Listrak_Remarketing_Block_R
156
  return $result;
157
  }
158
 
159
- private function getBasketId() {
 
 
 
 
 
 
160
  $storeId = Mage::app()->getStore()->getStoreId();
161
  $quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
162
 
163
  $str = $storeId . ' ' . $quoteId;
164
- while(strlen($str) < 16) // 5 for store ID, 1 for the space, and 10 for the quote ID
 
165
  $str .= ' ' . $quoteId;
 
166
  $str = substr($str, 0, 16);
167
 
168
- return Mage::helper('remarketing')->urlEncrypt($str);
 
 
169
  }
170
 
171
- private function _ensureLoaded() {
 
 
 
 
 
 
172
  if (!$this->_initialized) {
173
- if (Mage::helper('remarketing')->trackingTablesExist())
174
- $this->_convertSession = Mage::getSingleton('listrak/session')->loadFromCookie();
 
 
 
 
 
175
 
176
- if ($this->isOrderConfirmationPage())
177
- Mage::getSingleton('customer/session')->unsListrakCustomerTracked();
 
 
 
 
 
178
 
179
  $this->_initialized = true;
180
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Block_Tracking_Sca
17
+ */
18
+ class Listrak_Remarketing_Block_Tracking_Sca
19
+ extends Listrak_Remarketing_Block_Require_Sca
20
  {
21
  private $_initialized = false;
22
+
23
+ /* @var Listrak_Remarketing_Model_Session $_convertSession */
24
  private $_convertSession = null;
25
 
26
+ /**
27
+ * Render block
28
+ *
29
+ * @return string
30
+ */
31
+ public function _toHtml()
32
+ {
33
  try {
34
+ if (!$this->canRender()) {
35
  return '';
 
 
 
36
  }
37
+
38
+ if ($this->_hasAjaxScript()) {
39
+ $method = "track";
40
+ if ($this->isCartPage())
41
+ $method = "updateCart";
42
+
43
+ $this->addLine(
44
+ "Listrak_Remarketing.{$method}();"
45
+ );
46
+ } else {
47
+ $this->_addCustomerJS();
48
+ if (!$this->_addCartJS()) {
49
  $this->addLine("_ltk.SCA.Submit();");
50
+ }
51
  }
52
 
53
  return parent::_toHtml();
54
  } catch(Exception $e) {
55
+ $this->getLogger()->addException($e);
56
+
57
  return '';
58
  }
59
  }
60
 
61
+ /**
62
+ * Get the cart tracking code
63
+ *
64
+ * @return string
65
+ */
66
+ public function getCartJavascript()
67
+ {
68
  $this->_ensureLoaded();
69
 
70
+ $noSubmit = $this->_addCartJS(true);
71
+ if (trim($this->getScript()) && !$noSubmit) {
72
  $this->addLine("_ltk.SCA.Submit();");
73
+ }
74
 
75
  return $this->getScript(false);
76
  }
77
 
78
  private $_canRender = null;
79
+
80
+ /**
81
+ * Can render the block
82
+ *
83
+ * @return bool
84
+ */
85
+ public function canRender()
86
+ {
87
  $this->_ensureLoaded();
88
+ if ($this->_canRender == null) {
89
+ $this->_canRender = parent::canRender()
90
+ && !$this->isOrderConfirmationPage()
91
+ && (
92
+ $this->_hasAjaxScript()
93
+ || $this->_hasCartJS()
94
+ || $this->_hasCustomerJS()
95
+ );
96
+ }
97
 
98
  return $this->_canRender;
99
  }
100
 
101
+ /**
102
+ * Render the AJAX line
103
+ *
104
+ * @return bool
105
+ */
106
+ private function _hasAjaxScript()
107
+ {
108
+ /* @var Listrak_Remarketing_Helper_Data $helper */
109
+ $helper = Mage::helper('remarketing');
110
+
111
+ return $this->getFullPageRendering()
112
+ && $helper->ajaxTracking();
113
  }
114
 
115
+ /**
116
+ * Has legacy session conversion code
117
+ *
118
+ * @return bool
119
+ */
120
+ private function _hasSessionToConvert()
121
+ {
122
+ return $this->_convertSession != null
123
+ && $this->_convertSession->getId()
124
+ && !$this->_convertSession->getConverted();
125
  }
126
 
127
+ /**
128
+ * Has cart tracking code
129
+ *
130
+ * @return bool
131
+ */
132
+ private function _hasCartJS()
133
+ {
134
+ return $this->_hasSessionToConvert()
135
  || Mage::getSingleton('checkout/session')->getListrakCartModified()
136
  || $this->isCartPage();
137
  }
138
 
139
+ /**
140
+ * Render cart tracking code
141
+ *
142
+ * @param bool $forceRender Flag to render even if nothing changed
143
+ *
144
+ * @return bool
145
+ */
146
+ private function _addCartJS($forceRender = false)
147
+ {
148
  $noSubmit = false;
149
 
150
+ if ($forceRender || $this->_hasCartJS()) {
151
+ if ($this->_hasSessionToConvert()) {
152
+ $this->addLine(
153
+ "_ltk.SCA.SetSessionID("
154
+ . $this->toJsString($this->_convertSession->getSessionId())
155
+ . ");"
156
+ );
157
 
158
  $emails = $this->_convertSession->getEmails();
159
+
160
+ /* @var Mage_Customer_Model_Session $custSession */
161
+ $custSession = Mage::getSingleton('customer/session');
162
+ if (count($emails) > 0 && !$custSession->isLoggedIn()) {
163
+ $this->addLine(
164
+ "_ltk.SCA.SetCustomer("
165
+ . $this->toJsString($emails[0]['email'])
166
+ . ", '', '');"
167
+ );
168
+ }
169
  }
170
 
171
  $chkSession = Mage::getSingleton('checkout/session');
173
  $this->addLine("_ltk.SCA.Stage = 1;");
174
 
175
  if (Mage::getSingleton('checkout/cart')->getSummaryQty() > 0) {
176
+ foreach ($this->_getCartItems() as $item) {
177
+ $this->addLine(
178
+ "_ltk.SCA.AddItemWithLinks("
179
+ . $this->toJsString($item->getSku()) . ", "
180
+ . $this->toJsString($item->getQty()) . ", "
181
+ . $this->toJsString($item->getPrice()) . ", "
182
+ . $this->toJsString($item->getName()) . ", "
183
+ . $this->toJsString($item->getImageUrl()) . ", "
184
+ . $this->toJsString($item->getProductUrl()) . ");"
185
+ );
186
  }
187
 
188
+ $ltksid = $this->_getBasketId();
189
  $this->addLine("_ltk.SCA.Meta1 = {$this->toJsString($ltksid)};");
190
  $chkSession->setCartLtksid($ltksid);
191
+ } else {
 
192
  $this->addLine("_ltk.SCA.ClearCart();");
193
  $noSubmit = true;
194
  // _ltk.SCA.Submit is called by _ltk.SCA.ClearCart
196
 
197
  $chkSession->unsListrakCartModified();
198
 
199
+ if ($this->_hasSessionToConvert()) {
200
  $this->_convertSession->setConverted(true);
201
  $this->_convertSession->save();
202
  $this->_convertSession->deleteCookie();
206
  return $noSubmit;
207
  }
208
 
209
+ /**
210
+ * Has customer tracking code
211
+ *
212
+ * @return bool
213
+ */
214
+ private function _hasCustomerJS()
215
+ {
216
+ /* @var Mage_Customer_Model_Session $custSession */
217
  $custSession = Mage::getSingleton('customer/session');
218
+
219
+ return $custSession->isLoggedIn()
220
+ && !$custSession->getListrakCustomerTracked();
221
  }
222
 
223
+ /**
224
+ * Render customer tracking code
225
+ *
226
+ * @return void
227
+ */
228
+ private function _addCustomerJS()
229
+ {
230
+ if ($this->_hasCustomerJS()) {
231
+ /* @var Mage_Customer_Model_Session $custSession */
232
  $custSession = Mage::getSingleton('customer/session');
233
+
234
  $cust = $custSession->getCustomer();
235
 
236
+ $this->addLine(
237
+ "_ltk.SCA.SetCustomer("
238
  . $this->toJsString($cust->getEmail()) . ", "
239
  . $this->toJsString($cust->getFirstname()) . ", "
240
+ . $this->toJsString($cust->getLastname()) . ");"
241
+ );
242
 
243
  $custSession->setListrakCustomerTracked(true);
244
  }
245
  }
246
 
247
+ /**
248
+ * Retrieve cart items
249
+ *
250
+ * @return Mage_Sales_Model_Quote_Item[]
251
+ */
252
+ private function _getCartItems()
253
+ {
254
  $result = array();
255
 
256
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
257
  $productHelper = Mage::helper('remarketing/product');
258
+
259
+ /* @var Mage_Checkout_Model_Cart $cart */
260
+ $cart = Mage::getSingleton('checkout/cart');
261
+
262
+ /* @var Mage_Sales_Model_Quote_Item $item */
263
+ foreach ($cart->getQuote()->getAllVisibleItems() as $item) {
264
+ $info = $productHelper
265
+ ->getProductInformationFromQuoteItem(
266
+ $item, array('product_url', 'image_url')
267
+ );
268
 
269
  $item->setSku($info->getSku());
270
  $item->setProductUrl($info->getProductUrl());
276
  return $result;
277
  }
278
 
279
+ /**
280
+ * Builds the quote identifier string
281
+ *
282
+ * @return string
283
+ */
284
+ private function _getBasketId()
285
+ {
286
  $storeId = Mage::app()->getStore()->getStoreId();
287
  $quoteId = Mage::getSingleton('checkout/session')->getQuoteId();
288
 
289
  $str = $storeId . ' ' . $quoteId;
290
+ while (strlen($str) < 16) {
291
+ // 5 for store ID, 1 for the space, and 10 for the quote ID
292
  $str .= ' ' . $quoteId;
293
+ }
294
  $str = substr($str, 0, 16);
295
 
296
+ /* @var Listrak_Remarketing_Helper_Data $helper */
297
+ $helper = Mage::helper('remarketing');
298
+ return $helper->urlEncrypt($str);
299
  }
300
 
301
+ /**
302
+ * Loads session information only once
303
+ *
304
+ * @return void
305
+ */
306
+ private function _ensureLoaded()
307
+ {
308
  if (!$this->_initialized) {
309
+ /* @var Listrak_Remarketing_Helper_Data $helper */
310
+ $helper = Mage::helper('remarketing');
311
+
312
+ if ($helper->trackingTablesExist()) {
313
+ /* @var Listrak_Remarketing_Model_Session $session */
314
+ $session = Mage::getSingleton('listrak/session');
315
+ $session->loadFromCookie();
316
 
317
+ $this->_convertSession = $session;
318
+ }
319
+
320
+ if ($this->isOrderConfirmationPage()) {
321
+ Mage::getSingleton('customer/session')
322
+ ->unsListrakCustomerTracked();
323
+ }
324
 
325
  $this->_initialized = true;
326
  }
app/code/community/Listrak/Remarketing/Helper/Data.php CHANGED
@@ -12,23 +12,41 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Helper_Data
16
  extends Mage_Core_Helper_Abstract
17
  {
18
  private $_customerGroups;
19
  private $_categoryRootIdForStores = array();
20
 
 
 
 
 
 
 
 
21
  public function setGroupNameAndGenderNameForCustomer($customer)
22
  {
23
  if ($this->_customerGroups == null) {
24
  $this->_customerGroups = array();
25
- foreach (Mage::getModel('customer/group')->getCollection() as $group) {
26
- $this->_customerGroups[$group['customer_group_id']] = $group['customer_group_code'];
 
 
 
 
 
 
27
  }
28
  }
 
29
  if (array_key_exists($customer->getGroupId(), $this->_customerGroups)) {
30
  $customer->setGroupName($this->_customerGroups[$customer->getGroupId()]);
31
  }
 
32
  $customer->setGenderName(
33
  Mage::getResourceSingleton('customer/customer')
34
  ->getAttribute('gender')
@@ -37,11 +55,17 @@ class Listrak_Remarketing_Helper_Data
37
  );
38
  }
39
 
 
 
 
 
 
40
  public function genUuid()
41
  {
42
  // 32 bits for "time_low"
43
  // 16 bits for "time_mid"
44
- // 16 bits for "time_hi_and_version", four most significant bits holds version number 4
 
45
  // 16 bits, 8 bits for "clk_seq_hi_res", 8 bits for "clk_seq_low",
46
  // two most significant bits holds zero and one for variant DCE1.1
47
  // 48 bits for "node"
@@ -55,199 +79,459 @@ class Listrak_Remarketing_Helper_Data
55
  );
56
  }
57
 
 
 
 
 
 
 
 
 
58
  public function generateAndLogException($exceptionText, $sourceException)
59
  {
60
- $ex = new Exception($exceptionText, 0, $sourceException);
61
- Mage::getModel("listrak/log")->addException($ex);
62
- return $ex;
 
 
 
 
63
  }
64
 
 
 
 
 
 
65
  public function checkSetupStatus()
66
  {
67
- return Mage::getStoreConfig('remarketing/config/account_created');
68
  }
69
 
 
 
 
 
 
70
  public function displayAttributeSetNotification()
71
  {
72
- return (Mage::helper('remarketing/product_attribute_set_map')->newAttributeSetsCollection()->count() > 0);
 
 
73
  }
74
 
 
 
 
 
 
75
  public function coreEnabled()
76
  {
77
- return Mage::getStoreConfig('remarketing/modules/core');
78
  }
79
 
 
 
 
 
 
 
 
80
  public function requireCoreEnabled()
81
  {
82
  if (!$this->coreEnabled()) {
83
- throw new Exception('Listrak core functionality has been turned off in the System Configuration.');
 
 
84
  }
85
  }
86
 
87
- public function onescriptEnabled() {
88
- return ($this->coreEnabled()
89
- && Mage::getStoreConfig('remarketing/modal/enabled')
90
- && strlen(trim(Mage::getStoreConfig('remarketing/modal/listrakMerchantID'))) >= 12);
 
 
 
 
 
 
 
 
91
  }
92
 
93
- public function scaEnabled() {
94
- return ($this->onescriptTracking() && Mage::getStoreConfig('remarketing/modal/sca'));
 
 
 
 
 
 
 
95
  }
96
 
97
- public function activityEnabled() {
98
- return ($this->onescriptTracking() && Mage::getStoreConfig('remarketing/modal/activity'));
 
 
 
 
 
 
 
99
  }
100
 
101
- public function legacyTracking() {
 
 
 
 
 
 
102
  return $this->coreEnabled()
103
  && $this->trackingTablesExist()
104
  && !$this->onescriptReady();
105
  }
106
 
107
- public function onescriptTracking() {
108
- return $this->onescriptEnabled() && $this->onescriptReady();
 
 
 
 
 
 
 
109
  }
110
-
111
- public function ajaxTracking() {
112
- return (bool)Mage::getStoreConfig('remarketing/modal/ajax');
 
 
 
 
 
 
113
  }
114
 
 
 
 
 
 
115
  public function reviewsEnabled()
116
  {
117
- return Mage::getStoreConfig('remarketing/modules/reviews');
118
  }
119
 
 
 
 
 
 
 
 
120
  public function requireReviewsEnabled()
121
  {
122
  if (!$this->reviewsEnabled()) {
123
- throw new Exception('Listrak reviews API has been turned off in the System Configuration.');
 
 
124
  }
125
  }
126
-
127
- public function onescriptReady() {
128
- return (bool)Mage::getStoreConfig('remarketing/config/onescript_ready');
 
 
 
 
 
 
129
  }
130
 
131
- public function trackingTablesExist() {
132
- return !Mage::getStoreConfig('remarketing/config/tracking_tables_deleted');
 
 
 
 
 
 
133
  }
134
 
135
- public function requireSessionTrackingTable() {
136
- if (!$this->trackingTablesExist())
137
- throw new Exception('MissingSessionTrackingTable: The session tracking table has been deleted.');
 
 
 
 
 
 
 
 
 
 
 
138
  }
139
 
140
- public function requireClickTrackingTable() {
141
- if (!$this->trackingTablesExist())
142
- throw new Exception('MissingClickTrackingTable: The click tracking table has been deleted.');
 
 
 
 
 
 
 
 
 
 
 
143
  }
144
 
 
 
 
 
 
145
  public function categoriesSource()
146
  {
147
- return Mage::getStoreConfig('remarketing/productcategories/categories_source');
 
 
148
  }
149
 
 
 
 
 
 
150
  public function getCategoryLevel()
151
  {
152
- $cl = (int)Mage::getStoreConfig('remarketing/productcategories/category_level');
153
- if (!$cl) $cl = 3;
 
 
 
 
 
154
 
155
- return $cl;
156
  }
157
 
 
 
 
 
 
 
 
158
  public function getCategoryRootIdForStore($storeId)
159
  {
160
  if (!array_key_exists($storeId, $this->_categoryRootIdForStores)) {
161
- $this->_categoryRootIdForStores[$storeId] = Mage::getModel('core/store_group')
162
- ->load(
163
- Mage::getModel('core/store')
164
- ->load($storeId)
165
- ->getGroupId()
166
- )
 
 
 
167
  ->getRootCategoryId();
168
  }
 
169
  return $this->_categoryRootIdForStores[$storeId];
170
  }
171
 
172
- public function getFingerprintImageUrl() {
173
- $e = Mage::getStoreConfig('remarketing/endpoint/fingerprint');
 
 
 
 
 
 
174
  $tid = Mage::getStoreConfig('remarketing/modal/listrakMerchantID');
175
 
176
- if (!$e)
177
- $e = 'fp.listrakbi.com/fp';
178
- else
179
- $e = trim($e, '/');
 
 
 
 
 
180
 
181
- return (Mage::app()->getStore()->isCurrentlySecure() ? "https:" : "http:") . "//{$e}/{$tid}.jpg";
182
  }
183
 
184
- public function onescriptSrc() {
185
- $e = Mage::getStoreConfig('remarketing/endpoint/onescript');
 
 
 
 
 
 
186
  $tid = Mage::getStoreConfig('remarketing/modal/listrakMerchantID');
187
 
188
- if (!$e)
189
- $e = 'cdn.listrakbi.com/scripts/script.js';
190
- else
191
- $e = trim($e);
 
 
 
 
 
192
 
193
- return (Mage::app()->getStore()->isCurrentlySecure() ? "https:" : "http:") . "//{$e}?m={$tid}&v=1";
194
  }
195
 
196
- public function getInactiveCategories() {
197
- $inactiveIds = Mage::getModel('catalog/category')->getCollection()
 
 
 
 
 
 
 
 
 
198
  ->addAttributeToFilter('is_active', 0);
199
- $inactiveIds->getSelect()
200
  ->reset(Zend_Db_Select::COLUMNS)
201
  ->columns('entity_id');
202
 
203
  $ids = array();
204
- foreach ($inactiveIds as $id) {
205
  $ids[] = intval($id['entity_id']);
206
  }
207
 
208
  return array_filter($ids);
209
  }
210
 
211
- public function getCategoriesToSkip() {
212
- $skip = Mage::getStoreConfig('remarketing/productcategories/categories_skip');
 
 
 
 
 
 
 
 
 
213
  $arr = array_unique(array_map('intval', array_filter(explode(",", $skip))));
 
214
  sort($arr);
215
  return $arr;
216
  }
217
 
218
- public function getMetaDataProvider() {
 
 
 
 
 
 
219
  static $helper = null;
220
 
221
  if ($helper == null) {
222
- $helperRoute = Mage::getStoreConfig('remarketing/advanced/meta_provider');
 
 
 
223
  $helper = $helperRoute ? Mage::helper($helperRoute) : false;
224
  }
225
 
226
  return $helper;
227
  }
228
 
229
- public function urlEncrypt($str) {
230
- return rawurlencode(str_replace('/', '_', Mage::helper('core')->encrypt($str)));
 
 
 
 
 
 
 
 
 
 
 
231
  }
232
 
233
- public function urlDecrypt($str) {
234
- return Mage::helper('core')->decrypt(str_replace('_', '/', rawurldecode($str)));
 
 
 
 
 
 
 
 
 
 
 
235
  }
236
 
237
- public function getTableRowCount($modelEntity) {
238
- return Mage::getSingleton('core/resource')->getConnection('core_read')->fetchOne(
239
- Mage::getModel($modelEntity)->getCollection()->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns('COUNT(*)')
240
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
241
  }
242
 
243
- public function initCartCookie() {
 
 
 
 
 
 
 
 
 
244
  if (!$this->ajaxTracking()) {
245
- $value = md5('quote_' . Mage::getSingleton('checkout/session')->getQuoteId() . '_' . date("YmdHis"));
246
- Mage::getModel('core/cookie')->set('mltkc', $value, time() + 315532800, '/'); // 10 years, 2 of them leap years
 
 
 
 
 
247
  return $value;
248
- }
249
- else {
250
- Mage::getModel('core/cookie')->delete('mltkc');
251
  return 'AJAX';
252
  }
253
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Helper_Data
17
+ */
18
  class Listrak_Remarketing_Helper_Data
19
  extends Mage_Core_Helper_Abstract
20
  {
21
  private $_customerGroups;
22
  private $_categoryRootIdForStores = array();
23
 
24
+ /**
25
+ * Sets API attributes on a customer object
26
+ *
27
+ * @param Mage_Customer_Model_Customer $customer Customer to work with
28
+ *
29
+ * @return void
30
+ */
31
  public function setGroupNameAndGenderNameForCustomer($customer)
32
  {
33
  if ($this->_customerGroups == null) {
34
  $this->_customerGroups = array();
35
+
36
+ /* @var Mage_Customer_Model_Resource_Group $customerGroups */
37
+ $customerGroups = Mage::getModel('customer/group')->getCollection();
38
+ foreach ($customerGroups as $group) {
39
+ $groupId = $group['customer_group_id'];
40
+ $groupCode = $group['customer_group_code'];
41
+
42
+ $this->_customerGroups[$groupId] = $groupCode;
43
  }
44
  }
45
+
46
  if (array_key_exists($customer->getGroupId(), $this->_customerGroups)) {
47
  $customer->setGroupName($this->_customerGroups[$customer->getGroupId()]);
48
  }
49
+
50
  $customer->setGenderName(
51
  Mage::getResourceSingleton('customer/customer')
52
  ->getAttribute('gender')
55
  );
56
  }
57
 
58
+ /**
59
+ * Generate a random UUID
60
+ *
61
+ * @return string
62
+ */
63
  public function genUuid()
64
  {
65
  // 32 bits for "time_low"
66
  // 16 bits for "time_mid"
67
+ // 16 bits for "time_hi_and_version",
68
+ // four most significant bits holds version number 4
69
  // 16 bits, 8 bits for "clk_seq_hi_res", 8 bits for "clk_seq_low",
70
  // two most significant bits holds zero and one for variant DCE1.1
71
  // 48 bits for "node"
79
  );
80
  }
81
 
82
+ /**
83
+ * Creates a new exception based on another
84
+ *
85
+ * @param string $exceptionText Exception message
86
+ * @param Exception $sourceException The exception to wrap
87
+ *
88
+ * @return Exception
89
+ */
90
  public function generateAndLogException($exceptionText, $sourceException)
91
  {
92
+ $exception = new Exception($exceptionText, 0, $sourceException);
93
+
94
+ /* @var Listrak_Remarketing_Model_Log $log */
95
+ $log = Mage::getModel("listrak/log");
96
+
97
+ $log->addException($exception);
98
+ return $exception;
99
  }
100
 
101
+ /**
102
+ * Check whether a Listrak account has been configured
103
+ *
104
+ * @return bool
105
+ */
106
  public function checkSetupStatus()
107
  {
108
+ return Mage::getStoreConfig('remarketing/config/account_created') == '1';
109
  }
110
 
111
+ /**
112
+ * Check whether to display a notification in admin portal
113
+ *
114
+ * @return bool
115
+ */
116
  public function displayAttributeSetNotification()
117
  {
118
+ /* @var Listrak_Remarketing_Helper_Product_Attribute_Set_Map $helper */
119
+ $helper = Mage::helper('remarketing/product_attribute_set_map');
120
+ return ($helper->newAttributeSetsCollection()->count() > 0);
121
  }
122
 
123
+ /**
124
+ * Check whether Listrak core functionality is enabled
125
+ *
126
+ * @return bool
127
+ */
128
  public function coreEnabled()
129
  {
130
+ return Mage::getStoreConfig('remarketing/modules/core') == '1';
131
  }
132
 
133
+ /**
134
+ * Halt execution if Listrak core functionality is disabled
135
+ *
136
+ * @throws Exception
137
+ *
138
+ * @return void
139
+ */
140
  public function requireCoreEnabled()
141
  {
142
  if (!$this->coreEnabled()) {
143
+ throw new Exception(
144
+ 'Listrak core functionality has been turned off in the System Configuration.'
145
+ );
146
  }
147
  }
148
 
149
+ /**
150
+ * Check if the settings allow for OneScript usage
151
+ *
152
+ * @return bool
153
+ */
154
+ public function onescriptEnabled()
155
+ {
156
+ return $this->coreEnabled()
157
+ && Mage::getStoreConfig('remarketing/modal/enabled') == '1'
158
+ && strlen(
159
+ trim(Mage::getStoreConfig('remarketing/modal/listrakMerchantID'))
160
+ ) >= 12;
161
  }
162
 
163
+ /**
164
+ * Check whether OneScript SCA is enabled
165
+ *
166
+ * @return bool
167
+ */
168
+ public function scaEnabled()
169
+ {
170
+ return $this->onescriptTracking()
171
+ && Mage::getStoreConfig('remarketing/modal/sca') == '1';
172
  }
173
 
174
+ /**
175
+ * Check whether OneScript activity tracking is enabled
176
+ *
177
+ * @return bool
178
+ */
179
+ public function activityEnabled()
180
+ {
181
+ return $this->onescriptTracking()
182
+ && Mage::getStoreConfig('remarketing/modal/activity') == '1';
183
  }
184
 
185
+ /**
186
+ * Check whether the module is running in legacy mode
187
+ *
188
+ * @return bool
189
+ */
190
+ public function legacyTracking()
191
+ {
192
  return $this->coreEnabled()
193
  && $this->trackingTablesExist()
194
  && !$this->onescriptReady();
195
  }
196
 
197
+ /**
198
+ * Check whether all tracking is done through OneScript
199
+ *
200
+ * @return bool
201
+ */
202
+ public function onescriptTracking()
203
+ {
204
+ return $this->onescriptEnabled()
205
+ && $this->onescriptReady();
206
  }
207
+
208
+ /**
209
+ * Check whether cart changes are tracked through AJAX calls
210
+ *
211
+ * @return bool
212
+ */
213
+ public function ajaxTracking()
214
+ {
215
+ return Mage::getStoreConfig('remarketing/modal/ajax') == '1';
216
  }
217
 
218
+ /**
219
+ * Check whether review functionality has been enabled
220
+ *
221
+ * @return bool
222
+ */
223
  public function reviewsEnabled()
224
  {
225
+ return Mage::getStoreConfig('remarketing/modules/reviews') == '1';
226
  }
227
 
228
+ /**
229
+ * Halt execution if review functionality is disabled
230
+ *
231
+ * @throws Exception
232
+ *
233
+ * @return void
234
+ */
235
  public function requireReviewsEnabled()
236
  {
237
  if (!$this->reviewsEnabled()) {
238
+ throw new Exception(
239
+ 'Listrak reviews API has been turned off in the System Configuration.'
240
+ );
241
  }
242
  }
243
+
244
+ /**
245
+ * Check whether the module is ready for OneScript tracking
246
+ *
247
+ * @return bool
248
+ */
249
+ public function onescriptReady()
250
+ {
251
+ return Mage::getStoreConfig('remarketing/config/onescript_ready') == '1';
252
  }
253
 
254
+ /**
255
+ * Check whether the session and click tracking tables are available
256
+ *
257
+ * @return bool
258
+ */
259
+ public function trackingTablesExist()
260
+ {
261
+ return Mage::getStoreConfig('remarketing/config/tracking_tables_deleted') != '1';
262
  }
263
 
264
+ /**
265
+ * Halt execution if session tracking tables have been deleted
266
+ *
267
+ * @throws Exception
268
+ *
269
+ * @return void
270
+ */
271
+ public function requireSessionTrackingTable()
272
+ {
273
+ if (!$this->trackingTablesExist()) {
274
+ throw new Exception(
275
+ 'MissingSessionTrackingTable: The session tracking table has been deleted.'
276
+ );
277
+ }
278
  }
279
 
280
+ /**
281
+ * Halt execution if click tracking table is missing
282
+ *
283
+ * @throws Exception
284
+ *
285
+ * @return void
286
+ */
287
+ public function requireClickTrackingTable()
288
+ {
289
+ if (!$this->trackingTablesExist()) {
290
+ throw new Exception(
291
+ 'MissingClickTrackingTable: The click tracking table has been deleted.'
292
+ );
293
+ }
294
  }
295
 
296
+ /**
297
+ * Get the selected category source
298
+ *
299
+ * @return string
300
+ */
301
  public function categoriesSource()
302
  {
303
+ return Mage::getStoreConfig(
304
+ 'remarketing/productcategories/categories_source'
305
+ );
306
  }
307
 
308
+ /**
309
+ * Selected depth of the category tree, or how many categories to skip
310
+ *
311
+ * @return int
312
+ */
313
  public function getCategoryLevel()
314
  {
315
+ $setting = (int)Mage::getStoreConfig(
316
+ 'remarketing/productcategories/category_level'
317
+ );
318
+
319
+ if (!$setting) {
320
+ $setting = 3;
321
+ }
322
 
323
+ return $setting;
324
  }
325
 
326
+ /**
327
+ * Retrieve the root category ID for a store
328
+ *
329
+ * @param int $storeId Magento store ID
330
+ *
331
+ * @return int
332
+ */
333
  public function getCategoryRootIdForStore($storeId)
334
  {
335
  if (!array_key_exists($storeId, $this->_categoryRootIdForStores)) {
336
+ /* @var Mage_Core_Model_Store $store */
337
+ $store = Mage::getModel('core/store')
338
+ ->load($storeId);
339
+
340
+ /* @var Mage_Core_Model_Store_Group $storeGroup */
341
+ $storeGroup = Mage::getModel('core/store_group')
342
+ ->load($store->getGroupId());
343
+
344
+ $this->_categoryRootIdForStores[$storeId] = $storeGroup
345
  ->getRootCategoryId();
346
  }
347
+
348
  return $this->_categoryRootIdForStores[$storeId];
349
  }
350
 
351
+ /**
352
+ * Get fingerprint tracking image URL
353
+ *
354
+ * @return string
355
+ */
356
+ public function getFingerprintImageUrl()
357
+ {
358
+ $endpoint = Mage::getStoreConfig('remarketing/endpoint/fingerprint');
359
  $tid = Mage::getStoreConfig('remarketing/modal/listrakMerchantID');
360
 
361
+ if (!$endpoint) {
362
+ $endpoint = 'fp.listrakbi.com/fp';
363
+ } else {
364
+ $endpoint = trim($endpoint, '/');
365
+ }
366
+
367
+ $protocol = Mage::app()->getStore()->isCurrentlySecure()
368
+ ? "https:"
369
+ : "http:";
370
 
371
+ return "{$protocol}//{$endpoint}/{$tid}.jpg";
372
  }
373
 
374
+ /**
375
+ * Get the OneScript location
376
+ *
377
+ * @return string
378
+ */
379
+ public function onescriptSrc()
380
+ {
381
+ $endpoint = Mage::getStoreConfig('remarketing/endpoint/onescript');
382
  $tid = Mage::getStoreConfig('remarketing/modal/listrakMerchantID');
383
 
384
+ if (!$endpoint) {
385
+ $endpoint = 'cdn.listrakbi.com/scripts/script.js';
386
+ } else {
387
+ $endpoint = trim($endpoint);
388
+ }
389
+
390
+ $protocol = Mage::app()->getStore()->isCurrentlySecure()
391
+ ? "https:"
392
+ : "http:";
393
 
394
+ return "{$protocol}//{$endpoint}?m={$tid}&v=1";
395
  }
396
 
397
+ /**
398
+ * Get all categories disabled by the user
399
+ *
400
+ * @return array
401
+ */
402
+ public function getInactiveCategories()
403
+ {
404
+ /* @var Mage_Catalog_Model_Resource_Category_Collection $collection */
405
+ $collection = Mage::getModel('catalog/category')->getCollection();
406
+
407
+ $collection
408
  ->addAttributeToFilter('is_active', 0);
409
+ $collection->getSelect()
410
  ->reset(Zend_Db_Select::COLUMNS)
411
  ->columns('entity_id');
412
 
413
  $ids = array();
414
+ foreach ($collection as $id) {
415
  $ids[] = intval($id['entity_id']);
416
  }
417
 
418
  return array_filter($ids);
419
  }
420
 
421
+ /**
422
+ * Get all categories to ignore in Listrak code
423
+ *
424
+ * @return array
425
+ */
426
+ public function getCategoriesToSkip()
427
+ {
428
+ $skip = Mage::getStoreConfig(
429
+ 'remarketing/productcategories/categories_skip'
430
+ );
431
+
432
  $arr = array_unique(array_map('intval', array_filter(explode(",", $skip))));
433
+
434
  sort($arr);
435
  return $arr;
436
  }
437
 
438
+ /**
439
+ * Get the Listrak meta data provider, if any
440
+ *
441
+ * @return bool|Mage_Core_Helper_Abstract
442
+ */
443
+ public function getMetaDataProvider()
444
+ {
445
  static $helper = null;
446
 
447
  if ($helper == null) {
448
+ $helperRoute = Mage::getStoreConfig(
449
+ 'remarketing/advanced/meta_provider'
450
+ );
451
+
452
  $helper = $helperRoute ? Mage::helper($helperRoute) : false;
453
  }
454
 
455
  return $helper;
456
  }
457
 
458
+ /**
459
+ * Encrypt data and make ready for URL consumption
460
+ *
461
+ * @param string $str The string to encrypt
462
+ *
463
+ * @return string
464
+ */
465
+ public function urlEncrypt($str)
466
+ {
467
+ /* @var Mage_Core_Helper_Data $coreHelper */
468
+ $coreHelper = Mage::helper('core');
469
+
470
+ return rawurlencode(str_replace('/', '_', $coreHelper->encrypt($str)));
471
  }
472
 
473
+ /**
474
+ * Decrypt URL string
475
+ *
476
+ * @param string $str URL-encrypted string
477
+ *
478
+ * @return string
479
+ */
480
+ public function urlDecrypt($str)
481
+ {
482
+ /* @var Mage_Core_Helper_Data $coreHelper */
483
+ $coreHelper = Mage::helper('core');
484
+
485
+ return $coreHelper->decrypt(str_replace('_', '/', rawurldecode($str)));
486
  }
487
 
488
+ /**
489
+ * Get the number of rows in the database
490
+ *
491
+ * Not all models will be usable by this method, but the ones
492
+ * that the methods is called for are good
493
+ *
494
+ * @param string $modelEntity Magento router to desired model
495
+ *
496
+ * @return int
497
+ */
498
+ public function getTableRowCount($modelEntity)
499
+ {
500
+ /* @var Mage_Core_Model_Resource $resource */
501
+ $resource = Mage::getSingleton('core/resource');
502
+
503
+ $readConnection = $resource->getConnection('core_read');
504
+
505
+ $select = Mage::getModel($modelEntity)
506
+ ->getCollection()
507
+ ->getSelect()
508
+ ->reset(Zend_Db_Select::COLUMNS)
509
+ ->columns('COUNT(*)');
510
+
511
+ return intval($readConnection->fetchOne($select));
512
  }
513
 
514
+ /**
515
+ * Initialize cart tracking cookie
516
+ *
517
+ * @return string
518
+ */
519
+ public function initCartCookie()
520
+ {
521
+ /* @var Mage_Core_Model_Cookie $cookie */
522
+ $cookie = Mage::getModel('core/cookie');
523
+
524
  if (!$this->ajaxTracking()) {
525
+ /* @var Mage_Checkout_Model_Session $session */
526
+ $session = Mage::getSingleton('checkout/session');
527
+
528
+ $value = md5('quote_' . $session->getQuoteId() . '_' . date("YmdHis"));
529
+ $expiration = time() + 315532800; // 10 years, 2 of them leap years
530
+
531
+ $cookie->set('mltkc', $value, $expiration, '/');
532
  return $value;
533
+ } else {
534
+ $cookie->delete('mltkc');
 
535
  return 'AJAX';
536
  }
537
  }
app/code/community/Listrak/Remarketing/Helper/Product.php CHANGED
@@ -12,18 +12,61 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Helper_Product
16
  extends Mage_Core_Helper_Abstract
17
  {
 
18
  private $_parentsById = array();
 
 
19
  private $_urlsById = array();
 
 
 
 
 
20
  private $_attributeSets = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  private $_categories = array();
 
 
22
  private $_useConfigurableParentImages = null;
 
 
 
 
 
 
23
  private $_skipCategories = null;
24
 
25
- public function getProductEntity(Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true)
26
- {
 
 
 
 
 
 
 
 
 
 
27
  $result = array();
28
 
29
  $result['entity_id'] = $product->getEntityId();
@@ -50,31 +93,28 @@ class Listrak_Remarketing_Helper_Product
50
  $result['name'] = $parentProduct->getName();
51
 
52
  if ($parentProduct->isVisibleInSiteVisibility()) {
53
- $result['url_path'] = $this->_getProductUrlWithCache($parentProduct);
 
54
  }
55
  }
56
 
57
- if ($includeExtras && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parentProduct->getTypeId()) {
58
- $result['purchasable'] = $this->_isPurchasable($product, $parentProduct);
 
59
 
60
- $attributes = $parentProduct
61
- ->getTypeInstance(true)
 
62
  ->getUsedProductAttributes($parentProduct);
63
 
64
- $freshProduct = null;
65
  foreach ($attributes as $attribute) {
66
  if (!array_key_exists('configurable_attributes', $result)) {
67
  $result['configurable_attributes'] = array();
68
  }
69
- $attr = array();
70
- $attr['attribute_name'] = $attribute->getFrontend()->getLabel();
71
- $attr['value'] = $product->getAttributeText($attribute->getAttributeCode());
72
- if(empty($attr['value']) ) { // use the EAV tables only if the flat table doesn't work
73
- if ($freshProduct == null)
74
- $freshProduct = Mage::getModel('catalog/product')->load($product->getEntityId());
75
- $attr['value'] = $attribute->getFrontend()->getValue($freshProduct);
76
- }
77
- $result['configurable_attributes'][] = $attr;
78
  }
79
  }
80
  }
@@ -84,50 +124,67 @@ class Listrak_Remarketing_Helper_Product
84
  }
85
 
86
  $images = $this->_getProductImages($product);
87
- if (isset($images['image']))
88
  $result['image'] = $images['image'];
89
- if (isset($images['small_image']))
 
90
  $result['small_image'] = $images['small_image'];
91
- if (isset($images['thumbnail']))
92
- $result['thumbnail'] = $images['thumbnail'];
 
 
93
 
94
  if ($includeExtras) {
95
- // Metas
96
  $metas = $this->_getMetas($storeId, $product, $parentProduct);
97
  if ($metas != null) {
98
- //if(isset($metas['meta1'])) $result['meta1'] = $metas['meta1'];
99
- //if(isset($metas['meta2'])) $result['meta2'] = $metas['meta2'];
100
- if(isset($metas['meta3'])) $result['meta3'] = $metas['meta3'];
101
- if(isset($metas['meta4'])) $result['meta4'] = $metas['meta4'];
102
- if(isset($metas['meta5'])) $result['meta5'] = $metas['meta5'];
 
 
 
 
103
  }
104
 
105
  // Brand and Category
106
- $brandAndCategoryProduct = (!$parentProduct || $product->isVisibleInSiteVisibility()) ? $product : $parentProduct;
107
- $setSettings = $this->_getProductAttributeSetSettings($brandAndCategoryProduct);
 
 
 
108
 
109
  if ($setSettings['brandAttribute'] != null) {
110
- $result['brand'] = $brandAndCategoryProduct->getAttributeText($setSettings['brandAttribute']);
 
111
  }
112
 
113
  if ($setSettings['catFromMagento']) {
114
- $cats = $this->_getCategoryInformation($storeId, $brandAndCategoryProduct);
115
- if (isset($cats['category'])) $result['category'] = $cats['category'];
116
- if (isset($cats['sub_category'])) $result['sub_category'] = $cats['sub_category'];
117
- } else {
118
- if ($setSettings['catFromAttributes']) {
119
- if ($setSettings['categoryAttribute'] != null) {
120
- $result['category'] = $brandAndCategoryProduct->getAttributeText($setSettings['categoryAttribute']);
121
- }
122
-
123
- if ($setSettings['subcategoryAttribute'] != null) {
124
- $result['sub_category'] = $brandAndCategoryProduct->getAttributeText($setSettings['subcategoryAttribute']);
125
- }
 
 
 
126
  }
127
  }
128
 
 
 
129
  // Inventory
130
  $result['in_stock'] = $product->isAvailable() ? "true" : "false";
 
 
131
  $stockItem = $product->getStockItem();
132
  if ($stockItem) {
133
  $result['qty_on_hand'] = $stockItem->getStockQty();
@@ -142,31 +199,100 @@ class Listrak_Remarketing_Helper_Product
142
  return $result;
143
  }
144
 
145
- public function getProductInformationFromQuoteItem(Mage_Sales_Model_Quote_Item $item, $additionalInformation = array()) {
 
 
 
 
 
 
 
 
 
 
 
146
  $children = $item->getChildren();
147
- return $this->_getProductInformationWork($item, $additionalInformation, count($children) > 0, $children);
 
 
148
  }
149
 
150
- public function getProductInformationFromOrderItem(Mage_Sales_Model_Order_Item $item, $additionalInformation = array()) {
151
- return $this->_getProductInformationWork($item, $additionalInformation, $item->getHasChildren(), $item->getChildrenItems());
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  }
153
 
154
- public function getProductUrl(Mage_Catalog_Model_Product $product) {
155
- return substr(Mage::getSingleton('core/url')->parseUrl($product->getProductUrl())->getPath(), 1);
 
 
 
 
 
 
 
 
 
 
 
 
156
  }
157
 
158
- public function getProductImage(Mage_Catalog_Model_Product $product) {
 
 
 
 
 
 
 
 
159
  $images = $this->_getProductImages($product);
160
- if (isset($images['thumbnail']))
 
161
  return $images['thumbnail'];
162
- if (isset($images['small_image']))
 
163
  return $images['small_image'];
164
- if (isset($images['image']))
 
165
  return $images['image'];
 
 
166
  return null;
167
  }
168
-
169
- private function _getProductInformationWork($item, $getInfo, $hasChildren, $children) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
170
  $getProduct = in_array('product', $getInfo);
171
  $getImage = in_array('image_url', $getInfo);
172
  $getLink = in_array('product_url', $getInfo);
@@ -178,28 +304,37 @@ class Listrak_Remarketing_Helper_Product
178
  $result->setIsBundle(false);
179
  $result->setSku($item->getSku());
180
 
181
- if (Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $item->getProductType() && $hasChildren) {
182
  $result->setIsConfigurable(true);
183
 
184
  $result->setParentId($result->getProductId());
185
  $result->setProductId((int)$children[0]->getProductId());
186
  }
187
 
188
- if (Mage_Catalog_Model_Product_Type::TYPE_BUNDLE == $item->getProductType() && $hasChildren) {
189
  $result->setIsBundle(true);
190
 
191
- $product = Mage::getModel('catalog/product')->load($result->getProductId());
 
192
  $result->setSku($product->getSku());
193
  $result->setProduct($product);
194
- }
195
- else if ($getProduct || $getImage || ($getLink && !$result->getIsConfigurable())) {
196
- $result->setProduct(Mage::getModel('catalog/product')->load($result->getProductId()));
 
 
 
 
197
  }
198
 
199
  if ($getLink) {
200
- $result->setProductUrl($this->getProductUrl($result->getIsConfigurable()
201
- ? Mage::getModel('catalog/product')->load($result->getParentId())
202
- : $result->getProduct()));
 
 
 
 
203
  }
204
 
205
  if ($getImage) {
@@ -209,7 +344,15 @@ class Listrak_Remarketing_Helper_Product
209
  return $result;
210
  }
211
 
212
- private function _getProductUrlWithCache(Mage_Catalog_Model_Product $product) {
 
 
 
 
 
 
 
 
213
  $productId = $product->getEntityId();
214
 
215
  if (!isset($this->_urlsById[$productId])) {
@@ -219,12 +362,27 @@ class Listrak_Remarketing_Helper_Product
219
  return $this->_urlsById[$productId];
220
  }
221
 
222
- private function _getProductImages(Mage_Catalog_Model_Product $product) {
 
 
 
 
 
 
 
 
223
  $parent = $this->_getParentProduct($product);
224
- $parentIsConfigurable = $parent && Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $parent->getTypeId();
225
- if ($this->_useConfigurableParentImages == null)
226
- $this->_useConfigurableParentImages = Mage::getStoreConfig(Mage_Checkout_Block_Cart_Item_Renderer_Configurable::CONFIGURABLE_PRODUCT_IMAGE)
227
- == Mage_Checkout_Block_Cart_Item_Renderer_Configurable::USE_PARENT_IMAGE;
 
 
 
 
 
 
 
228
 
229
  $none = 'no_selection';
230
 
@@ -232,40 +390,68 @@ class Listrak_Remarketing_Helper_Product
232
  $smallImage = null;
233
  $thumbnail = null;
234
 
235
- if ($parent && $parentIsConfigurable && $this->_useConfigurableParentImages) {
236
  $image = $parent->getImage();
237
  $smallImage = $parent->getSmallImage();
238
  $thumbnail = $parent->getThumbnail();
239
- }
240
- else {
241
  $image = $product->getImage();
242
- if ($parent && (!$image || $image == $none)) $image = $parent->getImage();
 
 
243
 
244
  $smallImage = $product->getSmallImage();
245
- if ($parent && (!$smallImage || $smallImage == $none)) $smallImage = $parent->getSmallImage();
 
 
246
 
247
  $thumbnail = $product->getThumbnail();
248
- if ($parent && (!$thumbnail || $thumbnail == $none)) $thumbnail = $parent->getThumbnail();
 
 
249
  }
250
 
251
  $result = array();
252
- if ($image && $image != $none) $result['image'] = $image;
253
- if ($smallImage && $smallImage != $none) $result['small_image'] = $smallImage;
254
- if ($thumbnail && $thumbnail != $none) $result['thumbnail'] = $thumbnail;
 
 
 
 
 
 
255
 
256
  return $result;
257
  }
258
 
259
- private function _getParentProduct(Mage_Catalog_Model_Product $product) {
260
- $parentIds = Mage::getModel('catalog/product_type_configurable')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  ->getParentIdsByChild($product->getEntityId());
262
 
263
  if (is_array($parentIds) && count($parentIds) > 0) {
264
  $parentId = $parentIds[0];
265
  if ($parentId != null) {
266
  if (!array_key_exists($parentId, $this->_parentsById)) {
267
- $this->_parentsById[$parentId] = Mage::getModel('catalog/product')
 
268
  ->load($parentId);
 
 
269
  }
270
  return $this->_parentsById[$parentId];
271
  }
@@ -274,25 +460,191 @@ class Listrak_Remarketing_Helper_Product
274
  return null;
275
  }
276
 
277
- private function _isPurchasable(Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Product $parent = null) {
278
- if ($product->getStatus() != Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
279
- return "false";
280
-
281
- if ($parent == null) {
282
- return Mage::getSingleton('listrak/product_purchasable_visibility')
283
- ->isProductPurchasableBySetting(Mage::getStoreConfig('remarketing/productcategories/purchasable_visibility'), $product)
284
- ? "true" : "false";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  }
286
  else {
287
- return $parent->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_ENABLED
288
- && Mage::getSingleton('listrak/product_purchasable_visibility')
289
- ->isProductPurchasableBySetting(Mage::getStoreConfig('remarketing/productcategories/purchasable_visibility'), $parent)
290
- ? "true" : "false";
 
291
  }
292
  }
293
 
294
- private function _getProductAttributeSetSettings(Mage_Catalog_Model_Product $product)
 
 
 
 
 
 
 
 
 
 
295
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  if ($this->_attributeSets == null) {
297
  $this->_attributeSets = array(0 => array(
298
  //default values
@@ -303,119 +655,188 @@ class Listrak_Remarketing_Helper_Product
303
  'subcategoryAttribute' => null
304
  ));
305
 
306
- $attributeSetSettings = Mage::getModel('listrak/product_attribute_set_map')
 
307
  ->getCollection();
308
- foreach ($attributeSetSettings as $setSettings) {
309
- $this->_attributeSets[$setSettings->getAttributeSetId()] = array(
310
- 'brandAttribute' => $setSettings->getBrandAttributeCode(),
311
- 'catFromMagento' => $setSettings->finalCategoriesSource() == 'default',
312
- 'catFromAttributes' => $setSettings->finalCategoriesSource() == 'attributes',
313
- 'categoryAttribute' => $setSettings->getCategoryAttributeCode(),
314
- 'subcategoryAttribute' => $setSettings->getSubcategoryAttributeCode()
 
 
 
 
 
 
 
315
  );
316
  }
317
  }
 
318
  return array_key_exists($product->getAttributeSetId(), $this->_attributeSets)
319
- ? $this->_attributeSets[$product->getAttributeSetId()] : $this->_attributeSets[0];
 
320
  }
321
 
322
- private function _getCategoryInformation($storeId, Mage_Catalog_Model_Product $product) {
323
- $rootLevel = Mage::helper('remarketing')->getCategoryRootIdForStore($storeId);
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  $rootPath = array(1);
325
- if ($rootLevel)
326
  $rootPath[] = $rootLevel;
 
327
 
328
- $categoryLevel = Mage::helper('remarketing')->getCategoryLevel();
329
 
330
  if ($this->_skipCategories == null) {
331
- $this->_skipCategories = array_unique(array_merge(
332
- Mage::helper('remarketing')->getInactiveCategories(),
333
- Mage::helper('remarketing')->getCategoriesToSkip()));
 
 
 
334
  }
335
 
 
336
  $categories = $product->getCategoryCollection();
337
- $path = $this->_getFirstPathByPosition($categories, $categoryLevel + 1, $rootPath);
 
 
338
 
339
  $result = array();
340
- if (isset($path[$categoryLevel - 1])) $result['category'] = $this->_getCategoryField($path[$categoryLevel - 1], 'name');
341
- if (isset($path[$categoryLevel])) $result['sub_category'] = $this->_getCategoryField($path[$categoryLevel], 'name');
 
 
 
 
 
 
342
 
343
  return $result;
344
  }
345
 
346
- private function _getFirstPathByPosition($categoryCollection, $maxLevel, $underPath)
347
- {
348
- if (sizeof($underPath) >= $maxLevel)
 
 
 
 
 
 
 
 
 
 
349
  return $underPath;
 
350
 
351
  $nextCategory = array();
352
- foreach($categoryCollection as $category) {
 
 
353
  $pathIds = $category->getPathIds();
354
 
355
- if (sizeof(array_intersect($pathIds, $this->_skipCategories)) > 0)
356
- // the category tree contains a category that we want skipped or is not active
 
357
  continue;
 
358
 
359
- if (sizeof($pathIds) > sizeof($underPath) && !in_array($pathIds[sizeof($underPath)], $nextCategory)) {
 
 
360
  $isUnderPath = true;
361
- for($i = 0; $i < sizeof($underPath); $i++)
362
- {
363
- if ($pathIds[$i] != $underPath[$i])
364
- {
365
  $isUnderPath = false;
366
  break;
367
  }
368
  }
369
 
370
- if ($isUnderPath)
371
  $nextCategory[] = $pathIds[sizeof($underPath)];
 
372
  }
373
  }
374
 
375
- if (sizeof($nextCategory) == 0)
376
  return $underPath;
 
377
 
378
  $winnerPath = array();
379
  $winnerPathPosition = 0;
380
- foreach($nextCategory as $category)
381
- {
382
  $testPath = $underPath;
383
- $testPath[] = $category;
384
 
385
- $testPathPosition = $this->_getCategoryField($category, 'position');
 
 
386
 
387
- if (sizeof($winnerPath) == 0 || $winnerPathPosition > $testPathPosition)
388
- {
 
389
  $winnerPath = $testPath;
390
  $winnerPathPosition = $testPathPosition;
391
  }
392
  }
393
 
394
- return $this->_getFirstPathByPosition($categoryCollection, $maxLevel, $winnerPath);
 
 
395
  }
396
 
 
 
 
 
 
 
 
 
397
  private function _getCategoryField($categoryId, $field)
398
  {
399
  $category = $this->_getCategory($categoryId);
400
-
401
- if ($category != null)
402
- {
403
  return $category->getData($field);
404
  }
405
 
406
  return null;
407
  }
408
 
 
 
 
 
 
 
 
409
  private function _getCategory($categoryId)
410
  {
411
- if (array_key_exists($categoryId, $this->_categories))
412
  return $this->_categories[$categoryId];
413
- else {
414
- $category = Mage::getModel('catalog/category')
415
- ->load($categoryId);
416
 
417
- if ($category != null)
418
- {
419
  $this->_categories[$categoryId] = $category;
420
  return $category;
421
  }
@@ -424,75 +845,129 @@ class Listrak_Remarketing_Helper_Product
424
  return null;
425
  }
426
 
427
- private function _getProductLinks($product) {
428
- if (!Mage::getStoreConfig('remarketing/productcategories/product_links'))
 
 
 
 
 
 
 
 
 
 
429
  return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
431
- static $_catalog_product_table = null;
432
- if ($_catalog_product_table == null)
433
- // this is done because a query shows up in MySQL with 'SET GLOBAL SQL_MODE = ''; SET NAMES utf8;' that is very costly in a loop
434
- $_catalog_product_table = Mage::getModel('core/resource')->getTableName('catalog/product');
435
 
436
- static $_catalog_product_link_attribute_table = null;
437
- if ($_catalog_product_link_attribute_table == null)
438
- $_catalog_product_link_attribute_table = Mage::getModel('catalog/product_link')->getAttributeTypeTable('int');
439
 
440
  $linkTypes = $this->_getLinkTypes();
441
 
442
- $c = Mage::getModel('catalog/product_link')
 
443
  ->getCollection();
444
- $s = $c->getSelect();
445
- $a = $s->getAdapter();
446
 
447
- $s->where('main_table.product_id = ?', $product->getId())
 
 
448
  ->where('main_table.product_id <> main_table.linked_product_id')
449
  ->where('main_table.link_type_id IN (?)', array_keys($linkTypes));
450
 
451
- $s->join(array('product' => $_catalog_product_table),
 
452
  'main_table.linked_product_id = product.entity_id',
453
- 'sku');
 
454
 
455
  $positionJoinOn = array();
456
- foreach($linkTypes as $linkTypeId => $linkType) {
457
  if ($linkType['positionAttributeId'] != null) {
458
- array_push($positionJoinOn,
459
- $a->quoteInto('main_table.link_type_id = ?', $linkTypeId) . ' AND ' .
460
- $a->quoteInto('attributes.product_link_attribute_id = ?', $linkType['positionAttributeId']));
 
 
 
 
 
 
 
461
  }
462
  }
463
- $s->joinLeft(array('attributes' => $_catalog_product_link_attribute_table),
464
- 'main_table.link_id = attributes.link_id AND ((' . implode(') OR (', $positionJoinOn) . '))',
465
- array('position' => 'value'));
 
 
 
 
 
 
 
466
 
467
  $links = array();
468
- foreach($c as $r) {
469
- array_push($links, array(
470
- 'link_type' => $linkTypes[$r->getLinkTypeId()]['name'],
471
- 'sku' => $r->getSku(),
472
- 'position' => $r->getPosition()
473
- ));
474
  }
475
 
476
  return $links;
477
  }
478
 
479
- private function _getLinkTypes() {
 
 
 
 
 
 
480
  static $_types = null;
481
 
482
  if ($_types == null) {
483
  $allLinks = array(
484
- Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL => array('name' => 'up_sell', 'positionAttributeId' => null),
485
- Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL => array('name' => 'cross_sell', 'positionAttributeId' => null),
486
- Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED => array('name' => 'related', 'positionAttributeId' => null),
487
- Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED => array('name' => 'grouped', 'positionAttributeId' => null)
 
 
 
 
488
  );
489
 
490
- foreach($allLinks as $linkId => &$link) {
491
- $linkAttributes = Mage::getModel('catalog/product_link')
492
- ->setLinkTypeId($linkId)
 
 
493
  ->getAttributes();
494
- foreach($linkAttributes as $attribute) {
495
- if ($attribute['code'] == 'position' && $attribute['type'] == 'int') {
 
 
 
496
  $link['positionAttributeId'] = $attribute['id'];
497
  break;
498
  }
@@ -505,14 +980,69 @@ class Listrak_Remarketing_Helper_Product
505
  return $_types;
506
  }
507
 
508
- private function _getMetas($storeId, Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Product $parentProduct = null) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
509
  try {
510
- $provider = Mage::helper('remarketing')->getMetaDataProvider();
511
- if ($provider)
512
  return $provider->product($storeId, $product, $parentProduct);
 
513
  }
514
  catch(Exception $e) {
515
- Mage::helper('remarketing')->generateAndLogException('Exception retrieving product meta data', $e);
 
 
516
  }
517
 
518
  return null;
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Helper_Product
17
+ */
18
  class Listrak_Remarketing_Helper_Product
19
  extends Mage_Core_Helper_Abstract
20
  {
21
+ /* @var Mage_Catalog_Model_Product[] $_parentsById */
22
  private $_parentsById = array();
23
+
24
+ /* @var string[] $_urlsById */
25
  private $_urlsById = array();
26
+
27
+ /**
28
+ * Attribute set options
29
+ * @var array
30
+ */
31
  private $_attributeSets = null;
32
+
33
+ /**
34
+ * Flag that enables fetching of all attributes' values
35
+ * @var boolean
36
+ */
37
+ private $_retrieveAttributes = null;
38
+
39
+ /**
40
+ * Options to resolve attribute from selected ID to text
41
+ * @var array
42
+ */
43
+ private $_attributeOptions = null;
44
+
45
+ /* @var Mage_Catalog_Model_Category[] $_categories */
46
  private $_categories = array();
47
+
48
+ /* @var bool $_useConfigurableParentImages */
49
  private $_useConfigurableParentImages = null;
50
+
51
+ /**
52
+ * Categories to skip because they have been disabled
53
+ * or are set to be ignored
54
+ * @var int[]
55
+ */
56
  private $_skipCategories = null;
57
 
58
+ /**
59
+ * Inflate an API object from a product object
60
+ *
61
+ * @param Mage_Catalog_Model_Product $product Product
62
+ * @param int $storeId Magento store ID
63
+ * @param bool $includeExtras Retrieve all information
64
+ *
65
+ * @return array
66
+ */
67
+ public function getProductEntity(
68
+ Mage_Catalog_Model_Product $product, $storeId, $includeExtras = true
69
+ ) {
70
  $result = array();
71
 
72
  $result['entity_id'] = $product->getEntityId();
93
  $result['name'] = $parentProduct->getName();
94
 
95
  if ($parentProduct->isVisibleInSiteVisibility()) {
96
+ $result['url_path']
97
+ = $this->_getProductUrlWithCache($parentProduct);
98
  }
99
  }
100
 
101
+ if ($includeExtras && $this->_isConfigurableProduct($parentProduct)) {
102
+ $result['purchasable']
103
+ = $this->_isPurchasable($product, $parentProduct);
104
 
105
+ /* @var Mage_Catalog_Model_Product_Type_Configurable $typeInst */
106
+ $typeInst = $parentProduct->getTypeInstance(true);
107
+ $attributes = $typeInst
108
  ->getUsedProductAttributes($parentProduct);
109
 
110
+ /* @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute */
111
  foreach ($attributes as $attribute) {
112
  if (!array_key_exists('configurable_attributes', $result)) {
113
  $result['configurable_attributes'] = array();
114
  }
115
+
116
+ $result['configurable_attributes'][]
117
+ = array('attribute_name' => $attribute->getAttributeCode());
 
 
 
 
 
 
118
  }
119
  }
120
  }
124
  }
125
 
126
  $images = $this->_getProductImages($product);
127
+ if (isset($images['image'])) {
128
  $result['image'] = $images['image'];
129
+ }
130
+ if (isset($images['small_image'])) {
131
  $result['small_image'] = $images['small_image'];
132
+ }
133
+ if (isset($images['thumbnail'])) {
134
+ $result['thumbnail'] = $images['thumbnail'];
135
+ }
136
 
137
  if ($includeExtras) {
 
138
  $metas = $this->_getMetas($storeId, $product, $parentProduct);
139
  if ($metas != null) {
140
+ if (isset($metas['meta3'])) {
141
+ $result['meta3'] = $metas['meta3'];
142
+ }
143
+ if (isset($metas['meta4'])) {
144
+ $result['meta4'] = $metas['meta4'];
145
+ }
146
+ if (isset($metas['meta5'])) {
147
+ $result['meta5'] = $metas['meta5'];
148
+ }
149
  }
150
 
151
  // Brand and Category
152
+ $brandCatProduct = $product;
153
+ if ($parentProduct && !$product->isVisibleInSiteVisibility()) {
154
+ $brandCatProduct = $parentProduct;
155
+ }
156
+ $setSettings = $this->_getProductAttributeSetSettings($brandCatProduct);
157
 
158
  if ($setSettings['brandAttribute'] != null) {
159
+ $result['brand'] = $this->_getProductAttribute(
160
+ $brandCatProduct, $setSettings['brandAttribute']);
161
  }
162
 
163
  if ($setSettings['catFromMagento']) {
164
+ $cats = $this->_getCategoryInformation($storeId, $brandCatProduct);
165
+ if (isset($cats['category'])) {
166
+ $result['category'] = $cats['category'];
167
+ }
168
+ if (isset($cats['sub_category'])) {
169
+ $result['sub_category'] = $cats['sub_category'];
170
+ }
171
+ } else if ($setSettings['catFromAttributes']) {
172
+ if ($setSettings['categoryAttribute'] != null) {
173
+ $result['category'] = $this->_getProductAttribute(
174
+ $brandCatProduct, $setSettings['categoryAttribute']);
175
+ }
176
+ if ($setSettings['subcategoryAttribute'] != null) {
177
+ $result['sub_category'] = $this->_getProductAttribute(
178
+ $brandCatProduct, $setSettings['subcategoryAttribute']);
179
  }
180
  }
181
 
182
+ $result['attributes'] = $this->_getProductAttributes($product);
183
+
184
  // Inventory
185
  $result['in_stock'] = $product->isAvailable() ? "true" : "false";
186
+
187
+ /* @var Mage_Cataloginventory_Model_Stock_Item $stockItem */
188
  $stockItem = $product->getStockItem();
189
  if ($stockItem) {
190
  $result['qty_on_hand'] = $stockItem->getStockQty();
199
  return $result;
200
  }
201
 
202
+ /**
203
+ * Retrieve product information from a quote item object
204
+ *
205
+ * @param Mage_Sales_Model_Quote_Item $item Quote item
206
+ * @param array $additionalInfo Information to return
207
+ *
208
+ * @return Varien_Object
209
+ */
210
+ public function getProductInformationFromQuoteItem(
211
+ Mage_Sales_Model_Quote_Item $item,
212
+ $additionalInfo = array()
213
+ ) {
214
  $children = $item->getChildren();
215
+ return $this->_getProductInformationWork(
216
+ $item, $additionalInfo, count($children) > 0, $children
217
+ );
218
  }
219
 
220
+ /**
221
+ * Retrieve product information from an order item object
222
+ *
223
+ * @param Mage_Sales_Model_Order_Item $item Order item
224
+ * @param array $additionalInfo Information to return
225
+ *
226
+ * @return Varien_Object
227
+ */
228
+ public function getProductInformationFromOrderItem(
229
+ Mage_Sales_Model_Order_Item $item, $additionalInfo = array()
230
+ ) {
231
+ return $this->_getProductInformationWork(
232
+ $item, $additionalInfo,
233
+ $item->getHasChildren(), $item->getChildrenItems()
234
+ );
235
  }
236
 
237
+ /**
238
+ * Retrieve the relative product URL
239
+ *
240
+ * @param Mage_Catalog_Model_Product $product Product
241
+ *
242
+ * @return string
243
+ */
244
+ public function getProductUrl(Mage_Catalog_Model_Product $product)
245
+ {
246
+ /* @var Mage_Core_Model_Url $urlParser */
247
+ $urlParser = Mage::getSingleton('core/url');
248
+
249
+ $urlParser->parseUrl($product->getProductUrl());
250
+ return substr($urlParser->getPath(), 1);
251
  }
252
 
253
+ /**
254
+ * Returns the image URL
255
+ *
256
+ * @param Mage_Catalog_Model_Product $product Product
257
+ *
258
+ * @return string
259
+ */
260
+ public function getProductImage(Mage_Catalog_Model_Product $product)
261
+ {
262
  $images = $this->_getProductImages($product);
263
+
264
+ if (isset($images['thumbnail'])) {
265
  return $images['thumbnail'];
266
+ }
267
+ if (isset($images['small_image'])) {
268
  return $images['small_image'];
269
+ }
270
+ if (isset($images['image'])) {
271
  return $images['image'];
272
+ }
273
+
274
  return null;
275
  }
276
+
277
+ public function setAttributeOptions($withAttributes, $options)
278
+ {
279
+ $this->_retrieveAttributes = $withAttributes;
280
+ $this->_attributeOptions = $options;
281
+ }
282
+
283
+ /**
284
+ * Retrieve product information from an object with basic information
285
+ *
286
+ * @param mixed $item Object with data
287
+ * @param array $getInfo Additional information to retrieve
288
+ * @param bool $hasChildren Whether the product has children
289
+ * @param array $children Array of product children
290
+ *
291
+ * @return Varien_Object
292
+ */
293
+ private function _getProductInformationWork(
294
+ $item, $getInfo, $hasChildren, $children
295
+ ) {
296
  $getProduct = in_array('product', $getInfo);
297
  $getImage = in_array('image_url', $getInfo);
298
  $getLink = in_array('product_url', $getInfo);
304
  $result->setIsBundle(false);
305
  $result->setSku($item->getSku());
306
 
307
+ if ($this->_isConfigurableType($item->getProductType()) && $hasChildren) {
308
  $result->setIsConfigurable(true);
309
 
310
  $result->setParentId($result->getProductId());
311
  $result->setProductId((int)$children[0]->getProductId());
312
  }
313
 
314
+ if ($this->_isBundleType($item->getProductType()) && $hasChildren) {
315
  $result->setIsBundle(true);
316
 
317
+ $product = Mage::getModel('catalog/product')
318
+ ->load($result->getProductId());
319
  $result->setSku($product->getSku());
320
  $result->setProduct($product);
321
+ } else if ($getProduct || $getImage
322
+ || ($getLink && !$result->getIsConfigurable())
323
+ ) {
324
+ $product = Mage::getModel('catalog/product')
325
+ ->load($result->getProductId());
326
+
327
+ $result->setProduct($product);
328
  }
329
 
330
  if ($getLink) {
331
+ $linkProduct = $result->getProduct();
332
+ if ($result->getIsConfigurable()) {
333
+ $linkProduct = Mage::getModel('catalog/product')
334
+ ->load($result->getParentId());
335
+ }
336
+
337
+ $result->setProductUrl($this->getProductUrl($linkProduct));
338
  }
339
 
340
  if ($getImage) {
344
  return $result;
345
  }
346
 
347
+ /**
348
+ * Retrieve the product URL, with caching of the result for a request
349
+ *
350
+ * @param Mage_Catalog_Model_Product $product Current product
351
+ *
352
+ * @return string
353
+ */
354
+ private function _getProductUrlWithCache(Mage_Catalog_Model_Product $product)
355
+ {
356
  $productId = $product->getEntityId();
357
 
358
  if (!isset($this->_urlsById[$productId])) {
362
  return $this->_urlsById[$productId];
363
  }
364
 
365
+ /**
366
+ * Retrieve an array of all available images for a product
367
+ *
368
+ * @param Mage_Catalog_Model_Product $product Current product
369
+ *
370
+ * @return array
371
+ */
372
+ private function _getProductImages(Mage_Catalog_Model_Product $product)
373
+ {
374
  $parent = $this->_getParentProduct($product);
375
+ $parentIsConfigurable = $parent && $this->_isConfigurableProduct($parent);
376
+ if ($this->_useConfigurableParentImages == null) {
377
+ $confSetting = Mage::getStoreConfig(
378
+ Mage_Checkout_Block_Cart_Item_Renderer_Configurable
379
+ ::CONFIGURABLE_PRODUCT_IMAGE
380
+ );
381
+ $wanted = Mage_Checkout_Block_Cart_Item_Renderer_Configurable
382
+ ::USE_PARENT_IMAGE;
383
+
384
+ $this->_useConfigurableParentImages = $confSetting == $wanted;
385
+ }
386
 
387
  $none = 'no_selection';
388
 
390
  $smallImage = null;
391
  $thumbnail = null;
392
 
393
+ if ($parentIsConfigurable && $this->_useConfigurableParentImages) {
394
  $image = $parent->getImage();
395
  $smallImage = $parent->getSmallImage();
396
  $thumbnail = $parent->getThumbnail();
397
+ } else {
 
398
  $image = $product->getImage();
399
+ if ($parent && (!$image || $image == $none)) {
400
+ $image = $parent->getImage();
401
+ }
402
 
403
  $smallImage = $product->getSmallImage();
404
+ if ($parent && (!$smallImage || $smallImage == $none)) {
405
+ $smallImage = $parent->getSmallImage();
406
+ }
407
 
408
  $thumbnail = $product->getThumbnail();
409
+ if ($parent && (!$thumbnail || $thumbnail == $none)) {
410
+ $thumbnail = $parent->getThumbnail();
411
+ }
412
  }
413
 
414
  $result = array();
415
+ if ($image && $image != $none) {
416
+ $result['image'] = $image;
417
+ }
418
+ if ($smallImage && $smallImage != $none) {
419
+ $result['small_image'] = $smallImage;
420
+ }
421
+ if ($thumbnail && $thumbnail != $none) {
422
+ $result['thumbnail'] = $thumbnail;
423
+ }
424
 
425
  return $result;
426
  }
427
 
428
+ /**
429
+ * Get the parent of a configurable product
430
+ *
431
+ * @param Mage_Catalog_Model_Product $product Configurable product
432
+ *
433
+ * @return Mage_Catalog_Model_Product
434
+ */
435
+ private function _getParentProduct(Mage_Catalog_Model_Product $product)
436
+ {
437
+ if ($product->hasParentProduct())
438
+ return $product->getParentProduct();
439
+
440
+ /* @var Mage_Catalog_Model_Product_Type_Configurable $confProductModel */
441
+ $confProductModel = Mage::getModel('catalog/product_type_configurable');
442
+
443
+ $parentIds = $confProductModel
444
  ->getParentIdsByChild($product->getEntityId());
445
 
446
  if (is_array($parentIds) && count($parentIds) > 0) {
447
  $parentId = $parentIds[0];
448
  if ($parentId != null) {
449
  if (!array_key_exists($parentId, $this->_parentsById)) {
450
+ /* @var Mage_Catalog_Model_Product $parent */
451
+ $parent = Mage::getModel('catalog/product')
452
  ->load($parentId);
453
+
454
+ $this->_parentsById[$parentId] = $parent;
455
  }
456
  return $this->_parentsById[$parentId];
457
  }
460
  return null;
461
  }
462
 
463
+ private function _getProductAttributes(Mage_Catalog_Model_Product $product)
464
+ {
465
+ if (!$this->_retrieveAttributes)
466
+ return null;
467
+
468
+ $result = array();
469
+
470
+ $allAttributes = array_keys($product->getData());
471
+
472
+ $hasParent = $product->hasParentProduct();
473
+ if ($hasParent) {
474
+ $parent = $product->getParentProduct();
475
+ $allAttributes = array_unique(array_merge(
476
+ $allAttributes,
477
+ array_keys($parent->getData())));
478
+ }
479
+
480
+ $productAttributes = $this->_getAttributeValues($product, $allAttributes);
481
+
482
+ if ($hasParent) {
483
+ $parentAttributes = $this->_getAttributeValues($parent, $allAttributes);
484
+ }
485
+
486
+ foreach($allAttributes as $name) {
487
+ $key = 'value';
488
+ $value = $productAttributes[$name];
489
+ if (is_array($value)) {
490
+ $key = 'values';
491
+ }
492
+
493
+ $pkey = 'parent_value';
494
+ $pvalue = null;
495
+ if ($hasParent) {
496
+ $pvalue = $parentAttributes[$name];
497
+ if (is_array($pvalue)) {
498
+ $pkey = 'parent_values';
499
+ }
500
+ }
501
+
502
+ if (($value !== null && $value !== "") || ($pvalue !== null && $pvalue !== "")) {
503
+ $attr = array(
504
+ 'attribute_name' => $name,
505
+ $key => $value,
506
+ $pkey => $pvalue
507
+ );
508
+ $result[] = $attr;
509
+ }
510
+ }
511
+
512
+ return $result;
513
+ }
514
+
515
+ private function _getProductAttribute(Mage_Catalog_Model_Product $product, $attributeName)
516
+ {
517
+ if (!$this->_retrieveAttributes) {
518
+ return $product
519
+ ->getAttributeText($attributeName);
520
  }
521
  else {
522
+ $value = $this->_getAttributeValue($product, $attributeName);
523
+ if (is_array($value)) {
524
+ $value = implode(', ', $value);
525
+ }
526
+ return $value;
527
  }
528
  }
529
 
530
+ private function _getAttributeValues(Mage_Catalog_Model_Product $product, $attributeNames)
531
+ {
532
+ $result = array();
533
+ foreach($attributeNames as $name) {
534
+ $value = $this->_getAttributeValue($product, $name);
535
+ $result[$name] = $value;
536
+ }
537
+ return $result;
538
+ }
539
+
540
+ private function _getAttributeValue(Mage_Catalog_Model_Product $product, $attributeName)
541
  {
542
+ $value = $product->getData($attributeName);
543
+ if (is_object($value))
544
+ return null;
545
+
546
+ if (array_key_exists($attributeName, $this->_attributeOptions)) {
547
+ $options = $this->_attributeOptions[$attributeName];
548
+
549
+ if (array_key_exists('options', $options)) {
550
+ if ($options['multiple']) {
551
+ $selects = array();
552
+
553
+ $parts = explode(',', $value);
554
+ foreach($parts as $part) {
555
+ if (array_key_exists($part, $options['options'])) {
556
+ $selects[] = $options['options'][$part];
557
+ }
558
+ }
559
+
560
+ if (count($selects) > 0) {
561
+ $value = $selects;
562
+ }
563
+ } else if (array_key_exists($value, $options['options'])) {
564
+ $value = $options['options'][$value];
565
+ }
566
+ }
567
+ }
568
+
569
+ if (is_array($value) && sizeof($value) > 0) {
570
+ $arrValue = array();
571
+ foreach($value as $key => $item) {
572
+ if (is_numeric($key) && !is_object($item)) {
573
+ $arrValue[] = $item;
574
+ }
575
+ }
576
+ if (sizeof($arrValue) == 0) {
577
+ $arrValue = null;
578
+ }
579
+ $value = $arrValue;
580
+ }
581
+
582
+ return $value;
583
+ }
584
+
585
+ /**
586
+ * Retrieve purchasable value to be returned by the API
587
+ *
588
+ * @param Mage_Catalog_Model_Product $product Current product
589
+ * @param Mage_Catalog_Model_Product $parent Parent product
590
+ *
591
+ * @return string
592
+ */
593
+ private function _isPurchasable(
594
+ Mage_Catalog_Model_Product $product,
595
+ Mage_Catalog_Model_Product $parent = null
596
+ ) {
597
+ if (!$this->_isEnabled($product)) {
598
+ $result = false;
599
+ } else if ($parent == null) {
600
+ $result = $this->_isVisible($product);
601
+ } else {
602
+ $result = $this->_isEnabled($parent) && $this->_isVisible($parent);
603
+ }
604
+
605
+ return $result ? "true" : "false";
606
+ }
607
+
608
+ /**
609
+ * Returns whether the product is enabled in the catalog
610
+ *
611
+ * @param Mage_Catalog_Model_Product $product Current product
612
+ *
613
+ * @return bool
614
+ */
615
+ private function _isEnabled(Mage_Catalog_Model_Product $product)
616
+ {
617
+ return $product->getStatus()
618
+ == Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
619
+ }
620
+
621
+ /**
622
+ * Retrieve whether the product is purchasable according to the configuration
623
+ *
624
+ * @param Mage_Catalog_Model_Product $product Current product
625
+ *
626
+ * @return bool
627
+ */
628
+ private function _isVisible(Mage_Catalog_Model_Product $product)
629
+ {
630
+ /* @var Listrak_Remarketing_Model_Product_Purchasable_Visibility $visModel */
631
+ $visModel = Mage::getSingleton(
632
+ 'listrak/product_purchasable_visibility'
633
+ );
634
+
635
+ return $visModel->isProductPurchasable($product);
636
+ }
637
+
638
+ /**
639
+ * Retrieve the attribute settings for a product
640
+ *
641
+ * @param Mage_Catalog_Model_Product $product Current product
642
+ *
643
+ * @return array
644
+ */
645
+ private function _getProductAttributeSetSettings(
646
+ Mage_Catalog_Model_Product $product
647
+ ) {
648
  if ($this->_attributeSets == null) {
649
  $this->_attributeSets = array(0 => array(
650
  //default values
655
  'subcategoryAttribute' => null
656
  ));
657
 
658
+ /* @var Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection $settings */
659
+ $settings = Mage::getModel('listrak/product_attribute_set_map')
660
  ->getCollection();
661
+
662
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $set */
663
+ foreach ($settings as $set) {
664
+ $this->_attributeSets[$set->getAttributeSetId()] = array(
665
+ 'brandAttribute' =>
666
+ $set->getBrandAttributeCode(),
667
+ 'catFromMagento' =>
668
+ $set->finalCategoriesSource() == 'default',
669
+ 'catFromAttributes' =>
670
+ $set->finalCategoriesSource() == 'attributes',
671
+ 'categoryAttribute' =>
672
+ $set->getCategoryAttributeCode(),
673
+ 'subcategoryAttribute' =>
674
+ $set->getSubcategoryAttributeCode()
675
  );
676
  }
677
  }
678
+
679
  return array_key_exists($product->getAttributeSetId(), $this->_attributeSets)
680
+ ? $this->_attributeSets[$product->getAttributeSetId()]
681
+ : $this->_attributeSets[0];
682
  }
683
 
684
+ /**
685
+ * Retrieve the category and subcategory for a product
686
+ *
687
+ * @param int $storeId Magento store ID
688
+ * @param Mage_Catalog_Model_Product $product Current product
689
+ *
690
+ * @return array
691
+ */
692
+ private function _getCategoryInformation(
693
+ $storeId, Mage_Catalog_Model_Product $product
694
+ ) {
695
+ /* @var Listrak_Remarketing_Helper_Data $helper */
696
+ $helper = Mage::helper('remarketing');
697
+
698
+ $rootLevel = $helper->getCategoryRootIdForStore($storeId);
699
  $rootPath = array(1);
700
+ if ($rootLevel) {
701
  $rootPath[] = $rootLevel;
702
+ }
703
 
704
+ $categoryLevel = $helper->getCategoryLevel();
705
 
706
  if ($this->_skipCategories == null) {
707
+ $this->_skipCategories = array_unique(
708
+ array_merge(
709
+ $helper->getInactiveCategories(),
710
+ $helper->getCategoriesToSkip()
711
+ )
712
+ );
713
  }
714
 
715
+ /* @var Mage_Catalog_Model_Resource_Category_Collection $categories */
716
  $categories = $product->getCategoryCollection();
717
+ $path = $this->_getFirstPathByPosition(
718
+ $categories, $categoryLevel + 1, $rootPath
719
+ );
720
 
721
  $result = array();
722
+ if (isset($path[$categoryLevel - 1])) {
723
+ $result['category']
724
+ = $this->_getCategoryField($path[$categoryLevel - 1], 'name');
725
+ }
726
+ if (isset($path[$categoryLevel])) {
727
+ $result['sub_category']
728
+ = $this->_getCategoryField($path[$categoryLevel], 'name');
729
+ }
730
 
731
  return $result;
732
  }
733
 
734
+ /**
735
+ * Retrieve the first active category
736
+ *
737
+ * @param mixed $categoryCollection All product categories
738
+ * @param int $maxLevel Defines the depth of search
739
+ * @param int[] $underPath Partial, known good path
740
+ *
741
+ * @return array
742
+ */
743
+ private function _getFirstPathByPosition(
744
+ $categoryCollection, $maxLevel, $underPath
745
+ ) {
746
+ if (sizeof($underPath) >= $maxLevel) {
747
  return $underPath;
748
+ }
749
 
750
  $nextCategory = array();
751
+
752
+ /* @var Mage_Catalog_Model_Category $category */
753
+ foreach ($categoryCollection as $category) {
754
  $pathIds = $category->getPathIds();
755
 
756
+ if (sizeof(array_intersect($pathIds, $this->_skipCategories)) > 0) {
757
+ // the category tree contains a category
758
+ // that we want skipped or is not active
759
  continue;
760
+ }
761
 
762
+ if (sizeof($pathIds) > sizeof($underPath)
763
+ && !in_array($pathIds[sizeof($underPath)], $nextCategory)
764
+ ) {
765
  $isUnderPath = true;
766
+ for ($i = 0; $i < sizeof($underPath); $i++) {
767
+ if ($pathIds[$i] != $underPath[$i]) {
 
 
768
  $isUnderPath = false;
769
  break;
770
  }
771
  }
772
 
773
+ if ($isUnderPath) {
774
  $nextCategory[] = $pathIds[sizeof($underPath)];
775
+ }
776
  }
777
  }
778
 
779
+ if (sizeof($nextCategory) == 0) {
780
  return $underPath;
781
+ }
782
 
783
  $winnerPath = array();
784
  $winnerPathPosition = 0;
785
+ foreach ($nextCategory as $categoryId) {
 
786
  $testPath = $underPath;
787
+ $testPath[] = $categoryId;
788
 
789
+ $testPathPosition = $this->_getCategoryField(
790
+ $categoryId, 'position'
791
+ );
792
 
793
+ if (sizeof($winnerPath) == 0
794
+ || $winnerPathPosition > $testPathPosition
795
+ ) {
796
  $winnerPath = $testPath;
797
  $winnerPathPosition = $testPathPosition;
798
  }
799
  }
800
 
801
+ return $this->_getFirstPathByPosition(
802
+ $categoryCollection, $maxLevel, $winnerPath
803
+ );
804
  }
805
 
806
+ /**
807
+ * Retrieve data from a category
808
+ *
809
+ * @param int $categoryId Category ID
810
+ * @param string $field Category field/attribute by name
811
+ *
812
+ * @return mixed|null
813
+ */
814
  private function _getCategoryField($categoryId, $field)
815
  {
816
  $category = $this->_getCategory($categoryId);
817
+ if ($category != null) {
 
 
818
  return $category->getData($field);
819
  }
820
 
821
  return null;
822
  }
823
 
824
+ /**
825
+ * Retrieve a category by ID
826
+ *
827
+ * @param int $categoryId Category ID
828
+ *
829
+ * @return Mage_Catalog_Model_Category
830
+ */
831
  private function _getCategory($categoryId)
832
  {
833
+ if (array_key_exists($categoryId, $this->_categories)) {
834
  return $this->_categories[$categoryId];
835
+ } else {
836
+ $category = Mage::getModel('catalog/category');
 
837
 
838
+ $category->load($categoryId);
839
+ if ($category != null) {
840
  $this->_categories[$categoryId] = $category;
841
  return $category;
842
  }
845
  return null;
846
  }
847
 
848
+ /**
849
+ * Get all linked products
850
+ *
851
+ * @param Mage_Catalog_Model_Product $product Current product
852
+ *
853
+ * @return array
854
+ */
855
+ private function _getProductLinks(Mage_Catalog_Model_Product $product)
856
+ {
857
+ if (Mage::getStoreConfig(
858
+ 'remarketing/productcategories/product_links'
859
+ ) != '1') {
860
  return null;
861
+ }
862
+
863
+ static $productTable = null;
864
+ if ($productTable == null) {
865
+ // this is done because a query shows up in MySQL
866
+ // with 'SET GLOBAL SQL_MODE = ''; SET NAMES utf8;'
867
+ // that is very costly in a loop
868
+
869
+ /* @var Mage_Core_Model_Resource $resource */
870
+ $resource = Mage::getModel('core/resource');
871
+
872
+ $productTable = $resource->getTableName('catalog/product');
873
+ }
874
 
875
+ static $productAttrTable = null;
876
+ if ($productAttrTable == null) {
877
+ /* @var Mage_Catalog_Model_Product_Link $linkModel */
878
+ $linkModel = Mage::getModel('catalog/product_link');
879
 
880
+ $productAttrTable = $linkModel->getAttributeTypeTable('int');
881
+ }
 
882
 
883
  $linkTypes = $this->_getLinkTypes();
884
 
885
+ /* @var Mage_Catalog_Model_Resource_Product_Link_Collection $links */
886
+ $links = Mage::getModel('catalog/product_link')
887
  ->getCollection();
 
 
888
 
889
+ $select = $links->getSelect();
890
+
891
+ $select->where('main_table.product_id = ?', $product->getId())
892
  ->where('main_table.product_id <> main_table.linked_product_id')
893
  ->where('main_table.link_type_id IN (?)', array_keys($linkTypes));
894
 
895
+ $select->join(
896
+ array('product' => $productTable),
897
  'main_table.linked_product_id = product.entity_id',
898
+ 'sku'
899
+ );
900
 
901
  $positionJoinOn = array();
902
+ foreach ($linkTypes as $linkTypeId => $linkType) {
903
  if ($linkType['positionAttributeId'] != null) {
904
+ $adptr = $select->getAdapter();
905
+ $joinStmt
906
+ = $adptr->quoteInto('main_table.link_type_id = ?', $linkTypeId)
907
+ . ' AND '
908
+ . $adptr->quoteInto(
909
+ 'attributes.product_link_attribute_id = ?',
910
+ $linkType['positionAttributeId']
911
+ );
912
+
913
+ $positionJoinOn[] = $joinStmt;
914
  }
915
  }
916
+
917
+ $joinCond
918
+ = 'main_table.link_id = attributes.link_id AND (('
919
+ . implode(') OR (', $positionJoinOn)
920
+ . '))';
921
+ $select->joinLeft(
922
+ array('attributes' => $productAttrTable),
923
+ $joinCond,
924
+ array('position' => 'value')
925
+ );
926
 
927
  $links = array();
928
+ foreach ($links as $link) {
929
+ $links[] = array(
930
+ 'link_type' => $linkTypes[$link->getLinkTypeId()]['name'],
931
+ 'sku' => $link->getSku(),
932
+ 'position' => $link->getPosition()
933
+ );
934
  }
935
 
936
  return $links;
937
  }
938
 
939
+ /**
940
+ * Retrieve product link types
941
+ *
942
+ * @return array
943
+ */
944
+ private function _getLinkTypes()
945
+ {
946
  static $_types = null;
947
 
948
  if ($_types == null) {
949
  $allLinks = array(
950
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_UPSELL =>
951
+ array('name' => 'up_sell', 'positionAttributeId' => null),
952
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_CROSSSELL =>
953
+ array('name' => 'cross_sell', 'positionAttributeId' => null),
954
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_RELATED =>
955
+ array('name' => 'related', 'positionAttributeId' => null),
956
+ Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED =>
957
+ array('name' => 'grouped', 'positionAttributeId' => null)
958
  );
959
 
960
+ foreach ($allLinks as $linkId => &$link) {
961
+ /* @var Mage_Catalog_Model_Product_Link $linkModel */
962
+ $linkModel = Mage::getModel('catalog/product_link');
963
+
964
+ $linkAttributes = $linkModel->setLinkTypeId($linkId)
965
  ->getAttributes();
966
+
967
+ foreach ($linkAttributes as $attribute) {
968
+ if ($attribute['code'] == 'position'
969
+ && $attribute['type'] == 'int'
970
+ ) {
971
  $link['positionAttributeId'] = $attribute['id'];
972
  break;
973
  }
980
  return $_types;
981
  }
982
 
983
+ /**
984
+ * Return whether the product type is configurable
985
+ *
986
+ * @param Mage_Catalog_Model_Product $product Current product
987
+ *
988
+ * @return bool
989
+ */
990
+ private function _isConfigurableProduct(Mage_Catalog_Model_Product $product)
991
+ {
992
+ return $this->_isConfigurableType($product->getTypeId());
993
+ }
994
+
995
+ /**
996
+ * Return whether the product type passed in is configurable
997
+ *
998
+ * @param string $type Product type
999
+ *
1000
+ * @return bool
1001
+ */
1002
+ private function _isConfigurableType($type)
1003
+ {
1004
+ return Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE == $type;
1005
+ }
1006
+
1007
+ /**
1008
+ * Return whether the product type passed in is bundle
1009
+ *
1010
+ * @param string $type Product type
1011
+ *
1012
+ * @return bool
1013
+ */
1014
+ private function _isBundleType($type)
1015
+ {
1016
+ return Mage_Catalog_Model_Product_Type::TYPE_BUNDLE == $type;
1017
+ }
1018
+
1019
+ /**
1020
+ * Retrieve the meta data for the current product from the meta provider
1021
+ *
1022
+ * @param int $storeId Magento store ID
1023
+ * @param Mage_Catalog_Model_Product $product Current Product
1024
+ * @param Mage_Catalog_Model_Product $parentProduct Parent Product
1025
+ *
1026
+ * @return array|null
1027
+ */
1028
+ private function _getMetas(
1029
+ $storeId,
1030
+ Mage_Catalog_Model_Product $product,
1031
+ Mage_Catalog_Model_Product $parentProduct = null
1032
+ ) {
1033
+ /* @var Listrak_Remarketing_Helper_Data $helper */
1034
+ $helper = Mage::helper('remarketing');
1035
+
1036
  try {
1037
+ $provider = $helper->getMetaDataProvider();
1038
+ if ($provider) {
1039
  return $provider->product($storeId, $product, $parentProduct);
1040
+ }
1041
  }
1042
  catch(Exception $e) {
1043
+ $helper->generateAndLogException(
1044
+ 'Exception retrieving product meta data', $e
1045
+ );
1046
  }
1047
 
1048
  return null;
app/code/community/Listrak/Remarketing/Helper/Product/Attribute/Set/Map.php CHANGED
@@ -12,42 +12,72 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Helper_Product_Attribute_Set_Map
16
  extends Mage_Core_Helper_Abstract
17
  {
 
 
 
 
 
18
  public function ensureDataConsistency()
19
  {
20
  $newSets = $this->newAttributeSetsCollection();
21
 
22
  // add the new product attribute sets to our table
23
  foreach ($newSets as $set) {
24
- Mage::getModel('listrak/product_attribute_set_map')
25
- ->setAttributeSetId($set->getAttributeSetId())
26
- ->save();
 
 
27
  }
28
  }
29
 
 
 
 
 
 
30
  public function newAttributeSetsCollection()
31
  {
32
- $r = Mage::getSingleton('core/resource');
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- // all product attribute sets
35
- $allProductSets = Mage::getResourceModel('eav/entity_attribute_set_collection')
36
- ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId());
37
 
38
  // the sets already in the table
39
  $model = new Varien_Db_Select(
40
- Mage::getResourceModel('listrak/product_attribute_set_map')->getReadConnection()
41
  );
42
  $model
43
- ->from(array('current' => $r->getTableName('listrak/product_attribute_set_map')))
 
 
 
 
 
44
  ->where('main_table.attribute_set_id = current.attribute_set_id');
45
 
46
  // new product attribute sets
47
- $allProductSets->getSelect()
48
  ->where('NOT EXISTS (' . $model . ')');
49
 
50
- return $allProductSets;
51
  }
52
  }
53
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Helper_Product_Attribute_Set_Map
17
+ */
18
  class Listrak_Remarketing_Helper_Product_Attribute_Set_Map
19
  extends Mage_Core_Helper_Abstract
20
  {
21
+ /**
22
+ * Ensures that all attribute sets are the Listrak settings table
23
+ *
24
+ * @return void
25
+ */
26
  public function ensureDataConsistency()
27
  {
28
  $newSets = $this->newAttributeSetsCollection();
29
 
30
  // add the new product attribute sets to our table
31
  foreach ($newSets as $set) {
32
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $mapModel */
33
+ $mapModel = Mage::getModel('listrak/product_attribute_set_map');
34
+
35
+ $mapModel->setAttributeSetId($set->getAttributeSetId());
36
+ $mapModel->save();
37
  }
38
  }
39
 
40
+ /**
41
+ * Retrieves a collection of all new attribute sets
42
+ *
43
+ * @return Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection
44
+ */
45
  public function newAttributeSetsCollection()
46
  {
47
+ /* @var Mage_Core_Model_Resource $resource */
48
+ $resource = Mage::getSingleton('core/resource');
49
+
50
+ /* @var Mage_Catalog_Model_Resource_Product $productResource */
51
+ $productResource = Mage::getModel('catalog/product')->getResource();
52
+
53
+ /* @var Mage_Eav_Model_Resource_Entity_Attribute_Set_Collection $sets */
54
+ $sets = Mage::getResourceModel(
55
+ 'eav/entity_attribute_set_collection'
56
+ );
57
+ $sets
58
+ ->setEntityTypeFilter($productResource->getTypeId());
59
 
60
+ /* @var Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map $setResource */
61
+ $setResource = Mage::getResourceModel('listrak/product_attribute_set_map');
 
62
 
63
  // the sets already in the table
64
  $model = new Varien_Db_Select(
65
+ $setResource->getReadConnection()
66
  );
67
  $model
68
+ ->from(
69
+ array('current' =>
70
+ $resource->getTableName('listrak/product_attribute_set_map')
71
+ ),
72
+ array("*")
73
+ )
74
  ->where('main_table.attribute_set_id = current.attribute_set_id');
75
 
76
  // new product attribute sets
77
+ $sets->getSelect()
78
  ->where('NOT EXISTS (' . $model . ')');
79
 
80
+ return $sets;
81
  }
82
  }
83
 
app/code/community/Listrak/Remarketing/Helper/Review/Update.php CHANGED
@@ -12,27 +12,51 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
 
15
  class Listrak_Remarketing_Helper_Review_Update
16
  extends Mage_Core_Helper_Abstract
17
  {
 
 
 
 
 
 
 
18
  public function getReviewListCollection($storeId)
19
  {
 
20
  $collection = Mage::getModel('review/review')
21
  ->getCollection()
22
  ->addStoreFilter($storeId);
23
 
 
 
 
 
 
 
24
  $collection
25
  ->getSelect()
26
  ->joinLeft(
27
  array(
28
- 'updatetime' => Mage::getModel('listrak/review_update')->getReviewUpdateCollection()->getSelect()
 
 
 
29
  ),
30
  "main_table.review_id = updatetime.review_id",
31
  array("updatetime.update_id", "updatetime.updated_at")
32
  )
33
  ->joinLeft(
34
  array(
35
- 'employee' => Mage::getSingleton('core/resource')->getTableName('customer/entity')
 
36
  ),
37
  'detail.customer_id = employee.entity_id',
38
  array('employee.email')
@@ -41,14 +65,30 @@ class Listrak_Remarketing_Helper_Review_Update
41
  return $collection;
42
  }
43
 
 
 
 
 
 
 
 
44
  public function getRatingSummaryListCollection($storeId)
45
  {
 
46
  $collection = Mage::getModel('review/review_summary')
47
  ->getCollection();
48
 
49
- $updatetimeSelect = Mage::getModel('listrak/review_update')->getRatingSummaryUpdateCollection()->getSelect();
50
- $joinOnClause = "review_entity_summary.primary_id = updatetime.rating_summary_id "
51
- . "AND review_entity_summary.store_id = updatetime.store_id";
 
 
 
 
 
 
 
 
52
  $collection->getSelect()
53
  ->joinLeft(
54
  array('updatetime' => $updatetimeSelect),
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Helper_Review_Update
17
+ *
18
+ * Provides a few shortcuts to use in the API methods querying
19
+ * review and rating summary updates
20
+ */
21
  class Listrak_Remarketing_Helper_Review_Update
22
  extends Mage_Core_Helper_Abstract
23
  {
24
+ /**
25
+ * Retrieves a collection with review updates
26
+ *
27
+ * @param int $storeId Magento store ID
28
+ *
29
+ * @return Mage_Review_Model_Resource_Review_Collection
30
+ */
31
  public function getReviewListCollection($storeId)
32
  {
33
+ /* @var Mage_Review_Model_Resource_Review_Collection $collection */
34
  $collection = Mage::getModel('review/review')
35
  ->getCollection()
36
  ->addStoreFilter($storeId);
37
 
38
+ /* @var Listrak_Remarketing_Model_Review_Update $updateModel */
39
+ $updateModel = Mage::getModel('listrak/review_update');
40
+
41
+ /* @var Mage_Core_Model_Resource $resource */
42
+ $resource = Mage::getSingleton('core/resource');
43
+
44
  $collection
45
  ->getSelect()
46
  ->joinLeft(
47
  array(
48
+ 'updatetime' =>
49
+ $updateModel
50
+ ->getReviewUpdateCollection()
51
+ ->getSelect()
52
  ),
53
  "main_table.review_id = updatetime.review_id",
54
  array("updatetime.update_id", "updatetime.updated_at")
55
  )
56
  ->joinLeft(
57
  array(
58
+ 'employee' => $resource
59
+ ->getTableName('customer/entity')
60
  ),
61
  'detail.customer_id = employee.entity_id',
62
  array('employee.email')
65
  return $collection;
66
  }
67
 
68
+ /**
69
+ * Retrieves a collection with rating summary updates
70
+ *
71
+ * @param int $storeId Magento store ID
72
+ *
73
+ * @return Mage_Review_Model_Resource_Review_Summary_Collection
74
+ */
75
  public function getRatingSummaryListCollection($storeId)
76
  {
77
+ /* @var Mage_Review_Model_Resource_Review_Summary_Collection $collection */
78
  $collection = Mage::getModel('review/review_summary')
79
  ->getCollection();
80
 
81
+ /* @var Listrak_Remarketing_Model_Review_Update $updateModel */
82
+ $updateModel = Mage::getModel('listrak/review_update');
83
+
84
+ $updatetimeSelect = $updateModel
85
+ ->getRatingSummaryUpdateCollection()
86
+ ->getSelect();
87
+
88
+ $joinOnClause
89
+ = "review_entity_summary.primary_id = updatetime.rating_summary_id"
90
+ . " AND review_entity_summary.store_id = updatetime.store_id";
91
+
92
  $collection->getSelect()
93
  ->joinLeft(
94
  array('updatetime' => $updatetimeSelect),
app/code/community/Listrak/Remarketing/Model/Abandonedcart.php CHANGED
@@ -12,39 +12,20 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Abandonedcart
16
  extends Mage_Core_Model_Abstract
17
  {
 
 
 
 
 
18
  public function _construct()
19
  {
20
  parent::_construct();
21
  $this->_init('listrak/abandonedcart');
22
  }
23
-
24
- public function prepareForReport()
25
- {
26
- $session = $this->getSession();
27
- $customer = $session->getCustomer();
28
- $this->setSessionId($session->getSessionId());
29
-
30
- if ($customer && $customer->getId()) {
31
- $this->setCustomerName($customer->getFirstname() . ' ' . $customer->getLastname());
32
- $this->setEmail($customer->getEmail());
33
- $this->setIsCustomer('true');
34
- } else {
35
- $this->setCustomerName('');
36
- $this->setIsCustomer('false');
37
-
38
- if (is_array($session->getEmails()) && count($session->getEmails()) > 0) {
39
- foreach ($session->getEmails() as $email) {
40
- $this->setEmail($this->getEmail() . $email["email"] . ', ');
41
- }
42
-
43
- $this->setEmail(trim($this->getEmail(), ", "));
44
- } else {
45
-
46
- }
47
- }
48
-
49
- }
50
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Abandonedcart
17
+ */
18
  class Listrak_Remarketing_Model_Abandonedcart
19
  extends Mage_Core_Model_Abstract
20
  {
21
+ /**
22
+ * Initializes the object
23
+ *
24
+ * @return void
25
+ */
26
  public function _construct()
27
  {
28
  parent::_construct();
29
  $this->_init('listrak/abandonedcart');
30
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  }
app/code/community/Listrak/Remarketing/Model/Abandonedcart/Api.php CHANGED
@@ -12,19 +12,36 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Abandonedcart_Api
16
  extends Mage_Api_Model_Resource_Abstract
17
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- public function items($storeId = 1, $startDate = null, $endDate = null,
20
- $perPage = 50,
21
- $page = 1
22
- )
23
- {
24
  Mage::app()->setCurrentStore($storeId);
25
- Mage::helper('remarketing')->requireCoreEnabled();
26
 
27
- Mage::helper('remarketing')->requireSessionTrackingTable();
28
 
29
  try {
30
  if ($startDate === null || !strtotime($startDate)) {
@@ -37,13 +54,17 @@ class Listrak_Remarketing_Model_Abandonedcart_Api
37
 
38
  $storeIdArray = explode(',', $storeId);
39
 
40
- $collection = Mage::getModel('listrak/abandonedcart')
41
- ->getCollection()
42
- ->addFieldToFilter('main_table.updated_at', array('from' => $startDate, 'to' => $endDate))
43
- ->addFieldToFilter('main_table.converted', '0')
44
  ->addClearCartTrimFilter($startDate)
 
 
 
 
 
45
  ->setPageSize($perPage)->setCurPage($page)
46
- ->addStoreFilter($storeIdArray)
47
  ->setOrder('updated_at', 'ASC')
48
  ->distinct(true);
49
 
@@ -55,13 +76,28 @@ class Listrak_Remarketing_Model_Abandonedcart_Api
55
 
56
  return $result;
57
  } catch (Exception $e) {
58
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
59
  }
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
62
  public function purge($storeId = 1, $endDate = null)
63
  {
64
- Mage::helper('remarketing')->requireSessionTrackingTable();
 
 
 
65
 
66
  try {
67
  if ($endDate === null || !strtotime($endDate)) {
@@ -74,27 +110,39 @@ class Listrak_Remarketing_Model_Abandonedcart_Api
74
 
75
  $count = 0;
76
 
 
77
  foreach ($sessions as $session) {
78
  $session->delete();
79
  $count++;
80
  }
81
 
82
- $helper = Mage::helper('remarketing');
83
- if (!$helper->legacyTracking() && $helper->getTableRowCount('listrak/session') == 0 && $helper->getTableRowCount('listrak/click') == 0) {
 
 
 
84
  $resource = Mage::getSingleton('core/resource');
85
- $resource->getConnection('core_write')->query("DROP TABLE {$resource->getTableName('listrak/session')}"
86
- . ", {$resource->getTableName('listrak/session_email')}"
87
- . ", {$resource->getTableName('listrak/click')}");
 
 
 
 
88
 
89
  $config = Mage::getConfig();
90
- $config->saveConfig('remarketing/config/tracking_tables_deleted', '1');
 
 
91
  $config->reinit();
92
  Mage::app()->reinitStores();
93
  }
94
 
95
  return $count;
96
  } catch (Exception $e) {
97
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
98
  }
99
  }
100
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Abandonedcart_Api
17
+ */
18
  class Listrak_Remarketing_Model_Abandonedcart_Api
19
  extends Mage_Api_Model_Resource_Abstract
20
  {
21
+ /**
22
+ * Retrieve abandoned carts
23
+ *
24
+ * @param int $storeId Magento store ID
25
+ * @param datetime $startDate Lower date constraint
26
+ * @param datetime $endDate Upper date constraint
27
+ * @param int $perPage Page size
28
+ * @param int $page Cursor
29
+ *
30
+ * @return array
31
+ *
32
+ * @throws Exception
33
+ */
34
+ public function items(
35
+ $storeId = 1, $startDate = null, $endDate = null,
36
+ $perPage = 50, $page = 1
37
+ ) {
38
+ /* @var Listrak_Remarketing_Helper_Data $helper */
39
+ $helper = Mage::helper('remarketing');
40
 
 
 
 
 
 
41
  Mage::app()->setCurrentStore($storeId);
42
+ $helper->requireCoreEnabled();
43
 
44
+ $helper->requireSessionTrackingTable();
45
 
46
  try {
47
  if ($startDate === null || !strtotime($startDate)) {
54
 
55
  $storeIdArray = explode(',', $storeId);
56
 
57
+ /* @var Listrak_Remarketing_Model_Mysql4_Abandonedcart_Collection $collection */
58
+ $collection = Mage::getModel('listrak/abandonedcart')->getCollection();
59
+ $collection
60
+ ->addStoreFilter($storeIdArray)
61
  ->addClearCartTrimFilter($startDate)
62
+ ->addFieldToFilter(
63
+ 'main_table.updated_at',
64
+ array('from' => $startDate, 'to' => $endDate)
65
+ )
66
+ ->addFieldToFilter('main_table.converted', '0')
67
  ->setPageSize($perPage)->setCurPage($page)
 
68
  ->setOrder('updated_at', 'ASC')
69
  ->distinct(true);
70
 
76
 
77
  return $result;
78
  } catch (Exception $e) {
79
+ throw $helper->generateAndLogException(
80
+ "Exception occurred in API call: " . $e->getMessage(), $e
81
+ );
82
  }
83
  }
84
 
85
+ /**
86
+ * Purge old abandoned cart entries
87
+ *
88
+ * @param int $storeId Magento store ID (deprecated)
89
+ * @param datetime $endDate Upper date constraint
90
+ *
91
+ * @return int
92
+ *
93
+ * @throws Exception
94
+ */
95
  public function purge($storeId = 1, $endDate = null)
96
  {
97
+ /* @var Listrak_Remarketing_Helper_Data $helper */
98
+ $helper = Mage::helper('remarketing');
99
+
100
+ $helper->requireSessionTrackingTable();
101
 
102
  try {
103
  if ($endDate === null || !strtotime($endDate)) {
110
 
111
  $count = 0;
112
 
113
+ /* @var Listrak_Remarketing_Model_Session $session */
114
  foreach ($sessions as $session) {
115
  $session->delete();
116
  $count++;
117
  }
118
 
119
+ if (!$helper->legacyTracking()
120
+ && $helper->getTableRowCount('listrak/session') == 0
121
+ && $helper->getTableRowCount('listrak/click') == 0
122
+ ) {
123
+ /* @var Mage_Core_Model_Resource $resource */
124
  $resource = Mage::getSingleton('core/resource');
125
+
126
+ $resource->getConnection('core_write')
127
+ ->query(
128
+ "DROP TABLE {$resource->getTableName('listrak/session')}"
129
+ . ", {$resource->getTableName('listrak/session_email')}"
130
+ . ", {$resource->getTableName('listrak/click')}"
131
+ );
132
 
133
  $config = Mage::getConfig();
134
+ $config->saveConfig(
135
+ 'remarketing/config/tracking_tables_deleted', '1'
136
+ );
137
  $config->reinit();
138
  Mage::app()->reinitStores();
139
  }
140
 
141
  return $count;
142
  } catch (Exception $e) {
143
+ throw $helper->generateAndLogException(
144
+ "Exception occurred in API call: " . $e->getMessage(), $e
145
+ );
146
  }
147
  }
148
  }
app/code/community/Listrak/Remarketing/Model/Abandonedcart/Api/V2.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Abandonedcart_Api_V2
16
  extends Listrak_Remarketing_Model_Abandonedcart_Api
17
  {
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Abandonedcart_Api_V2
17
+ */
18
  class Listrak_Remarketing_Model_Abandonedcart_Api_V2
19
  extends Listrak_Remarketing_Model_Abandonedcart_Api
20
  {
app/code/community/Listrak/Remarketing/Model/Apiextension.php CHANGED
@@ -12,9 +12,20 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Apiextension
16
  extends Mage_Core_Model_Abstract
17
  {
 
 
 
 
 
18
  public function _construct()
19
  {
20
  parent::_construct();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Apiextension
17
+ *
18
+ * Exists to make possible an API class that handles any
19
+ * method whose return data doesn't fit in any other defined model
20
+ */
21
  class Listrak_Remarketing_Model_Apiextension
22
  extends Mage_Core_Model_Abstract
23
  {
24
+ /**
25
+ * Initializes the object
26
+ *
27
+ * @return void
28
+ */
29
  public function _construct()
30
  {
31
  parent::_construct();
app/code/community/Listrak/Remarketing/Model/Apiextension/Api.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Apiextension_Api
16
  extends Mage_Api_Model_Resource_Abstract
17
  {
@@ -19,20 +22,39 @@ class Listrak_Remarketing_Model_Apiextension_Api
19
  'order' => array('order_id' => 'entity_id')
20
  );
21
 
22
- public function subscribers($storeId = 1, $startDate = null, $perPage = 50, $page = 1)
23
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  Mage::app()->setCurrentStore($storeId);
25
- Mage::helper('remarketing')->requireCoreEnabled();
26
 
27
- try {
28
- if ($startDate === null || !strtotime($startDate)) {
29
- $this->_fault('incorrect_date');
30
- }
31
 
 
32
  $result = array();
33
 
34
- $collection = Mage::getModel("listrak/apiextension")
35
- ->getResource()
 
 
 
36
  ->subscribers($storeId, $startDate, $perPage, $page);
37
 
38
  foreach ($collection as $item) {
@@ -41,38 +63,69 @@ class Listrak_Remarketing_Model_Apiextension_Api
41
 
42
  return $result;
43
  } catch (Exception $e) {
44
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
45
  }
46
  }
47
 
 
 
 
 
 
 
 
 
 
48
  public function subscribersPurge($endDate = null)
49
  {
50
- try {
51
- if ($endDate === null || !strtotime($endDate)) {
52
- $this->_fault('incorrect_date');
53
- }
54
 
55
- $subscriberupdates = Mage::getModel("listrak/subscriberupdate")
 
56
  ->getCollection()
57
  ->addFieldToFilter('updated_at', array('lt' => $endDate));
58
 
59
  $count = 0;
60
 
61
- foreach ($subscriberupdates as $subscriberupdate) {
62
- $subscriberupdate->delete();
 
63
  $count++;
64
  }
65
 
66
  return $count;
67
  } catch (Exception $e) {
68
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
 
 
69
  }
70
  }
71
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  public function customers($storeId = 1, $websiteId = 1, $perPage = 50, $page = 1)
73
  {
 
 
 
74
  Mage::app()->setCurrentStore($storeId);
75
- Mage::helper('remarketing')->requireCoreEnabled();
76
 
77
  try {
78
  $collection = Mage::getModel('customer/customer')->getCollection()
@@ -89,52 +142,96 @@ class Listrak_Remarketing_Model_Apiextension_Api
89
 
90
  return $results;
91
  } catch (Exception $e) {
92
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
93
  }
94
  }
95
 
96
- private function _getCustomerArray($storeId, Mage_Customer_Model_Customer $customer)
97
- {
 
 
 
 
 
 
 
 
 
 
 
 
98
  $fields = array('entity_id' => '', 'firstname' => '', 'lastname' => '',
99
  'email' => '', 'website_id' => '', 'store_id' => '', 'group_id' => '',
100
  'gender_name' => '', 'dob' => '', 'group_name' => '');
101
- Mage::helper('remarketing')->setGroupNameAndGenderNameForCustomer($customer);
 
102
  $result = array_intersect_key($customer->toArray(), $fields);
103
 
104
  $metas = $this->_getCustomerMetas($storeId, $customer);
105
  if ($metas) {
106
- //if (isset($metas['meta1'])) $result['meta1'] = $metas['meta1'];
107
- if (isset($metas['meta2'])) $result['meta2'] = $metas['meta2'];
108
- if (isset($metas['meta3'])) $result['meta3'] = $metas['meta3'];
109
- if (isset($metas['meta4'])) $result['meta4'] = $metas['meta4'];
110
- if (isset($metas['meta5'])) $result['meta5'] = $metas['meta5'];
 
 
 
 
 
 
 
111
  }
112
 
113
  return $result;
114
  }
115
 
116
- public function orderStatus($storeId = 1, $startDate = null, $endDate = null,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  $perPage = 50, $page = 1, $filters = null
118
- )
119
- {
 
 
120
  Mage::app()->setCurrentStore($storeId);
121
- Mage::helper('remarketing')->requireCoreEnabled();
122
 
123
  try {
124
  $productsUpdated = array();
125
 
126
- $collection = Mage::getModel("sales/order")->getCollection()
127
- ->addFieldToFilter('store_id', $storeId)
128
- ->addFieldToFilter('updated_at', array('from' => $startDate, 'to' => $endDate))
 
 
 
 
129
  ->addFieldToFilter('status', array('neq' => 'pending'))
130
  ->setPageSize($perPage)->setCurPage($page)
131
  ->setOrder('updated_at', 'ASC');
132
 
133
- if (!Mage::helper('remarketing')->getMetaDataProvider())
134
  $collection->addAttributeToSelect('entity_id')
135
  ->addAttributeToSelect('increment_id')
136
  ->addAttributeToSelect('status')
137
  ->addAttributeToSelect('updated_at');
 
138
 
139
  if (is_array($filters)) {
140
  try {
@@ -152,6 +249,7 @@ class Listrak_Remarketing_Model_Apiextension_Api
152
 
153
  $results = array();
154
 
 
155
  foreach ($collection as $order) {
156
  $result = array();
157
  $result['increment_id'] = $order->getIncrementId();
@@ -160,34 +258,63 @@ class Listrak_Remarketing_Model_Apiextension_Api
160
 
161
  $metas = $this->_getOrderMetas($storeId, $order);
162
  if ($metas) {
163
- if (isset($metas['meta1'])) $result['meta1'] = $metas['meta1'];
164
- if (isset($metas['meta2'])) $result['meta2'] = $metas['meta2'];
165
- if (isset($metas['meta3'])) $result['meta3'] = $metas['meta3'];
166
- if (isset($metas['meta4'])) $result['meta4'] = $metas['meta4'];
167
- if (isset($metas['meta5'])) $result['meta5'] = $metas['meta5'];
 
 
 
 
 
 
 
 
 
 
168
  }
169
 
170
- $shipment = $order->getShipmentsCollection()->getFirstItem();
 
 
 
 
171
  if ($shipment) {
172
  $tracks = $shipment->getAllTracks();
173
  if (count($tracks) > 0) {
174
- $result['tracking_number'] = $tracks[0]->getNumber();
175
- $result['carrier_code'] = $tracks[0]->getCarrierCode();
 
 
 
176
  }
177
  }
178
 
179
  $quantities = array();
180
- foreach($order->getAllVisibleItems() as $item) {
181
- $info = Mage::helper('remarketing/product')
182
- ->getProductInformationFromOrderItem($item, array('product'));
 
 
 
 
 
 
 
183
 
184
  if (!in_array($info->getProductId(), $productsUpdated, true)) {
185
- $product = Mage::getModel('catalog/product')->load($info->getProductId());
 
 
186
  if ($product) {
187
  $quantity = array();
188
 
189
  $quantity['sku'] = $product->getSku();
190
- $quantity['in_stock'] = $product->isAvailable() ? "true" : "false";
 
 
 
191
  $stockItem = $product->getStockItem();
192
  if ($stockItem) {
193
  $quantity['qty_on_hand'] = $stockItem->getStockQty();
@@ -206,40 +333,65 @@ class Listrak_Remarketing_Model_Apiextension_Api
206
 
207
  return $results;
208
  } catch (Exception $e) {
209
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
210
  }
211
  }
212
 
213
- public function orders($storeId = 1, $startDate = null, $endDate = null,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
  $perPage = 50, $page = 1
215
- )
216
- {
 
 
217
  Mage::app()->setCurrentStore($storeId);
218
- Mage::helper('remarketing')->requireCoreEnabled();
219
 
220
- try {
221
- if ($startDate === null || !strtotime($startDate)) {
222
- $this->_fault('incorrect_date');
223
- }
224
 
225
- if ($endDate === null || !strtotime($endDate)) {
226
- $this->_fault('incorrect_date');
227
- }
228
 
229
- $orders = Mage::getModel('sales/order')->getCollection()
230
- ->addFieldToFilter('created_at', array('from' => $startDate, 'to' => $endDate))
 
 
 
 
 
 
231
  ->addFieldToFilter('store_id', $storeId)
232
  ->setPageSize($perPage)->setCurPage($page)
233
  ->setOrder('created_at', 'ASC');
234
 
235
  $results = array();
236
 
 
237
  foreach ($orders as $order) {
238
  $result = array();
239
  $result['info']['entity_id'] = $order->getEntityId();
240
  $result['info']['order_id'] = $order->getIncrementId();
241
  $result['info']['status'] = $order->getStatus();;
242
- $result['info']['customer_firstname'] = $order->getCustomerFirstname();
 
243
  $result['info']['customer_lastname'] = $order->getCustomerLastname();
244
  $result['info']['customer_email'] = $order->getCustomerEmail();
245
  $result['info']['subtotal'] = $order->getSubtotal();
@@ -254,50 +406,74 @@ class Listrak_Remarketing_Model_Apiextension_Api
254
 
255
  $metas = $this->_getOrderMetas($storeId, $order);
256
  if ($metas) {
257
- if (isset($metas['meta1'])) $result['info']['meta1'] = $metas['meta1'];
258
- if (isset($metas['meta2'])) $result['info']['meta2'] = $metas['meta2'];
259
- if (isset($metas['meta3'])) $result['info']['meta3'] = $metas['meta3'];
260
- if (isset($metas['meta4'])) $result['info']['meta4'] = $metas['meta4'];
261
- if (isset($metas['meta5'])) $result['info']['meta5'] = $metas['meta5'];
 
 
 
 
 
 
 
 
 
 
262
  }
263
 
 
264
  $shipping = $order->getShippingAddress();
265
  if ($shipping) {
266
- $result['shipping_address']['firstname'] = $shipping->getFirstname();
267
- $result['shipping_address']['lastname'] = $shipping->getLastname();
 
 
268
  $result['shipping_address']['company'] = $shipping->getCompany();
269
- $result['shipping_address']['street'] = implode(', ', $shipping->getStreet());
 
270
  $result['shipping_address']['city'] = $shipping->getCity();
271
  $result['shipping_address']['region'] = $shipping->getRegion();
272
- $result['shipping_address']['postcode'] = $shipping->getPostcode();
 
273
  $result['shipping_address']['country'] = $shipping->getCountry();
274
  }
275
 
 
276
  $billing = $order->getBillingAddress();
277
  if ($billing) {
278
- $result['billing_address']['firstname'] = $billing->getFirstname();
 
279
  $result['billing_address']['lastname'] = $billing->getLastname();
280
  $result['billing_address']['company'] = $billing->getCompany();
281
- $result['billing_address']['street'] = implode(', ', $billing->getStreet());
 
282
  $result['billing_address']['city'] = $billing->getCity();
283
  $result['billing_address']['region'] = $billing->getRegion();
284
  $result['billing_address']['postcode'] = $billing->getPostcode();
285
  $result['billing_address']['country'] = $billing->getCountry();
286
  }
287
 
288
- if (Mage::helper('remarketing')->trackingTablesExist()) {
289
- $result['session'] = Mage::getModel("listrak/session")->load($order->getQuoteId(), 'quote_id');
 
 
290
  }
291
 
292
  $result['product'] = array();
293
  foreach ($order->getAllVisibleItems() as $item) {
294
- $result['product'][] = $this->_getOrderItemProductEntity($storeId, $order, $item);
 
295
  }
296
 
297
  if ($order->getCustomerId()) {
298
- $customer = Mage::getModel("customer/customer")->load($order->getCustomerId());
 
 
299
  if ($customer) {
300
- $result['customer'] = $this->_getCustomerArray($storeId, $customer);
 
301
  }
302
  }
303
 
@@ -306,13 +482,31 @@ class Listrak_Remarketing_Model_Apiextension_Api
306
 
307
  return $results;
308
  } catch (Exception $e) {
309
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
310
  }
311
  }
312
 
313
- private function _getOrderItemProductEntity($storeId, Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Item $item)
314
- {
315
- $info = Mage::helper('remarketing/product')->getProductInformationFromOrderItem($item, array('product'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
316
  $productModel = $info->getProduct();
317
 
318
  $product = array();
@@ -323,107 +517,199 @@ class Listrak_Remarketing_Model_Apiextension_Api
323
 
324
  // Inventory
325
  $product['in_stock'] = $productModel->isAvailable() ? "true" : "false";
 
 
326
  $stockItem = $productModel->getStockItem();
327
  if ($stockItem) {
328
  $product['qty_on_hand'] = $stockItem->getStockQty();
329
  }
330
  } else {
331
  $product['sku'] = $item->getProductOptionByCode('simple_sku')
332
- ? $item->getProductOptionByCode('simple_sku') : $item->getSku();
 
333
  $product['name'] = $item->getName();
334
  }
335
 
336
  $product['price'] = $item->getPrice();
337
  $product['qty_ordered'] = $item->getQtyOrdered();
338
 
339
- $metas = $this->_getOrderItemMetas($storeId, $order, $item, $info->getProduct());
 
 
340
  if ($metas) {
341
- if (isset($metas['meta1'])) $product['meta1'] = $metas['meta1'];
342
- if (isset($metas['meta2'])) $product['meta2'] = $metas['meta2'];
343
- if (isset($metas['meta3'])) $product['meta3'] = $metas['meta3'];
344
- if (isset($metas['meta4'])) $product['meta4'] = $metas['meta4'];
345
- if (isset($metas['meta5'])) $product['meta5'] = $metas['meta5'];
 
 
 
 
 
 
 
 
 
 
346
  }
347
 
348
  if ($info->getIsBundle()) {
349
  $product['bundle_items'] = array();
350
  foreach ($item->getChildrenItems() as $childItem) {
351
- $product['bundle_items'][] = $this->_getOrderItemProductEntity($storeId, $order, $childItem);
 
 
352
  }
353
  }
354
 
355
  return $product;
356
  }
357
 
358
- private function _getCustomerMetas($storeId, Mage_Customer_Model_Customer $customer) {
 
 
 
 
 
 
 
 
 
 
 
 
 
359
  try {
360
- $provider = Mage::helper('remarketing')->getMetaDataProvider();
361
- if ($provider)
362
  return $provider->customer($storeId, $customer);
 
363
  }
364
  catch(Exception $e) {
365
- Mage::helper('remarketing')->generateAndLogException('Error retrieving customer meta data.', $e);
 
 
366
  }
367
 
368
  return null;
369
  }
370
 
371
- private function _getOrderMetas($storeId, Mage_Sales_Model_Order $order) {
 
 
 
 
 
 
 
 
 
 
 
 
372
  try {
373
- $provider = Mage::helper('remarketing')->getMetaDataProvider();
374
- if ($provider)
375
  return $provider->order($storeId, $order);
 
376
  }
377
  catch(Exception $e) {
378
- Mage::helper('remarketing')->generateAndLogException('Error retrieving order meta data.', $e);
 
 
379
  }
380
 
381
  return null;
382
  }
383
 
384
- private function _getOrderItemMetas($storeId, Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Item $orderItem, Mage_Catalog_Model_Product $product = null) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  try {
386
- $provider = Mage::helper('remarketing')->getMetaDataProvider();
387
- if ($provider)
388
  return $provider->orderItem($storeId, $order, $orderItem, $product);
 
389
  }
390
  catch(Exception $e) {
391
- Mage::helper('remarketing')->generateAndLogException('Error retrieving order item meta data.', $e);
 
 
392
  }
393
 
394
  return null;
395
  }
396
 
 
 
 
 
 
 
 
 
 
397
  public function info($storeId)
398
  {
399
  Mage::app()->setCurrentStore($storeId);
400
-
 
 
 
401
  try {
402
  $result = array();
403
  $result["magentoVersion"] = Mage::getVersion();
404
 
405
  $module = Mage::getConfig()->getNode('modules')->Listrak_Remarketing;
406
- $core_resource = Mage::getModel('core/resource_resource');
 
 
407
 
408
  $result['listrakExtension']['active'] = (string)$module->active;
409
- $result['listrakExtension']['output'] = Mage::getStoreConfig("advanced/modules_disable_output/Listrak_Remarketing") == '0' ? 'true' : 'false';
 
 
 
410
  $result['listrakExtension']['version'] = (string)$module->version;
411
- if ($core_resource) {
412
- $result['listrakExtension']['install_version'] = $core_resource->getDbVersion('listrak_remarketing_setup');
413
- $result['listrakExtension']['data_version'] = $core_resource->getDataVersion('listrak_remarketing_setup');
 
 
414
  }
415
 
416
- $helper = Mage::helper('remarketing');
417
  $result["listrakSettings"] = array(
418
  "coreEnabled" => $helper->coreEnabled() ? "true" : "false",
419
  "onescriptEnabled" => $helper->onescriptEnabled() ? "true" : "false",
420
  "onescriptReady" => $helper->onescriptReady() ? "true" : "false",
421
- "trackingID" => Mage::getStoreConfig('remarketing/modal/listrakMerchantID'),
 
 
422
  "scaEnabled" => $helper->scaEnabled() ? "true" : "false",
423
  "activityEnabled" => $helper->activityEnabled() ? "true" : "false",
424
  "reviewsApiEnabled" => $helper->reviewsEnabled() ? "true" : "false",
425
- "trackingTablesExist" => $helper->trackingTablesExist() ? "true" : "false",
426
- "skipCategoriesText" => Mage::getStoreConfig('remarketing/productcategories/categories_skip'),
 
 
 
427
  "skipCategories" => implode(",", $helper->getCategoriesToSkip())
428
  );
429
  $result["ini"] = array();
@@ -432,26 +718,32 @@ class Listrak_Remarketing_Model_Apiextension_Api
432
  $orderModel = Mage::getModel("sales/order");
433
  $productModel = Mage::getModel('catalog/product');
434
 
435
- $result["classes"] = get_class($subModel) . ',' . get_class($orderModel) .
436
- ',' . get_class($orderModel->getCollection()) . ',' .
437
- get_class($productModel) . ',' . get_class($productModel->getCollection());
 
 
 
 
 
 
438
 
439
- $ra = Mage::getSingleton('core/resource')->getConnection('core_read');
440
- $countQueryText = "select count(*) as c from " .
441
- Mage::getModel("listrak/subscriberupdate")->getResource()->getTable("listrak/subscriber_update");
442
- $numSubUpdates = $ra->fetchRow($countQueryText);
443
 
444
  if ($helper->trackingTablesExist()) {
445
- $countQueryText = "select count(*) as c from " .
446
- Mage::getModel("listrak/session")->getResource()->getTable("listrak/session");
447
- $numSessions = $ra->fetchRow($countQueryText);
448
- $countQueryText = "select count(*) as c from " .
449
- Mage::getModel("listrak/click")->getResource()->getTable("listrak/click");
450
- $numClicks = $ra->fetchRow($countQueryText);
451
-
452
- $result["counts"] = $numSessions['c'] . ',' . $numSubUpdates['c'] . ',' . $numClicks['c'];
453
- }
454
- else {
 
455
  $result["counts"] = $numSubUpdates['c'];
456
  }
457
 
@@ -460,9 +752,14 @@ class Listrak_Remarketing_Model_Apiextension_Api
460
 
461
  foreach ($modules as $key => $value) {
462
  $valueArray = $value->asCanonicalArray();
463
- $version = (isset($valueArray["version"])) ? $valueArray["version"] : '';
464
- $active = (isset($valueArray["active"])) ? $valueArray["active"] : '';
465
- $result["modules"][] = "name=$key, version=" . $version .", isActive=" . $active;
 
 
 
 
 
466
  }
467
 
468
  $ini = array("session.gc_maxlifetime", "session.cookie_lifetime",
@@ -474,7 +771,9 @@ class Listrak_Remarketing_Model_Apiextension_Api
474
 
475
  return $result;
476
  } catch (Exception $e) {
477
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
478
  }
479
  }
480
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Apiextension_Api
17
+ */
18
  class Listrak_Remarketing_Model_Apiextension_Api
19
  extends Mage_Api_Model_Resource_Abstract
20
  {
22
  'order' => array('order_id' => 'entity_id')
23
  );
24
 
25
+ /**
26
+ * Retrieve subscriber information
27
+ *
28
+ * @param int $storeId Magento store ID
29
+ * @param datetime $startDate Lower date constraint
30
+ * @param int $perPage Page size
31
+ * @param int $page Cursor
32
+ *
33
+ * @return array
34
+ *
35
+ * @throws Exception
36
+ */
37
+ public function subscribers(
38
+ $storeId = 1, $startDate = null, $perPage = 50, $page = 1
39
+ ) {
40
+ /* @var Listrak_Remarketing_Helper_Data $helper */
41
+ $helper = Mage::helper('remarketing');
42
+
43
  Mage::app()->setCurrentStore($storeId);
44
+ $helper->requireCoreEnabled();
45
 
46
+ if ($startDate === null || !strtotime($startDate)) {
47
+ $this->_fault('incorrect_date');
48
+ }
 
49
 
50
+ try {
51
  $result = array();
52
 
53
+ /* @var Listrak_Remarketing_Model_Mysql4_Apiextension $resource */
54
+ $resource = Mage::getModel("listrak/apiextension")
55
+ ->getResource();
56
+
57
+ $collection = $resource
58
  ->subscribers($storeId, $startDate, $perPage, $page);
59
 
60
  foreach ($collection as $item) {
63
 
64
  return $result;
65
  } catch (Exception $e) {
66
+ throw $helper->generateAndLogException(
67
+ "Exception occurred in API call: " . $e->getMessage(), $e
68
+ );
69
  }
70
  }
71
 
72
+ /**
73
+ * Purge old subscriber log entries
74
+ *
75
+ * @param datetime $endDate Upper date constraint
76
+ *
77
+ * @return int
78
+ *
79
+ * @throws Exception
80
+ */
81
  public function subscribersPurge($endDate = null)
82
  {
83
+ if ($endDate === null || !strtotime($endDate)) {
84
+ $this->_fault('incorrect_date');
85
+ }
 
86
 
87
+ try {
88
+ $updates = Mage::getModel("listrak/subscriberupdate")
89
  ->getCollection()
90
  ->addFieldToFilter('updated_at', array('lt' => $endDate));
91
 
92
  $count = 0;
93
 
94
+ /* @var Listrak_Remarketing_Model_Subscriberupdate $update */
95
+ foreach ($updates as $update) {
96
+ $update->delete();
97
  $count++;
98
  }
99
 
100
  return $count;
101
  } catch (Exception $e) {
102
+ /* @var Listrak_Remarketing_Helper_Data $helper */
103
+ $helper = Mage::helper('remarketing');
104
+ throw $helper->generateAndLogException(
105
+ "Exception occurred in API call: " . $e->getMessage(), $e
106
+ );
107
  }
108
  }
109
 
110
+ /**
111
+ * Retrieve customer information
112
+ *
113
+ * @param int $storeId Magento store ID
114
+ * @param int $websiteId Magento website ID (deprecated)
115
+ * @param int $perPage Page size
116
+ * @param int $page Cursor
117
+ *
118
+ * @return array
119
+ *
120
+ * @throws Exception
121
+ */
122
  public function customers($storeId = 1, $websiteId = 1, $perPage = 50, $page = 1)
123
  {
124
+ /* @var Listrak_Remarketing_Helper_Data $helper */
125
+ $helper = Mage::helper('remarketing');
126
+
127
  Mage::app()->setCurrentStore($storeId);
128
+ $helper->requireCoreEnabled();
129
 
130
  try {
131
  $collection = Mage::getModel('customer/customer')->getCollection()
142
 
143
  return $results;
144
  } catch (Exception $e) {
145
+ throw $helper->generateAndLogException(
146
+ "Exception occurred in API call: " . $e->getMessage(), $e
147
+ );
148
  }
149
  }
150
 
151
+ /**
152
+ * Transform product object into array
153
+ *
154
+ * @param int $storeId Magento store ID
155
+ * @param Mage_Customer_Model_Customer $customer Customer
156
+ *
157
+ * @return array
158
+ */
159
+ private function _getCustomerArray(
160
+ $storeId, Mage_Customer_Model_Customer $customer
161
+ ) {
162
+ /* @var Listrak_Remarketing_Helper_Data $helper */
163
+ $helper = Mage::helper('remarketing');
164
+
165
  $fields = array('entity_id' => '', 'firstname' => '', 'lastname' => '',
166
  'email' => '', 'website_id' => '', 'store_id' => '', 'group_id' => '',
167
  'gender_name' => '', 'dob' => '', 'group_name' => '');
168
+
169
+ $helper->setGroupNameAndGenderNameForCustomer($customer);
170
  $result = array_intersect_key($customer->toArray(), $fields);
171
 
172
  $metas = $this->_getCustomerMetas($storeId, $customer);
173
  if ($metas) {
174
+ if (isset($metas['meta2'])) {
175
+ $result['meta2'] = $metas['meta2'];
176
+ }
177
+ if (isset($metas['meta3'])) {
178
+ $result['meta3'] = $metas['meta3'];
179
+ }
180
+ if (isset($metas['meta4'])) {
181
+ $result['meta4'] = $metas['meta4'];
182
+ }
183
+ if (isset($metas['meta5'])) {
184
+ $result['meta5'] = $metas['meta5'];
185
+ }
186
  }
187
 
188
  return $result;
189
  }
190
 
191
+ /**
192
+ * Retrieve order status updates
193
+ *
194
+ * @param int $storeId Magento store ID
195
+ * @param datetime $startDate Lower date constraint
196
+ * @param datetime $endDate Upper date constraint
197
+ * @param int $perPage Page size
198
+ * @param int $page Cursor
199
+ * @param array $filters Order filters
200
+ *
201
+ * @return array
202
+ *
203
+ * @throws Exception
204
+ */
205
+ public function orderStatus(
206
+ $storeId = 1, $startDate = null, $endDate = null,
207
  $perPage = 50, $page = 1, $filters = null
208
+ ) {
209
+ /* @var Listrak_Remarketing_Helper_Data $helper */
210
+ $helper = Mage::helper('remarketing');
211
+
212
  Mage::app()->setCurrentStore($storeId);
213
+ $helper->requireCoreEnabled();
214
 
215
  try {
216
  $productsUpdated = array();
217
 
218
+ /* @var Mage_Sales_Model_Resource_Order_Collection $collection */
219
+ $collection = Mage::getModel("sales/order")->getCollection();
220
+
221
+ $collection->addFieldToFilter('store_id', $storeId)
222
+ ->addFieldToFilter(
223
+ 'updated_at', array('from' => $startDate, 'to' => $endDate)
224
+ )
225
  ->addFieldToFilter('status', array('neq' => 'pending'))
226
  ->setPageSize($perPage)->setCurPage($page)
227
  ->setOrder('updated_at', 'ASC');
228
 
229
+ if (!$helper->getMetaDataProvider()) {
230
  $collection->addAttributeToSelect('entity_id')
231
  ->addAttributeToSelect('increment_id')
232
  ->addAttributeToSelect('status')
233
  ->addAttributeToSelect('updated_at');
234
+ }
235
 
236
  if (is_array($filters)) {
237
  try {
249
 
250
  $results = array();
251
 
252
+ /* @var Mage_Sales_Model_Order $order */
253
  foreach ($collection as $order) {
254
  $result = array();
255
  $result['increment_id'] = $order->getIncrementId();
258
 
259
  $metas = $this->_getOrderMetas($storeId, $order);
260
  if ($metas) {
261
+ if (isset($metas['meta1'])) {
262
+ $result['meta1'] = $metas['meta1'];
263
+ }
264
+ if (isset($metas['meta2'])) {
265
+ $result['meta2'] = $metas['meta2'];
266
+ }
267
+ if (isset($metas['meta3'])) {
268
+ $result['meta3'] = $metas['meta3'];
269
+ }
270
+ if (isset($metas['meta4'])) {
271
+ $result['meta4'] = $metas['meta4'];
272
+ }
273
+ if (isset($metas['meta5'])) {
274
+ $result['meta5'] = $metas['meta5'];
275
+ }
276
  }
277
 
278
+ /* @var Mage_Sales_Model_Resource_Order_Shipment_Collection $shipmentCollection */
279
+ $shipmentCollection = $order->getShipmentsCollection();
280
+
281
+ /* @var Mage_Sales_Model_Order_Shipment $shipment */
282
+ $shipment = $shipmentCollection->getFirstItem();
283
  if ($shipment) {
284
  $tracks = $shipment->getAllTracks();
285
  if (count($tracks) > 0) {
286
+ /* @var Mage_Sales_Model_Order_Shipment_Track $firstTrack */
287
+ $firstTrack = $tracks[0];
288
+
289
+ $result['tracking_number'] = $firstTrack->getNumber();
290
+ $result['carrier_code'] = $firstTrack->getCarrierCode();
291
  }
292
  }
293
 
294
  $quantities = array();
295
+
296
+ /* @var Mage_Sales_Model_Order_Item $item */
297
+ foreach ($order->getAllVisibleItems() as $item) {
298
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
299
+ $productHelper = Mage::helper('remarketing/product');
300
+
301
+ $info = $productHelper
302
+ ->getProductInformationFromOrderItem(
303
+ $item, array('product')
304
+ );
305
 
306
  if (!in_array($info->getProductId(), $productsUpdated, true)) {
307
+ /* @var Mage_Catalog_Model_Product $product */
308
+ $product = Mage::getModel('catalog/product')
309
+ ->load($info->getProductId());
310
  if ($product) {
311
  $quantity = array();
312
 
313
  $quantity['sku'] = $product->getSku();
314
+ $quantity['in_stock']
315
+ = $product->isAvailable() ? "true" : "false";
316
+
317
+ /* @var Mage_Cataloginventory_Model_Stock_Item $stockItem */
318
  $stockItem = $product->getStockItem();
319
  if ($stockItem) {
320
  $quantity['qty_on_hand'] = $stockItem->getStockQty();
333
 
334
  return $results;
335
  } catch (Exception $e) {
336
+ throw $helper->generateAndLogException(
337
+ "Exception occurred in API call: " . $e->getMessage(), $e
338
+ );
339
  }
340
  }
341
 
342
+ /**
343
+ * Retrieve orders
344
+ *
345
+ * @param int $storeId Magento store ID
346
+ * @param datetime $startDate Lower date constraint
347
+ * @param datetime $endDate Upper date constraint
348
+ * @param int $perPage Page size
349
+ * @param int $page Cursor
350
+ *
351
+ * @return array
352
+ *
353
+ * @throws Exception
354
+ */
355
+ public function orders(
356
+ $storeId = 1, $startDate = null, $endDate = null,
357
  $perPage = 50, $page = 1
358
+ ) {
359
+ /* @var Listrak_Remarketing_Helper_Data $helper */
360
+ $helper = Mage::helper('remarketing');
361
+
362
  Mage::app()->setCurrentStore($storeId);
363
+ $helper->requireCoreEnabled();
364
 
365
+ if ($startDate === null || !strtotime($startDate)) {
366
+ $this->_fault('incorrect_date');
367
+ }
 
368
 
369
+ if ($endDate === null || !strtotime($endDate)) {
370
+ $this->_fault('incorrect_date');
371
+ }
372
 
373
+ try {
374
+ /* @var Mage_Sales_Model_Resource_Order_Collection $orders */
375
+ $orders = Mage::getModel('sales/order')->getCollection();
376
+
377
+ $orders
378
+ ->addFieldToFilter(
379
+ 'created_at', array('from' => $startDate, 'to' => $endDate)
380
+ )
381
  ->addFieldToFilter('store_id', $storeId)
382
  ->setPageSize($perPage)->setCurPage($page)
383
  ->setOrder('created_at', 'ASC');
384
 
385
  $results = array();
386
 
387
+ /* @var Mage_Sales_Model_Order $order */
388
  foreach ($orders as $order) {
389
  $result = array();
390
  $result['info']['entity_id'] = $order->getEntityId();
391
  $result['info']['order_id'] = $order->getIncrementId();
392
  $result['info']['status'] = $order->getStatus();;
393
+ $result['info']['customer_firstname']
394
+ = $order->getCustomerFirstname();
395
  $result['info']['customer_lastname'] = $order->getCustomerLastname();
396
  $result['info']['customer_email'] = $order->getCustomerEmail();
397
  $result['info']['subtotal'] = $order->getSubtotal();
406
 
407
  $metas = $this->_getOrderMetas($storeId, $order);
408
  if ($metas) {
409
+ if (isset($metas['meta1'])) {
410
+ $result['info']['meta1'] = $metas['meta1'];
411
+ }
412
+ if (isset($metas['meta2'])) {
413
+ $result['info']['meta2'] = $metas['meta2'];
414
+ }
415
+ if (isset($metas['meta3'])) {
416
+ $result['info']['meta3'] = $metas['meta3'];
417
+ }
418
+ if (isset($metas['meta4'])) {
419
+ $result['info']['meta4'] = $metas['meta4'];
420
+ }
421
+ if (isset($metas['meta5'])) {
422
+ $result['info']['meta5'] = $metas['meta5'];
423
+ }
424
  }
425
 
426
+ /* @var Mage_Sales_Model_Order_Address $shipping */
427
  $shipping = $order->getShippingAddress();
428
  if ($shipping) {
429
+ $result['shipping_address']['firstname']
430
+ = $shipping->getFirstname();
431
+ $result['shipping_address']['lastname']
432
+ = $shipping->getLastname();
433
  $result['shipping_address']['company'] = $shipping->getCompany();
434
+ $result['shipping_address']['street']
435
+ = implode(', ', $shipping->getStreet());
436
  $result['shipping_address']['city'] = $shipping->getCity();
437
  $result['shipping_address']['region'] = $shipping->getRegion();
438
+ $result['shipping_address']['postcode']
439
+ = $shipping->getPostcode();
440
  $result['shipping_address']['country'] = $shipping->getCountry();
441
  }
442
 
443
+ /* @var Mage_Sales_Model_Order_Address $billing */
444
  $billing = $order->getBillingAddress();
445
  if ($billing) {
446
+ $result['billing_address']['firstname']
447
+ = $billing->getFirstname();
448
  $result['billing_address']['lastname'] = $billing->getLastname();
449
  $result['billing_address']['company'] = $billing->getCompany();
450
+ $result['billing_address']['street']
451
+ = implode(', ', $billing->getStreet());
452
  $result['billing_address']['city'] = $billing->getCity();
453
  $result['billing_address']['region'] = $billing->getRegion();
454
  $result['billing_address']['postcode'] = $billing->getPostcode();
455
  $result['billing_address']['country'] = $billing->getCountry();
456
  }
457
 
458
+ if ($helper->trackingTablesExist()) {
459
+ $result['session']
460
+ = Mage::getModel("listrak/session")
461
+ ->load($order->getQuoteId(), 'quote_id');
462
  }
463
 
464
  $result['product'] = array();
465
  foreach ($order->getAllVisibleItems() as $item) {
466
+ $result['product'][]
467
+ = $this->_getOrderItemProductEntity($storeId, $order, $item);
468
  }
469
 
470
  if ($order->getCustomerId()) {
471
+ /* @var Mage_Customer_Model_Customer $customer */
472
+ $customer = Mage::getModel("customer/customer")
473
+ ->load($order->getCustomerId());
474
  if ($customer) {
475
+ $result['customer']
476
+ = $this->_getCustomerArray($storeId, $customer);
477
  }
478
  }
479
 
482
 
483
  return $results;
484
  } catch (Exception $e) {
485
+ throw $helper->generateAndLogException(
486
+ "Exception occurred in API call: " . $e->getMessage(), $e
487
+ );
488
  }
489
  }
490
 
491
+ /**
492
+ * Extract order item information for Magento objects
493
+ *
494
+ * @param int $storeId Magento store ID
495
+ * @param Mage_Sales_Model_Order $order Order
496
+ * @param Mage_Sales_Model_Order_Item $item Order item
497
+ *
498
+ * @return array
499
+ */
500
+ private function _getOrderItemProductEntity(
501
+ $storeId, Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Item $item
502
+ ) {
503
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
504
+ $productHelper = Mage::helper('remarketing/product');
505
+
506
+ $info = $productHelper
507
+ ->getProductInformationFromOrderItem($item, array('product'));
508
+
509
+ /* @var Mage_Catalog_Model_Product $productModel */
510
  $productModel = $info->getProduct();
511
 
512
  $product = array();
517
 
518
  // Inventory
519
  $product['in_stock'] = $productModel->isAvailable() ? "true" : "false";
520
+
521
+ /* @var Mage_Cataloginventory_Model_Stock_Item $stockItem */
522
  $stockItem = $productModel->getStockItem();
523
  if ($stockItem) {
524
  $product['qty_on_hand'] = $stockItem->getStockQty();
525
  }
526
  } else {
527
  $product['sku'] = $item->getProductOptionByCode('simple_sku')
528
+ ? $item->getProductOptionByCode('simple_sku')
529
+ : $item->getSku();
530
  $product['name'] = $item->getName();
531
  }
532
 
533
  $product['price'] = $item->getPrice();
534
  $product['qty_ordered'] = $item->getQtyOrdered();
535
 
536
+ $metas = $this->_getOrderItemMetas(
537
+ $storeId, $order, $item, $info->getProduct()
538
+ );
539
  if ($metas) {
540
+ if (isset($metas['meta1'])) {
541
+ $product['meta1'] = $metas['meta1'];
542
+ }
543
+ if (isset($metas['meta2'])) {
544
+ $product['meta2'] = $metas['meta2'];
545
+ }
546
+ if (isset($metas['meta3'])) {
547
+ $product['meta3'] = $metas['meta3'];
548
+ }
549
+ if (isset($metas['meta4'])) {
550
+ $product['meta4'] = $metas['meta4'];
551
+ }
552
+ if (isset($metas['meta5'])) {
553
+ $product['meta5'] = $metas['meta5'];
554
+ }
555
  }
556
 
557
  if ($info->getIsBundle()) {
558
  $product['bundle_items'] = array();
559
  foreach ($item->getChildrenItems() as $childItem) {
560
+ $product['bundle_items'][] = $this->_getOrderItemProductEntity(
561
+ $storeId, $order, $childItem
562
+ );
563
  }
564
  }
565
 
566
  return $product;
567
  }
568
 
569
+ /**
570
+ * Retrieve customer meta data from external provider
571
+ *
572
+ * @param int $storeId Magento store ID
573
+ * @param Mage_Customer_Model_Customer $customer Customer
574
+ *
575
+ * @return array|null
576
+ */
577
+ private function _getCustomerMetas(
578
+ $storeId, Mage_Customer_Model_Customer $customer
579
+ ) {
580
+ /* @var Listrak_Remarketing_Helper_Data $helper */
581
+ $helper = Mage::helper('remarketing');
582
+
583
  try {
584
+ $provider = $helper->getMetaDataProvider();
585
+ if ($provider) {
586
  return $provider->customer($storeId, $customer);
587
+ }
588
  }
589
  catch(Exception $e) {
590
+ $helper->generateAndLogException(
591
+ 'Error retrieving customer meta data.', $e
592
+ );
593
  }
594
 
595
  return null;
596
  }
597
 
598
+ /**
599
+ * Retrieve order meta data form external provider
600
+ *
601
+ * @param int $storeId Magento store ID
602
+ * @param Mage_Sales_Model_Order $order Order
603
+ *
604
+ * @return array|null
605
+ */
606
+ private function _getOrderMetas($storeId, Mage_Sales_Model_Order $order)
607
+ {
608
+ /* @var Listrak_Remarketing_Helper_Data $helper */
609
+ $helper = Mage::helper('remarketing');
610
+
611
  try {
612
+ $provider = $helper->getMetaDataProvider();
613
+ if ($provider) {
614
  return $provider->order($storeId, $order);
615
+ }
616
  }
617
  catch(Exception $e) {
618
+ $helper->generateAndLogException(
619
+ 'Error retrieving order meta data.', $e
620
+ );
621
  }
622
 
623
  return null;
624
  }
625
 
626
+ /**
627
+ * Retrieve order item meta data from external provider
628
+ *
629
+ * @param int $storeId Magento store ID
630
+ * @param Mage_Sales_Model_Order $order Order
631
+ * @param Mage_Sales_Model_Order_Item $orderItem Order item
632
+ * @param Mage_Catalog_Model_Product $product Ordered product
633
+ *
634
+ * @return array|null
635
+ */
636
+ private function _getOrderItemMetas(
637
+ $storeId,
638
+ Mage_Sales_Model_Order $order,
639
+ Mage_Sales_Model_Order_Item $orderItem,
640
+ Mage_Catalog_Model_Product $product = null
641
+ ) {
642
+ /* @var Listrak_Remarketing_Helper_Data $helper */
643
+ $helper = Mage::helper('remarketing');
644
+
645
  try {
646
+ $provider = $helper->getMetaDataProvider();
647
+ if ($provider) {
648
  return $provider->orderItem($storeId, $order, $orderItem, $product);
649
+ }
650
  }
651
  catch(Exception $e) {
652
+ $helper->generateAndLogException(
653
+ 'Error retrieving order item meta data.', $e
654
+ );
655
  }
656
 
657
  return null;
658
  }
659
 
660
+ /**
661
+ * Retrieves information about the store
662
+ *
663
+ * @param int $storeId Magento store ID
664
+ *
665
+ * @return array
666
+ *
667
+ * @throws Exception
668
+ */
669
  public function info($storeId)
670
  {
671
  Mage::app()->setCurrentStore($storeId);
672
+
673
+ /* @var Listrak_Remarketing_Helper_Data $helper */
674
+ $helper = Mage::helper('remarketing');
675
+
676
  try {
677
  $result = array();
678
  $result["magentoVersion"] = Mage::getVersion();
679
 
680
  $module = Mage::getConfig()->getNode('modules')->Listrak_Remarketing;
681
+
682
+ /* @var Mage_Core_Model_Resource_Resource $resourceResource */
683
+ $resourceResource = Mage::getModel('core/resource_resource');
684
 
685
  $result['listrakExtension']['active'] = (string)$module->active;
686
+ $result['listrakExtension']['output']
687
+ = Mage::getStoreConfig(
688
+ "advanced/modules_disable_output/Listrak_Remarketing"
689
+ ) == '1' ? 'false' : 'true';
690
  $result['listrakExtension']['version'] = (string)$module->version;
691
+ if ($resourceResource) {
692
+ $result['listrakExtension']['install_version']
693
+ = $resourceResource->getDbVersion('listrak_remarketing_setup');
694
+ $result['listrakExtension']['data_version']
695
+ = $resourceResource->getDataVersion('listrak_remarketing_setup');
696
  }
697
 
 
698
  $result["listrakSettings"] = array(
699
  "coreEnabled" => $helper->coreEnabled() ? "true" : "false",
700
  "onescriptEnabled" => $helper->onescriptEnabled() ? "true" : "false",
701
  "onescriptReady" => $helper->onescriptReady() ? "true" : "false",
702
+ "trackingID" => Mage::getStoreConfig(
703
+ 'remarketing/modal/listrakMerchantID'
704
+ ),
705
  "scaEnabled" => $helper->scaEnabled() ? "true" : "false",
706
  "activityEnabled" => $helper->activityEnabled() ? "true" : "false",
707
  "reviewsApiEnabled" => $helper->reviewsEnabled() ? "true" : "false",
708
+ "trackingTablesExist" =>
709
+ $helper->trackingTablesExist() ? "true" : "false",
710
+ "skipCategoriesText" => Mage::getStoreConfig(
711
+ 'remarketing/productcategories/categories_skip'
712
+ ),
713
  "skipCategories" => implode(",", $helper->getCategoriesToSkip())
714
  );
715
  $result["ini"] = array();
718
  $orderModel = Mage::getModel("sales/order");
719
  $productModel = Mage::getModel('catalog/product');
720
 
721
+ $result["classes"] = get_class($subModel) . ','
722
+ . get_class($orderModel) . ','
723
+ . get_class($orderModel->getCollection()) . ','
724
+ . get_class($productModel) . ','
725
+ . get_class($productModel->getCollection());
726
+
727
+ /* @var Mage_Core_Model_Resource $resource */
728
+ $resource = Mage::getSingleton('core/resource');
729
+ $dbRead = $resource->getConnection('core_read');
730
 
731
+ $countQueryText = "select count(*) as c from "
732
+ . $resource->getTableName("listrak/subscriber_update");
733
+ $numSubUpdates = $dbRead->fetchRow($countQueryText);
 
734
 
735
  if ($helper->trackingTablesExist()) {
736
+ $countQueryText = "select count(*) as c from "
737
+ . $resource->getTableName("listrak/session");
738
+ $numSessions = $dbRead->fetchRow($countQueryText);
739
+ $countQueryText = "select count(*) as c from "
740
+ . $resource->getTableName("listrak/click");
741
+ $numClicks = $dbRead->fetchRow($countQueryText);
742
+
743
+ $result["counts"] = $numSessions['c'] . ','
744
+ . $numSubUpdates['c'] . ','
745
+ . $numClicks['c'];
746
+ } else {
747
  $result["counts"] = $numSubUpdates['c'];
748
  }
749
 
752
 
753
  foreach ($modules as $key => $value) {
754
  $valueArray = $value->asCanonicalArray();
755
+ $version = isset($valueArray["version"])
756
+ ? $valueArray["version"]
757
+ : '';
758
+ $active = isset($valueArray["active"])
759
+ ? $valueArray["active"]
760
+ : '';
761
+ $result["modules"][]
762
+ = "name=$key, version=$version, isActive=$active";
763
  }
764
 
765
  $ini = array("session.gc_maxlifetime", "session.cookie_lifetime",
771
 
772
  return $result;
773
  } catch (Exception $e) {
774
+ throw $helper->generateAndLogException(
775
+ "Exception occurred in API call: " . $e->getMessage(), $e
776
+ );
777
  }
778
  }
779
  }
app/code/community/Listrak/Remarketing/Model/Apiextension/Api/V2.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Apiextension_Api_V2
16
  extends Listrak_Remarketing_Model_Apiextension_Api
17
  {
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Apiextension_Api_V2
17
+ */
18
  class Listrak_Remarketing_Model_Apiextension_Api_V2
19
  extends Listrak_Remarketing_Model_Apiextension_Api
20
  {
app/code/community/Listrak/Remarketing/Model/Cache/Sca.php CHANGED
@@ -12,49 +12,86 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Model_Cache_Sca extends Enterprise_PageCache_Model_Container_Abstract
 
 
 
 
 
 
16
  {
17
  private $_cartCookieValue = null;
18
  private $_saveBlock = false;
19
 
 
 
 
 
 
20
  protected function _getCacheId()
21
  {
22
- if (!$this->_cartCookieValue)
23
  $this->_cartCookieValue = $this->_getCookieValue('mltkc');
 
24
 
25
- if (!$this->_cartCookieValue)
26
  $this->_cartCookieValue = 'AJAX';
 
27
 
28
  return md5('REMARKETING_SCA_' . $this->_cartCookieValue);
29
  }
30
 
 
 
 
 
 
31
  protected function _renderBlock()
32
  {
 
 
 
33
  $block = $this->_placeholder->getAttribute('block');
 
 
34
  $block = new $block;
35
  $block->setFullPageRendering(true);
36
 
37
  if ($block->canRender()) {
38
  $block->setTemplate($this->_placeholder->getAttribute('template'));
39
 
40
- if (Mage::helper('remarketing')->ajaxTracking()) {
41
  $this->_cartCookieValue = 'AJAX';
42
  $this->_saveBlock = true;
43
  }
44
 
45
  return $block->toHtml();
46
- }
47
- else {
48
  $this->_saveBlock = true;
49
- if (!$this->_cartCookieValue)
50
- $this->_cartCookieValue = Mage::helper('remarketing')->initCartCookie();
 
51
 
52
  return "";
53
  }
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
56
  protected function _saveCache($data, $id, $tags = array(), $lifetime = null)
57
  {
58
- return $this->_saveBlock ? parent::_saveCache($data, $id, $tags, $lifetime) : false;
 
 
 
 
59
  }
60
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Cache_Sca
17
+ *
18
+ * Serves as the caching model for the SCA tracking block
19
+ */
20
+ class Listrak_Remarketing_Model_Cache_Sca
21
+ extends Enterprise_PageCache_Model_Container_Abstract
22
  {
23
  private $_cartCookieValue = null;
24
  private $_saveBlock = false;
25
 
26
+ /**
27
+ * Retrieve the block cache ID
28
+ *
29
+ * @return string
30
+ */
31
  protected function _getCacheId()
32
  {
33
+ if (!$this->_cartCookieValue) {
34
  $this->_cartCookieValue = $this->_getCookieValue('mltkc');
35
+ }
36
 
37
+ if (!$this->_cartCookieValue) {
38
  $this->_cartCookieValue = 'AJAX';
39
+ }
40
 
41
  return md5('REMARKETING_SCA_' . $this->_cartCookieValue);
42
  }
43
 
44
+ /**
45
+ * Render SCA tracking block
46
+ *
47
+ * @return string
48
+ */
49
  protected function _renderBlock()
50
  {
51
+ /* @var Listrak_Remarketing_Helper_Data $helper */
52
+ $helper = Mage::helper('remarketing');
53
+
54
  $block = $this->_placeholder->getAttribute('block');
55
+
56
+ /* @var Listrak_Remarketing_Block_Tracking_Sca $block */
57
  $block = new $block;
58
  $block->setFullPageRendering(true);
59
 
60
  if ($block->canRender()) {
61
  $block->setTemplate($this->_placeholder->getAttribute('template'));
62
 
63
+ if ($helper->ajaxTracking()) {
64
  $this->_cartCookieValue = 'AJAX';
65
  $this->_saveBlock = true;
66
  }
67
 
68
  return $block->toHtml();
69
+ } else {
 
70
  $this->_saveBlock = true;
71
+ if (!$this->_cartCookieValue) {
72
+ $this->_cartCookieValue = $helper->initCartCookie();
73
+ }
74
 
75
  return "";
76
  }
77
  }
78
 
79
+ /**
80
+ * Manages block storage
81
+ *
82
+ * @param string $data Block content to store
83
+ * @param string $id Cache ID
84
+ * @param array $tags Tags
85
+ * @param mixed $lifetime EOL
86
+ *
87
+ * @return bool
88
+ */
89
  protected function _saveCache($data, $id, $tags = array(), $lifetime = null)
90
  {
91
+ if ($this->_saveBlock) {
92
+ return parent::_saveCache($data, $id, $tags, $lifetime);
93
+ }
94
+
95
+ return false;
96
  }
97
  }
app/code/community/Listrak/Remarketing/Model/Click.php CHANGED
@@ -12,18 +12,34 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Click
16
  extends Mage_Core_Model_Abstract
17
  {
 
 
 
 
 
18
  public function _construct()
19
  {
20
  parent::_construct();
21
  $this->_init('listrak/click');
22
  }
23
 
 
 
 
 
 
24
  public function checkForClick()
25
  {
26
- foreach (Mage::app()->getRequest()->getParams() as $key => $value) {
 
27
  if (stripos($key, 'trk_') !== false) {
28
  $this->_recordClick();
29
  break;
@@ -31,16 +47,27 @@ class Listrak_Remarketing_Model_Click
31
  }
32
  }
33
 
 
 
 
 
 
34
  private function _recordClick()
35
  {
36
- $this->setTokenUid(Mage::helper('remarketing')->genUuid());
37
- $this->setClickDate(gmdate('Y-m-d H:i:s'));
38
  $session = Mage::getSingleton('listrak/session');
39
  $session->init();
 
 
 
40
  $this->setSessionId($session->getId());
41
- $this->setQuerystring(http_build_query(Mage::app()->getRequest()->getParams()));
 
 
42
  $this->save();
43
 
44
- Mage::getModel('core/cookie')->set('ltktrk', $this->getTokenUid(), true, null, null, null, true);
 
 
45
  }
46
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Click
17
+ *
18
+ * Processes requests for click data
19
+ */
20
  class Listrak_Remarketing_Model_Click
21
  extends Mage_Core_Model_Abstract
22
  {
23
+ /**
24
+ * Initializes the object
25
+ *
26
+ * @return void
27
+ */
28
  public function _construct()
29
  {
30
  parent::_construct();
31
  $this->_init('listrak/click');
32
  }
33
 
34
+ /**
35
+ * Check the request for a click
36
+ *
37
+ * @return void
38
+ */
39
  public function checkForClick()
40
  {
41
+ $urlKeys = array_keys(Mage::app()->getRequest()->getParams());
42
+ foreach ($urlKeys as $key) {
43
  if (stripos($key, 'trk_') !== false) {
44
  $this->_recordClick();
45
  break;
47
  }
48
  }
49
 
50
+ /**
51
+ * Record a click
52
+ *
53
+ * @return void
54
+ */
55
  private function _recordClick()
56
  {
57
+ /* @var Listrak_Remarketing_Model_Session $session */
 
58
  $session = Mage::getSingleton('listrak/session');
59
  $session->init();
60
+
61
+ $this->setTokenUid(Mage::helper('remarketing')->genUuid());
62
+ $this->setClickDate(gmdate('Y-m-d H:i:s'));
63
  $this->setSessionId($session->getId());
64
+ $this->setQuerystring(
65
+ http_build_query(Mage::app()->getRequest()->getParams())
66
+ );
67
  $this->save();
68
 
69
+ /* @var Mage_Core_Model_Cookie $cookies */
70
+ $cookies = Mage::getModel('core/cookie');
71
+ $cookies->set('ltktrk', $this->getTokenUid(), true, null, null, null, true);
72
  }
73
  }
app/code/community/Listrak/Remarketing/Model/Click/Api.php CHANGED
@@ -12,34 +12,58 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Click_Api
16
  extends Mage_Api_Model_Resource_Abstract
17
  {
18
-
19
- public function items($storeId = 1, $startDate = null, $endDate = null,
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  $perPage = 50, $page = 1
21
- )
22
- {
 
 
 
 
 
23
  Mage::app()->setCurrentStore($storeId);
24
- Mage::helper('remarketing')->requireCoreEnabled();
25
 
26
- Mage::helper('remarketing')->requireClickTrackingTable();
27
 
28
- try {
29
- if ($startDate === null || !strtotime($startDate)) {
30
- $this->_fault('incorrect_date');
31
- }
32
 
33
- if ($endDate === null || !strtotime($endDate)) {
34
- $this->_fault('incorrect_date');
35
- }
36
 
37
- $clicks = Mage::getModel("listrak/click")->getCollection()
38
- ->addFieldToFilter('click_date', array('from' => $startDate, 'to' => $endDate))
 
 
 
 
 
 
 
39
  ->setPageSize($perPage)->setCurPage($page);
40
 
41
- $clicks->addStoreFilter($storeId);
42
-
43
  $result = array();
44
 
45
  foreach ($clicks as $item) {
@@ -48,25 +72,41 @@ class Listrak_Remarketing_Model_Click_Api
48
 
49
  return $result;
50
  } catch (Exception $e) {
51
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
52
  }
53
  }
54
 
 
 
 
 
 
 
 
 
 
 
55
  public function purge($storeId = 1, $endDate = null)
56
  {
57
- Mage::helper('remarketing')->requireClickTrackingTable();
 
58
 
59
- try {
60
- if ($endDate === null || !strtotime($endDate)) {
61
- $this->_fault('incorrect_date');
62
- }
 
63
 
 
64
  $clicks = Mage::getModel("listrak/click")
65
  ->getCollection()
66
  ->addFieldToFilter('click_date', array('lt' => $endDate));
67
 
68
  $count = 0;
69
 
 
70
  foreach ($clicks as $click) {
71
  $click->delete();
72
  $count++;
@@ -74,7 +114,9 @@ class Listrak_Remarketing_Model_Click_Api
74
 
75
  return $count;
76
  } catch (Exception $e) {
77
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
78
  }
79
  }
80
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Click_Api
17
+ */
18
  class Listrak_Remarketing_Model_Click_Api
19
  extends Mage_Api_Model_Resource_Abstract
20
  {
21
+ /**
22
+ * Retrieve clicks
23
+ *
24
+ * @param int $storeId Magento store ID
25
+ * @param datetime $startDate Lower date constraint
26
+ * @param datetime $endDate Upper date constraint
27
+ * @param int $perPage Page size
28
+ * @param int $page Cursor
29
+ *
30
+ * @return array
31
+ *
32
+ * @throws Exception
33
+ */
34
+ public function items(
35
+ $storeId = 1, $startDate = null, $endDate = null,
36
  $perPage = 50, $page = 1
37
+ ) {
38
+ /* @var Listrak_Remarketing_Helper_Data $helper */
39
+ $helper = Mage::helper('remarketing');
40
+
41
+ // does not require a store to check - it's either there or not there
42
+ $helper->requireClickTrackingTable();
43
+
44
  Mage::app()->setCurrentStore($storeId);
 
45
 
46
+ $helper->requireCoreEnabled();
47
 
48
+ if ($startDate === null || !strtotime($startDate)) {
49
+ $this->_fault('incorrect_date');
50
+ }
 
51
 
52
+ if ($endDate === null || !strtotime($endDate)) {
53
+ $this->_fault('incorrect_date');
54
+ }
55
 
56
+ try {
57
+ /* @var Listrak_Remarketing_Model_Mysql4_Click_Collection $clicks */
58
+ $clicks = Mage::getModel("listrak/click")->getCollection();
59
+
60
+ $clicks
61
+ ->addStoreFilter($storeId)
62
+ ->addFieldToFilter(
63
+ 'click_date', array('from' => $startDate, 'to' => $endDate)
64
+ )
65
  ->setPageSize($perPage)->setCurPage($page);
66
 
 
 
67
  $result = array();
68
 
69
  foreach ($clicks as $item) {
72
 
73
  return $result;
74
  } catch (Exception $e) {
75
+ throw $helper->generateAndLogException(
76
+ "Exception occurred in API call: " . $e->getMessage(), $e
77
+ );
78
  }
79
  }
80
 
81
+ /**
82
+ * Purge clicks
83
+ *
84
+ * @param int $storeId Magento store ID (deprecated)
85
+ * @param datetime $endDate Upper date constraint
86
+ *
87
+ * @return int
88
+ *
89
+ * @throws Exception
90
+ */
91
  public function purge($storeId = 1, $endDate = null)
92
  {
93
+ /* @var Listrak_Remarketing_Helper_Data $helper */
94
+ $helper = Mage::helper('remarketing');
95
 
96
+ $helper->requireClickTrackingTable();
97
+
98
+ if ($endDate === null || !strtotime($endDate)) {
99
+ $this->_fault('incorrect_date');
100
+ }
101
 
102
+ try {
103
  $clicks = Mage::getModel("listrak/click")
104
  ->getCollection()
105
  ->addFieldToFilter('click_date', array('lt' => $endDate));
106
 
107
  $count = 0;
108
 
109
+ /* @var Listrak_Remarketing_Model_Click $click */
110
  foreach ($clicks as $click) {
111
  $click->delete();
112
  $count++;
114
 
115
  return $count;
116
  } catch (Exception $e) {
117
+ throw $helper->generateAndLogException(
118
+ "Exception occurred in API call: " . $e->getMessage(), $e
119
+ );
120
  }
121
  }
122
  }
app/code/community/Listrak/Remarketing/Model/Click/Api/V2.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Click_Api_V2
16
  extends Listrak_Remarketing_Model_Click_Api
17
  {
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Click_Api_V2
17
+ */
18
  class Listrak_Remarketing_Model_Click_Api_V2
19
  extends Listrak_Remarketing_Model_Click_Api
20
  {
app/code/community/Listrak/Remarketing/Model/Emailcapture.php CHANGED
@@ -12,9 +12,18 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Emailcapture extends Mage_Core_Model_Abstract
16
  {
17
-
 
 
 
 
18
  public function _construct()
19
  {
20
  parent::_construct();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Emailcapture
17
+ *
18
+ * The code object for the database storage of captured emails
19
+ */
20
  class Listrak_Remarketing_Model_Emailcapture extends Mage_Core_Model_Abstract
21
  {
22
+ /**
23
+ * Initializes the object
24
+ *
25
+ * @return void
26
+ */
27
  public function _construct()
28
  {
29
  parent::_construct();
app/code/community/Listrak/Remarketing/Model/Log.php CHANGED
@@ -12,35 +12,63 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Log extends Mage_Core_Model_Abstract
16
  {
17
- const LOGTYPE_MESSAGE = 1;
18
- const LOGTYPE_EXCEPTION = 2;
19
 
 
 
 
 
 
20
  public function _construct()
21
  {
22
  parent::_construct();
23
  $this->_init('listrak/log');
24
  }
25
 
 
 
 
 
 
 
 
 
26
  public function addMessage($msg, $storeId = null)
27
  {
28
  if ($storeId == null) {
29
  $storeId = Mage::app()->getStore()->getStoreId();
30
  }
 
31
  $this->setMessage($msg);
32
- $this->setLogTypeId(self::LOGTYPE_MESSAGE);
33
  $this->setStoreId($storeId);
34
  $this->save();
35
  }
36
 
 
 
 
 
 
 
 
 
37
  public function addException($msg, $storeId = null)
38
  {
39
  if ($storeId == null) {
40
  $storeId = Mage::app()->getStore()->getStoreId();
41
  }
 
42
  $this->setMessage($msg);
43
- $this->setLogTypeId(self::LOGTYPE_EXCEPTION);
44
  $this->setStoreId($storeId);
45
  $this->save();
46
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Log
17
+ *
18
+ * Serves as the logger of the extension
19
+ */
20
  class Listrak_Remarketing_Model_Log extends Mage_Core_Model_Abstract
21
  {
22
+ const LOG_TYPE_MESSAGE = 1;
23
+ const LOG_TYPE_EXCEPTION = 2;
24
 
25
+ /**
26
+ * Initializes the object
27
+ *
28
+ * @return void
29
+ */
30
  public function _construct()
31
  {
32
  parent::_construct();
33
  $this->_init('listrak/log');
34
  }
35
 
36
+ /**
37
+ * Log a line
38
+ *
39
+ * @param string $msg Message
40
+ * @param int|null $storeId Magento store ID, defaults to current
41
+ *
42
+ * @return void
43
+ */
44
  public function addMessage($msg, $storeId = null)
45
  {
46
  if ($storeId == null) {
47
  $storeId = Mage::app()->getStore()->getStoreId();
48
  }
49
+
50
  $this->setMessage($msg);
51
+ $this->setLogTypeId(self::LOG_TYPE_MESSAGE);
52
  $this->setStoreId($storeId);
53
  $this->save();
54
  }
55
 
56
+ /**
57
+ * Log an exception
58
+ *
59
+ * @param string $msg Exception message
60
+ * @param null|int $storeId Magento store ID
61
+ *
62
+ * @return void
63
+ */
64
  public function addException($msg, $storeId = null)
65
  {
66
  if ($storeId == null) {
67
  $storeId = Mage::app()->getStore()->getStoreId();
68
  }
69
+
70
  $this->setMessage($msg);
71
+ $this->setLogTypeId(self::LOG_TYPE_EXCEPTION);
72
  $this->setStoreId($storeId);
73
  $this->save();
74
  }
app/code/community/Listrak/Remarketing/Model/Log/Api.php CHANGED
@@ -12,27 +12,50 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Log_Api
16
  extends Mage_Api_Model_Resource_Abstract
17
  {
18
 
19
- public function items($storeId = 1, $startDate = null, $endDate = null,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  $perPage = 50, $page = 1, $logTypeId = 0
21
- )
22
- {
23
- try {
24
- if ($startDate === null || !strtotime($startDate)) {
25
- $this->_fault('incorrect_date');
26
- }
27
 
28
- if ($endDate === null || !strtotime($endDate)) {
29
- $this->_fault('incorrect_date');
30
- }
31
 
32
- $logs = Mage::getModel("listrak/log")->getCollection()
33
- ->addFieldToFilter('date_entered', array('from' => $startDate, 'to' => $endDate))
34
- ->setPageSize($perPage)->setCurPage($page)
35
- ->addStoreFilter($storeId);
 
 
 
 
 
 
 
36
 
37
  $result = array();
38
 
@@ -42,23 +65,38 @@ class Listrak_Remarketing_Model_Log_Api
42
 
43
  return $result;
44
  } catch (Exception $e) {
45
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
 
 
46
  }
47
  }
48
 
 
 
 
 
 
 
 
 
 
 
49
  public function purge($storeId = 1, $endDate = null)
50
  {
51
- try {
52
- if ($endDate === null || !strtotime($endDate)) {
53
- $this->_fault('incorrect_date');
54
- }
55
 
 
56
  $logs = Mage::getModel("listrak/log")
57
  ->getCollection()
58
  ->addFieldToFilter('date_entered', array('lt' => $endDate));
59
 
60
  $count = 0;
61
 
 
62
  foreach ($logs as $log) {
63
  $log->delete();
64
  $count++;
@@ -66,12 +104,11 @@ class Listrak_Remarketing_Model_Log_Api
66
 
67
  return $count;
68
  } catch (Exception $e) {
69
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
 
 
70
  }
71
  }
72
-
73
- public function toggle($storeId = 1, $onOff = true)
74
- {
75
- return $onOff;
76
- }
77
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Log_Api
17
+ */
18
  class Listrak_Remarketing_Model_Log_Api
19
  extends Mage_Api_Model_Resource_Abstract
20
  {
21
 
22
+ /**
23
+ * Retrieve logged messages and exceptions
24
+ *
25
+ * @param int $storeId Magento store ID
26
+ * @param datetime $startDate Lower date constraint
27
+ * @param datetime $endDate Upper date constraint
28
+ * @param int $perPage Page size
29
+ * @param int $page Cursor
30
+ * @param int $logTypeId Filter by log type (deprecated)
31
+ *
32
+ * @return array
33
+ *
34
+ * @throws Exception
35
+ */
36
+ public function items(
37
+ $storeId = 1, $startDate = null, $endDate = null,
38
  $perPage = 50, $page = 1, $logTypeId = 0
39
+ ) {
40
+ if ($startDate === null || !strtotime($startDate)) {
41
+ $this->_fault('incorrect_date');
42
+ }
 
 
43
 
44
+ if ($endDate === null || !strtotime($endDate)) {
45
+ $this->_fault('incorrect_date');
46
+ }
47
 
48
+ try {
49
+ /* @var Listrak_Remarketing_Model_Mysql4_Log_Collection $logs */
50
+ $logs = Mage::getModel("listrak/log")->getCollection();
51
+
52
+ $logs
53
+ ->addStoreFilter($storeId)
54
+ ->addFieldToFilter(
55
+ 'date_entered',
56
+ array('from' => $startDate, 'to' => $endDate)
57
+ )
58
+ ->setPageSize($perPage)->setCurPage($page);
59
 
60
  $result = array();
61
 
65
 
66
  return $result;
67
  } catch (Exception $e) {
68
+ /* @var Listrak_Remarketing_Helper_Data $helper */
69
+ $helper = Mage::helper('remarketing');
70
+ throw $helper->generateAndLogException(
71
+ "Exception occurred in API call: " . $e->getMessage(), $e
72
+ );
73
  }
74
  }
75
 
76
+ /**
77
+ * Purge all log lines
78
+ *
79
+ * @param int $storeId Magento store ID (deprecated)
80
+ * @param datetime $endDate Upper date constraint
81
+ *
82
+ * @return int
83
+ *
84
+ * @throws Exception
85
+ */
86
  public function purge($storeId = 1, $endDate = null)
87
  {
88
+ if ($endDate === null || !strtotime($endDate)) {
89
+ $this->_fault('incorrect_date');
90
+ }
 
91
 
92
+ try {
93
  $logs = Mage::getModel("listrak/log")
94
  ->getCollection()
95
  ->addFieldToFilter('date_entered', array('lt' => $endDate));
96
 
97
  $count = 0;
98
 
99
+ /* @var Listrak_Remarketing_Model_Log $log */
100
  foreach ($logs as $log) {
101
  $log->delete();
102
  $count++;
104
 
105
  return $count;
106
  } catch (Exception $e) {
107
+ /* @var Listrak_Remarketing_Helper_Data $helper */
108
+ $helper = Mage::helper('remarketing');
109
+ throw $helper->generateAndLogException(
110
+ "Exception occurred in API call: " . $e->getMessage(), $e
111
+ );
112
  }
113
  }
 
 
 
 
 
114
  }
app/code/community/Listrak/Remarketing/Model/Log/Api/V2.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Log_Api_V2
16
  extends Listrak_Remarketing_Model_Log_Api
17
  {
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Log_Api_V2
17
+ */
18
  class Listrak_Remarketing_Model_Log_Api_V2
19
  extends Listrak_Remarketing_Model_Log_Api
20
  {
app/code/community/Listrak/Remarketing/Model/Mysql4/Abandonedcart.php CHANGED
@@ -12,52 +12,90 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Abandonedcart
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
18
- protected $_read;
19
-
20
- protected $_write;
21
-
 
22
  public function _construct()
23
  {
24
  $this->_init('listrak/session', 'id');
25
- $this->_read = $this->_getReadAdapter();
26
- $this->_write = $this->_getWriteAdapter();
27
  }
28
 
29
- protected function _afterLoad(Mage_Core_Model_Abstract $object)
 
 
 
 
 
 
 
30
  {
31
- $object->setSession(Mage::getModel("listrak/session")->load($object->getId()));
 
 
32
 
33
  $this->loadCart($object);
34
 
35
  return parent::_afterLoad($object);
36
  }
37
 
38
- protected function loadCart(Mage_Core_Model_Abstract $object)
 
 
 
 
 
 
 
39
  {
40
  $products = array();
41
 
42
- foreach (Mage::getModel('sales/quote')->load($object->getQuoteId())->getAllVisibleItems() as $item) {
 
 
 
43
  $products[] = $this->_getCartProductEntity($item, $object->getStoreId());
44
  }
45
 
46
  $object->setProducts($products);
47
  }
48
 
49
- private function _getCartProductEntity($item, $storeId)
50
- {
51
- $info = Mage::helper('remarketing/product')->getProductInformationFromQuoteItem($item, array('product'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
- $product = Mage::helper('remarketing/product')->getProductEntity($info->getProduct(), $storeId, false);
 
 
54
  $product["qty"] = $item->getQty();
55
  $product["price"] = $item->getCalculationPrice();
56
 
57
  if ($info->getIsBundle()) {
58
  $product['bundle_items'] = array();
59
  foreach ($item->getChildren() as $child) {
60
- $product['bundle_items'][] = $this->_getCartProductEntity($child, $storeId);
 
61
  }
62
  }
63
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Abandonedcart
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Abandonedcart
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /**
22
+ * Intializes resource
23
+ *
24
+ * @return void
25
+ */
26
  public function _construct()
27
  {
28
  $this->_init('listrak/session', 'id');
 
 
29
  }
30
 
31
+ /**
32
+ * Inflate abandoned cart
33
+ *
34
+ * @param Listrak_Remarketing_Model_Abandonedcart $object Abandoned cart
35
+ *
36
+ * @return Mage_Core_Model_Resource_Db_Abstract
37
+ */
38
+ protected function _afterLoad(Listrak_Remarketing_Model_Abandonedcart $object)
39
  {
40
+ $object->setSession(
41
+ Mage::getModel("listrak/session")->load($object->getId())
42
+ );
43
 
44
  $this->loadCart($object);
45
 
46
  return parent::_afterLoad($object);
47
  }
48
 
49
+ /**
50
+ * Inflate cart with product information
51
+ *
52
+ * @param Listrak_Remarketing_Model_Abandonedcart $object Abandoned cart
53
+ *
54
+ * @return void
55
+ */
56
+ protected function loadCart(Listrak_Remarketing_Model_Abandonedcart $object)
57
  {
58
  $products = array();
59
 
60
+ /* @var Mage_Sales_Model_Quote $quote */
61
+ $quote = Mage::getModel('sales/quote')->load($object->getQuoteId());
62
+
63
+ foreach ($quote->getAllVisibleItems() as $item) {
64
  $products[] = $this->_getCartProductEntity($item, $object->getStoreId());
65
  }
66
 
67
  $object->setProducts($products);
68
  }
69
 
70
+ /**
71
+ * Retrieve product information for quote item
72
+ *
73
+ * @param Mage_Sales_Model_Quote_Item $item Quote item
74
+ * @param int $storeId Magento store ID
75
+ *
76
+ * @return array
77
+ */
78
+ private function _getCartProductEntity(
79
+ Mage_Sales_Model_Quote_Item $item, $storeId
80
+ ) {
81
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
82
+ $productHelper = Mage::helper('remarketing/product');
83
+
84
+ $info = $productHelper->getProductInformationFromQuoteItem(
85
+ $item, array('product')
86
+ );
87
 
88
+ $product = $productHelper->getProductEntity(
89
+ $info->getProduct(), $storeId, false
90
+ );
91
  $product["qty"] = $item->getQty();
92
  $product["price"] = $item->getCalculationPrice();
93
 
94
  if ($info->getIsBundle()) {
95
  $product['bundle_items'] = array();
96
  foreach ($item->getChildren() as $child) {
97
+ $product['bundle_items'][]
98
+ = $this->_getCartProductEntity($child, $storeId);
99
  }
100
  }
101
 
app/code/community/Listrak/Remarketing/Model/Mysql4/Abandonedcart/Collection.php CHANGED
@@ -12,16 +12,27 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Abandonedcart_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
18
- private $_prepareForReport = false;
19
-
 
 
 
20
  protected function _construct()
21
  {
22
  $this->_init('listrak/abandonedcart');
23
  }
24
 
 
 
 
 
 
25
  protected function _initSelect()
26
  {
27
  parent::_initSelect();
@@ -32,15 +43,30 @@ class Listrak_Remarketing_Model_Mysql4_Abandonedcart_Collection
32
  'main_table.quote_id = q.entity_id',
33
  array('items_qty', 'grand_total')
34
  )
35
- ->where('main_table.had_items = 1 AND q.is_active = 1'); // is_active is set to false when the order is submitted
 
36
  }
37
 
 
 
 
 
 
 
 
38
  public function addStoreFilter($storeIds)
39
  {
40
  $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
41
  return $this;
42
  }
43
-
 
 
 
 
 
 
 
44
  public function addClearCartTrimFilter($fromDate)
45
  {
46
  $this->getSelect()
@@ -48,19 +74,16 @@ class Listrak_Remarketing_Model_Mysql4_Abandonedcart_Collection
48
  return $this;
49
  }
50
 
51
- public function setPrepareForReport($prepareForReport)
52
- {
53
- $this->_prepareForReport = $prepareForReport;
54
- return $this;
55
- }
56
-
57
  protected function _afterLoad()
58
  {
 
59
  foreach ($this->_items as $item) {
60
  $item->afterLoad();
61
- if ($this->_prepareForReport === true) {
62
- $item->prepareForReport();
63
- }
64
  }
65
 
66
  return parent::_afterLoad();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Abandonedcart_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Abandonedcart_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/abandonedcart');
29
  }
30
 
31
+ /**
32
+ * Initializes database select
33
+ *
34
+ * @return void
35
+ */
36
  protected function _initSelect()
37
  {
38
  parent::_initSelect();
43
  'main_table.quote_id = q.entity_id',
44
  array('items_qty', 'grand_total')
45
  )
46
+ ->where('main_table.had_items = 1 AND q.is_active = 1');
47
+ // is_active is set to false when the order is submitted
48
  }
49
 
50
+ /**
51
+ * Filter by store
52
+ *
53
+ * @param array|int $storeIds Magento store ID(s)
54
+ *
55
+ * @return $this
56
+ */
57
  public function addStoreFilter($storeIds)
58
  {
59
  $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
60
  return $this;
61
  }
62
+
63
+ /**
64
+ * Filter out carts that have been create and cleared in current time frame
65
+ *
66
+ * @param datetime $fromDate Lower date constraint
67
+ *
68
+ * @return $this
69
+ */
70
  public function addClearCartTrimFilter($fromDate)
71
  {
72
  $this->getSelect()
74
  return $this;
75
  }
76
 
77
+ /**
78
+ * Inflate items for reporting
79
+ *
80
+ * @return Mage_Core_Model_Resource_Db_Collection_Abstract
81
+ */
 
82
  protected function _afterLoad()
83
  {
84
+ /* @var Listrak_Remarketing_Model_Abandonedcart $item */
85
  foreach ($this->_items as $item) {
86
  $item->afterLoad();
 
 
 
87
  }
88
 
89
  return parent::_afterLoad();
app/code/community/Listrak/Remarketing/Model/Mysql4/Apiextension.php CHANGED
@@ -12,32 +12,44 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Apiextension
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
18
-
19
- protected $_read;
20
-
21
- protected $_write;
22
-
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/session', 'id');
26
- $this->_read = $this->_getReadAdapter();
27
- $this->_write = $this->_getWriteAdapter();
28
  }
29
 
30
- public function subscribers($storeId = 1, $startDate = null, $perPage = 50,
31
- $page = 1
32
- )
33
- {
 
 
 
 
 
 
 
 
 
 
 
34
 
35
- $collection = Mage::getModel("newsletter/subscriber")->getCollection()
36
- ->addStoreFilter($storeId)
37
  ->setPageSize($perPage)
38
  ->setCurPage($page);
39
 
40
  $collection->getSelect()
 
41
  ->join(
42
  array('su' => $collection->getTable('listrak/subscriber_update')),
43
  'main_table.subscriber_id = su.subscriber_id',
@@ -48,22 +60,27 @@ class Listrak_Remarketing_Model_Mysql4_Apiextension
48
 
49
  $collection->setOrder('su.updated_at', 'ASC');
50
 
 
51
  foreach ($collection as $c) {
52
  switch ($c->getSubscriberStatus()) {
53
- case "1":
54
- $c->setSubscriberStatus("subscribed");
55
- break;
56
- case "2":
57
- $c->setSubscriberStatus("inactive");
58
- break;
59
- case "3":
60
- $c->setSubscriberStatus("unsubscribed");
61
- break;
62
- case "4":
63
- $c->setSubscriberStatus("unconfirmed");
64
- break;
65
- default:
66
- break;
 
 
 
 
67
  }
68
  }
69
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Apiextension
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Apiextension
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /**
22
+ * Initializes resource
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/session', 'id');
 
 
29
  }
30
 
31
+ /**
32
+ * Retrieves subscriber information
33
+ *
34
+ * @param int $storeId Magento store ID
35
+ * @param null $startDate Data constraint, lower
36
+ * @param int $perPage Page size
37
+ * @param int $page Cursor
38
+ *
39
+ * @return Mage_Newsletter_Model_Resource_Subscriber_Collection
40
+ */
41
+ public function subscribers(
42
+ $storeId = 1, $startDate = null, $perPage = 50, $page = 1
43
+ ) {
44
+ /* @var Mage_Newsletter_Model_Resource_Subscriber_Collection $collection */
45
+ $collection = Mage::getModel("newsletter/subscriber")->getCollection();
46
 
47
+ $collection->addStoreFilter($storeId)
 
48
  ->setPageSize($perPage)
49
  ->setCurPage($page);
50
 
51
  $collection->getSelect()
52
+ ->group('main_table.subscriber_id')
53
  ->join(
54
  array('su' => $collection->getTable('listrak/subscriber_update')),
55
  'main_table.subscriber_id = su.subscriber_id',
60
 
61
  $collection->setOrder('su.updated_at', 'ASC');
62
 
63
+ /* @var Mage_Newsletter_Model_Subscriber $c */
64
  foreach ($collection as $c) {
65
  switch ($c->getSubscriberStatus()) {
66
+ case "1":
67
+ $c->setSubscriberStatus("subscribed");
68
+ break;
69
+
70
+ case "2":
71
+ $c->setSubscriberStatus("inactive");
72
+ break;
73
+
74
+ case "3":
75
+ $c->setSubscriberStatus("unsubscribed");
76
+ break;
77
+
78
+ case "4":
79
+ $c->setSubscriberStatus("unconfirmed");
80
+ break;
81
+
82
+ default:
83
+ break;
84
  }
85
  }
86
 
app/code/community/Listrak/Remarketing/Model/Mysql4/Click.php CHANGED
@@ -12,25 +12,37 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Click
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
 
 
18
 
19
- protected $_read;
20
-
21
- protected $_write;
22
-
 
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/click', 'click_id');
26
  $this->_read = $this->_getReadAdapter();
27
- $this->_write = $this->_getWriteAdapter();
28
  }
29
 
 
 
 
 
 
 
 
30
  public function loadByQuoteId($quoteId)
31
  {
32
  $select = $this->_read->select()
33
- ->from($this->getTable('listrak/session'))
34
  ->where('quote_id=?', $quoteId)
35
  ->join(
36
  array('c' => $this->getTable('listrak/click')),
@@ -45,11 +57,22 @@ class Listrak_Remarketing_Model_Mysql4_Click
45
  return array();
46
  }
47
 
 
 
 
 
 
 
 
48
  public function loadLatestByQuoteId($quoteId)
49
  {
50
  $select = $this->_read->select()
51
- ->from(array('c' => $this->getTable('listrak/click')))
52
- ->joinInner(array('s' => $this->getTable('listrak/session')), 's.id = c.session_id', array())
 
 
 
 
53
  ->where('s.quote_id = ?', $quoteId)
54
  ->order('click_id ' . Varien_Db_Select::SQL_DESC)
55
  ->limit(0, 1);
@@ -61,11 +84,22 @@ class Listrak_Remarketing_Model_Mysql4_Click
61
  }
62
  }
63
 
 
 
 
 
 
 
 
64
  public function loadLatestBySessionId($sid)
65
  {
66
  $select = $this->_read->select()
67
- ->from(array('c' => $this->getTable('listrak/click')))
68
- ->joinInner(array('s' => $this->getTable('listrak/session')), 's.id = c.session_id', array())
 
 
 
 
69
  ->where('s.session_id = ?', $sid)
70
  ->order('click_id ' . Varien_Db_Select::SQL_DESC)
71
  ->limit(0, 1);
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Click
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Click
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /* @var Varien_Db_Adapter_Interface $_read */
22
+ private $_read;
23
 
24
+ /**
25
+ * Initializes resource
26
+ *
27
+ * @return void
28
+ */
29
  protected function _construct()
30
  {
31
  $this->_init('listrak/click', 'click_id');
32
  $this->_read = $this->_getReadAdapter();
 
33
  }
34
 
35
+ /**
36
+ * Load data associated with a quote
37
+ *
38
+ * @param int $quoteId Magento quote ID
39
+ *
40
+ * @return array
41
+ */
42
  public function loadByQuoteId($quoteId)
43
  {
44
  $select = $this->_read->select()
45
+ ->from($this->getTable('listrak/session'), array("*"))
46
  ->where('quote_id=?', $quoteId)
47
  ->join(
48
  array('c' => $this->getTable('listrak/click')),
57
  return array();
58
  }
59
 
60
+ /**
61
+ * Retrieve last click's data for a quote
62
+ *
63
+ * @param int $quoteId Magento quote ID
64
+ *
65
+ * @return array|null
66
+ */
67
  public function loadLatestByQuoteId($quoteId)
68
  {
69
  $select = $this->_read->select()
70
+ ->from(array('c' => $this->getTable('listrak/click')), array("*"))
71
+ ->joinInner(
72
+ array('s' => $this->getTable('listrak/session')),
73
+ 's.id = c.session_id',
74
+ array()
75
+ )
76
  ->where('s.quote_id = ?', $quoteId)
77
  ->order('click_id ' . Varien_Db_Select::SQL_DESC)
78
  ->limit(0, 1);
84
  }
85
  }
86
 
87
+ /**
88
+ * Retrieve last click's data for a session
89
+ *
90
+ * @param string $sid Session UID
91
+ *
92
+ * @return array|null
93
+ */
94
  public function loadLatestBySessionId($sid)
95
  {
96
  $select = $this->_read->select()
97
+ ->from(array('c' => $this->getTable('listrak/click')), array("*"))
98
+ ->joinInner(
99
+ array('s' => $this->getTable('listrak/session')),
100
+ 's.id = c.session_id',
101
+ array()
102
+ )
103
  ->where('s.session_id = ?', $sid)
104
  ->order('click_id ' . Varien_Db_Select::SQL_DESC)
105
  ->limit(0, 1);
app/code/community/Listrak/Remarketing/Model/Mysql4/Click/Collection.php CHANGED
@@ -12,15 +12,29 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Click_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
18
-
 
 
 
 
19
  protected function _construct()
20
  {
21
  $this->_init('listrak/click');
22
  }
23
 
 
 
 
 
 
 
 
24
  public function addStoreFilter($storeId)
25
  {
26
  $this->getSelect()
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Click_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Click_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/click');
29
  }
30
 
31
+ /**
32
+ * Filter by store
33
+ *
34
+ * @param array|int $storeId Magento store ID(s)
35
+ *
36
+ * @return $this
37
+ */
38
  public function addStoreFilter($storeId)
39
  {
40
  $this->getSelect()
app/code/community/Listrak/Remarketing/Model/Mysql4/Emailcapture.php CHANGED
@@ -12,18 +12,19 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Emailcapture
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
18
-
19
- protected $_read;
20
-
21
- protected $_write;
22
-
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/emailcapture', 'emailcapture_id');
26
- $this->_read = $this->_getReadAdapter();
27
- $this->_write = $this->_getWriteAdapter();
28
  }
29
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Emailcapture
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Emailcapture
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /**
22
+ * Initializes resource
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/emailcapture', 'emailcapture_id');
 
 
29
  }
30
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Emailcapture/Collection.php CHANGED
@@ -12,10 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Emailcapture_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
18
-
 
 
 
 
19
  protected function _construct()
20
  {
21
  $this->_init('listrak/emailcapture');
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Emailcapture_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Emailcapture_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/emailcapture');
app/code/community/Listrak/Remarketing/Model/Mysql4/Log.php CHANGED
@@ -12,17 +12,18 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract
16
  {
17
-
18
- protected $_read;
19
-
20
- protected $_write;
21
-
22
  protected function _construct()
23
  {
24
  $this->_init('listrak/log', 'id');
25
- $this->_read = $this->_getReadAdapter();
26
- $this->_write = $this->_getWriteAdapter();
27
  }
28
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Log
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Log extends Mage_Core_Model_Mysql4_Abstract
19
  {
20
+ /**
21
+ * Initializes resource
22
+ *
23
+ * @return void
24
+ */
25
  protected function _construct()
26
  {
27
  $this->_init('listrak/log', 'id');
 
 
28
  }
29
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Log/Collection.php CHANGED
@@ -12,14 +12,29 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Log_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
 
 
 
 
 
18
  protected function _construct()
19
  {
20
  $this->_init('listrak/log');
21
  }
22
 
 
 
 
 
 
 
 
23
  public function addStoreFilter($storeIds)
24
  {
25
  $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Log_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Log_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/log');
29
  }
30
 
31
+ /**
32
+ * Filter by store
33
+ *
34
+ * @param array|int $storeIds Magento store ID(s)
35
+ *
36
+ * @return $this
37
+ */
38
  public function addStoreFilter($storeIds)
39
  {
40
  $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
app/code/community/Listrak/Remarketing/Model/Mysql4/Product.php ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.0.0
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2011 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Product
17
+ */
18
+ class Listrak_Remarketing_Model_Mysql4_Product
19
+ extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product
20
+ {
21
+
22
+ }
app/code/community/Listrak/Remarketing/Model/Mysql4/Product/Attribute/Set/Map.php CHANGED
@@ -12,19 +12,18 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
18
-
19
- protected $_read;
20
-
21
- protected $_write;
22
-
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/product_attribute_set_map', 'map_id');
26
- $this->_read = $this->_getReadAdapter();
27
- $this->_write = $this->_getWriteAdapter();
28
  }
29
 
30
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /**
22
+ * Initializes resource
23
+ */
 
 
24
  protected function _construct()
25
  {
26
  $this->_init('listrak/product_attribute_set_map', 'map_id');
 
 
27
  }
28
 
29
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Product/Attribute/Set/Map/Collection.php CHANGED
@@ -12,18 +12,36 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
18
  // so we don't go getting it all the time
19
  private $_productTypeId;
20
 
 
 
 
 
 
21
  protected function _construct()
22
  {
23
  $this->_init('listrak/product_attribute_set_map');
24
- $this->_productTypeId = Mage::getModel('catalog/product')->getResource()->getTypeId();
 
 
 
25
  }
26
 
 
 
 
 
 
 
 
27
  public function addMapIdFilter($ids)
28
  {
29
  $this->getSelect()->where('map_id IN (' . $ids . ')');
@@ -31,21 +49,36 @@ class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
31
  return $this;
32
  }
33
 
34
- public function addAttributeSetFilter($id)
 
 
 
 
 
 
 
35
  {
36
- $this->getSelect()->where('attribute_set_id = ' . $id);
37
 
38
  return $this;
39
  }
40
 
 
 
 
 
 
41
  public function addAttributeSetName()
42
  {
 
43
  $resource = Mage::getSingleton('core/resource');
44
 
45
  // join in with the current settings to fetch attribute codes
46
  $this->getSelect()
47
  ->join(
48
- array('attribute_set' => $resource->getTableName('eav/attribute_set')),
 
 
49
  'main_table.attribute_set_id = attribute_set.attribute_set_id',
50
  array('attribute_set_name')
51
  );
@@ -56,10 +89,17 @@ class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
56
  return $this;
57
  }
58
 
 
 
 
 
 
59
  public function addAttributeNames()
60
  {
61
- $r = Mage::getSingleton('core/resource');
62
- $attributeTable = $r->getTableName('eav/attribute');
 
 
63
 
64
  // add brand attribute name
65
  $this->getSelect()
@@ -80,8 +120,8 @@ class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
80
  // add subcategory attribute name
81
  $this->getSelect()
82
  ->joinLeft(
83
- array('subcat_attribute' => $attributeTable),
84
- 'main_table.subcategory_attribute_code = subcat_attribute.attribute_code',
85
  array('subcategory_attribute_name' => 'frontend_label')
86
  );
87
 
@@ -89,8 +129,8 @@ class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
89
  . ' OR brand_attribute.entity_type_id IS NULL';
90
  $categoryFilter = 'cat_attribute.entity_type_id = ' . $this->_productTypeId
91
  . ' OR cat_attribute.entity_type_id IS NULL';
92
- $subcategoryFiler = 'subcat_attribute.entity_type_id = '
93
- . $this->_productTypeId . ' OR subcat_attribute.entity_type_id IS NULL';
94
  $this->getSelect()
95
  ->where($brandFilter)
96
  ->where($categoryFilter)
@@ -99,6 +139,11 @@ class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
99
  return $this;
100
  }
101
 
 
 
 
 
 
102
  public function orderByAttributeSetName()
103
  {
104
  $this->getSelect()->order('attribute_set_name ' . Varien_Db_Select::SQL_ASC);
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
  // so we don't go getting it all the time
22
  private $_productTypeId;
23
 
24
+ /**
25
+ * Initializes collection
26
+ *
27
+ * @return void
28
+ */
29
  protected function _construct()
30
  {
31
  $this->_init('listrak/product_attribute_set_map');
32
+
33
+ /* @var Mage_Catalog_Model_Resource_Product $productResource */
34
+ $productResource = Mage::getModel('catalog/product')->getResource();
35
+ $this->_productTypeId = $productResource->getTypeId();
36
  }
37
 
38
+ /**
39
+ * Filter by map
40
+ *
41
+ * @param array|int $ids Filter ID(s)
42
+ *
43
+ * @return $this
44
+ */
45
  public function addMapIdFilter($ids)
46
  {
47
  $this->getSelect()->where('map_id IN (' . $ids . ')');
49
  return $this;
50
  }
51
 
52
+ /**
53
+ * Filter by an attribute set
54
+ *
55
+ * @param int $setId Attribute set ID
56
+ *
57
+ * @return $this
58
+ */
59
+ public function addAttributeSetFilter($setId)
60
  {
61
+ $this->getSelect()->where('attribute_set_id = ' . $setId);
62
 
63
  return $this;
64
  }
65
 
66
+ /**
67
+ * Add attribute set name to collection
68
+ *
69
+ * @return $this
70
+ */
71
  public function addAttributeSetName()
72
  {
73
+ /* @var Mage_Core_Model_Resource $resource */
74
  $resource = Mage::getSingleton('core/resource');
75
 
76
  // join in with the current settings to fetch attribute codes
77
  $this->getSelect()
78
  ->join(
79
+ array(
80
+ 'attribute_set' => $resource->getTableName('eav/attribute_set')
81
+ ),
82
  'main_table.attribute_set_id = attribute_set.attribute_set_id',
83
  array('attribute_set_name')
84
  );
89
  return $this;
90
  }
91
 
92
+ /**
93
+ * Add attribute names to collection
94
+ *
95
+ * @return $this
96
+ */
97
  public function addAttributeNames()
98
  {
99
+ /* @var Mage_Core_Model_Resource $resource */
100
+ $resource = Mage::getSingleton('core/resource');
101
+
102
+ $attributeTable = $resource->getTableName('eav/attribute');
103
 
104
  // add brand attribute name
105
  $this->getSelect()
120
  // add subcategory attribute name
121
  $this->getSelect()
122
  ->joinLeft(
123
+ array('subcat_attr' => $attributeTable),
124
+ 'main_table.subcategory_attribute_code = subcat_attr.attribute_code',
125
  array('subcategory_attribute_name' => 'frontend_label')
126
  );
127
 
129
  . ' OR brand_attribute.entity_type_id IS NULL';
130
  $categoryFilter = 'cat_attribute.entity_type_id = ' . $this->_productTypeId
131
  . ' OR cat_attribute.entity_type_id IS NULL';
132
+ $subcategoryFiler = 'subcat_attr.entity_type_id = '
133
+ . $this->_productTypeId . ' OR subcat_attr.entity_type_id IS NULL';
134
  $this->getSelect()
135
  ->where($brandFilter)
136
  ->where($categoryFilter)
139
  return $this;
140
  }
141
 
142
+ /**
143
+ * Order collection by attribute set name
144
+ *
145
+ * @return $this
146
+ */
147
  public function orderByAttributeSetName()
148
  {
149
  $this->getSelect()->order('attribute_set_name ' . Varien_Db_Select::SQL_ASC);
app/code/community/Listrak/Remarketing/Model/Mysql4/Product/Collection.php ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.0.0
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2011 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Product_Collection
17
+ */
18
+ class Listrak_Remarketing_Model_Mysql4_Product_Collection
19
+ extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
20
+ {
21
+ private $_storeFilter = null;
22
+
23
+ private $_withResolution = true;
24
+
25
+ /**
26
+ * Retrieve is flat enabled flag
27
+ * Return alvays false if magento run admin
28
+ *
29
+ * @return bool
30
+ */
31
+ public function isEnabledFlat()
32
+ {
33
+ return false;
34
+ }
35
+
36
+ /**
37
+ * Initialize resources
38
+ *
39
+ */
40
+ protected function _construct()
41
+ {
42
+ $this->_init('listrak/product');
43
+ parent::_construct();
44
+ }
45
+
46
+ /**
47
+ * Add store availability filter. Include availability product
48
+ * for store website
49
+ *
50
+ * @param mixed $store
51
+ * @return Listrak_Remarketing_Model_Mysql4_Product_Collection
52
+ */
53
+ public function addStoreFilter($store = null)
54
+ {
55
+ $this->_storeFilter = $store;
56
+ parent::addStoreFilter($store);
57
+
58
+ return $this;
59
+ }
60
+
61
+ public function addModifiedFilter($startDate, $endDate)
62
+ {
63
+ $this->addAttributeToFilter(
64
+ 'updated_at',
65
+ array('from' => $startDate, 'to' => $endDate)
66
+ );
67
+
68
+ return $this;
69
+ }
70
+
71
+ public function disabledAttributeResolutionAfterLoad()
72
+ {
73
+ $this->_withResolution = false;
74
+ return $this;
75
+ }
76
+
77
+ /**
78
+ * After load method
79
+ *
80
+ * @return Mage_Eav_Model_Entity_Collection_Abstract
81
+ */
82
+ protected function _afterLoad()
83
+ {
84
+ if ($this->_withResolution) {
85
+ $this->_loadParentProducts();
86
+ }
87
+
88
+ return $this;
89
+ }
90
+
91
+ protected function _loadParentProducts()
92
+ {
93
+ $parentsById = array();
94
+
95
+ /* @var Mage_Catalog_Model_Product_Type_Configurable $confProductModel */
96
+ $confProductModel = Mage::getModel('catalog/product_type_configurable');
97
+
98
+ foreach($this->_items as $product) {
99
+ $ids = $confProductModel
100
+ ->getParentIdsByChild($product->getEntityId());
101
+
102
+ if (is_array($ids) && count($ids) > 0) {
103
+ $parentId = $ids[0];
104
+ if ($parentId != null) {
105
+ $parentsById[$product->getEntityId()] = $parentId;
106
+ }
107
+ }
108
+ }
109
+
110
+ $parentIds = array_unique(array_values($parentsById));
111
+
112
+ if (count($parentsById) > 0) {
113
+ $parentCollection = Mage::getModel('listrak/product')
114
+ ->getCollection()
115
+ ->addAttributeToSelect('*')
116
+ ->addAttributeToFilter('entity_id', array('in' => $parentIds))
117
+ ->disabledAttributeResolutionAfterLoad();
118
+
119
+ if ($this->_storeFilter != null) {
120
+ $parentCollection->addStoreFilter($this->_storeFilter);
121
+ }
122
+
123
+ foreach($parentCollection as $parent) {
124
+ $pid = $parent->getEntityId();
125
+
126
+ foreach($this->_items as $product) {
127
+ $id = $product->getEntityId();
128
+
129
+ if (array_key_exists($id, $parentsById) && $parentsById[$id] == $pid) {
130
+ $product->setParentProduct($parent);
131
+ }
132
+ }
133
+ }
134
+ }
135
+ }
136
+
137
+ public function getAttributeOptions()
138
+ {
139
+ $result = array();
140
+
141
+ $allSelectAttributes = Mage::getSingleton('eav/config')
142
+ ->getEntityType($this->getEntity()->getType())
143
+ ->getAttributeCollection()
144
+ ->addFieldToFilter('frontend_input', array('in' => array('select', 'multiselect')))
145
+ ->getItems();
146
+
147
+ foreach ($allSelectAttributes as $attr) {
148
+ $result[$attr->getAttributeCode()] = array(
149
+ 'multiple' => $attr->getFrontendInput() == 'multiselect',
150
+ 'id' => $attr->getId());
151
+ }
152
+
153
+ $collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
154
+ ->setPositionOrder('asc')
155
+ ->addFieldToFilter(
156
+ 'attribute_id',
157
+ array('in' => array_map(function($r) { return $r['id']; }, $result)))
158
+ ->setStoreFilter(1);
159
+
160
+ foreach($collection as $option) {
161
+ foreach($result as $attr) {
162
+ if ($attr['id'] == $option->getAttributeId()) {
163
+ $attr['options'][$option->getOptionId()] = $option->getValue();
164
+ break;
165
+ }
166
+ }
167
+ }
168
+
169
+ foreach ($allSelectAttributes as $attr) {
170
+ $attrCode = $attr->getAttributeCode();
171
+ if (!array_key_exists('options', $result[$attrCode])) {
172
+ $result[$attrCode]['options'] = array();
173
+ foreach($attr->getSource()->getAllOptions() as $option) {
174
+ $val = $option['value'];
175
+ if (!is_array($val) && $val != '') {
176
+ $result[$attrCode]['options'][$val]
177
+ = $option['label'];
178
+ }
179
+ }
180
+ }
181
+ }
182
+
183
+ return $result;
184
+ }
185
+ }
app/code/community/Listrak/Remarketing/Model/Mysql4/Review/Update.php CHANGED
@@ -12,19 +12,20 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Review_Update
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
18
-
19
- protected $_read;
20
-
21
- protected $_write;
22
-
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/review_update', 'update_id');
26
- $this->_read = $this->_getReadAdapter();
27
- $this->_write = $this->_getWriteAdapter();
28
  }
29
 
30
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Review_Update
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Review_Update
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /**
22
+ * Initializes resource
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/review_update', 'update_id');
 
 
29
  }
30
 
31
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Review/Update/Collection.php CHANGED
@@ -12,14 +12,27 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
 
 
 
 
 
18
  protected function _construct()
19
  {
20
  $this->_init('listrak/review_update');
21
  }
22
 
 
 
 
 
 
23
  public function productReviewsOnly()
24
  {
25
  $this->getSelect()
@@ -28,6 +41,11 @@ class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
28
  return $this;
29
  }
30
 
 
 
 
 
 
31
  public function updatedRowsOnly()
32
  {
33
  $this->getSelect()
@@ -36,6 +54,11 @@ class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
36
  return $this;
37
  }
38
 
 
 
 
 
 
39
  public function deletedRowsOnly()
40
  {
41
  $this->getSelect()
@@ -44,6 +67,11 @@ class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
44
  return $this;
45
  }
46
 
 
 
 
 
 
47
  public function getReviewUpdateTime()
48
  {
49
  $this->productReviewsOnly()
@@ -57,16 +85,25 @@ class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
57
  return $this;
58
  }
59
 
 
 
 
 
 
60
  public function getRatingSummaryUpdateTime()
61
  {
 
 
 
62
  $this->productReviewsOnly()
63
  ->getSelect()
64
  ->reset(Zend_Db_Select::COLUMNS)
65
  ->columns(array("update_id" => "MAX(update_id)"))
66
  ->columns(array("updated_at" => "MAX(activity_time)"))
67
  ->join(
68
- array("agg" => Mage::getSingleton('core/resource')->getTableName('review/review_aggregate')),
69
- "main_table.entity_pk_value = agg.entity_pk_value AND main_table.entity_id = agg.entity_type",
 
70
  array("rating_summary_id" => "primary_id", "store_id" => "store_id")
71
  )
72
  ->group(array("agg.primary_id", "agg.store_id"));
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/review_update');
29
  }
30
 
31
+ /**
32
+ * Filter to product reviews only
33
+ *
34
+ * @return $this
35
+ */
36
  public function productReviewsOnly()
37
  {
38
  $this->getSelect()
41
  return $this;
42
  }
43
 
44
+ /**
45
+ * Filter to reviews that have been updated
46
+ *
47
+ * @return $this
48
+ */
49
  public function updatedRowsOnly()
50
  {
51
  $this->getSelect()
54
  return $this;
55
  }
56
 
57
+ /**
58
+ * Filter to reviews that have been deleted
59
+ *
60
+ * @return $this
61
+ */
62
  public function deletedRowsOnly()
63
  {
64
  $this->getSelect()
67
  return $this;
68
  }
69
 
70
+ /**
71
+ * Add review update information to the collection
72
+ *
73
+ * @return $this
74
+ */
75
  public function getReviewUpdateTime()
76
  {
77
  $this->productReviewsOnly()
85
  return $this;
86
  }
87
 
88
+ /**
89
+ * Retrieve collection with rating summary update times
90
+ *
91
+ * @return $this
92
+ */
93
  public function getRatingSummaryUpdateTime()
94
  {
95
+ /* @var Mage_Core_Model_Resource $resource */
96
+ $resource = Mage::getSingleton('core/resource');
97
+
98
  $this->productReviewsOnly()
99
  ->getSelect()
100
  ->reset(Zend_Db_Select::COLUMNS)
101
  ->columns(array("update_id" => "MAX(update_id)"))
102
  ->columns(array("updated_at" => "MAX(activity_time)"))
103
  ->join(
104
+ array("agg" => $resource->getTableName('review/review_aggregate')),
105
+ "main_table.entity_pk_value = agg.entity_pk_value "
106
+ . "AND main_table.entity_id = agg.entity_type",
107
  array("rating_summary_id" => "primary_id", "store_id" => "store_id")
108
  )
109
  ->group(array("agg.primary_id", "agg.store_id"));
app/code/community/Listrak/Remarketing/Model/Mysql4/Session.php CHANGED
@@ -12,14 +12,23 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Session
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
 
 
18
 
19
- protected $_read;
20
-
21
- protected $_write;
22
 
 
 
 
 
 
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/session', 'id');
@@ -27,13 +36,26 @@ class Listrak_Remarketing_Model_Mysql4_Session
27
  $this->_write = $this->_getWriteAdapter();
28
  }
29
 
30
- protected function _afterLoad(Mage_Core_Model_Abstract $object)
 
 
 
 
 
 
 
31
  {
32
  if ($object->getCustomerId()) {
33
- $cust = Mage::getModel("customer/customer")->load($object->getCustomerId());
34
- if ($cust) {
35
- Mage::helper('remarketing')->setGroupNameAndGenderNameForCustomer($cust);
36
- $object->setCustomer($cust);
 
 
 
 
 
 
37
  }
38
  }
39
 
@@ -41,13 +63,21 @@ class Listrak_Remarketing_Model_Mysql4_Session
41
  $this->loadEmails($object);
42
  $this->loadClicks($object);
43
  }
 
44
  return parent::_afterLoad($object);
45
  }
46
 
 
 
 
 
 
 
 
47
  public function loadBySessionId(Listrak_Remarketing_Model_Session $session)
48
  {
49
  $select = $this->_read->select()
50
- ->from($this->getTable('listrak/session'))
51
  ->where('session_id=?', $session->getSessionId());
52
 
53
  if ($result = $this->_read->fetchRow($select)) {
@@ -56,10 +86,17 @@ class Listrak_Remarketing_Model_Mysql4_Session
56
  }
57
  }
58
 
 
 
 
 
 
 
 
59
  public function loadByQuoteId(Listrak_Remarketing_Model_Session $session)
60
  {
61
  $select = $this->_read->select()
62
- ->from($this->getTable('listrak/session'))
63
  ->where('quote_id=?', $session->getQuoteId());
64
 
65
  if ($result = $this->_read->fetchRow($select)) {
@@ -68,10 +105,19 @@ class Listrak_Remarketing_Model_Mysql4_Session
68
  }
69
  }
70
 
71
- public function insertEmail(Listrak_Remarketing_Model_Session $session, $email,
72
- $emailcaptureId
73
- )
74
- {
 
 
 
 
 
 
 
 
 
75
  if ($session->getId()) {
76
  $data = array();
77
  $data['session_id'] = $session->getId();
@@ -82,10 +128,20 @@ class Listrak_Remarketing_Model_Mysql4_Session
82
  }
83
  }
84
 
 
 
 
 
 
 
 
85
  public function loadEmails(Listrak_Remarketing_Model_Session $session)
86
  {
87
  $select = $this->_read->select()
88
- ->from(array('se' => $this->getTable('listrak/session_email')))
 
 
 
89
  ->joinLeft(
90
  array('ec' => $this->getTable('listrak/emailcapture')),
91
  'se.emailcapture_id = ec.emailcapture_id',
@@ -97,13 +153,20 @@ class Listrak_Remarketing_Model_Mysql4_Session
97
  $session->setEmails($emails);
98
  }
99
 
 
 
 
 
 
 
 
100
  public function loadClicks(Listrak_Remarketing_Model_Session $session)
101
  {
102
- $clicks = Mage::getModel("listrak/click")->getCollection()
103
- ->addFieldToFilter('session_id', array('eq' => $session->getId()));
 
104
 
105
  $sessionClicks = array();
106
-
107
  foreach ($clicks as $click) {
108
  $sessionClicks[] = $click;
109
  }
@@ -111,8 +174,18 @@ class Listrak_Remarketing_Model_Mysql4_Session
111
  $session->setData('clicks', $sessionClicks);
112
  }
113
 
114
- public function deleteEmails($id)
 
 
 
 
 
 
 
115
  {
116
- $this->_write->delete($this->getTable("listrak/session_email"), "session_id = $id");
 
 
 
117
  }
118
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Session
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Session
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /* @var Varien_Db_Adapter_Interface $_read */
22
+ private $_read;
23
 
24
+ /* @var Varien_Db_Adapter_Interface $_write */
25
+ private $_write;
 
26
 
27
+ /**
28
+ * Initializes the resource
29
+ *
30
+ * @return void
31
+ */
32
  protected function _construct()
33
  {
34
  $this->_init('listrak/session', 'id');
36
  $this->_write = $this->_getWriteAdapter();
37
  }
38
 
39
+ /**
40
+ * Inflate session object
41
+ *
42
+ * @param Listrak_Remarketing_Model_Session $object Session
43
+ *
44
+ * @return Listrak_Remarketing_Model_Session
45
+ */
46
+ protected function _afterLoad(Listrak_Remarketing_Model_Session $object)
47
  {
48
  if ($object->getCustomerId()) {
49
+ /* @var Mage_Customer_Model_Customer $customer */
50
+ $customer = Mage::getModel("customer/customer")
51
+ ->load($object->getCustomerId());
52
+
53
+ if ($customer) {
54
+ /* @var Listrak_Remarketing_Helper_Data $helper */
55
+ $helper = Mage::helper('remarketing');
56
+
57
+ $helper->setGroupNameAndGenderNameForCustomer($customer);
58
+ $object->setCustomer($customer);
59
  }
60
  }
61
 
63
  $this->loadEmails($object);
64
  $this->loadClicks($object);
65
  }
66
+
67
  return parent::_afterLoad($object);
68
  }
69
 
70
+ /**
71
+ * Load session by ID
72
+ *
73
+ * @param Listrak_Remarketing_Model_Session $session Session
74
+ *
75
+ * @return void
76
+ */
77
  public function loadBySessionId(Listrak_Remarketing_Model_Session $session)
78
  {
79
  $select = $this->_read->select()
80
+ ->from($this->getTable('listrak/session'), array("*"))
81
  ->where('session_id=?', $session->getSessionId());
82
 
83
  if ($result = $this->_read->fetchRow($select)) {
86
  }
87
  }
88
 
89
+ /**
90
+ * Load session tied to a quote
91
+ *
92
+ * @param Listrak_Remarketing_Model_Session $session Session
93
+ *
94
+ * @return void
95
+ */
96
  public function loadByQuoteId(Listrak_Remarketing_Model_Session $session)
97
  {
98
  $select = $this->_read->select()
99
+ ->from($this->getTable('listrak/session'), array("*"))
100
  ->where('quote_id=?', $session->getQuoteId());
101
 
102
  if ($result = $this->_read->fetchRow($select)) {
105
  }
106
  }
107
 
108
+ /**
109
+ * Save captured email address to the database
110
+ *
111
+ * @param Listrak_Remarketing_Model_Session $session Session
112
+ * @param string $email Email address
113
+ * @param int $emailcaptureId Capturing field
114
+ *
115
+ * @return void
116
+ */
117
+ public function insertEmail(
118
+ Listrak_Remarketing_Model_Session $session,
119
+ $email, $emailcaptureId
120
+ ) {
121
  if ($session->getId()) {
122
  $data = array();
123
  $data['session_id'] = $session->getId();
128
  }
129
  }
130
 
131
+ /**
132
+ * Load emails associate with a session
133
+ *
134
+ * @param Listrak_Remarketing_Model_Session $session Session
135
+ *
136
+ * @return void
137
+ */
138
  public function loadEmails(Listrak_Remarketing_Model_Session $session)
139
  {
140
  $select = $this->_read->select()
141
+ ->from(
142
+ array('se' => $this->getTable('listrak/session_email')),
143
+ array("*")
144
+ )
145
  ->joinLeft(
146
  array('ec' => $this->getTable('listrak/emailcapture')),
147
  'se.emailcapture_id = ec.emailcapture_id',
153
  $session->setEmails($emails);
154
  }
155
 
156
+ /**
157
+ * Load clicks into a session
158
+ *
159
+ * @param Listrak_Remarketing_Model_Session $session Session
160
+ *
161
+ * @return void
162
+ */
163
  public function loadClicks(Listrak_Remarketing_Model_Session $session)
164
  {
165
+ /* @var Listrak_Remarketing_Model_Mysql4_Click_Collection $clicks */
166
+ $clicks = Mage::getModel("listrak/click")->getCollection();
167
+ $clicks->addFieldToFilter('session_id', array('eq' => $session->getId()));
168
 
169
  $sessionClicks = array();
 
170
  foreach ($clicks as $click) {
171
  $sessionClicks[] = $click;
172
  }
174
  $session->setData('clicks', $sessionClicks);
175
  }
176
 
177
+ /**
178
+ * Delete all emails associated with a session
179
+ *
180
+ * @param string $sid session ID
181
+ *
182
+ * @return void
183
+ */
184
+ public function deleteEmails($sid)
185
  {
186
+ $this->_write->delete(
187
+ $this->getTable("listrak/session_email"),
188
+ "session_id = $sid"
189
+ );
190
  }
191
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Session/Collection.php CHANGED
@@ -12,23 +12,43 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Session_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
18
-
 
 
 
 
19
  protected function _construct()
20
  {
21
  $this->_init('listrak/session');
22
  }
23
 
 
 
 
 
 
 
 
24
  public function addStoreFilter($storeIds)
25
  {
26
  $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
27
  return $this;
28
  }
29
 
 
 
 
 
 
30
  protected function _afterLoad()
31
  {
 
32
  foreach ($this->_items as $i) {
33
  $i->afterLoad();
34
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Session_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Session_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/session');
29
  }
30
 
31
+ /**
32
+ * Limit result to specific stores
33
+ *
34
+ * @param array|int $storeIds Magento store ID(s)
35
+ *
36
+ * @return Listrak_Remarketing_Model_Mysql4_Session_Collection
37
+ */
38
  public function addStoreFilter($storeIds)
39
  {
40
  $this->getSelect()->where('main_table.store_id IN (?)', $storeIds);
41
  return $this;
42
  }
43
 
44
+ /**
45
+ * Inflate all items in collection
46
+ *
47
+ * @return Mage_Core_Model_Resource_Db_Collection_Abstract
48
+ */
49
  protected function _afterLoad()
50
  {
51
+ /* @var Listrak_Remarketing_Model_Session $i */
52
  foreach ($this->_items as $i) {
53
  $i->afterLoad();
54
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Subscriberupdate.php CHANGED
@@ -12,18 +12,19 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Subscriberupdate
16
  extends Mage_Core_Model_Mysql4_Abstract
17
  {
18
-
19
- protected $_read;
20
-
21
- protected $_write;
22
-
23
  protected function _construct()
24
  {
25
  $this->_init('listrak/subscriber_update', 'id');
26
- $this->_read = $this->_getReadAdapter();
27
- $this->_write = $this->_getWriteAdapter();
28
  }
29
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Subscriberupdate
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Subscriberupdate
19
  extends Mage_Core_Model_Mysql4_Abstract
20
  {
21
+ /**
22
+ * Initializes the resource
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/subscriber_update', 'id');
 
 
29
  }
30
  }
app/code/community/Listrak/Remarketing/Model/Mysql4/Subscriberupdate/Collection.php CHANGED
@@ -12,9 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Mysql4_Subscriberupdate_Collection
16
  extends Mage_Core_Model_Mysql4_Collection_Abstract
17
  {
 
 
 
 
 
18
  protected function _construct()
19
  {
20
  $this->_init('listrak/subscriberupdate');
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Mysql4_Subscriberupdate_Collection
17
+ */
18
  class Listrak_Remarketing_Model_Mysql4_Subscriberupdate_Collection
19
  extends Mage_Core_Model_Mysql4_Collection_Abstract
20
  {
21
+ /**
22
+ * Initializes collection
23
+ *
24
+ * @return void
25
+ */
26
  protected function _construct()
27
  {
28
  $this->_init('listrak/subscriberupdate');
app/code/community/Listrak/Remarketing/Model/Observer.php CHANGED
@@ -12,108 +12,206 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Observer
16
  {
17
- public function trackingInit($observer)
 
 
 
 
 
18
  {
19
  try {
20
- if (Mage::helper('remarketing')->legacyTracking()) {
 
 
 
 
21
  $session = Mage::getSingleton('listrak/session');
22
  $session->init(true);
23
 
 
24
  $click = Mage::getModel('listrak/click');
25
  $click->checkForClick();
26
  }
27
  } catch (Exception $ex) {
28
- Mage::getModel("listrak/log")->addException($ex);
 
 
29
  }
30
 
31
  return $this;
32
  }
33
 
34
- public function orderPlaced($observer)
 
 
 
 
 
35
  {
36
  try {
37
- if (Mage::helper('remarketing')->legacyTracking()) {
38
- $cs = Mage::getSingleton('core/session');
39
- $cs->setIsListrakOrderMade(true);
 
 
 
 
 
40
  $session = Mage::getSingleton('listrak/session');
41
  $session->init();
42
  }
43
  } catch (Exception $ex) {
44
- Mage::getModel("listrak/log")->addException($ex);
 
 
45
  }
46
 
47
  return $this;
48
  }
49
 
 
 
 
 
 
 
 
50
  public function subscriberSaved($observer)
51
  {
52
  try {
53
- if (Mage::helper('remarketing')->coreEnabled()) {
54
- $s = $observer->getSubscriber();
55
- $su = Mage::getModel("listrak/subscriberupdate")->load($s->getSubscriberId(), 'subscriber_id');
56
 
57
- if (!$su->getData()) {
58
- $su->setSubscriberId($s->getSubscriberId());
 
 
 
 
 
 
 
59
  }
60
 
61
- $su->setUpdatedAt(gmdate('Y-m-d H:i:s'));
62
- $su->save();
63
  }
64
- } catch (Exception $ex) {
65
- Mage::getModel("listrak/log")->addException($ex);
 
 
66
  }
67
 
68
  return $this;
69
  }
70
 
 
 
 
 
 
 
 
71
  public function reviewUpdated($observer)
72
  {
73
  try {
74
- if (Mage::helper('remarketing')->reviewsEnabled()) {
 
 
 
75
  $review = $observer->getObject();
76
 
77
- Mage::getModel('listrak/review_update')
78
- ->markUpdated($review->getReviewId(), $review->getEntityId(), $review->getEntityPkValue());
 
 
 
 
 
79
  }
80
  } catch (Exception $e) {
81
- Mage::getModel("listrak/log")->addException($e);
 
 
82
  }
83
 
84
  return $this;
85
  }
86
 
 
 
 
 
 
 
 
87
  public function reviewDeleted($observer)
88
  {
89
  try {
90
- if (Mage::helper('remarketing')->reviewsEnabled()) {
 
 
 
91
  $review = $observer->getObject();
92
 
93
- Mage::getModel('listrak/review_update')
94
- ->markDeleted($review->getReviewId(), $review->getEntityId(), $review->getEntityPkValue());
 
 
 
 
 
95
  }
96
  } catch (Exception $e) {
97
- Mage::getModel('listrak/log')->addException($e);
 
 
98
  }
99
 
100
  return $this;
101
  }
102
 
103
- public function cartModified($observer) {
 
 
 
 
 
 
104
  try {
105
- if (Mage::helper('remarketing')->scaEnabled()) {
106
- Mage::getSingleton('checkout/session')->setListrakCartModified(true);
107
- Mage::helper('remarketing')->initCartCookie();
 
 
 
 
 
108
  }
109
  } catch(Exception $e) {
110
- Mage::getModel('listrak/log')->addException($e);
 
 
111
  }
112
 
113
  return $this;
114
  }
115
 
116
- public function resetCustomerTracking() {
117
- Mage::getSingleton('customer/session')->unsListrakCustomerTracked();
 
 
 
 
 
 
 
 
 
118
  }
119
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Observer
17
+ */
18
  class Listrak_Remarketing_Model_Observer
19
  {
20
+ /**
21
+ * Process all requests
22
+ *
23
+ * @return $this
24
+ */
25
+ public function trackingInit()
26
  {
27
  try {
28
+ /* @var Listrak_Remarketing_Helper_Data $helper */
29
+ $helper = Mage::helper('remarketing');
30
+
31
+ if ($helper->legacyTracking()) {
32
+ /* @var Listrak_Remarketing_Model_Session $session */
33
  $session = Mage::getSingleton('listrak/session');
34
  $session->init(true);
35
 
36
+ /* @var Listrak_Remarketing_Model_Click $click */
37
  $click = Mage::getModel('listrak/click');
38
  $click->checkForClick();
39
  }
40
  } catch (Exception $ex) {
41
+ /* @var Listrak_Remarketing_Model_Log $logger */
42
+ $logger = Mage::getModel('listrak/log');
43
+ $logger->addException($ex);
44
  }
45
 
46
  return $this;
47
  }
48
 
49
+ /**
50
+ * Process a new order
51
+ *
52
+ * @return $this
53
+ */
54
+ public function orderPlaced()
55
  {
56
  try {
57
+ /* @var Listrak_Remarketing_Helper_Data $helper */
58
+ $helper = Mage::helper('remarketing');
59
+
60
+ if ($helper->legacyTracking()) {
61
+ Mage::getSingleton('core/session')
62
+ ->setIsListrakOrderMade(true);
63
+
64
+ /* @var Listrak_Remarketing_Model_Session $session */
65
  $session = Mage::getSingleton('listrak/session');
66
  $session->init();
67
  }
68
  } catch (Exception $ex) {
69
+ /* @var Listrak_Remarketing_Model_Log $logger */
70
+ $logger = Mage::getModel('listrak/log');
71
+ $logger->addException($ex);
72
  }
73
 
74
  return $this;
75
  }
76
 
77
+ /**
78
+ * Process a subscription sign-up
79
+ *
80
+ * @param mixed $observer Event data
81
+ *
82
+ * @return $this
83
+ */
84
  public function subscriberSaved($observer)
85
  {
86
  try {
87
+ /* @var Listrak_Remarketing_Helper_Data $helper */
88
+ $helper = Mage::helper('remarketing');
 
89
 
90
+ if ($helper->coreEnabled()) {
91
+ $subscriber = $observer->getSubscriber();
92
+
93
+ /* @var Listrak_Remarketing_Model_Subscriberupdate $updateModel */
94
+ $updateModel = Mage::getModel("listrak/subscriberupdate");
95
+ $updateModel->load($subscriber->getSubscriberId(), 'subscriber_id');
96
+
97
+ if (!$updateModel->getData()) {
98
+ $updateModel->setSubscriberId($subscriber->getSubscriberId());
99
  }
100
 
101
+ $updateModel->setUpdatedAt(gmdate('Y-m-d H:i:s'));
102
+ $updateModel->save();
103
  }
104
+ } catch (Exception $e) {
105
+ /* @var Listrak_Remarketing_Model_Log $logger */
106
+ $logger = Mage::getModel('listrak/log');
107
+ $logger->addException($e);
108
  }
109
 
110
  return $this;
111
  }
112
 
113
+ /**
114
+ * Process a review update
115
+ *
116
+ * @param mixed $observer Event data
117
+ *
118
+ * @return $this
119
+ */
120
  public function reviewUpdated($observer)
121
  {
122
  try {
123
+ /* @var Listrak_Remarketing_Helper_Data $helper */
124
+ $helper = Mage::helper('remarketing');
125
+
126
+ if ($helper->reviewsEnabled()) {
127
  $review = $observer->getObject();
128
 
129
+ /* @var Listrak_Remarketing_Model_Review_Update $updateModel */
130
+ $updateModel = Mage::getModel('listrak/review_update');
131
+ $updateModel->markUpdated(
132
+ $review->getReviewId(),
133
+ $review->getEntityId(),
134
+ $review->getEntityPkValue()
135
+ );
136
  }
137
  } catch (Exception $e) {
138
+ /* @var Listrak_Remarketing_Model_Log $logger */
139
+ $logger = Mage::getModel('listrak/log');
140
+ $logger->addException($e);
141
  }
142
 
143
  return $this;
144
  }
145
 
146
+ /**
147
+ * Process a review delete
148
+ *
149
+ * @param mixed $observer Event data
150
+ *
151
+ * @return $this
152
+ */
153
  public function reviewDeleted($observer)
154
  {
155
  try {
156
+ /* @var Listrak_Remarketing_Helper_Data $helper */
157
+ $helper = Mage::helper('remarketing');
158
+
159
+ if ($helper->reviewsEnabled()) {
160
  $review = $observer->getObject();
161
 
162
+ /* @var Listrak_Remarketing_Model_Review_Update $updateModel */
163
+ $updateModel = Mage::getModel('listrak/review_update');
164
+ $updateModel->markDeleted(
165
+ $review->getReviewId(),
166
+ $review->getEntityId(),
167
+ $review->getEntityPkValue()
168
+ );
169
  }
170
  } catch (Exception $e) {
171
+ /* @var Listrak_Remarketing_Model_Log $logger */
172
+ $logger = Mage::getModel('listrak/log');
173
+ $logger->addException($e);
174
  }
175
 
176
  return $this;
177
  }
178
 
179
+ /**
180
+ * Process a shopping cart update
181
+ *
182
+ * @return $this
183
+ */
184
+ public function cartModified()
185
+ {
186
  try {
187
+ /* @var Listrak_Remarketing_Helper_Data $helper */
188
+ $helper = Mage::helper('remarketing');
189
+
190
+ if ($helper->scaEnabled()) {
191
+ Mage::getSingleton('checkout/session')
192
+ ->setListrakCartModified(true);
193
+
194
+ $helper->initCartCookie();
195
  }
196
  } catch(Exception $e) {
197
+ /* @var Listrak_Remarketing_Model_Log $logger */
198
+ $logger = Mage::getModel('listrak/log');
199
+ $logger->addException($e);
200
  }
201
 
202
  return $this;
203
  }
204
 
205
+ /**
206
+ * Reset data associated with Listrak's customer tracking
207
+ *
208
+ * @return $this
209
+ */
210
+ public function resetCustomerTracking()
211
+ {
212
+ Mage::getSingleton('customer/session')
213
+ ->unsListrakCustomerTracked();
214
+
215
+ return $this;
216
  }
217
  }
app/code/community/Listrak/Remarketing/Model/Product.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.0.0
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2011 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product
17
+ */
18
+ class Listrak_Remarketing_Model_Product extends Mage_Catalog_Model_Product
19
+ {
20
+ /**
21
+ * Initializes the object
22
+ *
23
+ * @return void
24
+ */
25
+ public function _construct()
26
+ {
27
+ parent::_construct();
28
+ $this->_init('listrak/product');
29
+ }
30
+ }
app/code/community/Listrak/Remarketing/Model/Product/Api.php CHANGED
@@ -12,117 +12,228 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Product_Api
16
  extends Mage_Api_Model_Resource_Abstract
17
  {
18
- public function products($storeId = 1, $perPage = 50, $page = 1)
 
 
 
 
 
 
 
 
 
 
 
 
19
  {
20
  Mage::app()->setCurrentStore($storeId);
21
- Mage::helper('remarketing')->requireCoreEnabled();
22
 
23
- if (!is_numeric($storeId) || !is_numeric($perPage) || !is_numeric($page))
 
 
 
 
 
 
 
24
  throw new Exception("Bad request parameters.");
 
25
 
26
  try {
27
- $collection = Mage::getModel('catalog/product')->getCollection()
28
- ->addStoreFilter($storeId)
29
- ->addAttributeToSelect('*');
30
-
31
- if ($collection->isEnabledFlat()) {
32
- $collection
33
- ->joinAttribute('description', 'catalog_product/description', 'entity_id', null, 'left')
34
- ->addAttributeToSelect('description')
35
- ->joinAttribute('image', 'catalog_product/image', 'entity_id', null, 'left')
36
- ->addAttributeToSelect('image');
37
- }
38
 
39
- $collection->setPageSize($perPage)
40
- ->setCurPage($page)
41
- ->load();
42
 
43
- Mage::getModel('cataloginventory/stock')->addItemsToProducts($collection);
 
44
 
45
- $results = array();
 
 
 
 
46
 
47
  foreach ($collection as $product) {
48
- $results[] = Mage::helper('remarketing/product')->getProductEntity($product, $storeId);
49
  }
50
 
51
  return $results;
52
  } catch (Exception $e) {
53
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
54
  }
55
  }
56
 
57
- public function updates($storeId = 1, $startDate = null, $endDate = null, $perPage = 50, $page = 1)
58
- {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  Mage::app()->setCurrentStore($storeId);
60
- Mage::helper('remarketing')->requireCoreEnabled();
61
-
62
- $dte1 = strtotime($startDate);
63
- $dte2 = strtotime($endDate);
64
- if (!is_numeric($storeId) || !$dte1 || !$dte2 || !is_numeric($perPage) || !is_numeric($page))
 
 
 
 
 
 
65
  throw new Exception("Bad request parameters.");
 
66
 
67
  try {
68
- $collection = Mage::getModel('catalog/product')->getCollection()
69
- ->addStoreFilter($storeId)
70
- ->addAttributeToSelect('*')
71
- ->addAttributeToFilter('updated_at', array('from' => $dte1, 'to' => $dte2, 'date' => true))
72
- ->setPageSize($perPage)
73
- ->setCurPage($page);
74
- $collection->getSelect()
75
- ->order(array('e.updated_at ASC', 'e.entity_id ASC'));
76
- $collection->load();
77
-
78
- Mage::getModel('cataloginventory/stock')->addItemsToProducts($collection);
79
 
80
  $results = array();
81
 
 
 
 
 
 
 
 
 
 
82
  foreach ($collection as $product) {
83
- $result = Mage::helper('remarketing/product')->getProductEntity($product, $storeId);
84
  $result['updated_at'] = $product->getUpdatedAt();
85
  $results[] = $result;
86
  }
87
 
88
  return $results;
89
  } catch (Exception $e) {
90
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
91
  }
92
  }
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  public function purchasable($storeId = 1, $perPage = 50, $page = 1)
95
  {
96
  Mage::app()->setCurrentStore($storeId);
97
- Mage::helper('remarketing')->requireCoreEnabled();
98
 
99
- $collection = Mage::getModel('catalog/product')->getCollection()
100
- ->addStoreFilter($storeId)
 
 
 
 
 
101
  ->addAttributeToSelect('visibility', 'left')
102
- ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
 
 
 
 
 
 
 
103
 
104
- $purchasableFilter = Mage::getSingleton('listrak/product_purchasable_visibility')->getVisibilityFilterFromSetting(Mage::getStoreConfig('remarketing/productcategories/purchasable_visibility'));
105
  if ($purchasableFilter) {
106
- $dbRead = Mage::getSingleton('core/resource')->getConnection('core_read');
 
107
 
108
- // reset columns if the flat product table is used
109
- $resetColumns = Mage::helper('catalog/category_flat')->isEnabled();
110
 
111
  $productToParentQuery = $dbRead->select()
112
- ->from(Mage::getResourceSingleton('catalog/product_type_configurable')->getMainTable(), array('product_id', 'parent_id'))
 
 
 
 
113
  ->group('product_id');
114
 
115
- $parentCollection = Mage::getModel('catalog/product')->getCollection()
 
 
116
  ->addStoreFilter($storeId)
117
  ->addAttributeToSelect('visibility', 'left')
118
  ->addAttributeToSelect('status', 'inner');
119
 
120
  return $this->_retrievePurchasablePage(
121
- $this->_purchasableQueryHelper($dbRead, $collection, $productToParentQuery, $parentCollection, $purchasableFilter, $resetColumns),
 
 
 
122
  $page, $perPage
123
  );
124
- }
125
- else {
126
  $query = $collection->getSelect();
127
  $query->reset(Zend_Db_Select::COLUMNS)
128
  ->columns(array('e.entity_id', 'e.sku'));
@@ -130,23 +241,75 @@ class Listrak_Remarketing_Model_Product_Api
130
  }
131
  }
132
 
133
- private function _purchasableQueryHelper($dbRead, $productCollection, $productToParentQuery, $parentCollection, $purchasableFilter, $resetColumns) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  $productQuery = $productCollection->getSelect();
135
- if ($resetColumns) {
136
- $productQuery->reset(Zend_Db_Select::COLUMNS)->columns(array('e.entity_id', 'e.sku', 'e.attribute_set_id', 'e.type_id', 'e.visibility'));
137
- }
138
 
139
  $query = $dbRead->select();
140
- $query->from(array('product' => new Zend_Db_Expr("({$productQuery})")), array('entity_id', 'sku'))
141
- ->joinLeft(array('product_to_parent' => new Zend_Db_Expr("({$productToParentQuery})")), 'product_to_parent.product_id = product.entity_id', array())
142
- ->joinLeft(array('parent' => new Zend_Db_Expr("({$parentCollection->getSelect()})")), $dbRead->quoteInto('parent.entity_id = product_to_parent.parent_id AND parent.type_id = ?', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE), array())
143
- ->where('COALESCE(parent.visibility, product.visibility) IN (?)', $purchasableFilter)
144
- ->where('parent.status IS NULL OR parent.status = ?', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  return $query;
147
  }
148
 
149
- private function _retrievePurchasablePage($query, $page, $perPage) {
 
 
 
 
 
 
 
 
 
 
 
150
  $query->limit($perPage, $perPage * ($page - 1));
151
  return $query->query()->fetchAll();
152
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product_Api
17
+ */
18
  class Listrak_Remarketing_Model_Product_Api
19
  extends Mage_Api_Model_Resource_Abstract
20
  {
21
+ /**
22
+ * Retrieve product data
23
+ *
24
+ * @param int $storeId Magento store ID
25
+ * @param int $perPage Page size
26
+ * @param int $page Cursor
27
+ * @param boolean $withAttributes Retrieve attributes
28
+ *
29
+ * @return array
30
+ *
31
+ * @throws Exception
32
+ */
33
+ public function products($storeId = 1, $perPage = 50, $page = 1, $withAttributes = false)
34
  {
35
  Mage::app()->setCurrentStore($storeId);
 
36
 
37
+ /* @var Listrak_Remarketing_Helper_Data $helper */
38
+ $helper = Mage::helper('remarketing');
39
+ $helper->requireCoreEnabled();
40
+
41
+ if (!is_numeric($storeId)
42
+ || !is_numeric($perPage)
43
+ || !is_numeric($page)
44
+ ) {
45
  throw new Exception("Bad request parameters.");
46
+ }
47
 
48
  try {
49
+ /* @var Mage_Catalog_Model_Resource_Product_Collection $collection */
50
+ $collection = $this->_productCollection($storeId, $perPage, $page);
 
 
 
 
 
 
 
 
 
51
 
52
+ $results = array();
 
 
53
 
54
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
55
+ $productHelper = Mage::helper('remarketing/product');
56
 
57
+ $attributeOptions = null;
58
+ if ($withAttributes) {
59
+ $attributeOptions = $collection->getAttributeOptions();
60
+ }
61
+ $productHelper->setAttributeOptions($withAttributes, $attributeOptions);
62
 
63
  foreach ($collection as $product) {
64
+ $results[] = $productHelper->getProductEntity($product, $storeId);
65
  }
66
 
67
  return $results;
68
  } catch (Exception $e) {
69
+ throw $helper->generateAndLogException(
70
+ "Exception occurred in API call: " . $e->getMessage(), $e
71
+ );
72
  }
73
  }
74
 
75
+ /**
76
+ * Retrieve updated products' data
77
+ *
78
+ * @param int $storeId Magento store ID
79
+ * @param datetime $startDate Date constraint, lower
80
+ * @param datetime $endDate Date constraint, upper
81
+ * @param int $perPage Page size
82
+ * @param int $page Cursor
83
+ * @param boolean $withAttributes Retrieve attributes
84
+ *
85
+ * @return array
86
+ *
87
+ * @throws Exception
88
+ */
89
+ public function updates(
90
+ $storeId = 1, $startDate = null, $endDate = null,
91
+ $perPage = 50, $page = 1, $withAttributes = false
92
+ ) {
93
  Mage::app()->setCurrentStore($storeId);
94
+
95
+ /* @var Listrak_Remarketing_Helper_Data $helper */
96
+ $helper = Mage::helper('remarketing');
97
+ $helper->requireCoreEnabled();
98
+
99
+ if (!is_numeric($storeId)
100
+ || !strtotime($startDate)
101
+ || !strtotime($endDate)
102
+ || !is_numeric($perPage)
103
+ || !is_numeric($page)
104
+ ) {
105
  throw new Exception("Bad request parameters.");
106
+ }
107
 
108
  try {
109
+ /* @var Mage_Catalog_Model_Resource_Product_Collection $collection */
110
+ $collection = $this->_productCollection($storeId, $perPage, $page, $startDate, $endDate);
 
 
 
 
 
 
 
 
 
111
 
112
  $results = array();
113
 
114
+ /* @var Listrak_Remarketing_Helper_Product $productHelper */
115
+ $productHelper = Mage::helper('remarketing/product');
116
+
117
+ $attributeOptions = null;
118
+ if ($withAttributes) {
119
+ $attributeOptions = $collection->getAttributeOptions();
120
+ }
121
+ $productHelper->setAttributeOptions($withAttributes, $attributeOptions);
122
+
123
  foreach ($collection as $product) {
124
+ $result = $productHelper->getProductEntity($product, $storeId);
125
  $result['updated_at'] = $product->getUpdatedAt();
126
  $results[] = $result;
127
  }
128
 
129
  return $results;
130
  } catch (Exception $e) {
131
+ throw $helper->generateAndLogException(
132
+ "Exception occurred in API call: " . $e->getMessage(), $e
133
+ );
134
  }
135
  }
136
 
137
+ /**
138
+ * Get requested page of products
139
+ *
140
+ * @param int $storeId Magento store ID
141
+ * @param int $perPage Page size
142
+ * @param int $page Cursor
143
+ * @param datetime $startDate Date constraint, lower
144
+ * @param datetime $endDate Date constraint, upper
145
+ *
146
+ * @return Mage_Catalog_Model_Resource_Product_Collection
147
+ */
148
+ private function _productCollection(
149
+ $storeId = 1, $perPage = 50, $page = 1, $startDate = null, $endDate = null
150
+ ) {
151
+ /* @var Mage_Catalog_Model_Resource_Product_Collection $collection */
152
+ $collection = Mage::getModel('listrak/product')->getCollection();
153
+
154
+ $collection->addStoreFilter($storeId)
155
+ ->addAttributeToSelect('*');
156
+
157
+ $collectionOrder = array();
158
+ if ($startDate != null) {
159
+ $collection->addModifiedFilter($startDate, $endDate);
160
+ $collectionOrder[] = 'e.updated_at ASC';
161
+ }
162
+
163
+ $collectionOrder[] = 'e.entity_id ASC';
164
+ $collection->getSelect()
165
+ ->order($collectionOrder);
166
+
167
+ $collection->setPageSize($perPage)
168
+ ->setCurPage($page)
169
+ ->load();
170
+
171
+ /* @var Mage_Cataloginventory_Model_Stock $stockModel */
172
+ $stockModel = Mage::getModel('cataloginventory/stock');
173
+ $stockModel->addItemsToProducts($collection);
174
+
175
+ return $collection;
176
+ }
177
+
178
+ /**
179
+ * Retrieve purchasable products
180
+ *
181
+ * @param int $storeId Magento store ID
182
+ * @param int $perPage Page size
183
+ * @param int $page Cursor
184
+ *
185
+ * @return array
186
+ */
187
  public function purchasable($storeId = 1, $perPage = 50, $page = 1)
188
  {
189
  Mage::app()->setCurrentStore($storeId);
 
190
 
191
+ /* @var Listrak_Remarketing_Helper_Data $helper */
192
+ $helper = Mage::helper('remarketing');
193
+ $helper->requireCoreEnabled();
194
+
195
+ /* @var Mage_Catalog_Model_Resource_Product_Collection $collection */
196
+ $collection = Mage::getModel('listrak/product')->getCollection();
197
+ $collection->addStoreFilter($storeId)
198
  ->addAttributeToSelect('visibility', 'left')
199
+ ->addAttributeToFilter(
200
+ 'status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED
201
+ );
202
+
203
+ /* @var Listrak_Remarketing_Model_Product_Purchasable_Visibility $visModel */
204
+ $visModel = Mage::getSingleton('listrak/product_purchasable_visibility');
205
+
206
+ $purchasableFilter = $visModel->getVisibilityFilter();
207
 
 
208
  if ($purchasableFilter) {
209
+ /* @var Mage_Core_Model_Resource $resource */
210
+ $resource = Mage::getSingleton('core/resource');
211
 
212
+ $dbRead = $resource->getConnection('core_read');
 
213
 
214
  $productToParentQuery = $dbRead->select()
215
+ ->from(
216
+ Mage::getResourceSingleton('catalog/product_type_configurable')
217
+ ->getMainTable(),
218
+ array('product_id', 'parent_id')
219
+ )
220
  ->group('product_id');
221
 
222
+ /* @var Mage_Catalog_Model_Resource_Product_Collection $parents */
223
+ $parents = Mage::getModel('catalog/product')->getCollection();
224
+ $parents
225
  ->addStoreFilter($storeId)
226
  ->addAttributeToSelect('visibility', 'left')
227
  ->addAttributeToSelect('status', 'inner');
228
 
229
  return $this->_retrievePurchasablePage(
230
+ $this->_purchasableQueryHelper(
231
+ $dbRead, $collection, $productToParentQuery, $parents,
232
+ $purchasableFilter
233
+ ),
234
  $page, $perPage
235
  );
236
+ } else {
 
237
  $query = $collection->getSelect();
238
  $query->reset(Zend_Db_Select::COLUMNS)
239
  ->columns(array('e.entity_id', 'e.sku'));
241
  }
242
  }
243
 
244
+ /**
245
+ * Constructs the query returning purchasable products
246
+ *
247
+ * @param Varien_Db_Adapter_Interface $dbRead Read connection
248
+ * @param Varien_Data_Collection_Db $productCollection Products
249
+ * @param Varien_Db_Select $productToParentQuery Parent resolution
250
+ * @param Varien_Data_Collection_Db $parentCollection Parents
251
+ * @param array $purchasableFilter Visibility filter
252
+ *
253
+ * @return Varien_Db_Select
254
+ */
255
+ private function _purchasableQueryHelper(
256
+ $dbRead, $productCollection, $productToParentQuery, $parentCollection,
257
+ $purchasableFilter
258
+ ) {
259
  $productQuery = $productCollection->getSelect();
 
 
 
260
 
261
  $query = $dbRead->select();
262
+ $query
263
+ ->from(
264
+ array('product' => new Zend_Db_Expr("({$productQuery})")),
265
+ array('entity_id', 'sku')
266
+ )
267
+ ->joinLeft(
268
+ array(
269
+ 'product_to_parent' => new Zend_Db_Expr(
270
+ "({$productToParentQuery})"
271
+ )
272
+ ),
273
+ 'product_to_parent.product_id = product.entity_id',
274
+ array()
275
+ )
276
+ ->joinLeft(
277
+ array(
278
+ 'parent' => new Zend_Db_Expr(
279
+ "({$parentCollection->getSelect()})"
280
+ )
281
+ ),
282
+ $dbRead->quoteInto(
283
+ 'parent.entity_id = product_to_parent.parent_id '
284
+ . 'AND parent.type_id = ?',
285
+ Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE
286
+ ),
287
+ array()
288
+ )
289
+ ->where(
290
+ 'COALESCE(parent.visibility, product.visibility) IN (?)',
291
+ $purchasableFilter
292
+ )
293
+ ->where(
294
+ 'parent.status IS NULL OR parent.status = ?',
295
+ Mage_Catalog_Model_Product_Status::STATUS_ENABLED
296
+ );
297
 
298
  return $query;
299
  }
300
 
301
+ /**
302
+ * Retrieve purchasable products from the database
303
+ *
304
+ * @param Varien_Db_Select $query Query
305
+ * @param int $page Cursor
306
+ * @param int $perPage Page size
307
+ *
308
+ * @return array
309
+ */
310
+ private function _retrievePurchasablePage(
311
+ Varien_Db_Select $query, $page, $perPage
312
+ ) {
313
  $query->limit($perPage, $perPage * ($page - 1));
314
  return $query->query()->fetchAll();
315
  }
app/code/community/Listrak/Remarketing/Model/Product/Api/V2.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Product_Api_V2
16
  extends Listrak_Remarketing_Model_Product_Api
17
  {
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product_Api_V2
17
+ */
18
  class Listrak_Remarketing_Model_Product_Api_V2
19
  extends Listrak_Remarketing_Model_Product_Api
20
  {
app/code/community/Listrak/Remarketing/Model/Product/Attribute/Set/Map.php CHANGED
@@ -12,9 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Product_Attribute_Set_Map
16
  extends Mage_Core_Model_Abstract
17
  {
 
 
 
 
 
18
  public function _construct()
19
  {
20
  parent::_construct();
@@ -24,59 +32,101 @@ class Listrak_Remarketing_Model_Product_Attribute_Set_Map
24
  $this->setData('use_config_categories_source', 1);
25
  }
26
 
 
 
 
 
 
27
  public function finalCategoriesSource()
28
  {
 
 
 
29
  return $this->getUseConfigCategoriesSource()
30
- ? Mage::helper('remarketing')->categoriesSource() : $this->getCategoriesSource();
 
31
  }
32
 
 
 
 
 
 
33
  public function frontendCategoriesSource()
34
  {
35
  switch ($this->finalCategoriesSource()) {
36
- case 'default':
37
- return 'Magento Categories';
38
- case 'attributes' :
39
- return 'Product Attribute Mapping';
40
- default:
41
- return 'n/a';
 
 
42
  }
43
  }
44
 
 
 
 
 
 
45
  public function frontendBrandAttribute()
46
  {
47
  if ($this->getBrandAttributeCode() != null) {
48
- return $this->getBrandAttributeName() . ' (' . $this->getBrandAttributeCode() . ')';
 
 
49
  } else {
50
  return 'Not Set';
51
  }
52
  }
53
 
 
 
 
 
 
54
  public function frontendCategoryAttribute()
55
  {
56
  if ($this->finalCategoriesSource() == 'default') {
57
  return '';
58
  } else {
59
  if ($this->getCategoryAttributeCode() != null) {
60
- return $this->getCategoryAttributeName() . ' (' . $this->getCategoryAttributeCode() . ')';
 
 
61
  } else {
62
  return 'Not Set';
63
  }
64
  }
65
  }
66
 
 
 
 
 
 
67
  public function frontendSubcategoryAttribute()
68
  {
69
  if ($this->finalCategoriesSource() == 'default') {
70
  return '';
71
  } else {
72
  if ($this->getSubcategoryAttributeCode() != null) {
73
- return $this->getSubcategoryAttributeName() . ' (' . $this->getSubcategoryAttributeCode() . ')';
 
 
74
  } else {
75
  return 'Not Set';
76
  }
77
  }
78
  }
79
 
 
 
 
 
 
80
  public function save()
81
  {
82
  $this->setData('updated_at', gmdate('Y-m-d H:i:s'));
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product_Attribute_Set_Map
17
+ */
18
  class Listrak_Remarketing_Model_Product_Attribute_Set_Map
19
  extends Mage_Core_Model_Abstract
20
  {
21
+ /**
22
+ * Initializes the model
23
+ *
24
+ * @return void
25
+ */
26
  public function _construct()
27
  {
28
  parent::_construct();
32
  $this->setData('use_config_categories_source', 1);
33
  }
34
 
35
+ /**
36
+ * Retrieves the category source setting
37
+ *
38
+ * @return string
39
+ */
40
  public function finalCategoriesSource()
41
  {
42
+ /* @var Listrak_Remarketing_Helper_Data $helper */
43
+ $helper = Mage::helper('remarketing');
44
+
45
  return $this->getUseConfigCategoriesSource()
46
+ ? $helper->categoriesSource()
47
+ : $this->getCategoriesSource();
48
  }
49
 
50
+ /**
51
+ * Translates category source setting to user text
52
+ *
53
+ * @return string
54
+ */
55
  public function frontendCategoriesSource()
56
  {
57
  switch ($this->finalCategoriesSource()) {
58
+ case 'default':
59
+ return 'Magento Categories';
60
+
61
+ case 'attributes' :
62
+ return 'Product Attribute Mapping';
63
+
64
+ default:
65
+ return 'n/a';
66
  }
67
  }
68
 
69
+ /**
70
+ * Translates brand attribute setting to user text
71
+ *
72
+ * @return string
73
+ */
74
  public function frontendBrandAttribute()
75
  {
76
  if ($this->getBrandAttributeCode() != null) {
77
+ return $this->getBrandAttributeName()
78
+ . ' (' . $this->getBrandAttributeCode()
79
+ . ')';
80
  } else {
81
  return 'Not Set';
82
  }
83
  }
84
 
85
+ /**
86
+ * Translates category attribute setting to user text
87
+ *
88
+ * @return string
89
+ */
90
  public function frontendCategoryAttribute()
91
  {
92
  if ($this->finalCategoriesSource() == 'default') {
93
  return '';
94
  } else {
95
  if ($this->getCategoryAttributeCode() != null) {
96
+ return $this->getCategoryAttributeName()
97
+ . ' (' . $this->getCategoryAttributeCode()
98
+ . ')';
99
  } else {
100
  return 'Not Set';
101
  }
102
  }
103
  }
104
 
105
+ /**
106
+ * Translates subcategory attribute setting to user text
107
+ *
108
+ * @return string
109
+ */
110
  public function frontendSubcategoryAttribute()
111
  {
112
  if ($this->finalCategoriesSource() == 'default') {
113
  return '';
114
  } else {
115
  if ($this->getSubcategoryAttributeCode() != null) {
116
+ return $this->getSubcategoryAttributeName()
117
+ . ' (' . $this->getSubcategoryAttributeCode()
118
+ . ')';
119
  } else {
120
  return 'Not Set';
121
  }
122
  }
123
  }
124
 
125
+ /**
126
+ * Save the current settings
127
+ *
128
+ * @return void
129
+ */
130
  public function save()
131
  {
132
  $this->setData('updated_at', gmdate('Y-m-d H:i:s'));
app/code/community/Listrak/Remarketing/Model/Product/Attributes.php CHANGED
@@ -12,15 +12,28 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Product_Attributes
16
  {
 
 
 
 
 
17
  public function toOptionArray()
18
  {
19
- $collection = Mage::getResourceModel('catalog/product_attribute_collection')
20
- ->addVisibleFilter();
 
21
 
22
  $attributes = array();
23
- foreach ($collection as $value) {
 
 
24
  array_push(
25
  $attributes,
26
  array(
@@ -32,9 +45,10 @@ class Listrak_Remarketing_Model_Product_Attributes
32
 
33
  // sort the attributes by label
34
  usort(
35
- $attributes, function ($a, $b) {
36
- $valA = $a['label'] . ':' . $a['code'];
37
- $valB = $b['label'] . ':' . $b['code'];
 
38
  return (($valA == $valB) ? 0 : (($valA < $valB) ? -1 : 1));
39
  }
40
  );
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product_Attributes
17
+ *
18
+ * Model to populate attributes in the attribute set map admin page
19
+ */
20
  class Listrak_Remarketing_Model_Product_Attributes
21
  {
22
+ /**
23
+ * Returns all product attributes
24
+ *
25
+ * @return array
26
+ */
27
  public function toOptionArray()
28
  {
29
+ /* @var Mage_Catalog_Model_Resource_Product_Attribute_Collection $col */
30
+ $col = Mage::getResourceModel('catalog/product_attribute_collection');
31
+ $col->addVisibleFilter();
32
 
33
  $attributes = array();
34
+
35
+ /* @var Mage_Catalog_Model_Resource_Eav_Attribute $value */
36
+ foreach ($col as $value) {
37
  array_push(
38
  $attributes,
39
  array(
45
 
46
  // sort the attributes by label
47
  usort(
48
+ $attributes,
49
+ function ($attrA, $attrB) {
50
+ $valA = $attrA['label'] . ':' . $attrA['code'];
51
+ $valB = $attrB['label'] . ':' . $attrB['code'];
52
  return (($valA == $valB) ? 0 : (($valA < $valB) ? -1 : 1));
53
  }
54
  );
app/code/community/Listrak/Remarketing/Model/Product/Category/Source.php CHANGED
@@ -12,13 +12,29 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Product_Category_Source
16
  {
 
 
 
 
 
17
  public function toOptionArray()
18
  {
19
  return array(
20
- array('value' => 'default', 'label' => 'Use Catalog Configuration (Default)'),
21
- array('value' => 'attributes', 'label' => 'Map from Product Attributes')
 
 
 
 
 
 
22
  );
23
  }
24
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product_Category_Source
17
+ *
18
+ * Used to populate the category source in the attribute set map
19
+ */
20
  class Listrak_Remarketing_Model_Product_Category_Source
21
  {
22
+ /**
23
+ * Category source options
24
+ *
25
+ * @return array
26
+ */
27
  public function toOptionArray()
28
  {
29
  return array(
30
+ array(
31
+ 'value' => 'default',
32
+ 'label' => 'Use Catalog Configuration (Default)'
33
+ ),
34
+ array(
35
+ 'value' => 'attributes',
36
+ 'label' => 'Map from Product Attributes'
37
+ )
38
  );
39
  }
40
  }
app/code/community/Listrak/Remarketing/Model/Product/Purchasable/Visibility.php CHANGED
@@ -12,13 +12,23 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
 
 
 
15
  class Listrak_Remarketing_Model_Product_Purchasable_Visibility
16
  {
 
 
 
 
 
17
  public function toOptionArray()
18
  {
19
  return array(
20
  array('value' => 'off', 'label' => 'Do Not Filter'),
21
- //array('value' => 'no', 'label' => 'Not Visible Individually'),
22
  array('value' => 'catalog', 'label' => 'Catalog'),
23
  array('value' => 'search', 'label' => 'Search'),
24
  array('value' => 'both', 'label' => 'Catalog and Search'),
@@ -26,28 +36,82 @@ class Listrak_Remarketing_Model_Product_Purchasable_Visibility
26
  );
27
  }
28
 
29
- public function isProductPurchasableBySetting($setting, $product) {
30
- switch($setting) {
31
- case 'off': return true;
32
- //case 'no': return $product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
33
- case 'catalog': return $product->isVisibleInCatalog();
34
- case 'search': return in_array($product->getVisibility(), Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds());
35
- case 'both': return $product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH;
36
- case 'site': return $product->isVisibleInSiteVisibility();
37
- default: return true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  }
39
  }
40
 
41
- public function getVisibilityFilterFromSetting($setting) {
42
- switch($setting) {
43
- case 'off': return null;
44
- //case 'no': return Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
45
- case 'catalog': return array('in' => Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());
46
- case 'search': return array('in' => Mage::getSingleton('catalog/product_visibility')->getVisibleInSearchIds());
47
- case 'both': return Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH;
48
- case 'site': return array('in' => Mage::getSingleton('catalog/product_visibility')->getVisibleInSiteIds());
49
- default: return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  }
51
  }
 
 
 
 
 
 
 
 
 
 
 
 
52
  }
53
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Product_Purchasable_Visibility
17
+ *
18
+ * Serves as the source for the config purchasability setting, and to
19
+ * test products for purchasability
20
+ */
21
  class Listrak_Remarketing_Model_Product_Purchasable_Visibility
22
  {
23
+ /**
24
+ * Options displayed in system config
25
+ *
26
+ * @return array
27
+ */
28
  public function toOptionArray()
29
  {
30
  return array(
31
  array('value' => 'off', 'label' => 'Do Not Filter'),
 
32
  array('value' => 'catalog', 'label' => 'Catalog'),
33
  array('value' => 'search', 'label' => 'Search'),
34
  array('value' => 'both', 'label' => 'Catalog and Search'),
36
  );
37
  }
38
 
39
+ /**
40
+ * Retrieve whether a product is purchasable or not
41
+ *
42
+ * @param Mage_Catalog_Model_Product $product Current product
43
+ *
44
+ * @return bool
45
+ */
46
+ public function isProductPurchasable(Mage_Catalog_Model_Product $product)
47
+ {
48
+ switch($this->_getSetting()) {
49
+ case 'off':
50
+ return true;
51
+
52
+ case 'catalog':
53
+ return $product->isVisibleInCatalog();
54
+
55
+ case 'search':
56
+ /* @var Mage_Catalog_Model_Product_Visibility $visibilityModel */
57
+ $visibilityModel = Mage::getSingleton('catalog/product_visibility');
58
+ return in_array(
59
+ $product->getVisibility(),
60
+ $visibilityModel->getVisibleInSearchIds()
61
+ );
62
+
63
+ case 'both':
64
+ return Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
65
+ == $product->getVisibility();
66
+
67
+ case 'site':
68
+ return $product->isVisibleInSiteVisibility();
69
+
70
+ default:
71
+ return true;
72
  }
73
  }
74
 
75
+ /**
76
+ * Retrieve visibility setting to use in query
77
+ *
78
+ * @return array|int|null
79
+ */
80
+ public function getVisibilityFilter()
81
+ {
82
+ /* @var Mage_Catalog_Model_Product_Visibility $visibilityModel */
83
+ $visibilityModel = Mage::getSingleton('catalog/product_visibility');
84
+
85
+ switch($this->_getSetting()) {
86
+ case 'off':
87
+ return null;
88
+
89
+ case 'catalog':
90
+ return array('in' => $visibilityModel->getVisibleInCatalogIds());
91
+
92
+ case 'search':
93
+ return array('in' => $visibilityModel->getVisibleInSearchIds());
94
+ case 'both':
95
+ return Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH;
96
+
97
+ case 'site':
98
+ return array('in' => $visibilityModel->getVisibleInSiteIds());
99
+
100
+ default:
101
+ return null;
102
  }
103
  }
104
+
105
+ /**
106
+ * Visibility setting
107
+ *
108
+ * @return string
109
+ */
110
+ private function _getSetting()
111
+ {
112
+ return Mage::getStoreConfig(
113
+ 'remarketing/productcategories/purchasable_visibility'
114
+ );
115
+ }
116
  }
117
 
app/code/community/Listrak/Remarketing/Model/Review/Update.php CHANGED
@@ -12,18 +12,33 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Review_Update
16
  extends Mage_Core_Model_Abstract
17
  {
18
- const ACTIVITYTYPE_UPDATE = 1;
19
- const ACTIVITYTYPE_DELETE = 2;
20
 
 
 
 
 
 
21
  public function _construct()
22
  {
23
  parent::_construct();
24
  $this->_init('listrak/review_update');
25
  }
26
 
 
 
 
 
 
 
 
27
  public function loadByReviewId($reviewId)
28
  {
29
  return $this->getCollection()
@@ -31,26 +46,72 @@ class Listrak_Remarketing_Model_Review_Update
31
  ->getFirstItem();
32
  }
33
 
 
 
 
 
 
34
  public function getReviewUpdateCollection()
35
  {
36
- return $this->getCollection()->getReviewUpdateTime();
 
 
37
  }
38
 
 
 
 
 
 
39
  public function getRatingSummaryUpdateCollection()
40
  {
41
- return $this->getCollection()->getRatingSummaryUpdateTime();
 
 
42
  }
43
 
 
 
 
 
 
 
 
 
 
44
  public function markUpdated($reviewId, $entityId, $entityPkValue)
45
  {
46
- $this->mark($reviewId, $entityId, $entityPkValue, self::ACTIVITYTYPE_UPDATE);
 
 
47
  }
48
 
 
 
 
 
 
 
 
 
 
49
  public function markDeleted($reviewId, $entityId, $entityPkValue)
50
  {
51
- $this->mark($reviewId, $entityId, $entityPkValue, self::ACTIVITYTYPE_DELETE);
 
 
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
54
  protected function mark($reviewId, $entityId, $entityPkValue, $activityType)
55
  {
56
  $this->setReviewId($reviewId);
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Review_Update
17
+ */
18
  class Listrak_Remarketing_Model_Review_Update
19
  extends Mage_Core_Model_Abstract
20
  {
21
+ const ACTIVITY_TYPE_UPDATE = 1;
22
+ const ACTIVITY_TYPE_DELETE = 2;
23
 
24
+ /**
25
+ * Initializes the object
26
+ *
27
+ * @return void
28
+ */
29
  public function _construct()
30
  {
31
  parent::_construct();
32
  $this->_init('listrak/review_update');
33
  }
34
 
35
+ /**
36
+ * Retrieve an update record for a review
37
+ *
38
+ * @param int $reviewId Review ID
39
+ *
40
+ * @return Listrak_Remarketing_Model_Review_Update
41
+ */
42
  public function loadByReviewId($reviewId)
43
  {
44
  return $this->getCollection()
46
  ->getFirstItem();
47
  }
48
 
49
+ /**
50
+ * Retrieve a collection of updated reviews
51
+ *
52
+ * @return Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
53
+ */
54
  public function getReviewUpdateCollection()
55
  {
56
+ /* @var Listrak_Remarketing_Model_Mysql4_Review_Update_Collection $col */
57
+ $col = $this->getCollection();
58
+ return $col->getReviewUpdateTime();
59
  }
60
 
61
+ /**
62
+ * Retrieve a collection of updated rating summaries
63
+ *
64
+ * @return Listrak_Remarketing_Model_Mysql4_Review_Update_Collection
65
+ */
66
  public function getRatingSummaryUpdateCollection()
67
  {
68
+ /* @var Listrak_Remarketing_Model_Mysql4_Review_Update_Collection $col */
69
+ $col = $this->getCollection();
70
+ return $col->getRatingSummaryUpdateTime();
71
  }
72
 
73
+ /**
74
+ * Store a record of the review update
75
+ *
76
+ * @param int $reviewId Review ID
77
+ * @param int $entityId Review type
78
+ * @param int $entityPkValue Reviewed product ID
79
+ *
80
+ * @return void
81
+ */
82
  public function markUpdated($reviewId, $entityId, $entityPkValue)
83
  {
84
+ $this->mark(
85
+ $reviewId, $entityId, $entityPkValue, self::ACTIVITY_TYPE_UPDATE
86
+ );
87
  }
88
 
89
+ /**
90
+ * Store a record of review deletion
91
+ *
92
+ * @param int $reviewId Review ID
93
+ * @param int $entityId Review type
94
+ * @param int $entityPkValue Reviewed product ID
95
+ *
96
+ * @return void
97
+ */
98
  public function markDeleted($reviewId, $entityId, $entityPkValue)
99
  {
100
+ $this->mark(
101
+ $reviewId, $entityId, $entityPkValue, self::ACTIVITY_TYPE_DELETE
102
+ );
103
  }
104
 
105
+ /**
106
+ * Create a record to store review update or deletion
107
+ *
108
+ * @param int $reviewId Review ID
109
+ * @param int $entityId Review type
110
+ * @param int $entityPkValue Reviewed product ID
111
+ * @param int $activityType Updated or deleted
112
+ *
113
+ * @return void
114
+ */
115
  protected function mark($reviewId, $entityId, $entityPkValue, $activityType)
116
  {
117
  $this->setReviewId($reviewId);
app/code/community/Listrak/Remarketing/Model/Review/Update/Api.php CHANGED
@@ -12,46 +12,40 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Review_Update_Api
16
  extends Mage_Api_Model_Resource_Abstract
17
  {
18
- private $_statuses = array();
19
-
20
- private $_ratings = array();
21
-
22
- protected function getStatuses()
23
- {
24
- if (sizeof($this->_statuses) == 0) {
25
- foreach (Mage::getModel('review/review')->getStatusCollection()->getItems() as $status) {
26
- $this->_statuses[$status->getStatusId()] = $status->getStatusCode();
27
- }
28
- }
29
-
30
- return $this->_statuses;
31
- }
32
-
33
- protected function getRatings()
34
- {
35
- if (sizeof($this->_ratings) == 0) {
36
- foreach (Mage::getModel('rating/rating')->getResourceCollection()->getItems() as $rating) {
37
- $this->_ratings[$rating->getRatingId()] = $rating->getRatingCode();
38
- }
39
- }
40
-
41
- return $this->_ratings;
42
- }
43
-
44
  public function reviewList($storeId, $chunkSize, $startReviewId)
45
  {
46
  Mage::app()->setCurrentStore($storeId);
47
- Mage::helper('remarketing')->requireReviewsEnabled();
 
 
 
48
 
49
  try {
50
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
51
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
52
  $fromReviewId = $startReviewId + 1;
53
 
54
- $collection = Mage::helper('remarketing/review_update')->getReviewListCollection($getStoreId);
 
 
 
55
  $collection
56
  ->getSelect()
57
  ->where("main_table.review_id >= ?", $fromReviewId)
@@ -61,21 +55,40 @@ class Listrak_Remarketing_Model_Review_Update_Api
61
 
62
  return $this->_reviewsFromCollection($getStoreId, $collection);
63
  } catch (Exception $e) {
64
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
65
  }
66
  }
67
 
 
 
 
 
 
 
 
 
 
 
 
68
  public function reviewUpdateList($storeId, $chunkSize, $startUpdateId)
69
  {
70
  Mage::app()->setCurrentStore($storeId);
71
- Mage::helper('remarketing')->requireReviewsEnabled();
 
 
 
72
 
73
  try {
74
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
75
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
76
  $fromUpdateId = $startUpdateId + 1;
77
 
78
- $collection = Mage::helper('remarketing/review_update')->getReviewListCollection($getStoreId);
 
 
 
79
  $collection
80
  ->getSelect()
81
  ->where("updatetime.update_id >= ?", $fromUpdateId)
@@ -85,10 +98,20 @@ class Listrak_Remarketing_Model_Review_Update_Api
85
 
86
  return $this->_reviewsFromCollection($getStoreId, $collection);
87
  } catch (Exception $e) {
88
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
89
  }
90
  }
91
 
 
 
 
 
 
 
 
 
92
  private function _reviewsFromCollection($storeId, $reviewCollection)
93
  {
94
  $statuses = $this->getStatuses();
@@ -96,34 +119,41 @@ class Listrak_Remarketing_Model_Review_Update_Api
96
 
97
  $reviews = array();
98
 
 
99
  foreach ($reviewCollection as $review) {
100
  $reviewId = $review->getReviewId();
101
 
102
  $reviewRatings = array();
103
- $votesCollection = Mage::getModel('rating/rating_option_vote')
104
- ->getResourceCollection()
105
- ->setReviewFilter($reviewId);
106
 
107
- foreach ($votesCollection as $vote) {
 
 
 
 
 
 
108
  $ratingId = $vote->getRatingId();
109
 
110
  array_push(
111
- $reviewRatings, array(
112
- "rating_id" => $ratingId,
113
- "rating_code" => $ratings[$ratingId],
114
- "rating" => round($vote->getPercent() / 20, 4)
115
- )
 
116
  );
117
  }
118
 
119
- $overallRatingObj = Mage::getModel('rating/rating')
120
- ->getReviewSummary($reviewId, false);
 
121
 
122
  $overallRating = 0;
123
  foreach ($overallRatingObj as $ratingObj) {
124
  if ($ratingObj->getStoreId() == $storeId) {
125
  if ($ratingObj->getCount()) {
126
- $overallRating = $ratingObj->getSum() / $ratingObj->getCount();
 
127
  }
128
 
129
  break;
@@ -131,61 +161,100 @@ class Listrak_Remarketing_Model_Review_Update_Api
131
  }
132
 
133
  array_push(
134
- $reviews, array(
135
- "update_id" => $review->getUpdateId(),
136
- "review_id" => $reviewId,
137
- "product_id" => $review->getEntityPkValue(),
138
- "title" => $review->getTitle(),
139
- "text" => $review->getDetail(),
140
- "overall_rating" => round($overallRating / 20, 4),
141
- "created_at" => $review->getCreatedAt(),
142
- "updated_at" => $review->getUpdatedAt(),
143
- "reviewer_name" => $review->getNickname(),
144
- "email" => $review->getEmail(),
145
- "status_id" => $review->getStatusId(),
146
- "status_code" => $statuses[$review->getStatusId()],
147
- "ratings" => $reviewRatings
148
- )
 
149
  );
150
  }
151
 
152
  return $reviews;
153
  }
154
 
 
 
 
 
 
 
 
 
 
 
 
155
  public function ratingSummaryList($storeId, $chunkSize, $startRatingSummaryId)
156
  {
157
  Mage::app()->setCurrentStore($storeId);
158
- Mage::helper('remarketing')->requireReviewsEnabled();
 
 
 
159
 
160
  try {
161
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
162
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
163
  $fromRatingSummaryId = $startRatingSummaryId + 1;
164
 
165
- $collection = Mage::helper('remarketing/review_update')->getRatingSummaryListCollection($getStoreId);
 
 
166
  $collection->getSelect()
167
  ->where('review_entity_summary.entity_type = ?', 1)
168
- ->where("review_entity_summary.primary_id >= ?", $fromRatingSummaryId)
169
- ->order('review_entity_summary.primary_id ' . Varien_Db_Select::SQL_ASC)
 
 
 
 
170
  ->limit($getChunkSize);
171
 
172
  return $this->_ratingSummariesFromCollection($getStoreId, $collection);
173
  } catch (Exception $e) {
174
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
175
  }
176
  }
177
 
 
 
 
 
 
 
 
 
 
 
 
178
  public function ratingSummaryUpdateList($storeId, $chunkSize, $startUpdateId)
179
  {
180
  Mage::app()->setCurrentStore($storeId);
181
- Mage::helper('remarketing')->requireReviewsEnabled();
 
 
 
182
 
183
  try {
184
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
185
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
186
  $fromUpdateId = $startUpdateId + 1;
187
 
188
- $collection = Mage::helper('remarketing/review_update')->getRatingSummaryListCollection($getStoreId);
 
 
189
  $collection->getSelect()
190
  ->where('review_entity_summary.entity_type = ?', 1)
191
  ->where("updatetime.update_id >= ?", $fromUpdateId)
@@ -194,44 +263,60 @@ class Listrak_Remarketing_Model_Review_Update_Api
194
 
195
  return $this->_ratingSummariesFromCollection($getStoreId, $collection);
196
  } catch (Exception $e) {
197
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
198
  }
199
  }
200
 
 
 
 
 
 
 
 
 
201
  private function _ratingSummariesFromCollection($storeId, $collection)
202
  {
203
  $ratingSummaries = array();
204
 
 
205
  foreach ($collection as $ratingSummary) {
206
  $productId = $ratingSummary->getEntityPkValue();
207
 
 
208
  $ratingCollection = Mage::getModel('rating/rating')
209
- ->getResourceCollection()
210
- ->setStoreFilter($storeId)
211
- ->load()
212
- ->addEntitySummaryToItem($productId, $storeId);
213
 
214
  $ratings = array();
 
 
215
  foreach ($ratingCollection as $rating) {
216
  array_push(
217
- $ratings, array(
218
- "rating_id" => $rating->getRatingId(),
219
- "rating_code" => $rating->getRatingCode(),
220
- "rating" => round($rating->getSummary() / 20, 4)
221
- )
 
222
  );
223
  }
224
 
225
  array_push(
226
- $ratingSummaries, array(
227
- "update_id" => $ratingSummary->getUpdateId(),
228
- "rating_summary_id" => $ratingSummary->getPrimaryId(),
229
- "product_id" => $productId,
230
- "updated_at" => $ratingSummary->getUpdatedAt(),
231
- "total_reviews" => $ratingSummary->getReviewsCount(),
232
- "rating" => round($ratingSummary->getRatingSummary() / 20, 4),
233
- "ratings" => $ratings
234
- )
 
235
  );
236
  }
237
 
@@ -239,15 +324,27 @@ class Listrak_Remarketing_Model_Review_Update_Api
239
 
240
  }
241
 
 
 
 
 
 
 
 
 
 
 
242
  public function reviewDeleteList($chunkSize, $startDeleteId)
243
  {
244
  try {
 
245
  $mageResource = Mage::getSingleton('core/resource');
246
  $dbRead = $mageResource->getConnection('core_read');
247
 
248
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
249
  $fromDeleteId = $startDeleteId + 1;
250
 
 
251
  $collection = Mage::getModel('listrak/review_update')
252
  ->getCollection()
253
  ->productReviewsOnly()
@@ -256,40 +353,63 @@ class Listrak_Remarketing_Model_Review_Update_Api
256
  $allReviewIDs = $dbRead
257
  ->select()
258
  ->from(
259
- array('review' => Mage::getSingleton('core/resource')->getTableName('review/review')),
260
  'review.review_id'
261
  );
262
 
263
  $collection->getSelect()
264
- ->where('NOT EXISTS (' . $allReviewIDs->where('main_table.review_id = review.review_id') . ')')
 
 
 
 
265
  ->where("update_id >= ?", $fromDeleteId)
266
  ->limit($getChunkSize);
267
 
268
  $deletedReviews = array();
269
  foreach ($collection as $deletedReview) {
270
  array_push(
271
- $deletedReviews, array(
272
- "delete_id" => $deletedReview->getUpdateId(),
273
- "review_id" => $deletedReview->getReviewId()
274
- )
 
275
  );
276
  }
277
 
278
  return $deletedReviews;
279
  } catch (Exception $e) {
280
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
 
 
 
281
  }
282
  }
283
 
 
 
 
 
 
 
 
 
 
284
  public function reviewUpdatePurge($purgeBeforeDays)
285
  {
286
  try {
 
287
  $mageResource = Mage::getSingleton('core/resource');
288
  $dbWrite = $mageResource->getConnection('core_write');
289
 
290
- $doPurgeBeforeDays = is_numeric($purgeBeforeDays) ? $purgeBeforeDays : 30;
291
- $purgeBefore = $doPurgeBeforeDays > 0
292
- ? gmdate('Y-m-d H:i:s', strtotime("-{$doPurgeBeforeDays} days")) : gmdate('Y-m-d H:i:s');
 
 
 
293
 
294
  $rowsDeleted = $dbWrite->delete(
295
  $mageResource->getTableName('listrak/review_update'),
@@ -301,8 +421,59 @@ class Listrak_Remarketing_Model_Review_Update_Api
301
  "before" => $purgeBefore
302
  );
303
  } catch (Exception $e) {
304
- throw Mage::helper('remarketing')->generateAndLogException("Exception occurred in API call: " . $e->getMessage(), $e);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
305
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  }
307
  }
308
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Review_Update_Api
17
+ */
18
  class Listrak_Remarketing_Model_Review_Update_Api
19
  extends Mage_Api_Model_Resource_Abstract
20
  {
21
+ /**
22
+ * Retrieve reviews
23
+ *
24
+ * @param int $storeId Magento store ID
25
+ * @param int $chunkSize Page size
26
+ * @param int $startReviewId Cursor
27
+ *
28
+ * @return array
29
+ *
30
+ * @throws Exception
31
+ */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  public function reviewList($storeId, $chunkSize, $startReviewId)
33
  {
34
  Mage::app()->setCurrentStore($storeId);
35
+
36
+ /* @var Listrak_Remarketing_Helper_Data $helper */
37
+ $helper = Mage::helper('remarketing');
38
+ $helper->requireReviewsEnabled();
39
 
40
  try {
41
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
42
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
43
  $fromReviewId = $startReviewId + 1;
44
 
45
+ /* @var Listrak_Remarketing_Helper_Review_Update $updateHelper */
46
+ $updateHelper = Mage::helper('remarketing/review_update');
47
+
48
+ $collection = $updateHelper->getReviewListCollection($getStoreId);
49
  $collection
50
  ->getSelect()
51
  ->where("main_table.review_id >= ?", $fromReviewId)
55
 
56
  return $this->_reviewsFromCollection($getStoreId, $collection);
57
  } catch (Exception $e) {
58
+ throw $helper->generateAndLogException(
59
+ "Exception occurred in API call: " . $e->getMessage(), $e
60
+ );
61
  }
62
  }
63
 
64
+ /**
65
+ * Retrieve updated reviews
66
+ *
67
+ * @param int $storeId Magento store ID
68
+ * @param int $chunkSize Page size
69
+ * @param int $startUpdateId Cursor
70
+ *
71
+ * @return array
72
+ *
73
+ * @throws Exception
74
+ */
75
  public function reviewUpdateList($storeId, $chunkSize, $startUpdateId)
76
  {
77
  Mage::app()->setCurrentStore($storeId);
78
+
79
+ /* @var Listrak_Remarketing_Helper_Data $helper */
80
+ $helper = Mage::helper('remarketing');
81
+ $helper->requireReviewsEnabled();
82
 
83
  try {
84
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
85
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
86
  $fromUpdateId = $startUpdateId + 1;
87
 
88
+ /* @var Listrak_Remarketing_Helper_Review_Update $updateHelper */
89
+ $updateHelper = Mage::helper('remarketing/review_update');
90
+
91
+ $collection = $updateHelper->getReviewListCollection($getStoreId);
92
  $collection
93
  ->getSelect()
94
  ->where("updatetime.update_id >= ?", $fromUpdateId)
98
 
99
  return $this->_reviewsFromCollection($getStoreId, $collection);
100
  } catch (Exception $e) {
101
+ throw $helper->generateAndLogException(
102
+ "Exception occurred in API call: " . $e->getMessage(), $e
103
+ );
104
  }
105
  }
106
 
107
+ /**
108
+ * Retrieve review information
109
+ *
110
+ * @param int $storeId Magento store ID
111
+ * @param mixed $reviewCollection Collection of reviews
112
+ *
113
+ * @return array
114
+ */
115
  private function _reviewsFromCollection($storeId, $reviewCollection)
116
  {
117
  $statuses = $this->getStatuses();
119
 
120
  $reviews = array();
121
 
122
+ /* @var Mage_Review_Model_Review $review */
123
  foreach ($reviewCollection as $review) {
124
  $reviewId = $review->getReviewId();
125
 
126
  $reviewRatings = array();
 
 
 
127
 
128
+ /* @var Mage_Rating_Model_Resource_Rating_Option_Vote_Collection $votes */
129
+ $votes = Mage::getModel('rating/rating_option_vote')
130
+ ->getResourceCollection();
131
+ $votes->setReviewFilter($reviewId);
132
+
133
+ /* @var Mage_Rating_Model_Rating_Option_Vote $vote */
134
+ foreach ($votes as $vote) {
135
  $ratingId = $vote->getRatingId();
136
 
137
  array_push(
138
+ $reviewRatings,
139
+ array(
140
+ "rating_id" => $ratingId,
141
+ "rating_code" => $ratings[$ratingId],
142
+ "rating" => round($vote->getPercent() / 20, 4)
143
+ )
144
  );
145
  }
146
 
147
+ /* @var Mage_Rating_Model_Rating $ratingModel */
148
+ $ratingModel = Mage::getModel('rating/rating');
149
+ $overallRatingObj = $ratingModel->getReviewSummary($reviewId, false);
150
 
151
  $overallRating = 0;
152
  foreach ($overallRatingObj as $ratingObj) {
153
  if ($ratingObj->getStoreId() == $storeId) {
154
  if ($ratingObj->getCount()) {
155
+ $overallRating
156
+ = $ratingObj->getSum() / $ratingObj->getCount();
157
  }
158
 
159
  break;
161
  }
162
 
163
  array_push(
164
+ $reviews,
165
+ array(
166
+ "update_id" => $review->getUpdateId(),
167
+ "review_id" => $reviewId,
168
+ "product_id" => $review->getEntityPkValue(),
169
+ "title" => $review->getTitle(),
170
+ "text" => $review->getDetail(),
171
+ "overall_rating" => round($overallRating / 20, 4),
172
+ "created_at" => $review->getCreatedAt(),
173
+ "updated_at" => $review->getUpdatedAt(),
174
+ "reviewer_name" => $review->getNickname(),
175
+ "email" => $review->getEmail(),
176
+ "status_id" => $review->getStatusId(),
177
+ "status_code" => $statuses[$review->getStatusId()],
178
+ "ratings" => $reviewRatings
179
+ )
180
  );
181
  }
182
 
183
  return $reviews;
184
  }
185
 
186
+ /**
187
+ * Retrieve rating summaries
188
+ *
189
+ * @param int $storeId Magento store ID
190
+ * @param int $chunkSize Page size
191
+ * @param int $startRatingSummaryId Cursor
192
+ *
193
+ * @return array
194
+ *
195
+ * @throws Exception
196
+ */
197
  public function ratingSummaryList($storeId, $chunkSize, $startRatingSummaryId)
198
  {
199
  Mage::app()->setCurrentStore($storeId);
200
+
201
+ /* @var Listrak_Remarketing_Helper_Data $helper */
202
+ $helper = Mage::helper('remarketing');
203
+ $helper->requireReviewsEnabled();
204
 
205
  try {
206
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
207
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
208
  $fromRatingSummaryId = $startRatingSummaryId + 1;
209
 
210
+ /* @var Listrak_Remarketing_Helper_Review_Update $updateHelper */
211
+ $updateHelper = Mage::helper('remarketing/review_update');
212
+ $collection = $updateHelper->getRatingSummaryListCollection($getStoreId);
213
  $collection->getSelect()
214
  ->where('review_entity_summary.entity_type = ?', 1)
215
+ ->where(
216
+ "review_entity_summary.primary_id >= ?", $fromRatingSummaryId
217
+ )
218
+ ->order(
219
+ 'review_entity_summary.primary_id ' . Varien_Db_Select::SQL_ASC
220
+ )
221
  ->limit($getChunkSize);
222
 
223
  return $this->_ratingSummariesFromCollection($getStoreId, $collection);
224
  } catch (Exception $e) {
225
+ throw $helper->generateAndLogException(
226
+ "Exception occurred in API call: " . $e->getMessage(), $e
227
+ );
228
  }
229
  }
230
 
231
+ /**
232
+ * Retrieve updated rating summaries
233
+ *
234
+ * @param int $storeId Magento store ID
235
+ * @param int $chunkSize Page size
236
+ * @param int $startUpdateId Cursor
237
+ *
238
+ * @return array
239
+ *
240
+ * @throws Exception
241
+ */
242
  public function ratingSummaryUpdateList($storeId, $chunkSize, $startUpdateId)
243
  {
244
  Mage::app()->setCurrentStore($storeId);
245
+
246
+ /* @var Listrak_Remarketing_Helper_Data $helper */
247
+ $helper = Mage::helper('remarketing');
248
+ $helper->requireReviewsEnabled();
249
 
250
  try {
251
  $getStoreId = is_numeric($storeId) ? $storeId : 1;
252
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
253
  $fromUpdateId = $startUpdateId + 1;
254
 
255
+ /* @var Listrak_Remarketing_Helper_Review_Update $updateHelper */
256
+ $updateHelper = Mage::helper('remarketing/review_update');
257
+ $collection = $updateHelper->getRatingSummaryListCollection($getStoreId);
258
  $collection->getSelect()
259
  ->where('review_entity_summary.entity_type = ?', 1)
260
  ->where("updatetime.update_id >= ?", $fromUpdateId)
263
 
264
  return $this->_ratingSummariesFromCollection($getStoreId, $collection);
265
  } catch (Exception $e) {
266
+ throw $helper->generateAndLogException(
267
+ "Exception occurred in API call: " . $e->getMessage(), $e
268
+ );
269
  }
270
  }
271
 
272
+ /**
273
+ * Retrieve rating summary information
274
+ *
275
+ * @param int $storeId Magento store ID
276
+ * @param mixed $collection Collection of rating summaries
277
+ *
278
+ * @return array
279
+ */
280
  private function _ratingSummariesFromCollection($storeId, $collection)
281
  {
282
  $ratingSummaries = array();
283
 
284
+ /* @var Mage_Review_Model_Review_Summary $ratingSummary */
285
  foreach ($collection as $ratingSummary) {
286
  $productId = $ratingSummary->getEntityPkValue();
287
 
288
+ /* @var Mage_Rating_Model_Resource_Rating_Collection $ratingCollection */
289
  $ratingCollection = Mage::getModel('rating/rating')
290
+ ->getResourceCollection();
291
+ $ratingCollection->setStoreFilter($storeId)
292
+ ->load();
293
+ $ratingCollection->addEntitySummaryToItem($productId, $storeId);
294
 
295
  $ratings = array();
296
+
297
+ /* @var Mage_Rating_Model_Rating $rating */
298
  foreach ($ratingCollection as $rating) {
299
  array_push(
300
+ $ratings,
301
+ array(
302
+ "rating_id" => $rating->getRatingId(),
303
+ "rating_code" => $rating->getRatingCode(),
304
+ "rating" => round($rating->getSummary() / 20, 4)
305
+ )
306
  );
307
  }
308
 
309
  array_push(
310
+ $ratingSummaries,
311
+ array(
312
+ "update_id" => $ratingSummary->getUpdateId(),
313
+ "rating_summary_id" => $ratingSummary->getPrimaryId(),
314
+ "product_id" => $productId,
315
+ "updated_at" => $ratingSummary->getUpdatedAt(),
316
+ "total_reviews" => $ratingSummary->getReviewsCount(),
317
+ "rating" => round($ratingSummary->getRatingSummary() / 20, 4),
318
+ "ratings" => $ratings
319
+ )
320
  );
321
  }
322
 
324
 
325
  }
326
 
327
+ /**
328
+ * Retrieve deleted reviews
329
+ *
330
+ * @param int $chunkSize Page size
331
+ * @param int $startDeleteId Cursor
332
+ *
333
+ * @return array
334
+ *
335
+ * @throws Exception
336
+ */
337
  public function reviewDeleteList($chunkSize, $startDeleteId)
338
  {
339
  try {
340
+ /* @var Mage_Core_Model_Resource $mageResource */
341
  $mageResource = Mage::getSingleton('core/resource');
342
  $dbRead = $mageResource->getConnection('core_read');
343
 
344
  $getChunkSize = is_numeric($chunkSize) ? $chunkSize : 50;
345
  $fromDeleteId = $startDeleteId + 1;
346
 
347
+ /* @var Listrak_Remarketing_Model_Mysql4_Review_Update_Collection $collection */
348
  $collection = Mage::getModel('listrak/review_update')
349
  ->getCollection()
350
  ->productReviewsOnly()
353
  $allReviewIDs = $dbRead
354
  ->select()
355
  ->from(
356
+ array('review' => $mageResource->getTableName('review/review')),
357
  'review.review_id'
358
  );
359
 
360
  $collection->getSelect()
361
+ ->where(
362
+ 'NOT EXISTS ('
363
+ . $allReviewIDs->where('main_table.review_id = review.review_id')
364
+ . ')'
365
+ )
366
  ->where("update_id >= ?", $fromDeleteId)
367
  ->limit($getChunkSize);
368
 
369
  $deletedReviews = array();
370
  foreach ($collection as $deletedReview) {
371
  array_push(
372
+ $deletedReviews,
373
+ array(
374
+ "delete_id" => $deletedReview->getUpdateId(),
375
+ "review_id" => $deletedReview->getReviewId()
376
+ )
377
  );
378
  }
379
 
380
  return $deletedReviews;
381
  } catch (Exception $e) {
382
+ /* @var Listrak_Remarketing_Helper_Data $helper */
383
+ $helper = Mage::helper('remarketing');
384
+
385
+ throw $helper->generateAndLogException(
386
+ "Exception occurred in API call: " . $e->getMessage(), $e
387
+ );
388
  }
389
  }
390
 
391
+ /**
392
+ * Purge old entries to the review update collection
393
+ *
394
+ * @param int $purgeBeforeDays Days to keep
395
+ *
396
+ * @return array
397
+ *
398
+ * @throws Exception
399
+ */
400
  public function reviewUpdatePurge($purgeBeforeDays)
401
  {
402
  try {
403
+ /* @var Mage_Core_Model_Resource $mageResource */
404
  $mageResource = Mage::getSingleton('core/resource');
405
  $dbWrite = $mageResource->getConnection('core_write');
406
 
407
+ $doPurgeBeforeDays
408
+ = is_numeric($purgeBeforeDays) ? $purgeBeforeDays : 30;
409
+ $purgeBefore
410
+ = $doPurgeBeforeDays > 0
411
+ ? gmdate('Y-m-d H:i:s', strtotime("-{$doPurgeBeforeDays} days"))
412
+ : gmdate('Y-m-d H:i:s');
413
 
414
  $rowsDeleted = $dbWrite->delete(
415
  $mageResource->getTableName('listrak/review_update'),
421
  "before" => $purgeBefore
422
  );
423
  } catch (Exception $e) {
424
+ /* @var Listrak_Remarketing_Helper_Data $helper */
425
+ $helper = Mage::helper('remarketing');
426
+
427
+ throw $helper->generateAndLogException(
428
+ "Exception occurred in API call: " . $e->getMessage(), $e
429
+ );
430
+ }
431
+ }
432
+
433
+ /**
434
+ * Retrieve review statuses
435
+ *
436
+ * @return array
437
+ */
438
+ protected function getStatuses()
439
+ {
440
+ $statuses = array();
441
+
442
+ /* @var Mage_Review_Model_Review $reviewModel */
443
+ $reviewModel = Mage::getModel('review/review');
444
+
445
+ /* @var Mage_Review_Model_Resource_Review_Status_Collection $collection */
446
+ $collection = $reviewModel->getStatusCollection();
447
+
448
+ /* @var Mage_Review_Model_Review_Status $status */
449
+ foreach ($collection->getItems() as $status) {
450
+ $statuses[$status->getStatusId()] = $status->getStatusCode();
451
  }
452
+
453
+ return $statuses;
454
+ }
455
+
456
+ /**
457
+ * Retrieve all ratings
458
+ *
459
+ * @return array
460
+ */
461
+ protected function getRatings()
462
+ {
463
+ $ratings = array();
464
+
465
+ /* @var Mage_Rating_Model_Rating $ratingModel */
466
+ $ratingModel = Mage::getModel('rating/rating');
467
+
468
+ /* @var Mage_Rating_Model_Resource_Rating_Collection $collection */
469
+ $collection = $ratingModel->getResourceCollection();
470
+
471
+ /* @var Mage_Rating_Model_Rating $rating */
472
+ foreach ($collection->getItems() as $rating) {
473
+ $ratings[$rating->getRatingId()] = $rating->getRatingCode();
474
+ }
475
+
476
+ return $ratings;
477
  }
478
  }
479
 
app/code/community/Listrak/Remarketing/Model/Review/Update/Api/V2.php CHANGED
@@ -12,6 +12,9 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Review_Update_Api_V2
16
  extends Listrak_Remarketing_Model_Review_Update_Api
17
  {
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Review_Update_Api_V2
17
+ */
18
  class Listrak_Remarketing_Model_Review_Update_Api_V2
19
  extends Listrak_Remarketing_Model_Review_Update_Api
20
  {
app/code/community/Listrak/Remarketing/Model/Session.php CHANGED
@@ -12,17 +12,33 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_Model_Session extends Mage_Core_Model_Abstract
16
  {
17
-
 
 
 
 
18
  public function _construct()
19
  {
20
  parent::_construct();
21
  $this->_init('listrak/session');
22
  }
23
-
24
- public function loadFromCookie() {
25
- $ltksid = Mage::getModel('core/cookie')->get('ltksid');
 
 
 
 
 
 
 
 
 
26
  if (!empty($ltksid) && strlen($ltksid) > 37) {
27
  $ltkpk = intval(substr($ltksid, 37), 10);
28
  if ($ltkpk != $this->getId()) {
@@ -36,21 +52,38 @@ class Listrak_Remarketing_Model_Session extends Mage_Core_Model_Abstract
36
  return $this;
37
  }
38
 
39
- public function init($createOnlyIfCartHasItems = false)
 
 
 
 
 
 
 
 
 
40
  {
41
  $this->loadFromCookie();
42
 
43
- $piid = Mage::getModel('core/cookie')->get('personalmerchant');
 
 
 
 
 
44
  $custSession = Mage::getSingleton("customer/session");
45
 
46
- $cartHasItems = Mage::helper('checkout/cart')->getItemsCount() > 0;
 
 
 
47
 
48
  if (!empty($piid)) {
49
  $this->setPiId($piid);
50
  }
51
 
52
  if (!$this->getId()) {
53
- if ($createOnlyIfCartHasItems && !$cartHasItems) {
54
  return null;
55
  }
56
  $this->setCreatedAt(gmdate('Y-m-d H:i:s'));
@@ -64,7 +97,7 @@ class Listrak_Remarketing_Model_Session extends Mage_Core_Model_Abstract
64
  $this->setCustomerId($custSession->getId());
65
  }
66
 
67
- $quoteId = Mage::helper('checkout/cart')->getQuote()->getId();
68
 
69
  if ($quoteId) {
70
  $this->setQuoteId($quoteId);
@@ -82,55 +115,93 @@ class Listrak_Remarketing_Model_Session extends Mage_Core_Model_Abstract
82
  }
83
 
84
  if ($this->getIsNew() === true) {
 
 
 
85
  $saved = false;
86
  $tryCount = 0;
87
- while(!$saved && $tryCount < 2) {
88
  $tryCount++;
89
 
90
  try {
91
- $this->setSessionId(Mage::helper('remarketing')->genUuid());
92
  $this->save();
93
  $saved = true;
94
  } catch(Exception $e) {
95
- Mage::getModel('listrak/log')->addException(new Exception("{QuoteID: " . $this->getQuoteId() . ", SessionID: " . $this->getSessionId() . "} Exception when attempting to save session: " . $e->getMessage()));
 
 
 
 
 
 
 
 
 
 
96
  }
97
  }
98
 
99
  if (!$saved) {
100
- throw new Exception("{QuoteID: " . $this->getQuoteId() . "} Failed to save session. See previous exceptions.");
 
 
 
101
  }
102
 
103
- Mage::getModel('core/cookie')->set(
104
  'ltksid',
105
- $this->getSessionId() . '-' . $this->getId(),
106
  true, null, null, null, false
107
  );
108
  } else {
109
  $this->save();
110
  }
111
 
112
- $cs = Mage::getSingleton('core/session');
113
-
114
- if ($cs->getIsListrakOrderMade()) {
115
  $this->deleteCookie();
116
- $cs->setIsListrakOrderMade(false);
117
  }
118
 
119
  return $this;
120
  }
121
 
 
 
 
 
 
122
  public function loadEmails()
123
  {
124
- $this->getResource()->loadEmails($this);
 
 
125
  }
126
 
127
- public function deleteCookie() {
128
- Mage::getModel('core/cookie')->delete('ltksid');
 
 
 
 
 
 
 
 
129
  }
130
 
 
 
 
 
 
131
  public function delete()
132
  {
133
- $this->getResource()->deleteEmails($this->getId());
 
 
 
134
  parent::delete();
135
  }
136
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Session
17
+ */
18
  class Listrak_Remarketing_Model_Session extends Mage_Core_Model_Abstract
19
  {
20
+ /**
21
+ * Initializes the object
22
+ *
23
+ * @return void
24
+ */
25
  public function _construct()
26
  {
27
  parent::_construct();
28
  $this->_init('listrak/session');
29
  }
30
+
31
+ /**
32
+ * Loads the data associated with the session cookie
33
+ *
34
+ * @return $this
35
+ */
36
+ public function loadFromCookie()
37
+ {
38
+ /* @var Mage_Core_Model_Cookie $cookies */
39
+ $cookies = Mage::getModel('core/cookie');
40
+
41
+ $ltksid = $cookies->get('ltksid');
42
  if (!empty($ltksid) && strlen($ltksid) > 37) {
43
  $ltkpk = intval(substr($ltksid, 37), 10);
44
  if ($ltkpk != $this->getId()) {
52
  return $this;
53
  }
54
 
55
+ /**
56
+ * Initialize session for the current request
57
+ *
58
+ * @param bool $createOnlyIfHasItems Flag to ignore empty carts
59
+ *
60
+ * @return $this
61
+ *
62
+ * @throws Exception
63
+ */
64
+ public function init($createOnlyIfHasItems = false)
65
  {
66
  $this->loadFromCookie();
67
 
68
+ /* @var Mage_Core_Model_Cookie $cookies */
69
+ $cookies = Mage::getModel('core/cookie');
70
+
71
+ $piid = $cookies->get('personalmerchant');
72
+
73
+ /* @var Mage_Customer_Model_Session $custSession */
74
  $custSession = Mage::getSingleton("customer/session");
75
 
76
+ /* @var Mage_Checkout_Helper_Cart $cartHelper */
77
+ $cartHelper = Mage::helper('checkout/cart');
78
+
79
+ $cartHasItems = $cartHelper->getItemsCount() > 0;
80
 
81
  if (!empty($piid)) {
82
  $this->setPiId($piid);
83
  }
84
 
85
  if (!$this->getId()) {
86
+ if ($createOnlyIfHasItems && !$cartHasItems) {
87
  return null;
88
  }
89
  $this->setCreatedAt(gmdate('Y-m-d H:i:s'));
97
  $this->setCustomerId($custSession->getId());
98
  }
99
 
100
+ $quoteId = $cartHelper->getQuote()->getId();
101
 
102
  if ($quoteId) {
103
  $this->setQuoteId($quoteId);
115
  }
116
 
117
  if ($this->getIsNew() === true) {
118
+ /* @var Listrak_Remarketing_Helper_Data $helper */
119
+ $helper = Mage::helper('remarketing');
120
+
121
  $saved = false;
122
  $tryCount = 0;
123
+ while (!$saved && $tryCount < 2) {
124
  $tryCount++;
125
 
126
  try {
127
+ $this->setSessionId($helper->genUuid());
128
  $this->save();
129
  $saved = true;
130
  } catch(Exception $e) {
131
+ /* @var Listrak_Remarketing_Model_Log $logger */
132
+ $logger = Mage::getModel('listrak/log');
133
+
134
+ $logger->addException(
135
+ new Exception(
136
+ "{QuoteID: {$this->getQuoteId()}, "
137
+ . "SessionID: {$this->getSessionId()}} "
138
+ . "Exception when attempting to save session: "
139
+ . $e->getMessage()
140
+ )
141
+ );
142
  }
143
  }
144
 
145
  if (!$saved) {
146
+ throw new Exception(
147
+ "{QuoteID: {$this->getQuoteId()}} Failed to save session. "
148
+ . "See previous exceptions."
149
+ );
150
  }
151
 
152
+ $cookies->set(
153
  'ltksid',
154
+ "{$this->getSessionId()}-{$this->getId()}",
155
  true, null, null, null, false
156
  );
157
  } else {
158
  $this->save();
159
  }
160
 
161
+ $coreSession = Mage::getSingleton('core/session');
162
+ if ($coreSession->getIsListrakOrderMade()) {
 
163
  $this->deleteCookie();
164
+ $coreSession->setIsListrakOrderMade(false);
165
  }
166
 
167
  return $this;
168
  }
169
 
170
+ /**
171
+ * Loaded all captured emails
172
+ *
173
+ * @return void
174
+ */
175
  public function loadEmails()
176
  {
177
+ /* @var Listrak_Remarketing_Model_Mysql4_Session $resource */
178
+ $resource = $this->getResource();
179
+ $resource->loadEmails($this);
180
  }
181
 
182
+ /**
183
+ * Delete session cookie
184
+ *
185
+ * @return void
186
+ */
187
+ public function deleteCookie()
188
+ {
189
+ /* @var Mage_Core_Model_Cookie $cookies */
190
+ $cookies = Mage::getModel('core/cookie');
191
+ $cookies->delete('ltksid');
192
  }
193
 
194
+ /**
195
+ * Delete the data associated with the loaded session
196
+ *
197
+ * @return void
198
+ */
199
  public function delete()
200
  {
201
+ /* @var Listrak_Remarketing_Model_Mysql4_Session $resource */
202
+ $resource = $this->getResource();
203
+
204
+ $resource->deleteEmails($this->getId());
205
  parent::delete();
206
  }
207
  }
app/code/community/Listrak/Remarketing/Model/Subscriber.php CHANGED
@@ -12,24 +12,45 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
 
 
 
 
 
 
 
 
16
  {
17
-
 
 
 
 
18
  public function sendConfirmationSuccessEmail()
19
  {
20
- if (!Mage::getStoreConfig('remarketing/subscription/signup_success_email')) {
 
 
 
 
21
  return $this;
22
  }
23
-
24
- return parent::sendConfirmationSuccessEmail();
25
  }
26
 
 
 
 
 
 
27
  public function sendUnsubscriptionEmail()
28
  {
29
- if (!Mage::getStoreConfig('remarketing/subscription/unsubscribe_email')) {
 
 
 
 
30
  return $this;
31
  }
32
-
33
- return parent::sendUnsubscriptionEmail();
34
  }
35
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Subscriber
17
+ *
18
+ * Overwrites newsletter subscriber object to ensure that
19
+ * the customer receives only one signup/unsub email, and
20
+ * not one from each source
21
+ */
22
+ class Listrak_Remarketing_Model_Subscriber
23
+ extends Mage_Newsletter_Model_Subscriber
24
  {
25
+ /**
26
+ * Shim to test email singup configuration
27
+ *
28
+ * @return $this
29
+ */
30
  public function sendConfirmationSuccessEmail()
31
  {
32
+ if (Mage::getStoreConfig(
33
+ 'remarketing/subscription/signup_success_email'
34
+ ) == '1') {
35
+ return parent::sendConfirmationSuccessEmail();
36
+ } else {
37
  return $this;
38
  }
 
 
39
  }
40
 
41
+ /**
42
+ * Shim to test email unsub configuration
43
+ *
44
+ * @return $this
45
+ */
46
  public function sendUnsubscriptionEmail()
47
  {
48
+ if (Mage::getStoreConfig(
49
+ 'remarketing/subscription/unsubscribe_email'
50
+ ) == '1') {
51
+ return parent::sendUnsubscriptionEmail();
52
+ } else {
53
  return $this;
54
  }
 
 
55
  }
56
  }
app/code/community/Listrak/Remarketing/Model/Subscriberupdate.php CHANGED
@@ -12,8 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_Model_Subscriberupdate extends Mage_Core_Model_Abstract
 
 
 
 
16
  {
 
 
 
 
 
17
  public function _construct()
18
  {
19
  parent::_construct();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_Model_Subscriberupdate
17
+ */
18
+ class Listrak_Remarketing_Model_Subscriberupdate
19
+ extends Mage_Core_Model_Abstract
20
  {
21
+ /**
22
+ * Initializes the object
23
+ *
24
+ * @return void
25
+ */
26
  public function _construct()
27
  {
28
  parent::_construct();
app/code/community/Listrak/Remarketing/controllers/Adminhtml/AbandonedcartreportController.php DELETED
@@ -1,47 +0,0 @@
1
- <?php
2
- /**
3
- * Listrak Remarketing Magento Extension Ver. 1.0.0
4
- *
5
- * PHP version 5
6
- *
7
- * @category Listrak
8
- * @package Listrak_Remarketing
9
- * @author Listrak Magento Team <magento@listrak.com>
10
- * @copyright 2011 Listrak Inc
11
- * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
- * @link http://www.listrak.com
13
- */
14
-
15
- class Listrak_Remarketing_Adminhtml_AbandonedcartreportController
16
- extends Mage_Adminhtml_Controller_Action
17
- {
18
- protected function _initAction()
19
- {
20
- $this->loadLayout()
21
- ->_setActiveMenu('remarketing');
22
- return $this;
23
- }
24
-
25
- public function indexAction()
26
- {
27
- try {
28
- $this->_initAction();
29
- $this->_addContent($this->getLayout()->createBlock('remarketing/adminhtml_abandonedcartreport'));
30
- $this->renderLayout();
31
- } catch (Exception $e) {
32
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
33
- Mage::getSingleton('adminhtml/session')->setEmailCaptureData($this->getRequest()->getPost());
34
- $this->_redirect('adminhtml/dashboard');
35
- return;
36
- }
37
-
38
- }
39
-
40
- public function gridAction()
41
- {
42
- $this->loadLayout();
43
- $this->getResponse()->setBody(
44
- $this->getLayout()->createBlock('importedit/adminhtml_abandonedcartreport_grid')->toHtml()
45
- );
46
- }
47
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Listrak/Remarketing/controllers/Adminhtml/EmailcaptureController.php DELETED
@@ -1,153 +0,0 @@
1
- <?php
2
- /**
3
- * Listrak Remarketing Magento Extension Ver. 1.0.0
4
- *
5
- * PHP version 5
6
- *
7
- * @category Listrak
8
- * @package Listrak_Remarketing
9
- * @author Listrak Magento Team <magento@listrak.com>
10
- * @copyright 2011 Listrak Inc
11
- * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
- * @link http://www.listrak.com
13
- */
14
-
15
- class Listrak_Remarketing_Adminhtml_EmailCaptureController
16
- extends Mage_Adminhtml_Controller_Action
17
- {
18
-
19
- protected function _initAction()
20
- {
21
- $this->loadLayout()
22
- ->_setActiveMenu('remarketing')
23
- ->_addBreadcrumb(
24
- Mage::helper('adminhtml')->__('Fields Manager'),
25
- Mage::helper('adminhtml')->__('Field Manager')
26
- );
27
- return $this;
28
- }
29
-
30
- public function indexAction()
31
- {
32
- try {
33
- $this->_initAction();
34
- $this->_addContent($this->getLayout()->createBlock('remarketing/adminhtml_emailcapture'));
35
- $this->renderLayout();
36
- } catch (Exception $e) {
37
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
38
- Mage::getSingleton('adminhtml/session')->setEmailCaptureData($this->getRequest()->getPost());
39
- $this->_redirect('adminhtml/dashboard');
40
- return;
41
- }
42
-
43
- }
44
-
45
- public function editAction()
46
- {
47
- try {
48
- $emailcaptureId = $this->getRequest()->getParam('id');
49
- $emailcaptureModel = Mage::getModel('listrak/emailcapture')->load($emailcaptureId);
50
-
51
- if ($emailcaptureModel->getId() || $emailcaptureId == 0) {
52
-
53
- Mage::register('emailcapture_data', $emailcaptureModel);
54
-
55
- $this->loadLayout();
56
- $this->_setActiveMenu('emailcapture');
57
-
58
- $this->_addBreadcrumb(
59
- Mage::helper('adminhtml')->__('Item Manager'),
60
- Mage::helper('adminhtml')->__('Item Manager')
61
- );
62
- $this->_addBreadcrumb(
63
- Mage::helper('adminhtml')->__('Item News'),
64
- Mage::helper('adminhtml')->__('Item News')
65
- );
66
-
67
- $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
68
-
69
- $this->_addContent($this->getLayout()->createBlock('remarketing/adminhtml_emailcapture_edit'))
70
- ->_addLeft($this->getLayout()->createBlock('remarketing/adminhtml_emailcapture_edit_tabs'));
71
-
72
- $this->renderLayout();
73
- } else {
74
- Mage::getSingleton('adminhtml/session')->addError(
75
- Mage::helper('remarketing')->__('Item does not exist')
76
- );
77
- $this->_redirect('*/*/');
78
- }
79
- } catch (Exception $e) {
80
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
81
- Mage::getSingleton('adminhtml/session')->setEmailCaptureData($this->getRequest()->getPost());
82
- $this->_redirect('*/*/index', array('id' => $this->getRequest()->getParam('id')));
83
- return;
84
- }
85
- }
86
-
87
- public function newAction()
88
- {
89
- $this->_forward('edit');
90
- }
91
-
92
- public function saveAction()
93
- {
94
- if ($this->getRequest()->getPost()) {
95
- try {
96
- $postData = $this->getRequest()->getPost();
97
- $emailcaptureModel = Mage::getModel('listrak/emailcapture');
98
-
99
- $emailcaptureModel->setId($this->getRequest()->getParam('id'))
100
- ->setPage($postData['page'])
101
- ->setFieldId($postData['field_id'])
102
- ->save();
103
-
104
- Mage::getSingleton('adminhtml/session')->addSuccess(
105
- Mage::helper('adminhtml')->__('Item was successfully saved')
106
- );
107
- Mage::getSingleton('adminhtml/session')->setEmailCaptureData(false);
108
-
109
- $this->_redirect('*/*/');
110
- return;
111
- } catch (Exception $e) {
112
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
113
- Mage::getSingleton('adminhtml/session')->setEmailCaptureData($this->getRequest()->getPost());
114
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
115
- return;
116
- }
117
- }
118
- $this->_redirect('*/*/');
119
- }
120
-
121
- public function deleteAction()
122
- {
123
- if ($this->getRequest()->getParam('id') > 0) {
124
- try {
125
- $emailcaptureModel = Mage::getModel('listrak/emailcapture');
126
-
127
- $emailcaptureModel->setId($this->getRequest()->getParam('id'))
128
- ->delete();
129
-
130
- Mage::getSingleton('adminhtml/session')->addSuccess(
131
- Mage::helper('adminhtml')->__('Item was successfully deleted')
132
- );
133
- $this->_redirect('*/*/');
134
- } catch (Exception $e) {
135
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
136
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
137
- }
138
- }
139
- $this->_redirect('*/*/');
140
- }
141
-
142
- /**
143
- * Product grid for AJAX request.
144
- * Sort and filter result for example.
145
- */
146
- public function gridAction()
147
- {
148
- $this->loadLayout();
149
- $this->getResponse()->setBody(
150
- $this->getLayout()->createBlock('importedit/adminhtml_emailcapture_grid')->toHtml()
151
- );
152
- }
153
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Listrak/Remarketing/controllers/Adminhtml/ProductattributesController.php DELETED
@@ -1,162 +0,0 @@
1
- <?php
2
- /**
3
- * Listrak Remarketing Magento Extension Ver. 1.0.0
4
- *
5
- * PHP version 5
6
- *
7
- * @category Listrak
8
- * @package Listrak_Remarketing
9
- * @author Listrak Magento Team <magento@listrak.com>
10
- * @copyright 2011 Listrak Inc
11
- * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
- * @link http://www.listrak.com
13
- */
14
-
15
- class Listrak_Remarketing_Adminhtml_ProductAttributesController
16
- extends Mage_Adminhtml_Controller_Action
17
- {
18
- protected function _initAction()
19
- {
20
- $this->loadLayout()
21
- ->_setActiveMenu('remarketing');
22
- return $this;
23
- }
24
-
25
- public function indexAction()
26
- {
27
- $this->_initAction();
28
-
29
- try {
30
- // before we display the data, make sure all the product attribute sets are found in our table
31
- // that is done because we can't have null primary keys - something that would happen otherwise
32
- Mage::helper('remarketing/product_attribute_set_map')->ensureDataConsistency();
33
-
34
- // all is consistent - load the information and the UI
35
- $sets = Mage::getModel('listrak/product_attribute_set_map')
36
- ->getCollection()
37
- ->addAttributeSetName()
38
- ->addAttributeNames()
39
- ->orderByAttributeSetName();
40
-
41
- Mage::register('productattribute_sets', $sets);
42
-
43
- $this->_addContent($this->getLayout()->createBlock('remarketing/adminhtml_productattributes'));
44
-
45
- $this->renderLayout();
46
- } catch (Exception $e) {
47
- Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
48
- $this->_redirect('*/*/index', array('id' => $this->getRequest()->getParam('id')));
49
- return;
50
- }
51
- }
52
-
53
- public function editAction()
54
- {
55
- $this->_initAction();
56
-
57
- try {
58
- $id = $this->getRequest()->getParam('id');
59
- $model = Mage::getModel('listrak/product_attribute_set_map')
60
- ->getCollection()
61
- ->addAttributeSetName()
62
- ->addMapIdFilter($id)
63
- ->getFirstItem();
64
-
65
- Mage::register('productattribute_data', $model);
66
-
67
- $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
68
-
69
- $this->_addContent($this->getLayout()->createBlock('remarketing/adminhtml_productattributes_edit'))
70
- ->_addLeft($this->getLayout()->createBlock('remarketing/adminhtml_productattributes_edit_tabs'));
71
-
72
- $this->renderLayout();
73
- } catch (Exception $e) {
74
- Mage::getModel('listrak/log')->addException($e);
75
- Mage::getSingleton('adminhtml/session')->addError(
76
- "An unexpected error occurred while attempting to display the form. Please try again."
77
- );
78
- $this->_redirect('*/*/index', array('id' => $this->getRequest()->getParam('id')));
79
- return;
80
- }
81
- }
82
-
83
- public function saveAction()
84
- {
85
- if ($this->getRequest()->getPost()) {
86
- try {
87
- $postData = $this->getRequest()->getPost();
88
- $id = $this->getRequest()->getParam('id');
89
-
90
- $model = Mage::getModel('listrak/product_attribute_set_map')
91
- ->load($id);
92
-
93
- // now we know if there is a record and if there isn't, it will be inserted
94
- $categoriesSource = array_key_exists('categories_source', $postData)
95
- ? $postData['categories_source'] : null;
96
- $useConfigCategoriesSource = array_key_exists('use_config_categories_source', $postData)
97
- && $postData['use_config_categories_source'] ? 1 : 0;
98
- $categoryAttributeCode = $postData['categories_category_attribute'] == ''
99
- ? null : $postData['categories_category_attribute'];
100
- $subcategoryAttributeCode = $postData['categories_subcategory_attribute'] == ''
101
- ? null : $postData['categories_subcategory_attribute'];
102
- $model->setBrandAttributeCode($postData['brand_attribute'] == '' ? null : $postData['brand_attribute'])
103
- ->setCategoriesSource($categoriesSource)
104
- ->setUseConfigCategoriesSource($useConfigCategoriesSource)
105
- ->setCategoryAttributeCode($categoryAttributeCode)
106
- ->setSubcategoryAttributeCode($subcategoryAttributeCode)
107
- ->save();
108
-
109
- Mage::getSingleton('adminhtml/session')->addSuccess(
110
- Mage::helper('adminhtml')->__('Item was successfully saved')
111
- );
112
-
113
- $this->_redirect('*/*/');
114
- return;
115
- } catch (Exception $e) {
116
- Mage::getModel('listrak/log')->addException($e);
117
- Mage::getSingleton('adminhtml/session')->addError(
118
- "An unexpected error occurred while attempting to save the settings. Please try again."
119
- );
120
- $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
121
- return;
122
- }
123
- }
124
- $this->_redirect('*/*/');
125
- }
126
-
127
- public function bulkassignAction()
128
- {
129
- try {
130
- $postData = $this->getRequest()->getPost();
131
- if (array_key_exists('bulkassign_attribute', $postData) && $postData['bulkassign_attribute'] != '') {
132
- $attributeCode = $postData['bulkassign_attribute'];
133
-
134
- $sets = Mage::getModel('listrak/product_attribute_set_map')
135
- ->getCollection();
136
-
137
-
138
- foreach ($sets as $set) {
139
- $productAttributeCollectionCount = Mage::getResourceModel('catalog/product_attribute_collection')
140
- ->setAttributeSetFilter($set->getAttributeSetId())
141
- ->addVisibleFilter()
142
- ->setCodeFilter($attributeCode)
143
- ->count();
144
- if ($set->getBrandAttributeCode() == null
145
- && $productAttributeCollectionCount > 0
146
- ) {
147
- $set->setBrandAttributeCode($attributeCode)
148
- ->save();
149
- }
150
- }
151
- }
152
- } catch (Exception $e) {
153
- Mage::getModel('listrak/log')->addException($e);
154
- Mage::getSingleton('adminhtml/session')->addError(
155
- "An unexpected error occurred while assigning the brand attribute."
156
- );
157
- }
158
-
159
- $this->_redirect('*/*/');
160
- }
161
- }
162
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/Listrak/Remarketing/controllers/AjaxController.php CHANGED
@@ -12,19 +12,56 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_AjaxController extends Mage_Core_Controller_Front_Action
 
 
 
 
16
  {
17
- public function cartAction() {
 
 
 
 
 
 
 
18
  $tracking_cart = $this->getLayout()->createBlock('remarketing/tracking_sca');
 
19
 
20
- $this->getResponse()->setHeader('Content-Type', 'application/javascript', true);
21
- $this->getResponse()->setBody($tracking_cart->getCartJavascript());
 
22
  }
23
-
24
- public function trackAction() {
 
 
 
 
 
 
 
25
  $tracking_cart = $this->getLayout()->createBlock('remarketing/tracking_sca');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
- $this->getResponse()->setHeader('Content-Type', 'application/javascript', true);
28
- $this->getResponse()->setBody($tracking_cart->toHtml());
29
  }
30
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_AjaxController
17
+ */
18
+ class Listrak_Remarketing_AjaxController
19
+ extends Mage_Core_Controller_Front_Action
20
  {
21
+ /**
22
+ * Respond with javascript that contains the cart contents
23
+ *
24
+ * @return $this
25
+ */
26
+ public function cartAction()
27
+ {
28
+ /* @var Listrak_Remarketing_Block_Tracking_Sca $tracking_cart */
29
  $tracking_cart = $this->getLayout()->createBlock('remarketing/tracking_sca');
30
+ $jsResponse = $tracking_cart->getCartJavascript();
31
 
32
+ $this->_setJavascriptResponse($jsResponse);
33
+
34
+ return $this;
35
  }
36
+
37
+ /**
38
+ * Respond with javascript that tracks the current session
39
+ *
40
+ * @return $this
41
+ */
42
+ public function trackAction()
43
+ {
44
+ /* @var Listrak_Remarketing_Block_Tracking_Sca $tracking_cart */
45
  $tracking_cart = $this->getLayout()->createBlock('remarketing/tracking_sca');
46
+ $jsResponse = $tracking_cart->toHtml();
47
+
48
+ $this->_setJavascriptResponse($jsResponse);
49
+
50
+ return $this;
51
+ }
52
+
53
+ /**
54
+ * Forms the response to execute in the browser.
55
+ *
56
+ * @param string $body The response body
57
+ *
58
+ * @return void
59
+ */
60
+ private function _setJavascriptResponse($body)
61
+ {
62
+ $response = $this->getResponse();
63
 
64
+ $response->setHeader('Content-Type', 'application/javascript', true);
65
+ $response->setBody($body);
66
  }
67
  }
app/code/community/Listrak/Remarketing/controllers/CartController.php CHANGED
@@ -12,46 +12,97 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_CartController extends Mage_Core_Controller_Front_Action
 
 
 
 
16
  {
17
  private $_ltkSession = false;
18
 
 
 
 
 
 
19
  public function indexAction()
20
  {
21
  return $this;
22
  }
23
 
 
 
 
 
 
 
 
 
 
24
  public function reloadAction()
25
  {
26
- $checkout = Mage::getSingleton('checkout/session');
27
- $cust = Mage::getSingleton('customer/session');
28
- $chkQuote = Mage::helper('checkout/cart')->getQuote();
29
-
30
  try {
 
 
 
 
 
 
 
 
 
 
31
  $ltksid = $this->_getLtksid();
32
  if (!$ltksid) {
33
  return $this->_redirectAfterReload();
34
  }
35
 
36
  if ($this->_isUid($ltksid)) {
37
- $ltksidcookie = Mage::getModel('core/cookie')->get('ltksid');
38
- if (!Mage::helper('remarketing')->trackingTablesExist() || (!empty($ltksidcookie) && $ltksidcookie == $ltksid && $chkQuote && $chkQuote->getId())) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  return $this->_redirectAfterReload();
40
  }
41
 
42
  $ltksession = $this->_getSession();
43
- if ($ltksession && $ltksession->getQuoteId() && $cust && $cust->isLoggedIn() && $cust->getId() === $ltksession->getCustomerId()) {
 
 
 
44
  return $this->_redirectAfterReload();
45
  }
46
- }
47
- else {
48
- if (($checkout->getCartLtksid() == $ltksid || $checkout->getMergedLtksid() == $ltksid) && Mage::getSingleton('checkout/cart')->getSummaryQty() > 0) {
 
 
 
 
 
 
 
49
  return $this->_redirectAfterReload();
50
  }
51
  }
52
 
53
  $quote = $this->_getQuote();
54
- if ($quote && $quote->getId() && $quote->getId() != $checkout->getQuoteId() && $quote->getIsActive()) {
 
 
 
55
  if (!$chkQuote) {
56
  $chkQuote = Mage::getModel('sales/quote');
57
  }
@@ -63,52 +114,89 @@ class Listrak_Remarketing_CartController extends Mage_Core_Controller_Front_Acti
63
  $checkout->setMergedLtksid($ltksid);
64
  }
65
  } catch (Exception $ex) {
66
- Mage::getModel("listrak/log")->addException($ex);
 
 
67
  }
68
 
69
  return $this->_redirectAfterReload();
70
  }
71
-
 
 
 
 
 
72
  private function _getLtksid()
73
  {
74
  return $this->getRequest()->getParam('ltksid');
75
  }
76
-
77
- private function _isUid($str) {
78
- return preg_match('/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i', $str);
 
 
 
 
 
 
 
 
 
 
79
  }
80
 
 
 
 
 
 
81
  private function _getSession()
82
  {
83
  if ($this->_ltkSession === false) {
84
  $sid = $this->_getLtksid();
85
 
86
- if(Mage::helper('remarketing')->trackingTablesExist() && $this->_isUid($sid))
87
- {
88
- $ltksession = Mage::getModel("listrak/session")->setSessionId($sid);
89
- $ltksession->getResource()->loadBySessionId($ltksession);
 
 
 
 
 
 
90
 
91
- if ($ltksession->hasQuoteId())
92
- $this->_ltkSession = $ltksession;
 
93
  }
94
 
95
- if ($this->_ltkSession === false)
96
  $this->_ltkSession = null;
 
97
  }
98
 
99
  return $this->_ltkSession;
100
  }
101
 
 
 
 
 
 
102
  private function _getQuote()
103
  {
104
  $session = $this->_getSession();
105
  if ($session) {
106
  $storeId = Mage::app()->getStore()->getStoreId();
107
  $quoteId = $session->getQuoteId();
108
- }
109
- else {
 
 
110
  $sid = $this->_getLtksid();
111
- $qid = Mage::helper('remarketing')->urlDecrypt($sid);
112
 
113
  $parts = explode(' ', $qid, 2);
114
  if (sizeof($parts) > 1) {
@@ -118,19 +206,31 @@ class Listrak_Remarketing_CartController extends Mage_Core_Controller_Front_Acti
118
  }
119
 
120
  if (isset($storeId) && isset($quoteId)) {
121
- $quote = Mage::getModel('sales/quote')->setStoreId($storeId)->load($quoteId);
122
- if ($quote->getEntityId())
 
 
 
 
 
 
123
  return $quote;
 
124
  }
125
 
126
  return null;
127
  }
128
 
 
 
 
 
 
129
  private function _redirectAfterReload()
130
  {
131
- $qs = $this->getRequest()->getParams();
132
- unset($qs["redirectUrl"]);
133
- unset($qs["ltksid"]);
134
 
135
  $url = $this->getRequest()->getParam('redirectUrl');
136
  if (!$url) {
@@ -139,7 +239,10 @@ class Listrak_Remarketing_CartController extends Mage_Core_Controller_Front_Acti
139
 
140
  return $this->_redirect(
141
  $url,
142
- array('_query' => $qs, '_secure' => Mage::app()->getStore()->isCurrentlySecure())
 
 
 
143
  );
144
  }
145
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_CartController
17
+ */
18
+ class Listrak_Remarketing_CartController
19
+ extends Mage_Core_Controller_Front_Action
20
  {
21
  private $_ltkSession = false;
22
 
23
+ /**
24
+ * Index action
25
+ *
26
+ * @return $this
27
+ */
28
  public function indexAction()
29
  {
30
  return $this;
31
  }
32
 
33
+ /**
34
+ * Reload cart action
35
+ *
36
+ * Processes cart reload to give the customer the cart
37
+ * contents that are found in the email the link was clicked
38
+ * from, if the constraints allow
39
+ *
40
+ * @return Listrak_Remarketing_CartController
41
+ */
42
  public function reloadAction()
43
  {
 
 
 
 
44
  try {
45
+ /* @var Mage_Checkout_Model_Session $checkout */
46
+ $checkout = Mage::getSingleton('checkout/session');
47
+
48
+ /* @var Mage_Customer_Model_Session $cust */
49
+ $cust = Mage::getSingleton('customer/session');
50
+
51
+ /* @var Mage_Checkout_Helper_Cart $checkoutHelper */
52
+ $checkoutHelper = Mage::helper('checkout/cart');
53
+ $chkQuote = $checkoutHelper->getQuote();
54
+
55
  $ltksid = $this->_getLtksid();
56
  if (!$ltksid) {
57
  return $this->_redirectAfterReload();
58
  }
59
 
60
  if ($this->_isUid($ltksid)) {
61
+ if ($chkQuote && $chkQuote->getId()) {
62
+ $this->_redirectAfterReload();
63
+ }
64
+
65
+ /* @var Listrak_Remarketing_Helper_Data $helper */
66
+ $helper = Mage::helper('remarketing');
67
+
68
+ if (!$helper->trackingTablesExist()) {
69
+ return $this->_redirectAfterReload();
70
+ }
71
+
72
+ /* @var Mage_Core_Model_Cookie $cookies */
73
+ $cookies = Mage::getModel('core/cookie');
74
+ $ltksidcookie = $cookies->get('ltksid');
75
+
76
+ if (!empty($ltksidcookie) && $ltksidcookie == $ltksid) {
77
  return $this->_redirectAfterReload();
78
  }
79
 
80
  $ltksession = $this->_getSession();
81
+ if ($ltksession && $ltksession->getQuoteId()
82
+ && $cust && $cust->isLoggedIn()
83
+ && $cust->getId() === $ltksession->getCustomerId()
84
+ ) {
85
  return $this->_redirectAfterReload();
86
  }
87
+ } else {
88
+ $cartLtksid = $checkout->getCartLtksid();
89
+ $mergedLtksid = $checkout->getMergedLtksid();
90
+
91
+ /* @var Mage_Checkout_Model_Cart $cart */
92
+ $cart = Mage::getSingleton('checkout/cart');
93
+
94
+ if (($cartLtksid == $ltksid || $mergedLtksid == $ltksid)
95
+ && $cart->getSummaryQty() > 0
96
+ ) {
97
  return $this->_redirectAfterReload();
98
  }
99
  }
100
 
101
  $quote = $this->_getQuote();
102
+ if ($quote && $quote->getId()
103
+ && $quote->getId() != $checkout->getQuoteId()
104
+ && $quote->getIsActive()
105
+ ) {
106
  if (!$chkQuote) {
107
  $chkQuote = Mage::getModel('sales/quote');
108
  }
114
  $checkout->setMergedLtksid($ltksid);
115
  }
116
  } catch (Exception $ex) {
117
+ /* @var Listrak_Remarketing_Model_Log $logger */
118
+ $logger = Mage::getModel("listrak/log");
119
+ $logger->addException($ex);
120
  }
121
 
122
  return $this->_redirectAfterReload();
123
  }
124
+
125
+ /**
126
+ * Retrieves the session ID from the querystring
127
+ *
128
+ * @return string
129
+ */
130
  private function _getLtksid()
131
  {
132
  return $this->getRequest()->getParam('ltksid');
133
  }
134
+
135
+ /**
136
+ * Returns whether session ID is in UUID format
137
+ *
138
+ * @param string $str Session ID
139
+ *
140
+ * @return bool
141
+ */
142
+ private function _isUid($str)
143
+ {
144
+ return preg_match(
145
+ '/^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i', $str
146
+ ) == 1;
147
  }
148
 
149
+ /**
150
+ * Retrieve session model
151
+ *
152
+ * @return Listrak_Remarketing_Model_Session
153
+ */
154
  private function _getSession()
155
  {
156
  if ($this->_ltkSession === false) {
157
  $sid = $this->_getLtksid();
158
 
159
+ /* @var Listrak_Remarketing_Helper_Data $helper */
160
+ $helper = Mage::helper('remarketing');
161
+ if ($helper->trackingTablesExist() && $this->_isUid($sid)) {
162
+ /* @var Listrak_Remarketing_Model_Session */
163
+ $ltkSession = Mage::getModel("listrak/session");
164
+ $ltkSession->setSessionId($sid);
165
+
166
+ /* @var Listrak_Remarketing_Model_Mysql4_Session $ltkResource */
167
+ $ltkResource = $ltkSession->getResource();
168
+ $ltkResource->loadBySessionId($ltkSession);
169
 
170
+ if ($ltkSession->hasQuoteId()) {
171
+ $this->_ltkSession = $ltkSession;
172
+ }
173
  }
174
 
175
+ if ($this->_ltkSession === false) {
176
  $this->_ltkSession = null;
177
+ }
178
  }
179
 
180
  return $this->_ltkSession;
181
  }
182
 
183
+ /**
184
+ * Retrieve Magento quote associated with the request
185
+ *
186
+ * @return Mage_Sales_Model_Quote
187
+ */
188
  private function _getQuote()
189
  {
190
  $session = $this->_getSession();
191
  if ($session) {
192
  $storeId = Mage::app()->getStore()->getStoreId();
193
  $quoteId = $session->getQuoteId();
194
+ } else {
195
+ /* @var Listrak_Remarketing_Helper_Data $helper */
196
+ $helper = Mage::helper('remarketing');
197
+
198
  $sid = $this->_getLtksid();
199
+ $qid = $helper->urlDecrypt($sid);
200
 
201
  $parts = explode(' ', $qid, 2);
202
  if (sizeof($parts) > 1) {
206
  }
207
 
208
  if (isset($storeId) && isset($quoteId)) {
209
+ /* @var Mage_Sales_Model_Quote $quote */
210
+ $quote = Mage::getModel('sales/quote');
211
+
212
+ $quote
213
+ ->setStoreId($storeId)
214
+ ->load($quoteId);
215
+
216
+ if ($quote->getEntityId()) {
217
  return $quote;
218
+ }
219
  }
220
 
221
  return null;
222
  }
223
 
224
+ /**
225
+ * Redirects to checkout with all querystring parameters
226
+ *
227
+ * @return $this
228
+ */
229
  private function _redirectAfterReload()
230
  {
231
+ $query = $this->getRequest()->getParams();
232
+ unset($query["redirectUrl"]);
233
+ unset($query["ltksid"]);
234
 
235
  $url = $this->getRequest()->getParam('redirectUrl');
236
  if (!$url) {
239
 
240
  return $this->_redirect(
241
  $url,
242
+ array(
243
+ '_query' => $query,
244
+ '_secure' => Mage::app()->getStore()->isCurrentlySecure()
245
+ )
246
  );
247
  }
248
  }
app/code/community/Listrak/Remarketing/controllers/ConfigController.php CHANGED
@@ -12,20 +12,36 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_ConfigController extends Mage_Core_Controller_Front_Action
 
 
 
 
16
  {
 
 
 
 
 
 
 
 
17
  public function indexAction()
18
  {
19
- if($this->getRequest()->has('version')) {
20
  echo Mage::getConfig()->getNode('modules')->Listrak_Remarketing->version;
21
- }
22
- else if ($this->getRequest()->has('enableOnescriptTracking')) {
23
  echo $this->_enableOnescriptTracking();
24
  }
25
 
26
  return $this;
27
  }
28
 
 
 
 
 
 
29
  public function registerAction()
30
  {
31
  $reg = Mage::getStoreConfig('remarketing/config/account_created');
@@ -34,40 +50,62 @@ class Listrak_Remarketing_ConfigController extends Mage_Core_Controller_Front_Ac
34
  Mage::getConfig()->saveConfig('remarketing/config/account_created', '1');
35
  Mage::getConfig()->reinit();
36
  }
 
 
37
  }
38
 
 
 
 
 
 
39
  public function checkAction()
40
  {
41
  echo Mage::getStoreConfig('remarketing/config/account_created');
 
 
42
  }
43
 
44
- private function _enableOnescriptTracking() {
45
- if (!Mage::helper('remarketing')->onescriptEnabled())
 
 
 
 
 
 
 
 
 
46
  return "failure: Onescript is disabled";
 
47
 
48
- if (Mage::helper('remarketing')->onescriptReady())
49
  return "success: already enabled";
 
50
 
51
  if (!$this->getRequest()->has('skipValidation')) {
52
- $ch = curl_init();
53
- curl_setopt($ch, CURLOPT_TIMEOUT, 15);
54
- curl_setopt($ch, CURLOPT_ENCODING, "");
55
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
56
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
57
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
58
 
59
- curl_setopt($ch, CURLOPT_URL, Mage::helper('remarketing')->onescriptSrc());
60
- $script = curl_exec($ch);
61
- $error = $script === false ? curl_error($ch) : '';
62
 
63
  // $ch shouldn't be used below this next line
64
- curl_close($ch);
65
 
66
- if ($script === false)
67
  return "failure: Onescript did not load: {$error}";
 
68
 
69
- if (strpos($script, "_ltk.SCA.Load(") === false)
70
  return "failure: Onescript does not load the SCA session ID";
 
71
  }
72
 
73
  Mage::getConfig()->saveConfig('remarketing/config/onescript_ready', '1');
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_ConfigController
17
+ */
18
+ class Listrak_Remarketing_ConfigController
19
+ extends Mage_Core_Controller_Front_Action
20
  {
21
+ /**
22
+ * Index action
23
+ *
24
+ * Returns the extension version, or enables OneScript tracking,
25
+ * when asked to do these things specifically
26
+ *
27
+ * @return $this
28
+ */
29
  public function indexAction()
30
  {
31
+ if ($this->getRequest()->has('version')) {
32
  echo Mage::getConfig()->getNode('modules')->Listrak_Remarketing->version;
33
+ } else if ($this->getRequest()->has('enableOnescriptTracking')) {
 
34
  echo $this->_enableOnescriptTracking();
35
  }
36
 
37
  return $this;
38
  }
39
 
40
+ /**
41
+ * Flags the extension as registered with Listrak
42
+ *
43
+ * @return $this
44
+ */
45
  public function registerAction()
46
  {
47
  $reg = Mage::getStoreConfig('remarketing/config/account_created');
50
  Mage::getConfig()->saveConfig('remarketing/config/account_created', '1');
51
  Mage::getConfig()->reinit();
52
  }
53
+
54
+ return $this;
55
  }
56
 
57
+ /**
58
+ * Returns whether the extension is registered with Listrak
59
+ *
60
+ * @return $this
61
+ */
62
  public function checkAction()
63
  {
64
  echo Mage::getStoreConfig('remarketing/config/account_created');
65
+
66
+ return $this;
67
  }
68
 
69
+ /**
70
+ * Ensure all the pieces are in place to enable OneScript tracking
71
+ *
72
+ * @return string
73
+ */
74
+ private function _enableOnescriptTracking()
75
+ {
76
+ /* @var Listrak_Remarketing_Helper_Data $helper */
77
+ $helper = Mage::helper('remarketing');
78
+
79
+ if (!$helper->onescriptEnabled()) {
80
  return "failure: Onescript is disabled";
81
+ }
82
 
83
+ if ($helper->onescriptReady()) {
84
  return "success: already enabled";
85
+ }
86
 
87
  if (!$this->getRequest()->has('skipValidation')) {
88
+ $request = curl_init();
89
+ curl_setopt($request, CURLOPT_TIMEOUT, 15);
90
+ curl_setopt($request, CURLOPT_ENCODING, "");
91
+ curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
92
+ curl_setopt($request, CURLOPT_SSL_VERIFYPEER, 0);
93
+ curl_setopt($request, CURLOPT_SSL_VERIFYHOST, 0);
94
 
95
+ curl_setopt($request, CURLOPT_URL, $helper->onescriptSrc());
96
+ $script = curl_exec($request);
97
+ $error = $script === false ? curl_error($request) : '';
98
 
99
  // $ch shouldn't be used below this next line
100
+ curl_close($request);
101
 
102
+ if ($script === false) {
103
  return "failure: Onescript did not load: {$error}";
104
+ }
105
 
106
+ if (strpos($script, "_ltk.SCA.Load(") === false) {
107
  return "failure: Onescript does not load the SCA session ID";
108
+ }
109
  }
110
 
111
  Mage::getConfig()->saveConfig('remarketing/config/onescript_ready', '1');
app/code/community/Listrak/Remarketing/controllers/EmailController.php CHANGED
@@ -12,31 +12,60 @@
12
  * @link http://www.listrak.com
13
  */
14
 
15
- class Listrak_Remarketing_EmailController extends Mage_Core_Controller_Front_Action
 
 
 
 
16
  {
 
 
 
 
 
 
 
17
  public function indexAction()
18
  {
19
  try {
20
  $email = $this->getRequest()->getParam('email');
21
  if (Zend_Validate::is($email, 'EmailAddress')) {
22
  $emailcaptureId = $this->getRequest()->getParam('cid');
23
- $session = Mage::getSingleton('listrak/session')->init();
24
- $emailcapture = Mage::getModel('listrak/emailcapture')->load($emailcaptureId);
 
 
 
 
 
25
 
26
  if ($emailcapture->getId()) {
27
- $session->getResource()->insertEmail($session, $email, $emailcaptureId);
 
 
 
28
  $result = array('status' => true);
29
  } else {
30
  $result = array('status' => false);
31
  }
 
32
  header('Content-type: application/json');
33
  echo json_encode($result);
34
  }
35
  } catch (Exception $e) {
36
- Mage::getModel("listrak/log")->addException($e);
 
 
37
  }
38
  }
39
 
 
 
 
 
 
 
 
40
  public function fsidAction()
41
  {
42
  $email = $this->getRequest()->getParam('email');
@@ -45,10 +74,15 @@ class Listrak_Remarketing_EmailController extends Mage_Core_Controller_Front_Act
45
  echo "invalid";
46
  } else {
47
  $emailcaptureId = $this->getRequest()->getParam('cid');
 
 
48
  $session = Mage::getModel('listrak/session');
49
  $session->setSessionId($this->getRequest()->getParam('ltksid'));
50
- $session->getResource()->loadBySessionId($session);
51
- $session->getResource()->insertEmail($session, $email, $emailcaptureId);
 
 
 
52
 
53
  echo json_encode(array('status' => true));
54
  }
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_EmailController
17
+ */
18
+ class Listrak_Remarketing_EmailController
19
+ extends Mage_Core_Controller_Front_Action
20
  {
21
+ /**
22
+ * Index action
23
+ *
24
+ * Stores a captured email address in legacy mode
25
+ *
26
+ * @return void
27
+ */
28
  public function indexAction()
29
  {
30
  try {
31
  $email = $this->getRequest()->getParam('email');
32
  if (Zend_Validate::is($email, 'EmailAddress')) {
33
  $emailcaptureId = $this->getRequest()->getParam('cid');
34
+
35
+ /* @var Listrak_Remarketing_Model_Session $session */
36
+ $session = Mage::getSingleton('listrak/session');
37
+ $session->init();
38
+
39
+ $emailcapture = Mage::getModel('listrak/emailcapture')
40
+ ->load($emailcaptureId);
41
 
42
  if ($emailcapture->getId()) {
43
+ /* @var Listrak_Remarketing_Model_Mysql4_Session $resource */
44
+ $resource = $session->getResource();
45
+ $resource->insertEmail($session, $email, $emailcaptureId);
46
+
47
  $result = array('status' => true);
48
  } else {
49
  $result = array('status' => false);
50
  }
51
+
52
  header('Content-type: application/json');
53
  echo json_encode($result);
54
  }
55
  } catch (Exception $e) {
56
+ /* @var Listrak_Remarketing_Model_Log $logger */
57
+ $logger = Mage::getModel("listrak/log");
58
+ $logger->addException($e);
59
  }
60
  }
61
 
62
+ /**
63
+ * FSID action
64
+ *
65
+ * @deprecated This action is not used anywhere, and its use isn't clear
66
+ *
67
+ * @return void
68
+ */
69
  public function fsidAction()
70
  {
71
  $email = $this->getRequest()->getParam('email');
74
  echo "invalid";
75
  } else {
76
  $emailcaptureId = $this->getRequest()->getParam('cid');
77
+
78
+ /* @var Listrak_Remarketing_Model_Session $session */
79
  $session = Mage::getModel('listrak/session');
80
  $session->setSessionId($this->getRequest()->getParam('ltksid'));
81
+
82
+ /* @var Listrak_Remarketing_Model_Mysql4_Session $sessionResource */
83
+ $sessionResource = $session->getResource();
84
+ $sessionResource->loadBySessionId($session);
85
+ $sessionResource->insertEmail($session, $email, $emailcaptureId);
86
 
87
  echo json_encode(array('status' => true));
88
  }
app/code/community/Listrak/Remarketing/controllers/Remarketing/EmailcaptureController.php ADDED
@@ -0,0 +1,264 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.0.0
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2011 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /**
16
+ * Class Listrak_Remarketing_Remarketing_EmailCaptureController
17
+ */
18
+ class Listrak_Remarketing_Remarketing_EmailCaptureController
19
+ extends Mage_Adminhtml_Controller_Action
20
+ {
21
+ /**
22
+ * Sets up visual context
23
+ *
24
+ * @return $this
25
+ */
26
+ protected function _initAction()
27
+ {
28
+ $this->loadLayout()
29
+ ->_setActiveMenu('remarketing')
30
+ ->_addBreadcrumb(
31
+ Mage::helper('adminhtml')->__('Fields Manager'),
32
+ Mage::helper('adminhtml')->__('Field Manager')
33
+ );
34
+ return $this;
35
+ }
36
+
37
+ /**
38
+ * Requires ACL Permissions
39
+ *
40
+ * @return bool
41
+ */
42
+ protected function _isAllowed()
43
+ {
44
+ /* @var Mage_Admin_Model_Session $session */
45
+ $session = Mage::getSingleton('admin/session');
46
+ return $session->isAllowed('admin/remarketing/emailcapture');
47
+ }
48
+
49
+ /**
50
+ * Index action
51
+ *
52
+ * @return $this
53
+ */
54
+ public function indexAction()
55
+ {
56
+ try {
57
+ $this->_initAction();
58
+
59
+ $this->_addContent(
60
+ $this->getLayout()->createBlock('remarketing/adminhtml_emailcapture')
61
+ );
62
+
63
+ return $this->renderLayout();
64
+ } catch (Exception $e) {
65
+ /* @var Listrak_Remarketing_Model_Log $logger */
66
+ $logger = Mage::getSingleton('listrak/log');
67
+ $logger->addException($e->getMessage());
68
+
69
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
70
+ $adminSession = Mage::getSingleton('adminhtml/session');
71
+ $adminSession->addError($e->getMessage());
72
+ $adminSession->setEmailCaptureData($this->getRequest()->getPost());
73
+
74
+ return $this->_redirect('adminhtml/dashboard');
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Edit action
80
+ *
81
+ * @return $this
82
+ */
83
+ public function editAction()
84
+ {
85
+ try {
86
+ $emailcaptureId = $this->getRequest()->getParam('id');
87
+
88
+ /* @var Listrak_Remarketing_Model_Emailcapture $model */
89
+ $model = Mage::getModel('listrak/emailcapture')
90
+ ->load($emailcaptureId);
91
+
92
+ if ($model->getId() || $emailcaptureId == 0) {
93
+ Mage::register('emailcapture_data', $model);
94
+
95
+ $this->loadLayout();
96
+ $this->_setActiveMenu('emailcapture');
97
+
98
+ $this->_addBreadcrumb(
99
+ Mage::helper('adminhtml')->__('Item Manager'),
100
+ Mage::helper('adminhtml')->__('Item Manager')
101
+ );
102
+ $this->_addBreadcrumb(
103
+ Mage::helper('adminhtml')->__('Item News'),
104
+ Mage::helper('adminhtml')->__('Item News')
105
+ );
106
+
107
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
108
+
109
+ $this
110
+ ->_addContent(
111
+ $this->getLayout()->createBlock(
112
+ 'remarketing/adminhtml_emailcapture_edit'
113
+ )
114
+ )
115
+ ->_addLeft(
116
+ $this->getLayout()->createBlock(
117
+ 'remarketing/adminhtml_emailcapture_edit_tabs'
118
+ )
119
+ );
120
+
121
+ return $this->renderLayout();
122
+ } else {
123
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
124
+ $adminSession = Mage::getSingleton('adminhtml/session');
125
+ $adminSession->addError(
126
+ Mage::helper('remarketing')->__('Item does not exist')
127
+ );
128
+
129
+ return $this->_redirect('*/*/');
130
+ }
131
+ } catch (Exception $e) {
132
+ /* @var Listrak_Remarketing_Model_Log $logger */
133
+ $logger = Mage::getSingleton('listrak/log');
134
+ $logger->addException($e->getMessage());
135
+
136
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
137
+ $adminSession = Mage::getSingleton('adminhtml/session');
138
+ $adminSession->addError($e->getMessage());
139
+ $adminSession->setEmailCaptureData($this->getRequest()->getPost());
140
+
141
+ return $this->_redirect(
142
+ '*/*/index',
143
+ array('id' => $this->getRequest()->getParam('id'))
144
+ );
145
+ }
146
+ }
147
+
148
+ /**
149
+ * New action, redirect to edit
150
+ *
151
+ * @return void
152
+ */
153
+ public function newAction()
154
+ {
155
+ $this->_forward('edit');
156
+ }
157
+
158
+ /**
159
+ * Save action
160
+ *
161
+ * @return $this
162
+ */
163
+ public function saveAction()
164
+ {
165
+ if ($this->getRequest()->getPost()) {
166
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
167
+ $adminSession = Mage::getSingleton('adminhtml/session');
168
+
169
+ try {
170
+ $request = $this->getRequest();
171
+
172
+ /* @var Listrak_Remarketing_Model_Emailcapture $model */
173
+ $model = Mage::getModel('listrak/emailcapture');
174
+
175
+ $model
176
+ ->setId($this->getRequest()->getParam('id'))
177
+ ->setPage($request->getPost('page'))
178
+ ->setFieldId($request->getPost('field_id'));
179
+ $model->save();
180
+
181
+ $adminSession->addSuccess(
182
+ Mage::helper('adminhtml')->__('Item was successfully saved')
183
+ );
184
+ $adminSession->unsEmailCaptureData();
185
+
186
+ return $this->_redirect('*/*/');
187
+ } catch (Exception $e) {
188
+ /* @var Listrak_Remarketing_Model_Log $logger */
189
+ $logger = Mage::getSingleton('listrak/log');
190
+ $logger->addException($e->getMessage());
191
+
192
+ $adminSession->addError($e->getMessage());
193
+ $adminSession->setEmailCaptureData($this->getRequest()->getPost());
194
+
195
+ return $this->_redirect(
196
+ '*/*/edit',
197
+ array('id' => $this->getRequest()->getParam('id'))
198
+ );
199
+ }
200
+ }
201
+
202
+ return $this->_redirect('*/*/');
203
+ }
204
+
205
+ /**
206
+ * Delete action
207
+ *
208
+ * @return $this
209
+ */
210
+ public function deleteAction()
211
+ {
212
+ if ($this->getRequest()->getParam('id') > 0) {
213
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
214
+ $adminSession = Mage::getSingleton('adminhtml/session');
215
+
216
+ try {
217
+ /* @var Listrak_Remarketing_Model_Emailcapture $model */
218
+ $model = Mage::getModel('listrak/emailcapture');
219
+
220
+ $model->setId($this->getRequest()->getParam('id'))
221
+ ->delete();
222
+
223
+ $adminSession->addSuccess(
224
+ Mage::helper('adminhtml')->__('Item was successfully deleted')
225
+ );
226
+
227
+ return $this->_redirect('*/*/');
228
+ } catch (Exception $e) {
229
+ /* @var Listrak_Remarketing_Model_Log $logger */
230
+ $logger = Mage::getSingleton('listrak/log');
231
+ $logger->addException($e->getMessage());
232
+
233
+ $adminSession->addError($e->getMessage());
234
+
235
+ return $this->_redirect(
236
+ '*/*/edit',
237
+ array('id' => $this->getRequest()->getParam('id'))
238
+ );
239
+ }
240
+ }
241
+
242
+ return $this->_redirect('*/*/');
243
+ }
244
+
245
+ /**
246
+ * Grid action
247
+ *
248
+ * Product grid for AJAX request.
249
+ * Sort and filter result for example.
250
+ *
251
+ * @return void
252
+ */
253
+ public function gridAction()
254
+ {
255
+ $this->loadLayout();
256
+ $this->getResponse()->setBody(
257
+ $this->getLayout()
258
+ ->createBlock(
259
+ 'importedit/adminhtml_emailcapture_grid'
260
+ )
261
+ ->toHtml()
262
+ );
263
+ }
264
+ }
app/code/community/Listrak/Remarketing/controllers/Remarketing/ProductattributesController.php ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.0.0
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2011 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /**
16
+ * Class Listrak_Remarketing_Remarketing_ProductAttributesController
17
+ */
18
+ class Listrak_Remarketing_Remarketing_ProductAttributesController
19
+ extends Mage_Adminhtml_Controller_Action
20
+ {
21
+ /**
22
+ * Handles marking the Listrak menu as active
23
+ *
24
+ * @return $this
25
+ */
26
+ protected function _initAction()
27
+ {
28
+ $this->loadLayout()
29
+ ->_setActiveMenu('remarketing');
30
+ return $this;
31
+ }
32
+
33
+ /**
34
+ * Requires ACL Permissions
35
+ *
36
+ * @return bool
37
+ */
38
+ protected function _isAllowed()
39
+ {
40
+ /* @var Mage_Admin_Model_Session $session */
41
+ $session = Mage::getSingleton('admin/session');
42
+ return $session->isAllowed('admin/remarketing/productattributes');
43
+ }
44
+
45
+ /**
46
+ * Index action
47
+ *
48
+ * Show grid of selected attributes for each attribute set
49
+ *
50
+ * @return $this
51
+ */
52
+ public function indexAction()
53
+ {
54
+ $this->_initAction();
55
+
56
+ try {
57
+ /* @var Listrak_Remarketing_Helper_Product_Attribute_Set_Map $helper */
58
+ $helper = Mage::helper('remarketing/product_attribute_set_map');
59
+
60
+ // before we display the data, make sure all the product attribute
61
+ // sets are found in our table - because we can't have null primary keys,
62
+ // something that would happen otherwise
63
+ $helper->ensureDataConsistency();
64
+
65
+ /* @var Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection $sets */
66
+ $sets = Mage::getModel('listrak/product_attribute_set_map')
67
+ ->getCollection();
68
+ $sets->addAttributeSetName()
69
+ ->addAttributeNames()
70
+ ->orderByAttributeSetName();
71
+
72
+ Mage::register('productattribute_sets', $sets);
73
+
74
+ $this->_addContent(
75
+ $this->getLayout()
76
+ ->createBlock('remarketing/adminhtml_productattributes')
77
+ );
78
+
79
+ return $this->renderLayout();
80
+ } catch (Exception $e) {
81
+ /* @var Listrak_Remarketing_Model_Log $logger */
82
+ $logger = Mage::getModel('listrak/log');
83
+ $logger->addException($e);
84
+
85
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
86
+ $adminSession = Mage::getSingleton('adminhtml/session');
87
+ $adminSession->addError($e->getMessage());
88
+
89
+ $this->_redirect(
90
+ '*/*/index',
91
+ array('id' => $this->getRequest()->getParam('id'))
92
+ );
93
+
94
+ return $this;
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Edit action
100
+ *
101
+ * Assembles the edit page
102
+ *
103
+ * @return $this
104
+ */
105
+ public function editAction()
106
+ {
107
+ $this->_initAction();
108
+
109
+ try {
110
+ $mapId = $this->getRequest()->getParam('id');
111
+ $model = Mage::getModel('listrak/product_attribute_set_map')
112
+ ->getCollection()
113
+ ->addAttributeSetName()
114
+ ->addMapIdFilter($mapId)
115
+ ->getFirstItem();
116
+
117
+ Mage::register('productattribute_data', $model);
118
+
119
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
120
+
121
+ $this
122
+ ->_addContent(
123
+ $this->getLayout()
124
+ ->createBlock('remarketing/adminhtml_productattributes_edit')
125
+ )
126
+ ->_addLeft(
127
+ $this->getLayout()
128
+ ->createBlock(
129
+ 'remarketing/adminhtml_productattributes_edit_tabs'
130
+ )
131
+ );
132
+
133
+ return $this->renderLayout();
134
+ } catch (Exception $e) {
135
+ /* @var Listrak_Remarketing_Model_Log $logger */
136
+ $logger = Mage::getModel('listrak/log');
137
+ $logger->addException($e);
138
+
139
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
140
+ $adminSession = Mage::getSingleton('adminhtml/session');
141
+ $adminSession->addError(
142
+ "An unexpected error occurred while attempting to display the form. Please try again."
143
+ );
144
+
145
+ $this->_redirect(
146
+ '*/*/index',
147
+ array('id' => $this->getRequest()->getParam('id'))
148
+ );
149
+
150
+ return $this;
151
+ }
152
+ }
153
+
154
+ /**
155
+ * Save action
156
+ *
157
+ * Save attribute set map selections
158
+ *
159
+ * @return $this
160
+ */
161
+ public function saveAction()
162
+ {
163
+ if ($this->getRequest()->getPost()) {
164
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
165
+ $adminSession = Mage::getSingleton('adminhtml/session');
166
+
167
+ try {
168
+ $mapId = $this->getRequest()->getParam('id');
169
+
170
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $model */
171
+ $model = Mage::getModel('listrak/product_attribute_set_map')
172
+ ->load($mapId);
173
+
174
+ $model->setBrandAttributeCode(
175
+ $this->_nullIfEmpty($this->_getPost('brand_attribute'))
176
+ );
177
+
178
+ $model->setCategoriesSource(
179
+ $this->_getPost('categories_source')
180
+ );
181
+
182
+ $model->setUseConfigCategoriesSource(
183
+ $this->_getPost('use_config_categories_source') ? 1 : 0
184
+ );
185
+
186
+ $model->setCategoryAttributeCode(
187
+ $this->_nullIfEmpty(
188
+ $this->_getPost('categories_category_attribute')
189
+ )
190
+ );
191
+
192
+ $model->setSubcategoryAttributeCode(
193
+ $this->_nullIfEmpty(
194
+ $this->_getPost('categories_subcategory_attribute')
195
+ )
196
+ );
197
+
198
+ $model->save();
199
+
200
+ $adminSession->addSuccess(
201
+ Mage::helper('adminhtml')->__('Item was successfully saved')
202
+ );
203
+
204
+ return $this->_redirect('*/*/');
205
+ } catch (Exception $e) {
206
+ /* @var Listrak_Remarketing_Model_Log $logger */
207
+ $logger = Mage::getModel('listrak/log');
208
+ $logger->addException($e);
209
+
210
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
211
+ $adminSession = Mage::getSingleton('adminhtml/session');
212
+ $adminSession->addError(
213
+ "An unexpected error occurred while attempting to save the settings. Please try again."
214
+ );
215
+
216
+ $this->_redirect(
217
+ '*/*/edit',
218
+ array('id' => $this->getRequest()->getParam('id'))
219
+ );
220
+
221
+ return $this;
222
+ }
223
+ }
224
+
225
+ return $this->_redirect('*/*/');
226
+ }
227
+
228
+ /**
229
+ * Bulk assign action
230
+ *
231
+ * Stores the brand attribute for all attribute sets that have it
232
+ *
233
+ * @return $this
234
+ */
235
+ public function bulkassignAction()
236
+ {
237
+ try {
238
+ $attributeCode = $this->_nullIfEmpty(
239
+ $this->_getPost('bulkassign_attribute')
240
+ );
241
+
242
+ if ($attributeCode) {
243
+ /* @var Listrak_Remarketing_Model_Mysql4_Product_Attribute_Set_Map_Collection $sets */
244
+ $sets = Mage::getModel('listrak/product_attribute_set_map')
245
+ ->getCollection();
246
+
247
+ /* @var Listrak_Remarketing_Model_Product_Attribute_Set_Map $set */
248
+ foreach ($sets as $set) {
249
+ if ($set->getBrandAttributeCode() == null) {
250
+ /* @var Mage_Catalog_Model_Resource_Product_Attribute_Collection $attrCollection */
251
+ $attrCollection = Mage::getResourceModel(
252
+ 'catalog/product_attribute_collection'
253
+ );
254
+
255
+ $attrCount = $attrCollection
256
+ ->addVisibleFilter()
257
+ ->setAttributeSetFilter($set->getAttributeSetId())
258
+ ->setCodeFilter($attributeCode)
259
+ ->count();
260
+
261
+ if ($attrCount > 0) {
262
+ $set->setBrandAttributeCode($attributeCode);
263
+ $set->save();
264
+ }
265
+ }
266
+ }
267
+ }
268
+ } catch (Exception $e) {
269
+ /* @var Listrak_Remarketing_Model_Log $logger */
270
+ $logger = Mage::getModel('listrak/log');
271
+ $logger->addException($e);
272
+
273
+ /* @var Mage_Adminhtml_Model_Session $adminSession */
274
+ $adminSession = Mage::getSingleton('adminhtml/session');
275
+ $adminSession->addError(
276
+ "An unexpected error occurred while assigning the brand attribute."
277
+ );
278
+ }
279
+
280
+ $this->_redirect('*/*/');
281
+ }
282
+
283
+ /**
284
+ * Return null if the argument passed in is empty
285
+ *
286
+ * @param string $str String to nulify
287
+ *
288
+ * @return string
289
+ */
290
+ private function _nullIfEmpty($str)
291
+ {
292
+ if ($str == '') {
293
+ return null;
294
+ }
295
+
296
+ return $str;
297
+ }
298
+
299
+ /**
300
+ * Retrieve posted value
301
+ *
302
+ * @param string $key Key of value
303
+ *
304
+ * @return mixed
305
+ */
306
+ private function _getPost($key)
307
+ {
308
+ return $this->getRequest()->getPost($key, null);
309
+ }
310
+ }
311
+
app/code/community/Listrak/Remarketing/controllers/TroubleshootingController.php CHANGED
@@ -12,9 +12,17 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
 
 
15
  class Listrak_Remarketing_TroubleshootingController
16
  extends Mage_Core_Controller_Front_Action
17
  {
 
 
 
 
 
18
  public function indexAction()
19
  {
20
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /**
16
+ * Class Listrak_Remarketing_TroubleshootingController
17
+ */
18
  class Listrak_Remarketing_TroubleshootingController
19
  extends Mage_Core_Controller_Front_Action
20
  {
21
+ /**
22
+ * Index action
23
+ *
24
+ * @return void
25
+ */
26
  public function indexAction()
27
  {
28
 
app/code/community/Listrak/Remarketing/etc/adminhtml.xml CHANGED
@@ -6,19 +6,19 @@
6
  -->
7
  <config>
8
  <menu>
9
- <remarketing module="remarketing">
10
  <title>Listrak</title>
11
  <sort_order>71</sort_order>
12
  <children>
13
  <emailcapture module="remarketing">
14
  <title>Email Capture</title>
15
  <sort_order>0</sort_order>
16
- <action>remarketing/adminhtml_emailcapture</action>
17
  </emailcapture>
18
  <productattributes module="remarketing">
19
  <title>Product Attributes</title>
20
  <sort_order>1</sort_order>
21
- <action>remarketing/adminhtml_productattributes</action>
22
  </productattributes>
23
  </children>
24
  </remarketing>
6
  -->
7
  <config>
8
  <menu>
9
+ <remarketing translate="title" module="remarketing">
10
  <title>Listrak</title>
11
  <sort_order>71</sort_order>
12
  <children>
13
  <emailcapture module="remarketing">
14
  <title>Email Capture</title>
15
  <sort_order>0</sort_order>
16
+ <action>adminhtml/remarketing_emailcapture/</action>
17
  </emailcapture>
18
  <productattributes module="remarketing">
19
  <title>Product Attributes</title>
20
  <sort_order>1</sort_order>
21
+ <action>adminhtml/remarketing_productattributes/</action>
22
  </productattributes>
23
  </children>
24
  </remarketing>
app/code/community/Listrak/Remarketing/etc/api.xml CHANGED
@@ -1,8 +1,8 @@
1
  <?xml version="1.0"?>
2
- <!--
3
- /**
4
- * Listrak Remarketing Magento Extension Ver. 1.0.0 - Copyright (c) 2011 Listrak, Inc.
5
- */
6
  -->
7
  <config>
8
  <api>
@@ -49,10 +49,6 @@
49
  <title>Purge old data</title>
50
  <method>purge</method>
51
  </purge>
52
- <toggle translate="title" module="listrak_remarketing">
53
- <title>toggle logging</title>
54
- <method>toggle</method>
55
- </toggle>
56
  </methods>
57
  </listrak_remarketing_log>
58
  <listrak_remarketing_order translate="title"
1
  <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Listrak Remarketing Magento Extension Ver. 1.0.0 - Copyright (c) 2011 Listrak, Inc.
5
+ */
6
  -->
7
  <config>
8
  <api>
49
  <title>Purge old data</title>
50
  <method>purge</method>
51
  </purge>
 
 
 
 
52
  </methods>
53
  </listrak_remarketing_log>
54
  <listrak_remarketing_order translate="title"
app/code/community/Listrak/Remarketing/etc/cache.xml CHANGED
@@ -1,4 +1,4 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
  <!--
3
  /**
4
  * Listrak Remarketing Magento Extension Ver. 1.0.0 - Copyright (c) 2011 Listrak, Inc.
1
+ <?xml version="1.0" encoding="utf-8"?>
2
  <!--
3
  /**
4
  * Listrak Remarketing Magento Extension Ver. 1.0.0 - Copyright (c) 2011 Listrak, Inc.
app/code/community/Listrak/Remarketing/etc/config.xml CHANGED
@@ -7,7 +7,7 @@
7
  <config>
8
  <modules>
9
  <Listrak_Remarketing>
10
- <version>1.1.9.2</version>
11
  </Listrak_Remarketing>
12
  </modules>
13
  <frontend>
@@ -176,13 +176,13 @@
176
  </global>
177
  <admin>
178
  <routers>
179
- <remarketing>
180
- <use>admin</use>
181
  <args>
182
- <module>Listrak_Remarketing</module>
183
- <frontName>remarketing</frontName>
 
184
  </args>
185
- </remarketing>
186
  </routers>
187
  </admin>
188
  <adminhtml>
7
  <config>
8
  <modules>
9
  <Listrak_Remarketing>
10
+ <version>1.1.9.4</version>
11
  </Listrak_Remarketing>
12
  </modules>
13
  <frontend>
176
  </global>
177
  <admin>
178
  <routers>
179
+ <adminhtml>
 
180
  <args>
181
+ <modules>
182
+ <Listrak_Remarketing after="Mage_Adminhtml">Listrak_Remarketing</Listrak_Remarketing>
183
+ </modules>
184
  </args>
185
+ </adminhtml>
186
  </routers>
187
  </admin>
188
  <adminhtml>
app/code/community/Listrak/Remarketing/etc/wsdl.xml CHANGED
@@ -118,6 +118,23 @@
118
  </complexType>
119
 
120
  <!-- product -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
  <complexType name="ListrakRemarketingConfigurableAttributeEntity">
122
  <all>
123
  <element name="attribute_name" type="xsd:string" minOccurs="0"/>
@@ -197,6 +214,9 @@
197
  <element name="links"
198
  type="typens:ArrayOfListrakRemarketingProductLinkEntity"
199
  minOccurs="0"/>
 
 
 
200
  <element name="meta3" type="xsd:string" minOccurs="0"/>
201
  <element name="meta4" type="xsd:string" minOccurs="0"/>
202
  <element name="meta5" type="xsd:string" minOccurs="0"/>
@@ -648,14 +668,6 @@
648
  <message name="listrakRemarketingLogPurgeResponse">
649
  <part name="result" type="xsd:string"/>
650
  </message>
651
- <message name="listrakRemarketingLogToggleRequest">
652
- <part name="sessionId" type="xsd:string"/>
653
- <part name="storeId" type="xsd:string"/>
654
- <part name="onOff" type="xsd:string"/>
655
- </message>
656
- <message name="listrakRemarketingLogToggleResponse">
657
- <part name="result" type="xsd:string"/>
658
- </message>
659
  <message name="listrakRemarketingOrderListRequest">
660
  <part name="sessionId" type="xsd:string"/>
661
  <part name="storeId" type="xsd:string"/>
@@ -684,6 +696,7 @@
684
  <part name="storeId" type="xsd:string"/>
685
  <part name="perPage" type="xsd:int"/>
686
  <part name="page" type="xsd:int"/>
 
687
  </message>
688
  <message name="listrakRemarketingProductListResponse">
689
  <part name="result" type="typens:ArrayOfListrakRemarketingProduct"/>
@@ -695,6 +708,7 @@
695
  <part name="endDate" type="xsd:dateTime"/>
696
  <part name="perPage" type="xsd:int"/>
697
  <part name="page" type="xsd:int"/>
 
698
  </message>
699
  <message name="listrakRemarketingProductUpdateListResponse">
700
  <part name="result" type="typens:ArrayOfListrakRemarketingProduct"/>
@@ -824,11 +838,6 @@
824
  <input message="typens:listrakRemarketingLogPurgeRequest"/>
825
  <output message="typens:listrakRemarketingLogPurgeResponse"/>
826
  </operation>
827
- <operation name="listrakRemarketingLogToggle">
828
- <documentation>toggle logging</documentation>
829
- <input message="typens:listrakRemarketingLogToggleRequest"/>
830
- <output message="typens:listrakRemarketingLogToggleResponse"/>
831
- </operation>
832
  <operation name="listrakRemarketingOrderList">
833
  <documentation>Get orders</documentation>
834
  <input message="typens:listrakRemarketingOrderListRequest"/>
@@ -974,17 +983,6 @@
974
  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
975
  </output>
976
  </operation>
977
- <operation name="listrakRemarketingLogToggle">
978
- <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
979
- <input>
980
- <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
981
- encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
982
- </input>
983
- <output>
984
- <soap:body namespace="urn:{{var wsdl.name}}" use="encoded"
985
- encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
986
- </output>
987
- </operation>
988
  <operation name="listrakRemarketingOrderList">
989
  <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
990
  <input>
118
  </complexType>
119
 
120
  <!-- product -->
121
+ <complexType name="ListrakRemarketingAttributeEntity">
122
+ <all>
123
+ <element name="attribute_name" type="xsd:string" minOccurs="0"/>
124
+ <element name="value" type="xsd:string" minOccurs="0"/>
125
+ <element name="values" type="typens:ArrayOfString" minOccurs="0"/>
126
+ <element name="parent_value" type="xsd:string" minOccurs="0"/>
127
+ <element name="parent_values" type="typens:ArrayOfString" minOccurs="0"/>
128
+ </all>
129
+ </complexType>
130
+ <complexType name="ArrayOfListrakRemarketingAttributeEntity">
131
+ <complexContent>
132
+ <restriction base="soapenc:Array">
133
+ <attribute ref="soapenc:arrayType"
134
+ wsdl:arrayType="typens:ListrakRemarketingAttributeEntity[]"/>
135
+ </restriction>
136
+ </complexContent>
137
+ </complexType>
138
  <complexType name="ListrakRemarketingConfigurableAttributeEntity">
139
  <all>
140
  <element name="attribute_name" type="xsd:string" minOccurs="0"/>
214
  <element name="links"
215
  type="typens:ArrayOfListrakRemarketingProductLinkEntity"
216
  minOccurs="0"/>
217
+ <element name="attributes"
218
+ type="typens:ArrayOfListrakRemarketingAttributeEntity"
219
+ minOccurs="0"/>
220
  <element name="meta3" type="xsd:string" minOccurs="0"/>
221
  <element name="meta4" type="xsd:string" minOccurs="0"/>
222
  <element name="meta5" type="xsd:string" minOccurs="0"/>
668
  <message name="listrakRemarketingLogPurgeResponse">
669
  <part name="result" type="xsd:string"/>
670
  </message>
 
 
 
 
 
 
 
 
671
  <message name="listrakRemarketingOrderListRequest">
672
  <part name="sessionId" type="xsd:string"/>
673
  <part name="storeId" type="xsd:string"/>
696
  <part name="storeId" type="xsd:string"/>
697
  <part name="perPage" type="xsd:int"/>
698
  <part name="page" type="xsd:int"/>
699
+ <part name="withAttributes" type="xsd:boolean"/>
700
  </message>
701
  <message name="listrakRemarketingProductListResponse">
702
  <part name="result" type="typens:ArrayOfListrakRemarketingProduct"/>
708
  <part name="endDate" type="xsd:dateTime"/>
709
  <part name="perPage" type="xsd:int"/>
710
  <part name="page" type="xsd:int"/>
711
+ <part name="withAttributes" type="xsd:boolean"/>
712
  </message>
713
  <message name="listrakRemarketingProductUpdateListResponse">
714
  <part name="result" type="typens:ArrayOfListrakRemarketingProduct"/>
838
  <input message="typens:listrakRemarketingLogPurgeRequest"/>
839
  <output message="typens:listrakRemarketingLogPurgeResponse"/>
840
  </operation>
 
 
 
 
 
841
  <operation name="listrakRemarketingOrderList">
842
  <documentation>Get orders</documentation>
843
  <input message="typens:listrakRemarketingOrderListRequest"/>
983
  encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
984
  </output>
985
  </operation>
 
 
 
 
 
 
 
 
 
 
 
986
  <operation name="listrakRemarketingOrderList">
987
  <soap:operation soapAction="urn:{{var wsdl.handler}}Action"/>
988
  <input>
app/code/community/Listrak/Remarketing/etc/wsi.xml CHANGED
@@ -113,6 +113,24 @@
113
  </xsd:complexType>
114
 
115
  <!-- product -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  <xsd:complexType name="ListrakRemarketingConfigurableAttributeEntity">
117
  <xsd:sequence>
118
  <xsd:element name="attribute_name" type="xsd:string"
@@ -191,7 +209,10 @@
191
  minOccurs="0"/>
192
  <xsd:element name="links"
193
  type="typens:ArrayOfListrakRemarketingProductLinkEntity"
194
- minOccurs="0"/>
 
 
 
195
  <xsd:element name="meta3" type="xsd:string" minOccurs="0"/>
196
  <xsd:element name="meta4" type="xsd:string" minOccurs="0"/>
197
  <xsd:element name="meta5" type="xsd:string" minOccurs="0"/>
@@ -724,26 +745,6 @@
724
  </xsd:sequence>
725
  </xsd:complexType>
726
  </xsd:element>
727
- <xsd:element name="listrakRemarketingLogToggleRequestParam">
728
- <xsd:complexType>
729
- <xsd:sequence>
730
- <xsd:element minOccurs="1" maxOccurs="1" name="sessionId"
731
- type="xsd:string"/>
732
- <xsd:element minOccurs="1" maxOccurs="1" name="storeId"
733
- type="xsd:string"/>
734
- <xsd:element minOccurs="1" maxOccurs="1" name="onOff"
735
- type="xsd:string"/>
736
- </xsd:sequence>
737
- </xsd:complexType>
738
- </xsd:element>
739
- <xsd:element name="listrakRemarketingLogToggleResponseParam">
740
- <xsd:complexType>
741
- <xsd:sequence>
742
- <xsd:element minOccurs="1" maxOccurs="1" name="result"
743
- type="xsd:string"/>
744
- </xsd:sequence>
745
- </xsd:complexType>
746
- </xsd:element>
747
  <xsd:element name="listrakRemarketingOrderListRequestParam">
748
  <xsd:complexType>
749
  <xsd:sequence>
@@ -809,6 +810,8 @@
809
  type="xsd:int"/>
810
  <xsd:element minOccurs="1" maxOccurs="1" name="page"
811
  type="xsd:int"/>
 
 
812
  </xsd:sequence>
813
  </xsd:complexType>
814
  </xsd:element>
@@ -829,6 +832,7 @@
829
  <xsd:element minOccurs="1" maxOccurs="1" name="endDate" type="xsd:dateTime"/>
830
  <xsd:element minOccurs="1" maxOccurs="1" name="perPage" type="xsd:int"/>
831
  <xsd:element minOccurs="1" maxOccurs="1" name="page" type="xsd:int"/>
 
832
  </xsd:sequence>
833
  </xsd:complexType>
834
  </xsd:element>
@@ -1120,14 +1124,6 @@
1120
  <wsdl:part name="parameters"
1121
  element="typens:listrakRemarketingLogPurgeResponseParam"/>
1122
  </wsdl:message>
1123
- <wsdl:message name="listrakRemarketingLogToggleRequest">
1124
- <wsdl:part name="parameters"
1125
- element="typens:listrakRemarketingLogToggleRequestParam"/>
1126
- </wsdl:message>
1127
- <wsdl:message name="listrakRemarketingLogToggleResponse">
1128
- <wsdl:part name="parameters"
1129
- element="typens:listrakRemarketingLogToggleResponseParam"/>
1130
- </wsdl:message>
1131
  <wsdl:message name="listrakRemarketingOrderListRequest">
1132
  <wsdl:part name="parameters"
1133
  element="typens:listrakRemarketingOrderListRequestParam"/>
@@ -1282,11 +1278,6 @@
1282
  <wsdl:input message="typens:listrakRemarketingLogPurgeRequest"/>
1283
  <wsdl:output message="typens:listrakRemarketingLogPurgeResponse"/>
1284
  </wsdl:operation>
1285
- <wsdl:operation name="listrakRemarketingLogToggle">
1286
- <wsdl:documentation>toggle logging</wsdl:documentation>
1287
- <wsdl:input message="typens:listrakRemarketingLogToggleRequest"/>
1288
- <wsdl:output message="typens:listrakRemarketingLogToggleResponse"/>
1289
- </wsdl:operation>
1290
  <wsdl:operation name="listrakRemarketingOrderList">
1291
  <wsdl:documentation>Get orders</wsdl:documentation>
1292
  <wsdl:input message="typens:listrakRemarketingOrderListRequest"/>
@@ -1427,15 +1418,6 @@
1427
  <soap:body use="literal"/>
1428
  </wsdl:output>
1429
  </wsdl:operation>
1430
- <wsdl:operation name="listrakRemarketingLogToggle">
1431
- <soap:operation soapAction=""/>
1432
- <wsdl:input>
1433
- <soap:body use="literal"/>
1434
- </wsdl:input>
1435
- <wsdl:output>
1436
- <soap:body use="literal"/>
1437
- </wsdl:output>
1438
- </wsdl:operation>
1439
  <wsdl:operation name="listrakRemarketingOrderList">
1440
  <soap:operation soapAction=""/>
1441
  <wsdl:input>
113
  </xsd:complexType>
114
 
115
  <!-- product -->
116
+ <xsd:complexType name="ListrakRemarketingAttributeEntity">
117
+ <xsd:sequence>
118
+ <xsd:element name="attribute_name" type="xsd:string"
119
+ minOccurs="0"/>
120
+ <xsd:element name="value" type="xsd:string" minOccurs="0"/>
121
+ <xsd:element name="values" type="typens:ArrayOfString" minOccurs="0"/>
122
+ <xsd:element name="parent_value" type="xsd:string" minOccurs="0"/>
123
+ <xsd:element name="parent_values" type="typens:ArrayOfString" minOccurs="0"/>
124
+ </xsd:sequence>
125
+ </xsd:complexType>
126
+ <xsd:complexType
127
+ name="ArrayOfListrakRemarketingAttributeEntity">
128
+ <xsd:sequence>
129
+ <xsd:element minOccurs="0" maxOccurs="unbounded"
130
+ name="complexObjectArray"
131
+ type="typens:ListrakRemarketingAttributeEntity"/>
132
+ </xsd:sequence>
133
+ </xsd:complexType>
134
  <xsd:complexType name="ListrakRemarketingConfigurableAttributeEntity">
135
  <xsd:sequence>
136
  <xsd:element name="attribute_name" type="xsd:string"
209
  minOccurs="0"/>
210
  <xsd:element name="links"
211
  type="typens:ArrayOfListrakRemarketingProductLinkEntity"
212
+ minOccurs="0"/>
213
+ <xsd:element name="attributes"
214
+ type="typens:ArrayOfListrakRemarketingAttributeEntity"
215
+ minOccurs="0"/>
216
  <xsd:element name="meta3" type="xsd:string" minOccurs="0"/>
217
  <xsd:element name="meta4" type="xsd:string" minOccurs="0"/>
218
  <xsd:element name="meta5" type="xsd:string" minOccurs="0"/>
745
  </xsd:sequence>
746
  </xsd:complexType>
747
  </xsd:element>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
748
  <xsd:element name="listrakRemarketingOrderListRequestParam">
749
  <xsd:complexType>
750
  <xsd:sequence>
810
  type="xsd:int"/>
811
  <xsd:element minOccurs="1" maxOccurs="1" name="page"
812
  type="xsd:int"/>
813
+ <xsd:element minOccurs="1" maxOccurs="1" name="withAttributes"
814
+ type="xsd:boolean"/>
815
  </xsd:sequence>
816
  </xsd:complexType>
817
  </xsd:element>
832
  <xsd:element minOccurs="1" maxOccurs="1" name="endDate" type="xsd:dateTime"/>
833
  <xsd:element minOccurs="1" maxOccurs="1" name="perPage" type="xsd:int"/>
834
  <xsd:element minOccurs="1" maxOccurs="1" name="page" type="xsd:int"/>
835
+ <xsd:element minOccurs="1" maxOccurs="1" name="withAttributes" type="xsd:boolean"/>
836
  </xsd:sequence>
837
  </xsd:complexType>
838
  </xsd:element>
1124
  <wsdl:part name="parameters"
1125
  element="typens:listrakRemarketingLogPurgeResponseParam"/>
1126
  </wsdl:message>
 
 
 
 
 
 
 
 
1127
  <wsdl:message name="listrakRemarketingOrderListRequest">
1128
  <wsdl:part name="parameters"
1129
  element="typens:listrakRemarketingOrderListRequestParam"/>
1278
  <wsdl:input message="typens:listrakRemarketingLogPurgeRequest"/>
1279
  <wsdl:output message="typens:listrakRemarketingLogPurgeResponse"/>
1280
  </wsdl:operation>
 
 
 
 
 
1281
  <wsdl:operation name="listrakRemarketingOrderList">
1282
  <wsdl:documentation>Get orders</wsdl:documentation>
1283
  <wsdl:input message="typens:listrakRemarketingOrderListRequest"/>
1418
  <soap:body use="literal"/>
1419
  </wsdl:output>
1420
  </wsdl:operation>
 
 
 
 
 
 
 
 
 
1421
  <wsdl:operation name="listrakRemarketingOrderList">
1422
  <soap:operation soapAction=""/>
1423
  <wsdl:input>
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-install-1.0.0.php CHANGED
@@ -12,6 +12,7 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
@@ -84,12 +85,13 @@ INSERT INTO {$this->getTable('listrak/emailcapture')} (`emailcapture_id` ,`page`
84
  VALUES (NULL , '/checkout/onepage/index', 'login-email');
85
  INSERT INTO {$this->getTable('listrak/emailcapture')} (`emailcapture_id` ,`page` ,`field_id`)
86
  VALUES (NULL , '*', 'newsletter');
87
-
88
  "
89
  );
90
 
91
  try {
92
- Mage::getModel("listrak/log")->addMessage("1.0.0 install");
 
 
93
  } catch (Exception $e) {
94
  }
95
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
85
  VALUES (NULL , '/checkout/onepage/index', 'login-email');
86
  INSERT INTO {$this->getTable('listrak/emailcapture')} (`emailcapture_id` ,`page` ,`field_id`)
87
  VALUES (NULL , '*', 'newsletter');
 
88
  "
89
  );
90
 
91
  try {
92
+ /* @var Listrak_Remarketing_Model_Log $log */
93
+ $log = Mage::getModel("listrak/log");
94
+ $log->addMessage("1.0.0 install");
95
  } catch (Exception $e) {
96
  }
97
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-install-1.1.9.php CHANGED
@@ -12,6 +12,7 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
@@ -79,29 +80,18 @@ VALUES (NULL , '/checkout/onepage/index', 'billing:email')
79
  , (NULL , '/checkout/onepage/index', 'login-email')
80
  , (NULL , '*', 'newsletter')
81
  , (NULL , '*', 'ltkmodal-email');
82
-
83
  "
84
  );
85
 
86
  try {
87
- Mage::getModel("listrak/log")->addMessage("1.1.9 install");
88
- } catch (Exception $e) {
89
- }
90
-
91
- try {
92
- $client = new Varien_Http_Client("http://magento.listrakbi.com/Install.ashx");
93
- $client->setMethod(Varien_Http_Client::POST);
94
- $client->setParameterPost("Listrak Extension Version", "1.1.9");
95
- $client->setParameterPost("Magento Version", Mage::getVersion());
96
- $client->setParameterPost("Install URL", "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
97
- $client->setParameterPost("IP Address", "$_SERVER[SERVER_ADDR]");
98
- $client->request();
99
  } catch (Exception $e) {
100
  }
101
 
102
  $config = Mage::getConfig();
103
  $config->saveConfig('remarketing/config/tracking_tables_deleted', '1');
104
  $config->saveConfig('remarketing/config/onescript_ready', '1');
105
- // the cache is updated automatically, no need to do a full cache clean
106
 
107
  $installer->endSetup();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
80
  , (NULL , '/checkout/onepage/index', 'login-email')
81
  , (NULL , '*', 'newsletter')
82
  , (NULL , '*', 'ltkmodal-email');
 
83
  "
84
  );
85
 
86
  try {
87
+ /* @var Listrak_Remarketing_Model_Log $log */
88
+ $log = Mage::getModel("listrak/log");
89
+ $log->addMessage("1.1.9 install");
 
 
 
 
 
 
 
 
 
90
  } catch (Exception $e) {
91
  }
92
 
93
  $config = Mage::getConfig();
94
  $config->saveConfig('remarketing/config/tracking_tables_deleted', '1');
95
  $config->saveConfig('remarketing/config/onescript_ready', '1');
 
96
 
97
  $installer->endSetup();
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.0.0-1.0.1.php CHANGED
@@ -12,18 +12,23 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
18
  $installer->run(
19
  "
20
- ALTER TABLE {$this->getTable('listrak/session')} ADD `ips` VARCHAR( 1000 ) CHARACTER SET ascii COLLATE ascii_general_ci
 
 
21
  "
22
  );
23
 
24
  try {
25
- Mage::getModel("listrak/log")->addMessage("1.0.0-1.0.1 upgrade");
 
 
26
  } catch (Exception $e) {
27
  }
28
 
29
- $installer->endSetup();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
19
  $installer->run(
20
  "
21
+ ALTER TABLE {$this->getTable('listrak/session')}
22
+ ADD `ips` VARCHAR( 1000 )
23
+ CHARACTER SET ascii COLLATE ascii_general_ci
24
  "
25
  );
26
 
27
  try {
28
+ /* @var Listrak_Remarketing_Model_Log $log */
29
+ $log = Mage::getModel("listrak/log");
30
+ $log->addMessage("1.0.0-1.0.1 upgrade");
31
  } catch (Exception $e) {
32
  }
33
 
34
+ $installer->endSetup();
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.0.8-1.0.9.php CHANGED
@@ -12,6 +12,7 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
@@ -23,8 +24,10 @@ VALUES (NULL , '*', 'ltkmodal-email');
23
  );
24
 
25
  try {
26
- Mage::getModel("listrak/log")->addMessage("1.0.8-1.0.9 upgrade");
 
 
27
  } catch (Exception $e) {
28
  }
29
 
30
- $installer->endSetup();
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
24
  );
25
 
26
  try {
27
+ /* @var Listrak_Remarketing_Model_Log $log */
28
+ $log = Mage::getModel("listrak/log");
29
+ $log->addMessage("1.0.8-1.0.9 upgrade");
30
  } catch (Exception $e) {
31
  }
32
 
33
+ $installer->endSetup();
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.0-1.1.1.php CHANGED
@@ -12,6 +12,7 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
@@ -23,10 +24,10 @@ ADD `pi_id` VARCHAR( 32 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL
23
  );
24
 
25
  try {
26
- Mage::getModel("listrak/log")->addMessage("1.1.0-1.1.1 upgrade");
 
 
27
  } catch (Exception $e) {
28
  }
29
 
30
  $installer->endSetup();
31
-
32
-
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
24
  );
25
 
26
  try {
27
+ /* @var Listrak_Remarketing_Model_Log $log */
28
+ $log = Mage::getModel("listrak/log");
29
+ $log->addMessage("1.1.0-1.1.1 upgrade");
30
  } catch (Exception $e) {
31
  }
32
 
33
  $installer->endSetup();
 
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.3-1.1.4.php CHANGED
@@ -12,6 +12,7 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
@@ -31,9 +32,10 @@ CREATE TABLE {$this->getTable('listrak/review_update')} (
31
  );
32
 
33
  try {
34
- Mage::getModel("listrak/log")->addMessage("1.1.3-1.1.4 upgrade");
 
 
35
  } catch (Exception $e) {
36
  }
37
 
38
  $installer->endSetup();
39
-
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
32
  );
33
 
34
  try {
35
+ /* @var Listrak_Remarketing_Model_Log $log */
36
+ $log = Mage::getModel("listrak/log");
37
+ $log->addMessage("1.1.3-1.1.4 upgrade");
38
  } catch (Exception $e) {
39
  }
40
 
41
  $installer->endSetup();
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.4-1.1.5.php CHANGED
@@ -12,6 +12,7 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
@@ -34,9 +35,10 @@ CREATE TABLE {$this->getTable('listrak/product_attribute_set_map')} (
34
  );
35
 
36
  try {
37
- Mage::getModel("listrak/log")->addMessage("1.1.4-1.1.5 upgrade");
 
 
38
  } catch (Exception $e) {
39
  }
40
 
41
  $installer->endSetup();
42
-
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
35
  );
36
 
37
  try {
38
+ /* @var Listrak_Remarketing_Model_Log $log */
39
+ $log = Mage::getModel("listrak/log");
40
+ $log->addMessage("1.1.4-1.1.5 upgrade");
41
  } catch (Exception $e) {
42
  }
43
 
44
  $installer->endSetup();
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.5-1.1.6.php CHANGED
@@ -12,13 +12,15 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
18
  try {
19
- Mage::getModel("listrak/log")->addMessage("1.1.5-1.1.6 upgrade");
 
 
20
  } catch (Exception $e) {
21
  }
22
 
23
  $installer->endSetup();
24
-
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
19
  try {
20
+ /* @var Listrak_Remarketing_Model_Log $log */
21
+ $log = Mage::getModel("listrak/log");
22
+ $log->addMessage("1.1.5-1.1.6 upgrade");
23
  } catch (Exception $e) {
24
  }
25
 
26
  $installer->endSetup();
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.6-1.1.7.php CHANGED
@@ -12,24 +12,38 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
18
  try {
19
- $installer->run("ALTER TABLE {$this->getTable('listrak/session')} DROP COLUMN `had_items`");
 
 
 
 
 
20
  } catch(Exception $e) {
21
  }
22
 
23
- $installer->run("
 
24
  ALTER TABLE {$this->getTable('listrak/session')}
25
  ADD COLUMN `had_items` boolean NOT NULL DEFAULT 0;
26
 
27
  UPDATE {$this->getTable('listrak/session')} s SET s.`had_items` = 1
28
- WHERE EXISTS (SELECT * FROM {$this->getTable('sales/quote')} q WHERE s.quote_id = q.entity_id AND q.items_count > 0);
29
- ");
 
 
 
 
 
30
 
31
  try {
32
- Mage::getModel("listrak/log")->addMessage("1.1.6-1.1.7 upgrade");
 
 
33
  } catch (Exception $e) {
34
  }
35
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
19
  try {
20
+ $installer->run(
21
+ "
22
+ ALTER TABLE {$this->getTable('listrak/session')}
23
+ DROP COLUMN `had_items`
24
+ "
25
+ );
26
  } catch(Exception $e) {
27
  }
28
 
29
+ $installer->run(
30
+ "
31
  ALTER TABLE {$this->getTable('listrak/session')}
32
  ADD COLUMN `had_items` boolean NOT NULL DEFAULT 0;
33
 
34
  UPDATE {$this->getTable('listrak/session')} s SET s.`had_items` = 1
35
+ WHERE EXISTS (
36
+ SELECT *
37
+ FROM {$this->getTable('sales/quote')} q
38
+ WHERE s.quote_id = q.entity_id AND q.items_count > 0
39
+ );
40
+ "
41
+ );
42
 
43
  try {
44
+ /* @var Listrak_Remarketing_Model_Log $log */
45
+ $log = Mage::getModel("listrak/log");
46
+ $log->addMessage("1.1.6-1.1.7 upgrade");
47
  } catch (Exception $e) {
48
  }
49
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.7-1.1.8.php CHANGED
@@ -12,11 +12,14 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
18
  try {
19
- Mage::getModel("listrak/log")->addMessage("1.1.7-1.1.8 upgrade");
 
 
20
  } catch (Exception $e) {
21
  }
22
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
19
  try {
20
+ /* @var Listrak_Remarketing_Model_Log $log */
21
+ $log = Mage::getModel("listrak/log");
22
+ $log->addMessage("1.1.7-1.1.8 upgrade");
23
  } catch (Exception $e) {
24
  }
25
 
app/code/community/Listrak/Remarketing/sql/listrak_remarketing_setup/mysql4-upgrade-1.1.8-1.1.9.php CHANGED
@@ -12,16 +12,21 @@
12
  * @link http://www.listrak.com
13
  */
14
 
 
15
  $installer = $this;
16
  $installer->startSetup();
17
 
18
- $installer->run("
 
19
  ALTER TABLE {$this->getTable('listrak/session')}
20
  ADD COLUMN `converted` boolean NOT NULL DEFAULT 0;
21
- ");
 
22
 
23
  try {
24
- Mage::getModel("listrak/log")->addMessage("1.1.8-1.1.9 upgrade");
 
 
25
  } catch (Exception $e) {
26
  }
27
 
12
  * @link http://www.listrak.com
13
  */
14
 
15
+ /* @var Mage_Core_Model_Resource_Setup $installer */
16
  $installer = $this;
17
  $installer->startSetup();
18
 
19
+ $installer->run(
20
+ "
21
  ALTER TABLE {$this->getTable('listrak/session')}
22
  ADD COLUMN `converted` boolean NOT NULL DEFAULT 0;
23
+ "
24
+ );
25
 
26
  try {
27
+ /* @var Listrak_Remarketing_Model_Log $log */
28
+ $log = Mage::getModel("listrak/log");
29
+ $log->addMessage("1.1.8-1.1.9 upgrade");
30
  } catch (Exception $e) {
31
  }
32
 
app/design/adminhtml/default/default/template/listrak/remarketing/productattributes.phtml CHANGED
@@ -16,8 +16,10 @@
16
  <div class="content-header">
17
  <table cellspacing="0">
18
  <tr>
19
- <td style="width:50%;"><h3
20
- class="icon-head head-products"><?php echo Mage::helper('remarketing')->__('Product Attributes') ?></h3>
 
 
21
  </td>
22
  <td class="a-right">
23
  <?php echo '' . $this->getButtonsHtml() ?>
@@ -25,9 +27,11 @@
25
  </tr>
26
  </table>
27
  </div>
28
- <?php if (sizeof($this->setsWithoutBrandAttribute()) > 3): ?>
29
- <?php echo '' . $this->getInitBrandsHtml(); ?>
30
- <?php endif; ?>
 
 
31
  <div>
32
  <?php echo '' . $this->getGridHtml() ?>
33
  </div>
16
  <div class="content-header">
17
  <table cellspacing="0">
18
  <tr>
19
+ <td style="width:50%;">
20
+ <h3 class="icon-head head-products"><?php
21
+ echo Mage::helper('remarketing')->__('Product Attributes')
22
+ ?></h3>
23
  </td>
24
  <td class="a-right">
25
  <?php echo '' . $this->getButtonsHtml() ?>
27
  </tr>
28
  </table>
29
  </div>
30
+ <?php
31
+ if (sizeof($this->setsWithoutBrandAttribute()) > 3) {
32
+ echo '' . $this->getInitBrandsHtml();
33
+ }
34
+ ?>
35
  <div>
36
  <?php echo '' . $this->getGridHtml() ?>
37
  </div>
app/design/adminhtml/default/default/template/listrak/remarketing/productattributes/form/categories.phtml CHANGED
@@ -36,36 +36,65 @@
36
  <select id="categories_source" name="categories_source"
37
  class="select">
38
  <option value="default"
39
- <?php if ($this->getCategoriesSource() == 'default'): ?> selected="selected"<?php endif; ?>>
40
- <?php echo Mage::helper('remarketing')->__('Use Catalog Configuration') ?>
 
 
 
 
 
 
 
 
41
  </option>
42
  <option value="attributes"
43
- <?php if ($this->getCategoriesSource() == 'attributes'): ?> selected="selected"<?php endif; ?>>
44
- <?php echo Mage::helper('remarketing')->__('Map from Product Attributes') ?>
 
 
 
 
 
 
 
45
  </option>
46
  </select>
47
  <input type="hidden" id="categories_source_default"
48
- value="<?php echo $this->getConfigCategoriesSource(); ?>"/>
 
49
 
50
- <?php $_checked = $this->getUseConfigCategoriesSource() ? 'checked="checked"' : '' ?>
 
 
 
 
51
  <input type="checkbox" id="categories_use_config_source"
52
  name="use_config_categories_source"
53
  value="1" <?php echo $_checked ?>
54
  onclick="toggleValueElements(this, this.parentNode);"
55
  class="checkbox"/>
56
  <label for="categories_use_config_source" class="normal">
57
- <?php echo Mage::helper('catalog')->__('Use Listrak Configuration Settings') ?>
 
 
 
58
  </label>
59
  </td>
60
  <td class="value scope-label">
61
- <?php echo Mage::helper('remarketing')->__('[GLOBAL]') ?>
 
 
 
62
  </td>
63
  </tr>
64
 
65
  <tr>
66
  <td class="label">
67
  <label for="categories_category_attribute">
68
- <?php echo Mage::helper('remarketing')->__('Category Attribute') ?>
 
 
 
69
  </label>
70
  </td>
71
  <td class="value">
@@ -74,9 +103,15 @@
74
  class="listrak_validate_unique_selection_category_attribute select">
75
  <option value="">- No Category Attribute -</option>
76
  <?php foreach ($this->getAttributeOptions() as $key => $option): ?>
77
- <?php $_selected = ($key == $this->getCategoryAttributeCode()) ? 'selected="selected"' : '' ?>
 
 
 
 
78
  <option
79
- value="<?php echo $key ?>" <?php echo $_selected ?>><?php echo $option ?></option>
 
 
80
  <?php endforeach; ?>
81
  </select>
82
  </td>
@@ -88,7 +123,10 @@
88
  <tr>
89
  <td class="label">
90
  <label for="categories_subcategory_attribute">
91
- <?php echo Mage::helper('catalog')->__('Subcategory Attribute') ?>
 
 
 
92
  </label>
93
  </td>
94
  <td class="value">
@@ -97,9 +135,16 @@
97
  class="listrak_validate_unique_selection_subcategory_attribute select">
98
  <option value="">- No Subcategory Attribute -</option>
99
  <?php foreach ($this->getAttributeOptions() as $key => $option): ?>
100
- <?php $_selected = ($key == $this->getSubcategoryAttributeCode()) ? 'selected="selected"' : '' ?>
 
 
 
 
 
101
  <option
102
- value="<?php echo $key ?>" <?php echo $_selected ?>><?php echo $option ?></option>
 
 
103
  <?php endforeach; ?>
104
  </select>
105
  </td>
@@ -112,7 +157,9 @@
112
  //<![CDATA[
113
  function changeCategoriesSourceOption() {
114
  var configSource = $('categories_use_config_source').checked;
115
- var catSource = configSource ? $('categories_source_default').value : $('categories_source').value;
 
 
116
  var showSelect = catSource == 'attributes';
117
 
118
  var catRow = $('categories_category_attribute').up('tr');
@@ -128,30 +175,51 @@
128
  }
129
  }
130
 
131
- toggleValueElements($('categories_use_config_source'), $('categories_use_config_source').parentNode);
 
 
 
132
 
133
- Event.observe($('categories_source'), 'change', changeCategoriesSourceOption);
134
- Event.observe($('categories_use_config_source'), 'change', changeCategoriesSourceOption);
 
 
 
 
 
 
135
  changeCategoriesSourceOption();
136
 
137
- Validation.add('listrak_validate_unique_selection_category_attribute', 'You may select an attribute only once.', function (attr) {
138
- if (attr == '')
139
- return true;
 
 
 
140
 
141
- // make sure brand doesn't have this value
142
- var brandAttr = $('brand_attribute');
143
- return brandAttr == null || !(brandAttr.selectedIndex > 0 && brandAttr.value == attr);
144
- });
 
 
 
145
 
146
- Validation.add('listrak_validate_unique_selection_subcategory_attribute', 'You may select an attribute only once.', function (attr) {
147
- if (attr == '')
148
- return true;
 
 
 
149
 
150
- // make sure neither brand nor category has the same value
151
- var brandAttr = $('brand_attribute');
152
- var catAttr = $('categories_category_attribute');
153
- return ((brandAttr == null || !(brandAttr.selectedIndex > 0 && brandAttr.value == attr)) && !(catAttr.selectedIndex > 0 && catAttr.value == attr));
154
- });
 
 
 
155
  //]]>
156
  </script>
157
  </fieldset>
36
  <select id="categories_source" name="categories_source"
37
  class="select">
38
  <option value="default"
39
+ <?php
40
+ if ($this->getCategoriesSource() == 'default') {
41
+ echo 'selected="selected"';
42
+ }
43
+ ?>
44
+ >
45
+ <?php
46
+ echo Mage::helper('remarketing')
47
+ ->__('Use Catalog Configuration')
48
+ ?>
49
  </option>
50
  <option value="attributes"
51
+ <?php if ($this->getCategoriesSource() == 'attributes') {
52
+ echo 'selected="selected"';
53
+ }
54
+ ?>
55
+ >
56
+ <?php
57
+ echo Mage::helper('remarketing')
58
+ ->__('Map from Product Attributes')
59
+ ?>
60
  </option>
61
  </select>
62
  <input type="hidden" id="categories_source_default"
63
+ value="<?php echo $this->getConfigCategoriesSource(); ?>"
64
+ />
65
 
66
+ <?php
67
+ $_checked = $this->getUseConfigCategoriesSource()
68
+ ? 'checked="checked"'
69
+ : ''
70
+ ?>
71
  <input type="checkbox" id="categories_use_config_source"
72
  name="use_config_categories_source"
73
  value="1" <?php echo $_checked ?>
74
  onclick="toggleValueElements(this, this.parentNode);"
75
  class="checkbox"/>
76
  <label for="categories_use_config_source" class="normal">
77
+ <?php
78
+ echo Mage::helper('catalog')
79
+ ->__('Use Listrak Configuration Settings')
80
+ ?>
81
  </label>
82
  </td>
83
  <td class="value scope-label">
84
+ <?php
85
+ echo Mage::helper('remarketing')
86
+ ->__('[GLOBAL]')
87
+ ?>
88
  </td>
89
  </tr>
90
 
91
  <tr>
92
  <td class="label">
93
  <label for="categories_category_attribute">
94
+ <?php
95
+ echo Mage::helper('remarketing')
96
+ ->__('Category Attribute')
97
+ ?>
98
  </label>
99
  </td>
100
  <td class="value">
103
  class="listrak_validate_unique_selection_category_attribute select">
104
  <option value="">- No Category Attribute -</option>
105
  <?php foreach ($this->getAttributeOptions() as $key => $option): ?>
106
+ <?php
107
+ $_selected = ($key == $this->getCategoryAttributeCode())
108
+ ? 'selected="selected"'
109
+ : ''
110
+ ?>
111
  <option
112
+ value="<?php echo $key ?>" <?php echo $_selected ?>>
113
+ <?php echo $option ?>
114
+ </option>
115
  <?php endforeach; ?>
116
  </select>
117
  </td>
123
  <tr>
124
  <td class="label">
125
  <label for="categories_subcategory_attribute">
126
+ <?php
127
+ echo Mage::helper('catalog')
128
+ ->__('Subcategory Attribute')
129
+ ?>
130
  </label>
131
  </td>
132
  <td class="value">
135
  class="listrak_validate_unique_selection_subcategory_attribute select">
136
  <option value="">- No Subcategory Attribute -</option>
137
  <?php foreach ($this->getAttributeOptions() as $key => $option): ?>
138
+ <?php
139
+ $_selected
140
+ = ($key == $this->getSubcategoryAttributeCode())
141
+ ? 'selected="selected"'
142
+ : ''
143
+ ?>
144
  <option
145
+ value="<?php echo $key ?>" <?php echo $_selected ?>>
146
+ <?php echo $option ?>
147
+ </option>
148
  <?php endforeach; ?>
149
  </select>
150
  </td>
157
  //<![CDATA[
158
  function changeCategoriesSourceOption() {
159
  var configSource = $('categories_use_config_source').checked;
160
+ var catSource = configSource
161
+ ? $('categories_source_default').value
162
+ : $('categories_source').value;
163
  var showSelect = catSource == 'attributes';
164
 
165
  var catRow = $('categories_category_attribute').up('tr');
175
  }
176
  }
177
 
178
+ toggleValueElements(
179
+ $('categories_use_config_source'),
180
+ $('categories_use_config_source').parentNode
181
+ );
182
 
183
+ Event.observe(
184
+ $('categories_source'), 'change',
185
+ changeCategoriesSourceOption
186
+ );
187
+ Event.observe(
188
+ $('categories_use_config_source'), 'change',
189
+ changeCategoriesSourceOption
190
+ );
191
  changeCategoriesSourceOption();
192
 
193
+ Validation.add(
194
+ 'listrak_validate_unique_selection_category_attribute',
195
+ 'You may select an attribute only once.',
196
+ function (attr) {
197
+ if (attr == '')
198
+ return true;
199
 
200
+ // make sure brand doesn't have this value
201
+ var brandAttr = $('brand_attribute');
202
+ return brandAttr == null || !(
203
+ brandAttr.selectedIndex > 0 && brandAttr.value == attr
204
+ );
205
+ }
206
+ );
207
 
208
+ Validation.add(
209
+ 'listrak_validate_unique_selection_subcategory_attribute',
210
+ 'You may select an attribute only once.',
211
+ function (attr) {
212
+ if (attr == '')
213
+ return true;
214
 
215
+ // make sure neither brand nor category has the same value
216
+ var brandAttr = $('brand_attribute');
217
+ var catAttr = $('categories_category_attribute');
218
+ return ((brandAttr == null
219
+ || !(brandAttr.selectedIndex > 0 && brandAttr.value == attr))
220
+ && !(catAttr.selectedIndex > 0 && catAttr.value == attr));
221
+ }
222
+ );
223
  //]]>
224
  </script>
225
  </fieldset>
app/design/frontend/base/default/layout/remarketing.xml CHANGED
@@ -11,6 +11,9 @@
11
  <block type="remarketing/legacy_ecjs" name="remarketing_ecjs" as="remarketing_ecjs"/>
12
  <block type="remarketing/legacy_modal" name="remarketing_modal" as="remarketing_modal"/>
13
  </block>
 
 
 
14
  <block type="remarketing/require_onescript" name="remarketing_onescript_block" template="remarketing/async_wrapper.phtml">
15
  <block type="remarketing/tracking_click" name="remarketing_click_tracking" />
16
  <block type="remarketing/tracking_email" name="remarketing_email_capture" />
@@ -22,9 +25,6 @@
22
  <block type="remarketing/require_onescript" name="remarketing_onescript" template="remarketing/onescript.phtml">
23
  <action method="setAlwaysRenderTemplate"><val>true</val></action>
24
  </block>
25
- <block type="remarketing/require_onescript" name="remarketing_utils" template="remarketing/utils.phtml">
26
- <action method="setAlwaysRenderTemplate"><val>true</val></action>
27
- </block>
28
  </reference>
29
  </default>
30
 
11
  <block type="remarketing/legacy_ecjs" name="remarketing_ecjs" as="remarketing_ecjs"/>
12
  <block type="remarketing/legacy_modal" name="remarketing_modal" as="remarketing_modal"/>
13
  </block>
14
+ <block type="remarketing/require_onescript" name="remarketing_utils" template="remarketing/utils.phtml">
15
+ <action method="setAlwaysRenderTemplate"><val>true</val></action>
16
+ </block>
17
  <block type="remarketing/require_onescript" name="remarketing_onescript_block" template="remarketing/async_wrapper.phtml">
18
  <block type="remarketing/tracking_click" name="remarketing_click_tracking" />
19
  <block type="remarketing/tracking_email" name="remarketing_email_capture" />
25
  <block type="remarketing/require_onescript" name="remarketing_onescript" template="remarketing/onescript.phtml">
26
  <action method="setAlwaysRenderTemplate"><val>true</val></action>
27
  </block>
 
 
 
28
  </reference>
29
  </default>
30
 
app/design/frontend/base/default/template/remarketing/async_wrapper.phtml CHANGED
@@ -1,8 +1,21 @@
1
- 
2
- <script type="text/javascript">
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  (function(d) { if (document.addEventListener) document.addEventListener('ltkAsyncListener', d);
4
  else {e = document.documentElement; e.ltkAsyncProperty = 0; e.attachEvent('onpropertychange', function (e) {
5
- if (e.propertyName == 'ltkAsyncProperty'){d();}});}})(function() {
6
  <?php echo rtrim($this->getScript()); ?>
7
 
8
  });
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.1.9
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2013 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ ?><script type="text/javascript">
16
  (function(d) { if (document.addEventListener) document.addEventListener('ltkAsyncListener', d);
17
  else {e = document.documentElement; e.ltkAsyncProperty = 0; e.attachEvent('onpropertychange', function (e) {
18
+ if (e.propertyName == 'ltkAsyncProperty' && typeof _ltk !== 'undefined'){d();}});}})(function() {
19
  <?php echo rtrim($this->getScript()); ?>
20
 
21
  });
app/design/frontend/base/default/template/remarketing/onescript.phtml CHANGED
@@ -1,9 +1,25 @@
1
- 
2
- <script type="text/javascript">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  (function (d, s, id, url) {
4
  var js, ljs = d.getElementsByTagName(s)[0];
5
  if (d.getElementById(id)) return;
6
- js = d.createElement(s); js.id = id; js.src = url;
7
  ljs.parentNode.insertBefore(js, ljs);
8
- })(document, 'script', 'ltkSDK', '<?php echo Mage::helper('remarketing')->onescriptSrc() ?>');
9
  </script>
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.1.9
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2013 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /* @var Listrak_Remarketing_Helper_Data $helper */
16
+ $helper = Mage::helper('remarketing');
17
+
18
+ ?><script type="text/javascript">
19
  (function (d, s, id, url) {
20
  var js, ljs = d.getElementsByTagName(s)[0];
21
  if (d.getElementById(id)) return;
22
+ js = d.createElement(s); js.id = id; js.src = url; js.type = "text/javascript";
23
  ljs.parentNode.insertBefore(js, ljs);
24
+ })(document, 'script', 'ltkSDK', '<?php echo $helper->onescriptSrc() ?>');
25
  </script>
app/design/frontend/base/default/template/remarketing/utils.phtml CHANGED
@@ -1,16 +1,42 @@
1
- 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <script type="text/javascript">
3
  Listrak_Remarketing = new function() {
4
  this.updateCart = function() {
5
- <?php if (Mage::helper('remarketing')->scaEnabled()) { ?>
6
- new Ajax.Request('<?php echo Mage::getUrl('remarketing/ajax/cart')?>');
7
- <?php } ?>
 
 
 
8
  };
9
 
10
  this.track = function() {
11
- <?php if (Mage::helper('remarketing')->scaEnabled()) { ?>
12
- new Ajax.Request('<?php echo Mage::getUrl('remarketing/ajax/tracking')?>');
13
- <?php } ?>
 
 
 
14
  };
15
  };
16
  </script>
1
+ <?php
2
+ /**
3
+ * Listrak Remarketing Magento Extension Ver. 1.1.9
4
+ *
5
+ * PHP version 5
6
+ *
7
+ * @category Listrak
8
+ * @package Listrak_Remarketing
9
+ * @author Listrak Magento Team <magento@listrak.com>
10
+ * @copyright 2013 Listrak Inc
11
+ * @license http://s1.listrakbi.com/licenses/magento.txt License For Customer Use of Listrak Software
12
+ * @link http://www.listrak.com
13
+ */
14
+
15
+ /* @var Listrak_Remarketing_Helper_Data $helper */
16
+ $helper = Mage::helper('remarketing');
17
+ $scaEnabled = $helper->scaEnabled();
18
+
19
+ /* @var bool $isSecure */
20
+ $isSecure = Mage::app()->getStore()->isCurrentlySecure();
21
+ ?>
22
  <script type="text/javascript">
23
  Listrak_Remarketing = new function() {
24
  this.updateCart = function() {
25
+ <?php
26
+ if ($scaEnabled) {
27
+ $updateUrl = Mage::getUrl('remarketing/ajax/cart', array('_forced_secure' => $isSecure));
28
+ echo "new Ajax.Request('{$updateUrl}');";
29
+ }
30
+ ?>
31
  };
32
 
33
  this.track = function() {
34
+ <?php
35
+ if ($scaEnabled) {
36
+ $trackUrl = Mage::getUrl('remarketing/ajax/track', array('_forced_secure' => $isSecure));
37
+ echo "new Ajax.Request('{$trackUrl}');";
38
+ }
39
+ ?>
40
  };
41
  };
42
  </script>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Listrak_Remarketing</name>
4
- <version>1.1.9.2</version>
5
  <stability>stable</stability>
6
  <license uri="http://s1.listrakbi.com/licenses/magento.txt">Listrak EULA</license>
7
  <channel>community</channel>
@@ -46,14 +46,11 @@ To make sure your marketing list is always current, all newsletter subscribers a
46
  &#xD;
47
  &lt;p&gt;&lt;b&gt;About Listrak&lt;/b&gt;&lt;br /&gt;&#xD;
48
  Listrak works with online retailers to maximize marketing ROI by helping them reach optimal engagement with their customers. Our focus is on prompting dialog and interaction through email and mobile marketing to increase customer lifetime value.&lt;/p&gt;</description>
49
- <notes>Browse tracking functionality.&#xD;
50
- Session tracking improvements.&#xD;
51
- Catalog retrieval improvements.&#xD;
52
- Cart recreate improvements.</notes>
53
  <authors><author><name>Listrak</name><user>auto-converted</user><email>magento@listrak.com</email></author></authors>
54
- <date>2015-03-30</date>
55
- <time>14:14:14</time>
56
- <contents><target name="magecommunity"><dir name="Listrak"><dir name="Remarketing"><dir name="Block"><dir name="Adminhtml"><dir name="Emailcapture"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="03de7fb256e7b7acd1e149e46bc8a75a"/></dir><file name="Form.php" hash="ec3e084666f6625236b888f679ee05ae"/><file name="Tabs.php" hash="5d3f873074ebb7a29d109784c10dbfd3"/></dir><file name="Edit.php" hash="b60f716de292575504649b46224d6d09"/><file name="Grid.php" hash="b904f2c149c904244b34444cae38eb88"/></dir><dir name="Productattributes"><dir name="Edit"><dir name="Tab"><dir name="Form"><file name="Brand.php" hash="74c68b4b8ea1c1e785257aa4bbeaab09"/><file name="Categories.php" hash="529c82cc102872e4f57570c68e0adf87"/></dir></dir><file name="Form.php" hash="56f7c630820641cb8f12d82e91aea1bf"/><file name="Tabs.php" hash="a735bcf5bd86a67fae4efda97f0fa41a"/></dir><dir name="Init"><dir name="Brands"><file name="Form.php" hash="e83a9e79275f50b0cb3df8da597ad4e2"/></dir><file name="Brands.php" hash="8bf63ec8fdda9cf9bc1b3a9e493c62e8"/></dir><file name="Edit.php" hash="e774d47debad3a91ee06695fc4bd2c26"/><file name="Grid.php" hash="a464e4f72f82f61a80510e19c09b98a0"/></dir><file name="Emailcapture.php" hash="fa12181d06b55d08e7534129ecd4f371"/><file name="Notifications.php" hash="d1d5f8c95716290d60583c4c72ada6f4"/><file name="Productattributes.php" hash="3b27f937512e1d2c01e6786cbc8ceb8f"/></dir><dir name="Conversion"><file name="Abstract.php" hash="91bab6ad58c72008a6c2e1beb8713aa5"/><file name="Cart.php" hash="2c3ccc919286f473c2144a58a9c8bb83"/><file name="Fingerprint.php" hash="63bd2fb001809b886cd21fb1439fa416"/><file name="Order.php" hash="e3fd1e2bdaa8fb58e0727cf5f542eadc"/></dir><dir name="Legacy"><file name="Ecjs.php" hash="1c3e2e0b3a20811a84e5ac0532a799d8"/><file name="Modal.php" hash="c38f33f50aa073f1d0cc07b5110a68ac"/></dir><dir name="Require"><file name="Activity.php" hash="57938fe6fa15a200ec603462945a4ff2"/><file name="Legacy.php" hash="fb0aef1f56f9c11d55e052d562c786f3"/><file name="Onescript.php" hash="29442f56f7fd82835c3addab236c1e1c"/><file name="Sca.php" hash="1049bfb1b2f1e0b155f1adb561a72be6"/></dir><dir name="Tracking"><file name="Activity.php" hash="3c8d7d1dea5ef7e1a418f952982c291d"/><file name="Click.php" hash="9420ff3ba4367164908adc2c803e523e"/><file name="Email.php" hash="7b62ee2823e71cf0002a972576be0a13"/><file name="Sca.php" hash="ec56b127dbe85a34e2966fcc766562cb"/></dir><file name="Base.php" hash="d2adc523e1cf1c0c598cbad958bd236a"/></dir><dir name="Helper"><dir name="Product"><dir name="Attribute"><dir name="Set"><file name="Map.php" hash="74587e809ea245eaab053cab5b4c8ac5"/></dir></dir></dir><dir name="Review"><file name="Update.php" hash="2b43132557868702c9b0826925da428c"/></dir><file name="Data.php" hash="3508288a3a83ef2af456c8c73917ee56"/><file name="Product.php" hash="9b6d290870b27ccd6af8800519659ec5"/></dir><dir name="Model"><dir name="Abandonedcart"><dir name="Api"><file name="V2.php" hash="00ffd794e4b681008b648b708cb92150"/></dir><file name="Api.php" hash="d14a38e07929230a034cf9ce6d55a1fc"/></dir><dir name="Apiextension"><dir name="Api"><file name="V2.php" hash="f4c04e0182f109bf142fcdc029314f3c"/></dir><file name="Api.php" hash="00c6758776587be1707651cede44b278"/></dir><dir name="Cache"><file name="Sca.php" hash="8da2873971aae723872ce5138c7a4838"/></dir><dir name="Click"><dir name="Api"><file name="V2.php" hash="46247b357cbe65be78625c21f78af51f"/></dir><file name="Api.php" hash="f91354214b431e1f76cdc91daeb02c4c"/></dir><dir name="Log"><dir name="Api"><file name="V2.php" hash="b6c152d27d85b2db1e0ce24b56d38e9f"/></dir><file name="Api.php" hash="8828beb6ef4a1217aa7c4d476819663c"/></dir><dir name="Mysql4"><dir name="Abandonedcart"><file name="Collection.php" hash="d54243b443d4569b666f26d4af4b6c21"/></dir><dir name="Click"><file name="Collection.php" hash="4e426d50bd9039ec6a54d3bcbe56fbb0"/></dir><dir name="Emailcapture"><file name="Collection.php" hash="02be573207405024553d363cd1f51aa0"/></dir><dir name="Log"><file name="Collection.php" hash="9f0597af33ffd65e09ba9fce51f5f0ff"/></dir><dir name="Product"><dir name="Attribute"><dir name="Set"><dir name="Map"><file name="Collection.php" hash="80b7748fec09b135cee605d07e4c62e5"/></dir><file name="Map.php" hash="2e146d91dc174dc9bd8ce96b5fc52483"/></dir></dir></dir><dir name="Review"><dir name="Update"><file name="Collection.php" hash="abbd1594c2ff6218998beaa9411d244f"/></dir><file name="Update.php" hash="19ede3bb0dd78a7f2cac10ae466c1bc0"/></dir><dir name="Session"><file name="Collection.php" hash="93fd53dbdc2a8c5ddb34ea1c0390865b"/></dir><dir name="Subscriberupdate"><file name="Collection.php" hash="a348915e86b7400bdb2f9fb9910f3b45"/></dir><file name="Abandonedcart.php" hash="1d51e3f43c055255d37b8395357f0764"/><file name="Apiextension.php" hash="9f1ebf124573901dd15f6101f3a39074"/><file name="Click.php" hash="1b4f106a299611574dbfa958dfc96c6c"/><file name="Emailcapture.php" hash="be122a427584d13e6469ddafc01e55bb"/><file name="Log.php" hash="4729dc9fdf2a812a9243c82cf3a0659a"/><file name="Session.php" hash="a7d1ea065a9042d9aab466a981a3554b"/><file name="Subscriberupdate.php" hash="6eb60180f5a84a05c8b1396f649dcd03"/></dir><dir name="Product"><dir name="Api"><file name="V2.php" hash="86a66a07f3e20d744f64c56d133cfbb9"/></dir><dir name="Attribute"><dir name="Set"><file name="Map.php" hash="44794eb84ab1f1aa1b6b1fd6d2a45ced"/></dir></dir><dir name="Category"><file name="Source.php" hash="49bb519e75521ad4f5273f1a8306fc0a"/></dir><dir name="Purchasable"><file name="Visibility.php" hash="f0cb0ec0411347f3b777592eaa5f6181"/></dir><file name="Api.php" hash="74ddc3ecb4af61280f9516e3be4c1556"/><file name="Attributes.php" hash="1d10e1b56d7dfa4726e25888d36f8611"/></dir><dir name="Review"><dir name="Update"><dir name="Api"><file name="V2.php" hash="37a0b841ea0b575526ef04c2c63fc6fe"/></dir><file name="Api.php" hash="6fe750f995c8145aaa6072872a6e5839"/></dir><file name="Update.php" hash="d2bb50a577d4dbd739936e6478e2603b"/></dir><file name="Abandonedcart.php" hash="d731df1be52538c4a08ee3486049430f"/><file name="Apiextension.php" hash="3967cefbb8bb4bffb1c9d6660107fe04"/><file name="Click.php" hash="047b2b5543071a37d8535e067b4a73ba"/><file name="Emailcapture.php" hash="0f733cbfd06586daef5c2f7bb17cb697"/><file name="Log.php" hash="554d1e99cc1c976bfed850c929b122ab"/><file name="Observer.php" hash="2bb3d975cc70ae3148f6a3634d57bd6c"/><file name="Session.php" hash="3e6261f9cd95a6523cb44e56f4c92cfd"/><file name="Subscriber.php" hash="eb8b7f41801140579b7f58f63a66c854"/><file name="Subscriberupdate.php" hash="b5d8a6e7e0e2e803f72c8a28bff4b098"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="AbandonedcartreportController.php" hash="30190c05d46c027a095fc5b88a4473ba"/><file name="EmailcaptureController.php" hash="8facd1046802dd5a95148c994dea008d"/><file name="ProductattributesController.php" hash="33df5581af7a1d6cb75b4b390d8e412c"/></dir><file name="AjaxController.php" hash="76a4e0bb99c7a84172f826fe5bb92a05"/><file name="CartController.php" hash="48b83f136e93ed9d0adc57bbc2c7fd59"/><file name="ConfigController.php" hash="f57183b58036815da7eaa557fcef944c"/><file name="EmailController.php" hash="981a5f70785b332cd5d0823fa34254d0"/><file name="TroubleshootingController.php" hash="cf13b1319d5eca6c86e0f0f6c863678f"/></dir><dir name="etc"><file name="adminhtml.xml" hash="cdea6da6f2e806cbaa85259b241a92b4"/><file name="api.xml" hash="3d4f2b7486c21f4e8a10316d1e167bf1"/><file name="cache.xml" hash="54e65d484807b3ca62ab1efdada4ced2"/><file name="config.xml" hash="b9ca07edf42347f8a94427434586f5e9"/><file name="system.xml" hash="50af45b64a41b740dfc92581d0948766"/><file name="wsdl.xml" hash="844a40c62ac578ccf86b3245b3c5c6be"/><file name="wsi.xml" hash="3f45fdac125d4caba1b6aa15c1339f74"/></dir><dir name="sql"><dir name="listrak_remarketing_setup"><file name="mysql4-install-1.0.0.php" hash="b717cc55a937eb1241efe38a38b3dd1c"/><file name="mysql4-install-1.1.9.php" hash="846ddc4cbcc4ff54e42a8b28cbe883a6"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="adcb8ac59dcb86c44aeb4d79a5529e31"/><file name="mysql4-upgrade-1.0.8-1.0.9.php" hash="de98367400f3d5d77b3a4622cb87275d"/><file name="mysql4-upgrade-1.1.0-1.1.1.php" hash="1962c9ca9337a8ab6e97f0bdbc5df088"/><file name="mysql4-upgrade-1.1.3-1.1.4.php" hash="1a3d6deb0a4358f4b2593c54360e1cd8"/><file name="mysql4-upgrade-1.1.4-1.1.5.php" hash="f4f265d29d27d1486a80d1d5f820d441"/><file name="mysql4-upgrade-1.1.5-1.1.6.php" hash="eaa1104f5a74d3c55fdd01c8cef5374f"/><file name="mysql4-upgrade-1.1.6-1.1.7.php" hash="97a23595bab47c7cd6af9afc45edea17"/><file name="mysql4-upgrade-1.1.7-1.1.8.php" hash="1f402652d7715a9e7db8c264d4c67c46"/><file name="mysql4-upgrade-1.1.8-1.1.9.php" hash="11dbb40a1ceaf0ff64d1a778d03114cc"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="remarketing.xml" hash="f2442f57ca7aada33af17ef8fe763dff"/></dir><dir name="template"><dir name="remarketing"><file name="async_wrapper.phtml" hash="131528d3e0bc654416a0fba97d866704"/><file name="onescript.phtml" hash="f47365d62611a25fb9edab4e537bf3c4"/><file name="utils.phtml" hash="6c1c2312acf13cc9ccd16348ff71c2b7"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="remarketing.xml" hash="d8065af171ca34e334f29d506217cd65"/></dir><dir name="template"><dir name="listrak"><dir name="remarketing"><dir name="productattributes"><dir name="form"><file name="categories.phtml" hash="dc4313b519c4981538d524749c955789"/><file name="initbrands.phtml" hash="64eb3bd86b40fa6d9fcdf451cca56b34"/></dir></dir><file name="productattributes.phtml" hash="fad54db289cbc4fe113419ccfb9d3ab0"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Listrak_Remarketing.xml" hash="63082a312f4668561da45ccd445a862b"/></dir></target></contents>
57
  <compatible/>
58
  <dependencies/>
59
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Listrak_Remarketing</name>
4
+ <version>1.1.9.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://s1.listrakbi.com/licenses/magento.txt">Listrak EULA</license>
7
  <channel>community</channel>
46
  &#xD;
47
  &lt;p&gt;&lt;b&gt;About Listrak&lt;/b&gt;&lt;br /&gt;&#xD;
48
  Listrak works with online retailers to maximize marketing ROI by helping them reach optimal engagement with their customers. Our focus is on prompting dialog and interaction through email and mobile marketing to increase customer lifetime value.&lt;/p&gt;</description>
49
+ <notes>Product API improvements</notes>
 
 
 
50
  <authors><author><name>Listrak</name><user>auto-converted</user><email>magento@listrak.com</email></author></authors>
51
+ <date>2015-11-04</date>
52
+ <time>19:15:59</time>
53
+ <contents><target name="magecommunity"><dir name="Listrak"><dir name="Remarketing"><dir name="Block"><dir name="Adminhtml"><dir name="Emailcapture"><dir name="Edit"><dir name="Tab"><file name="Form.php" hash="4b7fc006028ffb6a40df036251f4a466"/></dir><file name="Form.php" hash="fe59d021e009b6582f66b30c1d72d271"/><file name="Tabs.php" hash="18f64d32e33ec092607a8bc8ab8dde42"/></dir><file name="Edit.php" hash="33c259a85ca1e51d16846527b3145580"/><file name="Grid.php" hash="d7f492b26f46ee21aa708c8812c596e6"/></dir><dir name="Productattributes"><dir name="Edit"><dir name="Tab"><dir name="Form"><file name="Brand.php" hash="e666a45cd60aae1d37a0240b97cd51ea"/><file name="Categories.php" hash="180558517932501f8538a738bd8f2c10"/></dir></dir><file name="Form.php" hash="a4776c4adcf8bce5969318a05e3692e5"/><file name="Tabs.php" hash="3919921c3dc15de0ceb22640d4d07fe1"/></dir><dir name="Init"><dir name="Brands"><file name="Form.php" hash="62c96540bd5ea3c64f1c3eb4b4118c26"/></dir><file name="Brands.php" hash="ee8a43d4221feeb9e70e4b39fd927e89"/></dir><file name="Edit.php" hash="46f8d9209680340b07c2536b2e640cb9"/><file name="Grid.php" hash="bd340f7bd23ac2ec5f4d44b04a3a106a"/></dir><file name="Emailcapture.php" hash="990d7597b42f8888dbbea37d6398aba6"/><file name="Notifications.php" hash="956cc8e53866b00405976d0ca3de0be3"/><file name="Productattributes.php" hash="f605df88b6589f57fe375091285c8f5f"/></dir><dir name="Conversion"><file name="Abstract.php" hash="8c4d5ce3775afa48082c0e904a23c890"/><file name="Cart.php" hash="8919929cbfadd2d6be73235bb75fb86c"/><file name="Fingerprint.php" hash="4276a34be1452b591e56c24f93d557f4"/><file name="Order.php" hash="b33c1425bc84a975df58aec0e907ef49"/></dir><dir name="Legacy"><file name="Ecjs.php" hash="84ef445f27b29bbcdd3fc2776f0252ce"/><file name="Modal.php" hash="6d880f77547fb1d0d4da36d4da6136bb"/></dir><dir name="Require"><file name="Activity.php" hash="66155793d621b112ab6f897f1a0d67de"/><file name="Legacy.php" hash="c26f5187a18c35551aeddeb71bf9155c"/><file name="Onescript.php" hash="082f2f148a23655b33a67b9bf1cc24dc"/><file name="Sca.php" hash="c1c501b706c53ce101be25711477e586"/></dir><dir name="Tracking"><file name="Activity.php" hash="4927f310eae79c3922c3876596ee8f14"/><file name="Click.php" hash="8396fdfcd932b8ac8fcb33325e7063c5"/><file name="Email.php" hash="236b0fdc7729a5950d4f55cb10624df1"/><file name="Sca.php" hash="c30f9e69a52dd9059a81ff1ac3fb3d75"/></dir><file name="Base.php" hash="04b804fd6da705242064005e5c84d315"/></dir><dir name="Helper"><dir name="Product"><dir name="Attribute"><dir name="Set"><file name="Map.php" hash="d55cadfab5d9ad38880fa9fd57ea8dbf"/></dir></dir></dir><dir name="Review"><file name="Update.php" hash="8883e702a5871426e768a4d6c8afd12e"/></dir><file name="Data.php" hash="a20ca84a6fa92372717130de24f9d77a"/><file name="Product.php" hash="9a70964e1564f9195e4148a035f57efc"/></dir><dir name="Model"><dir name="Abandonedcart"><dir name="Api"><file name="V2.php" hash="9f6b4dcf6dc3e5786563b874bfe5a628"/></dir><file name="Api.php" hash="34ae38fcf33358a479c76833f87b82f5"/></dir><dir name="Apiextension"><dir name="Api"><file name="V2.php" hash="4c7b906f43dada5f20b4df23fe6fdc46"/></dir><file name="Api.php" hash="79639cd57404da8b00c5e45b89e37404"/></dir><dir name="Cache"><file name="Sca.php" hash="2a2a58d8b4d601ede6df88259373b79d"/></dir><dir name="Click"><dir name="Api"><file name="V2.php" hash="223e139fabb121fc7200f4709f133f46"/></dir><file name="Api.php" hash="ac48e5676e3bf8fb4802cece40ad9e04"/></dir><dir name="Log"><dir name="Api"><file name="V2.php" hash="9263c4ac205a8fc1e32e5d37d21f0daf"/></dir><file name="Api.php" hash="28bb96796dc0bcd9d954c8a032a9e67a"/></dir><dir name="Mysql4"><dir name="Abandonedcart"><file name="Collection.php" hash="d1882ca4499bc5c56d93a171865293bd"/></dir><dir name="Click"><file name="Collection.php" hash="286c6eb5d0aca628823c041761494301"/></dir><dir name="Emailcapture"><file name="Collection.php" hash="d96f0744722f18064a855e0fdc294415"/></dir><dir name="Log"><file name="Collection.php" hash="e5bc090bf9605dfe93d4d1962e66ca5f"/></dir><dir name="Product"><dir name="Attribute"><dir name="Set"><dir name="Map"><file name="Collection.php" hash="34b9084c9c60746ff4cf4712e6b248e1"/></dir><file name="Map.php" hash="78db3f6778a93c9d82b19de660d72db4"/></dir></dir><file name="Collection.php" hash="f39792ca3a30c6cbea5294cedd7cb052"/></dir><dir name="Review"><dir name="Update"><file name="Collection.php" hash="148b67805880086583ecb3f7ae0f4a30"/></dir><file name="Update.php" hash="e894546d22e4da32ecd8cbfa5f57c8ef"/></dir><dir name="Session"><file name="Collection.php" hash="6acf9de01b85cdc1dbbb3bfb1646244a"/></dir><dir name="Subscriberupdate"><file name="Collection.php" hash="77331688f90271c757b5a7d319b9d351"/></dir><file name="Abandonedcart.php" hash="b1f1eb28df646de5f1678967b1f0b183"/><file name="Apiextension.php" hash="0a00057cd50cd462ce3518d5a9519757"/><file name="Click.php" hash="92558ac0fa543da96d0a16ed9f03f333"/><file name="Emailcapture.php" hash="7fb60c5b61155e42674ecb05f4be7de8"/><file name="Log.php" hash="efa5dac7cb3610debf45d10484a80caf"/><file name="Product.php" hash="44e13acab31b9e6cf80f0de7c8472b53"/><file name="Session.php" hash="cdd6a9d97ffbf629002b17a5a8677edf"/><file name="Subscriberupdate.php" hash="b813c47bef3889d2ad2a2c5629722798"/></dir><dir name="Product"><dir name="Api"><file name="V2.php" hash="285034adde0f68c63c084ab480307ec8"/></dir><dir name="Attribute"><dir name="Set"><file name="Map.php" hash="4887562fd27e4c7be060f44f6d603c44"/></dir></dir><dir name="Category"><file name="Source.php" hash="ff8e5347be75728a5325ed628c347d72"/></dir><dir name="Purchasable"><file name="Visibility.php" hash="625efae1b17b73aaf05ed79eaa793360"/></dir><file name="Api.php" hash="0bcbb06a0f0530b592f0629eccb5e9d7"/><file name="Attributes.php" hash="460420f1f7cfb10c411b01d7032c1624"/></dir><dir name="Review"><dir name="Update"><dir name="Api"><file name="V2.php" hash="70d0c2f9811f9f73befe7c2d1f8c1363"/></dir><file name="Api.php" hash="dd2185bf79bde1fa221d280f91aa305b"/></dir><file name="Update.php" hash="ad967b1675f15d2ee6f18bf77239b3a2"/></dir><file name="Abandonedcart.php" hash="73b64fa8e765cae40f2639e0c097f952"/><file name="Apiextension.php" hash="40589bd7b1676e2223a4bf87647679c8"/><file name="Click.php" hash="f0bff55e889b18c0c09f75efd7e6aba4"/><file name="Emailcapture.php" hash="b292bd6eb233454f67ad99d4a0100dc5"/><file name="Log.php" hash="81a87ea8df5b64b57029884694788d9d"/><file name="Observer.php" hash="0b8eafb52fb2c16878614ba18568ab19"/><file name="Product.php" hash="bcb70ef1a133904dc926edc27aa1c96f"/><file name="Session.php" hash="4550d5ca3320827d1381c5b0e3aeb05b"/><file name="Subscriber.php" hash="95fce814868be28873bbb06026a0a74c"/><file name="Subscriberupdate.php" hash="9af7dbc06a76ade1b7add599b53df2dd"/></dir><dir name="controllers"><dir name="Remarketing"><file name="EmailcaptureController.php" hash="2fe6b9cb036e77b482ace04be0c7dd7b"/><file name="ProductattributesController.php" hash="4289f58110e9ac4096f791964319a698"/></dir><file name="AjaxController.php" hash="cb87a8df81ad6691bffe91dc315103a9"/><file name="CartController.php" hash="739fc692206d7ed9aafe8dcedeb1dc7d"/><file name="ConfigController.php" hash="d5d86c3c1383bfa2955e3c62594cc421"/><file name="EmailController.php" hash="bd0d7fb1717c58120cf4f2b5fda38e40"/><file name="TroubleshootingController.php" hash="c4b220b35f026a985d66383f9493423c"/></dir><dir name="etc"><file name="adminhtml.xml" hash="c5e8ade6b6c95176096cd392ccda5b16"/><file name="api.xml" hash="aa1711c3d2a0f4aead42df0c98d55cec"/><file name="cache.xml" hash="d161a338887fd508c10abe159f7a4060"/><file name="config.xml" hash="7bf0b7a7c4f92b5497458a2f42fbaf0a"/><file name="system.xml" hash="50af45b64a41b740dfc92581d0948766"/><file name="wsdl.xml" hash="aed14669c808d20719d348026e12437a"/><file name="wsi.xml" hash="881c87b26f062ebf8929777f6127286b"/></dir><dir name="sql"><dir name="listrak_remarketing_setup"><file name="mysql4-install-1.0.0.php" hash="26f1234ccc6d5505d20e27746f310581"/><file name="mysql4-install-1.1.9.php" hash="08f87628a62d6d2583d529b96a3344d9"/><file name="mysql4-upgrade-1.0.0-1.0.1.php" hash="0b01c013188802e9b325206f8a6464dc"/><file name="mysql4-upgrade-1.0.8-1.0.9.php" hash="862600bc223bc0074b669c5d576a40a4"/><file name="mysql4-upgrade-1.1.0-1.1.1.php" hash="6d1fdaf22e00279fdd6ae2f4073d6a34"/><file name="mysql4-upgrade-1.1.3-1.1.4.php" hash="f9c651f243ca6e6664df57a8cc7b3e41"/><file name="mysql4-upgrade-1.1.4-1.1.5.php" hash="4dc6e11122b62890932940be88838901"/><file name="mysql4-upgrade-1.1.5-1.1.6.php" hash="343ccdc500df5933ab57bc6391e57598"/><file name="mysql4-upgrade-1.1.6-1.1.7.php" hash="78fce151f25f60aba363956a88596781"/><file name="mysql4-upgrade-1.1.7-1.1.8.php" hash="28503560158e4346859450f289f1fe9a"/><file name="mysql4-upgrade-1.1.8-1.1.9.php" hash="f793cdc96107dcfe3d063bda26065158"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="remarketing.xml" hash="42e96a38405dc4b2975e5b185111c351"/></dir><dir name="template"><dir name="remarketing"><file name="async_wrapper.phtml" hash="ce78a31a93be4963ec1556d34f4572d3"/><file name="onescript.phtml" hash="30571a551e2653be8841d56575a76702"/><file name="utils.phtml" hash="b9b128932d453424816c43d531095495"/></dir></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="remarketing.xml" hash="d8065af171ca34e334f29d506217cd65"/></dir><dir name="template"><dir name="listrak"><dir name="remarketing"><dir name="productattributes"><dir name="form"><file name="categories.phtml" hash="80d4a9beaa0bbbfb1bce17af569685b9"/><file name="initbrands.phtml" hash="64eb3bd86b40fa6d9fcdf451cca56b34"/></dir></dir><file name="productattributes.phtml" hash="b22fbe3f7ff1337e5d19104d42447a5f"/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Listrak_Remarketing.xml" hash="63082a312f4668561da45ccd445a862b"/></dir></target></contents>
54
  <compatible/>
55
  <dependencies/>
56
  </package>