Version Notes
- general bugfixes
- tracking method selection added
- sellerAPI payment added
- sellerAPI partial cancellation added
Download this release
Release Info
Developer | Magento Core Team |
Extension | Channelpilotsolutions_Channelpilot |
Version | 2.2.0 |
Comparing to | |
See all releases |
Code changes from version 2.1.6 to 2.2.0
- app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Abstract.php +45 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Exportfields.php +4 -18
- app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Replacefields.php +72 -87
- app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Specialfields.php +54 -55
- app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Trackingkeys.php +66 -67
- app/code/community/Channelpilotsolutions/Channelpilot/Block/Tracking/Tracking.php +140 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/Data.php +22 -29
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/Export.php +296 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/ExportData.php +398 -580
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/api/1_0/ChannelPilotSellerAPI_v1_0.php +29 -16
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/api/1_0/thin/CPPayment.php +37 -10
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPAbstractHandler.php +42 -103
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPCancellationHandler.php +75 -71
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPDebugHandler.php +29 -30
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPDeliveryHandler.php +46 -37
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPExportHandler.php +324 -503
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPNewPriceHandler.php +99 -91
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPNewsHandler.php +44 -39
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPOrderHandler.php +182 -124
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPPaymentHandler.php +85 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPRegisterHandler.php +47 -48
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/CPStatusHandler.php +5 -9
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/handler/todoCPPaymentHandler.php +0 -12
- app/code/community/Channelpilotsolutions/Channelpilot/Helper/responses/CPHookResponse.php +54 -65
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Adminhtml/Source/Trackingmethod.php +34 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Carrier/Cpshipping.php +15 -5
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Logs.php +39 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Order.php +66 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Order/Item.php +53 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Order/Shipment.php +45 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Prices.php +39 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Registration.php +74 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Logs.php +32 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Logs/Collection.php +32 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Order.php +82 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Order/Collection.php +98 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Order/Item.php +60 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Order/Item/Collection.php +98 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Order/Shipment.php +52 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Order/Shipment/Collection.php +32 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Prices.php +33 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Prices/Collection.php +32 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Registration.php +98 -0
- app/code/community/Channelpilotsolutions/Channelpilot/Model/Resource/Registration/Collection.php +32 -0
- app/code/community/Channelpilotsolutions/Channelpilot/controllers/IndexController.php +36 -36
- app/code/community/Channelpilotsolutions/Channelpilot/etc/config.xml +41 -6
- app/code/community/Channelpilotsolutions/Channelpilot/etc/system.xml +12 -3
- app/code/community/Channelpilotsolutions/Channelpilot/sql/channelpilot_setup/mysql4-install-2.0.0.php +206 -206
- app/code/community/Channelpilotsolutions/Channelpilot/sql/channelpilot_setup/mysql4-upgrade-2.1.6-2.2.0.php +58 -0
- app/design/frontend/base/default/layout/Channelpilotsolutions/channelpilot.xml +15 -3
- app/design/frontend/base/default/template/Channelpilotsolutions/channelpilot.phtml +0 -118
- app/design/frontend/base/default/template/Channelpilotsolutions/clicktracking_js.phtml +26 -0
- app/design/frontend/base/default/template/Channelpilotsolutions/salestracking_js.phtml +46 -0
- app/design/frontend/base/default/template/Channelpilotsolutions/tracking_image.phtml +26 -0
- app/locale/de_AT/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/de_CH/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/de_DE/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/en_AU/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/en_CA/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/en_GB/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/en_IE/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/en_NZ/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/en_US/Channelpilotsolutions_Channelpilot.csv +6 -1
- app/locale/es_AR/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_CL/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_CO/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_CR/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_ES/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_MX/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_PA/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_PE/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/es_VE/Channelpilotsolutions_Channelpilot.csv +1 -0
- app/locale/fr_CA/Channelpilotsolutions_Channelpilot.csv +3 -2
- app/locale/fr_FR/Channelpilotsolutions_Channelpilot.csv +3 -2
- package.xml +8 -6
app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Abstract.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 block_adminhtml_field
|
18 |
+
* @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
|
19 |
+
* @author Björn Wehner <info@channelpilot.com>
|
20 |
+
* @license <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
|
21 |
+
* @link http://www.channelpilot.com
|
22 |
+
*/
|
23 |
+
|
24 |
+
abstract class Channelpilotsolutions_Channelpilot_Block_Adminhtml_Field_Abstract extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
|
25 |
+
|
26 |
+
/**
|
27 |
+
* Get all product attribute codes as array. Returned format:
|
28 |
+
* [0] => Array
|
29 |
+
* (
|
30 |
+
* [attribute_code] => code
|
31 |
+
* )
|
32 |
+
* @param array $excludeAttributeCodes Attribute codes used for a NOT IN filter
|
33 |
+
* @return array
|
34 |
+
*/
|
35 |
+
protected function _getProductAttributeCodes(array $excludeAttributeCodes = array()) {
|
36 |
+
$query = new Zend_Db_Select(Mage::getSingleton('core/resource')->getConnection('core_read'));
|
37 |
+
$query->from(Mage::getSingleton('core/resource')->getTableName('eav_entity_type'), array('entity_type_id'))
|
38 |
+
->where('entity_type_code = ?', 'catalog_product');
|
39 |
+
return Mage::getResourceModel('eav/entity_attribute_collection')
|
40 |
+
->addFieldToSelect('attribute_code')
|
41 |
+
->addFieldToFilter('entity_type_id', array('eq' => new Zend_Db_Expr('('.$query.')')))
|
42 |
+
->addFieldToFilter('attribute_code', array('nin' => $excludeAttributeCodes))
|
43 |
+
->getData();
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Exportfields.php
CHANGED
@@ -21,9 +21,7 @@
|
|
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
|
25 |
-
|
26 |
-
private $_standardattributes;
|
27 |
|
28 |
public function __construct() {
|
29 |
$this->addColumn('productattribute', array(
|
@@ -37,35 +35,23 @@ class Channelpilotsolutions_Channelpilot_Block_Adminhtml_Field_Exportfields exte
|
|
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 |
-
|
56 |
-
|
57 |
-
|
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>';
|
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 Channelpilotsolutions_Channelpilot_Block_Adminhtml_Field_Abstract {
|
|
|
|
|
25 |
|
26 |
public function __construct() {
|
27 |
$this->addColumn('productattribute', array(
|
35 |
}
|
36 |
|
37 |
protected function _renderCellTemplate($columnName) {
|
|
|
38 |
if (empty($this->_columns[$columnName])) {
|
39 |
throw new Exception('Wrong column name specified.');
|
40 |
}
|
|
|
41 |
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
|
42 |
|
43 |
if ($columnName == 'productattribute') {
|
44 |
$rendered = '<select name="' . $inputName . '">';
|
45 |
|
|
|
|
|
|
|
|
|
46 |
// Get attribute codes and types
|
47 |
+
$attributes = $this->_getProductAttributeCodes(array(
|
48 |
+
'sku','price','name','description','manufacturer','color','weight', 'parent_id'
|
49 |
+
));
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
$attributes[]['attribute_code'] = 'qty';
|
52 |
$attributes[]['attribute_code'] = 'stock_status';
|
53 |
$attributes[]['attribute_code'] = 'cp_color_attribute_id';
|
54 |
$attributes[]['attribute_code'] = 'type_id';
|
|
|
55 |
asort($attributes);
|
56 |
foreach ($attributes as $attribute) {
|
57 |
$rendered .= '<option value="' . $attribute['attribute_code'] . '">' . $attribute['attribute_code'] . '</option>';
|
app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Replacefields.php
CHANGED
@@ -1,88 +1,73 @@
|
|
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_Replacefields extends
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
$
|
51 |
-
$
|
52 |
-
$
|
53 |
-
|
54 |
-
|
55 |
-
$
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
$
|
65 |
-
$
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
$attributes[]['attribute_code'] = 'cp_additional_image_2';
|
74 |
-
$attributes[]['attribute_code'] = 'cp_additional_image_3';
|
75 |
-
asort($attributes);
|
76 |
-
foreach ($attributes as $attribute) {
|
77 |
-
$rendered .= '<option value="' . $attribute['attribute_code'] . '">' . $attribute['attribute_code'] . '</option>';
|
78 |
-
}
|
79 |
-
$rendered .= '</select>';
|
80 |
-
return $rendered;
|
81 |
-
}
|
82 |
-
|
83 |
-
return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"/>';
|
84 |
-
}
|
85 |
-
|
86 |
-
}
|
87 |
-
|
88 |
?>
|
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_Replacefields extends Channelpilotsolutions_Channelpilot_Block_Adminhtml_Field_Abstract {
|
25 |
+
|
26 |
+
public function __construct() {
|
27 |
+
$this->addColumn('productattribute', array(
|
28 |
+
'label' => Mage::helper('adminhtml')->__('Data field'),
|
29 |
+
'size' => 30
|
30 |
+
));
|
31 |
+
$this->_addAfter = false;
|
32 |
+
|
33 |
+
parent::__construct();
|
34 |
+
$this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
|
35 |
+
}
|
36 |
+
|
37 |
+
protected function _renderCellTemplate($columnName) {
|
38 |
+
if (empty($this->_columns[$columnName])) {
|
39 |
+
throw new Exception('Wrong column name specified.');
|
40 |
+
}
|
41 |
+
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
|
42 |
+
|
43 |
+
if ($columnName == 'productattribute') {
|
44 |
+
$rendered = '<select name="' . $inputName . '">';
|
45 |
+
$attributes = $this->_getProductAttributeCodes(array(
|
46 |
+
'sku','price','name','description','manufacturer','color','weight'
|
47 |
+
));
|
48 |
+
|
49 |
+
$attributes[]['attribute_code'] = 'qty';
|
50 |
+
$attributes[]['attribute_code'] = 'stock_status';
|
51 |
+
$attributes[]['attribute_code'] = 'cp_color_attribute_id';
|
52 |
+
$attributes[]['attribute_code'] = 'parent_id';
|
53 |
+
|
54 |
+
$attributes[]['attribute_code'] = 'categories';
|
55 |
+
$attributes[]['attribute_code'] = 'cp_image_url';
|
56 |
+
$attributes[]['attribute_code'] = 'cp_product_url';
|
57 |
+
$attributes[]['attribute_code'] = 'cp_additional_image_1';
|
58 |
+
$attributes[]['attribute_code'] = 'cp_additional_image_2';
|
59 |
+
$attributes[]['attribute_code'] = 'cp_additional_image_3';
|
60 |
+
asort($attributes);
|
61 |
+
foreach ($attributes as $attribute) {
|
62 |
+
$rendered .= '<option value="' . $attribute['attribute_code'] . '">' . $attribute['attribute_code'] . '</option>';
|
63 |
+
}
|
64 |
+
$rendered .= '</select>';
|
65 |
+
return $rendered;
|
66 |
+
}
|
67 |
+
|
68 |
+
return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"/>';
|
69 |
+
}
|
70 |
+
|
71 |
+
}
|
72 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
?>
|
app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Specialfields.php
CHANGED
@@ -1,56 +1,55 @@
|
|
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_Specialfields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
|
25 |
-
|
26 |
-
protected $magentoAttributes;
|
27 |
-
|
28 |
-
public function __construct() {
|
29 |
-
$this->addColumn('name', array(
|
30 |
-
'label' => Mage::helper('adminhtml')->__('Data field name'),
|
31 |
-
'size' => 30
|
32 |
-
));
|
33 |
-
$this->addColumn('value', array(
|
34 |
-
'label' => Mage::helper('adminhtml')->__('Data field value'),
|
35 |
-
'size' => 30
|
36 |
-
));
|
37 |
-
$this->_addAfter = false;
|
38 |
-
|
39 |
-
parent::__construct();
|
40 |
-
$this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
|
41 |
-
}
|
42 |
-
|
43 |
-
protected function _renderCellTemplate($columnName) {
|
44 |
-
if (empty($this->_columns[$columnName])) {
|
45 |
-
throw new Exception('Wrong column name specified.');
|
46 |
-
}
|
47 |
-
$
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
?>
|
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_Specialfields extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
|
25 |
+
|
26 |
+
protected $magentoAttributes;
|
27 |
+
|
28 |
+
public function __construct() {
|
29 |
+
$this->addColumn('name', array(
|
30 |
+
'label' => Mage::helper('adminhtml')->__('Data field name'),
|
31 |
+
'size' => 30
|
32 |
+
));
|
33 |
+
$this->addColumn('value', array(
|
34 |
+
'label' => Mage::helper('adminhtml')->__('Data field value'),
|
35 |
+
'size' => 30
|
36 |
+
));
|
37 |
+
$this->_addAfter = false;
|
38 |
+
|
39 |
+
parent::__construct();
|
40 |
+
$this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
|
41 |
+
}
|
42 |
+
|
43 |
+
protected function _renderCellTemplate($columnName) {
|
44 |
+
if (empty($this->_columns[$columnName])) {
|
45 |
+
throw new Exception('Wrong column name specified.');
|
46 |
+
}
|
47 |
+
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
|
48 |
+
|
49 |
+
|
50 |
+
return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"/>';
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
54 |
+
|
|
|
55 |
?>
|
app/code/community/Channelpilotsolutions/Channelpilot/Block/Adminhtml/Field/Trackingkeys.php
CHANGED
@@ -1,68 +1,67 @@
|
|
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_Trackingkeys extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
|
25 |
-
|
26 |
-
protected $magentoAttributes;
|
27 |
-
|
28 |
-
public function __construct() {
|
29 |
-
$this->addColumn('shop', array(
|
30 |
-
'label' => Mage::helper('adminhtml')->__('Shop'),
|
31 |
-
'size' => 15
|
32 |
-
));
|
33 |
-
$this->addColumn('trackingkey', array(
|
34 |
-
'label' => Mage::helper('adminhtml')->__('TrackingKey'),
|
35 |
-
'size' => 28
|
36 |
-
));
|
37 |
-
$this->_addAfter = false;
|
38 |
-
|
39 |
-
parent::__construct();
|
40 |
-
$this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
|
41 |
-
}
|
42 |
-
|
43 |
-
protected function _renderCellTemplate($columnName) {
|
44 |
-
if (empty($this->_columns[$columnName])) {
|
45 |
-
throw new Exception('Wrong column name specified.');
|
46 |
-
}
|
47 |
-
$
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
$rendered
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
?>
|
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_Trackingkeys extends Mage_Adminhtml_Block_System_Config_Form_Field_Array_Abstract {
|
25 |
+
|
26 |
+
protected $magentoAttributes;
|
27 |
+
|
28 |
+
public function __construct() {
|
29 |
+
$this->addColumn('shop', array(
|
30 |
+
'label' => Mage::helper('adminhtml')->__('Shop'),
|
31 |
+
'size' => 15
|
32 |
+
));
|
33 |
+
$this->addColumn('trackingkey', array(
|
34 |
+
'label' => Mage::helper('adminhtml')->__('TrackingKey'),
|
35 |
+
'size' => 28
|
36 |
+
));
|
37 |
+
$this->_addAfter = false;
|
38 |
+
|
39 |
+
parent::__construct();
|
40 |
+
$this->setTemplate('channelpilotsolutions/array_dropdown.phtml');
|
41 |
+
}
|
42 |
+
|
43 |
+
protected function _renderCellTemplate($columnName) {
|
44 |
+
if (empty($this->_columns[$columnName])) {
|
45 |
+
throw new Exception('Wrong column name specified.');
|
46 |
+
}
|
47 |
+
$inputName = $this->getElement()->getName() . '[#{_id}][' . $columnName . ']';
|
48 |
+
|
49 |
+
if ($columnName == 'shop') {
|
50 |
+
$rendered = '<select name="' . $inputName . '">';
|
51 |
+
$storeCollection = Mage::getSingleton('core/store')->getCollection()
|
52 |
+
->addFieldToFilter('code', array('neq' => Mage_Core_Model_Store::ADMIN_CODE))
|
53 |
+
->setOrder('website_id', 'ASC');
|
54 |
+
|
55 |
+
foreach ($storeCollection as $store) {
|
56 |
+
$rendered .= '<option value="' . $store->getId() . '">' . $store->getName() . '</option>';
|
57 |
+
}
|
58 |
+
|
59 |
+
$rendered .= '</select>';
|
60 |
+
return $rendered;
|
61 |
+
}
|
62 |
+
return '<input type="text" name="' . $inputName . '" value="#{' . $columnName . '}"/>';
|
63 |
+
}
|
64 |
+
|
65 |
+
}
|
66 |
+
|
|
|
67 |
?>
|
app/code/community/Channelpilotsolutions/Channelpilot/Block/Tracking/Tracking.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
|
19 |
+
* @author Bj�rn Wehner <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_Block_Tracking_Tracking extends Mage_Core_Block_Template
|
24 |
+
{
|
25 |
+
const IMAGE_URL_CLICK = 'https://click.cptrack.de/verify';
|
26 |
+
const IMAGE_URL_SALE = 'https://sale.cptrack.de/';
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Flag to wether use the click or sales tracking.
|
30 |
+
* @var bool
|
31 |
+
*/
|
32 |
+
protected $_isSale;
|
33 |
+
|
34 |
+
public function __construct() {
|
35 |
+
$this->_isSale = false;
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Check if tracking is enabled.
|
40 |
+
* @return bool
|
41 |
+
*/
|
42 |
+
public function isEnabled() {
|
43 |
+
return Mage::getStoreConfigFlag('channelpilot_tracking/channelpilot_tracking/channelpilot_useTracking');
|
44 |
+
}
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Check if the current tracking mode is set to "Image".
|
48 |
+
* @return bool
|
49 |
+
*/
|
50 |
+
public function isTrackingModeImage() {
|
51 |
+
return Mage::getStoreConfig('channelpilot_tracking/channelpilot_tracking/method') == Channelpilotsolutions_Channelpilot_Model_Adminhtml_Source_Trackingmethod::TRACKING_METHOD_IMAGE;
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Get the tracking key for the current shop.
|
56 |
+
* @return mixed
|
57 |
+
*/
|
58 |
+
public function getTrackingKey() {
|
59 |
+
$storeId = Mage::app()->getStore()->getId();
|
60 |
+
$trackingKeys = unserialize(Mage::getStoreConfig('channelpilot_tracking/channelpilot_tracking/channelpilot_trackingkeys'));
|
61 |
+
foreach ($trackingKeys as $element) {
|
62 |
+
if ($element['shop'] == $storeId) {
|
63 |
+
return $element['trackingkey'];
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Get the order with the last increment id from the checkout session.
|
70 |
+
* Returns false if the order could not be loaded.
|
71 |
+
* @return Mage_Sales_Model_Order | bool
|
72 |
+
*/
|
73 |
+
public function getOrder() {
|
74 |
+
$lastIncrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
|
75 |
+
$order = Mage::getModel('sales/order')->loadByIncrementId($lastIncrementId);
|
76 |
+
if($order && $order->getId()) {
|
77 |
+
return $order;
|
78 |
+
}
|
79 |
+
|
80 |
+
Mage::log('Could not load order with increment id '.$lastIncrementId.' for sales tracking.');
|
81 |
+
return false;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Get the identifier field for the product (entity_id oder sku).
|
86 |
+
* @return string
|
87 |
+
*/
|
88 |
+
public function getProductIdField() {
|
89 |
+
return Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_articlenumber');
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Get the tracking cookie mode.
|
94 |
+
* @return string
|
95 |
+
*/
|
96 |
+
public function getCookieMode() {
|
97 |
+
return Mage::getStoreConfig('channelpilot_tracking/channelpilot_tracking/channelpilot_cookiemode');
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* Get the url for the tracking image.
|
102 |
+
* @return string
|
103 |
+
*/
|
104 |
+
public function getImageUrl() {
|
105 |
+
if($this->_isSale) {
|
106 |
+
$order = $this->getOrder();
|
107 |
+
if($order) {
|
108 |
+
$url = self::IMAGE_URL_SALE
|
109 |
+
. '?trackingKey='.urlencode($this->getTrackingKey())
|
110 |
+
. '&cookie='.urlencode($this->getCookieMode())
|
111 |
+
. '&orderId='.urlencode($order->getId())
|
112 |
+
. '&orderTotal='.urlencode($order->getGrandTotal() - $order->getTaxAmount());
|
113 |
+
|
114 |
+
$productIdField = $this->getProductIdField();
|
115 |
+
$i = 1;
|
116 |
+
foreach($order->getItemsCollection(array(), true) as $item) {
|
117 |
+
$url .= '&id'.$i.'='.urlencode($item->getData($productIdField))
|
118 |
+
. '&price'.$i.'='.urlencode($item->getPrice())
|
119 |
+
. '&amount'.$i.'='.urlencode($item->getQtyOrdered());
|
120 |
+
$i++;
|
121 |
+
}
|
122 |
+
|
123 |
+
return $url;
|
124 |
+
}
|
125 |
+
return '';
|
126 |
+
}
|
127 |
+
return self::IMAGE_URL_CLICK;
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Set the isSale flag. If the param is set to anything that can be interpreted as
|
132 |
+
* true, the class variable _isSale is set to true.
|
133 |
+
* @param bool|false $isSale
|
134 |
+
*/
|
135 |
+
public function setIsSale($isSale = false) {
|
136 |
+
if($isSale) {
|
137 |
+
$this->_isSale = true;
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
app/code/community/Channelpilotsolutions/Channelpilot/Helper/Data.php
CHANGED
@@ -35,6 +35,7 @@ require_once 'handler/CPDeliveryHandler.php';
|
|
35 |
require_once 'handler/CPCancellationHandler.php';
|
36 |
require_once 'handler/CPNewsHandler.php';
|
37 |
require_once 'handler/CPDebugHandler.php';
|
|
|
38 |
|
39 |
// RESPONSES
|
40 |
require_once 'responses/CPHookResponse.php';
|
@@ -60,6 +61,7 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
|
|
60 |
const GET_NEWS = "news";
|
61 |
const GET_NEWPRICES = "prices";
|
62 |
const GET_DEBUG = "debug";
|
|
|
63 |
|
64 |
public function __construct($root = 'root') {
|
65 |
|
@@ -68,7 +70,8 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
|
|
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 |
-
|
|
|
72 |
header('Content-Type: text/xml; charset=utf-8');
|
73 |
include 'ExportData.php';
|
74 |
$exporter = new ExportData();
|
@@ -109,8 +112,8 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
|
|
109 |
$exportActive = true;
|
110 |
}
|
111 |
|
112 |
-
|
113 |
-
switch ($
|
114 |
// Send method
|
115 |
case self::GET_STATUS:
|
116 |
$this->checkActivation(array($marketplaceActive, $pricecontrolActive), 'marketplace OR pricecontrol');
|
@@ -177,11 +180,18 @@ 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:
|
184 |
-
$hook = "not supported method: " . $
|
185 |
break;
|
186 |
}
|
187 |
header("Content-Type: application/json;");
|
@@ -190,11 +200,14 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
|
|
190 |
}
|
191 |
|
192 |
private function checkSignature() {
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
195 |
return true;
|
196 |
}
|
197 |
-
CPErrorHandler::handle(CPErrors::RESULT_SIGNATURE_MISMATCH, "Signature changed", "Signature changed \n" . $
|
198 |
} else {
|
199 |
CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "Missing params for signature check", "Missing params for signature check");
|
200 |
}
|
@@ -211,30 +224,10 @@ class Channelpilotsolutions_Channelpilot_Helper_Data extends Mage_Core_Helper_Ab
|
|
211 |
|
212 |
private function checkIp() {
|
213 |
if (Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp')) {
|
214 |
-
|
215 |
-
$allIps[] = CPAbstractHandler::ChannelPilot_IP;
|
216 |
-
$sQuery = "SELECT ips_authorized FROM " . CPAbstractHandler::DB_REGISTRATION;
|
217 |
-
$dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
218 |
-
try {
|
219 |
-
$sResult = $dbConnection->fetchAll($sQuery);
|
220 |
-
foreach ($sResult as $resultType) {
|
221 |
-
$ips = explode(";", $resultType['ips_authorized']);
|
222 |
-
foreach ($ips as $ip) {
|
223 |
-
$allIps[] = $ip;
|
224 |
-
}
|
225 |
-
}
|
226 |
-
} catch (Exception $e) {
|
227 |
-
$dbConnection->closeConnection();
|
228 |
-
CPErrorHandler::handle(CPResultCodes::SYSTEM_ERROR, "Exception in getAllowedIpsViaSecurityToken(): " . $e->getMessage(), "Exception in getAllowedIpsViaSecurityToken(): '$sQuery'\n" . $e->getMessage());
|
229 |
-
}
|
230 |
-
|
231 |
-
if (!in_array($_SERVER['REMOTE_ADDR'], $allIps)) {
|
232 |
-
return false;
|
233 |
-
}
|
234 |
}
|
235 |
return true;
|
236 |
}
|
237 |
-
|
238 |
}
|
239 |
|
240 |
?>
|
35 |
require_once 'handler/CPCancellationHandler.php';
|
36 |
require_once 'handler/CPNewsHandler.php';
|
37 |
require_once 'handler/CPDebugHandler.php';
|
38 |
+
require_once 'handler/CPPaymentHandler.php';
|
39 |
|
40 |
// RESPONSES
|
41 |
require_once 'responses/CPHookResponse.php';
|
61 |
const GET_NEWS = "news";
|
62 |
const GET_NEWPRICES = "prices";
|
63 |
const GET_DEBUG = "debug";
|
64 |
+
const GET_PAYMENTS = "payments";
|
65 |
|
66 |
public function __construct($root = 'root') {
|
67 |
|
70 |
public function createXml() {
|
71 |
if (Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_useExport')) {
|
72 |
$password = Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_password');
|
73 |
+
$paramPassword = Mage::app()->getRequest()->getParam('password', false);
|
74 |
+
if ($password == '' || ($paramPassword AND $paramPassword == $password)) {
|
75 |
header('Content-Type: text/xml; charset=utf-8');
|
76 |
include 'ExportData.php';
|
77 |
$exporter = new ExportData();
|
112 |
$exportActive = true;
|
113 |
}
|
114 |
|
115 |
+
$method = Mage::app()->getRequest()->getParam('method', '');
|
116 |
+
switch ($method) {
|
117 |
// Send method
|
118 |
case self::GET_STATUS:
|
119 |
$this->checkActivation(array($marketplaceActive, $pricecontrolActive), 'marketplace OR pricecontrol');
|
180 |
case self::GET_DEBUG:
|
181 |
$this->checkSignature();
|
182 |
$handler = new CPDebugHandler();
|
183 |
+
$hook = $handler->handle();
|
184 |
break;
|
185 |
|
186 |
+
case self::GET_PAYMENTS:
|
187 |
+
$this->checkSignature();
|
188 |
+
$this->checkActivation(array($marketplaceActive), 'marketplace');
|
189 |
+
$handler = new CPPaymentHandler();
|
190 |
+
$handler->handle();
|
191 |
+
break;
|
192 |
+
|
193 |
default:
|
194 |
+
$hook = "not supported method: " . $method;
|
195 |
break;
|
196 |
}
|
197 |
header("Content-Type: application/json;");
|
200 |
}
|
201 |
|
202 |
private function checkSignature() {
|
203 |
+
$php = Mage::app()->getRequest()->getParam('php', false);
|
204 |
+
$shop = Mage::app()->getRequest()->getParam('shop', false);
|
205 |
+
$plugin = Mage::app()->getRequest()->getParam('plugin', false);
|
206 |
+
IF ($php && $shop && $plugin) {
|
207 |
+
if ($php == phpversion() && $shop == CPHookResponse::getSignatureShop() && $plugin == CPHookResponse::getModuleVersion()) {
|
208 |
return true;
|
209 |
}
|
210 |
+
CPErrorHandler::handle(CPErrors::RESULT_SIGNATURE_MISMATCH, "Signature changed", "Signature changed \n" . $php . " -> " . phpversion() . "\n" . $shop . " -> " . CPHookResponse::getSignatureShop() . "\n" . $plugin . " -> " . CPHookResponse::getModuleVersion());
|
211 |
} else {
|
212 |
CPErrorHandler::handle(CPErrors::RESULT_MISSING_PARAMS, "Missing params for signature check", "Missing params for signature check");
|
213 |
}
|
224 |
|
225 |
private function checkIp() {
|
226 |
if (Mage::getStoreConfig('channelpilot_general/channelpilot_general/channelpilot_checkIp')) {
|
227 |
+
return Mage::getModel('channelpilot/registration')->isIpAuthorized($_SERVER['REMOTE_ADDR']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
}
|
229 |
return true;
|
230 |
}
|
|
|
231 |
}
|
232 |
|
233 |
?>
|
app/code/community/Channelpilotsolutions/Channelpilot/Helper/Export.php
ADDED
@@ -0,0 +1,296 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
* @copyright Copyright (c) 2012 <info@channelpilot.com> - www.channelpilot.com
|
19 |
+
* @author Bj�rn Wehner <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_Helper_Export extends Mage_Core_Helper_Abstract
|
24 |
+
{
|
25 |
+
protected $_productEntityTypeId = null;
|
26 |
+
protected $_masterProductQuery = null;
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Get the entity_type_id for catalog_product.
|
30 |
+
* @return mixed
|
31 |
+
*/
|
32 |
+
public function getEntityTypeIdForProduct() {
|
33 |
+
if($this->_productEntityTypeId === null) {
|
34 |
+
// Get the entity type for products
|
35 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
36 |
+
$query = new Zend_Db_Select($connection);
|
37 |
+
$query->from(Mage::getSingleton('core/resource')->getTableName('eav/entity_type'), array('entity_type_id'));
|
38 |
+
$query->where("entity_type_code = 'catalog_product'");
|
39 |
+
|
40 |
+
$this->_productEntityTypeId = $connection->fetchOne($query);
|
41 |
+
}
|
42 |
+
return $this->_productEntityTypeId;
|
43 |
+
}
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Get all product attributes.
|
47 |
+
* @return mixed
|
48 |
+
*/
|
49 |
+
public function getProductAttributes() {
|
50 |
+
// Get attribute codes and types
|
51 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
52 |
+
$query = new Zend_Db_Select($connection);
|
53 |
+
$query->from(Mage::getSingleton('core/resource')->getTableName('eav/attribute'),
|
54 |
+
array('attribute_id', 'attribute_code', 'backend_type', 'frontend_input')
|
55 |
+
);
|
56 |
+
$query->where('entity_type_id = ?', $this->getEntityTypeIdForProduct());
|
57 |
+
|
58 |
+
return $connection->FetchAssoc($query);
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Get the attribute options for an attribute_id.
|
63 |
+
*
|
64 |
+
* @param int $attributeId
|
65 |
+
* @return array
|
66 |
+
*/
|
67 |
+
public function getAttributeOptions($attributeId, $storeId) {
|
68 |
+
// Get the option_id => value from the attribute options
|
69 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
70 |
+
$query = new Zend_Db_Select($connection);
|
71 |
+
$query->from(array('ao' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_option')),
|
72 |
+
array(
|
73 |
+
'option_id' => new Zend_Db_Expr($connection->quoteInto(
|
74 |
+
'CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.option_id) ELSE
|
75 |
+
MAX(CASE WHEN aov.store_id = ? THEN aov.option_id ELSE NULL END)
|
76 |
+
END', $storeId
|
77 |
+
)),
|
78 |
+
'value' => new Zend_Db_Expr($connection->quoteInto(
|
79 |
+
'CASE WHEN SUM(aov.store_id) = 0 THEN MAX(aov.value) ELSE
|
80 |
+
MAX(CASE WHEN aov.store_id = ? THEN aov.value ELSE NULL END)
|
81 |
+
END', $storeId
|
82 |
+
))
|
83 |
+
)
|
84 |
+
);
|
85 |
+
$query->join(array('aov' => Mage::getSingleton('core/resource')->getTableName('eav/attribute_option_value')),
|
86 |
+
'ao.option_id = aov.option_id',
|
87 |
+
null
|
88 |
+
);
|
89 |
+
$query->where('aov.store_id IN(0, ?)', $storeId);
|
90 |
+
$query->where('ao.attribute_id = ?', $attributeId);
|
91 |
+
$query->group(array('aov.option_id'));
|
92 |
+
|
93 |
+
return $connection->fetchPairs($query);
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Get the additional image urls for an entity_id.
|
98 |
+
* @param int $entityId
|
99 |
+
* @return array
|
100 |
+
*/
|
101 |
+
public function getAdditionalImageUrl($entityId, $storeId, $mediaGalleryAttributeId, $baseImageAttributeId) {
|
102 |
+
$store = Mage::app()->getStore($storeId);
|
103 |
+
$mediaUrl = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
|
104 |
+
|
105 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
106 |
+
$galleryImagePrefix = $connection->quote($mediaUrl . 'catalog/product');
|
107 |
+
|
108 |
+
$subquery = new Zend_Db_Select($connection);
|
109 |
+
$subquery->from(Mage::getSingleton('core/resource')->getTableName(array('catalog/product', 'varchar')),
|
110 |
+
array('value')
|
111 |
+
);
|
112 |
+
$subquery->where('entity_id = ?', $entityId);
|
113 |
+
$subquery->where('attribute_id = ?', $baseImageAttributeId);
|
114 |
+
|
115 |
+
|
116 |
+
$query = new Zend_Db_Select($connection);
|
117 |
+
$query->from(array('gallery' => Mage::getSingleton('core/resource')->getTableName('catalog/product_attribute_media_gallery')),
|
118 |
+
array(
|
119 |
+
'value_id' => new Zend_Db_Expr("GROUP_CONCAT(gallery.value_id SEPARATOR ',')"),
|
120 |
+
'value' => new Zend_Db_Expr("GROUP_CONCAT(CONCAT(" . $galleryImagePrefix . ", gallery.value) SEPARATOR ',')")
|
121 |
+
)
|
122 |
+
);
|
123 |
+
$query->join(array('gallery_value' => Mage::getSingleton('core/resource')->getTableName('catalog/product_attribute_media_gallery_value')),
|
124 |
+
'gallery.value_id = gallery_value.value_id',
|
125 |
+
null
|
126 |
+
);
|
127 |
+
$query->where('gallery_value.store_id IN(0, ?)', $storeId);
|
128 |
+
$query->where('gallery_value.disabled = 0');
|
129 |
+
$query->where('gallery.entity_id = ?', $entityId);
|
130 |
+
$query->where('gallery.attribute_id = ?', $mediaGalleryAttributeId);
|
131 |
+
$query->where('gallery.value NOT IN(?)', $subquery);
|
132 |
+
$query->order('gallery_value.position ASC');
|
133 |
+
|
134 |
+
$connection->setFetchMode(ZEND_DB::FETCH_NUM);
|
135 |
+
return $connection->fetchAll($query);
|
136 |
+
}
|
137 |
+
|
138 |
+
/**
|
139 |
+
* Get the master product query.
|
140 |
+
* @param int $storeId
|
141 |
+
* @param string $exportDataFieldIds
|
142 |
+
* @return null|string
|
143 |
+
*/
|
144 |
+
public function getMasterProductQuery($storeId, $exportDataFieldIds) {
|
145 |
+
if($this->_masterProductQuery === null) {
|
146 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
147 |
+
// Build queries for each attribute type
|
148 |
+
$backendTypes = array(
|
149 |
+
'datetime',
|
150 |
+
'decimal',
|
151 |
+
'int',
|
152 |
+
'text',
|
153 |
+
'varchar',
|
154 |
+
);
|
155 |
+
$queries = array();
|
156 |
+
foreach ($backendTypes as $backendType) {
|
157 |
+
// Get store value if there is one, otherwise, global value
|
158 |
+
$query = new Zend_Db_Select($connection);
|
159 |
+
$query->from(array('ce' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
|
160 |
+
array('value' => new Zend_Db_Expr($connection->quoteInto(
|
161 |
+
'CASE WHEN SUM(ev.store_id) = 0 THEN MAX(ev.value) ELSE
|
162 |
+
MAX(CASE WHEN ev.store_id = ? THEN ev.value ELSE NULL END)
|
163 |
+
END', $storeId
|
164 |
+
)), 'ev.attribute_id')
|
165 |
+
);
|
166 |
+
$query->join(array('ev' => Mage::getSingleton('core/resource')->getTableName(array('catalog/product', $backendType))),
|
167 |
+
'ce.entity_id = ev.entity_id',
|
168 |
+
null
|
169 |
+
);
|
170 |
+
$query->where('ev.store_id IN(0, ?)', $storeId);
|
171 |
+
$query->where('ev.entity_type_id = ?', $this->getEntityTypeIdForProduct());
|
172 |
+
$query->where('ev.entity_id = @ENTITY_ID');
|
173 |
+
$query->where('ev.attribute_id IN('.$exportDataFieldIds.')');
|
174 |
+
$query->group(array('ev.attribute_id', 'ev.entity_id'));
|
175 |
+
|
176 |
+
$queries[] = $query->__toString();
|
177 |
+
}
|
178 |
+
$this->_masterProductQuery = implode(" UNION ALL ", $queries);
|
179 |
+
}
|
180 |
+
return $this->_masterProductQuery;
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Get the export fields from the system config.
|
185 |
+
* @param array $attributeCodes
|
186 |
+
* @return array
|
187 |
+
*/
|
188 |
+
public function getExportFields(array $attributeCodes, &$blankProduct) {
|
189 |
+
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
190 |
+
$result = array('code' => array(), 'id' => array(), 'use_type_id' => false);
|
191 |
+
foreach (array_keys($blankProduct) as $key) {
|
192 |
+
$result['code'][] = $key;
|
193 |
+
$tmpid = array_search($key, $attributeCodes);
|
194 |
+
if (!empty($tmpid)) {
|
195 |
+
$result['id'][] = $connection->quote($tmpid);
|
196 |
+
}
|
197 |
+
}
|
198 |
+
|
199 |
+
$export_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_exportfields'));
|
200 |
+
$result['use_type_id'] = false;
|
201 |
+
if (!empty($export_fields)) {
|
202 |
+
foreach ($export_fields as $element) {
|
203 |
+
if (!empty($element['productattribute'])) {
|
204 |
+
$blankProduct[preg_replace('/\W/', '', $element['productattribute'])] = '';
|
205 |
+
$result['code'][] = $element['productattribute'];
|
206 |
+
if($element['productattribute'] == 'type_id') {
|
207 |
+
$result['use_type_id'] = true;
|
208 |
+
} else {
|
209 |
+
$tmpid = array_search($element['productattribute'], $attributeCodes);
|
210 |
+
if (!empty($tmpid)) {
|
211 |
+
$result['id'][] = $connection->quote($tmpid);
|
212 |
+
}
|
213 |
+
}
|
214 |
+
}
|
215 |
+
}
|
216 |
+
}
|
217 |
+
|
218 |
+
$tmpid = array_search('status', $attributeCodes);
|
219 |
+
if (!empty($tmpid)) {
|
220 |
+
$result['id'][] = $connection->quote($tmpid);;
|
221 |
+
}
|
222 |
+
$tmpid = array_search('url_path', $attributeCodes);
|
223 |
+
if (!empty($tmpid)) {
|
224 |
+
$result['id'][] = $connection->quote($tmpid);;
|
225 |
+
}
|
226 |
+
$tmpid = array_search('image', $attributeCodes);
|
227 |
+
if (!empty($tmpid)) {
|
228 |
+
$result['id'][] = $connection->quote($tmpid);;
|
229 |
+
}
|
230 |
+
$result['id'] = implode(',', $result['id']);
|
231 |
+
|
232 |
+
return $result;
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* Set the special export fields to the _blankProduct.
|
237 |
+
* @param array $blankProduct
|
238 |
+
*/
|
239 |
+
public function setSpecialExportField(&$blankProduct) {
|
240 |
+
$special_export_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_specialexportfields'));
|
241 |
+
if (!empty($special_export_fields)) {
|
242 |
+
foreach ($special_export_fields as $element) {
|
243 |
+
if (!empty($element['name'])) {
|
244 |
+
$blankProduct[preg_replace('/\W/', '', $element['name'])] = $element['value'];
|
245 |
+
}
|
246 |
+
}
|
247 |
+
}
|
248 |
+
}
|
249 |
+
|
250 |
+
/**
|
251 |
+
* Build the category tree and return it as array.
|
252 |
+
* @return array
|
253 |
+
*/
|
254 |
+
public function buildCategoryTree() {
|
255 |
+
$allCat = array();
|
256 |
+
$oldCatPath = '';
|
257 |
+
$oldCatTree = '';
|
258 |
+
|
259 |
+
$categoryCollection = Mage::getModel('catalog/category')->getCollection()
|
260 |
+
->addAttributeToSelect('name')
|
261 |
+
->addAttributeToSort('path');
|
262 |
+
|
263 |
+
foreach($categoryCollection as $category) {
|
264 |
+
// if (strpos($category->getPath(), $oldCatPath) !== 0) {
|
265 |
+
// start tree
|
266 |
+
$path = $this->getCategory($category->getPath(), $allCat);
|
267 |
+
if($path !== 0) {
|
268 |
+
$allCat[$category->getPath()] = str_replace('Root Catalog', 'Home', $path . '>' . $category->getName());
|
269 |
+
$oldCatTree = $path . '>' . $category->getName();
|
270 |
+
} else {
|
271 |
+
$allCat[$category->getPath()] = str_replace('Root Catalog', 'Home', $category->getName());
|
272 |
+
$oldCatTree = $category->getName();
|
273 |
+
}
|
274 |
+
// } else {
|
275 |
+
// // continue tree
|
276 |
+
// $allCat[$category->getPath()] = str_replace('Root Catalog', 'Home', $oldCatTree . '>' . $category->getName());
|
277 |
+
// $oldCatTree = $allCat[$category->getPath()];
|
278 |
+
// }
|
279 |
+
}
|
280 |
+
|
281 |
+
return $allCat;
|
282 |
+
}
|
283 |
+
|
284 |
+
private function getCategory($key, $allCat) {
|
285 |
+
$return = 0;
|
286 |
+
if (strpos($key, '/') != false) {
|
287 |
+
$tmpKey = substr($key, 0, strpos($key, strrchr($key, '/')));
|
288 |
+
if (isset($allCat[$tmpKey])) {
|
289 |
+
$return = $allCat[$tmpKey];
|
290 |
+
} else {
|
291 |
+
$return = $this->getCategory($tmpKey, $allCat);
|
292 |
+
}
|
293 |
+
}
|
294 |
+
return $return;
|
295 |
+
}
|
296 |
+
}
|
app/code/community/Channelpilotsolutions/Channelpilot/Helper/ExportData.php
CHANGED
@@ -33,6 +33,11 @@ class ExportData {
|
|
33 |
private $_storeCode;
|
34 |
private $oldCatPath;
|
35 |
private $xml;
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
function __construct() {
|
38 |
|
@@ -44,10 +49,28 @@ class ExportData {
|
|
44 |
Mage::app('admin');
|
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
|
@@ -64,15 +87,12 @@ class ExportData {
|
|
64 |
|
65 |
$currencyCode = Mage::app()->getRequest()->getParam('currency', false);
|
66 |
if ($currencyCode && $currencyCode != '') {
|
67 |
-
$
|
68 |
-
|
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
|
76 |
|
77 |
}
|
78 |
// Validate store and get information
|
@@ -82,636 +102,434 @@ class ExportData {
|
|
82 |
return $this->_extractFromMySQL();
|
83 |
}
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
$return = $this->getCategory($tmpKey);
|
93 |
-
}
|
94 |
-
}
|
95 |
-
return $return;
|
96 |
-
}
|
97 |
-
|
98 |
-
// Extract natively directly from the database
|
99 |
-
private function _extractFromMySQL() {
|
100 |
-
$selectLimit = 100;
|
101 |
-
|
102 |
-
// Increase maximium length for group_concat (for additional image URLs field)
|
103 |
-
$query = "SET SESSION group_concat_max_len = 1000000;";
|
104 |
-
$this->_dbConnection->query($query);
|
105 |
-
|
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 |
-
|
121 |
$query = new Zend_Db_Select($this->_dbConnection);
|
122 |
-
$query->
|
123 |
-
|
124 |
-
array('ev.entity_id', 'ce.path', 'ev.value')
|
125 |
);
|
126 |
-
$query->join(
|
127 |
-
|
128 |
-
'ev.entity_id = ce.entity_id',
|
129 |
null
|
130 |
);
|
131 |
-
|
132 |
-
$
|
133 |
-
$
|
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);
|
143 |
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
-
|
149 |
-
|
150 |
-
// Start tree
|
151 |
-
$path = $this->getCategory($categorie[1]);
|
152 |
-
if ($path !== 0) {
|
153 |
-
$this->_allCat[$categorie[1]] = str_replace('Root Catalog', 'Home', $path . '>' . $categorie[2]);
|
154 |
-
$oldCatTree = $path . '>' . $categorie[2];
|
155 |
-
} else {
|
156 |
-
$this->_allCat[$categorie[1]] = str_replace('Root Catalog', 'Home', $categorie[2]);
|
157 |
-
$oldCatTree = $categorie[2];
|
158 |
-
}
|
159 |
-
} else {
|
160 |
-
// continue tree
|
161 |
-
$this->_allCat[$categorie[1]] = str_replace('Root Catalog', 'Home', $oldCatTree . '>' . $categorie[2]);
|
162 |
-
$oldCatTree = $this->_allCat[$categorie[1]];
|
163 |
-
}
|
164 |
-
$oldCatPath = $categorie[1];
|
165 |
-
}
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
$query = new Zend_Db_Select($this->_dbConnection);
|
173 |
-
$query->from(Mage::getSingleton('core/resource')->getTableName('
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
$blankProduct['sku'] = '';
|
189 |
-
$blankProduct['parent_id'] = '';
|
190 |
-
$blankProduct['variationTheme'] = '';
|
191 |
-
$blankProduct['name'] = '';
|
192 |
-
$blankProduct['description'] = '';
|
193 |
-
$blankProduct['price'] = '';
|
194 |
-
$blankProduct['categories'] = '';
|
195 |
-
$blankProduct['manufacturer'] = '';
|
196 |
-
$blankProduct['cp_product_url'] = '';
|
197 |
-
$blankProduct['cp_image_url'] = '';
|
198 |
-
$blankProduct['color'] = '';
|
199 |
-
$blankProduct['weight'] = '';
|
200 |
-
for($i = 1; $i <= Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_imagenumber'); $i++) {
|
201 |
-
$blankProduct['cp_additional_image_'.$i] = '';
|
202 |
-
}
|
203 |
|
204 |
-
|
205 |
-
if (!empty($special_export_fields)) {
|
206 |
-
foreach ($special_export_fields as $element) {
|
207 |
-
if (!empty($element['name'])) {
|
208 |
-
$blankProduct[preg_replace('/\W/', '', $element['name'])] = $element['value'];
|
209 |
-
}
|
210 |
-
}
|
211 |
-
}
|
212 |
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
218 |
|
219 |
-
|
220 |
-
case 'datetime':
|
221 |
-
case 'decimal':
|
222 |
-
case 'int':
|
223 |
-
case 'text':
|
224 |
-
case 'varchar':
|
225 |
-
$attributeCodes[$row['attribute_id']] = $row['attribute_code'];
|
226 |
-
//$blankProduct[$row['attribute_code']] = '';
|
227 |
-
break;
|
228 |
-
case 'static':
|
229 |
-
// ignore columns in entity table
|
230 |
-
// print("Skipping static attribute: ".$row['attribute_code']."\n");
|
231 |
-
break;
|
232 |
-
default:
|
233 |
-
// print("Unsupported backend_type: ".$row['backend_type']."\n");
|
234 |
-
break;
|
235 |
-
}
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
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 |
-
|
264 |
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
}
|
272 |
-
$result = null;
|
273 |
-
}
|
274 |
-
}
|
275 |
|
276 |
-
|
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 |
-
|
287 |
-
$
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
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
|
321 |
-
$backendTypes = array(
|
322 |
-
'datetime',
|
323 |
-
'decimal',
|
324 |
-
'int',
|
325 |
-
'text',
|
326 |
-
'varchar',
|
327 |
-
);
|
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 |
-
|
350 |
-
}
|
351 |
-
$query = implode(" UNION ALL ", $queries);
|
352 |
-
$MasterProductQuery = $query;
|
353 |
|
354 |
-
|
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 |
-
|
367 |
-
|
|
|
|
|
|
|
368 |
|
369 |
-
|
370 |
|
371 |
-
|
372 |
-
|
373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
374 |
}
|
375 |
|
376 |
-
|
377 |
-
$replace_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_replacefields'));
|
378 |
|
379 |
-
|
380 |
-
|
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 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
$
|
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);
|
442 |
-
// Loop through each product and output the data
|
443 |
-
foreach ($EntityIds as $entity) {
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
// Fill the master query with the entity ID
|
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 |
-
|
454 |
-
// Create a new product record
|
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) {
|
472 |
-
$variationTheme = $variationTheme . "|" . $varresult[0];
|
473 |
-
}
|
474 |
-
$product['variationTheme'] = ltrim($variationTheme, "|");
|
475 |
-
$variationThemes[$entity[0]] = ltrim($variationTheme, "|");
|
476 |
-
} else {
|
477 |
-
if (empty($entity[2]) != true) {
|
478 |
-
$product['variationTheme'] = $variationThemes[$entity[2]];
|
479 |
-
}
|
480 |
-
}
|
481 |
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
if ($attributeCodes[$column[1]] == 'url_path') {
|
535 |
-
$product_url = $column[0];
|
536 |
-
}
|
537 |
-
if ($attributeCodes[$column[1]] == 'image') {
|
538 |
-
$product_image = $column[0];
|
539 |
-
}
|
540 |
-
}
|
541 |
-
$result = null;
|
542 |
|
543 |
-
|
544 |
-
|
545 |
-
|
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 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
if ($categorieField !== '') {
|
587 |
-
$categorieField = $categorieField . ', ' . $this->_allCat[$this->oldCatPath];
|
588 |
-
} else {
|
589 |
-
$categorieField = $this->_allCat[$this->oldCatPath];
|
590 |
-
}
|
591 |
-
}
|
592 |
-
$this->oldCatPath = $categorie[1];
|
593 |
-
} else {
|
594 |
-
// Add to tree
|
595 |
-
$this->oldCatPath = $categorie[1];
|
596 |
-
}
|
597 |
-
}
|
598 |
-
if ($categorieField !== '') {
|
599 |
-
$categorieField = $categorieField . ', ' . $this->_allCat[$this->oldCatPath];
|
600 |
-
} else {
|
601 |
-
if ($this->oldCatPath !== '') {
|
602 |
-
$categorieField = $this->_allCat[$this->oldCatPath];
|
603 |
-
}
|
604 |
-
}
|
605 |
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
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) {
|
651 |
-
$additional_images = explode(',', $galleryValues[0][1]);
|
652 |
-
for($i = 0; $i < Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_imagenumber'); $i++) {
|
653 |
-
if (isset($additional_images[$i])) {
|
654 |
-
$product['cp_additional_image_' . ($i + 1)] = $additional_images[$i];
|
655 |
-
}
|
656 |
-
}
|
657 |
-
}
|
658 |
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
|
|
|
|
|
|
|
|
663 |
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
}
|
669 |
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
|
|
674 |
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
|
|
|
|
|
|
702 |
|
703 |
-
if($
|
704 |
-
$product['type_id'] = $entity
|
705 |
}
|
706 |
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
|
|
|
|
|
|
715 |
|
716 |
// Join two URL paths and handle forward slashes
|
717 |
private function _urlPathJoin($part1, $part2) {
|
33 |
private $_storeCode;
|
34 |
private $oldCatPath;
|
35 |
private $xml;
|
36 |
+
private $_mediaGalleryAttributeId;
|
37 |
+
private $_productEntityTypeId;
|
38 |
+
private $_variationThemes;
|
39 |
+
private $_blankProduct;
|
40 |
+
private $_baseImageAttributeId;
|
41 |
|
42 |
function __construct() {
|
43 |
|
49 |
Mage::app('admin');
|
50 |
|
51 |
// Get the table prefix
|
52 |
+
// $tableName = Mage::getSingleton('core/resource')->getTableName('core_website');
|
53 |
|
54 |
// Get database connection
|
55 |
$this->_dbConnection = Mage::getSingleton('core/resource')->getConnection('core_read');
|
56 |
+
|
57 |
+
$this->_blankProduct = array();
|
58 |
+
$this->_blankProduct['entity_id'] = '';
|
59 |
+
$this->_blankProduct['sku'] = '';
|
60 |
+
$this->_blankProduct['parent_id'] = '';
|
61 |
+
$this->_blankProduct['variationTheme'] = '';
|
62 |
+
$this->_blankProduct['name'] = '';
|
63 |
+
$this->_blankProduct['description'] = '';
|
64 |
+
$this->_blankProduct['price'] = '';
|
65 |
+
$this->_blankProduct['categories'] = '';
|
66 |
+
$this->_blankProduct['manufacturer'] = '';
|
67 |
+
$this->_blankProduct['cp_product_url'] = '';
|
68 |
+
$this->_blankProduct['cp_image_url'] = '';
|
69 |
+
$this->_blankProduct['color'] = '';
|
70 |
+
$this->_blankProduct['weight'] = '';
|
71 |
+
for($i = 1; $i <= Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_imagenumber'); $i++) {
|
72 |
+
$this->_blankProduct['cp_additional_image_'.$i] = '';
|
73 |
+
}
|
74 |
}
|
75 |
|
76 |
// Run the main application and call the appropriate function
|
87 |
|
88 |
$currencyCode = Mage::app()->getRequest()->getParam('currency', false);
|
89 |
if ($currencyCode && $currencyCode != '') {
|
90 |
+
$result = Mage::getModel('directory/currency')->getCurrencyRates(Mage::app()->getBaseCurrencyCode(), $currencyCode);
|
91 |
+
if(count($result) === 0){
|
|
|
|
|
|
|
92 |
echo "<error>wrong currency</error>";
|
93 |
return;
|
94 |
}
|
95 |
+
$this->_currencyChange = $result[$currencyCode];
|
96 |
|
97 |
}
|
98 |
// Validate store and get information
|
102 |
return $this->_extractFromMySQL();
|
103 |
}
|
104 |
|
105 |
+
/**
|
106 |
+
* Get the category information for an entity_id.
|
107 |
+
* @param int $entityId
|
108 |
+
* @return string
|
109 |
+
*/
|
110 |
+
private function _getCategoryInformation($entityId) {
|
111 |
+
if (substr(Mage::getVersion(), 2, 3) >= 6 && Mage::getStoreConfigFlag('catalog/frontend/flat_catalog_category', $this->_storeId)) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
$query = new Zend_Db_Select($this->_dbConnection);
|
113 |
$query->distinct();
|
114 |
$query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
|
115 |
array('fs.entity_id', 'fs.path', 'fs.name')
|
116 |
);
|
117 |
+
$query->join(array('fs' => Mage::getSingleton('core/resource')->getTableName(array('catalog/category_flat', 'store_'.$this->_storeId))),
|
|
|
118 |
'pi.category_id = fs.entity_id',
|
119 |
null
|
120 |
);
|
121 |
+
$query->where('pi.product_id = ?', $entityId);
|
122 |
+
$query->where('pi.store_id = ?', $this->_storeId);
|
123 |
$query->order('fs.path ASC');
|
124 |
+
} else {
|
125 |
$query = new Zend_Db_Select($this->_dbConnection);
|
126 |
+
$query->from(array('pi' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')),
|
127 |
+
array('pi.category_id', 'ce.path')
|
|
|
128 |
);
|
129 |
+
$query->join(array('ce' => Mage::getSingleton('core/resource')->getTableName('catalog/category')),
|
130 |
+
'pi.category_id = ce.entity_id',
|
|
|
131 |
null
|
132 |
);
|
133 |
+
$query->where('pi.product_id = ?', $entityId);
|
134 |
+
$query->where('pi.is_parent = 1');
|
135 |
+
$query->where('pi.store_id = ?', $this->_storeId);
|
|
|
|
|
|
|
136 |
$query->order('ce.path ASC');
|
137 |
+
}
|
|
|
|
|
|
|
|
|
138 |
|
139 |
+
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
|
140 |
+
|
141 |
+
$categoriesTable = $this->_dbConnection->fetchAll($query);
|
142 |
+
$categorieField = '';
|
143 |
+
$this->oldCatPath = '';
|
144 |
+
foreach ($categoriesTable as $categorie) {
|
145 |
+
if (($this->oldCatPath == '') || (strpos($categorie[1], $this->oldCatPath) !== 0)) {
|
146 |
+
// Start tree
|
147 |
+
if ($this->oldCatPath !== '') {
|
148 |
+
if ($categorieField !== '') {
|
149 |
+
$categorieField = $categorieField . ', ' . $this->_allCat[$this->oldCatPath];
|
150 |
+
} else {
|
151 |
+
$categorieField = $this->_allCat[$this->oldCatPath];
|
152 |
+
}
|
153 |
+
}
|
154 |
+
$this->oldCatPath = $categorie[1];
|
155 |
+
} else {
|
156 |
+
// Add to tree
|
157 |
+
$this->oldCatPath = $categorie[1];
|
158 |
+
}
|
159 |
+
}
|
160 |
+
if ($categorieField !== '') {
|
161 |
+
$categorieField = $categorieField . ', ' . $this->_allCat[$this->oldCatPath];
|
162 |
+
} else {
|
163 |
+
if ($this->oldCatPath !== '') {
|
164 |
+
$categorieField = $this->_allCat[$this->oldCatPath];
|
165 |
+
}
|
166 |
+
}
|
167 |
|
168 |
+
return $categorieField;
|
169 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
170 |
|
171 |
+
/**
|
172 |
+
* Get the count of all products.
|
173 |
+
* @return mixed
|
174 |
+
*/
|
175 |
+
private function _getProductCount() {
|
176 |
$query = new Zend_Db_Select($this->_dbConnection);
|
177 |
+
$query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')),
|
178 |
+
new Zend_Db_Expr('count(*)')
|
179 |
+
);
|
180 |
+
$query->join(array('cpw' => Mage::getSingleton('core/resource')->getTableName('catalog/product_website')),
|
181 |
+
'cpw.product_id = cpe.entity_id',
|
182 |
+
null
|
183 |
+
);
|
184 |
+
$query->where('cpw.website_id = ?', $this->_siteId);
|
185 |
+
$query->where("IFNULL(cpe.sku, '') != ''");
|
186 |
|
187 |
+
$this->_dbConnection->setFetchMode(ZEND_DB::FETCH_NUM);
|
188 |
+
return $this->_dbConnection->fetchAll($query);
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Get products from the database limited by the count and offset.
|
193 |
+
* @param int $count
|
194 |
+
* @param int $offset
|
195 |
+
* @return mixed
|
196 |
+
*/
|
197 |
+
private function _getProductEntities($count, $offset) {
|
198 |
+
// Get all entity_ids for all products in the selected store
|
199 |
+
$columns = array('cpe.entity_id', 'cpe.sku', 'cpe.type_id');
|
200 |
$query = new Zend_Db_Select($this->_dbConnection);
|
|
|
|
|
|
|
201 |
|
202 |
+
$subquery = new Zend_Db_Select($this->_dbConnection);
|
203 |
+
$subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'), array('parent_id'));
|
204 |
+
$subquery->where('product_id = cpe.entity_id');
|
205 |
+
$subquery->limit(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
|
207 |
+
$columns['parent'] = new Zend_Db_Expr('('.$subquery.')');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
+
$subquery = new Zend_Db_Select($this->_dbConnection);
|
210 |
+
$subquery->from(Mage::getSingleton('core/resource')->getTableName('catalog/product_super_link'), array(
|
211 |
+
new Zend_Db_Expr('COUNT(*)')
|
212 |
+
));
|
213 |
+
$subquery->where('parent_id = cpe.entity_id');
|
214 |
+
$subquery->limit(1);
|
215 |
|
216 |
+
$columns['is_parent'] = new Zend_Db_Expr('('.$subquery.')');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
+
$subquery = new Zend_Db_Select($this->_dbConnection);
|
219 |
+
$subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'), array('qty'));
|
220 |
+
$subquery->where('product_id = cpe.entity_id');
|
221 |
+
$subquery->where('website_id = ?', $this->_siteId);
|
222 |
+
$subquery->where('stock_id = 1');
|
223 |
+
$subquery->limit(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
+
$columns['qty'] = new Zend_Db_Expr('('.$subquery.')');
|
226 |
|
227 |
+
$subquery = new Zend_Db_Select($this->_dbConnection);
|
228 |
+
$subquery->from(Mage::getSingleton('core/resource')->getTableName('cataloginventory/stock_status'), array('stock_status'));
|
229 |
+
$subquery->where('product_id = cpe.entity_id');
|
230 |
+
$subquery->where('website_id = ?', $this->_siteId);
|
231 |
+
$subquery->where('stock_id = 1');
|
232 |
+
$subquery->limit(1);
|
|
|
|
|
|
|
|
|
233 |
|
234 |
+
$columns['stock_status'] = new Zend_Db_Expr('('.$subquery.')');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
|
236 |
+
$subquery = new Zend_Db_Select($this->_dbConnection);
|
237 |
+
$subquery->from(array('crpp' => Mage::getSingleton('core/resource')->getTableName('catalogrule/rule_product_price')), array('crpp.rule_price'));
|
238 |
+
$subquery->where('crpp.rule_date = CURDATE()');
|
239 |
+
$subquery->where('crpp.product_id = cpe.entity_id');
|
240 |
+
$subquery->where('crpp.customer_group_id = 1');
|
241 |
+
$subquery->where('crpp.website_id = ?', $this->_siteId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
243 |
+
$columns['cat_price'] = new Zend_Db_Expr('('.$subquery.')');
|
|
|
|
|
|
|
244 |
|
245 |
+
$query->from(array('cpe' => Mage::getSingleton('core/resource')->getTableName('catalog/product')), $columns);
|
|
|
|
|
|
|
|
|
246 |
$query->join(array('cpw' => Mage::getSingleton('core/resource')->getTableName('catalog/product_website')),
|
247 |
'cpw.product_id = cpe.entity_id',
|
248 |
null
|
249 |
);
|
250 |
$query->where('cpw.website_id = ?', $this->_siteId);
|
251 |
$query->where("IFNULL(cpe.sku, '') != ''");
|
252 |
+
$query->order(array('is_parent DESC', 'entity_id DESC'));
|
253 |
+
$query->limit($count, $offset);
|
254 |
+
|
255 |
+
return $this->_dbConnection->fetchAssoc($query);
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Get the variation theme for a product id.
|
260 |
+
* @param int $productId
|
261 |
+
* @param int $isParent
|
262 |
+
* @param int $parentId
|
263 |
+
* @return string
|
264 |
+
*/
|
265 |
+
private function _getVariationTheme($productId, $isParent, $parentId = 0) {
|
266 |
+
if (intval($isParent) > 0) {
|
267 |
+
$varQuery = new Zend_Db_Select($this->_dbConnection);
|
268 |
+
$varQuery->from(array('cpsa' => Mage::getSingleton('core/resource')->getTableName('catalog/product_super_attribute')),
|
269 |
+
array('ea.attribute_code')
|
270 |
+
);
|
271 |
+
$varQuery->joinLeft(array('ea' => Mage::getSingleton('core/resource')->getTableName('eav/attribute')),
|
272 |
+
'ea.attribute_id = cpsa.attribute_id',
|
273 |
+
null
|
274 |
+
);
|
275 |
+
$varQuery->where('cpsa.product_id = ?', $productId);
|
276 |
+
$varQuery->order('ea.attribute_id');
|
277 |
+
|
278 |
+
$varresults = $this->_dbConnection->fetchAll($varQuery);
|
279 |
+
$variationTheme = "";
|
280 |
+
foreach ($varresults as $varresult) {
|
281 |
+
$variationTheme = $variationTheme . "|" . $varresult[0];
|
282 |
+
}
|
283 |
+
$variationTheme = ltrim($variationTheme, "|");
|
284 |
+
$this->_variationThemes[$productId] = $variationTheme;
|
285 |
+
return $variationTheme;
|
286 |
+
} else {
|
287 |
+
if (!empty($parentId)) {
|
288 |
+
return $this->_variationThemes[$parentId];
|
289 |
+
}
|
290 |
+
}
|
291 |
+
}
|
292 |
|
293 |
+
// Extract natively directly from the database
|
294 |
+
private function _extractFromMySQL() {
|
295 |
+
// Increase maximium length for group_concat (for additional image URLs field)
|
296 |
+
$query = "SET SESSION group_concat_max_len = 1000000;";
|
297 |
+
$this->_dbConnection->query($query);
|
298 |
|
299 |
+
$this->_allCat = Mage::helper('channelpilot/export')->buildCategoryTree();
|
300 |
|
301 |
+
// By default, set media gallery attribute id to 703
|
302 |
+
// Look it up later
|
303 |
+
$this->_mediaGalleryAttributeId = 703;
|
304 |
+
|
305 |
+
// Get the entity type for products
|
306 |
+
$this->_productEntityTypeId = Mage::helper('channelpilot/export')->getEntityTypeIdForProduct();
|
307 |
+
|
308 |
+
// Get attribute codes and types
|
309 |
+
$attributes = Mage::helper('channelpilot/export')->getProductAttributes();
|
310 |
+
|
311 |
+
$attributeCodes = array();
|
312 |
+
$attributeOptions = array();
|
313 |
+
|
314 |
+
Mage::helper('channelpilot/export')->setSpecialExportField($this->_blankProduct);
|
315 |
+
|
316 |
+
foreach ($attributes as $row) {
|
317 |
+
// Save attribute ID for media gallery
|
318 |
+
if ($row['attribute_code'] == 'media_gallery') {
|
319 |
+
$this->_mediaGalleryAttributeId = $row['attribute_id'];
|
320 |
+
}
|
321 |
+
|
322 |
+
if($row['attribute_code'] == 'image') {
|
323 |
+
$this->_baseImageAttributeId = $row['attribute_id'];
|
324 |
+
}
|
325 |
+
|
326 |
+
if($row['backend_type'] != 'static') {
|
327 |
+
$attributeCodes[$row['attribute_id']] = $row['attribute_code'];
|
328 |
+
}
|
329 |
+
|
330 |
+
// If the type is multiple choice, cache the option values
|
331 |
+
// in a lookup array for performance (avoids several joins/aggregations)
|
332 |
+
if ($row['frontend_input'] == 'select' || $row['frontend_input'] == 'multiselect') {
|
333 |
+
$result = Mage::helper('channelpilot/export')->getAttributeOptions($row['attribute_id'], $this->_storeId);
|
334 |
+
// If found, then save the lookup table in the attributeOptions array
|
335 |
+
if (is_array($result)) {
|
336 |
+
$attributeOptions[$row['attribute_id']] = $result;
|
337 |
+
} else {
|
338 |
+
// Otherwise, leave a blank array
|
339 |
+
$attributeOptions[$row['attribute_id']] = array();
|
340 |
+
}
|
341 |
+
$result = null;
|
342 |
+
}
|
343 |
}
|
344 |
|
345 |
+
$this->_displayProductData($attributeCodes, $attributeOptions);
|
|
|
346 |
|
347 |
+
return;
|
348 |
+
}
|
|
|
|
|
|
|
349 |
|
350 |
+
/**
|
351 |
+
* Create a product and output it as xml.
|
352 |
+
* @param array $attributeCodes
|
353 |
+
* @param array $attributeOptions
|
354 |
+
*/
|
355 |
+
private function _displayProductData(array $attributeCodes, array $attributeOptions) {
|
356 |
+
$selectLimit = 100;
|
357 |
+
$count = $this->_getProductCount();
|
358 |
+
$counter = 0;
|
359 |
+
|
360 |
+
$border = (int) $count[0][0] - $selectLimit;
|
361 |
+
if ($border < $count[0][0]) {
|
362 |
+
$border = $count[0][0];
|
363 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
364 |
|
365 |
+
$exportFields = Mage::helper('channelpilot/export')->getExportFields($attributeCodes, $this->_blankProduct);
|
366 |
+
|
367 |
+
// Build queries for each attribute type
|
368 |
+
$MasterProductQuery = Mage::helper('channelpilot/export')->getMasterProductQuery($this->_storeId, $exportFields['id']);
|
369 |
+
|
370 |
+
$parentProductArray = array();
|
371 |
+
$this->_variationThemes = array();
|
372 |
+
while ($counter <= $border) {
|
373 |
+
// Get all entity_ids for all products in the selected store
|
374 |
+
$EntityIds = $this->_getProductEntities($selectLimit, $counter);
|
375 |
+
// Loop through each product and output the data
|
376 |
+
foreach ($EntityIds as $entity) {
|
377 |
+
// Fill the master query with the entity ID
|
378 |
+
$query = str_replace('@ENTITY_ID', $entity['entity_id'], $MasterProductQuery);
|
379 |
+
$result = $this->_dbConnection->query($query);
|
380 |
+
// Create a new product record
|
381 |
+
$product = $this->_blankProduct;
|
382 |
+
$product['variationTheme'] = $this->_getVariationTheme($entity['entity_id'], $entity['is_parent'], $entity['parent']);
|
383 |
+
|
384 |
+
// Initialize basic product data
|
385 |
+
$product['entity_id'] = $entity['entity_id'];
|
386 |
+
$product['sku'] = $entity['sku'];
|
387 |
+
|
388 |
+
// Escape the SKU (it may contain double-quotes)
|
389 |
+
$product['sku'] = str_replace('"', '""', $product['sku']);
|
390 |
+
$product['is_parent'] = $entity['is_parent'] > 0 ? 1 : 0;
|
391 |
+
|
392 |
+
$product_status = null;
|
393 |
+
$product_url = null;
|
394 |
+
$product_image = null;
|
395 |
+
// Loop through each field in the row and get the value
|
396 |
+
foreach($result->fetchAll() as $column) {
|
397 |
+
// Translate the option option_id to a value.
|
398 |
+
if (isset($attributeOptions[$column[1]])) {
|
399 |
+
// Convert all option values
|
400 |
+
$optionValues = explode(',', $column[0]);
|
401 |
+
$convertedOptionValues = array();
|
402 |
+
foreach ($optionValues as $optionValue) {
|
403 |
+
if (isset($attributeOptions[$column[1]][$optionValue]) == true) {
|
404 |
+
// If a option_id is found, translate it
|
405 |
+
$convertedOptionValues[] = $attributeOptions[$column[1]][$optionValue];
|
406 |
+
}
|
407 |
+
}
|
408 |
+
// Erase values that are set to zero
|
409 |
+
if ($column[0] == '0') {
|
410 |
+
$column[0] = '';
|
411 |
+
} elseif (!empty($convertedOptionValues)) {
|
412 |
+
// Use convert values if any conversions exist
|
413 |
+
$column[0] = implode(',', $convertedOptionValues);
|
414 |
+
}
|
415 |
+
// Otherwise, leave value as-is
|
416 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
417 |
|
418 |
+
if (in_array($attributeCodes[$column[1]], $exportFields['code'])) {
|
419 |
+
$product[$attributeCodes[$column[1]]] = $column[0];
|
420 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
|
422 |
+
if ($attributeCodes[$column[1]] == 'status') {
|
423 |
+
$product_status = $column[0];
|
424 |
+
}
|
425 |
+
if ($attributeCodes[$column[1]] == 'url_path') {
|
426 |
+
$product_url = $column[0];
|
427 |
+
}
|
428 |
+
if ($attributeCodes[$column[1]] == 'image') {
|
429 |
+
$product_image = $column[0];
|
430 |
+
}
|
431 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
432 |
|
433 |
+
$result = null;
|
434 |
+
|
435 |
+
// Skip product that are disabled or have no status
|
436 |
+
if (empty($product_status) || $product_status == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
|
437 |
+
continue;
|
438 |
+
}
|
439 |
+
// Get category information
|
440 |
+
$product['categories'] = $this->_getCategoryInformation($entity['entity_id']);
|
441 |
+
// Get stock quantity
|
442 |
+
// NOTE: stock_id = 1 is the 'Default' stock
|
443 |
+
if (in_array('qty', $exportFields['code'])) {
|
444 |
+
if (empty($entity['qty']) == true) {
|
445 |
+
$product['qty'] = '0';
|
446 |
+
} else {
|
447 |
+
$product['qty'] = $entity['qty'];
|
448 |
+
}
|
449 |
+
}
|
450 |
+
|
451 |
+
if (in_array('stock_status', $exportFields['code'])) {
|
452 |
+
if (empty($entity['stock_status']) == true) {
|
453 |
+
$product['stock_status'] = '';
|
454 |
+
} else {
|
455 |
+
$product['stock_status'] = $entity['stock_status'];
|
456 |
+
}
|
457 |
+
}
|
458 |
+
$stockInfoResult = null;
|
459 |
+
|
460 |
+
// Get additional image URLs
|
461 |
+
$galleryValues = Mage::helper('channelpilot/export')->getAdditionalImageUrl(
|
462 |
+
$entity['entity_id'],
|
463 |
+
$this->_storeId,
|
464 |
+
$this->_mediaGalleryAttributeId,$this->_baseImageAttributeId
|
|
|
|
|
|
|
465 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
466 |
|
467 |
+
if (empty($galleryValues) != true) {
|
468 |
+
$additional_images = explode(',', $galleryValues[0][1]);
|
469 |
+
for($i = 0; $i < Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_imagenumber'); $i++) {
|
470 |
+
if (isset($additional_images[$i])) {
|
471 |
+
$product['cp_additional_image_' . ($i + 1)] = $additional_images[$i];
|
472 |
+
}
|
473 |
+
}
|
474 |
+
}
|
475 |
|
476 |
+
// Get parent ID
|
477 |
+
if (empty($entity['parent']) != true && in_array('parent_id', $exportFields['code'])) {
|
478 |
+
$product['parent_id'] = $entity['parent'];
|
479 |
+
}
|
|
|
480 |
|
481 |
+
// Override price with catalog price rule, if found
|
482 |
+
if (empty($entity['cat_price']) != true) {
|
483 |
+
// Override price with catalog rule price
|
484 |
+
$product['price'] = $entity['cat_price'];
|
485 |
+
}
|
486 |
|
487 |
+
// Calculate image and product URLs
|
488 |
+
if (empty($product_url) == false) {
|
489 |
+
$product['cp_product_url'] = $this->_urlPathJoin($this->_webUrl, $product_url);
|
490 |
+
}
|
491 |
|
492 |
+
if (empty($product_image) == false) {
|
493 |
+
$product['cp_image_url'] = $this->_urlPathJoin($this->_mediaUrl, 'catalog/product');
|
494 |
+
$product['cp_image_url'] = $this->_urlPathJoin($product['cp_image_url'], $product_image);
|
495 |
+
}
|
496 |
+
|
497 |
+
$replace_fields = unserialize(Mage::getStoreConfig('channelpilot_export/channelpilot_productfeed/channelpilot_replacefields'));
|
498 |
+
if (!empty($replace_fields)) {
|
499 |
+
// PARENT
|
500 |
+
if ($entity['is_parent'] > 0) {
|
501 |
+
foreach ($replace_fields as $element) {
|
502 |
+
if (!empty($element['productattribute']) && array_key_exists($element['productattribute'], $product)) {
|
503 |
+
$parentProductArray[$product['id']][$element['productattribute']] = $product[$element['productattribute']];
|
504 |
+
}
|
505 |
+
}
|
506 |
+
} else {
|
507 |
+
// CHILD
|
508 |
+
if ($entity['parent'] != null) {
|
509 |
+
foreach ($replace_fields as $element) {
|
510 |
+
if (!empty($element['productattribute']) && array_key_exists($element['productattribute'], $product)) {
|
511 |
+
$product[$element['productattribute']] = $parentProductArray[$entity['parent']][$element['productattribute']];
|
512 |
+
}
|