Polytab_Marketing_Attribution_Tracker - Version 1.0.3

Version Notes

Polytab Attribution Tracker will work after enable extension.

Download this release

Release Info

Developer Polytab Tech
Extension Polytab_Marketing_Attribution_Tracker
Version 1.0.3
Comparing to
See all releases


Version 1.0.3

Files changed (38) hide show
  1. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Form/Setting.php +17 -0
  2. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Form/Setting/Form.php +68 -0
  3. app/code/community/Polytab/OmniPixel/Block/Adminhtml/OmniPixelsetting.php +14 -0
  4. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings.php +15 -0
  5. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit.php +39 -0
  6. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit/Form.php +19 -0
  7. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit/Tab/Form.php +73 -0
  8. app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit/Tabs.php +24 -0
  9. app/code/community/Polytab/OmniPixel/Helper/Data.php +239 -0
  10. app/code/community/Polytab/OmniPixel/Helper/Registry.php +168 -0
  11. app/code/community/Polytab/OmniPixel/Model/Api.php +350 -0
  12. app/code/community/Polytab/OmniPixel/Model/Api/User.php +111 -0
  13. app/code/community/Polytab/OmniPixel/Model/Cron.php +63 -0
  14. app/code/community/Polytab/OmniPixel/Model/Observer.php +216 -0
  15. app/code/community/Polytab/OmniPixel/Model/Omnipixelsetting.php +20 -0
  16. app/code/community/Polytab/OmniPixel/Model/Product.php +414 -0
  17. app/code/community/Polytab/OmniPixel/Model/Resource/Omnipixelsetting.php +6 -0
  18. app/code/community/Polytab/OmniPixel/Model/Resource/Omnipixelsetting/Collection.php +8 -0
  19. app/code/community/Polytab/OmniPixel/Model/Resource/Omnipixelsetting/Collection/Db.php +310 -0
  20. app/code/community/Polytab/OmniPixel/Model/Resource/Product.php +4 -0
  21. app/code/community/Polytab/OmniPixel/Model/Resource/Product/Collection.php +245 -0
  22. app/code/community/Polytab/OmniPixel/Model/Resource/Product/Collection/Db.php +331 -0
  23. app/code/community/Polytab/OmniPixel/Model/Resource/Settings.php +7 -0
  24. app/code/community/Polytab/OmniPixel/Model/Resource/Settings/Collection.php +13 -0
  25. app/code/community/Polytab/OmniPixel/Model/Resource/Settings/Collection/Db.php +331 -0
  26. app/code/community/Polytab/OmniPixel/Model/Settings.php +20 -0
  27. app/code/community/Polytab/OmniPixel/Model/System/Config/Source/Inheritance.php +55 -0
  28. app/code/community/Polytab/OmniPixel/Model/System/Config/Source/Textarea/Values.php +9 -0
  29. app/code/community/Polytab/OmniPixel/controllers/Adminhtml/OmnipixelbackendController.php +119 -0
  30. app/code/community/Polytab/OmniPixel/etc/api.xml +37 -0
  31. app/code/community/Polytab/OmniPixel/etc/config.xml +232 -0
  32. app/code/community/Polytab/OmniPixel/etc/system.xml +100 -0
  33. app/code/community/Polytab/OmniPixel/sql/omnipixel_setup/install-0.1.0.php +26 -0
  34. app/design/adminhtml/default/default/layout/omnipixel.xml +9 -0
  35. app/design/adminhtml/default/default/template/omnipixel/omnipixelbackend.phtml +39 -0
  36. app/design/frontend/base/default/layout/omnipixel.xml +8 -0
  37. app/etc/modules/Polytab_OmniPixel.xml +10 -0
  38. package.xml +18 -0
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Form/Setting.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Block_Adminhtml_Form_Setting extends Mage_Adminhtml_Block_Widget_Form_Container
3
+ {
4
+ public function __construct()
5
+ {
6
+ parent::__construct();
7
+ $this->_blockGroup = 'omnipixel';
8
+ $this->_controller = 'adminhtml_form';
9
+ $this->_mode = 'setting';
10
+ $this->_updateButton('save', 'label', Mage::helper('omnipixel')->__('Save Config'));
11
+ }
12
+
13
+ public function getHeaderText()
14
+ {
15
+ return Mage::helper('omnipixel')->__('Polytab Attribution');
16
+ }
17
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Form/Setting/Form.php ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Block_Adminhtml_Form_Setting_Form extends Mage_Adminhtml_Block_Widget_Form
3
+ {
4
+ protected function _prepareForm()
5
+ {
6
+ $form = new Varien_Data_Form(array(
7
+ 'id' => 'edit_form',
8
+ 'action' => $this->getUrl('*/*/getkey',array('id' => 1)),
9
+ 'method' => 'post',
10
+ ));
11
+
12
+
13
+ $form->setUseContainer(true);
14
+ $this->setForm($form);
15
+
16
+ $model = Mage::getModel('omnipixel/omnipixelsetting');
17
+ $id = 1;
18
+ $data = array();
19
+ if($id){
20
+ $model->load($id);
21
+ $data = $model->getData();
22
+ }
23
+
24
+ if($data['is_enable'] == ""){
25
+ $data['is_enable'] = 0;
26
+ }
27
+
28
+ $fieldset = $form->addFieldset('form_general', array('legend' => Mage::helper('omnipixel')->__('General Configuration')));
29
+
30
+ $fieldset->addField('is_enable', 'select', array(
31
+ 'label' => Mage::helper('omnipixel')->__('Enable'),
32
+ 'class' => 'required-entry',
33
+ 'required' => true,
34
+ 'name' => 'is_enable',
35
+ 'value' => $data['is_enable'],
36
+ 'values' => array(
37
+ array('value'=>'1','label'=>'Enable'),
38
+ array('value'=>'0','label'=>'Disable'),
39
+ )
40
+ ));
41
+
42
+
43
+
44
+ $platform_code = $data["platform_code"];
45
+ if($platform_code == ""){
46
+ $fieldset->addField('platform_code', 'hidden', array(
47
+ 'label' => Mage::helper('omnipixel')->__('Platform Code'),
48
+ 'required' => false,
49
+ 'name' => 'platform_code',
50
+ 'value'=>'M90912138394TYTYBEQWETF'
51
+ ));
52
+
53
+ $note = 'By agreeing to install the Polytab attribution extension, you acknowledge acceptance of the terms and conditions listed <a href="http://www.infemotions.com/privacy-terms-of-use/" target="_blank">here.</a>';
54
+ $fieldset->addField('terms', 'checkbox', array(
55
+ 'required' => false,
56
+ 'name' => 'terms',
57
+ 'after_element_html' => $note,
58
+ 'value'=>'1',
59
+ 'values' => array(
60
+ array('value'=>'1'),
61
+ array('value'=>'0'),
62
+ )
63
+ ));
64
+ }
65
+ return parent::_prepareForm();
66
+ }
67
+
68
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/OmniPixelsetting.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Block_Adminhtml_OmniPixelsetting extends Mage_Adminhtml_Block_Widget_Form_Container{
3
+
4
+ public function __construct(){
5
+ parent::__construct();
6
+ $this->_objectId = 'id';
7
+ $this->_blockGroup = 'omnipixel';
8
+ $this->_controller = 'adminhtml_omniPixelsetting';
9
+ }
10
+
11
+ public function getHeaderText(){
12
+ return Mage::helper('omnipixel')->__('Polytab Settings');
13
+ }
14
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Block_Adminhtml_Settings extends Mage_Adminhtml_Block_Widget_Form_Container{
3
+
4
+ public function __construct(){
5
+ parent::__construct();
6
+ $this->_objectId = 'id';
7
+ $this->_blockGroup = 'omnipixel';
8
+ $this->_controller = 'adminhtml_settings';
9
+ $this->_mode = 'form';
10
+ }
11
+
12
+ public function getHeaderText(){
13
+ return Mage::helper('omnipixel')->__('Form Container');
14
+ }
15
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Block_Adminhtml_Settings_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+
9
+ $this->_objectId = 'id';
10
+ $this->_blockGroup = 'omnipixel';
11
+ $this->_controller = 'adminhtml_settings';
12
+
13
+ $this->_updateButton('save', 'label', Mage::helper('omnipixel')->__('Save Item'));
14
+ $this->_updateButton('delete', 'label', Mage::helper('omnipixel')->__('Delete Item'));
15
+
16
+ $this->_formScripts[] = "
17
+ function toggleEditor() {
18
+ if (tinyMCE.getInstanceById('payment_content') == null) {
19
+ tinyMCE.execCommand('mceAddControl', false, 'omnipixel_content');
20
+ } else {
21
+ tinyMCE.execCommand('mceRemoveControl', false, 'omnipixel_content');
22
+ }
23
+ }
24
+
25
+ function saveAndContinueEdit(){
26
+ editForm.submit($('edit_form').action+'back/edit/');
27
+ }
28
+ ";
29
+ }
30
+
31
+ public function getHeaderText()
32
+ {
33
+ if(Mage::registry('omnipixel_data') && Mage::registry('omnipixel_data')->getId()){
34
+ return Mage::helper('omnipixel')->__("Edit Item %s", $this->htmlEscape(Mage::registry('omnipixel_data')->getTitle()));
35
+ } else {
36
+ return Mage::helper('omnipixel')->__('Domains Mapping');
37
+ }
38
+ }
39
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit/Form.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Block_Adminhtml_Settings_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form(array(
8
+ 'id' => 'edit_form',
9
+ 'action' => $this->getUrl('*/*/save', array('entity_id' => $this->getRequest()->getParam('entity_id'))),
10
+ 'method' => 'post',
11
+ 'enctype' => 'multipart/form-data'
12
+ )
13
+ );
14
+
15
+ $form->setUseContainer(true);
16
+ $this->setForm($form);
17
+ return parent::_prepareForm();
18
+ }
19
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit/Tab/Form.php ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Block_Adminhtml_Settings_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form
4
+ {
5
+ protected function _prepareForm()
6
+ {
7
+ $form = new Varien_Data_Form();
8
+ $this->setForm($form);
9
+
10
+ $fieldset = $form->addFieldset('settings_form', array('legend'=>Mage::helper('omnipixel')->__('Domain Mapping')));
11
+ //$Mage_fld = Mage::getSingleton('omnipixel/settings')->getMageFieldsArray();
12
+ $SF_accounts = Mage::getSingleton('omnipixel/settings')->getAccountNamesArray();
13
+
14
+ $registrRecord = Mage::registry('omnipixel_data')->getData();
15
+ //print_r($registrRecord);exit;
16
+ //$selectVal = Mage::getModel('omnipixel/productfldmap')->load($recordId['id'])->getData('add_type');
17
+
18
+ $account_selected = $registrRecord['account_name'];
19
+ $domain_selected = $registrRecord['domain_name'];
20
+
21
+ if($this->getRequest()->getParam('entity_id')){
22
+
23
+ }
24
+
25
+ $field = $fieldset->addField('account_name', 'select', array(
26
+ 'label' => Mage::helper('omnipixel')->__('Salesforce Account :'),
27
+ 'class' => 'custom-select required-entry',
28
+ 'name' => 'account_name',
29
+ 'searchable'=> 'true',
30
+ 'values' => $SF_accounts,
31
+ 'value' => $account_selected
32
+ ));
33
+
34
+ $field->setAfterElementHtml('<script>
35
+ //< ![C
36
+
37
+ $j(function() {
38
+ $j("#account_name").customselect();
39
+ });
40
+
41
+
42
+ //]]>
43
+ </script>');
44
+
45
+ $fieldset->addField('domain_name', 'text', array(
46
+ 'label' => Mage::helper('omnipixel')->__('Email Domain :'),
47
+ 'class' => 'required-entry',
48
+ 'name' => 'domain_name',
49
+ 'value' => $domain_selected
50
+ ));
51
+
52
+
53
+ /*
54
+ if ( Mage::getSingleton('adminhtml/session')->get<Module>Data() ){
55
+ $form->setValues(Mage::getSingleton('adminhtml/session')->get<Module>Data());
56
+ Mage::getSingleton('adminhtml/session')->set<Module>Data(null);
57
+ } elseif ( Mage::registry('<module>_data') ) {
58
+ $form->setValues(Mage::registry('<module>_data')->getData());
59
+ }
60
+
61
+ */
62
+ /*
63
+ if ( Mage::getSingleton('adminhtml/session')->getMagerpsyncData() )
64
+ {
65
+ $form->setValues(Mage::getSingleton('adminhtml/session')->getMagerpsyncData());
66
+ Mage::getSingleton('adminhtml/session')->getMagerpsyncData(null);
67
+ } elseif ( Mage::registry('omnipixel_data') ) {
68
+ $form->setValues(Mage::registry('omnipixel_data')->getData());
69
+ }
70
+ */
71
+ return parent::_prepareForm();
72
+ }
73
+ }
app/code/community/Polytab/OmniPixel/Block/Adminhtml/Settings/Edit/Tabs.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Block_Adminhtml_Settings_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ parent::__construct();
9
+ $this->setId('settings_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle(Mage::helper('omnipixel')->__('Domain Mapping'));
12
+ }
13
+
14
+ protected function _beforeToHtml()
15
+ {
16
+ $this->addTab('form_section', array(
17
+ 'label' => Mage::helper('omnipixel')->__('Domain Mapping'),
18
+ 'title' => Mage::helper('omnipixel')->__('Domain Mapping'),
19
+ 'content' => $this->getLayout()->createBlock('omnipixel/adminhtml_settings_edit_tab_form')->toHtml(),
20
+ ));
21
+
22
+ return parent::_beforeToHtml();
23
+ }
24
+ }
app/code/community/Polytab/OmniPixel/Helper/Data.php ADDED
@@ -0,0 +1,239 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ const MY_DATA_FEED_WATCH_URL = 'https://my.datafeedwatch.com/';
5
+ const LOG_DIR_NAME = 'Polytab_OmniPixel';
6
+ const API_LOG_DIR_NAME = 'api';
7
+ const SQL_LOG_DIR_NAME = 'sql';
8
+ const CRON_LOG_DIR_NAME = 'cron';
9
+ const DEBUG_XPATH = 'omnipixel/general/debug';
10
+ const PRODUCT_URL_CUSTOM_INHERITANCE_XPATH = 'omnipixel/custom_inheritance/product_url';
11
+ const IMAGE_URL_CUSTOM_INHERITANCE_XPATH = 'omnipixel/custom_inheritance/image_url';
12
+ const LAST_CATALOGRULE_PRICE_ID_XPATH = 'omnipixel/custom_inheritance/last_catalogrule_price_id';
13
+ const LAST_INHERITANCE_UPDATE_XPATH = 'omnipixel/custom_inheritance/last_inheritance_update';
14
+
15
+ /**
16
+ * @return bool
17
+ */
18
+ public function isDebugModeEnabled()
19
+ {
20
+ return Mage::getStoreConfigFlag(self::DEBUG_XPATH);
21
+ }
22
+
23
+ /**
24
+ * @return bool
25
+ */
26
+ public function isProductUrlInherited()
27
+ {
28
+ return Mage::getStoreConfigFlag(self::PRODUCT_URL_CUSTOM_INHERITANCE_XPATH);
29
+ }
30
+
31
+ /**
32
+ * @return bool
33
+ */
34
+ public function isImageUrlInherited()
35
+ {
36
+ return Mage::getStoreConfigFlag(self::IMAGE_URL_CUSTOM_INHERITANCE_XPATH);
37
+ }
38
+
39
+ /**
40
+ * @return string
41
+ */
42
+ public function getLastCatalogRulePriceId()
43
+ {
44
+ return Mage::getStoreConfig(self::LAST_CATALOGRULE_PRICE_ID_XPATH);
45
+ }
46
+
47
+ /**
48
+ * @param string|int $id
49
+ */
50
+ public function setLastCatalogRulePriceId($id)
51
+ {
52
+ Mage::getModel('core/config')->saveConfig(self::LAST_CATALOGRULE_PRICE_ID_XPATH, $id);
53
+ }
54
+
55
+ /**
56
+ * @return string
57
+ */
58
+ public function getLastInheritanceUpdateDate()
59
+ {
60
+ return Mage::getStoreConfig(self::LAST_INHERITANCE_UPDATE_XPATH);
61
+ }
62
+
63
+ /**
64
+ * @param string $date
65
+ */
66
+ public function setLastInheritanceUpdateDate($date)
67
+ {
68
+ Mage::getModel('core/config')->saveConfig(self::LAST_INHERITANCE_UPDATE_XPATH, $date)->reinit();
69
+ }
70
+
71
+ public function updateLastInheritanceUpdateDate()
72
+ {
73
+ $this->setLastInheritanceUpdateDate(date('Y-m-d H:i:s'));
74
+ }
75
+
76
+ /**
77
+ * @param mixed $message
78
+ */
79
+ public function log($message)
80
+ {
81
+ $this->logToFile($message, self::API_LOG_DIR_NAME);
82
+ }
83
+
84
+ /**
85
+ * @param mixed $message
86
+ */
87
+ public function sqlLog($message)
88
+ {
89
+ $this->logToFile($message, self::SQL_LOG_DIR_NAME);
90
+ }
91
+
92
+ /**
93
+ * @param mixed $message
94
+ */
95
+ public function cronLog($message)
96
+ {
97
+ $this->logToFile($message, self::CRON_LOG_DIR_NAME);
98
+ }
99
+
100
+ /**
101
+ * @param string $message
102
+ * @param string $type
103
+ */
104
+ public function logToFile($message, $type)
105
+ {
106
+ if ($this->isDebugModeEnabled()) {
107
+ $this->createLogFileDir($type);
108
+ $fileName = $this->getLogFilePath($type);
109
+ Mage::log($message, null, $fileName, true);
110
+ }
111
+ }
112
+
113
+ /**
114
+ * @param string $type
115
+ * @return string
116
+ */
117
+ public function getLogFilePath($type)
118
+ {
119
+ return self::LOG_DIR_NAME. DS . $type . DS . sprintf('%s.log', date('Y-m-d'));
120
+ }
121
+
122
+ /**
123
+ * @param string $type
124
+ */
125
+ public function createLogFileDir($type) {
126
+ $dir = Mage::getBaseDir('var') . DS . 'log' . DS . self::LOG_DIR_NAME . DS . $type . DS;
127
+ if (!file_exists($dir)) {
128
+ try {
129
+ mkdir($dir, 0775, true);
130
+ } catch (Exception $e) {
131
+ Mage::log($e->getMessage());
132
+ }
133
+ }
134
+ }
135
+
136
+ /**
137
+ * @return string
138
+ */
139
+ public function getDataFeedWatchUrl()
140
+ {
141
+ return self::MY_DATA_FEED_WATCH_URL;
142
+ }
143
+
144
+ public function restoreOriginalAttributesConfig()
145
+ {
146
+ $cannotConfigureImportField = array(
147
+ 'name',
148
+ 'description',
149
+ 'short_description',
150
+ 'tax_class_id',
151
+ 'visibility',
152
+ 'status',
153
+ 'meta_title',
154
+ 'meta_keyword',
155
+ 'meta_description',
156
+ 'media_gallery',
157
+ 'image',
158
+ 'small_image',
159
+ 'thumbnail',
160
+ 'price',
161
+ 'special_price',
162
+ 'special_from_date',
163
+ 'special_to_date',
164
+ 'sku',
165
+ 'updated_at',
166
+ 'ignore_datafeedwatch',
167
+ 'dfw_parent_ids',
168
+ );
169
+
170
+ $cannotConfigureInheritanceField = array(
171
+ 'sku',
172
+ 'price',
173
+ 'special_price',
174
+ 'special_from_date',
175
+ 'special_to_date',
176
+ 'media_gallery',
177
+ 'image',
178
+ 'small_image',
179
+ 'thumbnail',
180
+ 'updated_at',
181
+ 'ignore_datafeedwatch',
182
+ 'dfw_parent_ids',
183
+ );
184
+
185
+ $enableImport = array(
186
+ 'name',
187
+ 'description',
188
+ 'short_description',
189
+ 'tax_class_id',
190
+ 'visibility',
191
+ 'status',
192
+ 'meta_title',
193
+ 'meta_keyword',
194
+ 'meta_description',
195
+ 'sku',
196
+ 'price',
197
+ 'special_price',
198
+ 'special_from_date',
199
+ 'special_to_date',
200
+ 'updated_at',
201
+ 'color',
202
+ 'size',
203
+ 'gender',
204
+ 'manufacturer',
205
+ 'material',
206
+ );
207
+
208
+ $inheritanceData = array(
209
+ 'updated_at' => Polytab_OmniPixel_Model_System_Config_Source_Inheritance::PARENT_OPTION_ID,
210
+ 'ignore_datafeedwatch' => Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_OPTION_ID,
211
+ 'dfw_parent_ids' => Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_OPTION_ID,
212
+ 'status' => Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_THEN_PARENT_OPTION_ID,
213
+ );
214
+
215
+ $catalogAttributes = Mage::getResourceModel('catalog/product_attribute_collection');
216
+ $catalogAttributes->setDataToAll('can_configure_inheritance', null);
217
+ $catalogAttributes->setDataToAll('inheritance', null);
218
+ $catalogAttributes->setDataToAll('can_configure_import', null);
219
+ $catalogAttributes->setDataToAll('import_to_dfw', null);
220
+ $catalogAttributes->save();
221
+
222
+ $attributes = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter();
223
+ foreach ($attributes as $attribute) {
224
+ $attributeCode = $attribute->getAttributeCode();
225
+ $inheritance = Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_OPTION_ID;
226
+ if (array_key_exists($attributeCode, $inheritanceData)) {
227
+ $inheritance = $inheritanceData[$attributeCode];
228
+ }
229
+ $attribute->setImportToDfw(in_array($attributeCode, $enableImport))
230
+ ->setCanConfigureImport(!in_array($attributeCode, $cannotConfigureImportField))
231
+ ->setCanConfigureInheritance(!in_array($attributeCode, $cannotConfigureInheritanceField))
232
+ ->setInheritance($inheritance)
233
+ ->save();
234
+ }
235
+
236
+ Mage::getModel('core/config')->saveConfig('omnipixel/custom_inheritance/product_url', 1);
237
+ Mage::getModel('core/config')->saveConfig('omnipixel/custom_inheritance/image_url', 0);
238
+ }
239
+ }
app/code/community/Polytab/OmniPixel/Helper/Registry.php ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Helper_Registry
4
+ extends Mage_Core_Helper_Abstract
5
+ {
6
+ const ALL_CATEGORIES_ARRAY_KEY = 'all_categories_array';
7
+ const ALL_SUPER_ATTRIBUTES_KEY = 'all_super_attributes_array';
8
+ const ALL_IMPORTABLE_ATTRIBUTES_KEY = 'all_importable_attributes';
9
+ const ALL_ATTRIBUTE_COLLECTION_KEY = 'all_attribute_collection';
10
+ const DFW_STATUS_ATTRIBUTE_KEY = 'dfw_status_attribute';
11
+ const DFW_UPDATED_AT_ATTRIBUTE_KEY = 'dfw_updated_at_attribute';
12
+ const DFW_VISIBILITY_ATTRIBUTE_KEY = 'dfw_visibility_at_attribute';
13
+ const DFW_PARENT_ID_ATTRIBUTE_KEY = 'dfw_parent_id_attribute';
14
+
15
+ /**
16
+ * @param string $storeId
17
+ */
18
+ public function initImportRegistry($storeId)
19
+ {
20
+ $this->registerCategories($storeId);
21
+ $this->registerStatusAttribute();
22
+ $this->registerUpdatedAtAttribute();
23
+ $this->registerVisibilityAttribute();
24
+ $this->registerParentIdAttribute();
25
+ $this->registerSuperAttributes();
26
+ $this->registerInheritableAttributes();
27
+ $this->registerAttributeCollection();
28
+ }
29
+ /**
30
+ * @param string $storeId
31
+ */
32
+ protected function registerCategories($storeId)
33
+ {
34
+ $registry = Mage::registry(self::ALL_CATEGORIES_ARRAY_KEY);
35
+ if (empty($registry)) {
36
+ $categories = Mage::getResourceModel('catalog/category_collection')
37
+ ->addNameToResult()
38
+ ->setStoreId($storeId)
39
+ ->addFieldToFilter('level', array('gt' => 1))
40
+ ->getItems();
41
+
42
+ Mage::register(self::ALL_CATEGORIES_ARRAY_KEY, $categories);
43
+ }
44
+ }
45
+
46
+ protected function registerSuperAttributes()
47
+ {
48
+ $registry = Mage::registry(self::ALL_SUPER_ATTRIBUTES_KEY);
49
+ if (empty($registry)) {
50
+ $superAttributes = Mage::getResourceModel('catalog/product_attribute_collection')
51
+ ->addVisibleFilter()
52
+ ->getItems();
53
+ Mage::register(self::ALL_SUPER_ATTRIBUTES_KEY, $superAttributes);
54
+ }
55
+ }
56
+
57
+ protected function registerInheritableAttributes()
58
+ {
59
+ $registry = Mage::registry(self::ALL_IMPORTABLE_ATTRIBUTES_KEY);
60
+ if (empty($registry)) {
61
+ $importableAttributes = Mage::getResourceModel('catalog/product_attribute_collection')
62
+ ->addVisibleFilter()
63
+ ->addFieldToFilter('import_to_dfw', 1);
64
+ Mage::register(self::ALL_IMPORTABLE_ATTRIBUTES_KEY, $importableAttributes);
65
+ }
66
+ }
67
+
68
+ protected function registerAttributeCollection()
69
+ {
70
+ $registry = Mage::registry(self::ALL_ATTRIBUTE_COLLECTION_KEY);
71
+ if (empty($registry)) {
72
+ $attributeCollection = Mage::getResourceModel('catalog/product_attribute_collection')->addVisibleFilter();
73
+ foreach ($attributeCollection as $key => $attribute) {
74
+ if (!$this->isAttributeInheritable($attribute) || !$this->isAttributeImportable($attribute)) {
75
+ $attributeCollection->removeItemByKey($key);
76
+ }
77
+ }
78
+ Mage::register(self::ALL_ATTRIBUTE_COLLECTION_KEY, $attributeCollection);
79
+ }
80
+ }
81
+
82
+ protected function registerStatusAttribute()
83
+ {
84
+ $registry = Mage::registry(self::DFW_STATUS_ATTRIBUTE_KEY);
85
+ if (empty($registry)) {
86
+ /** @var Mage_Catalog_Model_Resource_Eav_Attribute $statusAttribute */
87
+ $statusAttribute = Mage::getResourceModel('catalog/product_attribute_collection')
88
+ ->addVisibleFilter()
89
+ ->addFieldToFilter('attribute_code', 'status')->getFirstItem();
90
+ Mage::register(self::DFW_STATUS_ATTRIBUTE_KEY, $statusAttribute);
91
+ }
92
+ }
93
+
94
+ /**
95
+ * @return bool
96
+ */
97
+ public function isStatusAttributeInheritable()
98
+ {
99
+ return $this->isAttributeInheritable(Mage::registry(self::DFW_STATUS_ATTRIBUTE_KEY));
100
+ }
101
+
102
+ protected function registerUpdatedAtAttribute()
103
+ {
104
+ $registry = Mage::registry(self::DFW_UPDATED_AT_ATTRIBUTE_KEY);
105
+ if (empty($registry)) {
106
+ /** @var Mage_Catalog_Model_Resource_Eav_Attribute $statusAttribute */
107
+ $updatedAtAttribute = Mage::getResourceModel('catalog/product_attribute_collection')
108
+ ->addVisibleFilter()
109
+ ->addFieldToFilter('attribute_code', 'updated_at')->getFirstItem();
110
+ Mage::register(self::DFW_UPDATED_AT_ATTRIBUTE_KEY, $updatedAtAttribute);
111
+ }
112
+ }
113
+
114
+ protected function registerVisibilityAttribute()
115
+ {
116
+ $registry = Mage::registry(self::DFW_VISIBILITY_ATTRIBUTE_KEY);
117
+ if (empty($registry)) {
118
+ /** @var Mage_Catalog_Model_Resource_Eav_Attribute $statusAttribute */
119
+ $visibilityAttribute = Mage::getResourceModel('catalog/product_attribute_collection')
120
+ ->addVisibleFilter()
121
+ ->addFieldToFilter('attribute_code', 'visibility')->getFirstItem();
122
+ Mage::register(self::DFW_VISIBILITY_ATTRIBUTE_KEY, $visibilityAttribute);
123
+ }
124
+ }
125
+
126
+ protected function registerParentIdAttribute()
127
+ {
128
+ $registry = Mage::registry(self::DFW_PARENT_ID_ATTRIBUTE_KEY);
129
+ if (empty($registry)) {
130
+ /** @var Mage_Catalog_Model_Resource_Eav_Attribute $statusAttribute */
131
+ $attribute = Mage::getResourceModel('catalog/product_attribute_collection')
132
+ ->addVisibleFilter()
133
+ ->addFieldToFilter('attribute_code', 'dfw_parent_ids')->getFirstItem();
134
+ Mage::register(self::DFW_PARENT_ID_ATTRIBUTE_KEY, $attribute);
135
+ }
136
+ }
137
+
138
+ /**
139
+ * @return bool
140
+ */
141
+ public function isUpdatedAtAttributeInheritable()
142
+ {
143
+ return $this->isAttributeInheritable(Mage::registry(self::DFW_UPDATED_AT_ATTRIBUTE_KEY));
144
+ }
145
+
146
+ /**
147
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
148
+ * @return bool
149
+ */
150
+ public function isAttributeInheritable($attribute)
151
+ {
152
+ return in_array($attribute->getInheritance(),
153
+ array(
154
+ (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::PARENT_OPTION_ID,
155
+ (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_THEN_PARENT_OPTION_ID,
156
+ )
157
+ );
158
+ }
159
+
160
+ /**
161
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
162
+ * @return bool
163
+ */
164
+ public function isAttributeImportable($attribute)
165
+ {
166
+ return (int)$attribute->getImportToDfw() === 1;
167
+ }
168
+ }
app/code/community/Polytab/OmniPixel/Model/Api.php ADDED
@@ -0,0 +1,350 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Api extends Mage_Catalog_Model_Product_Api
4
+ {
5
+ /**
6
+ * @return Polytab_OmniPixel_Helper_Data
7
+ */
8
+ public function helper()
9
+ {
10
+ return Mage::helper('omnipixel');
11
+ }
12
+
13
+ /**
14
+ * @return string
15
+ */
16
+ public function version()
17
+ {
18
+ $this->helper()->log('datafeedwatch.version');
19
+ $version = Mage::getConfig()->getNode()->modules->Polytab_OmniPixel->version->__toString();
20
+ $this->helper()->log($version);
21
+
22
+ return $version;
23
+ }
24
+
25
+ /**
26
+ * @return int
27
+ */
28
+ public function gmt_offset()
29
+ {
30
+ $this->helper()->log('datafeedwatch.gmt_offset');
31
+ $timeZone = Mage::getStoreConfig('general/locale/timezone');
32
+ $timeZone = new DateTimeZone($timeZone);
33
+ $time = new DateTime('now', $timeZone);
34
+ $offset = (int)($timeZone->getOffset($time) / 3600);
35
+ $this->helper()->log($offset);
36
+
37
+ return $offset;
38
+ }
39
+
40
+ /**
41
+ * @return array
42
+ */
43
+ public function stores()
44
+ {
45
+ $this->helper()->log('datafeedwatch.stores');
46
+ $storeViews = $this->getStoresArray();
47
+ $this->helper()->log($storeViews);
48
+
49
+ return $storeViews;
50
+ }
51
+
52
+ /**
53
+ * @param array $options
54
+ * @return array
55
+ */
56
+ public function products($options = array())
57
+ {
58
+ $this->helper()->log('datafeedwatch.products');
59
+ $this->unsetUpdatedOptions($options);
60
+ $this->filterOptions($options);
61
+ $collection = $this->getProductCollection($options);
62
+ $collection->applyInheritanceLogic();
63
+
64
+ return $this->processProducts($collection);
65
+ }
66
+
67
+ /**
68
+ * @param array $options
69
+ * @return int
70
+ */
71
+ public function product_count($options = array())
72
+ {
73
+ $this->helper()->log('datafeedwatch.product_count');
74
+ $this->unsetUpdatedOptions($options);
75
+ $this->filterOptions($options);
76
+ $collection = $this->getProductCollection($options);
77
+ $amount = (int) $collection->getSize();
78
+ $this->helper()->log(sprintf('datafeedwatch.product_count %d', $amount));
79
+
80
+ return $amount;
81
+ }
82
+
83
+ /**
84
+ * @param array $options
85
+ * @return array
86
+ */
87
+ public function updated_products($options = array())
88
+ {
89
+ $this->helper()->log('datafeedwatch.updated_products');
90
+ $this->filterOptions($options);
91
+ if (!$this->isFromDateEarlierThanConfigDate($options)) {
92
+ $collection = $this->getProductCollection($options);
93
+ $collection->applyInheritanceLogic();
94
+
95
+ return $this->processProducts($collection);
96
+ } else {
97
+ $this->helper()->log('datafeedwatch.updated_products -> datafeedwatch.products');
98
+
99
+ return $this->products($options);
100
+ }
101
+ }
102
+
103
+ /**
104
+ * @param array $options
105
+ * @return int
106
+ */
107
+ public function updated_product_count($options = array())
108
+ {
109
+ $this->helper()->log('datafeedwatch.updated_product_count');
110
+ $this->filterOptions($options);
111
+ if (!$this->isFromDateEarlierThanConfigDate($options)) {
112
+ $collection = $this->getProductCollection($options);
113
+ $amount = (int) $collection->getSize();
114
+ $this->helper()->log(sprintf('datafeedwatch.updated_product_count %d', $amount));
115
+ } else {
116
+ $this->helper()->log('datafeedwatch.updated_product_count -> datafeedwatch.product_count');
117
+ $amount = $this->product_count($options);
118
+ }
119
+
120
+ return $amount;
121
+ }
122
+
123
+ /**
124
+ * @param array $options
125
+ * @return array
126
+ */
127
+ public function product_ids($options = array())
128
+ {
129
+ $this->helper()->log('datafeedwatch.product_ids');
130
+ $this->filterOptions($options);
131
+ $collection = $this->getProductCollection($options);
132
+
133
+ return $collection->getColumnValues('entity_id');
134
+ }
135
+
136
+ /**
137
+ * @param array $options
138
+ * @return bool
139
+ */
140
+ protected function isFromDateEarlierThanConfigDate($options)
141
+ {
142
+ $this->helper()->log('START: Model/Api.php->isFromDateEarlierThanConfigDate()');
143
+ if (!isset($options['from_date'])) {
144
+ $this->helper()->log('$options[\'from_date\'] is not set');
145
+ $this->helper()->log('END: Model/Api.php->isFromDateEarlierThanConfigDate()');
146
+
147
+ return false;
148
+ }
149
+ $this->helper()->log('$options[\'from_date\']');
150
+ $this->helper()->log($options['from_date']);
151
+ $this->helper()->log('$this->helper()->getLastInheritanceUpdateDate()');
152
+ $this->helper()->log($this->helper()->getLastInheritanceUpdateDate());
153
+ $this->helper()->log('result');
154
+ if ($options['from_date'] < $this->helper()->getLastInheritanceUpdateDate()) {
155
+ $this->helper()->log('$options[\'from_date\'] < $this->helper()->getLastInheritanceUpdateDate()');
156
+ } else {
157
+ $this->helper()->log('From date is equal or greater');
158
+ }
159
+ $this->helper()->log('END: Model/Api.php->isFromDateEarlierThanConfigDate()');
160
+
161
+ return $options['from_date'] < $this->helper()->getLastInheritanceUpdateDate();
162
+ }
163
+
164
+ /**
165
+ * @return array
166
+ */
167
+ protected function getStoresArray()
168
+ {
169
+ $storeViews = array();
170
+ foreach (Mage::app()->getWebsites() as $website) {
171
+ foreach ($website->getGroups() as $group) {
172
+ foreach ($group->getStores() as $store) {
173
+ $storeViews[$store->getCode()] = array(
174
+ 'Website' => $website->getName(),
175
+ 'Store' => $group->getName(),
176
+ 'Store View' => $store->getName(),
177
+ );
178
+ }
179
+ }
180
+ }
181
+
182
+ return $storeViews;
183
+ }
184
+
185
+ /**
186
+ * @param array $options
187
+ * @return Polytab_OmniPixel_Model_Resource_Product_Collection
188
+ */
189
+ public function getProductCollection($options)
190
+ {
191
+ /** @var Polytab_OmniPixel_Model_Resource_Product_Collection $collection */
192
+ $collection = Mage::getResourceModel('omnipixel/product_collection')->addAttributeToSelect('*');
193
+ $collection->applyFiltersOnCollection($options);
194
+
195
+ return $collection;
196
+ }
197
+
198
+ /**
199
+ * @param array $options
200
+ */
201
+ public function filterOptions(&$options)
202
+ {
203
+ $this->helper()->log($options);
204
+
205
+ if (isset($options['store'])) {
206
+ $this->filterStoreOption($options);
207
+ }
208
+
209
+ if (isset($options['type'])) {
210
+ $this->filterTypeOption($options);
211
+ }
212
+
213
+ if (isset($options['status'])) {
214
+ $this->filterStatusOption($options);
215
+ }
216
+
217
+ if (isset($options['timezone'])) {
218
+ $this->filterTimeZoneOption($options);
219
+ }
220
+
221
+ if (isset($options['updated_at'])) {
222
+ $options['from_date'] = $options['updated_at'];
223
+ unset($options['updated_at']);
224
+ }
225
+
226
+ if (isset($options['from_date'])) {
227
+ $this->filterFromDateOption($options);
228
+ }
229
+
230
+ if (!isset($options['page'])) {
231
+ $options['page'] = 1;
232
+ }
233
+
234
+ if (!isset($options['per_page'])) {
235
+ $options['per_page'] = 100;
236
+ }
237
+ }
238
+
239
+ /**
240
+ * @param array $options
241
+ */
242
+ public function filterStoreOption(&$options)
243
+ {
244
+ $existingStoreViews = array_keys($this->getStoresArray());
245
+ if (!in_array($options['store'], $existingStoreViews)) {
246
+ $message = 'The store view %s does not exist. Default store will be applied';
247
+ $this->helper()->log(sprintf($message, $options['store']));
248
+ $options['store'] = Mage::app()->getDefaultStoreView()->getCode();
249
+ }
250
+ Mage::app()->setCurrentStore($options['store']);
251
+ }
252
+
253
+ /**
254
+ * @param array $options
255
+ */
256
+ public function filterTypeOption(&$options)
257
+ {
258
+ $types = $options['type'];
259
+ $magentoTypes = array(
260
+ Mage_Catalog_Model_Product_Type::TYPE_SIMPLE,
261
+ Mage_Catalog_Model_Product_Type::TYPE_BUNDLE,
262
+ Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE,
263
+ Mage_Catalog_Model_Product_Type::TYPE_GROUPED,
264
+ Mage_Catalog_Model_Product_Type::TYPE_VIRTUAL,
265
+ );
266
+ if (!is_array($types)) {
267
+ $types = array($types);
268
+ }
269
+ $types = array_map('strtolower', $types);
270
+ $types = array_intersect($types, $magentoTypes);
271
+ if (!empty($types)) {
272
+ $options['type'] = $types;
273
+ } else {
274
+ $this->helper()->log('The type below does not exist');
275
+ $this->helper()->log($options['type']);
276
+ unset($options['type']);
277
+ }
278
+ }
279
+
280
+ /**
281
+ * @param array $options
282
+ */
283
+ public function filterStatusOption(&$options)
284
+ {
285
+ $status = (string) $options['status'];
286
+ if ($status === '0') {
287
+ $options['status'] = Mage_Catalog_Model_Product_Status::STATUS_DISABLED;
288
+ } else if ($status === '1') {
289
+ $options['status'] = Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
290
+ } else {
291
+ $message = 'The status %s does not exist';
292
+ $this->helper()->log(sprintf($message, $options['status']));
293
+ unset($options['status']);
294
+ }
295
+ }
296
+
297
+ /**
298
+ * @param array $options
299
+ */
300
+ public function unsetUpdatedOptions(&$options)
301
+ {
302
+ unset($options['from_date']);
303
+ unset($options['updated_at']);
304
+ unset($options['timezone']);
305
+ }
306
+
307
+ /**
308
+ * @param array $options
309
+ */
310
+ public function filterTimeZoneOption(&$options)
311
+ {
312
+ try {
313
+ $options['timezone'] = new DateTimeZone($options['timezone']);
314
+ } catch (Exception $e) {
315
+ $this->helper()->log(sprintf('%s timezone is wrong', $options['timezone']));
316
+ $options['timezone'] = null;
317
+ }
318
+ }
319
+
320
+ /**
321
+ * @param array $options
322
+ */
323
+ public function filterFromDateOption(&$options)
324
+ {
325
+ if (!isset($options['timezone'])) {
326
+ $options['timezone'] = null;
327
+ }
328
+ try {
329
+ $options['from_date'] = new DateTime($options['from_date'], $options['timezone']);
330
+ } catch (Exception $e) {
331
+ $this->helper()->log(sprintf('%s from_date is wrong', $options['from_date']));
332
+ $options['from_date'] = new DateTime();
333
+ }
334
+ $options['from_date'] = $options['from_date']->format('Y-m-d H:i:s');
335
+ }
336
+
337
+ /**
338
+ * @param Polytab_OmniPixel_Model_Resource_Product_Collection $collection
339
+ * @return array
340
+ */
341
+ protected function processProducts($collection)
342
+ {
343
+ $products = array();
344
+ foreach ($collection as $product) {
345
+ $products[] = $product->getDataToImport();
346
+ }
347
+
348
+ return $products;
349
+ }
350
+ }
app/code/community/Polytab/OmniPixel/Model/Api/User.php ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Model_Api_User extends Mage_Api_Model_User
3
+ {
4
+ const API_KEY_SHUFFLE_STRING = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
5
+ const API_KEY_LENGTH = 32;
6
+ const USER_NAME = 'datafeedwatch';
7
+ const USER_FIRST_NAME = 'Api Access';
8
+ const USER_LAST_NAME = 'DataFeedWatch';
9
+ const USER_EMAIL = 'magento@datafeedwatch.com';
10
+ const USER_IS_ACTIVE = 1;
11
+ const ROLE_NAME = 'DataFeedWatch';
12
+ const ROLE_TYPE = 'G';
13
+ const ROLE_PID = false;
14
+ const RULE_RESOURCES = 'all';
15
+
16
+ /** @var string $decodedApiKey */
17
+ private $decodedApiKey;
18
+
19
+ public function createDfwUser()
20
+ {
21
+ $role = $this->createDfwUserRole();
22
+ $this->generateApiKey();
23
+ $this->addUserData();
24
+ $this->save();
25
+ $this->setRoleId($role->getId())->setUserId($this->getId());
26
+ $this->add();
27
+ $this->sendNewApiKeyToDfw();
28
+ }
29
+
30
+ /**
31
+ * @return string
32
+ */
33
+ public function getDecodedApiKey()
34
+ {
35
+ return $this->decodedApiKey;
36
+ }
37
+
38
+ /**
39
+ * @return Polytab_OmniPixel_Model_Api_User
40
+ */
41
+ public function loadDfwUser()
42
+ {
43
+ return $this->load(self::USER_EMAIL, 'email');
44
+ }
45
+
46
+ /**
47
+ * @return Mage_Api_Model_Roles
48
+ * @throws Exception
49
+ */
50
+ protected function createDfwUserRole()
51
+ {
52
+ $role = Mage::getModel('api/roles')->load(self::ROLE_NAME, 'role_name');
53
+
54
+ $data = array(
55
+ 'name' => self::ROLE_NAME,
56
+ 'pid' => self::ROLE_PID,
57
+ 'role_type' => self::ROLE_TYPE,
58
+ );
59
+
60
+ $role->addData($data);
61
+ $role->save();
62
+
63
+ Mage::getModel('api/rules')
64
+ ->setRoleId($role->getId())
65
+ ->setResources(array(self::RULE_RESOURCES))
66
+ ->saveRel();
67
+
68
+ return $role;
69
+ }
70
+
71
+ protected function generateApiKey()
72
+ {
73
+ $this->decodedApiKey = sha1(time() . substr(str_shuffle(self::API_KEY_SHUFFLE_STRING), 0, self::API_KEY_LENGTH));
74
+ }
75
+
76
+ protected function addUserData()
77
+ {
78
+ $data = array(
79
+ 'username' => self::USER_NAME,
80
+ 'firstname' => self::USER_FIRST_NAME,
81
+ 'lastname' => self::USER_LAST_NAME,
82
+ 'is_active' => self::USER_IS_ACTIVE,
83
+ 'api_key' => $this->decodedApiKey,
84
+ 'email' => self::USER_EMAIL,
85
+ 'api_key_confirmation' => $this->decodedApiKey,
86
+ );
87
+
88
+ $this->addData($data);
89
+ }
90
+
91
+ protected function sendNewApiKeyToDfw()
92
+ {
93
+ file_get_contents($this->getRegisterUrl());
94
+ }
95
+
96
+ public function getRegisterUrl()
97
+ {
98
+ $registerUrl = sprintf('%splatforms/magento/sessions/finalize',
99
+ $this->_helper()->getDataFeedWatchUrl());
100
+
101
+ return $registerUrl . '?shop=' . Mage::getBaseUrl() . '&token=' . $this->getDecodedApiKey();
102
+ }
103
+
104
+ /**
105
+ * @return Polytab_OmniPixel_Helper_Data
106
+ */
107
+ public function _helper()
108
+ {
109
+ return Mage::helper('omnipixel');
110
+ }
111
+ }
app/code/community/Polytab/OmniPixel/Model/Cron.php ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Cron extends Mage_Catalog_Model_Resource_Product_Collection
4
+ {
5
+ const CATALOGRULE_DATE_TABLE_ALIAS = 'catalogrule_product_price_date';
6
+
7
+ /**
8
+ * @return $this
9
+ * @throws Mage_Core_Exception
10
+ */
11
+ public function reindex()
12
+ {
13
+ $date = date('Y-m-d H:i:s');
14
+ $lastPriceId = $this->helper()->getLastCatalogRulePriceId();
15
+ $resource = Mage::getSingleton('core/resource');
16
+ $writeConnection = $resource->getConnection('core_write');
17
+ $select = new Zend_Db_Select($this->getEntity()->getReadConnection());
18
+ $select->from(
19
+ array(
20
+ self::CATALOGRULE_DATE_TABLE_ALIAS => $this->getTable('catalogrule/rule_product_price'),
21
+ )
22
+ );
23
+
24
+ if (!empty($lastPriceId)) {
25
+ $select->where('rule_product_price_id > ?', $lastPriceId);
26
+ }
27
+ $select->where('customer_group_id = ?', Mage_Customer_Model_Group::NOT_LOGGED_IN_ID);
28
+ $select->where('rule_date <= ?', $date);
29
+
30
+ $priceData = $select->query()->fetchAll();
31
+ if (count($priceData) < 1) {
32
+
33
+ return $this;
34
+ }
35
+
36
+ $this->helper()->cronLog($select->__toString());
37
+ $this->helper()->cronLog(count($priceData));
38
+
39
+ $updatedDataTable = $this->getTable('omnipixel/updated_products');
40
+ foreach ($priceData as $data) {
41
+ $insertedData = array(
42
+ 'dfw_prod_id' => $data['product_id'],
43
+ 'updated_at' => $date,
44
+ );
45
+ $writeConnection->insertOnDuplicate($updatedDataTable, $insertedData, array('updated_at'));
46
+ }
47
+
48
+ if (!empty($priceData)) {
49
+ $data = end($priceData);
50
+ $this->helper()->setLastCatalogRulePriceId($data['rule_product_price_id']);
51
+ }
52
+
53
+ return $this;
54
+ }
55
+
56
+ /**
57
+ * @return Polytab_OmniPixel_Helper_Data
58
+ */
59
+ public function helper()
60
+ {
61
+ return Mage::helper('omnipixel');
62
+ }
63
+ }
app/code/community/Polytab/OmniPixel/Model/Observer.php ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Observer
4
+ {
5
+ /**
6
+ * @param Varien_Event_Observer $observer
7
+ * @return $this
8
+ */
9
+ public function addInheritanceFieldToAttributeForm(Varien_Event_Observer $observer)
10
+ {
11
+ $form = $observer->getForm();
12
+ $fieldset = $form->getElement('base_fieldset');
13
+ $attribute = $observer->getAttribute();
14
+ $fieldset->addField('import_to_dfw', 'select', array(
15
+ 'name' => 'import_to_dfw',
16
+ 'label' => Mage::helper('omnipixel')->__('Import To DataFeedWatch'),
17
+ 'values' => Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray(),
18
+ 'disabled' => $attribute->hasCanConfigureImport() && !$attribute->getCanConfigureImport(),
19
+ ), 'is_configurable');
20
+ $fieldset->addField('inheritance', 'select', array(
21
+ 'name' => 'inheritance',
22
+ 'label' => Mage::helper('omnipixel')->__('DataFeedWatch Inheritance'),
23
+ 'values' => Mage::getModel('omnipixel/system_config_source_inheritance')->toOptionArray(),
24
+ 'disabled' => $attribute->hasCanConfigureImport() && !$attribute->getCanConfigureInheritance(),
25
+ ), 'import_to_dfw');
26
+
27
+ return $this;
28
+ }
29
+
30
+ /**
31
+ * @param Varien_Event_Observer $observer
32
+ * @return $this
33
+ */
34
+ public function updateLastInheritanceUpdateDateOnCategoryChangeName(Varien_Event_Observer $observer)
35
+ {
36
+ $category = $observer->getCategory();
37
+ if($category instanceof Varien_Object && $category->dataHasChangedFor('name')) {
38
+ $this->helper()->updateLastInheritanceUpdateDate();
39
+ }
40
+
41
+ return $this;
42
+ }
43
+
44
+ /**
45
+ * @param Varien_Event_Observer $observer
46
+ * @return $this
47
+ */
48
+ public function updateLastInheritanceUpdateDate(Varien_Event_Observer $observer)
49
+ {
50
+ $this->helper()->updateLastInheritanceUpdateDate();
51
+
52
+ return $this;
53
+ }
54
+
55
+ /**
56
+ * @param Varien_Event_Observer $observer
57
+ * @return $this
58
+ */
59
+ public function removeProductFromUpdatedTable(Varien_Event_Observer $observer)
60
+ {
61
+ /** @var Mage_Catalog_Model_Product $product */
62
+ $product = $observer->getProduct();
63
+ $resource = Mage::getSingleton('core/resource');
64
+ $connection = $resource->getConnection('core_write');
65
+ $connection->delete(Mage::getModel('core/resource')->getTableName('omnipixel/updated_products'),
66
+ sprintf('dfw_prod_id = %s', $product->getId()));
67
+
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * @param Varien_Event_Observer $observer
73
+ * @return $this
74
+ */
75
+ public function updateInheritanceUpdateDate(Varien_Event_Observer $observer)
76
+ {
77
+ /** @var Mage_Adminhtml_Model_Config_Data $configModel */
78
+ $configModel = $observer->getObject();
79
+ if ($configModel->getSection() !== 'omnipixel') {
80
+
81
+ return $this;
82
+ }
83
+
84
+ $productUrlXpath = Polytab_OmniPixel_Helper_Data::PRODUCT_URL_CUSTOM_INHERITANCE_XPATH;
85
+ $imageUrlXpath = Polytab_OmniPixel_Helper_Data::IMAGE_URL_CUSTOM_INHERITANCE_XPATH;
86
+
87
+ if ($this->hasConfigDataChanged($configModel, $productUrlXpath)
88
+ || $this->hasConfigDataChanged($configModel, $imageUrlXpath)) {
89
+ $this->helper()->updateLastInheritanceUpdateDate();
90
+ }
91
+
92
+ return $this;
93
+ }
94
+
95
+ /**
96
+ * @param Mage_Adminhtml_Model_Config_Data $configModel
97
+ * @param string $xpath
98
+ * @return null
99
+ */
100
+ protected function getConfigDataFromXpath($configModel, $xpath)
101
+ {
102
+ $xpath = explode('/', $xpath);
103
+ if (!is_array($xpath)) {
104
+ return null;
105
+ }
106
+
107
+ if (count($xpath) === 3) {
108
+ unset($xpath[0]);
109
+ }
110
+
111
+ try {
112
+ $group = reset($xpath);
113
+ $field = end($xpath);
114
+ $configPath = $configModel->getGroups();
115
+ if (is_array($configPath) && array_key_exists($group, $configPath)) {
116
+ $configPath = $configPath[$group];
117
+ } else {
118
+ return null;
119
+ }
120
+ if (is_array($configPath) && array_key_exists('fields', $configPath)) {
121
+ $configPath = $configPath['fields'];
122
+ } else {
123
+ return null;
124
+ }
125
+ if (is_array($configPath) && array_key_exists($field, $configPath)) {
126
+ $configPath = $configPath[$field];
127
+ } else {
128
+ return null;
129
+ }
130
+
131
+ if (is_array($configPath) && array_key_exists('value', $configPath)) {
132
+ return $configPath['value'];
133
+ } else {
134
+ return null;
135
+ }
136
+ } catch (Exception $e) {
137
+ $this->helper()->log($e->getMessage());
138
+
139
+ return null;
140
+ }
141
+ }
142
+
143
+ public function checkAndUpdateAttributeInheritance(Varien_Event_Observer $observer)
144
+ {
145
+ $attribute = $observer->getAttribute();
146
+ if (!$attribute->getCanConfigureImport() && !$attribute->isObjectNew()) {
147
+ $attribute->setImportToDfw($attribute->getOrigData('import_to_dfw'));
148
+ }
149
+ if ($attribute->hasCanConfigureInheritance() && !$attribute->getCanConfigureInheritance() && !$attribute->isObjectNew()) {
150
+ $attribute->setInheritance($attribute->getOrigData('inheritance'));
151
+ }
152
+
153
+ if ($this->canSaveUpdateDate($attribute)) {
154
+ $this->helper()->updateLastInheritanceUpdateDate();
155
+ }
156
+
157
+ return $this;
158
+ }
159
+
160
+ /**
161
+ * @param $attribute
162
+ *
163
+ * @return bool
164
+ */
165
+ protected function canSaveUpdateDate($attribute)
166
+ {
167
+ return ($attribute->dataHasChangedFor('inheritance') && (int)$attribute->getOrigData('import_to_dfw') === 1)
168
+ || $attribute->dataHasChangedFor('import_to_dfw')
169
+ || (int)$attribute->getData('import_to_dfw') === 1
170
+ || $attribute->isObjectNew();
171
+ }
172
+
173
+ public function changeChildProductUpdatedAt(Varien_Event_Observer $observer)
174
+ {
175
+ /** @var Mage_Catalog_Model_Product $product */
176
+ $product = $observer->getProduct();
177
+
178
+ if ($product->isConfigurable()) {
179
+ $childProducts = $product->getTypeInstance(true)->getUsedProducts(null, $product);
180
+ foreach ($childProducts as $child) {
181
+ $child->setUpdatedAt($product->getUpdatedAt())->save();
182
+ }
183
+ }
184
+
185
+ return $this;
186
+ }
187
+
188
+ /**
189
+ * @param Mage_Adminhtml_Model_Config_Data $configModel
190
+ * @param string $xpath
191
+ * @return bool
192
+ */
193
+ protected function hasConfigDataChanged($configModel, $xpath)
194
+ {
195
+ return $configModel->getConfigDataValue($xpath) !== $this->getConfigDataFromXpath($configModel, $xpath);
196
+ }
197
+
198
+ /**
199
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
200
+ * @return bool
201
+ */
202
+ protected function isProductEntityType($attribute)
203
+ {
204
+ $productEntityType = Mage::getResourceModel('catalog/product')->getEntityType()->getEntityTypeId();
205
+
206
+ return $productEntityType === $attribute->getEntityTypeId();
207
+ }
208
+
209
+ /**
210
+ * @return Polytab_OmniPixel_Helper_Data
211
+ */
212
+ public function helper()
213
+ {
214
+ return Mage::helper('omnipixel');
215
+ }
216
+ }
app/code/community/Polytab/OmniPixel/Model/Omnipixelsetting.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @method Polytab_OmniPixel_Model_Product getParent()
4
+ */
5
+
6
+ class Polytab_OmniPixel_Model_Omnipixelsetting extends Mage_Core_Model_Abstract
7
+ {
8
+
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('omnipixel/omnipixelsetting');
14
+ }
15
+
16
+ /**
17
+ * @return array
18
+ */
19
+
20
+ }
app/code/community/Polytab/OmniPixel/Model/Product.php ADDED
@@ -0,0 +1,414 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @method Polytab_OmniPixel_Model_Product getParent()
4
+ */
5
+
6
+ class Polytab_OmniPixel_Model_Product extends Mage_Catalog_Model_Product
7
+ {
8
+ /** @var array $importData */
9
+ protected $importData = array();
10
+
11
+ protected function _construct()
12
+ {
13
+ $this->_init('omnipixel/product');
14
+ }
15
+
16
+ /**
17
+ * @return array
18
+ */
19
+ public function getDataToImport()
20
+ {
21
+ $parent = $this->getParent();
22
+ if ($this->registryHelper()->isStatusAttributeInheritable()) {
23
+ $this->setStatus($this->getFilterStatus());
24
+ }
25
+ $date = $this->getRuleDate();
26
+ $date = new DateTime($date);
27
+ $this->setUpdatedAt($date->format('Y-m-d H:i:s'));
28
+ $this->fillAllAttributesData();
29
+ $this->importData['product_id'] = $this->getId();
30
+ $this->importData['sku'] = $this->getSku();
31
+ $this->importData['product_type'] = $this->getTypeId();
32
+ $this->importData['quantity'] = (int) $this->getQty();
33
+ $this->importData['currency_code'] = $this->getStore()->getCurrentCurrencyCode();
34
+ $this->importData['price'] = $this->getImportPrice(false);
35
+ $this->importData['price_with_tax'] = $this->getImportPrice(true);
36
+ $this->importData['special_price'] = $this->getImportSpecialPrice(false);
37
+ $this->importData['special_price_with_tax'] = $this->getImportSpecialPrice(true);
38
+ $this->importData['special_from_date'] = $this->getSpecialFromDate();
39
+ $this->importData['special_to_date'] = $this->getSpecialToDate();
40
+ $this->importData['image_url'] = $this->getBaseImageUrl();
41
+ $this->importData['product_url'] = $this->getProductUrl();
42
+ $this->importData['product_url_rewritten'] = $this->getProductUrlRewritten();
43
+ $this->importData['is_in_stock'] = (int) $this->getIsInStock();
44
+ $this->getCategoryPathToImport();
45
+ $this->setDataToImport($this->getCategoriesNameToImport(false));
46
+
47
+ if (!empty($parent)) {
48
+ $this->importData['parent_id'] = $parent->getId();
49
+ $this->importData['parent_sku'] = $parent->getSku();
50
+ $this->importData['parent_price'] = $parent->getImportPrice(false);
51
+ $this->importData['parent_price_with_tax'] = $parent->getImportPrice(true);
52
+ $this->importData['parent_special_price'] = $parent->getImportSpecialPrice(false);
53
+ $this->importData['parent_special_price_with_tax'] = $parent->getImportSpecialPrice(true);
54
+ $this->importData['parent_special_from_date'] = $parent->getSpecialFromDate();
55
+ $this->importData['parent_special_to_date'] = $parent->getSpecialToDate();
56
+ $this->importData['parent_url'] = $parent->getProductUrl();
57
+
58
+ if ($this->helper()->isProductUrlInherited()) {
59
+ $this->importData['product_url'] = $this->importData['parent_url'];
60
+ }
61
+
62
+ $this->setDataToImport($parent->getCategoriesNameToImport(true));
63
+ if ($parent->isConfigurable()) {
64
+ $this->importData['variant_spac_price'] = $parent->getVariantSpacPrice($this, false);
65
+ $this->importData['variant_spac_price_with_tax'] = $parent->getVariantSpacPrice($this, true);
66
+ $this->importData['variant_name'] = $this->getName();
67
+ $this->getDfwDefaultVariant();
68
+ }
69
+ }
70
+
71
+ $this->getExcludedImages();
72
+ $this->setDataToImport($this->getAdditionalImages($this->importData['image_url'], false));
73
+ if (!empty($parent)) {
74
+ if ($this->helper()->isImageUrlInherited()) {
75
+ $this->importData['image_url'] = $parent->getBaseImageUrl();
76
+ }
77
+ $this->setDataToImport($parent->getAdditionalImages($this->importData['image_url'], true));
78
+ }
79
+
80
+ return $this->importData;
81
+ }
82
+
83
+ /**
84
+ * @param string $key
85
+ * @param mixed $data
86
+ * @return Varien_Object
87
+ */
88
+ public function setOrigData($key = null, $data = null)
89
+ {
90
+ if (is_null($key)) {
91
+ $this->_origData = $this->_data;
92
+ } else {
93
+ $this->_origData[$key] = $data;
94
+ }
95
+ return $this;
96
+ }
97
+
98
+ /**
99
+ * @return $this
100
+ */
101
+ protected function fillAllAttributesData()
102
+ {
103
+ $productAttributes = array_keys($this->getAttributes());
104
+ $attributeCollection = Mage::registry(Polytab_OmniPixel_Helper_Registry::ALL_IMPORTABLE_ATTRIBUTES_KEY);
105
+ foreach ($attributeCollection as $attribute) {
106
+ $attributeCode = $attribute->getAttributeCode();
107
+ if (empty($attributeCode) || !in_array($attributeCode, $productAttributes)) {
108
+ continue;
109
+ }
110
+ $value = $attribute->getFrontend()->getValue($this);
111
+ if ($attribute->getBackendType() === 'int' && $value === 'N/A') {
112
+ $value = '';
113
+ }
114
+ $this->importData[$attributeCode] = $value;
115
+ }
116
+
117
+ return $this;
118
+ }
119
+
120
+ /**
121
+ * @param array $data
122
+ */
123
+ protected function setDataToImport($data)
124
+ {
125
+ foreach ($data as $key => $value) {
126
+ $this->importData[$key] = $value;
127
+ }
128
+ }
129
+
130
+ /**
131
+ * @param bool $withTax
132
+ * @return float
133
+ */
134
+ protected function getImportPrice($withTax = false)
135
+ {
136
+ $price = $this->getStore()->roundPrice($this->getStore()->convertPrice($this->getFinalPrice()));
137
+ return $this->getTaxHelper()->getPrice($this, $price, $withTax);
138
+ }
139
+
140
+ /**
141
+ * @param bool $withTax
142
+ * @return float
143
+ */
144
+ protected function getImportSpecialPrice($withTax = false)
145
+ {
146
+ return $this->getTaxHelper()->getPrice($this, $this->getSpecialPrice(), $withTax);
147
+ }
148
+
149
+ /**
150
+ * @param Polytab_OmniPixel_Model_Product $child
151
+ * @param bool $withTax
152
+ * @return float
153
+ */
154
+ protected function getVariantSpacPrice($child, $withTax = false)
155
+ {
156
+ if (!$this->isConfigurable()) {
157
+ return null;
158
+ }
159
+ $attributes = $this->getTypeInstance(true)->getConfigurableAttributes($this);
160
+ $pricesByAttributeValues = array();
161
+ $basePrice = $this->getFinalPrice();
162
+ foreach ($attributes as $attribute) {
163
+ $prices = $attribute->getPrices();
164
+ foreach ($prices as $price) {
165
+ if ($price['is_percent']) {
166
+ $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
167
+ } else {
168
+ $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
169
+ }
170
+ }
171
+ }
172
+ $totalPrice = $basePrice;
173
+ foreach ($attributes as $attribute) {
174
+ $value = $child->getData($attribute->getProductAttribute()->getAttributeCode());
175
+ if (isset($pricesByAttributeValues[$value])) {
176
+ $totalPrice += $pricesByAttributeValues[$value];
177
+ }
178
+ }
179
+
180
+ return $this->getTaxHelper()->getPrice($this, $totalPrice, $withTax);
181
+ }
182
+
183
+ /**
184
+ * @return $this
185
+ */
186
+ protected function getCategoryPathToImport()
187
+ {
188
+ $index = '';
189
+ $categoriesCollection = Mage::registry(Polytab_OmniPixel_Helper_Registry::ALL_CATEGORIES_ARRAY_KEY);
190
+ foreach ($this->getCategoryCollection()->addNameToResult() as $category) {
191
+
192
+ $categoryName = array();
193
+ $path = $category->getPath();
194
+ foreach (explode('/', $path) as $categoryId) {
195
+ if (isset($categoriesCollection[$categoryId])) {
196
+ $categoryName[] = $categoriesCollection[$categoryId]->getName();
197
+ }
198
+ }
199
+ if (!empty($categoryName)) {
200
+ $key = 'category_path' . $index;
201
+ $this->importData[$key] = implode(' > ', $categoryName);
202
+ $index++;
203
+ }
204
+ }
205
+
206
+ return $this;
207
+ }
208
+
209
+ /**
210
+ * @param bool $isParent
211
+ * @return array
212
+ */
213
+ protected function getCategoriesNameToImport($isParent = false)
214
+ {
215
+ $index = '';
216
+ $names = array();
217
+ foreach ($this->getCategoryCollection()->addNameToResult() as $category) {
218
+ $key = $isParent ? 'category_parent_name' : 'category_name';
219
+ $key .= $index++;
220
+ $names[$key] = $category->getName();
221
+ }
222
+
223
+ return $names;
224
+ }
225
+
226
+ /**
227
+ * @return string|null
228
+ */
229
+ protected function getBaseImageUrl()
230
+ {
231
+ $this->load('image');
232
+ $image = $this->getImage();
233
+ if ($image !== 'no_selection' && !empty($image)) {
234
+
235
+ return $this->getMediaConfig()->getMediaUrl($image);
236
+ }
237
+
238
+ return null;
239
+ }
240
+
241
+ /**
242
+ * @param null|string $importedBaseImage
243
+ * @param bool $isParent
244
+ * @return array
245
+ */
246
+ protected function getAdditionalImages($importedBaseImage = null, $isParent = false)
247
+ {
248
+ if (empty($importedBaseImage)) {
249
+ $this->getBaseImageUrl();
250
+ }
251
+ $this->load('media_gallery');
252
+ $gallery = $this->getMediaGalleryImages();
253
+
254
+ $index = 1;
255
+ $additionalImages = array();
256
+ foreach ($gallery as $image) {
257
+ $imageUrl = $image->getUrl();
258
+ if ($imageUrl !== $importedBaseImage && $imageUrl !== 'no_selection' && !empty($imageUrl)) {
259
+ $key = $isParent ? 'parent_additional_image_url' : 'product_additional_image_url';
260
+ $key .= $index++;
261
+ $additionalImages[$key] = $imageUrl;
262
+ }
263
+ }
264
+
265
+ return $additionalImages;
266
+ }
267
+
268
+ /**
269
+ * @return $this
270
+ */
271
+ protected function getExcludedImages()
272
+ {
273
+ $this->load('media_gallery');
274
+ $gallery = $this->getMediaGallery('images');
275
+ $index = 1;
276
+ foreach ($gallery as $image) {
277
+ if ($image['disabled']) {
278
+ $imageUrl = $this->getMediaConfig()->getMediaUrl($image['file']);
279
+ $key = 'image_url_excluded' . $index++;
280
+ $this->importData[$key] = $imageUrl;
281
+ }
282
+ }
283
+
284
+ return $this;
285
+ }
286
+
287
+ /**
288
+ * @param null|Mage_Catalog_Model_Category $category
289
+ * @return string
290
+ * @throws Mage_Core_Exception
291
+ */
292
+ public function getProductUrlRewritten($category = null)
293
+ {
294
+ if (!empty($category)) {
295
+ $categoryId = $category->getId();
296
+ }
297
+ $productId = $this->getId();
298
+ $store = $this->getStore();
299
+ $storeId = $store->getId();
300
+ $coreUrl = Mage::getModel('core/url_rewrite');
301
+ $idPath = sprintf('product/%d', $productId);
302
+
303
+ if (!empty($categoryId)) {
304
+ $idPath = sprintf('%s/%d', $idPath, $categoryId);
305
+ }
306
+ $coreUrl->setStoreId($storeId);
307
+ $coreUrl->loadByIdPath($idPath);
308
+ $requestPath = $coreUrl->getRequestPath();
309
+ if (empty($requestPath)) {
310
+ return '';
311
+ }
312
+
313
+ return $store->getBaseUrl() . $requestPath;
314
+ }
315
+
316
+ /**
317
+ * @return $this
318
+ */
319
+ protected function getDfwDefaultVariant()
320
+ {
321
+ $parent = $this->getParent();
322
+ if (empty($parent)) {
323
+ return $this;
324
+ }
325
+
326
+ $superAttributes = Mage::registry(Polytab_OmniPixel_Helper_Registry::ALL_SUPER_ATTRIBUTES_KEY);
327
+ $parentSuperAttributes = $parent->getData('super_attribute_ids');
328
+ $parentSuperAttributes = explode(',', $parentSuperAttributes);
329
+ $this->importData['dfw_default_variant'] = 1;
330
+ foreach ($parentSuperAttributes as $superAttributeId) {
331
+ if (!isset($superAttributes[$superAttributeId])) {
332
+ continue;
333
+ }
334
+ $superAttribute = $superAttributes[$superAttributeId];
335
+ $defaultValue = $superAttribute->getDefaultValue();
336
+ if (!empty($defaultValue) && $defaultValue !== $this->getData($superAttribute->getAttributeCode())) {
337
+ $this->importData['dfw_default_variant'] = 0;
338
+
339
+ return $this;
340
+ }
341
+ }
342
+
343
+ return $this;
344
+ }
345
+
346
+ /**
347
+ * @return $this
348
+ */
349
+ public function getParentAttributes()
350
+ {
351
+ $parent = $this->getParent();
352
+ if (empty($parent)) {
353
+
354
+ return $this;
355
+ }
356
+ $allAttributes = Mage::registry(Polytab_OmniPixel_Helper_Registry::ALL_ATTRIBUTE_COLLECTION_KEY);
357
+ foreach ($allAttributes as $attribute) {
358
+ $attributeCode = $attribute->getAttributeCode();
359
+ switch ($attribute->getInheritance()) {
360
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_THEN_PARENT_OPTION_ID:
361
+ $productData = $this->getData($attributeCode);
362
+ if (empty($productData) || $this->shouldChangeVisibilityForProduct($attribute)) {
363
+ $parentData = $parent->getData($attributeCode);
364
+ $this->setData($attributeCode, $parentData);
365
+ }
366
+ break;
367
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::PARENT_OPTION_ID:
368
+ $parentData = $parent->getData($attributeCode);
369
+ if ($attributeCode === 'meta_title') {
370
+ }
371
+ $this->setData($attributeCode, $parentData);
372
+ break;
373
+ }
374
+ }
375
+
376
+ return $this;
377
+ }
378
+
379
+ /**
380
+ * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
381
+ * @return bool
382
+ */
383
+ public function shouldChangeVisibilityForProduct($attribute)
384
+ {
385
+ $attributeCode = $attribute->getAttributeCode();
386
+
387
+ return $attributeCode === 'visibility'
388
+ && (int)$this->getData($attributeCode) === Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE;
389
+ }
390
+
391
+ /**
392
+ * @return Mage_Tax_Helper_Data
393
+ */
394
+ public function getTaxHelper()
395
+ {
396
+ return Mage::helper('tax');
397
+ }
398
+
399
+ /**
400
+ * @return Polytab_OmniPixel_Helper_Data
401
+ */
402
+ public function helper()
403
+ {
404
+ return Mage::helper('omnipixel');
405
+ }
406
+
407
+ /**
408
+ * @return Polytab_OmniPixel_Helper_Registry
409
+ */
410
+ public function registryHelper()
411
+ {
412
+ return Mage::helper('omnipixel/registry');
413
+ }
414
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Omnipixelsetting.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Model_Resource_Omnipixelsetting extends Mage_Core_Model_Resource_Db_Abstract{
3
+ public function _construct(){
4
+ $this->_init('omnipixel/omnipixelsetting', 'id');
5
+ }
6
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Omnipixelsetting/Collection.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Omnipixelsetting_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{
4
+ protected function _construct(){
5
+ parent::_construct();
6
+ $this->_init('omnipixel/omnipixelsetting');
7
+ }
8
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Omnipixelsetting/Collection/Db.php ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Product_Collection_Db extends Mage_Catalog_Model_Resource_Product_Collection{
4
+ const INHERITED_STATUS_TABLE_ALIAS = 'inherited_status';
5
+ const INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE = 'inherited_status_default_store';
6
+ const ORIGINAL_STATUS_TABLE_ALIAS = 'original_status';
7
+ const ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE = 'status_default_store';
8
+ const ORIGINAL_VISIBILITY_TABLE_ALIAS = 'original_visibility';
9
+ const VISIBILITY_TABLE_ALIAS_DEFAULT_STORE = 'visibility_default_store';
10
+ const PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE = 'dfw_parent_ids_default_store';
11
+ const ORIGINAL_PARENT_IDS_TABLE_ALIAS = 'original_dfw_parent_ids';
12
+ const MIXED_STATUS_COLUMN_ALIAS = 'filter_status';
13
+ const PARENT_CONFIGURABLE_ATTRIBUTES_TABLE_ALIAS = 'parent_configurable_attributes';
14
+ const PARENT_RELATIONS_TABLE_ALIAS = 'parent_relation';
15
+ const UPDATED_AT_TABLE_ALIAS = 'custom_updated_at';
16
+ const CATALOGRULE_DATE_COLUMN_ALIAS = 'rule_date';
17
+
18
+ /** @var string $filterStatusCondition */
19
+ protected $filterStatusCondition;
20
+ /** @var array $optionsFilters */
21
+ protected $optionsFilters;
22
+ /** @var string $ruleDateSelect */
23
+ protected $ruleDateSelect;
24
+
25
+ /**
26
+ * @param string $tableAlias
27
+ * @return bool
28
+ * @throws Zend_Db_Select_Exception
29
+ */
30
+ protected function isTableAliasAdded($tableAlias){
31
+ $tables = $this->getSelect()->getPart(Zend_Db_Select::FROM);
32
+ $currentAliases = array_keys($tables);
33
+
34
+ return in_array($tableAlias, $currentAliases);
35
+
36
+ }
37
+
38
+ /**
39
+ * @return $this
40
+ */
41
+ protected function addRuleDate(){
42
+ /** @var Polytab_OmniPixel_Model_Cron $cron */
43
+ $cron = Mage::getModel('omnipixel/cron');
44
+ $cron->reindex();
45
+
46
+ $condition = $this->getUpdatedAtCondition();
47
+ $select = new Zend_Db_Select($this->getEntity()->getReadConnection());
48
+ $select->from(
49
+ array(
50
+ self::UPDATED_AT_TABLE_ALIAS => $this->getTable('omnipixel/updated_products'),
51
+ ),
52
+ array(
53
+ sprintf('COALESCE(%1$s.updated_at, 0)', self::UPDATED_AT_TABLE_ALIAS),
54
+ )
55
+ );
56
+ $select->where($condition);
57
+ $select->limit(1);
58
+
59
+ $this->ruleDateSelect = sprintf('GREATEST(IFNULL((%s), 0), COALESCE(%2$s.updated_at, 0))',
60
+ $select->__toString(), self::MAIN_TABLE_ALIAS);
61
+ $this->getSelect()->columns(array(self::CATALOGRULE_DATE_COLUMN_ALIAS => new Zend_Db_Expr($this->ruleDateSelect)));
62
+
63
+ return $this;
64
+ }
65
+
66
+ /**
67
+ * @return string
68
+ * @throws Mage_Core_Exception
69
+ */
70
+ protected function getUpdatedAtCondition(){
71
+ $condition = '(IFNULL(%3$s.value, %4$s.value) IS NOT NULL AND %1$s.dfw_prod_id IN (IFNULL(%3$s.value, %4$s.value)) OR %1$s.dfw_prod_id = %2$s.entity_id)';
72
+ $condition = sprintf($condition,
73
+ self::UPDATED_AT_TABLE_ALIAS, self::MAIN_TABLE_ALIAS, self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE);
74
+
75
+ return $condition;
76
+ }
77
+
78
+ /**
79
+ * @return $this
80
+ * @throws Mage_Core_Exception
81
+ */
82
+ protected function joinQty(){
83
+ $this->joinField('qty',
84
+ 'cataloginventory/stock_item',
85
+ 'qty',
86
+ 'product_id=entity_id',
87
+ '{{table}}.stock_id=1',
88
+ 'left');
89
+
90
+ return $this;
91
+ }
92
+ /**
93
+ * @return string
94
+ * @throws Mage_Core_Exception
95
+ */
96
+ protected function getStatusTable(){
97
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)
98
+ ->getBackend()->getTable();
99
+ }
100
+
101
+ /**
102
+ * @return string
103
+ * @throws Mage_Core_Exception
104
+ */
105
+ protected function getVisibilityTable(){
106
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)
107
+ ->getBackend()->getTable();
108
+ }
109
+
110
+ /**
111
+ * @return string|int
112
+ * @throws Mage_Core_Exception
113
+ */
114
+ protected function getVisibilityAttributeId(){
115
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)->getAttributeId();
116
+ }
117
+
118
+ protected function buildFilterStatusCondition(){
119
+ $childString = 'IFNULL(%1$s.value, %3$s.value)';
120
+ $parentString = 'IFNULL(%2$s.value, %4$s.value)';
121
+ $enable = Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
122
+ $statusAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY);
123
+ switch($statusAttribute->getInheritance()){
124
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_THEN_PARENT_OPTION_ID:
125
+ $inheritString = "IFNULL({$childString}, {$parentString})";
126
+ // $inheritWithStatusString = 'IFNULL(
127
+ // IF(' . $childString . ' <> ' . $enable . ', ' . $parentString . ', ' . $childString . '),
128
+ // ' . $childString
129
+ // . ')';
130
+ $notVisibleIndividually = "IF({$childString} <> {$enable}, {$childString}, {$parentString})";
131
+ $string = 'IF(IFNULL(%5$s.value, %6$s.value) = '. Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
132
+ . ', ' . $notVisibleIndividually .', '. $inheritString.')';
133
+ break;
134
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::PARENT_OPTION_ID:
135
+ $string = 'IFNULL(' . $parentString . ', ' . $childString . ')';
136
+ break;
137
+ default :
138
+ $string = $childString;
139
+ }
140
+ $this->filterStatusCondition = sprintf($string,
141
+ self::ORIGINAL_STATUS_TABLE_ALIAS, self::INHERITED_STATUS_TABLE_ALIAS,
142
+ self::ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE, self::INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE,
143
+ self::ORIGINAL_VISIBILITY_TABLE_ALIAS, self::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE
144
+ );
145
+ }
146
+
147
+ /**
148
+ * @param string $tableAlias
149
+ * @param string $storeId
150
+ * @return $this
151
+ */
152
+ protected function joinInheritedStatusTable($tableAlias = self::INHERITED_STATUS_TABLE_ALIAS, $storeId = '0'){
153
+ if($this->isTableAliasAdded($tableAlias)){
154
+
155
+ return $this;
156
+ }
157
+
158
+ $this->getSelect()->joinLeft(
159
+ array($tableAlias => $this->getStatusTable()),
160
+ $this->getJoinInheritedStatusTableStatement($tableAlias, $storeId),
161
+ array(self::MIXED_STATUS_COLUMN_ALIAS => $this->filterStatusCondition));
162
+
163
+ return $this;
164
+ }
165
+
166
+ /**
167
+ * @param string $tableAlias
168
+ * @param string $storeId
169
+ * @return string
170
+ */
171
+ protected function getJoinInheritedStatusTableStatement($tableAlias, $storeId){
172
+ return sprintf('%1$s.entity_id IN (IFNULL(%2$s.value, %3$s.value)) and %4$s',
173
+ $tableAlias, self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE,
174
+ $this->getJoinStatusAttributeStatement($tableAlias, $storeId)
175
+ );
176
+ }
177
+
178
+ /**
179
+ * @param string $tableAlias
180
+ * @param string $storeId
181
+ * @return $this
182
+ */
183
+ protected function joinOriginalStatusTable($tableAlias = self::ORIGINAL_STATUS_TABLE_ALIAS, $storeId = '0'){
184
+ if($this->isTableAliasAdded($tableAlias)){
185
+
186
+ return $this;
187
+ }
188
+
189
+ $this->getSelect()->joinLeft(
190
+ array($tableAlias => $this->getStatusTable()),
191
+ $this->getJoinOriginalStatusTableStatement($tableAlias, $storeId),
192
+ array(self::MIXED_STATUS_COLUMN_ALIAS => $this->filterStatusCondition));
193
+
194
+ return $this;
195
+ }
196
+
197
+ /**
198
+ * @param string $tableAlias
199
+ * @param string $storeId
200
+ * @return $this
201
+ */
202
+ protected function joinVisibilityTable($tableAlias = self::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE, $storeId = '0'){
203
+ if($this->isTableAliasAdded($tableAlias)){
204
+
205
+ return $this;
206
+ }
207
+
208
+ $this->getSelect()->joinLeft(
209
+ array($tableAlias => $this->getVisibilityTable()),
210
+ $this->getJoinVisibilityTableStatement($tableAlias, $storeId),
211
+ array('value'));
212
+
213
+ return $this;
214
+ }
215
+
216
+ /**
217
+ * @param string $tableAlias
218
+ * @param string $storeId
219
+ * @return string
220
+ */
221
+ protected function getJoinVisibilityTableStatement($tableAlias, $storeId){
222
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
223
+ $tableAlias, $this->getJoinVisibilityAttributeStatement($tableAlias, $storeId)
224
+ );
225
+ }
226
+
227
+ /**
228
+ * @param string $tableAlias
229
+ * @param string $storeId
230
+ * @return string
231
+ */
232
+ protected function getJoinVisibilityAttributeStatement($tableAlias, $storeId = '0'){
233
+ $visibilityAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_VISIBILITY_ATTRIBUTE_KEY);
234
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
235
+ $tableAlias, $visibilityAttribute->getId(), $storeId);
236
+ }
237
+
238
+ /**
239
+ * @param string $tableAlias
240
+ * @param string $storeId
241
+ * @return string
242
+ */
243
+ protected function getJoinOriginalStatusTableStatement($tableAlias, $storeId){
244
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
245
+ $tableAlias, $this->getJoinStatusAttributeStatement($tableAlias, $storeId)
246
+ );
247
+ }
248
+
249
+ /**
250
+ * @param string $tableAlias
251
+ * @param string $storeId
252
+ * @return string
253
+ */
254
+ protected function getJoinStatusAttributeStatement($tableAlias, $storeId = '0'){
255
+ $statusAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY);
256
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
257
+ $tableAlias, $statusAttribute->getId(), $storeId);
258
+ }
259
+
260
+ /**
261
+ * @param string $tableAlias
262
+ * @param string $storeId
263
+ * @return $this
264
+ */
265
+ protected function joinParentIdsTable($tableAlias = self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE, $storeId = '0'){
266
+ if($this->isTableAliasAdded($tableAlias)){
267
+
268
+ return $this;
269
+ }
270
+
271
+ $this->getSelect()->joinLeft(
272
+ array($tableAlias => $this->getParentIdsTable()),
273
+ $this->getJoinParentIdsTableStatement($tableAlias, $storeId),
274
+ array('value'));
275
+ $this->getSelect()->columns(sprintf('IFNULL(%1$s.value, %2$s.value) as parent_id', self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE));
276
+
277
+ return $this;
278
+ }
279
+
280
+ /**
281
+ * @param string $tableAlias
282
+ * @param string $storeId
283
+ * @return string
284
+ */
285
+ protected function getJoinParentIdsTableStatement($tableAlias, $storeId){
286
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
287
+ $tableAlias, $this->getJoinParentIdsAttributeStatement($tableAlias, $storeId)
288
+ );
289
+ }
290
+
291
+ /**
292
+ * @param string $tableAlias
293
+ * @param string $storeId
294
+ * @return string
295
+ */
296
+ protected function getJoinParentIdsAttributeStatement($tableAlias, $storeId = '0'){
297
+ $attribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_PARENT_ID_ATTRIBUTE_KEY);
298
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
299
+ $tableAlias, $attribute->getId(), $storeId);
300
+ }
301
+
302
+ /**
303
+ * @return string
304
+ * @throws Mage_Core_Exception
305
+ */
306
+ protected function getParentIdsTable(){
307
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_PARENT_ID_ATTRIBUTE_KEY)
308
+ ->getBackend()->getTable();
309
+ }
310
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Product.php ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Model_Resource_Product extends Mage_Catalog_Model_Resource_Product{
3
+
4
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Product/Collection.php ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Product_Collection extends Polytab_OmniPixel_Model_Resource_Product_Collection_Db
4
+ {
5
+ /**
6
+ * @return bool
7
+ */
8
+ public function isEnabledFlat()
9
+ {
10
+ return false;
11
+ }
12
+
13
+ protected function _construct()
14
+ {
15
+ $this->_init('omnipixel/product');
16
+ $this->_initTables();
17
+ }
18
+
19
+ /**
20
+ * Overwrite to set default $joinLeft value to true.
21
+ *
22
+ * @param bool $joinLeft
23
+ * @return Polytab_OmniPixel_Model_Resource_Product_Collection $this
24
+ */
25
+ protected function _productLimitationPrice($joinLeft = true)
26
+ {
27
+ parent::_productLimitationPrice($joinLeft);
28
+
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * @param array $options
34
+ * @return Polytab_OmniPixel_Model_Resource_Product_Collection $this
35
+ */
36
+ public function applyFiltersOnCollection($options)
37
+ {
38
+ $this->helper()->log($options);
39
+ $this->optionsFilters = $options;
40
+ $this->applyStoreFilter();
41
+ $this->registryHelper()->initImportRegistry($this->getStoreId());
42
+ $this->joinVisibilityTable(Polytab_OmniPixel_Model_Resource_Product_Collection_Db::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE, '0');
43
+ $this->joinVisibilityTable(Polytab_OmniPixel_Model_Resource_Product_Collection_Db::ORIGINAL_VISIBILITY_TABLE_ALIAS, $this->getStoreId());
44
+ $this->fillParentIds();
45
+ $this->addAttributeToSelect('dfw_parent_ids');
46
+ $this->joinParentIdsTable(Polytab_OmniPixel_Model_Resource_Product_Collection_Db::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE, '0');
47
+ $this->joinParentIdsTable(Polytab_OmniPixel_Model_Resource_Product_Collection_Db::ORIGINAL_PARENT_IDS_TABLE_ALIAS, $this->getStoreId());
48
+ $this->addRuleDate();
49
+ $this->applyTypeFilter();
50
+ $this->joinQty();
51
+ $this->addFinalPrice();
52
+ $this->addUrlRewrite();
53
+ $this->applyStatusFilter();
54
+ $this->applyUpdatedAtFilter();
55
+ $this->addAttributeToSelect('ignore_datafeedwatch');
56
+ $this->addAttributeToFilter('ignore_datafeedwatch', array(array('null' => true), array('neq' => 1)), 'left');
57
+
58
+ $this->setPage($this->optionsFilters['page'], $this->optionsFilters['per_page']);
59
+ $this->helper()->sqlLog($this->getSelect()->__toString());
60
+
61
+ return $this;
62
+ }
63
+
64
+ public function fillParentIds()
65
+ {
66
+ Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
67
+
68
+ $collection = Mage::getResourceModel('catalog/product_collection');
69
+ foreach($collection as $product) {
70
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
71
+ if (!empty($parentIds)) {
72
+ // $product->setDfwParentIds(implode(',', $parentIds));
73
+ $product->setDfwParentIds(current($parentIds));
74
+ $product->getResource()->saveAttribute($product, 'dfw_parent_ids');
75
+ }
76
+ }
77
+ Mage::app()->setCurrentStore($this->getStoreId());
78
+
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * @param $store
84
+ * @return Polytab_OmniPixel_Model_Resource_Product_Collection $this
85
+ */
86
+ public function applySpecificStore($store)
87
+ {
88
+ $store = Mage::app()->getStore($store);
89
+ $this->optionsFilters['store'] = $store->getId();
90
+
91
+ return $this->applyStoreFilter();
92
+ }
93
+
94
+ /**
95
+ * @return $this
96
+ */
97
+ protected function applyStoreFilter()
98
+ {
99
+ if (isset($this->optionsFilters['store'])) {
100
+ $store = Mage::getModel('core/store')->load($this->optionsFilters['store']);
101
+ $StoreColumn = sprintf('IFNULL(null, %s) as store_id', $store->getId());
102
+ $this->setStoreId($store->getId());
103
+ $this->addStoreFilter($store);
104
+ $this->getSelect()->columns($StoreColumn);
105
+ }
106
+
107
+ return $this;
108
+ }
109
+
110
+ /**
111
+ * @return $this
112
+ */
113
+ protected function applyTypeFilter()
114
+ {
115
+ if (isset($this->optionsFilters['type'])) {
116
+ $this->addAttributeToFilter('type_id', array('in' => $this->optionsFilters['type']));
117
+ }
118
+
119
+ return $this;
120
+ }
121
+
122
+ /**
123
+ * @return $this
124
+ */
125
+ protected function applyUpdatedAtFilter()
126
+ {
127
+ if (!isset($this->optionsFilters['from_date'])) {
128
+
129
+ return $this;
130
+ }
131
+
132
+ $this->getSelect()->where($this->ruleDateSelect . ' >= ?', $this->optionsFilters['from_date']);
133
+
134
+ return $this;
135
+ }
136
+
137
+ /**
138
+ * @return $this
139
+ */
140
+ protected function applyStatusFilter()
141
+ {
142
+ if (!isset($this->optionsFilters['status'])) {
143
+
144
+ return $this;
145
+ }
146
+
147
+ if ($this->registryHelper()->isStatusAttributeInheritable()) {
148
+ $this->buildFilterStatusCondition();
149
+ $this->joinInheritedStatusTable(self::INHERITED_STATUS_TABLE_ALIAS, $this->getStoreId())
150
+ ->joinInheritedStatusTable(self::INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE, '0')
151
+ ->joinOriginalStatusTable(self::ORIGINAL_STATUS_TABLE_ALIAS, $this->getStoreId())
152
+ ->joinOriginalStatusTable(self::ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE, '0');
153
+ $this->getSelect()->where($this->filterStatusCondition . ' = ?', $this->optionsFilters['status']);
154
+ } else {
155
+ $this->addAttributeToFilter('status', $this->optionsFilters['status']);
156
+ }
157
+
158
+ return $this;
159
+ }
160
+
161
+ /**
162
+ * @return $this
163
+ */
164
+ protected function addParentData()
165
+ {
166
+ $parentCollection = $this->getParentProductsCollection();
167
+ $parentCollection = $parentCollection->getItems();
168
+ foreach ($this->getItems() as $product) {
169
+ $parentId = $product->getParentId();
170
+ $parentId = explode(',', $parentId);
171
+ if (is_array($parentId)) {
172
+ $parentId = current($parentId);
173
+ }
174
+
175
+ if (empty($parentId) || !isset($parentCollection[$parentId])) {
176
+ continue;
177
+ }
178
+ $product->setParent($parentCollection[$parentId]);
179
+ }
180
+
181
+ return $this;
182
+ }
183
+
184
+ /**
185
+ * @return Mage_Catalog_Model_Resource_Product_Collection
186
+ */
187
+ protected function getParentProductsCollection()
188
+ {
189
+ $parentCollection = Mage::getResourceModel('omnipixel/product_collection')
190
+ ->addAttributeToSelect('*')
191
+ ->addUrlRewrite()
192
+ ->addFinalPrice()
193
+ ->applySpecificStore($this->optionsFilters['store']);
194
+
195
+ $parentCollection->getSelect()->joinLeft(
196
+ array(self::PARENT_CONFIGURABLE_ATTRIBUTES_TABLE_ALIAS =>
197
+ $this->getTable('catalog/product_super_attribute'),
198
+ ),
199
+ sprintf('%s.product_id = e.entity_id', self::PARENT_CONFIGURABLE_ATTRIBUTES_TABLE_ALIAS),
200
+ array('super_attribute_ids' =>
201
+ sprintf('GROUP_CONCAT(DISTINCT %s.attribute_id)', self::PARENT_CONFIGURABLE_ATTRIBUTES_TABLE_ALIAS),
202
+ )
203
+ );
204
+
205
+ $parentCollection->getSelect()->joinRight(
206
+ array(self::PARENT_RELATIONS_TABLE_ALIAS => $this->getTable('catalog/product_relation')),
207
+ sprintf('%s.parent_id = e.entity_id', self::PARENT_RELATIONS_TABLE_ALIAS),
208
+ array('parent_id' => sprintf('%s.parent_id', self::PARENT_RELATIONS_TABLE_ALIAS))
209
+ )->group('e.entity_id');
210
+
211
+ return $parentCollection;
212
+ }
213
+
214
+ /**
215
+ * @return $this
216
+ */
217
+ public function applyInheritanceLogic()
218
+ {
219
+ $this->addParentData();
220
+ foreach ($this->getItems() as $product) {
221
+ $parent = $product->getParent();
222
+ if (!empty($parent)) {
223
+ $product->getParentAttributes();
224
+ }
225
+ }
226
+
227
+ return $this;
228
+ }
229
+
230
+ /**
231
+ * @return Polytab_OmniPixel_Helper_Registry
232
+ */
233
+ public function registryHelper()
234
+ {
235
+ return Mage::helper('omnipixel/registry');
236
+ }
237
+
238
+ /**
239
+ * @return Polytab_OmniPixel_Helper_Data
240
+ */
241
+ public function helper()
242
+ {
243
+ return Mage::helper('omnipixel');
244
+ }
245
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Product/Collection/Db.php ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Product_Collection_Db extends Mage_Catalog_Model_Resource_Product_Collection
4
+ {
5
+ const INHERITED_STATUS_TABLE_ALIAS = 'inherited_status';
6
+ const INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE = 'inherited_status_default_store';
7
+ const ORIGINAL_STATUS_TABLE_ALIAS = 'original_status';
8
+ const ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE = 'status_default_store';
9
+ const ORIGINAL_VISIBILITY_TABLE_ALIAS = 'original_visibility';
10
+ const VISIBILITY_TABLE_ALIAS_DEFAULT_STORE = 'visibility_default_store';
11
+ const PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE = 'dfw_parent_ids_default_store';
12
+ const ORIGINAL_PARENT_IDS_TABLE_ALIAS = 'original_dfw_parent_ids';
13
+ const MIXED_STATUS_COLUMN_ALIAS = 'filter_status';
14
+ const PARENT_CONFIGURABLE_ATTRIBUTES_TABLE_ALIAS = 'parent_configurable_attributes';
15
+ const PARENT_RELATIONS_TABLE_ALIAS = 'parent_relation';
16
+ const UPDATED_AT_TABLE_ALIAS = 'custom_updated_at';
17
+ const CATALOGRULE_DATE_COLUMN_ALIAS = 'rule_date';
18
+
19
+ /** @var string $filterStatusCondition */
20
+ protected $filterStatusCondition;
21
+ /** @var array $optionsFilters */
22
+ protected $optionsFilters;
23
+ /** @var string $ruleDateSelect */
24
+ protected $ruleDateSelect;
25
+
26
+ /**
27
+ * @param string $tableAlias
28
+ * @return bool
29
+ * @throws Zend_Db_Select_Exception
30
+ */
31
+ protected function isTableAliasAdded($tableAlias)
32
+ {
33
+ $tables = $this->getSelect()->getPart(Zend_Db_Select::FROM);
34
+ $currentAliases = array_keys($tables);
35
+
36
+ return in_array($tableAlias, $currentAliases);
37
+
38
+ }
39
+
40
+ /**
41
+ * @return $this
42
+ */
43
+ protected function addRuleDate()
44
+ {
45
+ /** @var Polytab_OmniPixel_Model_Cron $cron */
46
+ $cron = Mage::getModel('omnipixel/cron');
47
+ $cron->reindex();
48
+
49
+ $condition = $this->getUpdatedAtCondition();
50
+ $select = new Zend_Db_Select($this->getEntity()->getReadConnection());
51
+ $select->from(
52
+ array(
53
+ self::UPDATED_AT_TABLE_ALIAS => $this->getTable('omnipixel/updated_products'),
54
+ ),
55
+ array(
56
+ sprintf('COALESCE(%1$s.updated_at, 0)', self::UPDATED_AT_TABLE_ALIAS),
57
+ )
58
+ );
59
+ $select->where($condition);
60
+ $select->limit(1);
61
+
62
+ $this->ruleDateSelect = sprintf('GREATEST(IFNULL((%s), 0), COALESCE(%2$s.updated_at, 0))',
63
+ $select->__toString(), self::MAIN_TABLE_ALIAS);
64
+ $this->getSelect()->columns(array(self::CATALOGRULE_DATE_COLUMN_ALIAS => new Zend_Db_Expr($this->ruleDateSelect)));
65
+
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * @return string
71
+ * @throws Mage_Core_Exception
72
+ */
73
+ protected function getUpdatedAtCondition()
74
+ {
75
+ $condition = '(IFNULL(%3$s.value, %4$s.value) IS NOT NULL AND %1$s.dfw_prod_id IN (IFNULL(%3$s.value, %4$s.value)) OR %1$s.dfw_prod_id = %2$s.entity_id)';
76
+ $condition = sprintf($condition,
77
+ self::UPDATED_AT_TABLE_ALIAS, self::MAIN_TABLE_ALIAS, self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE);
78
+
79
+ return $condition;
80
+ }
81
+
82
+ /**
83
+ * @return $this
84
+ * @throws Mage_Core_Exception
85
+ */
86
+ protected function joinQty()
87
+ {
88
+ $this->joinField('qty',
89
+ 'cataloginventory/stock_item',
90
+ 'qty',
91
+ 'product_id=entity_id',
92
+ '{{table}}.stock_id=1',
93
+ 'left');
94
+
95
+ return $this;
96
+ }
97
+ /**
98
+ * @return string
99
+ * @throws Mage_Core_Exception
100
+ */
101
+ protected function getStatusTable()
102
+ {
103
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)
104
+ ->getBackend()->getTable();
105
+ }
106
+
107
+ /**
108
+ * @return string
109
+ * @throws Mage_Core_Exception
110
+ */
111
+ protected function getVisibilityTable()
112
+ {
113
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)
114
+ ->getBackend()->getTable();
115
+ }
116
+
117
+ /**
118
+ * @return string|int
119
+ * @throws Mage_Core_Exception
120
+ */
121
+ protected function getVisibilityAttributeId()
122
+ {
123
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)->getAttributeId();
124
+ }
125
+
126
+ protected function buildFilterStatusCondition()
127
+ {
128
+ $childString = 'IFNULL(%1$s.value, %3$s.value)';
129
+ $parentString = 'IFNULL(%2$s.value, %4$s.value)';
130
+ $enable = Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
131
+ $statusAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY);
132
+ switch($statusAttribute->getInheritance()) {
133
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_THEN_PARENT_OPTION_ID:
134
+ $inheritString = "IFNULL({$childString}, {$parentString})";
135
+ // $inheritWithStatusString = 'IFNULL(
136
+ // IF(' . $childString . ' <> ' . $enable . ', ' . $parentString . ', ' . $childString . '),
137
+ // ' . $childString
138
+ // . ')';
139
+ $notVisibleIndividually = "IF({$childString} <> {$enable}, {$childString}, {$parentString})";
140
+ $string = 'IF(IFNULL(%5$s.value, %6$s.value) = '. Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
141
+ . ', ' . $notVisibleIndividually .', '. $inheritString.')';
142
+ break;
143
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::PARENT_OPTION_ID:
144
+ $string = 'IFNULL(' . $parentString . ', ' . $childString . ')';
145
+ break;
146
+ default :
147
+ $string = $childString;
148
+ }
149
+ $this->filterStatusCondition = sprintf($string,
150
+ self::ORIGINAL_STATUS_TABLE_ALIAS, self::INHERITED_STATUS_TABLE_ALIAS,
151
+ self::ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE, self::INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE,
152
+ self::ORIGINAL_VISIBILITY_TABLE_ALIAS, self::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE
153
+ );
154
+ }
155
+
156
+ /**
157
+ * @param string $tableAlias
158
+ * @param string $storeId
159
+ * @return $this
160
+ */
161
+ protected function joinInheritedStatusTable($tableAlias = self::INHERITED_STATUS_TABLE_ALIAS, $storeId = '0')
162
+ {
163
+ if ($this->isTableAliasAdded($tableAlias)) {
164
+
165
+ return $this;
166
+ }
167
+
168
+ $this->getSelect()->joinLeft(
169
+ array($tableAlias => $this->getStatusTable()),
170
+ $this->getJoinInheritedStatusTableStatement($tableAlias, $storeId),
171
+ array(self::MIXED_STATUS_COLUMN_ALIAS => $this->filterStatusCondition));
172
+
173
+ return $this;
174
+ }
175
+
176
+ /**
177
+ * @param string $tableAlias
178
+ * @param string $storeId
179
+ * @return string
180
+ */
181
+ protected function getJoinInheritedStatusTableStatement($tableAlias, $storeId)
182
+ {
183
+ return sprintf('%1$s.entity_id IN (IFNULL(%2$s.value, %3$s.value)) and %4$s',
184
+ $tableAlias, self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE,
185
+ $this->getJoinStatusAttributeStatement($tableAlias, $storeId)
186
+ );
187
+ }
188
+
189
+ /**
190
+ * @param string $tableAlias
191
+ * @param string $storeId
192
+ * @return $this
193
+ */
194
+ protected function joinOriginalStatusTable($tableAlias = self::ORIGINAL_STATUS_TABLE_ALIAS, $storeId = '0')
195
+ {
196
+ if ($this->isTableAliasAdded($tableAlias)) {
197
+
198
+ return $this;
199
+ }
200
+
201
+ $this->getSelect()->joinLeft(
202
+ array($tableAlias => $this->getStatusTable()),
203
+ $this->getJoinOriginalStatusTableStatement($tableAlias, $storeId),
204
+ array(self::MIXED_STATUS_COLUMN_ALIAS => $this->filterStatusCondition));
205
+
206
+ return $this;
207
+ }
208
+
209
+ /**
210
+ * @param string $tableAlias
211
+ * @param string $storeId
212
+ * @return $this
213
+ */
214
+ protected function joinVisibilityTable($tableAlias = self::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE, $storeId = '0')
215
+ {
216
+ if ($this->isTableAliasAdded($tableAlias)) {
217
+
218
+ return $this;
219
+ }
220
+
221
+ $this->getSelect()->joinLeft(
222
+ array($tableAlias => $this->getVisibilityTable()),
223
+ $this->getJoinVisibilityTableStatement($tableAlias, $storeId),
224
+ array('value'));
225
+
226
+ return $this;
227
+ }
228
+
229
+ /**
230
+ * @param string $tableAlias
231
+ * @param string $storeId
232
+ * @return string
233
+ */
234
+ protected function getJoinVisibilityTableStatement($tableAlias, $storeId)
235
+ {
236
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
237
+ $tableAlias, $this->getJoinVisibilityAttributeStatement($tableAlias, $storeId)
238
+ );
239
+ }
240
+
241
+ /**
242
+ * @param string $tableAlias
243
+ * @param string $storeId
244
+ * @return string
245
+ */
246
+ protected function getJoinVisibilityAttributeStatement($tableAlias, $storeId = '0')
247
+ {
248
+ $visibilityAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_VISIBILITY_ATTRIBUTE_KEY);
249
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
250
+ $tableAlias, $visibilityAttribute->getId(), $storeId);
251
+ }
252
+
253
+ /**
254
+ * @param string $tableAlias
255
+ * @param string $storeId
256
+ * @return string
257
+ */
258
+ protected function getJoinOriginalStatusTableStatement($tableAlias, $storeId)
259
+ {
260
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
261
+ $tableAlias, $this->getJoinStatusAttributeStatement($tableAlias, $storeId)
262
+ );
263
+ }
264
+
265
+ /**
266
+ * @param string $tableAlias
267
+ * @param string $storeId
268
+ * @return string
269
+ */
270
+ protected function getJoinStatusAttributeStatement($tableAlias, $storeId = '0')
271
+ {
272
+ $statusAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY);
273
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
274
+ $tableAlias, $statusAttribute->getId(), $storeId);
275
+ }
276
+
277
+ /**
278
+ * @param string $tableAlias
279
+ * @param string $storeId
280
+ * @return $this
281
+ */
282
+ protected function joinParentIdsTable($tableAlias = self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE, $storeId = '0')
283
+ {
284
+ if ($this->isTableAliasAdded($tableAlias)) {
285
+
286
+ return $this;
287
+ }
288
+
289
+ $this->getSelect()->joinLeft(
290
+ array($tableAlias => $this->getParentIdsTable()),
291
+ $this->getJoinParentIdsTableStatement($tableAlias, $storeId),
292
+ array('value'));
293
+ $this->getSelect()->columns(sprintf('IFNULL(%1$s.value, %2$s.value) as parent_id', self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE));
294
+
295
+ return $this;
296
+ }
297
+
298
+ /**
299
+ * @param string $tableAlias
300
+ * @param string $storeId
301
+ * @return string
302
+ */
303
+ protected function getJoinParentIdsTableStatement($tableAlias, $storeId)
304
+ {
305
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
306
+ $tableAlias, $this->getJoinParentIdsAttributeStatement($tableAlias, $storeId)
307
+ );
308
+ }
309
+
310
+ /**
311
+ * @param string $tableAlias
312
+ * @param string $storeId
313
+ * @return string
314
+ */
315
+ protected function getJoinParentIdsAttributeStatement($tableAlias, $storeId = '0')
316
+ {
317
+ $attribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_PARENT_ID_ATTRIBUTE_KEY);
318
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
319
+ $tableAlias, $attribute->getId(), $storeId);
320
+ }
321
+
322
+ /**
323
+ * @return string
324
+ * @throws Mage_Core_Exception
325
+ */
326
+ protected function getParentIdsTable()
327
+ {
328
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_PARENT_ID_ATTRIBUTE_KEY)
329
+ ->getBackend()->getTable();
330
+ }
331
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Settings.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Settings extends Mage_Core_Model_Resource_Db_Abstract{
4
+ public function _construct(){
5
+ $this->_init('omnipixel/settings', 'id');
6
+ }
7
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Settings/Collection.php ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Settings_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
4
+ {
5
+
6
+ protected function _construct()
7
+ {
8
+ parent::_construct();
9
+ $this->_init('omnipixel/settings');
10
+ }
11
+
12
+
13
+ }
app/code/community/Polytab/OmniPixel/Model/Resource/Settings/Collection/Db.php ADDED
@@ -0,0 +1,331 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_Resource_Product_Collection_Db extends Mage_Catalog_Model_Resource_Product_Collection
4
+ {
5
+ const INHERITED_STATUS_TABLE_ALIAS = 'inherited_status';
6
+ const INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE = 'inherited_status_default_store';
7
+ const ORIGINAL_STATUS_TABLE_ALIAS = 'original_status';
8
+ const ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE = 'status_default_store';
9
+ const ORIGINAL_VISIBILITY_TABLE_ALIAS = 'original_visibility';
10
+ const VISIBILITY_TABLE_ALIAS_DEFAULT_STORE = 'visibility_default_store';
11
+ const PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE = 'dfw_parent_ids_default_store';
12
+ const ORIGINAL_PARENT_IDS_TABLE_ALIAS = 'original_dfw_parent_ids';
13
+ const MIXED_STATUS_COLUMN_ALIAS = 'filter_status';
14
+ const PARENT_CONFIGURABLE_ATTRIBUTES_TABLE_ALIAS = 'parent_configurable_attributes';
15
+ const PARENT_RELATIONS_TABLE_ALIAS = 'parent_relation';
16
+ const UPDATED_AT_TABLE_ALIAS = 'custom_updated_at';
17
+ const CATALOGRULE_DATE_COLUMN_ALIAS = 'rule_date';
18
+
19
+ /** @var string $filterStatusCondition */
20
+ protected $filterStatusCondition;
21
+ /** @var array $optionsFilters */
22
+ protected $optionsFilters;
23
+ /** @var string $ruleDateSelect */
24
+ protected $ruleDateSelect;
25
+
26
+ /**
27
+ * @param string $tableAlias
28
+ * @return bool
29
+ * @throws Zend_Db_Select_Exception
30
+ */
31
+ protected function isTableAliasAdded($tableAlias)
32
+ {
33
+ $tables = $this->getSelect()->getPart(Zend_Db_Select::FROM);
34
+ $currentAliases = array_keys($tables);
35
+
36
+ return in_array($tableAlias, $currentAliases);
37
+
38
+ }
39
+
40
+ /**
41
+ * @return $this
42
+ */
43
+ protected function addRuleDate()
44
+ {
45
+ /** @var Polytab_OmniPixel_Model_Cron $cron */
46
+ $cron = Mage::getModel('omnipixel/cron');
47
+ $cron->reindex();
48
+
49
+ $condition = $this->getUpdatedAtCondition();
50
+ $select = new Zend_Db_Select($this->getEntity()->getReadConnection());
51
+ $select->from(
52
+ array(
53
+ self::UPDATED_AT_TABLE_ALIAS => $this->getTable('omnipixel/updated_products'),
54
+ ),
55
+ array(
56
+ sprintf('COALESCE(%1$s.updated_at, 0)', self::UPDATED_AT_TABLE_ALIAS),
57
+ )
58
+ );
59
+ $select->where($condition);
60
+ $select->limit(1);
61
+
62
+ $this->ruleDateSelect = sprintf('GREATEST(IFNULL((%s), 0), COALESCE(%2$s.updated_at, 0))',
63
+ $select->__toString(), self::MAIN_TABLE_ALIAS);
64
+ $this->getSelect()->columns(array(self::CATALOGRULE_DATE_COLUMN_ALIAS => new Zend_Db_Expr($this->ruleDateSelect)));
65
+
66
+ return $this;
67
+ }
68
+
69
+ /**
70
+ * @return string
71
+ * @throws Mage_Core_Exception
72
+ */
73
+ protected function getUpdatedAtCondition()
74
+ {
75
+ $condition = '(IFNULL(%3$s.value, %4$s.value) IS NOT NULL AND %1$s.dfw_prod_id IN (IFNULL(%3$s.value, %4$s.value)) OR %1$s.dfw_prod_id = %2$s.entity_id)';
76
+ $condition = sprintf($condition,
77
+ self::UPDATED_AT_TABLE_ALIAS, self::MAIN_TABLE_ALIAS, self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE);
78
+
79
+ return $condition;
80
+ }
81
+
82
+ /**
83
+ * @return $this
84
+ * @throws Mage_Core_Exception
85
+ */
86
+ protected function joinQty()
87
+ {
88
+ $this->joinField('qty',
89
+ 'cataloginventory/stock_item',
90
+ 'qty',
91
+ 'product_id=entity_id',
92
+ '{{table}}.stock_id=1',
93
+ 'left');
94
+
95
+ return $this;
96
+ }
97
+ /**
98
+ * @return string
99
+ * @throws Mage_Core_Exception
100
+ */
101
+ protected function getStatusTable()
102
+ {
103
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)
104
+ ->getBackend()->getTable();
105
+ }
106
+
107
+ /**
108
+ * @return string
109
+ * @throws Mage_Core_Exception
110
+ */
111
+ protected function getVisibilityTable()
112
+ {
113
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)
114
+ ->getBackend()->getTable();
115
+ }
116
+
117
+ /**
118
+ * @return string|int
119
+ * @throws Mage_Core_Exception
120
+ */
121
+ protected function getVisibilityAttributeId()
122
+ {
123
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY)->getAttributeId();
124
+ }
125
+
126
+ protected function buildFilterStatusCondition()
127
+ {
128
+ $childString = 'IFNULL(%1$s.value, %3$s.value)';
129
+ $parentString = 'IFNULL(%2$s.value, %4$s.value)';
130
+ $enable = Mage_Catalog_Model_Product_Status::STATUS_ENABLED;
131
+ $statusAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY);
132
+ switch($statusAttribute->getInheritance()) {
133
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::CHILD_THEN_PARENT_OPTION_ID:
134
+ $inheritString = "IFNULL({$childString}, {$parentString})";
135
+ // $inheritWithStatusString = 'IFNULL(
136
+ // IF(' . $childString . ' <> ' . $enable . ', ' . $parentString . ', ' . $childString . '),
137
+ // ' . $childString
138
+ // . ')';
139
+ $notVisibleIndividually = "IF({$childString} <> {$enable}, {$childString}, {$parentString})";
140
+ $string = 'IF(IFNULL(%5$s.value, %6$s.value) = '. Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE
141
+ . ', ' . $notVisibleIndividually .', '. $inheritString.')';
142
+ break;
143
+ case (string) Polytab_OmniPixel_Model_System_Config_Source_Inheritance::PARENT_OPTION_ID:
144
+ $string = 'IFNULL(' . $parentString . ', ' . $childString . ')';
145
+ break;
146
+ default :
147
+ $string = $childString;
148
+ }
149
+ $this->filterStatusCondition = sprintf($string,
150
+ self::ORIGINAL_STATUS_TABLE_ALIAS, self::INHERITED_STATUS_TABLE_ALIAS,
151
+ self::ORIGINAL_STATUS_TABLE_ALIAS_DEFAULT_STORE, self::INHERITED_STATUS_TABLE_ALIAS_DEFAULT_STORE,
152
+ self::ORIGINAL_VISIBILITY_TABLE_ALIAS, self::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE
153
+ );
154
+ }
155
+
156
+ /**
157
+ * @param string $tableAlias
158
+ * @param string $storeId
159
+ * @return $this
160
+ */
161
+ protected function joinInheritedStatusTable($tableAlias = self::INHERITED_STATUS_TABLE_ALIAS, $storeId = '0')
162
+ {
163
+ if ($this->isTableAliasAdded($tableAlias)) {
164
+
165
+ return $this;
166
+ }
167
+
168
+ $this->getSelect()->joinLeft(
169
+ array($tableAlias => $this->getStatusTable()),
170
+ $this->getJoinInheritedStatusTableStatement($tableAlias, $storeId),
171
+ array(self::MIXED_STATUS_COLUMN_ALIAS => $this->filterStatusCondition));
172
+
173
+ return $this;
174
+ }
175
+
176
+ /**
177
+ * @param string $tableAlias
178
+ * @param string $storeId
179
+ * @return string
180
+ */
181
+ protected function getJoinInheritedStatusTableStatement($tableAlias, $storeId)
182
+ {
183
+ return sprintf('%1$s.entity_id IN (IFNULL(%2$s.value, %3$s.value)) and %4$s',
184
+ $tableAlias, self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE,
185
+ $this->getJoinStatusAttributeStatement($tableAlias, $storeId)
186
+ );
187
+ }
188
+
189
+ /**
190
+ * @param string $tableAlias
191
+ * @param string $storeId
192
+ * @return $this
193
+ */
194
+ protected function joinOriginalStatusTable($tableAlias = self::ORIGINAL_STATUS_TABLE_ALIAS, $storeId = '0')
195
+ {
196
+ if ($this->isTableAliasAdded($tableAlias)) {
197
+
198
+ return $this;
199
+ }
200
+
201
+ $this->getSelect()->joinLeft(
202
+ array($tableAlias => $this->getStatusTable()),
203
+ $this->getJoinOriginalStatusTableStatement($tableAlias, $storeId),
204
+ array(self::MIXED_STATUS_COLUMN_ALIAS => $this->filterStatusCondition));
205
+
206
+ return $this;
207
+ }
208
+
209
+ /**
210
+ * @param string $tableAlias
211
+ * @param string $storeId
212
+ * @return $this
213
+ */
214
+ protected function joinVisibilityTable($tableAlias = self::VISIBILITY_TABLE_ALIAS_DEFAULT_STORE, $storeId = '0')
215
+ {
216
+ if ($this->isTableAliasAdded($tableAlias)) {
217
+
218
+ return $this;
219
+ }
220
+
221
+ $this->getSelect()->joinLeft(
222
+ array($tableAlias => $this->getVisibilityTable()),
223
+ $this->getJoinVisibilityTableStatement($tableAlias, $storeId),
224
+ array('value'));
225
+
226
+ return $this;
227
+ }
228
+
229
+ /**
230
+ * @param string $tableAlias
231
+ * @param string $storeId
232
+ * @return string
233
+ */
234
+ protected function getJoinVisibilityTableStatement($tableAlias, $storeId)
235
+ {
236
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
237
+ $tableAlias, $this->getJoinVisibilityAttributeStatement($tableAlias, $storeId)
238
+ );
239
+ }
240
+
241
+ /**
242
+ * @param string $tableAlias
243
+ * @param string $storeId
244
+ * @return string
245
+ */
246
+ protected function getJoinVisibilityAttributeStatement($tableAlias, $storeId = '0')
247
+ {
248
+ $visibilityAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_VISIBILITY_ATTRIBUTE_KEY);
249
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
250
+ $tableAlias, $visibilityAttribute->getId(), $storeId);
251
+ }
252
+
253
+ /**
254
+ * @param string $tableAlias
255
+ * @param string $storeId
256
+ * @return string
257
+ */
258
+ protected function getJoinOriginalStatusTableStatement($tableAlias, $storeId)
259
+ {
260
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
261
+ $tableAlias, $this->getJoinStatusAttributeStatement($tableAlias, $storeId)
262
+ );
263
+ }
264
+
265
+ /**
266
+ * @param string $tableAlias
267
+ * @param string $storeId
268
+ * @return string
269
+ */
270
+ protected function getJoinStatusAttributeStatement($tableAlias, $storeId = '0')
271
+ {
272
+ $statusAttribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_STATUS_ATTRIBUTE_KEY);
273
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
274
+ $tableAlias, $statusAttribute->getId(), $storeId);
275
+ }
276
+
277
+ /**
278
+ * @param string $tableAlias
279
+ * @param string $storeId
280
+ * @return $this
281
+ */
282
+ protected function joinParentIdsTable($tableAlias = self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE, $storeId = '0')
283
+ {
284
+ if ($this->isTableAliasAdded($tableAlias)) {
285
+
286
+ return $this;
287
+ }
288
+
289
+ $this->getSelect()->joinLeft(
290
+ array($tableAlias => $this->getParentIdsTable()),
291
+ $this->getJoinParentIdsTableStatement($tableAlias, $storeId),
292
+ array('value'));
293
+ $this->getSelect()->columns(sprintf('IFNULL(%1$s.value, %2$s.value) as parent_id', self::ORIGINAL_PARENT_IDS_TABLE_ALIAS, self::PARENT_IDS_TABLE_ALIAS_DEFAULT_STORE));
294
+
295
+ return $this;
296
+ }
297
+
298
+ /**
299
+ * @param string $tableAlias
300
+ * @param string $storeId
301
+ * @return string
302
+ */
303
+ protected function getJoinParentIdsTableStatement($tableAlias, $storeId)
304
+ {
305
+ return sprintf('%1$s.entity_id = e.entity_id and %2$s',
306
+ $tableAlias, $this->getJoinParentIdsAttributeStatement($tableAlias, $storeId)
307
+ );
308
+ }
309
+
310
+ /**
311
+ * @param string $tableAlias
312
+ * @param string $storeId
313
+ * @return string
314
+ */
315
+ protected function getJoinParentIdsAttributeStatement($tableAlias, $storeId = '0')
316
+ {
317
+ $attribute = Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_PARENT_ID_ATTRIBUTE_KEY);
318
+ return sprintf('%1$s.attribute_id = %2$s and %1$s.store_id = %3$s',
319
+ $tableAlias, $attribute->getId(), $storeId);
320
+ }
321
+
322
+ /**
323
+ * @return string
324
+ * @throws Mage_Core_Exception
325
+ */
326
+ protected function getParentIdsTable()
327
+ {
328
+ return Mage::registry(Polytab_OmniPixel_Helper_Registry::DFW_PARENT_ID_ATTRIBUTE_KEY)
329
+ ->getBackend()->getTable();
330
+ }
331
+ }
app/code/community/Polytab/OmniPixel/Model/Settings.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @method Polytab_OmniPixel_Model_Product getParent()
4
+ */
5
+
6
+ class Polytab_OmniPixel_Model_Settings extends Mage_Core_Model_Abstract
7
+ {
8
+
9
+
10
+ protected function _construct()
11
+ {
12
+ parent::_construct();
13
+ $this->_init('omnipixel/settings');
14
+ }
15
+
16
+ /**
17
+ * @return array
18
+ */
19
+
20
+ }
app/code/community/Polytab/OmniPixel/Model/System/Config/Source/Inheritance.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_System_Config_Source_Inheritance
4
+ {
5
+ const CHILD_OPTION_ID = 1;
6
+ const CHILD_OPTION_LABEL = 'Child';
7
+ const PARENT_OPTION_ID = 2;
8
+ const PARENT_OPTION_LABEL = 'Parent';
9
+ const CHILD_THEN_PARENT_OPTION_ID = 3;
10
+ const CHILD_THEN_PARENT_OPTION_LABEL = 'Child Then Parent';
11
+
12
+ /**
13
+ * @return array
14
+ */
15
+ public function toOptionArray()
16
+ {
17
+ return array(
18
+ array(
19
+ 'value' => self::CHILD_OPTION_ID,
20
+ 'label' => $this->_helper()->__(self::CHILD_OPTION_LABEL),
21
+ ),
22
+ array(
23
+ 'value' => self::PARENT_OPTION_ID,
24
+ 'label' => $this->_helper()->__(self::PARENT_OPTION_LABEL),
25
+ ),
26
+ array(
27
+ 'value' => self::CHILD_THEN_PARENT_OPTION_ID,
28
+ 'label' => $this->_helper()->__(self::CHILD_THEN_PARENT_OPTION_LABEL),
29
+ ),
30
+ );
31
+ }
32
+
33
+ /**
34
+ * @return array
35
+ */
36
+ public function toArray()
37
+ {
38
+ return array(
39
+ self::CHILD_OPTION_ID =>
40
+ $this->_helper()->__(self::CHILD_OPTION_LABEL),
41
+ self::PARENT_OPTION_ID =>
42
+ $this->_helper()->__(self::PARENT_OPTION_LABEL),
43
+ self::CHILD_THEN_PARENT_OPTION_ID =>
44
+ $this->_helper()->__(self::CHILD_THEN_PARENT_OPTION_LABEL),
45
+ );
46
+ }
47
+
48
+ /**
49
+ * @return Polytab_OmniPixel_Helper_Data
50
+ */
51
+ public function _helper()
52
+ {
53
+ return Mage::helper('omnipixel');
54
+ }
55
+ }
app/code/community/Polytab/OmniPixel/Model/System/Config/Source/Textarea/Values.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Polytab_OmniPixel_Model_System_Config_Source_Textarea_Values
4
+ {
5
+ public function toOptionArray()
6
+ {
7
+ return "dfsfdsfdsfsf";
8
+ }
9
+ }
app/code/community/Polytab/OmniPixel/controllers/Adminhtml/OmnipixelbackendController.php ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Polytab_OmniPixel_Adminhtml_OmnipixelbackendController extends Mage_Adminhtml_Controller_Action{
3
+ public function indexAction(){
4
+ $this->loadLayout()
5
+ ->_setActiveMenu('omnipixel/omnipixel');
6
+ $this->_title($this->__("Polytab Pixel Heartbeat"));
7
+ $this->renderLayout();
8
+ }
9
+
10
+ protected function _isAllowed(){
11
+ return Mage::getSingleton('admin/session')->isAllowed('admin/omnipixel/omnipixelbackend');
12
+ }
13
+
14
+ public function getkeyAction(){
15
+
16
+ if($data = $this->getRequest()->getPost()){
17
+
18
+ $platformdevcode = $data['platform_code'];
19
+ $Responce = $this->checkPlatformCode($platformdevcode);
20
+
21
+ if($platformdevcode != ""){
22
+ if($Responce['status'] =='error' ){
23
+ Mage::getSingleton('core/session')->addError('Cannot Generate Client And Secert Key please Check.');
24
+ $this->_redirect('*/*/config');
25
+ return;
26
+ }
27
+ $data['client_key'] = $Responce['client_key'];
28
+ $data['secret_key'] = $Responce['secret_key'];
29
+ }
30
+
31
+ $model = Mage::getModel('omnipixel/omnipixelsetting');
32
+ $id = $this->getRequest()->getParam('id');
33
+ if($id){
34
+ $model->load($id);
35
+ }
36
+
37
+
38
+ $model->setData($data);
39
+
40
+ try{
41
+ if($id){
42
+ $model->setId($id);
43
+ }
44
+ $model->save();
45
+
46
+ if(!$model->getId()){
47
+ Mage::throwException(Mage::helper('omnipixel')->__('Error saving example'));
48
+ }
49
+
50
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('omnipixel')->__('Attribution Tracker config was successfully saved.'));
51
+ //Mage::getSingleton('adminhtml/session')->setFormData(false);
52
+
53
+
54
+ if($this->getRequest()->getParam('back')){
55
+ $this->_redirect('*/*/config', array('id' => $model->getId()));
56
+ } else{
57
+ $this->_redirect('*/*/config');
58
+ }
59
+
60
+ } catch(Exception $e){
61
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
62
+ if($model && $model->getId()){
63
+ $this->_redirect('*/*/config', array('id' => $model->getId()));
64
+ } else{
65
+ $this->_redirect('*/*/config');
66
+ }
67
+ }
68
+
69
+ return;
70
+ }
71
+ }
72
+
73
+ public function checkPlatformCode($platformdevcode){
74
+
75
+ /* Check API KEYs */
76
+
77
+ $getattributeurl ='https://api.polytab.com/v1/api/PixelRegistration/GetSecret/M90912138394TYTYBEQWETF';
78
+ $key_data = array();
79
+ try{
80
+ $ch = curl_init();
81
+ curl_setopt($ch, CURLOPT_URL,$getattributeurl);
82
+ curl_setopt($ch, CURLOPT_POST, 1);
83
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $fieldData);
84
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
85
+ $server_output = curl_exec ($ch);
86
+ curl_close ($ch);
87
+ $resArr = json_decode($server_output);
88
+ $client_id =$resArr->clientid;
89
+ $secret_key =$resArr->secretkey;
90
+ $key_data['client_key'] = $client_id;
91
+ $key_data['secret_key'] = $secret_key;
92
+
93
+ if($client_id !='' && $secret_key !=''){
94
+
95
+ $key_data['status'] = 'success';
96
+ }else{
97
+ $key_data['status'] = 'error';
98
+ }
99
+
100
+ } catch(Exception $e){
101
+
102
+ $key_data['status'] = 'error';
103
+
104
+ }
105
+
106
+ return $key_data;
107
+ }
108
+
109
+ public function configAction(){
110
+
111
+ $this->loadLayout()
112
+ ->_setActiveMenu('omnipixel/omnipixel');
113
+ $this->_title($this->__("Attribution Tracker Setting"));
114
+ //$this->_addContent($this->getLayout()->createBlock('omnipixel/adminhtml_omnipixelbackend'));adminhtml_form_store
115
+ $this->_addContent($this->getLayout()->createBlock('omnipixel/adminhtml_form_setting'));
116
+
117
+ $this->renderLayout();
118
+ }
119
+ }
app/code/community/Polytab/OmniPixel/etc/api.xml ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <config>
3
+ <api>
4
+ <resources>
5
+ <omnipixel translate="title" module="omnipixel">
6
+ <title>Omnipixel API</title>
7
+ <model>omnipixel/api</model>
8
+ <methods>
9
+ <version translate="title" module="omnipixel">
10
+ <title>Retrieve extension version</title>
11
+ </version>
12
+ <gmt_offset translate="title" module="omnipixel">
13
+ <title>Retrieve datetime in GMT</title>
14
+ </gmt_offset>
15
+ <stores translate="title" module="omnipixel">
16
+ <title>Retrieve stores</title>
17
+ </stores>
18
+ <products translate="title" module="omnipixel">
19
+ <title>Retrieve products</title>
20
+ </products>
21
+ <product_count translate="title" module="omnipixel">
22
+ <title>Retrieve product count</title>
23
+ </product_count>
24
+ <updated_products translate="title" module="omnipixel">
25
+ <title>Retrieve products based on last update</title>
26
+ </updated_products>
27
+ <updated_product_count translate="title" module="omnipixel">
28
+ <title>Retrieve product count based on last update</title>
29
+ </updated_product_count>
30
+ <product_ids translate="title" module="omnipixel">
31
+ <title>Retrieve Product Ids</title>
32
+ </product_ids>
33
+ </methods>
34
+ </omnipixel>
35
+ </resources>
36
+ </api>
37
+ </config>
app/code/community/Polytab/OmniPixel/etc/config.xml ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Polytab_OmniPixel>
5
+ <version>0.1.0</version>
6
+ </Polytab_OmniPixel>
7
+ </modules>
8
+ <global>
9
+ <helpers>
10
+ <omnipixel>
11
+ <class>Polytab_OmniPixel_Helper</class>
12
+ </omnipixel>
13
+ </helpers>
14
+ <blocks>
15
+ <omnipixel>
16
+ <class>Polytab_OmniPixel_Block</class>
17
+ </omnipixel>
18
+ </blocks>
19
+ <models>
20
+ <omnipixel>
21
+ <class>Polytab_OmniPixel_Model</class>
22
+ <resourceModel>omnipixel_resource</resourceModel>
23
+ </omnipixel>
24
+ <omnipixel_resource>
25
+ <class>Polytab_OmniPixel_Model_Resource</class>
26
+ <entities>
27
+ <updated_products>
28
+ <table>datafeedwatch_updated_products</table>
29
+ </updated_products>
30
+ <omnipixelsetting>
31
+ <table>omnipixel_settings</table>
32
+ </omnipixelsetting>
33
+ </entities>
34
+ </omnipixel_resource>
35
+ </models>
36
+ <resources>
37
+ <omnipixel_setup>
38
+ <setup>
39
+ <module>Polytab_OmniPixel</module>
40
+ </setup>
41
+ </omnipixel_setup>
42
+ </resources>
43
+ <events>
44
+ <catalog_category_save_after>
45
+ <observers>
46
+ <omnipixel_catalog_category_save_after>
47
+ <class>omnipixel/observer</class>
48
+ <method>updateLastInheritanceUpdateDateOnCategoryChangeName</method>
49
+ </omnipixel_catalog_category_save_after>
50
+ </observers>
51
+ </catalog_category_save_after>
52
+ <catalog_category_delete_before>
53
+ <observers>
54
+ <omnipixel_catalog_category_delete_before>
55
+ <class>omnipixel/observer</class>
56
+ <method>updateLastInheritanceUpdateDate</method>
57
+ </omnipixel_catalog_category_delete_before>
58
+ </observers>
59
+ </catalog_category_delete_before>
60
+ <catalog_category_change_products>
61
+ <observers>
62
+ <omnipixel_catalog_category_change_products>
63
+ <class>omnipixel/observer</class>
64
+ <method>updateLastInheritanceUpdateDate</method>
65
+ </omnipixel_catalog_category_change_products>
66
+ </observers>
67
+ </catalog_category_change_products>
68
+ <catalog_category_tree_move_after>
69
+ <observers>
70
+ <omnipixel_catalog_category_tree_move_after>
71
+ <class>omnipixel/observer</class>
72
+ <method>updateLastInheritanceUpdateDate</method>
73
+ </omnipixel_catalog_category_tree_move_after>
74
+ </observers>
75
+ </catalog_category_tree_move_after>
76
+ <catalog_product_delete_before>
77
+ <observers>
78
+ <omnipixel_product_delete_before>
79
+ <class>omnipixel/observer</class>
80
+ <method>removeProductFromUpdatedTable</method>
81
+ </omnipixel_product_delete_before>
82
+ </observers>
83
+ </catalog_product_delete_before>
84
+ <catalog_product_save_after>
85
+ <observers>
86
+ <omnipixel_product_delete_before>
87
+ <class>omnipixel/observer</class>
88
+ <method>changeChildProductUpdatedAt</method>
89
+ </omnipixel_product_delete_before>
90
+ </observers>
91
+ </catalog_product_save_after>
92
+ <catalog_entity_attribute_save_before>
93
+ <observers>
94
+ <omnipixel_attribute_save_before>
95
+ <class>omnipixel/observer</class>
96
+ <method>checkAndUpdateAttributeInheritance</method>
97
+ </omnipixel_attribute_save_before>
98
+ </observers>
99
+ </catalog_entity_attribute_save_before>
100
+ <catalog_entity_attribute_delete_before>
101
+ <observers>
102
+ <omnipixel_attribute_delete_before>
103
+ <class>omnipixel/observer</class>
104
+ <method>updateLastInheritanceUpdateDate</method>
105
+ </omnipixel_attribute_delete_before>
106
+ </observers>
107
+ </catalog_entity_attribute_delete_before>
108
+ </events>
109
+ </global>
110
+ <frontend>
111
+ <layout>
112
+ <updates>
113
+ <omnipixel>
114
+ <file>omnipixel.xml</file>
115
+ </omnipixel>
116
+ </updates>
117
+ </layout>
118
+ </frontend>
119
+ <admin>
120
+ <routers>
121
+ <adminhtml>
122
+ <args>
123
+ <modules>
124
+ <Polytab_OmniPixel before="Mage_Adminhtml">Polytab_OmniPixel_Adminhtml</Polytab_OmniPixel>
125
+ </modules>
126
+ <frontName>omnipixel</frontName>
127
+ </args>
128
+ </adminhtml>
129
+ </routers>
130
+ </admin>
131
+ <adminhtml>
132
+ <events>
133
+ <adminhtml_catalog_product_attribute_edit_prepare_form>
134
+ <observers>
135
+ <connector_add_inheritance_field_to_attribute_form>
136
+ <class>omnipixel/observer</class>
137
+ <method>addInheritanceFieldToAttributeForm</method>
138
+ </connector_add_inheritance_field_to_attribute_form>
139
+ </observers>
140
+ </adminhtml_catalog_product_attribute_edit_prepare_form>
141
+ <model_config_data_save_before>
142
+ <observers>
143
+ <dfw_connector_update_inheritance_date_after_config_save>
144
+ <class>omnipixel/observer</class>
145
+ <method>updateInheritanceUpdateDate</method>
146
+ </dfw_connector_update_inheritance_date_after_config_save>
147
+ </observers>
148
+ </model_config_data_save_before>
149
+ </events>
150
+ <menu>
151
+ <omnipixel module="omnipixel">
152
+ <title>Polytab Attribution</title>
153
+ <sort_order>100</sort_order>
154
+ <children>
155
+ <omnipixelbackend module="omnipixel">
156
+ <title>Attribution Tracker</title>
157
+ <sort_order>1</sort_order>
158
+ <action>adminhtml/omnipixelbackend</action>
159
+ </omnipixelbackend>
160
+ <omnipixelbackend_config module="omnipixel">
161
+ <title>Settings</title>
162
+ <sort_order>2</sort_order>
163
+ <action>adminhtml/omnipixelbackend/config</action>
164
+ </omnipixelbackend_config>
165
+ <!--<setting>
166
+ <title>Polytab Pixel Heartbeat Settin</title>
167
+ <sort_order>3</sort_order>
168
+ <action>adminhtml/system_config/edit/section/omnipixel</action>
169
+ </setting>-->
170
+ </children>
171
+ </omnipixel>
172
+ </menu>
173
+ <acl>
174
+ <resources>
175
+ <all>
176
+ <title>Allow Everything</title>
177
+ </all>
178
+ <admin>
179
+ <children>
180
+ <omnipixel translate="title" module="omnipixel">
181
+ <title>OmniPixel</title>
182
+ <sort_order>1000</sort_order>
183
+ <children>
184
+ <omnipixelbackend translate="title">
185
+ <title>Polytab Pixel Heartbeat</title>
186
+ </omnipixelbackend>
187
+ </children>
188
+ </omnipixel>
189
+ <system>
190
+ <children>
191
+ <config>
192
+ <children>
193
+ <omnipixel>
194
+ <title>Polytab</title>
195
+ </omnipixel>
196
+ </children>
197
+ </config>
198
+ </children>
199
+ </system>
200
+ </children>
201
+ </admin>
202
+ </resources>
203
+ </acl>
204
+ <layout>
205
+ <updates>
206
+ <omnipixel>
207
+ <file>omnipixel.xml</file>
208
+ </omnipixel>
209
+ </updates>
210
+ </layout>
211
+ </adminhtml>
212
+ <crontab>
213
+ <jobs>
214
+ <omnipixel_fill_updated_at_table>
215
+ <schedule><cron_expr>0 * * * *</cron_expr></schedule>
216
+ <run><model>omnipixel/cron::reindex</model></run>
217
+ </omnipixel_fill_updated_at_table>
218
+ </jobs>
219
+ </crontab>
220
+ <default>
221
+ <omnipixel>
222
+ <general>
223
+ <debug>0</debug>
224
+ <terms_conditions>1</terms_conditions>
225
+ </general>
226
+ <custom_inheritance>
227
+ <product_url>1</product_url>
228
+ <image_url>0</image_url>
229
+ </custom_inheritance>
230
+ </omnipixel>
231
+ </default>
232
+ </config>
app/code/community/Polytab/OmniPixel/etc/system.xml ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <config>
3
+ <tabs>
4
+ <polytab translate="label" module="omnipixel">
5
+ <label>Polytab</label>
6
+ <sort_order>100</sort_order>
7
+ </polytab>
8
+ </tabs>
9
+
10
+ <sections>
11
+ <omnipixel translate="label" module="omnipixel">
12
+ <label>Settings</label>
13
+ <tab>polytab</tab>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <groups>
17
+ <general translate="label" module="omnipixel">
18
+ <label>General Configuration</label>
19
+ <frontend_type>text</frontend_type>
20
+ <sort_order>1</sort_order>
21
+ <show_in_default>1</show_in_default>
22
+ <expanded>1</expanded>
23
+ <fields>
24
+ <debug translate="label comment" module="omnipixel">
25
+ <label>Enable</label>
26
+ <frontend_type>select</frontend_type>
27
+ <source_model>adminhtml/system_config_source_yesno</source_model>
28
+ <sort_order>1</sort_order>
29
+ <show_in_default>1</show_in_default>
30
+ </debug>
31
+ <terms_conditions translate="label">
32
+ <label>Terms Conditions</label>
33
+ <frontend_type>checkbox</frontend_type>
34
+ <sort_order>2</sort_order>
35
+ <show_in_default>0</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <depends><debug>1</debug></depends>
39
+ <comment>By agreeing to install the Polytab attribution extension, you acknowledge acceptance of the terms and conditions listed <![CDATA[<a href="http://www.infemotions.com/privacy-terms-of-use/" target="_blank">here.</a>]]>
40
+ </comment>
41
+ <ans>
42
+
43
+ </ans>
44
+ </terms_conditions>
45
+ <!-- <public_id translate="label">
46
+ <label>Container Public ID</label>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>2</sort_order>
49
+ <show_in_default>1</show_in_default>
50
+ <show_in_website>1</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ <validate>validate-text required-entry</validate>
53
+ <depends><debug>1</debug></depends>
54
+ </public_id>-->
55
+ <platform_code translate="label comment">
56
+ <label>Platform Code</label>
57
+ <comment>Polytab attribution Client key.</comment>
58
+ <frontend_type>text</frontend_type>
59
+ <sort_order>3</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>1</show_in_website>
62
+ <show_in_store>1</show_in_store>
63
+ <validate>validate-text required-entry</validate>
64
+ <depends><debug>1</debug></depends>
65
+ </platform_code>
66
+ <get_secret_key translate="label" module="omnipixel">
67
+ <label>Get Client and Secret Key</label>
68
+ <frontend_type>button</frontend_type>
69
+ <frontend_model>omnipixel/adminhtml_system_config_form_button_extort</frontend_model>
70
+ <comment>Get Client Key and Secret Key.</comment>
71
+ <sort_order>4</sort_order>
72
+ <show_in_default>1</show_in_default>
73
+ <depends><debug>1</debug></depends>
74
+ </get_secret_key>
75
+ <client_key translate="label comment">
76
+ <label>Client Key</label>
77
+ <comment>Polytab attribution Client key.</comment>
78
+ <frontend_type>text</frontend_type>
79
+ <sort_order>5</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>0</show_in_website>
82
+ <show_in_store>0</show_in_store>
83
+ <depends><debug>1</debug></depends>
84
+ </client_key>
85
+ <secret_key translate="label comment">
86
+ <label>Secret Key</label>
87
+ <comment>Polytab attribution Secret Key.</comment>
88
+ <frontend_type>text</frontend_type>
89
+ <sort_order>6</sort_order>
90
+ <show_in_default>1</show_in_default>
91
+ <show_in_website>0</show_in_website>
92
+ <show_in_store>0</show_in_store>
93
+ <depends><debug>1</debug></depends>
94
+ </secret_key>
95
+ </fields>
96
+ </general>
97
+ </groups>
98
+ </omnipixel>
99
+ </sections>
100
+ </config>
app/code/community/Polytab/OmniPixel/sql/omnipixel_setup/install-0.1.0.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ /* @var $installer Mage_Core_Model_Resource_Setup */
5
+
6
+ $installer->startSetup();
7
+
8
+ $installer->run("
9
+ DROP TABLE IF EXISTS `{$this->getTable('omnipixel_settings')}`;
10
+ CREATE TABLE `{$this->getTable('omnipixel_settings')}` (
11
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
12
+ `is_enable` enum('1','0') NOT NULL DEFAULT '0',
13
+ `platform_code` varchar(100) NOT NULL,
14
+ `client_key` varchar(100) NOT NULL,
15
+ `secret_key` varchar(100) NOT NULL,
16
+ `terms` enum('1','0') NOT NULL DEFAULT '0',
17
+ PRIMARY KEY (`id`)
18
+ ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8;
19
+ ");
20
+
21
+ $installer->run("
22
+ INSERT INTO `omnipixel_settings` (`id`, `is_enable`, `platform_code`, `client_key`, `secret_key`, `terms`) VALUES ('1', '0', '', '', '', '0');
23
+ ");
24
+
25
+
26
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/omnipixel.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_omnipixelbackend_index>
4
+
5
+ <reference name="content">
6
+ <block type="adminhtml/template" name="omnipixel_omnipixelbackend" template="omnipixel/omnipixelbackend.phtml"/>
7
+ </reference>
8
+ </adminhtml_omnipixelbackend_index>
9
+ </layout>
app/design/adminhtml/default/default/template/omnipixel/omnipixelbackend.phtml ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $model = Mage::getModel('omnipixel/omnipixelsetting');
3
+ $model->load(1);
4
+ $data = $model->getData();
5
+ $enable = $data['is_enable'];
6
+
7
+ if($enable == '1')
8
+ {
9
+
10
+
11
+ $client_key = $data['client_key'];
12
+ $secret_key = $data['secret_key'];
13
+
14
+ $iframe_url = 'https://api.polytab.com/v1/api/ChannelPerformance/CPPage/'.$client_key.'/'.$secret_key;
15
+ if($client_key !='' && $secret_key !='')
16
+ {
17
+
18
+ ?>
19
+ <div id="inheritance_grid">
20
+ <iframe src="<?php echo $iframe_url; ?>" width="100%" frameborder="0"></iframe>
21
+ </div>
22
+ <?php
23
+ }
24
+ else
25
+ {
26
+ echo "You need to enbale this extension to view channel performance report.";
27
+ }
28
+ }
29
+ else
30
+ {
31
+ echo "You need to enbale this extension to view channel performance report.";
32
+ }
33
+ ?>
34
+ <style>
35
+ #inheritance_grid iframe
36
+ {
37
+ height: 450px !important;
38
+ }
39
+ </style>
app/design/frontend/base/default/layout/omnipixel.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="head">
5
+ <block type="core/template" name="ajax_analytics" template="omnipixel/scripthead.phtml"/>
6
+ </reference>
7
+ </default>
8
+ </layout>
app/etc/modules/Polytab_OmniPixel.xml ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Polytab_OmniPixel>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <version>0.1.0</version>
8
+ </Polytab_OmniPixel>
9
+ </modules>
10
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Polytab_Marketing_Attribution_Tracker</name>
4
+ <version>1.0.3</version>
5
+ <stability>stable</stability>
6
+ <license uri="https://opensource.org/licenses/osl-3.0.php">Open Software License 3.0 (OSL-3.0)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Polytab Attribution Tracker</summary>
10
+ <description>Polytab Attribution Tracker</description>
11
+ <notes>Polytab Attribution Tracker will work after enable extension.</notes>
12
+ <authors><author><name>Polytab Tech</name><user>varun</user><email>varun@infernotions.com</email></author></authors>
13
+ <date>2016-12-12</date>
14
+ <time>09:22:34</time>
15
+ <contents><target name="magecommunity"><dir name="Polytab"><dir name="OmniPixel"><dir name="Block"><dir name="Adminhtml"><dir name="Form"><dir name="Setting"><file name="Form.php" hash="84b46db9e5645c0f6bbe1d585481416b"/></dir><file name="Setting.php" hash="03771c303e95d65640f1f0f5816610fd"/></dir><file name="OmniPixelsetting.php" hash="d73e7385b9f1ebe39a101e722d40a0b1"/><dir name="Settings"><dir name="Edit"><file name="Form.php" hash="22b82a296a0938b1a29dc06e5d914317"/><dir name="Tab"><file name="Form.php" hash="23e0fdb2b4048191c2543257c3a1929d"/></dir><file name="Tabs.php" hash="bf8537bc9bd2fe6e86a41133df73c9b8"/></dir><file name="Edit.php" hash="c4f1962a7f70948324029204bb33b9d9"/></dir><file name="Settings.php" hash="c4fe046b24cd0b360815e800d4f3d809"/></dir></dir><dir name="Helper"><file name="Data.php" hash="a539396741c2590e02dc812b0b9243cf"/><file name="Registry.php" hash="357be4d9edcdb124b47176a279067288"/></dir><dir name="Model"><dir name="Api"><file name="User.php" hash="859229338e356b62500be79b43952807"/></dir><file name="Api.php" hash="67ba174f8dc86805c3a0ee8571f301bd"/><file name="Cron.php" hash="8afe0db5c6a5d91dc0f7d01a4e3fe186"/><file name="Observer.php" hash="2c665cb05cb2e403801765bdae3dc6a5"/><file name="Omnipixelsetting.php" hash="be590f4fdbdc69d0a08672b476106419"/><file name="Product.php" hash="f73d8d7153a1d23b331523777666f238"/><dir name="Resource"><dir name="Omnipixelsetting"><dir name="Collection"><file name="Db.php" hash="be8a716c6a71753e5b5f19617107afd8"/></dir><file name="Collection.php" hash="42a67f90507e4840c7e6c178128611a8"/></dir><file name="Omnipixelsetting.php" hash="272b2304d1d7a8dd8dd9ee4368b79895"/><dir name="Product"><dir name="Collection"><file name="Db.php" hash="8184820b5c6e1d01b9e6b7df3f529e43"/></dir><file name="Collection.php" hash="5403913fe2e67e9d515c18ae5143fb49"/></dir><file name="Product.php" hash="88a6d2573e0a4c36d2ce337a84b58572"/><dir name="Settings"><dir name="Collection"><file name="Db.php" hash="8184820b5c6e1d01b9e6b7df3f529e43"/></dir><file name="Collection.php" hash="2b2d20e6ac99fba35266619eb25916d1"/></dir><file name="Settings.php" hash="251fda447d397f164ea47243d45c680b"/></dir><file name="Settings.php" hash="ec99e65ac1cdafe86683a743f71a22d9"/><dir name="System"><dir name="Config"><dir name="Source"><file name="Inheritance.php" hash="6a9c2f4523fcd1ddd574deff11934b07"/><dir name="Textarea"><file name="Values.php" hash="c96c05eafdd9f61eb7a3547d83478533"/></dir></dir></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="OmnipixelbackendController.php" hash="0ca71a040644a2ce8181d41972536141"/></dir></dir><dir name="etc"><file name="api.xml" hash="a76a7e3edb2be36b96a07dc1861822ef"/><file name="config.xml" hash="29616ebf42b5a39292163b9a58e1cf1f"/><file name="system.xml" hash="66ed6bcfdded4352acc0e047f0e161e4"/></dir><dir name="sql"><dir name="omnipixel_setup"><file name="install-0.1.0.php" hash="d5631887f3b357633d0df7ffaab3992e"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Polytab_OmniPixel.xml" hash="584a5307e4eb2409030a6a1ad85c7977"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="omnipixel.xml" hash="09c10454874342f991ae4df77f8c6234"/></dir><dir name="template"><dir name="omnipixel"><file name="omnipixelbackend.phtml" hash="c3e7687a95d40f6ba5f51f4cf61c25ec"/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="omnipixel.xml" hash="a6630abf760d500255cd7a4f292baf4a"/></dir></dir></dir></dir></target><target name="magelocal"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="omnipixel"><file name="scripthead.phtml" hash=""/></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>