Channelpilotsolutions_Channelpilot - Version 2.1.4

Version Notes

- fixed some bugs

Download this release

Release Info

Developer Magento Core Team
Extension Channelpilotsolutions_Channelpilot
Version 2.1.4
Comparing to
See all releases


Code changes from version 2.1.3 to 2.1.4

app/code/community/Channelpilotsolutions/Channelpilot/Adminhtml/Model/Articlenumber/Values.php CHANGED
@@ -1,33 +1,34 @@
1
- <?php
2
- /**
3
- *
4
- * NOTICE OF LICENSE
5
- *
6
- * This source file is subject to the GNU General Public License (GPL 3)
7
- * that is bundled with this package in the file LICENSE.txt
8
- *
9
- * DISCLAIMER
10
- *
11
- * Do not edit or add to this file if you wish to upgrade Channelpilotsolutions_Channelpilot to newer
12
- * versions in the future. If you wish to customize Channelpilotsolutions_Channelpilot for your
13
- * needs please refer to http://www.channelpilot.com for more information.
14
- *
15
- * @category Channelpilotsolutions
16
- * @package Channelpilotsolutions_Channelpilot
17
- * @subpackage adminhtml_model_cookiemode
18
- * @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
19
- * @author Peter Hoffmann <info@channelpilot.com>
20
- * @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
21
- * @link http://www.channelpilot.com
22
- */
23
- class Channelpilotsolutions_Channelpilot_Adminhtml_Model_Articlenumber_Values
24
- {
25
- public function toOptionArray()
26
- {
27
- return array(
28
- array('value' => 'product_id', 'label'=>'Entity ID'),
29
- array('value' => 'sku', 'label'=>'Sku')
30
- );
31
- }
32
- }
33
?>
1
+ <?php
2
+ /**
3
+ *
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the GNU General Public License (GPL 3)
7
+ * that is bundled with this package in the file LICENSE.txt
8
+ *
9
+ * DISCLAIMER
10
+ *
11
+ * Do not edit or add to this file if you wish to upgrade Channelpilotsolutions_Channelpilot to newer
12
+ * versions in the future. If you wish to customize Channelpilotsolutions_Channelpilot for your
13
+ * needs please refer to http://www.channelpilot.com for more information.
14
+ *
15
+ * @category Channelpilotsolutions
16
+ * @package Channelpilotsolutions_Channelpilot
17
+ * @subpackage adminhtml_model_cookiemode
18
+ * @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
19
+ * @author Peter Hoffmann <info@channelpilot.com>
20
+ * @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
21
+ * @link http://www.channelpilot.com
22
+ */
23
+ class Channelpilotsolutions_Channelpilot_Adminhtml_Model_Articlenumber_Values
24
+ {
25
+ public function toOptionArray()
26
+ {
27
+ return array(
28
+ array('value' => "---", 'label' => "---"),
29
+ array('value' => 'product_id', 'label'=>'Entity ID'),
30
+ array('value' => 'sku', 'label'=>'Sku')
31
+ );
32
+ }
33
+ }
34
?>
app/code/community/Channelpilotsolutions/Channelpilot/Adminhtml/Model/Orderstatus/Values.php ADDED
@@ -0,0 +1,47 @@
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the GNU General Public License (GPL 3)
8
+ * that is bundled with this package in the file LICENSE.txt
9
+ *
10
+ * DISCLAIMER
11
+ *
12
+ * Do not edit or add to this file if you wish to upgrade Channelpilotsolutions_Channelpilot to newer
13
+ * versions in the future. If you wish to customize Channelpilotsolutions_Channelpilot for your
14
+ * needs please refer to http://www.channelpilot.com for more information.
15
+ *
16
+ * @category Channelpilotsolutions
17
+ * @package Channelpilotsolutions_Channelpilot
18
+ * @subpackage adminhtml_model_cookiemode
19
+ * @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
20
+ * @author Peter Hoffmann <info@channelpilot.com>
21
+ * @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
22
+ * @link http://www.channelpilot.com
23
+ */
24
+ class Channelpilotsolutions_Channelpilot_Adminhtml_Model_Orderstatus_Values {
25
+
26
+ public function toOptionArray() {
27
+
28
+ $sQuery = "select * from sales_order_status;";
29
+ $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
30
+ try {
31
+ $sResult = $dbConnection->fetchAll($sQuery);
32
+ $result_array = array();
33
+ $result_array[] = array('value' => "---", 'label' => "---");
34
+ foreach ($sResult as $resultType) {
35
+ $result_array[] = array('value' => $resultType['status'], 'label' => $resultType['label']);
36
+ }
37
+ } catch (Exception $e) {
38
+ $dbConnection->closeConnection();
39
+ }
40
+ $dbConnection->closeConnection();
41
+
42
+ return $result_array;
43
+ }
44
+
45
+ }
46
+
47
+ ?>
app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Exportfields.php CHANGED
@@ -1,81 +1,82 @@
1
- <?php
2
-
3
- /**
4
- *
5
- * NOTICE OF LICENSE
6
- *
7
- * This source file is subject to the GNU General Public License (GPL 3)
8
- * that is bundled with this package in the file LICENSE.txt
9
- *
10
- * DISCLAIMER
11
- *
12
- * Do not edit or add to this file if you wish to upgrade Channelpilotsolutions_Channelpilot to newer
13
- * versions in the future. If you wish to customize Channelpilotsolutions_Channelpilot for your
14
- * needs please refer to http://www.channelpilot.com for more information.
15
- *
16
- * @category Channelpilotsolutions
17
- * @package Channelpilotsolutions_Channelpilot
18
- * @subpackage block_adminhtml_field
19
- * @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
20
- * @author Peter Hoffmann <info@channelpilot.com>
21
- * @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
22
- * @link http://www.channelpilot.com
23
- */
24
- class Channelpilotsolutions_Channelpilot_Block_Adminhtml_Field_Exportfields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
25
-
26
- private $_standardattributes;
27
-
28
- public function __construct() {
29
- $this->addColumn('productattribute', array(
30
- 'label' => Mage::helper('adminhtml')->__('Data field'),
31
- 'size' => 30
32
- ));
33
- $this->_addAfter = false;
34
-
35
- parent::__construct();
36
- $this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
37
- }
38
-
39
- protected function _renderCellTemplate($columnName) {
40
- $this->_standardattributes = "('sku','price','name','description','manufacturer','color','weight', 'parent_id')";
41
- if (empty($this->_columns[$columnName])) {
42
- throw new Exception('Wrong column name specified.');
43
- }
44
- $column = $this->_columns[$columnName];
45
- $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
46
-
47
- if ($columnName == 'productattribute') {
48
- $rendered = '<select name="' . $inputName . '">';
49
-
50
- $tableName = Mage::getSingleton('core/resource')->getTableName('core_website');
51
- $tablePrefix = substr($tableName, 0, strpos($tableName, 'core_website'));
52
- $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
53
-
54
- // Get attribute codes and types
55
- $query = "SELECT attribute_code
56
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute
57
- WHERE entity_type_id = (SELECT entity_type_id FROM
58
- ChannelPilotSolutions_ChannelPilot_eav_entity_type WHERE entity_type_code = 'catalog_product') AND
59
- attribute_code NOT IN $this->_standardattributes
60
- ";
61
- $query = str_replace('ChannelPilotSolutions_ChannelPilot_', $tablePrefix, $query);
62
- $attributes = $dbConnection->FetchAssoc($query);
63
-
64
- $attributes[]['attribute_code'] = 'qty';
65
- $attributes[]['attribute_code'] = 'stock_status';
66
- $attributes[]['attribute_code'] = 'cp_color_attribute_id';
67
- // $attributes[]['attribute_code'] = 'parent_id';
68
- asort($attributes);
69
- foreach ($attributes as $attribute) {
70
- $rendered .= '<option value="' . $attribute['attribute_code'] . '">' . $attribute['attribute_code'] . '</option>';
71
- }
72
- $rendered .= '</select>';
73
- return $rendered;
74
- }
75
-
76
- return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"/>';
77
- }
78
-
79
- }
80
-
81
?>
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the GNU General Public License (GPL 3)
8
+ * that is bundled with this package in the file LICENSE.txt
9
+ *
10
+ * DISCLAIMER
11
+ *
12
+ * Do not edit or add to this file if you wish to upgrade Channelpilotsolutions_Channelpilot to newer
13
+ * versions in the future. If you wish to customize Channelpilotsolutions_Channelpilot for your
14
+ * needs please refer to http://www.channelpilot.com for more information.
15
+ *
16
+ * @category Channelpilotsolutions
17
+ * @package Channelpilotsolutions_Channelpilot
18
+ * @subpackage block_adminhtml_field
19
+ * @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
20
+ * @author Peter Hoffmann <info@channelpilot.com>
21
+ * @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
22
+ * @link http://www.channelpilot.com
23
+ */
24
+ class Channelpilotsolutions_Channelpilot_Block_Adminhtml_Field_Exportfields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
25
+
26
+ private $_standardattributes;
27
+
28
+ public function __construct() {
29
+ $this->addColumn('productattribute', array(
30
+ 'label' => Mage::helper('adminhtml')->__('Data field'),
31
+ 'size' => 30
32
+ ));
33
+ $this->_addAfter = false;
34
+
35
+ parent::__construct();
36
+ $this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
37
+ }
38
+
39
+ protected function _renderCellTemplate($columnName) {
40
+ $this->_standardattributes = "('sku','price','name','description','manufacturer','color','weight', 'parent_id')";
41
+ if (empty($this->_columns[$columnName])) {
42
+ throw new Exception('Wrong column name specified.');
43
+ }
44
+ $column = $this->_columns[$columnName];
45
+ $inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
46
+
47
+ if ($columnName == 'productattribute') {
48
+ $rendered = '<select name="' . $inputName . '">';
49
+
50
+ $tableName = Mage::getSingleton('core/resource')->getTableName('core_website');
51
+ $tablePrefix = substr($tableName, 0, strpos($tableName, 'core_website'));
52
+ $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
53
+
54
+ // Get attribute codes and types
55
+ $query = "SELECT attribute_code
56
+ FROM ChannelPilotSolutions_ChannelPilot_eav_attribute
57
+ WHERE entity_type_id = (SELECT entity_type_id FROM
58
+ ChannelPilotSolutions_ChannelPilot_eav_entity_type WHERE entity_type_code = 'catalog_product') AND
59
+ attribute_code NOT IN $this->_standardattributes
60
+ ";
61
+ $query = str_replace('ChannelPilotSolutions_ChannelPilot_', $tablePrefix, $query);
62
+ $attributes = $dbConnection->FetchAssoc($query);
63
+
64
+ $attributes[]['attribute_code'] = 'qty';
65
+ $attributes[]['attribute_code'] = 'stock_status';
66
+ $attributes[]['attribute_code'] = 'cp_color_attribute_id';
67
+ $attributes[]['attribute_code'] = 'type_id';
68
+ // $attributes[]['attribute_code'] = 'parent_id';
69
+ asort($attributes);
70
+ foreach ($attributes as $attribute) {
71
+ $rendered .= '<option value="' . $attribute['attribute_code'] . '">' . $attribute['attribute_code'] . '</option>';
72
+ }
73
+ $rendered .= '</select>';
74
+ return $rendered;
75
+ }
76
+
77
+ return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"/>';
78
+ }
79
+
80
+ }
81
+
82
?>
app/code/community/Channelpilotsolutions/Channelpilot/Helper/Data.php CHANGED
@@ -66,7 +66,7 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
66
}
67
68
public function createXml() {
69
- if (strpos(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport'), "true") !== false || strpos(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport'), "1") !== false) {
70
$password = Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_password');
71
if ($password == '' || (isset($_GET['password']) AND $_GET['password'] == $password)) {
72
header('Content-Type: text/xml; charset=utf-8');
@@ -93,19 +93,19 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
93
}
94
95
$newsActive = false;
96
- if (strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_useNews'), "true") === 0 || strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_useNews'), "1") === 0) {
97
$newsActive = true;
98
}
99
$marketplaceActive = false;
100
- if (strcmp(Mage::getStoreConfig('channelpilot_marketplace/channelpilot_marketplace/channelpilot_useMarketplaces'), "true") === 0 || strcmp(Mage::getStoreConfig('channelpilot_marketplace/channelpilot_marketplace/channelpilot_useMarketplaces'), "1") === 0) {
101
$marketplaceActive = true;
102
}
103
$pricecontrolActive = false;
104
- if (strcmp(Mage::getStoreConfig('channelpilot_pricecontrol/channelpilot_general/channelpilot_usePricecontrol'), "true") === 0 || strcmp(Mage::getStoreConfig('channelpilot_pricecontrol/channelpilot_general/channelpilot_usePricecontrol'), "1") === 0) {
105
$pricecontrolActive = true;
106
- }
107
$exportActive = false;
108
- if (strcmp(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport'), "true") === 0 || strcmp(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport'), "1") === 0) {
109
$exportActive = true;
110
}
111
@@ -177,7 +177,7 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
177
case self::GET_DEBUG:
178
$this->checkSignature();
179
$handler = new CPDebugHandler();
180
- $hook = $handler->handle();
181
break;
182
183
default:
@@ -210,7 +210,7 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
210
}
211
212
private function checkIp() {
213
- if (strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp'), "true") === 0) {
214
$allIps = array();
215
$allIps[] = CPAbstractHandler::ChannelPilot_IP;
216
$sQuery = "SELECT ips_authorized FROM " . CPAbstractHandler::DB_REGISTRATION;
66
}
67
68
public function createXml() {
69
+ if (Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport')) {
70
$password = Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_password');
71
if ($password == '' || (isset($_GET['password']) AND $_GET['password'] == $password)) {
72
header('Content-Type: text/xml; charset=utf-8');
93
}
94
95
$newsActive = false;
96
+ if (Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_useNews')) {
97
$newsActive = true;
98
}
99
$marketplaceActive = false;
100
+ if (Mage::getStoreConfig('channelpilot_marketplace/channelpilot_marketplace/channelpilot_useMarketplaces')) {
101
$marketplaceActive = true;
102
}
103
$pricecontrolActive = false;
104
+ if (Mage::getStoreConfig('channelpilot_pricecontrol/channelpilot_general/channelpilot_usePricecontrol')) {
105
$pricecontrolActive = true;
106
+ }
107
$exportActive = false;
108
+ if (Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport')) {
109
$exportActive = true;
110
}
111
177
case self::GET_DEBUG:
178
$this->checkSignature();
179
$handler = new CPDebugHandler();
180
+ $hook = $handler->handle();
181
break;
182
183
default:
210
}
211
212
private function checkIp() {
213
+ if (Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp')) {
214
$allIps = array();
215
$allIps[] = CPAbstractHandler::ChannelPilot_IP;
216
$sQuery = "SELECT ips_authorized FROM " . CPAbstractHandler::DB_REGISTRATION;
app/code/community/Channelpilotsolutions/Channelpilot/Helper/ExportData.php CHANGED
@@ -23,13 +23,14 @@
23
*/
24
class ExportData {
25
26
- private $_tablePrefix;
27
private $_storeId;
28
private $_siteId;
29
private $_mediaUrl;
30
private $_webUrl;
31
private $_dbConnection;
32
private $_allCat;
33
private $oldCatPath;
34
private $xml;
35
@@ -44,26 +45,36 @@ class ExportData {
44
45
// Get the table prefix
46
$tableName = Mage::getSingleton('core/resource')->getTableName('core_website');
47
- $this->_tablePrefix = substr($tableName, 0, strpos($tableName, 'core_website'));
48
49
// Get database connection
50
$this->_dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
51
}
52
53
- // Apply prefix to table names in the query
54
- private function _applyTablePrefix($query) {
55
- return str_replace('ChannelPilotSolutions_ChannelPilot_', $this->_tablePrefix, $query);
56
- }
57
-
58
// Run the main application and call the appropriate function
59
// depending on the command.
60
public function _runMain() {
61
- if (isset($_GET['store']) AND $_GET['store'] != '') {
62
- $this->_storeId = $_GET['store'];
63
- } else {
64
- $this->_storeId = Mage::app()->getStore()->getId();
65
- }
66
67
// Validate store and get information
68
$this->_getStoreInformation();
69
@@ -95,27 +106,37 @@ class ExportData {
95
// Get category information
96
$query = '';
97
if (substr(Mage::getVersion(), 2, 3) >= 6) {
98
- $query = "
99
- SELECT DISTINCT fs.entity_id, fs.path, fs.name
100
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_product_index AS pi
101
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_flat_store_" . $this->_storeId . " AS fs
102
- ON pi.category_id = fs.entity_id
103
- ORDER BY fs.path ASC
104
- ";
105
} else {
106
- $query = "
107
- SELECT DISTINCT ev.entity_id, ce.path, ev.value
108
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_entity_varchar AS ev
109
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_entity AS ce ON ev.entity_id = ce.entity_id
110
- WHERE ev.attribute_id = (
111
- SELECT attribute_id
112
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute as att
113
- WHERE att.entity_type_id = ev.entity_type_id AND att.attribute_code='name'
114
- )
115
- ORDER BY ce.path ASC
116
- ";
117
}
118
- $query = $this->_applyTablePrefix($query);
119
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
120
121
$categoriesTable = $this->_dbConnection->fetchAll($query);
@@ -143,23 +164,23 @@ class ExportData {
143
$oldCatPath = $categorie[1];
144
}
145
146
- // print_r($this->_allCat);
147
- // exit();
148
// By default, set media gallery attribute id to 703
149
// Look it up later
150
$MEDIA_GALLERY_ATTRIBUTE_ID = 703;
151
152
// Get the entity type for products
153
- $query = "SELECT entity_type_id FROM ChannelPilotSolutions_ChannelPilot_eav_entity_type WHERE entity_type_code = 'catalog_product'";
154
- $query = $this->_applyTablePrefix($query);
155
$PRODUCT_ENTITY_TYPE_ID = $this->_dbConnection->fetchOne($query);
156
157
// Get attribute codes and types
158
- $query = "SELECT attribute_id, attribute_code, backend_type, frontend_input
159
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute
160
- WHERE entity_type_id = $PRODUCT_ENTITY_TYPE_ID
161
- ";
162
- $query = $this->_applyTablePrefix($query);
163
$attributes = $this->_dbConnection->FetchAssoc($query);
164
$attributeCodes = array();
165
$blankProduct = array();
@@ -217,22 +238,28 @@ class ExportData {
217
// in a lookup array for performance (avoids several joins/aggregations)
218
if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') {
219
// Get the option_id => value from the attribute options
220
- $query = "
221
- SELECT
222
- CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.option_id) ELSE
223
- MAX(CASE WHEN aov.store_id = " . $this->_storeId . " THEN aov.option_id ELSE NULL END)
224
- END AS 'option_id'
225
- ,CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.value) ELSE
226
- MAX(CASE WHEN aov.store_id = " . $this->_storeId . " THEN aov.value ELSE NULL END)
227
- END AS 'value'
228
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute_option AS ao
229
- INNER JOIN ChannelPilotSolutions_ChannelPilot_eav_attribute_option_value AS aov
230
- ON ao.option_id = aov.option_id
231
- WHERE aov.store_id IN (" . $this->_storeId . ", 0)
232
- AND ao.attribute_id = " . $row['attribute_id'] . "
233
- GROUP BY aov.option_id
234
- ";
235
- $query = $this->_applyTablePrefix($query);
236
$result = $this->_dbConnection->fetchPairs($query);
237
238
// If found, then save the lookup table in the attributeOptions array
@@ -247,43 +274,47 @@ class ExportData {
247
}
248
249
$export_data_fields_codes = '';
250
- $export_data_fields_ids = '';
251
foreach (array_keys($blankProduct) as $key) {
252
$export_data_fields_codes = $export_data_fields_codes . "'" . $key . "',";
253
$tmpid = array_search($key, $attributeCodes);
254
if (!empty($tmpid)) {
255
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
256
}
257
}
258
259
$export_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_exportfields'));
260
if (!empty($export_fields)) {
261
foreach ($export_fields as $element) {
262
if (!empty($element['productattribute'])) {
263
$blankProduct[preg_replace('/\W/', '', $element['productattribute'])] = '';
264
$export_data_fields_codes = $export_data_fields_codes . "'" . $element['productattribute'] . "',";
265
- $tmpid = array_search($element['productattribute'], $attributeCodes);
266
- if (!empty($tmpid)) {
267
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
268
- }
269
}
270
}
271
}
272
273
$tmpid = array_search('status', $attributeCodes);
274
if (!empty($tmpid)) {
275
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
276
}
277
$tmpid = array_search('url_path', $attributeCodes);
278
if (!empty($tmpid)) {
279
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
280
}
281
$tmpid = array_search('image', $attributeCodes);
282
if (!empty($tmpid)) {
283
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
284
}
285
- $export_data_fields_ids = rtrim($export_data_fields_ids, ',');
286
-
287
288
289
// Build queries for each attribute type
@@ -297,32 +328,41 @@ class ExportData {
297
$queries = array();
298
foreach ($backendTypes as $backendType) {
299
// Get store value if there is one, otherwise, global value
300
- $queries[] = "
301
- SELECT CASE WHEN SUM(ev.store_id) = 0 THEN MAX(ev.value) ELSE
302
- MAX(CASE WHEN ev.store_id = " . $this->_storeId . " THEN ev.value ELSE NULL END)
303
- END AS 'value', ev.attribute_id
304
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity
305
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_entity_$backendType AS ev
306
- ON ChannelPilotSolutions_ChannelPilot_catalog_product_entity.entity_id = ev.entity_id
307
- WHERE ev.store_id IN (" . $this->_storeId . ", 0)
308
- AND ev.entity_type_id = $PRODUCT_ENTITY_TYPE_ID
309
- AND ev.entity_id = @ENTITY_ID AND ev.attribute_id IN (" . $export_data_fields_ids . ")
310
- GROUP BY ev.attribute_id, ev.entity_id
311
- ";
312
}
313
$query = implode(" UNION ALL ", $queries);
314
$MasterProductQuery = $query;
315
316
$count = 0;
317
- $query = "
318
- SELECT count(*)
319
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity AS cpe
320
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_website as cpw
321
- ON cpw.product_id = cpe.entity_id
322
- WHERE cpw.website_id = " . $this->_siteId . "
323
- AND IFNULL(cpe.sku, '') != ''
324
- ";
325
- $query = $this->_applyTablePrefix($query);
326
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
327
$count = $this->_dbConnection->fetchAll($query);
328
@@ -339,22 +379,63 @@ class ExportData {
339
$variationThemes = array();
340
while ($counter <= $border) {
341
// Get all entity_ids for all products in the selected store
342
- $query = "
343
- SELECT cpe.entity_id, cpe.sku,
344
- (SELECT parent_id FROM ChannelPilotSolutions_ChannelPilot_catalog_product_super_link WHERE product_id=cpe.entity_id LIMIT 1) as parent,
345
- (SELECT count(*) FROM ChannelPilotSolutions_ChannelPilot_catalog_product_super_link WHERE parent_id=cpe.entity_id LIMIT 1) as is_parent,
346
- (SELECT qty FROM ChannelPilotSolutions_ChannelPilot_cataloginventory_stock_status WHERE product_id=cpe.entity_id AND website_id=" . $this->_siteId . " AND stock_id = 1 LIMIT 1) as qty,
347
- (SELECT stock_status FROM ChannelPilotSolutions_ChannelPilot_cataloginventory_stock_status WHERE product_id=cpe.entity_id AND website_id=" . $this->_siteId . " AND stock_id = 1 LIMIT 1) as stock_status,
348
- (SELECT crpp.rule_price FROM ChannelPilotSolutions_ChannelPilot_catalogrule_product_price AS crpp WHERE crpp.rule_date = CURDATE() AND crpp.product_id =cpe.entity_id AND crpp.customer_group_id = 1 AND crpp.website_id = " . $this->_siteId . ") as cat_price
349
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity AS cpe
350
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_website as cpw
351
- ON cpw.product_id = cpe.entity_id
352
- WHERE cpw.website_id = " . $this->_siteId . "
353
- AND IFNULL(cpe.sku, '') != ''
354
- ORDER BY is_parent DESC, entity_id DESC
355
- LIMIT " . $counter . ", " . $selectLimit . "
356
- ";
357
- $query = $this->_applyTablePrefix($query);
358
// Set fetch mode to numeric to save memory
359
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
360
$EntityIds = $this->_dbConnection->fetchAll($query);
@@ -367,7 +448,6 @@ class ExportData {
367
// $entity[0] = entity_id
368
// $entity[1] = sku
369
$query = str_replace('@ENTITY_ID', $entity[0], $MasterProductQuery);
370
- $query = $this->_applyTablePrefix($query);
371
$result = $this->_dbConnection->query($query);
372
373
@@ -375,10 +455,17 @@ class ExportData {
375
$product = $blankProduct;
376
377
if (intval($entity[3]) > 0) {
378
- $varQuery = "SELECT ea.attribute_code FROM ChannelPilotSolutions_ChannelPilot_catalog_product_super_attribute cpsa
379
- LEFT JOIN ChannelPilotSolutions_ChannelPilot_eav_attribute ea ON ea.attribute_id = cpsa.attribute_id
380
- WHERE cpsa.product_id = '$entity[0]' ORDER BY ea.attribute_id; ";
381
- $varQuery = $this->_applyTablePrefix($varQuery);
382
$varresults = $this->_dbConnection->fetchAll($varQuery);
383
$variationTheme = "";
384
foreach ($varresults as $varresult) {
@@ -392,20 +479,17 @@ class ExportData {
392
}
393
}
394
395
-
396
-
397
-
398
-
399
// Initialize basic product data
400
$product['entity_id'] = $entity[0];
401
$product['sku'] = $entity[1];
402
403
// Escape the SKU (it may contain double-quotes)
404
$product['sku'] = str_replace('"', '""', $product['sku']);
405
406
- $product_status;
407
- $product_url;
408
- $product_image;
409
// Loop through each field in the row and get the value
410
while (true) {
411
// Get next column
@@ -461,24 +545,34 @@ class ExportData {
461
continue;
462
}
463
// Get category information
464
- $query = '';
465
if (substr(Mage::getVersion(), 2, 3) >= 6) {
466
- $query = "
467
- SELECT DISTINCT fs.entity_id, fs.path, fs.name
468
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_product_index AS pi
469
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_flat_store_" . $this->_storeId . " AS fs
470
- ON pi.category_id = fs.entity_id
471
- WHERE pi.product_id = " . $entity[0] . " ORDER BY fs.path ASC
472
- ";
473
} else {
474
- $query = "
475
- SELECT pi.category_id, ce.path
476
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_product_index AS pi
477
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_entity AS ce ON pi.category_id = ce.entity_id
478
- WHERE pi.product_id = " . $entity[0] . " AND pi.is_parent = 1 AND pi.store_id = " . $this->_storeId . " ORDER BY ce.path ASC
479
- ";
480
}
481
- $query = $this->_applyTablePrefix($query);
482
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
483
484
$categoriesTable = $this->_dbConnection->fetchAll($query);
@@ -508,6 +602,9 @@ class ExportData {
508
$categorieField = $this->_allCat[$this->oldCatPath];
509
}
510
}
511
$product['categories'] = $categorieField;
512
513
// Get stock quantity
@@ -529,20 +626,25 @@ class ExportData {
529
$stockInfoResult = null;
530
531
// Get additional image URLs
532
- $galleryImagePrefix = $this->_dbConnection->quote($this->_mediaUrl . 'catalog/product');
533
- $query = "
534
- SELECT
535
- GROUP_CONCAT(gallery.value_id SEPARATOR ',') AS value_id
536
- ,GROUP_CONCAT(CONCAT(" . $galleryImagePrefix . ", gallery.value) SEPARATOR ',') AS value
537
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity_media_gallery AS gallery
538
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_entity_media_gallery_value AS gallery_value
539
- ON gallery.value_id = gallery_value.value_id
540
- WHERE gallery_value.store_id IN (" . $this->_storeId . ", 0)
541
- AND gallery_value.disabled = 0
542
- AND gallery.entity_id=" . $entity[0] . "
543
- AND gallery.attribute_id = " . $MEDIA_GALLERY_ATTRIBUTE_ID . "
544
- ORDER BY gallery_value.position ASC";
545
- $query = $this->_applyTablePrefix($query);
546
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
547
$galleryValues = $this->_dbConnection->fetchAll($query);
548
if (empty($galleryValues) != true) {
@@ -567,7 +669,7 @@ class ExportData {
567
568
// Calculate image and product URLs
569
if (empty($product_url) == false) {
570
- $product['cp_product_url'] = $this->_urlPathJoin($this->_webUrl, $product_url);
571
}
572
573
if (empty($product_image) == false) {
@@ -594,6 +696,14 @@ class ExportData {
594
}
595
}
596
}
597
$this->xml = new SimpleXMLElement("<product></product>");
598
echo str_replace('<?xml version="1.0"?>', '', $this->toXML($product));
599
$this->xml = null;
@@ -617,6 +727,7 @@ class ExportData {
617
// Load the store information
618
$this->_siteId = $store->getWebsiteId();
619
$this->_webUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
620
$this->_mediaUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
621
} catch (Exception $e) {
622
die('Store=' . $this->_storeId . " probably does not exist.");
23
*/
24
class ExportData {
25
26
private $_storeId;
27
private $_siteId;
28
private $_mediaUrl;
29
private $_webUrl;
30
private $_dbConnection;
31
private $_allCat;
32
+ private $_currencyChange;
33
+ private $_storeCode;
34
private $oldCatPath;
35
private $xml;
36
45
46
// Get the table prefix
47
$tableName = Mage::getSingleton('core/resource')->getTableName('core_website');
48
49
// Get database connection
50
$this->_dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
51
}
52
53
// Run the main application and call the appropriate function
54
// depending on the command.
55
public function _runMain() {
56
+ try {
57
+ $storeId = Mage::app()->getRequest()->getParam('store', null);
58
+ $this->_storeId = Mage::app()->getStore($storeId)->getId();
59
+ } catch(Exception $e) {
60
+ // The exception thrown by Mage::app()->getStore() has an empty message ...
61
+ echo "<error>Error retrieving store.</error>";
62
+ return;
63
+ }
64
+
65
+ $currencyCode = Mage::app()->getRequest()->getParam('currency', false);
66
+ if ($currencyCode && $currencyCode != '') {
67
+ $query = new Zend_Db_Select($this->_dbConnection);
68
+ $query->from(Mage::getSingleton('core/resource')->getTableName('directory_currency_rate'));
69
+ $query->where('currency_to = ?', $currencyCode);
70
+ $result = $this->_dbConnection->fetchAll($query);
71
+ if(sizeof($result) === 0){
72
+ echo "<error>wrong currency</error>";
73
+ return;
74
+ }
75
+ $this->_currencyChange = $result[0]['rate'];
76
77
+ }
78
// Validate store and get information
79
$this->_getStoreInformation();
80
106
// Get category information
107
$query = '';
108
if (substr(Mage::getVersion(), 2, 3) >= 6) {
109
+ $query = new Zend_Db_Select($this->_dbConnection);
110
+ $query->distinct();
111
+ $query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
112
+ array('fs.entity_id', 'fs.path', 'fs.name')
113
+ );
114
+ $query->join(
115
+ array('fs' => Mage::getSingleton('core/resource')->getTableName(array('catalog/category_flat','store_'.$this->_storeId))),
116
+ 'pi.category_id = fs.entity_id',
117
+ null
118
+ );
119
+ $query->order('fs.path ASC');
120
} else {
121
+ $query = new Zend_Db_Select($this->_dbConnection);
122
+ $query->distinct();
123
+ $query->from(array('ev' => Mage::getSingleton('core/resource')->getTableName(array('catalog/category', 'varchar'))),
124
+ array('ev.entity_id', 'ce.path', 'ev.value')
125
+ );
126
+ $query->join(
127
+ array('ce' => Mage::getSingleton('core/resource')->getTableName('catalog/category')),
128
+ 'ev.entity_id = ce.entity_id',
129
+ null
130
+ );
131
+
132
+ $subquery = new Zend_Db_Select($this->_dbConnection);
133
+ $subquery->from(array('att' => Mage::getSingleton('core/resource')->getTableName('eav/attribute')), array('attribute_id'));
134
+ $subquery->where('att.entity_type_id = ev.entity_type_id AND att.attribute_code = \'name\'');
135
+
136
+ $query->where('ev.attribute_id = ('.$subquery->__toString().')');
137
+ $query->order('ce.path ASC');
138
}
139
+
140
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
141
142
$categoriesTable = $this->_dbConnection->fetchAll($query);
164
$oldCatPath = $categorie[1];
165
}
166
167
// By default, set media gallery attribute id to 703
168
// Look it up later
169
$MEDIA_GALLERY_ATTRIBUTE_ID = 703;
170
171
// Get the entity type for products
172
+ $query = new Zend_Db_Select($this->_dbConnection);
173
+ $query->from(Mage::getSingleton('core/resource')->getTableName('eav/entity_type'), array('entity_type_id'));
174
+ $query->where('entity_type_code = ?', Mage_Catalog_Model_Product::ENTITY);
175
+
176
$PRODUCT_ENTITY_TYPE_ID = $this->_dbConnection->fetchOne($query);
177
178
// Get attribute codes and types
179
+ $query = new Zend_Db_Select($this->_dbConnection);
180
+ $query->from(Mage::getSingleton('core/resource')->getTableName('eav/attribute'),
181
+ array('attribute_id', 'attribute_code', 'backend_type', 'frontend_input'));
182
+ $query->where('entity_type_id = ?', $PRODUCT_ENTITY_TYPE_ID);
183
+
184
$attributes = $this->_dbConnection->FetchAssoc($query);
185
$attributeCodes = array();
186
$blankProduct = array();
238
// in a lookup array for performance (avoids several joins/aggregations)
239
if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') {
240
// Get the option_id => value from the attribute options
241
+ $query = new Zend_Db_Select($this->_dbConnection);
242
+ $query->from(array('ao' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_option')),
243
+ array(
244
+ new Zend_Db_Expr($this->_dbConnection->quoteInto(
245
+ 'CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.option_id) ELSE
246
+ MAX(CASE WHEN aov.store_id = ? THEN aov.option_id ELSE NULL END)
247
+ END AS \'option_id\'
248
+ ,CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.value) ELSE
249
+ MAX(CASE WHEN aov.store_id = ? THEN aov.value ELSE NULL END)
250
+ END AS \'value\'',
251
+ $this->_storeId
252
+ ))
253
+ )
254
+ );
255
+ $query->join(array('aov' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_option_value')),
256
+ 'ao.option_id = aov.option_id',
257
+ null
258
+ );
259
+ $query->where('aov.store_id IN (0, ?)', $this->_storeId);
260
+ $query->where('ao.attribute_id = ?', $row['attribute_id']);
261
+ $query->group('aov.option_id');
262
+
263
$result = $this->_dbConnection->fetchPairs($query);
264
265
// If found, then save the lookup table in the attributeOptions array
274
}
275
276
$export_data_fields_codes = '';
277
+ $export_data_fields_ids = array();
278
foreach (array_keys($blankProduct) as $key) {
279
$export_data_fields_codes = $export_data_fields_codes . "'" . $key . "',";
280
$tmpid = array_search($key, $attributeCodes);
281
if (!empty($tmpid)) {
282
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
283
}
284
}
285
286
$export_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_exportfields'));
287
+ $useTypeId = false;
288
if (!empty($export_fields)) {
289
foreach ($export_fields as $element) {
290
if (!empty($element['productattribute'])) {
291
$blankProduct[preg_replace('/\W/', '', $element['productattribute'])] = '';
292
$export_data_fields_codes = $export_data_fields_codes . "'" . $element['productattribute'] . "',";
293
+ if($element['productattribute'] == 'type_id') {
294
+ $useTypeId = true;
295
+ } else {
296
+ $tmpid = array_search($element['productattribute'], $attributeCodes);
297
+ if (!empty($tmpid)) {
298
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
299
+ }
300
+ }
301
}
302
}
303
}
304
305
$tmpid = array_search('status', $attributeCodes);
306
if (!empty($tmpid)) {
307
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
308
}
309
$tmpid = array_search('url_path', $attributeCodes);
310
if (!empty($tmpid)) {
311
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
312
}
313
$tmpid = array_search('image', $attributeCodes);
314
if (!empty($tmpid)) {
315
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
316
}
317
+ $export_data_fields_ids = implode(',',$export_data_fields_ids);
318
319
320
// Build queries for each attribute type
328
$queries = array();
329
foreach ($backendTypes as $backendType) {
330
// Get store value if there is one, otherwise, global value
331
+ $query = new Zend_Db_Select($this->_dbConnection);
332
+ $query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
333
+ array(new Zend_Db_Expr($this->_dbConnection->quoteInto('
334
+ CASE WHEN SUM(ev.store_id) = 0 THEN MAX(ev.value) ELSE
335
+ MAX(CASE WHEN ev.store_id = ? THEN ev.value ELSE NULL END)
336
+ END AS \'value\'
337
+ ', $this->_storeId)), 'ev.attribute_id')
338
+ );
339
+ $query->join(array('ev' => Mage::getSingleton('core/resource')->getTableName(array('catalog/product', $backendType))),
340
+ 'cpe.entity_id = ev.entity_id',
341
+ null
342
+ );
343
+ $query->where('ev.store_id IN (0, ?)', $this->_storeId);
344
+ $query->where('ev.entity_type_id = ?', $PRODUCT_ENTITY_TYPE_ID);
345
+ $query->where('ev.entity_id = @ENTITY_ID');
346
+ $query->where('ev.attribute_id IN ('.$export_data_fields_ids.')');
347
+ $query->group(array('ev.attribute_id', 'ev.entity_id'));
348
+
349
+ $queries[] = $query->__toString();
350
}
351
$query = implode(" UNION ALL ", $queries);
352
$MasterProductQuery = $query;
353
354
$count = 0;
355
+ $query = new Zend_Db_Select($this->_dbConnection);
356
+ $query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
357
+ new Zend_Db_Expr('count(*)')
358
+ );
359
+ $query->join(array('cpw' => Mage::getSingleton('core/resource')->getTableName('catalog/product_website')),
360
+ 'cpw.product_id = cpe.entity_id',
361
+ null
362
+ );
363
+ $query->where('cpw.website_id = ?', $this->_siteId);
364
+ $query->where("IFNULL(cpe.sku, '') != ''");
365
+
366
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
367
$count = $this->_dbConnection->fetchAll($query);
368
379
$variationThemes = array();
380
while ($counter <= $border) {
381
// Get all entity_ids for all products in the selected store
382
+ $columns = array('cpe.entity_id', 'cpe.sku');
383
+ $query = new Zend_Db_Select($this->_dbConnection);
384
+
385
+ $subquery = new Zend_Db_Select($this->_dbConnection);
386
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'), array('parent_id'));
387
+ $subquery->where('product_id = cpe.entity_id');
388
+ $subquery->limit(1);
389
+
390
+ $columns['parent'] = new Zend_Db_Expr('('.$subquery.')');
391
+
392
+ $subquery = new Zend_Db_Select($this->_dbConnection);
393
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'), array(
394
+ new Zend_Db_Expr('COUNT(*)')
395
+ ));
396
+ $subquery->where('parent_id = cpe.entity_id');
397
+ $subquery->limit(1);
398
+
399
+ $columns['is_parent'] = new Zend_Db_Expr('('.$subquery.')');
400
+
401
+ $subquery = new Zend_Db_Select($this->_dbConnection);
402
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'), array('qty'));
403
+ $subquery->where('product_id = cpe.entity_id');
404
+ $subquery->where('website_id = ?', $this->_siteId);
405
+ $subquery->where('stock_id = 1');
406
+ $subquery->limit(1);
407
+
408
+ $columns['qty'] = new Zend_Db_Expr('('.$subquery.')');
409
+
410
+ $subquery = new Zend_Db_Select($this->_dbConnection);
411
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'), array('stock_status'));
412
+ $subquery->where('product_id = cpe.entity_id');
413
+ $subquery->where('website_id = ?', $this->_siteId);
414
+ $subquery->where('stock_id = 1');
415
+ $subquery->limit(1);
416
+
417
+ $columns['stock_status'] = new Zend_Db_Expr('('.$subquery.')');
418
+
419
+ $subquery = new Zend_Db_Select($this->_dbConnection);
420
+ $subquery->from(array('crpp' => Mage::getSingleton('core/resource')->getTableName('catalogrule/rule_product_price')), array('crpp.rule_price'));
421
+ $subquery->where('crpp.rule_date = CURDATE()');
422
+ $subquery->where('crpp.product_id = cpe.entity_id');
423
+ $subquery->where('crpp.customer_group_id = 1');
424
+ $subquery->where('crpp.website_id = ?', $this->_siteId);
425
+
426
+ $columns['cat_price'] = new Zend_Db_Expr('('.$subquery.')');
427
+ $columns[] = 'cpe.type_id';
428
+
429
+ $query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), $columns);
430
+ $query->join(array('cpw' => Mage::getSingleton('core/resource')->getTableName('catalog/product_website')),
431
+ 'cpw.product_id = cpe.entity_id',
432
+ null
433
+ );
434
+ $query->where('cpw.website_id = ?', $this->_siteId);
435
+ $query->where("IFNULL(cpe.sku, '') != ''");
436
+ $query->order(array('is_parent DESC', 'entity_id DESC'));
437
+ $query->limit($selectLimit, $counter);
438
+
439
// Set fetch mode to numeric to save memory
440
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
441
$EntityIds = $this->_dbConnection->fetchAll($query);
448
// $entity[0] = entity_id
449
// $entity[1] = sku
450
$query = str_replace('@ENTITY_ID', $entity[0], $MasterProductQuery);
451
$result = $this->_dbConnection->query($query);
452
453
455
$product = $blankProduct;
456
457
if (intval($entity[3]) > 0) {
458
+ $varQuery = new Zend_Db_Select($this->_dbConnection);
459
+ $varQuery->from(array('cpsa' => Mage::getSingleton('core/resource')->getTableName('catalog/product_super_attribute')),
460
+ array('ea.attribute_code')
461
+ );
462
+ $varQuery->joinLeft(array('ea' => Mage::getSingleton('core/resource')->getTableName('eav/attribute')),
463
+ 'ea.attribute_id = cpsa.attribute_id',
464
+ null
465
+ );
466
+ $varQuery->where('cpsa.product_id = ?', $entity[0]);
467
+ $varQuery->order('ea.attribute_id');
468
+
469
$varresults = $this->_dbConnection->fetchAll($varQuery);
470
$variationTheme = "";
471
foreach ($varresults as $varresult) {
479
}
480
}
481
482
// Initialize basic product data
483
$product['entity_id'] = $entity[0];
484
$product['sku'] = $entity[1];
485
486
// Escape the SKU (it may contain double-quotes)
487
$product['sku'] = str_replace('"', '""', $product['sku']);
488
+ $product['is_parent'] = $entity[3] > 0 ? 1 : 0;
489
490
+ $product_status = null;
491
+ $product_url = null;
492
+ $product_image = null;
493
// Loop through each field in the row and get the value
494
while (true) {
495
// Get next column
545
continue;
546
}
547
// Get category information
548
if (substr(Mage::getVersion(), 2, 3) >= 6) {
549
+ $query = new Zend_Db_Select($this->_dbConnection);
550
+ $query->distinct();
551
+ $query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
552
+ array('fs.entity_id', 'fs.path', 'fs.name')
553
+ );
554
+ $query->join(array('fs' => Mage::getSingleton('core/resource')->getTableName(array('catalog/category_flat', 'store_'.$this->_storeId))),
555
+ 'pi.category_id = fs.entity_id',
556
+ null
557
+ );
558
+ $query->where('pi.product_id = ?', $entity[0]);
559
+ $query->where('pi.store_id = ?', $this->_storeId);
560
+ $query->order('fs.path ASC');
561
} else {
562
+ $query = new Zend_Db_Select($this->_dbConnection);
563
+ $query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
564
+ array('pi.category_id', 'ce.path')
565
+ );
566
+ $query->join(array('ce' => Mage::getSingleton('core/resource')->getTableName('catalog/category')),
567
+ 'pi.category_id = ce.entity_id',
568
+ null
569
+ );
570
+ $query->where('pi.product_id = ?', $entity[0]);
571
+ $query->where('pi.is_parent = 1');
572
+ $query->where('pi.store_id = ?', $this->_storeId);
573
+ $query->order('ce.path ASC');
574
}
575
+
576
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
577
578
$categoriesTable = $this->_dbConnection->fetchAll($query);
602
$categorieField = $this->_allCat[$this->oldCatPath];
603
}
604
}
605
+
606
+ //print_r($query);
607
+ //exit;
608
$product['categories'] = $categorieField;
609
610
// Get stock quantity
626
$stockInfoResult = null;
627
628
// Get additional image URLs
629
+ $query = new Zend_Db_Select($this->_dbConnection);
630
+ $query->from(array('gallery' => Mage::getSingleton('core/resource')->getTableName('catalog/product_attribute_media_gallery')),
631
+ array(
632
+ new Zend_Db_Expr("GROUP_CONCAT(gallery.value_id SEPARATOR ',') AS value_id"),
633
+ new Zend_Db_Expr("GROUP_CONCAT(CONCAT(" .
634
+ $this->_dbConnection->quote($this->_mediaUrl . 'catalog/product') .
635
+ ", gallery.value) SEPARATOR ',') AS value")
636
+ )
637
+ );
638
+ $query->join(array('gallery_value' => Mage::getSingleton('core/resource')->getTableName('catalog/product_attribute_media_gallery_value')),
639
+ 'gallery.value_id = gallery_value.value_id',
640
+ null
641
+ );
642
+ $query->where('gallery_value.store_id IN (0, ?)', $this->_storeId);
643
+ $query->where('gallery_value.disabled = 0');
644
+ $query->where('gallery.entity_id = ?',$entity[0]);
645
+ $query->where('gallery.attribute_id = ?', $MEDIA_GALLERY_ATTRIBUTE_ID);
646
+ $query->order('gallery_value.position ASC');
647
+
648
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
649
$galleryValues = $this->_dbConnection->fetchAll($query);
650
if (empty($galleryValues) != true) {
669
670
// Calculate image and product URLs
671
if (empty($product_url) == false) {
672
+ $product['cp_product_url'] = $this->_urlPathJoin($this->_webUrl.$this->_storeCode, $product_url);
673
}
674
675
if (empty($product_image) == false) {
696
}
697
}
698
}
699
+ if(isset($this->_currencyChange)) {
700
+ $product['price'] = round($product['price']*$this->_currencyChange, 2);
701
+ }
702
+
703
+ if($useTypeId) {
704
+ $product['type_id'] = $entity[7];
705
+ }
706
+
707
$this->xml = new SimpleXMLElement("<product></product>");
708
echo str_replace('<?xml version="1.0"?>', '', $this->toXML($product));
709
$this->xml = null;
727
// Load the store information
728
$this->_siteId = $store->getWebsiteId();
729
$this->_webUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
730
+ $this->_storeCode = Mage::getStoreConfig('web/url/use_store') ? $store->getCode(). "/" : "";
731
$this->_mediaUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
732
} catch (Exception $e) {
733
die('Store=' . $this->_storeId . " probably does not exist.");
app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPAbstractHandler.php CHANGED
@@ -1,198 +1,198 @@
1
- <?php
2
-
3
- /**
4
- * an cp abstract handler
5
- * @author Channel Pilot Solutions GmbH <api@channelpilot.com>
6
- * @version 1.0
7
- */
8
- class CPAbstractHandler {
9
-
10
- const defaultHeader = "Content-Type: application/json;";
11
- const errorHeader_forbidden = "HTTP/1.0 403 Forbidden";
12
- const ChannelPilot_IP = "148.251.65.130";
13
- const DB_REGISTRATION = "cp_registration";
14
- const DB_PRICES = "cp_prices";
15
- const DB_ORDERS = "cp_marketplace_orders";
16
- const DB_ORDER_ITEMS = "cp_marketplace_order_items";
17
-
18
- /**
19
- * Is the IP allowed for this shopId
20
- *
21
- * @param type $shopId
22
- * @return boolean
23
- */
24
- public static function isIpAllowedViaShopId($shopId, $dbConnection) {
25
- if (self::ChannelPilot_IP == $_SERVER['REMOTE_ADDR'] || strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp'), "false") == 0) {
26
- return true;
27
- } else {
28
- return in_array($_SERVER['REMOTE_ADDR'], self::getAllowedIpsViaShopId($shopId, $dbConnection));
29
- }
30
- }
31
-
32
- /**
33
- * Is the IP allowed for this securityToken
34
- *
35
- * @param type $token
36
- * @return boolean
37
- */
38
- public static function isIpAllowedViaSecurityToken($token) {
39
- if (self::ChannelPilot_IP == $_SERVER['REMOTE_ADDR'] || strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp'), "false") == 0) {
40
- return true;
41
- } else {
42
- return in_array($_SERVER['REMOTE_ADDR'], self::getAllowedIpsViaSecurityToken($token));
43
- }
44
- }
45
-
46
- /**
47
- * Get allowed ips for the shop via securityToken
48
- *
49
- * @param type $token
50
- * @return array with allowed ips
51
- */
52
- public static function getAllowedIpsViaSecurityToken($token) {
53
- $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
54
- $sQuery = "SELECT ips_authorized FROM " . self::DB_REGISTRATION . " WHERE securityToken = ?;";
55
- $array = array($token);
56
- try {
57
- $sResult = $dbConnection->fetchOne($sQuery, $array);
58
- $dbConnection->closeConnection();
59
- return explode(";", $sResult);
60
- } catch (Exception $e) {
61
- $dbConnection->closeConnection();
62
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getAllowedIpsViaSecurityToken(): " . $e->getMessage(), "Exception in getAllowedIpsViaSecurityToken(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
63
- }
64
- return null;
65
- }
66
-
67
- /**
68
- * Get allowed ips for the shop via shopId
69
- *
70
- * @param type $shopId
71
- * @return array with allowed ips
72
- */
73
- public static function getAllowedIpsViaShopId($shopId) {
74
- $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
75
- $sQuery = "SELECT ips_authorized FROM " . self::DB_REGISTRATION . " WHERE shopId = ?;";
76
- $array = array($shopId);
77
- try {
78
- $sResult = $dbConnection->fetchOne($sQuery, $array);
79
- $dbConnection->closeConnection();
80
- return explode(";", $sResult);
81
- } catch (Exception $e) {
82
- $dbConnection->closeConnection();
83
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getAllowedIpsViaShopId(): " . $e->getMessage(), "Exception in getAllowedIpsViaShopId(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
84
- }
85
- return null;
86
- }
87
-
88
- /**
89
- * Is the shop still registered?
90
- *
91
- * @param integer $shopId
92
- * @return boolean
93
- */
94
- public static function isShopRegistered($shopId) {
95
- $sQuery = "SELECT shopId FROM " . self::DB_REGISTRATION . " WHERE shopId = ?;";
96
- $array = array($shopId);
97
- $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
98
- try {
99
- $sResult = $dbConnection->fetchOne($sQuery, $array);
100
- $dbConnection->closeConnection();
101
- if (empty($sResult)) {
102
- return false;
103
- }
104
- } catch (Exception $e) {
105
- $dbConnection->closeConnection();
106
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in isShopRegistered(): " . $e->getMessage(), "Exception in isShopRegistered(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
107
- }
108
- return true;
109
- }
110
-
111
- public static function getMerchantId($token) {
112
- $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
113
- $sQuery = "SELECT merchantId FROM " . self::DB_REGISTRATION . " WHERE securityToken = ?;";
114
- $array = array($token);
115
- try {
116
- $sResult = $dbConnection->fetchOne($sQuery, $array);
117
- $dbConnection->closeConnection();
118
- } catch (Exception $e) {
119
- $dbConnection->closeConnection();
120
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getMerchantId(): " . $e->getMessage(), "Exception in getMerchantId(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
121
- }
122
- return $sResult;
123
- }
124
-
125
- /**
126
- * Get shopId by token for registered shop
127
- *
128
- * @param type $token
129
- * @param type $dbConnection
130
- * @return type
131
- */
132
- public static function getShopId($token, $dbConnection) {
133
- $sQuery = "SELECT shopId FROM " . self::DB_REGISTRATION . " WHERE securityToken = ?;";
134
- $array = array($token);
135
- try {
136
- $sResult = $dbConnection->fetchOne($sQuery, $array);
137
- } catch (Exception $e) {
138
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getShopId(): " . $e->getMessage(), "Exception in getShopId(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
139
- $dbConnection->closeConnection();
140
- }
141
- return $sResult;
142
- }
143
-
144
- public static function changeStatusOrders($apiOrders, $dbConnection) {
145
- foreach ($apiOrders as $apiOrder) {
146
- if ($apiOrder->header->resultCode == CPResultCodes::SUCCESS) {
147
- self::changeStatusOrder($apiOrder->orderHeader, $dbConnection);
148
- } else {
149
- self::logError("Cannot change orderstatus from order (id: '" . $apiOrder->orderHeader->orderId . "', status: '" . $apiOrder->orderHeader->status->identifier . "')");
150
- }
151
- }
152
- }
153
-
154
- public static function changeStatusOrder($apiOrderHeader, $dbConnection) {
155
- $query = "update " . self::DB_ORDERS . " set status = ? where order_nr = ?;";
156
- $array = array($apiOrderHeader->status->identifier, $apiOrderHeader->orderId);
157
- try {
158
- $dbConnection->query($query, $array);
159
- } catch (Exception $e) {
160
- $dbConnection->closeConnections();
161
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception during changeStatusOrder: " . $e->getMessage(), "Exception during insert into cp_marketplace_orders: '$query'\n" . print_r($array, true) . "\n" . $e->getMessage());
162
- }
163
- }
164
-
165
- /**
166
- * log the error in the cp_marketplace - log file
167
- *
168
- * @param type $msg
169
- */
170
- public static function logError($msg) {
171
- $msg = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI] by IP: {$_SERVER['REMOTE_ADDR']}\n$msg";
172
-
173
- Mage::log("$msg\n\n", null, 'cp_plugin.log');
174
- $dbWriteConnection = Mage::getSingleton('core/resource')->getConnection('core_write');
175
- $query = "INSERT INTO cp_logging (created, content) VALUES (NOW(), ?);";
176
- $array = array($msg);
177
- $dbWriteConnection->query($query, $array);
178
- $dbWriteConnection->closeConnection();
179
- }
180
-
181
- public static function checkConfig() {
182
- /* if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_ART_NUMBER')==2 && oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_ART_OTHERARTNUM')==''){
183
- CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No column for other article number", "No column for other article number");
184
- }
185
- if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_IMPORT')==''){
186
- CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No folder for unpaid orders", "No folder for unpaid orders");
187
- }
188
- if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_PAIDIMPORT')==''){
189
- CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No folder for paid orders", "No folder for paid orders");
190
- }
191
- if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_CANCEL')==''){
192
- CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No folder for cancelled orders", "No folder for cancelled orders");
193
- } */
194
- }
195
-
196
- }
197
-
198
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * an cp abstract handler
5
+ * @author Channel Pilot Solutions GmbH <api@channelpilot.com>
6
+ * @version 1.0
7
+ */
8
+ class CPAbstractHandler {
9
+
10
+ const defaultHeader = "Content-Type: application/json;";
11
+ const errorHeader_forbidden = "HTTP/1.0 403 Forbidden";
12
+ const ChannelPilot_IP = "148.251.65.130";
13
+ const DB_REGISTRATION = "cp_registration";
14
+ const DB_PRICES = "cp_prices";
15
+ const DB_ORDERS = "cp_marketplace_orders";
16
+ const DB_ORDER_ITEMS = "cp_marketplace_order_items";
17
+
18
+ /**
19
+ * Is the IP allowed for this shopId
20
+ *
21
+ * @param type $shopId
22
+ * @return boolean
23
+ */
24
+ public static function isIpAllowedViaShopId($shopId, $dbConnection) {
25
+ if (self::ChannelPilot_IP == $_SERVER['REMOTE_ADDR'] || strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp'), "false") == 0) {
26
+ return true;
27
+ } else {
28
+ return in_array($_SERVER['REMOTE_ADDR'], self::getAllowedIpsViaShopId($shopId, $dbConnection));
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Is the IP allowed for this securityToken
34
+ *
35
+ * @param type $token
36
+ * @return boolean
37
+ */
38
+ public static function isIpAllowedViaSecurityToken($token) {
39
+ if (self::ChannelPilot_IP == $_SERVER['REMOTE_ADDR'] || strcmp(Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp'), "false") == 0) {
40
+ return true;
41
+ } else {
42
+ return in_array($_SERVER['REMOTE_ADDR'], self::getAllowedIpsViaSecurityToken($token));
43
+ }
44
+ }
45
+
46
+ /**
47
+ * Get allowed ips for the shop via securityToken
48
+ *
49
+ * @param type $token
50
+ * @return array with allowed ips
51
+ */
52
+ public static function getAllowedIpsViaSecurityToken($token) {
53
+ $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
54
+ $sQuery = "SELECT ips_authorized FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_REGISTRATION . " WHERE securityToken = ?;";
55
+ $array = array($token);
56
+ try {
57
+ $sResult = $dbConnection->fetchOne($sQuery, $array);
58
+ $dbConnection->closeConnection();
59
+ return explode(";", $sResult);
60
+ } catch (Exception $e) {
61
+ $dbConnection->closeConnection();
62
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getAllowedIpsViaSecurityToken(): " . $e->getMessage(), "Exception in getAllowedIpsViaSecurityToken(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
63
+ }
64
+ return null;
65
+ }
66
+
67
+ /**
68
+ * Get allowed ips for the shop via shopId
69
+ *
70
+ * @param type $shopId
71
+ * @return array with allowed ips
72
+ */
73
+ public static function getAllowedIpsViaShopId($shopId) {
74
+ $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
75
+ $sQuery = "SELECT ips_authorized FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_REGISTRATION . " WHERE shopId = ?;";
76
+ $array = array($shopId);
77
+ try {
78
+ $sResult = $dbConnection->fetchOne($sQuery, $array);
79
+ $dbConnection->closeConnection();
80
+ return explode(";", $sResult);
81
+ } catch (Exception $e) {
82
+ $dbConnection->closeConnection();
83
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getAllowedIpsViaShopId(): " . $e->getMessage(), "Exception in getAllowedIpsViaShopId(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
84
+ }
85
+ return null;
86
+ }
87
+
88
+ /**
89
+ * Is the shop still registered?
90
+ *
91
+ * @param integer $shopId
92
+ * @return boolean
93
+ */
94
+ public static function isShopRegistered($shopId) {
95
+ $sQuery = "SELECT shopId FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_REGISTRATION . " WHERE shopId = ?;";
96
+ $array = array($shopId);
97
+ $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
98
+ try {
99
+ $sResult = $dbConnection->fetchOne($sQuery, $array);
100
+ $dbConnection->closeConnection();
101
+ if (empty($sResult)) {
102
+ return false;
103
+ }
104
+ } catch (Exception $e) {
105
+ $dbConnection->closeConnection();
106
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in isShopRegistered(): " . $e->getMessage(), "Exception in isShopRegistered(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
107
+ }
108
+ return true;
109
+ }
110
+
111
+ public static function getMerchantId($token) {
112
+ $dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
113
+ $sQuery = "SELECT merchantId FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_REGISTRATION . " WHERE securityToken = ?;";
114
+ $array = array($token);
115
+ try {
116
+ $sResult = $dbConnection->fetchOne($sQuery, $array);
117
+ $dbConnection->closeConnection();
118
+ } catch (Exception $e) {
119
+ $dbConnection->closeConnection();
120
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getMerchantId(): " . $e->getMessage(), "Exception in getMerchantId(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
121
+ }
122
+ return $sResult;
123
+ }
124
+
125
+ /**
126
+ * Get shopId by token for registered shop
127
+ *
128
+ * @param type $token
129
+ * @param type $dbConnection
130
+ * @return type
131
+ */
132
+ public static function getShopId($token, $dbConnection) {
133
+ $sQuery = "SELECT shopId FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_REGISTRATION . " WHERE securityToken = ?;";
134
+ $array = array($token);
135
+ try {
136
+ $sResult = $dbConnection->fetchOne($sQuery, $array);
137
+ } catch (Exception $e) {
138
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getShopId(): " . $e->getMessage(), "Exception in getShopId(): '$sQuery'\n" . print_r($array, true) . "\n" . $e->getMessage());
139
+ $dbConnection->closeConnection();
140
+ }
141
+ return $sResult;
142
+ }
143
+
144
+ public static function changeStatusOrders($apiOrders, $dbConnection) {
145
+ foreach ($apiOrders as $apiOrder) {
146
+ if ($apiOrder->header->resultCode == CPResultCodes::SUCCESS) {
147
+ self::changeStatusOrder($apiOrder->orderHeader, $dbConnection);
148
+ } else {
149
+ self::logError("Cannot change orderstatus from order (id: '" . $apiOrder->orderHeader->orderId . "', status: '" . $apiOrder->orderHeader->status->identifier . "')");
150
+ }
151
+ }
152
+ }
153
+
154
+ public static function changeStatusOrder($apiOrderHeader, $dbConnection) {
155
+ $query = "update " . (string)Mage::getConfig()->getTablePrefix().self::DB_ORDERS . " set status = ? where order_nr = ?;";
156
+ $array = array($apiOrderHeader->status->identifier, $apiOrderHeader->orderId);
157
+ try {
158
+ $dbConnection->query($query, $array);
159
+ } catch (Exception $e) {
160
+ $dbConnection->closeConnections();
161
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception during changeStatusOrder: " . $e->getMessage(), "Exception during insert into cp_marketplace_orders: '$query'\n" . print_r($array, true) . "\n" . $e->getMessage());
162
+ }
163
+ }
164
+
165
+ /**
166
+ * log the error in the cp_marketplace - log file
167
+ *
168
+ * @param type $msg
169
+ */
170
+ public static function logError($msg) {
171
+ $msg = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI] by IP: {$_SERVER['REMOTE_ADDR']}\n$msg";
172
+
173
+ Mage::log("$msg\n\n", null, 'cp_plugin.log');
174
+ $dbWriteConnection = Mage::getSingleton('core/resource')->getConnection('core_write');
175
+ $query = "INSERT INTO ".(string)Mage::getConfig()->getTablePrefix()."cp_logging (created, content) VALUES (NOW(), ?);";
176
+ $array = array($msg);
177
+ $dbWriteConnection->query($query, $array);
178
+ $dbWriteConnection->closeConnection();
179
+ }
180
+
181
+ public static function checkConfig() {
182
+ /* if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_ART_NUMBER')==2 && oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_ART_OTHERARTNUM')==''){
183
+ CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No column for other article number", "No column for other article number");
184
+ }
185
+ if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_IMPORT')==''){
186
+ CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No folder for unpaid orders", "No folder for unpaid orders");
187
+ }
188
+ if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_PAIDIMPORT')==''){
189
+ CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No folder for paid orders", "No folder for paid orders");
190
+ }
191
+ if(oxConfig::getInstance()->getShopConfVar('CPMARKETPLACE_CANCEL')==''){
192
+ CPErrorHandler::handle(CPErrors::RESULT_CONFIG_INVALID, "No folder for cancelled orders", "No folder for cancelled orders");
193
+ } */
194
+ }
195
+
196
+ }
197
+
198
+ ?>
app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPCancellationHandler.php CHANGED
@@ -1,142 +1,142 @@
1
- <?php
2
-
3
- /**
4
- * an cp cancellation handler
5
- * @author Channel Pilot Solutions GmbH <api@channelpilot.com>
6
- * @version 1.0
7
- */
8
- class CPCancellationHandler extends CPAbstractHandler {
9
-
10
- /**
11
- * Handle cancellation hook.
12
- * @return type
13
- */
14
- public function handle() {
15
- if (isset($_GET['token']) && self::isIpAllowedViaSecurityToken($_GET['token'])) {
16
- self::checkConfig();
17
- if (isset($_GET['limit'])) {
18
- $cancelled = array();
19
-
20
- $cancelledOrders = self::getCancelledOrders();
21
- foreach ($cancelledOrders as $orders) {
22
- if (isset($orders)) {
23
- $cancelled[] = $orders;
24
- }
25
- }
26
- $cancelledOrderItems = self::getCancelledItems();
27
-
28
- foreach ($cancelledOrderItems as $orders) {
29
- if (isset($orders)) {
30
- $cancelled[] = $orders;
31
- }
32
- }
33
-
34
- if (sizeof($cancelled) == 0) {
35
- self::hookResult(false);
36
- }
37
- $merchantId = self::getMerchantId($_GET['token']);
38
- $api = new ChannelPilotSellerAPI_v1_0($merchantId, $_GET['token']);
39
- $result = $api->registerCancellations($cancelled);
40
- if ($result->header->resultCode == CPResultCodes::SUCCESS) {
41
- // return $result;
42
-
43
- $dbWriteConnection = Mage::getSingleton('core/resource')->getConnection('core_write');
44
- self::changeStatusOrders($result->updateResults, $dbWriteConnection);
45
- $dbWriteConnection->closeConnection();
46
- } else {
47
- // Result from registerDeliveries has no success
48
- self::logError("request registerDeliveries() resultCode " . $result->header->resultCode);
49
- $hook = new CPHookResponse();
50
- $hook->resultCode = CPResultCodes::SUCCESS;
51
- $hook->resultMessage = "request registerDeliveries() resultCode " . $result->header->resultCode;
52
- $hook->moreAvailable = false;
53
- $hook->apiResultCode = $result->header->resultCode;
54
- $hook->writeResponse(self::defaultHeader, json_encode($hook));
55
- }
56
- self::hookResult(true);
57
- } else {
58
- CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "not enough parameter for method: " . $_GET['method'], "not enough parameter for method: " . $_GET['method']);
59
- }
60
- } else {
61
- if (empty($_GET['token'])) {
62
- CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "no token found", "no token found");
63
- } else {
64
- CPErrorHandler::handle(CPErrors::RESULT_FAILED, "ip not allowed by token: " . $_GET['token'], "ip not allowed by token: " . $_GET['token']);
65
- }
66
- }
67
- }
68
-
69
- private function hookResult($moreAvailable) {
70
- $hook = new CPHookResponse();
71
- $hook->resultCode = CPResultCodes::SUCCESS;
72
- $hook->resultMessage = "CANCELLATION HOOK SUCCESS";
73
- $hook->moreAvailable = $moreAvailable;
74
- $hook->writeResponse(self::defaultHeader, json_encode($hook));
75
- }
76
-
77
- private static function getCancelledItems() {
78
- $sQuery = "SELECT cp_orders.order_nr, cp_orders.marketplace, NOW() as time, cp_orders.status, cp_items.order_item_id, cp_items.marketplace_order_item_id, sales_flat_order_item.qty_canceled
79
- FROM " . self::DB_ORDER_ITEMS . " cp_items
80
- LEFT JOIN " . self::DB_ORDERS . " cp_orders ON cp_orders.order_id = cp_items.order_id
81
- LEFT JOIN sales_flat_order ON sales_flat_order.entity_id = cp_orders.order_id
82
- LEFT JOIN sales_flat_order_item ON sales_flat_order_item.item_id = cp_items.order_item_id
83
- WHERE sales_flat_order_item.qty_canceled > 0 AND sales_flat_order.status != 'canceled' ORDER BY sales_flat_order_item.order_id;";
84
- $dbReadConnection = null;
85
- try {
86
- $dbReadConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
87
- $sResult = $dbReadConnection->fetchAll($sQuery);
88
- $dbReadConnection->closeConnection();
89
- $order = null;
90
- $orderId = null;
91
- $orders = array();
92
- foreach ($sResult AS $result) {
93
- if ($orderId == null || $orderId != $result['order_nr']) {
94
- if ($orderId != null) {
95
- $orders[] = $order;
96
- }
97
- $order = new CPCancellation($result['order_nr'], $result['marketplace'], $result['status'], date("Y-m-d", strtotime($result['time'])) . 'T' . date("H:i:s", strtotime($result['time'])), false);
98
- $orderId = $result['order_nr'];
99
- }
100
- $item = new CPOrderItem();
101
- $item->id = $result['order_item_id'];
102
- $item->idExternal = $result['marketplace_order_item_id'];
103
- $item->quantityCancelled = $result['qty_canceled'];
104
- $order->cancelledItems[] = $item;
105
- }
106
- $orders[] = $order;
107
- return $orders;
108
- } catch (Exception $e) {
109
- if (isset($dbReadConnection)) {
110
- $dbReadConnection->closeConnection();
111
- }
112
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in handle CancellationHook: " . $e->getMessage(), "Exception in handle CancellationHook: '$sQuery'\n" . $e->getMessage());
113
- }
114
- }
115
-
116
- private static function getCancelledOrders() {
117
- $sQuery = "SELECT cp_orders.order_nr, cp_orders.marketplace, NOW() as time, cp_orders.status
118
- FROM " . self::DB_ORDERS . " cp_orders
119
- LEFT JOIN sales_flat_order ON sales_flat_order.entity_id = cp_orders.order_id
120
- WHERE sales_flat_order.status = 'canceled' AND cp_orders.status <> " . CPOrderStatus::ID_CANCELLED . ";";
121
- $dbReadConnection = null;
122
- try {
123
- $dbReadConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
124
- $sResult = $dbReadConnection->fetchAll($sQuery);
125
- $dbReadConnection->closeConnection();
126
- $orders = array();
127
- foreach ($sResult AS $order) {
128
- $cancelled = new CPCancellation($order['order_nr'], $order['marketplace'], $order['status'], date("Y-m-d", strtotime($order['time'])) . 'T' . date("H:i:s", strtotime($order['time'])), true);
129
- $orders[] = $cancelled;
130
- }
131
- return $orders;
132
- } catch (Exception $e) {
133
- if (isset($dbReadConnection)) {
134
- $dbReadConnection->closeConnection();
135
- }
136
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in handle CancellationHook: " . $e->getMessage(), "Exception in handle CancellationHook: '$sQuery'\n" . $e->getMessage());
137
- }
138
- }
139
-
140
- }
141
-
142
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * an cp cancellation handler
5
+ * @author Channel Pilot Solutions GmbH <api@channelpilot.com>
6
+ * @version 1.0
7
+ */
8
+ class CPCancellationHandler extends CPAbstractHandler {
9
+
10
+ /**
11
+ * Handle cancellation hook.
12
+ * @return type
13
+ */
14
+ public function handle() {
15
+ if (isset($_GET['token']) && self::isIpAllowedViaSecurityToken($_GET['token'])) {
16
+ self::checkConfig();
17
+ if (isset($_GET['limit'])) {
18
+ $cancelled = array();
19
+
20
+ $cancelledOrders = self::getCancelledOrders();
21
+ foreach ($cancelledOrders as $orders) {
22
+ if (isset($orders)) {
23
+ $cancelled[] = $orders;
24
+ }
25
+ }
26
+ $cancelledOrderItems = self::getCancelledItems();
27
+
28
+ foreach ($cancelledOrderItems as $orders) {
29
+ if (isset($orders)) {
30
+ $cancelled[] = $orders;
31
+ }
32
+ }
33
+
34
+ if (sizeof($cancelled) == 0) {
35
+ self::hookResult(false);
36
+ }
37
+ $merchantId = self::getMerchantId($_GET['token']);
38
+ $api = new ChannelPilotSellerAPI_v1_0($merchantId, $_GET['token']);
39
+ $result = $api->registerCancellations($cancelled);
40
+ if ($result->header->resultCode == CPResultCodes::SUCCESS) {
41
+ // return $result;
42
+
43
+ $dbWriteConnection = Mage::getSingleton('core/resource')->getConnection('core_write');
44
+ self::changeStatusOrders($result->updateResults, $dbWriteConnection);
45
+ $dbWriteConnection->closeConnection();
46
+ } else {
47
+ // Result from registerDeliveries has no success
48
+ self::logError("request registerDeliveries() resultCode " . $result->header->resultCode);
49
+ $hook = new CPHookResponse();
50
+ $hook->resultCode = CPResultCodes::SUCCESS;
51
+ $hook->resultMessage = "request registerDeliveries() resultCode " . $result->header->resultCode;
52
+ $hook->moreAvailable = false;
53
+ $hook->apiResultCode = $result->header->resultCode;
54
+ $hook->writeResponse(self::defaultHeader, json_encode($hook));
55
+ }
56
+ self::hookResult(true);
57
+ } else {
58
+ CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "not enough parameter for method: " . $_GET['method'], "not enough parameter for method: " . $_GET['method']);
59
+ }
60
+ } else {
61
+ if (empty($_GET['token'])) {
62
+ CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "no token found", "no token found");
63
+ } else {
64
+ CPErrorHandler::handle(CPErrors::RESULT_FAILED, "ip not allowed by token: " . $_GET['token'], "ip not allowed by token: " . $_GET['token']);
65
+ }
66
+ }
67
+ }
68
+
69
+ private function hookResult($moreAvailable) {
70
+ $hook = new CPHookResponse();
71
+ $hook->resultCode = CPResultCodes::SUCCESS;
72
+ $hook->resultMessage = "CANCELLATION HOOK SUCCESS";
73
+ $hook->moreAvailable = $moreAvailable;
74
+ $hook->writeResponse(self::defaultHeader, json_encode($hook));
75
+ }
76
+
77
+ private static function getCancelledItems() {
78
+ $sQuery = "SELECT cp_orders.order_nr, cp_orders.marketplace, NOW() as time, cp_orders.status, cp_items.order_item_id, cp_items.marketplace_order_item_id, sales_flat_order_item.qty_canceled
79
+ FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_ORDER_ITEMS . " cp_items
80
+ LEFT JOIN " . (string)Mage::getConfig()->getTablePrefix().self::DB_ORDERS . " cp_orders ON cp_orders.order_id = cp_items.order_id
81
+ LEFT JOIN sales_flat_order ON sales_flat_order.entity_id = cp_orders.order_id
82
+ LEFT JOIN sales_flat_order_item ON sales_flat_order_item.item_id = cp_items.order_item_id
83
+ WHERE sales_flat_order_item.qty_canceled > 0 AND sales_flat_order.status != 'canceled' ORDER BY sales_flat_order_item.order_id;";
84
+ $dbReadConnection = null;
85
+ try {
86
+ $dbReadConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
87
+ $sResult = $dbReadConnection->fetchAll($sQuery);
88
+ $dbReadConnection->closeConnection();
89
+ $order = null;
90
+ $orderId = null;
91
+ $orders = array();
92
+ foreach ($sResult AS $result) {
93
+ if ($orderId == null || $orderId != $result['order_nr']) {
94
+ if ($orderId != null) {
95
+ $orders[] = $order;
96
+ }
97
+ $order = new CPCancellation($result['order_nr'], $result['marketplace'], $result['status'], date("Y-m-d", strtotime($result['time'])) . 'T' . date("H:i:s", strtotime($result['time'])), false);
98
+ $orderId = $result['order_nr'];
99
+ }
100
+ $item = new CPOrderItem();
101
+ $item->id = $result['order_item_id'];
102
+ $item->idExternal = $result['marketplace_order_item_id'];
103
+ $item->quantityCancelled = $result['qty_canceled'];
104
+ $order->cancelledItems[] = $item;
105
+ }
106
+ $orders[] = $order;
107
+ return $orders;
108
+ } catch (Exception $e) {
109
+ if (isset($dbReadConnection)) {
110
+ $dbReadConnection->closeConnection();
111
+ }
112
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in handle CancellationHook: " . $e->getMessage(), "Exception in handle CancellationHook: '$sQuery'\n" . $e->getMessage());
113
+ }
114
+ }
115
+
116
+ private static function getCancelledOrders() {
117
+ $sQuery = "SELECT cp_orders.order_nr, cp_orders.marketplace, NOW() as time, cp_orders.status
118
+ FROM " . (string)Mage::getConfig()->getTablePrefix().self::DB_ORDERS . " cp_orders
119
+ LEFT JOIN sales_flat_order ON sales_flat_order.entity_id = cp_orders.order_id
120
+ WHERE sales_flat_order.status = 'canceled' AND cp_orders.status <> " . CPOrderStatus::ID_CANCELLED . ";";
121
+ $dbReadConnection = null;
122
+ try {
123
+ $dbReadConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
124
+ $sResult = $dbReadConnection->fetchAll($sQuery);
125
+ $dbReadConnection->closeConnection();
126
+ $orders = array();
127
+ foreach ($sResult AS $order) {
128
+ $cancelled = new CPCancellation($order['order_nr'], $order['marketplace'], $order['status'], date("Y-m-d", strtotime($order['time'])) . 'T' . date("H:i:s", strtotime($order['time'])), true);
129
+ $orders[] = $cancelled;
130
+ }
131
+ return $orders;
132
+ } catch (Exception $e) {
133
+ if (isset($dbReadConnection)) {
134
+ $dbReadConnection->closeConnection();
135
+ }
136
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in handle CancellationHook: " . $e->getMessage(), "Exception in handle CancellationHook: '$sQuery'\n" . $e->getMessage());
137
+ }
138
+ }
139
+
140
+ }
141
+
142
+ ?>
app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPDebugHandler.php CHANGED
@@ -14,7 +14,7 @@ class CPDebugHandler extends CPAbstractHandler {
14
public function handle() {
15
if (isset($_GET['limit'])) {
16
$limit = $_GET['limit'];
17
- $query = "SELECT id, created, content FROM cp_logging
18
ORDER BY id DESC LIMIT $limit";
19
$readConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
20
$logEntries = $readConnection->fetchAll($query);
14
public function handle() {
15
if (isset($_GET['limit'])) {
16
$limit = $_GET['limit'];
17
+ $query = "SELECT id, created, content FROM ".(string)Mage::getConfig()->getTablePrefix()."cp_logging
18
ORDER BY id DESC LIMIT $limit";
19
$readConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
20
$logEntries = $readConnection->fetchAll($query);
app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPDeliveryHandler.php CHANGED
@@ -1,94 +1,94 @@
1
- <?php
2
-
3
- /**
4
- * an cp delivery handler
5
- * @author Channel Pilot Solutions GmbH <api@channelpilot.com>
6
- * @version 1.0
7
- */
8
- class CPDeliveryHandler extends CPAbstractHandler {
9
-
10
- /**
11
- * Handle delivery hook.
12
- * @return type
13
- */
14
- public function handle() {
15
- if (isset($_GET['token']) && self::isIpAllowedViaSecurityToken($_GET['token'])) {
16
- self::checkConfig();
17
- if (isset($_GET['limit'])) {
18
- $dbReadConnection = null;
19
- $dbWriteConnection = null;
20
- $query = "SELECT @CP_ORDERS.order_id, @CP_ORDERS.order_nr, @CP_ORDERS.marketplace, sales_flat_shipment_track.track_number, sales_flat_shipment.created_at, sales_flat_shipment_track.title, sales_flat_order.shipping_method
21
- FROM @CP_ORDERS
22
- LEFT JOIN sales_flat_shipment ON sales_flat_shipment.order_id = @CP_ORDERS.order_id
23
- LEFT JOIN sales_flat_shipment_track ON sales_flat_shipment_track.order_id = @CP_ORDERS.order_id
24
- LEFT JOIN sales_flat_order ON sales_flat_order.entity_id = @CP_ORDERS.order_id
25
- WHERE @CP_ORDERS.status = '" . CPOrderStatus::ID_IMPORTED . "' AND sales_flat_shipment.created_at IS NOT NULL GROUP BY @CP_ORDERS.order_id LIMIT " . intval($_GET['limit']) . ";";
26
- try {
27
- $query = str_replace('@CP_ORDERS', self::DB_ORDERS, $query);
28
- $dbReadConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
29
- $sResult = $dbReadConnection->fetchAll($query);
30
- $dbReadConnection->closeConnection();
31
- $orders = array();
32
- foreach ($sResult AS $order) {
33
- $delivered = new CPDelivery($order['order_nr'], $order['marketplace'], true, $order['track_number'], date("Y-m-d", strtotime($order['created_at'])) . 'T' . date("H:i:s", strtotime($order['created_at'])));
34
- $delivered->carrierName = $order['title'];
35
- $delivered->shipping = new CPShipping();
36
- $delivered->shipping->typeId = $order['shipping_method'];
37
- $delivered->shipping->typeTitle = $order['title'];
38
- $orders[] = $delivered;
39
- }
40
- $deliveries = $orders;
41
- if (sizeof($deliveries) == 0) {
42
- self::hookResult(false);
43
- }
44
- $merchantId = self::getMerchantId($_GET['token']);
45
- $api = new ChannelPilotSellerAPI_v1_0($merchantId, $_GET['token']);
46
- $result = $api->registerDeliveries($deliveries);
47
- if ($result->header->resultCode == CPResultCodes::SUCCESS) {
48
- $dbWriteConnection = Mage::getSingleton('core/resource')->getConnection('core_write');
49
- self::changeStatusOrders($result->updateResults, $dbWriteConnection);
50
- $dbWriteConnection->closeConnection();
51
- } else {
52
- // Result from registerDeliveries has no success
53
- self::logError("request registerDeliveries() resultCode " . $result->header->resultCode);
54
- $hook = new CPHookResponse();
55
- $hook->resultCode = CPResultCodes::SUCCESS;
56
- $hook->resultMessage = "request registerDeliveries() resultCode " . $result->header->resultCode;
57
- $hook->moreAvailable = false;
58
- $hook->apiResultCode = $result->header->resultCode;
59
- $hook->writeResponse(self::defaultHeader, self::_processOutput(json_encode($hook)));
60
- }
61
- self::hookResult(true);
62
- } catch (Exception $e) {
63
- if (isset($dbReadConnection)) {
64
- $dbReadConnection->closeConnection();
65
- }
66
- if (isset($dbWriteConnection)) {
67
- $dbWriteConnection->closeConnection();
68
- }
69
- CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in handle DeliveryHook: " . $e->getMessage(), "Exception in handle DeliveryHook: '$query'\n" . $e->getMessage());
70
- }
71
- } else {
72
- CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "no limit set for method: " . $_GET['method'], "no limit set for method: " . $_GET['method']);
73
- }
74
- } else {
75
- if (empty($_GET['token'])) {
76
- CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "no token found", "no token found");
77
- } else {
78
- CPErrorHandler::handle(CPErrors::RESULT_FAILED, "ip not allowed by token: " . $_GET['token'], "ip not allowed by token: " . $_GET['token']);
79
- }
80
- }
81
- return "Error during handle deliveryHook";
82
- }
83
-
84
- private function hookResult($moreAvailable) {
85
- $hook = new CPHookResponse();
86
- $hook->resultCode = CPResultCodes::SUCCESS;
87
- $hook->resultMessage = "DELIVERY HOOK SUCCESS";
88
- $hook->moreAvailable = $moreAvailable;
89
- $hook->writeResponse(self::defaultHeader, json_encode($hook));
90
- }
91
-
92
- }
93
-
94
- ?>
1
+ <?php
2
+
3
+ /**
4
+ * an cp delivery handler
5
+ * @author Channel Pilot Solutions GmbH <api@channelpilot.com>
6
+ * @version 1.0
7
+ */
8
+ class CPDeliveryHandler extends CPAbstractHandler {
9
+
10
+ /**
11
+ * Handle delivery hook.
12
+ * @return type
13
+ */
14
+ public function handle() {
15
+ if (isset($_GET['token']) && self::isIpAllowedViaSecurityToken($_GET['token'])) {
16
+ self::checkConfig();
17
+ if (isset($_GET['limit'])) {
18
+ $dbReadConnection = null;
19
+ $dbWriteConnection = null;
20
+ $query = "SELECT @CP_ORDERS.order_id, @CP_ORDERS.order_nr, @CP_ORDERS.marketplace, sales_flat_shipment_track.track_number, sales_flat_shipment.created_at, sales_flat_shipment_track.title, sales_flat_order.shipping_method
21
+ FROM @CP_ORDERS
22
+ LEFT JOIN sales_flat_shipment ON sales_flat_shipment.order_id = @CP_ORDERS.order_id
23
+ LEFT JOIN sales_flat_shipment_track ON sales_flat_shipment_track.order_id = @CP_ORDERS.order_id
24
+ LEFT JOIN sales_flat_order ON sales_flat_order.entity_id = @CP_ORDERS.order_id
25
+ WHERE @CP_ORDERS.status = '" . CPOrderStatus::ID_IMPORTED . "' AND sales_flat_shipment.created_at IS NOT NULL GROUP BY @CP_ORDERS.order_id LIMIT " . intval($_GET['limit']) . ";";
26
+ try {
27
+ $query = str_replace('@CP_ORDERS', (string)Mage::getConfig()->getTablePrefix().self::DB_ORDERS, $query);
28
+ $dbReadConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
29
+ $sResult = $dbReadConnection->fetchAll($query);
30
+ $dbReadConnection->closeConnection();
31
+ $orders = array();
32
+ foreach ($sResult AS $order) {
33
+ $delivered = new CPDelivery($order['order_nr'], $order['marketplace'], true, $order['track_number'], date("Y-m-d", strtotime($order['created_at'])) . 'T' . date("H:i:s", strtotime($order['created_at'])));
34
+ $delivered->carrierName = $order['title'];
35
+ $delivered->shipping = new CPShipping();
36
+ $delivered->shipping->typeId = $order['shipping_method'];
37
+ $delivered->shipping->typeTitle = $order['title'];
38
+ $orders[] = $delivered;
39
+ }
40
+ $deliveries = $orders;
41
+ if (sizeof($deliveries) == 0) {
42
+ self::hookResult(false);
43
+ }
44
+ $merchantId = self::getMerchantId($_GET['token']);
45
+ $api = new ChannelPilotSellerAPI_v1_0($merchantId, $_GET['token']);
46
+ $result = $api->registerDeliveries($deliveries);
47
+ if ($result->header->resultCode == CPResultCodes::SUCCESS) {
48
+ $dbWriteConnection = Mage::getSingleton('core/resource')->getConnection('core_write');
49
+ self::changeStatusOrders($result->updateResults, $dbWriteConnection);
50
+ $dbWriteConnection->closeConnection();
51
+ } else {
52
+ // Result from registerDeliveries has no success
53
+ self::logError("request registerDeliveries() resultCode " . $result->header->resultCode);
54
+ $hook = new CPHookResponse();
55
+ $hook->resultCode = CPResultCodes::SUCCESS;
56
+ $hook->resultMessage = "request registerDeliveries() resultCode " . $result->header->resultCode;
57
+ $hook->moreAvailable = false;
58
+ $hook->apiResultCode = $result->header->resultCode;
59
+ $hook->writeResponse(self::defaultHeader, self::_processOutput(json_encode($hook)));
60
+ }
61
+ self::hookResult(true);
62
+ } catch (Exception $e) {
63
+ if (isset($dbReadConnection)) {
64
+ $dbReadConnection->closeConnection();
65
+ }
66
+ if (isset($dbWriteConnection)) {
67
+ $dbWriteConnection->closeConnection();
68
+ }
69
+ CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in handle DeliveryHook: " . $e->getMessage(), "Exception in handle DeliveryHook: '$query'\n" . $e->getMessage());
70
+ }
71
+ } else {
72
+ CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "no limit set for method: " . $_GET['method'], "no limit set for method: " . $_GET['method']);
73
+ }
74
+ } else {
75
+ if (empty($_GET['token'])) {
76
+ CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "no token found", "no token found");
77
+ } else {
78
+ CPErrorHandler::handle(CPErrors::RESULT_FAILED, "ip not allowed by token: " . $_GET['token'], "ip not allowed by token: " . $_GET['token']);
79
+ }
80
+ }
81
+ return "Error during handle deliveryHook";
82
+ }
83
+
84
+ private function hookResult($moreAvailable) {
85
+ $hook = new CPHookResponse();
86
+ $hook->resultCode = CPResultCodes::SUCCESS;
87
+ $hook->resultMessage = "DELIVERY HOOK SUCCESS";
88
+ $hook->moreAvailable = $moreAvailable;
89
+ $hook->writeResponse(self::defaultHeader, json_encode($hook));
90
+ }
91
+
92
+ }
93
+
94
+ ?>
app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPExportHandler.php CHANGED
@@ -24,13 +24,15 @@ class CPExportHandler extends CPAbstractHandler {
24
*
25
*/
26
public function handle() {
27
- if (isset($_GET['limit']) && isset($_GET['shopId'])) {
28
- $this->limit = $_GET['limit'];
29
- $this->last = $_GET['last'];
30
- $this->_storeId = $_GET['shopId'];
31
$this->initExport();
32
$productData = null;
33
- if ($_GET['priceStock'] === "true") {
34
$productData = $this->getStockAndPriceData();
35
} else {
36
$productData = $this->getFullProductData();
@@ -73,45 +75,101 @@ class CPExportHandler extends CPAbstractHandler {
73
}
74
75
private function getStockAndPriceData() {
76
- $selectProductIdsQuery = $this->_applyTablePrefix(
77
- "SELECT p.entity_id, l.parent_id FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity p
78
- LEFT JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_super_link l ON l.product_id = p.entity_id
79
- WHERE p.entity_id NOT IN (SELECT parent_id FROM catalog_product_super_link)"
80
- );
81
- if (isset($this->limit)) {
82
- if (isset($this->last)) {
83
- $selectProductIdsQuery .= " AND p.entity_id > {$this->last} ";
84
- }
85
- $selectProductIdsQuery .= " GROUP BY p.entity_id ORDER BY p.entity_id ASC LIMIT {$this->limit};";
86
- } else {
87
- $selectProductIdsQuery .= " GROUP BY p.entity_id ORDER BY p.entity_id ASC;";
88
}
89
90
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
91
$productEntities = $this->_dbConnection->fetchAll($selectProductIdsQuery);
92
- $productIds = "";
93
foreach ($productEntities as $productId) {
94
- $productIds .= $productId[0] . ",";
95
}
96
- $productIds = rtrim($productIds, ',');
97
-
98
- $query = "
99
- SELECT cpe.entity_id, cpe.sku,
100
- (SELECT count(*) FROM ChannelPilotSolutions_ChannelPilot_catalog_product_super_link WHERE parent_id=cpe.entity_id LIMIT 1) as is_parent,
101
- (SELECT cped.value FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity_decimal AS cped
102
- LEFT JOIN ChannelPilotSolutions_ChannelPilot_eav_attribute as eavAttr ON eavAttr.attribute_id = cped.attribute_id WHERE cped.entity_id=cpe.entity_id AND eavAttr.attribute_code = 'price' LIMIT 1) as price,
103
- (SELECT qty FROM ChannelPilotSolutions_ChannelPilot_cataloginventory_stock_status WHERE product_id=cpe.entity_id AND website_id=" . $this->_siteId . " AND stock_id = 1 LIMIT 1) as qty,
104
- (SELECT stock_status FROM ChannelPilotSolutions_ChannelPilot_cataloginventory_stock_status WHERE product_id=cpe.entity_id AND website_id=" . $this->_siteId . " AND stock_id = 1 LIMIT 1) as stock_status,
105
- (SELECT crpp.rule_price FROM ChannelPilotSolutions_ChannelPilot_catalogrule_product_price AS crpp WHERE crpp.rule_date = CURDATE() AND crpp.product_id =cpe.entity_id AND crpp.customer_group_id = 1 AND crpp.website_id = " . $this->_siteId . ") as cat_price
106
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity AS cpe
107
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_website as cpw
108
- ON cpw.product_id = cpe.entity_id
109
- WHERE cpw.website_id = " . $this->_siteId . "
110
- AND IFNULL(cpe.sku, '') != '' AND cpe.entity_id IN ($productIds)
111
- ORDER BY is_parent DESC, entity_id ASC
112
- ";
113
-
114
- $query = $this->_applyTablePrefix($query);
115
// Set fetch mode to numeric to save memory
116
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
117
$productEntities = $this->_dbConnection->fetchAll($query);
@@ -143,16 +201,19 @@ class CPExportHandler extends CPAbstractHandler {
143
$MEDIA_GALLERY_ATTRIBUTE_ID = 703;
144
145
// Get the entity type for products
146
- $query = "SELECT entity_type_id FROM ChannelPilotSolutions_ChannelPilot_eav_entity_type WHERE entity_type_code = 'catalog_product'";
147
- $query = $this->_applyTablePrefix($query);
148
$PRODUCT_ENTITY_TYPE_ID = $this->_dbConnection->fetchOne($query);
149
150
// Get attribute codes and types
151
- $query = "SELECT attribute_id, attribute_code, backend_type, frontend_input
152
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute
153
- WHERE entity_type_id = $PRODUCT_ENTITY_TYPE_ID
154
- ";
155
- $query = $this->_applyTablePrefix($query);
156
$attributes = $this->_dbConnection->FetchAssoc($query);
157
$attributeCodes = array();
158
$blankProduct = array();
@@ -209,22 +270,29 @@ class CPExportHandler extends CPAbstractHandler {
209
// in a lookup array for performance (avoids several joins/aggregations)
210
if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') {
211
// Get the option_id => value from the attribute options
212
- $query = "
213
- SELECT
214
- CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.option_id) ELSE
215
- MAX(CASE WHEN aov.store_id = " . $this->_storeId . " THEN aov.option_id ELSE NULL END)
216
- END AS 'option_id'
217
- ,CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.value) ELSE
218
- MAX(CASE WHEN aov.store_id = " . $this->_storeId . " THEN aov.value ELSE NULL END)
219
- END AS 'value'
220
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute_option AS ao
221
- INNER JOIN ChannelPilotSolutions_ChannelPilot_eav_attribute_option_value AS aov
222
- ON ao.option_id = aov.option_id
223
- WHERE aov.store_id IN (" . $this->_storeId . ", 0)
224
- AND ao.attribute_id = " . $row['attribute_id'] . "
225
- GROUP BY aov.option_id
226
- ";
227
- $query = $this->_applyTablePrefix($query);
228
$result = $this->_dbConnection->fetchPairs($query);
229
230
// If found, then save the lookup table in the attributeOptions array
@@ -239,42 +307,47 @@ class CPExportHandler extends CPAbstractHandler {
239
}
240
241
$export_data_fields_codes = '';
242
- $export_data_fields_ids = '';
243
foreach (array_keys($blankProduct) as $key) {
244
$export_data_fields_codes = $export_data_fields_codes . "'" . $key . "',";
245
$tmpid = array_search($key, $attributeCodes);
246
if (!empty($tmpid)) {
247
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
248
}
249
}
250
251
$export_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_exportfields'));
252
if (!empty($export_fields)) {
253
foreach ($export_fields as $element) {
254
if (!empty($element['productattribute'])) {
255
$blankProduct[preg_replace('/\W/', '', $element['productattribute'])] = '';
256
$export_data_fields_codes = $export_data_fields_codes . "'" . $element['productattribute'] . "',";
257
- $tmpid = array_search($element['productattribute'], $attributeCodes);
258
- if (!empty($tmpid)) {
259
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
260
- }
261
}
262
}
263
}
264
265
$tmpid = array_search('status', $attributeCodes);
266
if (!empty($tmpid)) {
267
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
268
}
269
$tmpid = array_search('url_path', $attributeCodes);
270
if (!empty($tmpid)) {
271
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
272
}
273
$tmpid = array_search('image', $attributeCodes);
274
if (!empty($tmpid)) {
275
- $export_data_fields_ids = $export_data_fields_ids . "'" . $tmpid . "',";
276
}
277
- $export_data_fields_ids = rtrim($export_data_fields_ids, ',');
278
279
// Build queries for each attribute type
280
$backendTypes = array(
@@ -287,18 +360,25 @@ class CPExportHandler extends CPAbstractHandler {
287
$queries = array();
288
foreach ($backendTypes as $backendType) {
289
// Get store value if there is one, otherwise, global value
290
- $queries[] = "
291
- SELECT CASE WHEN SUM(ev.store_id) = 0 THEN MAX(ev.value) ELSE
292
- MAX(CASE WHEN ev.store_id = " . $this->_storeId . " THEN ev.value ELSE NULL END)
293
- END AS 'value', ev.attribute_id
294
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity
295
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_entity_$backendType AS ev
296
- ON ChannelPilotSolutions_ChannelPilot_catalog_product_entity.entity_id = ev.entity_id
297
- WHERE ev.store_id IN (" . $this->_storeId . ", 0)
298
- AND ev.entity_type_id = $PRODUCT_ENTITY_TYPE_ID
299
- AND ev.entity_id = @ENTITY_ID AND ev.attribute_id IN (" . $export_data_fields_ids . ")
300
- GROUP BY ev.attribute_id, ev.entity_id
301
- ";
302
}
303
$query = implode(" UNION ALL ", $queries);
304
$MasterProductQuery = $query;
@@ -306,47 +386,103 @@ class CPExportHandler extends CPAbstractHandler {
306
$parentProductArray = array();
307
$replace_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_replacefields'));
308
309
- $selectProductIdsQuery = $this->_applyTablePrefix(
310
- "SELECT p.entity_id, l.parent_id FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity p
311
- LEFT JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_super_link l ON l.product_id = p.entity_id
312
- WHERE p.entity_id NOT IN (SELECT parent_id FROM catalog_product_super_link)"
313
- );
314
- if (isset($this->limit)) {
315
- if (isset($this->last)) {
316
- $selectProductIdsQuery .= " AND p.entity_id > {$this->last} ";
317
- }
318
- $selectProductIdsQuery .= " GROUP BY p.entity_id ORDER BY p.entity_id ASC LIMIT {$this->limit};";
319
- } else {
320
- $selectProductIdsQuery .= " GROUP BY p.entity_id ORDER BY p.entity_id ASC;";
321
}
322
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
323
$productEntities = $this->_dbConnection->fetchAll($selectProductIdsQuery);
324
- $productIds = "";
325
foreach ($productEntities as $productId) {
326
- $productIds .= $productId[0] . ",";
327
if (!empty($productId[1])) {
328
- $productIds .= $productId[1] . ",";
329
}
330
}
331
- $productIds = rtrim($productIds, ',');
332
333
// Get all entity_ids for all products in the selected store
334
- $query = "
335
- SELECT cpe.entity_id, cpe.sku,
336
- (SELECT parent_id FROM ChannelPilotSolutions_ChannelPilot_catalog_product_super_link WHERE product_id=cpe.entity_id LIMIT 1) as parent,
337
- (SELECT count(*) FROM ChannelPilotSolutions_ChannelPilot_catalog_product_super_link WHERE parent_id=cpe.entity_id LIMIT 1) as is_parent,
338
- (SELECT qty FROM ChannelPilotSolutions_ChannelPilot_cataloginventory_stock_status WHERE product_id=cpe.entity_id AND website_id=" . $this->_siteId . " AND stock_id = 1 LIMIT 1) as qty,
339
- (SELECT stock_status FROM ChannelPilotSolutions_ChannelPilot_cataloginventory_stock_status WHERE product_id=cpe.entity_id AND website_id=" . $this->_siteId . " AND stock_id = 1 LIMIT 1) as stock_status,
340
- (SELECT crpp.rule_price FROM ChannelPilotSolutions_ChannelPilot_catalogrule_product_price AS crpp WHERE crpp.rule_date = CURDATE() AND crpp.product_id =cpe.entity_id AND crpp.customer_group_id = 1 AND crpp.website_id = " . $this->_siteId . ") as cat_price
341
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity AS cpe
342
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_website as cpw
343
- ON cpw.product_id = cpe.entity_id
344
- WHERE cpw.website_id = " . $this->_siteId . "
345
- AND IFNULL(cpe.sku, '') != '' AND cpe.entity_id IN ($productIds)
346
- ORDER BY is_parent DESC, entity_id ASC
347
- ";
348
-
349
- $query = $this->_applyTablePrefix($query);
350
// Set fetch mode to numeric to save memory
351
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
352
$productEntities = $this->_dbConnection->fetchAll($query);
@@ -358,7 +494,6 @@ class CPExportHandler extends CPAbstractHandler {
358
// $entity[0] = entity_id
359
// $entity[1] = sku
360
$query = str_replace('@ENTITY_ID', $entity[0], $MasterProductQuery);
361
- $query = $this->_applyTablePrefix($query);
362
$result = $this->_dbConnection->query($query);
363
364
// Create a new product record
@@ -368,9 +503,9 @@ class CPExportHandler extends CPAbstractHandler {
368
$product['id'] = $entity[0];
369
$product['sku'] = $entity[1];
370
371
- $product_status;
372
- $product_url;
373
- $product_image;
374
// Loop through each field in the row and get the value
375
while (true) {
376
// Get next column
@@ -430,22 +565,32 @@ class CPExportHandler extends CPAbstractHandler {
430
// Get category information
431
$query = '';
432
if (substr(Mage::getVersion(), 2, 3) >= 6) {
433
- $query = "
434
- SELECT DISTINCT fs.entity_id, fs.path, fs.name
435
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_product_index AS pi
436
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_flat_store_" . $this->_storeId . " AS fs
437
- ON pi.category_id = fs.entity_id
438
- WHERE pi.product_id = " . $entity[0] . " ORDER BY fs.path ASC
439
- ";
440
} else {
441
- $query = "
442
- SELECT pi.category_id, ce.path
443
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_product_index AS pi
444
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_entity AS ce ON pi.category_id = ce.entity_id
445
- WHERE pi.product_id = " . $entity[0] . " AND pi.is_parent = 1 AND pi.store_id = " . $this->_storeId . " ORDER BY ce.path ASC
446
- ";
447
}
448
- $query = $this->_applyTablePrefix($query);
449
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
450
$categoriesTable = $this->_dbConnection->fetchAll($query);
451
$product['categories'] = '';
@@ -496,19 +641,24 @@ class CPExportHandler extends CPAbstractHandler {
496
497
// Get additional image URLs
498
$galleryImagePrefix = $this->_dbConnection->quote($this->_mediaUrl . 'catalog/product');
499
- $query = "
500
- SELECT
501
- GROUP_CONCAT(gallery.value_id SEPARATOR ',') AS value_id
502
- ,GROUP_CONCAT(CONCAT(" . $galleryImagePrefix . ", gallery.value) SEPARATOR ',') AS value
503
- FROM ChannelPilotSolutions_ChannelPilot_catalog_product_entity_media_gallery AS gallery
504
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_product_entity_media_gallery_value AS gallery_value
505
- ON gallery.value_id = gallery_value.value_id
506
- WHERE gallery_value.store_id IN (" . $this->_storeId . ", 0)
507
- AND gallery_value.disabled = 0
508
- AND gallery.entity_id=" . $entity[0] . "
509
- AND gallery.attribute_id = " . $MEDIA_GALLERY_ATTRIBUTE_ID . "
510
- ORDER BY gallery_value.position ASC";
511
- $query = $this->_applyTablePrefix($query);
512
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
513
$galleryValues = $this->_dbConnection->fetchAll($query);
514
if (empty($galleryValues) != true) {
@@ -560,6 +710,11 @@ class CPExportHandler extends CPAbstractHandler {
560
}
561
}
562
}
563
if ($entity[3] < 1) {
564
foreach ($product as $key => $value) {
565
$product[$key] = str_replace('""', '"', $value);
@@ -576,35 +731,39 @@ class CPExportHandler extends CPAbstractHandler {
576
return rtrim($part1, '/') . '/' . ltrim($part2, '/');
577
}
578
579
- private function _applyTablePrefix($query) {
580
- return str_replace('ChannelPilotSolutions_ChannelPilot_', $this->_tablePrefix, $query);
581
- }
582
-
583
private function buildCategoryTree() {
584
// Get category information
585
- $query = '';
586
if (substr(Mage::getVersion(), 2, 3) >= 6) {
587
- $query = "
588
- SELECT DISTINCT fs.entity_id, fs.path, fs.name
589
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_product_index AS pi
590
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_flat_store_" . $this->_storeId . " AS fs
591
- ON pi.category_id = fs.entity_id
592
- ORDER BY fs.path ASC
593
- ";
594
} else {
595
- $query = "
596
- SELECT DISTINCT ev.entity_id, ce.path, ev.value
597
- FROM ChannelPilotSolutions_ChannelPilot_catalog_category_entity_varchar AS ev
598
- INNER JOIN ChannelPilotSolutions_ChannelPilot_catalog_category_entity AS ce ON ev.entity_id = ce.entity_id
599
- WHERE ev.attribute_id = (
600
- SELECT attribute_id
601
- FROM ChannelPilotSolutions_ChannelPilot_eav_attribute as att
602
- WHERE att.entity_type_id = ev.entity_type_id AND att.attribute_code='name'
603
- )
604
- ORDER BY ce.path ASC
605
- ";
606
}
607
- $query = $this->_applyTablePrefix($query);
608
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
609
610
$categoriesTable = $this->_dbConnection->fetchAll($query);
24
*
25
*/
26
public function handle() {
27
+ $limit = Mage::app()->getRequest()->getParam('limit', 0);
28
+ $store = Mage::app()->getRequest()->getParam('store', false);
29
+ if ($limit && $store) {
30
+ $this->limit = $limit;
31
+ $this->last = Mage::app()->getRequest()->getParam('last', null);
32
+ $this->_storeId = $store;
33
$this->initExport();
34
$productData = null;
35
+ if (Mage::app()->getRequest()->getParam('priceStock') === "true") {
36
$productData = $this->getStockAndPriceData();
37
} else {
38
$productData = $this->getFullProductData();
75
}
76
77
private function getStockAndPriceData() {
78
+ $selectProductIdsQuery = new Zend_Db_Select($this->_dbConnection);
79
+ $selectProductIdsQuery->from(array('p' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
80
+ array('p.entity_id', 'l.parent_id')
81
+ );
82
+ $selectProductIdsQuery->joinLeft(array('l' => Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link')),
83
+ 'l.product_id = p.entity_id',
84
+ null
85
+ );
86
+ $selectProductIdsQuery->where('p.entity_id NOT IN (SELECT parent_id FROM '.
87
+ $this->_dbConnection->quoteIdentifier(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link')). ')');
88
+
89
+ if (isset($this->last)) {
90
+ $selectProductIdsQuery->where('p.entity_id > ?', $this->last);
91
}
92
+ $selectProductIdsQuery->group('p.entity_id');
93
+ $selectProductIdsQuery->order('p.entity_id ASC');
94
+ $selectProductIdsQuery->limit($this->limit);
95
96
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
97
$productEntities = $this->_dbConnection->fetchAll($selectProductIdsQuery);
98
+ $productIds = array();
99
foreach ($productEntities as $productId) {
100
+ $productIds[] = $this->_dbConnection->quote($productId[0]);
101
}
102
+ $productIds = implode(',', $productIds);
103
+
104
+ $columns = array('cpe.entity_id', 'cpe.sku');
105
+
106
+ $subquery = new Zend_Db_Select($this->_dbConnection);
107
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'),
108
+ array(new Zend_Db_Expr('COUNT(*)'))
109
+ );
110
+ $subquery->where('parent_id = cpe.entity_id');
111
+ $subquery->limit(1);
112
+
113
+ $columns['is_parent'] = new Zend_Db_Expr('('.$subquery.')');
114
+
115
+ $subquery = New Zend_Db_Select($this->_dbConnection);
116
+ $subquery->from(array('cped' => Mage::getSingleton('core/resource')->getTableName(array('catalog/product', 'decimal'))),
117
+ array('cped.value')
118
+ );
119
+ $subquery->joinLeft(array('eavAttr' => Mage::getSingleton('core/resource')->getTableName('eav/attribute')),
120
+ 'eavAttr.attribute_id = cped.attribute_id',
121
+ null
122
+ );
123
+ $subquery->where('cped.entity_id = cpe.entity_id');
124
+ $subquery->where('eavAttr.attribute_code = ?', 'price');
125
+ $subquery->limit(1);
126
+
127
+ $columns['price'] = new Zend_Db_Expr('('.$subquery.')');
128
+
129
+ $subquery = new Zend_Db_Select($this->_dbConnection);
130
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'),
131
+ array('qty')
132
+ );
133
+ $subquery->where('product_id = cpe.entity_id');
134
+ $subquery->where('website_id = ?', $this->_siteId);
135
+ $subquery->where('stock_id = 1');
136
+ $subquery->limit(1);
137
+
138
+ $columns['qty'] = new Zend_Db_Expr('('.$subquery.')');
139
+
140
+ $subquery = new Zend_Db_Select($this->_dbConnection);
141
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'),
142
+ array('stock_status')
143
+ );
144
+ $subquery->where('product_id = cpe.entity_id');
145
+ $subquery->where('website_id = ?', $this->_siteId);
146
+ $subquery->where('stock_id = 1');
147
+ $subquery->limit(1);
148
+
149
+ $columns['stock_status'] = new Zend_Db_Expr('('.$subquery.')');
150
+
151
+ $subquery = new Zend_Db_Select($this->_dbConnection);
152
+ $subquery->from(array('crpp' => Mage::getSingleton('core/resource')->getTableName('catalogrule/rule_product_price')),
153
+ array('crpp.rule_price')
154
+ );
155
+ $subquery->where('crpp.rule_date = CURDATE()');
156
+ $subquery->where('crpp.product_id = cpe.entity_id');
157
+ $subquery->where('crpp.customer_group_id = 1');
158
+ $subquery->where('crpp.website_id = ?', $this->_siteId);
159
+
160
+ $columns['cat_price'] = new Zend_Db_Expr('('.$subquery.')');
161
+
162
+ $query = new Zend_Db_Select($this->_dbConnection);
163
+ $query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), $columns);
164
+ $query->join(array('cpw' => Mage::getSingleton('core/resource')->getTableName('catalog/product_website')),
165
+ 'cpw.product_id = cpe.entity_id',
166
+ null
167
+ );
168
+ $query->where('cpw.website_id = ?', $this->_siteId);
169
+ $query->where("IFNULL(cpe.sku, '') != ''");
170
+ $query->where('cpe.entity_id IN ('.$productIds.')');
171
+ $query->order(array('is_parent DESC', 'entity_id ASC'));
172
+
173
// Set fetch mode to numeric to save memory
174
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
175
$productEntities = $this->_dbConnection->fetchAll($query);
201
$MEDIA_GALLERY_ATTRIBUTE_ID = 703;
202
203
// Get the entity type for products
204
+ $query = new Zend_Db_Select($this->_dbConnection);
205
+ $query->from(Mage::getSingleton('core/resource')->getTableName('eav/entity_type'), array('entity_type_id'));
206
+ $query->where("entity_type_code = 'catalog_product'");
207
+
208
$PRODUCT_ENTITY_TYPE_ID = $this->_dbConnection->fetchOne($query);
209
210
// Get attribute codes and types
211
+ $query = new Zend_Db_Select($this->_dbConnection);
212
+ $query->from(Mage::getSingleton('core/resource')->getTableName('eav/attribute'),
213
+ array('attribute_id', 'attribute_code', 'backend_type', 'frontend_input')
214
+ );
215
+ $query->where('entity_type_id = ?', $PRODUCT_ENTITY_TYPE_ID);
216
+
217
$attributes = $this->_dbConnection->FetchAssoc($query);
218
$attributeCodes = array();
219
$blankProduct = array();
270
// in a lookup array for performance (avoids several joins/aggregations)
271
if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') {
272
// Get the option_id => value from the attribute options
273
+ $query = new Zend_Db_Select($this->_dbConnection);
274
+ $query->from(array('ao' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_option')),
275
+ array(
276
+ 'option_id' => new Zend_Db_Expr($this->_dbConnection->quoteInto(
277
+ 'CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.option_id) ELSE
278
+ MAX(CASE WHEN aov.store_id = ? THEN aov.option_id ELSE NULL END)
279
+ END', $this->_storeId
280
+ )),
281
+ 'value' => new Zend_Db_Expr($this->_dbConnection->quoteInto(
282
+ 'CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.value) ELSE
283
+ MAX(CASE WHEN aov.store_id = ? THEN aov.value ELSE NULL END)
284
+ END', $this->_storeId
285
+ ))
286
+ )
287
+ );
288
+ $query->join(array('aov' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_option_value')),
289
+ 'ao.option_id = aov.option_id',
290
+ null
291
+ );
292
+ $query->where('aov.store_id IN(0, ?)', $this->_storeId);
293
+ $query->where('ao.attribute_id = ?', $row['attribute_id']);
294
+ $query->group(array('aov.option_id'));
295
+
296
$result = $this->_dbConnection->fetchPairs($query);
297
298
// If found, then save the lookup table in the attributeOptions array
307
}
308
309
$export_data_fields_codes = '';
310
+ $export_data_fields_ids = array();
311
foreach (array_keys($blankProduct) as $key) {
312
$export_data_fields_codes = $export_data_fields_codes . "'" . $key . "',";
313
$tmpid = array_search($key, $attributeCodes);
314
if (!empty($tmpid)) {
315
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
316
}
317
}
318
319
$export_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_exportfields'));
320
+ $useTypeId = false;
321
if (!empty($export_fields)) {
322
foreach ($export_fields as $element) {
323
if (!empty($element['productattribute'])) {
324
$blankProduct[preg_replace('/\W/', '', $element['productattribute'])] = '';
325
$export_data_fields_codes = $export_data_fields_codes . "'" . $element['productattribute'] . "',";
326
+ if($element['productattribute'] == 'type_id') {
327
+ $useTypeId = true;
328
+ } else {
329
+ $tmpid = array_search($element['productattribute'], $attributeCodes);
330
+ if (!empty($tmpid)) {
331
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);
332
+ }
333
+ }
334
}
335
}
336
}
337
338
$tmpid = array_search('status', $attributeCodes);
339
if (!empty($tmpid)) {
340
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);;
341
}
342
$tmpid = array_search('url_path', $attributeCodes);
343
if (!empty($tmpid)) {
344
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);;
345
}
346
$tmpid = array_search('image', $attributeCodes);
347
if (!empty($tmpid)) {
348
+ $export_data_fields_ids[] = $this->_dbConnection->quote($tmpid);;
349
}
350
+ $export_data_fields_ids = implode(',', $export_data_fields_ids);
351
352
// Build queries for each attribute type
353
$backendTypes = array(
360
$queries = array();
361
foreach ($backendTypes as $backendType) {
362
// Get store value if there is one, otherwise, global value
363
+ $query = new Zend_Db_Select($this->_dbConnection);
364
+ $query->from(array('ce' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
365
+ array('value' => new Zend_Db_Expr($this->_dbConnection->quoteInto(
366
+ 'CASE WHEN SUM(ev.store_id) = 0 THEN MAX(ev.value) ELSE
367
+ MAX(CASE WHEN ev.store_id = ? THEN ev.value ELSE NULL END)
368
+ END', $this->_storeId
369
+ )), 'ev.attribute_id')
370
+ );
371
+ $query->join(array('ev' => Mage::getSingleton('core/resource')->getTableName(array('catalog/product', $backendType))),
372
+ 'ce.entity_id = ev.entity_id',
373
+ null
374
+ );
375
+ $query->where('ev.store_id IN(0, ?)', $this->_storeId);
376
+ $query->where('ev.entity_type_id = ?', $PRODUCT_ENTITY_TYPE_ID);
377
+ $query->where('ev.entity_id = @ENTITY_ID');
378
+ $query->where('ev.attribute_id IN('.$export_data_fields_ids.')');
379
+ $query->group(array('ev.attribute_id', 'ev.entity_id'));
380
+
381
+ $queries[] = $query->__toString();
382
}
383
$query = implode(" UNION ALL ", $queries);
384
$MasterProductQuery = $query;
386
$parentProductArray = array();
387
$replace_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_replacefields'));
388
389
+ $subquery = new Zend_Db_Select($this->_dbConnection);
390
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'), array('parent_id'));
391
+
392
+ $selectProductIdsQuery = new Zend_Db_Select($this->_dbConnection);
393
+ $selectProductIdsQuery->from(array('p' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
394
+ array('p.entity_id', 'l.parent_id')
395
+ );
396
+ $selectProductIdsQuery->joinLeft(array('l' => Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link')),
397
+ 'l.product_id = p.entity_id',
398
+ null
399
+ );
400
+ $selectProductIdsQuery->where('p.entity_id NOT IN(?)', $subquery);
401
+
402
+ if (isset($this->last)) {
403
+ $selectProductIdsQuery->where('p.entity_id > ?', $this->last);
404
}
405
+ $selectProductIdsQuery->group('p.entity_id');
406
+ $selectProductIdsQuery->order('p.entity_id ASC');
407
+ $selectProductIdsQuery->limit($this->limit);
408
+
409
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
410
$productEntities = $this->_dbConnection->fetchAll($selectProductIdsQuery);
411
+ $productIds = array();
412
foreach ($productEntities as $productId) {
413
+ $productIds[] = $this->_dbConnection->quote($productId[0]);
414
if (!empty($productId[1])) {
415
+ $productIds[] = $this->_dbConnection->quote($productId[1]);
416
}
417
}
418
+ $productIds = implode(',', $productIds);
419
420
// Get all entity_ids for all products in the selected store
421
+ $columns = array('cpe.entity_id', 'cpe.sku');
422
+
423
+ $subquery = new Zend_Db_Select($this->_dbConnection);
424
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'),
425
+ array('parent_id')
426
+ );
427
+ $subquery->where('product_id = cpe.entity_id');
428
+ $subquery->limit(1);
429
+
430
+ $columns['parent'] = new Zend_Db_Expr('('.$subquery.')');
431
+
432
+ $subquery = new Zend_Db_Select($this->_dbConnection);
433
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'),
434
+ array(new Zend_Db_Expr('COUNT(*)'))
435
+ );
436
+ $subquery->where('parent_id = cpe.entity_id');
437
+ $subquery->limit(1);
438
+
439
+ $columns['is_parent'] = new Zend_Db_Expr('('.$subquery.')');
440
+
441
+ $subquery = new Zend_Db_Select($this->_dbConnection);
442
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'), array('qty'));
443
+ $subquery->where('product_id = cpe.entity_id');
444
+ $subquery->where('website_id = ?', $this->_siteId);
445
+ $subquery->where('stock_id = 1');
446
+ $subquery->limit(1);
447
+
448
+ $columns['qty'] = new Zend_Db_Expr('('.$subquery.')');
449
+
450
+ $subquery = new Zend_Db_Select($this->_dbConnection);
451
+ $subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'),
452
+ array('stock_status')
453
+ );
454
+ $subquery->where('product_id = cpe.entity_id');
455
+ $subquery->where('website_id = ?', $this->_siteId);
456
+ $subquery->where('stock_id = 1');
457
+ $subquery->limit(1);
458
+
459
+ $columns['stock_status'] = new Zend_Db_Expr('('.$subquery.')');
460
+
461
+ $subquery = new Zend_Db_Select($this->_dbConnection);
462
+ $subquery->from(array('crpp' => Mage::getSingleton('core/resource')->getTableName('catalogrule/rule_product_price')),
463
+ array('crpp.rule_price')
464
+ );
465
+ $subquery->where('crpp.rule_date = CURDATE()');
466
+ $subquery->where('crpp.product_id = cpe.entity_id');
467
+ $subquery->where('crpp.customer_group_id = 1');
468
+ $subquery->where('crpp.website_id = ?', $this->_siteId);
469
+
470
+ $columns['cat_price'] = new Zend_Db_Expr('('.$subquery.')');
471
+ $columns[] = 'cpe.type_id';
472
+
473
+ $query = new Zend_Db_Select($this->_dbConnection);
474
+ $query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
475
+ $columns
476
+ );
477
+ $query->join(array('cpw' => Mage::getSingleton('core/resource')->getTableName('catalog/product_website')),
478
+ 'cpw.product_id = cpe.entity_id',
479
+ null
480
+ );
481
+ $query->where('cpw.website_id = ?', $this->_siteId);
482
+ $query->where("IFNULL(cpe.sku, '') != ''");
483
+ $query->where('cpe.entity_id IN ('.$productIds.')');
484
+ $query->order(array('is_parent DESC', 'entity_id ASC'));
485
+
486
// Set fetch mode to numeric to save memory
487
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
488
$productEntities = $this->_dbConnection->fetchAll($query);
494
// $entity[0] = entity_id
495
// $entity[1] = sku
496
$query = str_replace('@ENTITY_ID', $entity[0], $MasterProductQuery);
497
$result = $this->_dbConnection->query($query);
498
499
// Create a new product record
503
$product['id'] = $entity[0];
504
$product['sku'] = $entity[1];
505
506
+ $product_status = null;
507
+ $product_url = null;
508
+ $product_image = null;
509
// Loop through each field in the row and get the value
510
while (true) {
511
// Get next column
565
// Get category information
566
$query = '';
567
if (substr(Mage::getVersion(), 2, 3) >= 6) {
568
+ $query = new Zend_Db_Select($this->_dbConnection);
569
+ $query->distinct();
570
+ $query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
571
+ array('fs.entity_id', 'fs.path', 'fs.name')
572
+ );
573
+ $query->join(array('fs' => Mage::getSingleton('core/resource')
574
+ ->getTableName(array('catalog/category_flat', 'store_'.$this->_storeId))),
575
+ 'pi.category_id = fs.entity_id',
576
+ null
577
+ );
578
+ $query->where('pi.product_id = ?', $entity[0]);
579
+ $query->order('fs.path ASC');
580
} else {
581
+ $query = new Zend_Db_Select($this->_dbConnection);
582
+ $query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
583
+ array('pi.category_id', 'ce.path')
584
+ );
585
+ $query->join(array('ce' => Mage::getSingleton('core/resource')->getTableName('catalog/category')),
586
+ 'pi.category_id = ce.entity_id',
587
+ null
588
+ );
589
+ $query->where('pi.product_id = ?', $entity[0]);
590
+ $query->where('pi.is_parent = 1');
591
+ $query->where('pi.store_id = ?', $this->_storeId);
592
+ $query->order('ce.path ASC');
593
}
594
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
595
$categoriesTable = $this->_dbConnection->fetchAll($query);
596
$product['categories'] = '';
641