Profileolabs_Shoppingflux - Version 1.1.0

Version Notes

[Features]
* It is now possible to specify how much product images should be exported (all by default)
* Orders synchronization is enabled by default
* When out-of-stock and not-salable products are not exported in the feed, it is now possible to temporarily retain them, ensuring that they can be updated wherever necessary (experimental)
* Shipment tracking URLs are now automatically detected for DPD France modules

[Bug fixes]
* The default shipping delay for products is now consistently used when necessary
* The rewrite of the "cataloginventory/stock_item" model is not based anymore on the corresponding rewrite from the "MDN_AdvancedStock" extension when this extension is installed but not enabled
* Non-admin users can now have access to the extension menus
* The number of products that can be associated to a category does not depend on the server configuration anymore
* Products are now consistently visible within the export selection grid when a store view is chosen
* The feed generation could crash on fresh Magento installations, if the shipping carriers configuration was not saved yet

Download this release

Release Info

Developer ShoppingFlux
Extension Profileolabs_Shoppingflux
Version 1.1.0
Comparing to
See all releases


Code changes from version 1.0.3 to 1.1.0

Files changed (87) hide show
  1. app/code/community/Profileolabs/.DS_Store +0 -0
  2. app/code/community/Profileolabs/Shoppingflux/Block/Adminhtml/Register/Notification.php +12 -12
  3. app/code/community/Profileolabs/Shoppingflux/Block/Adminhtml/System/Config/Form/Fieldset/Abstract.php +59 -59
  4. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Catalog/Category/Edit/Form.php +38 -38
  5. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Catalog/Category/Tab/Default.php +191 -191
  6. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Feed.php +27 -27
  7. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Process.php +149 -149
  8. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Product.php +64 -64
  9. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Product/Grid.php +260 -260
  10. app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Widget/Grid/Column/Renderer/Bool.php +33 -33
  11. app/code/community/Profileolabs/Shoppingflux/Block/Export/Flow.php +984 -984
  12. app/code/community/Profileolabs/Shoppingflux/Block/Export/Flux.php +112 -107
  13. app/code/community/Profileolabs/Shoppingflux/Block/Export/Tracking.php +68 -68
  14. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Cron.php +21 -21
  15. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Cron/Grid.php +107 -107
  16. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Import.php +12 -12
  17. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Log.php +24 -24
  18. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Log/Grid.php +64 -64
  19. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Order.php +19 -19
  20. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Order/Grid.php +235 -235
  21. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Order/View/Tab/Shoppingflux.php +47 -47
  22. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/System/Config/Form/Fieldset/Customer/Group.php +87 -87
  23. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/System/Config/Form/Fieldset/Shipping/Method.php +87 -87
  24. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/System/Config/Form/Fieldset/Shipping/Method/Extra.php +97 -97
  25. app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Payment/Info/Purchaseorder.php +17 -17
  26. app/code/community/Profileolabs/Shoppingflux/Block/Tracking/Buyline.php +40 -40
  27. app/code/community/Profileolabs/Shoppingflux/Block/Tracking/Roi.php +44 -44
  28. app/code/community/Profileolabs/Shoppingflux/Helper/Data.php +492 -491
  29. app/code/community/Profileolabs/Shoppingflux/Helper/String.php +217 -0
  30. app/code/community/Profileolabs/Shoppingflux/Model/Attribute/Source/Category.php +66 -66
  31. app/code/community/Profileolabs/Shoppingflux/Model/Catalog/Product/Collection.php +26 -26
  32. app/code/community/Profileolabs/Shoppingflux/Model/Catalog/Resource/Eav/Attribute.php +11 -11
  33. app/code/community/Profileolabs/Shoppingflux/Model/Config.php +355 -323
  34. app/code/community/Profileolabs/Shoppingflux/Model/Export/Convert/Parser/Product.php +39 -39
  35. app/code/community/Profileolabs/Shoppingflux/Model/Export/Flow.php +799 -799
  36. app/code/community/Profileolabs/Shoppingflux/Model/Export/Flux.php +1181 -1152
  37. app/code/community/Profileolabs/Shoppingflux/Model/Export/Observer.php +715 -444
  38. app/code/community/Profileolabs/Shoppingflux/Model/Export/Rewrite/Catalog/Config.php +58 -58
  39. app/code/community/Profileolabs/Shoppingflux/Model/Export/Rewrite/CatalogInventory/Stock/Item.php +32 -32
  40. app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Attributes.php +56 -56
  41. app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Attributesprice.php +31 -31
  42. app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Category/Level.php +18 -18
  43. app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Tracking/Delay.php +28 -28
  44. app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Visibility.php +21 -21
  45. app/code/community/Profileolabs/Shoppingflux/Model/Export/Updates.php +31 -31
  46. app/code/community/Profileolabs/Shoppingflux/Model/Export/Xml.php +149 -149
  47. app/code/community/Profileolabs/Shoppingflux/Model/Export/Xmlflow.deprecated.php +250 -250
  48. app/code/community/Profileolabs/Shoppingflux/Model/Export/Xmlflow.php +139 -139
  49. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Convert/Customer.php +117 -117
  50. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Export/Shipments.php +19 -19
  51. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Log.php +35 -35
  52. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Observer.php +305 -252
  53. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Order.php +923 -923
  54. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Payment/Method/Purchaseorder.php +44 -44
  55. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Product.php +17 -17
  56. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Shipping/Carrier/Shoppingflux.php +106 -106
  57. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Shipping/Method.php +45 -45
  58. app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Source/Attributes.php +59 -59
  59. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Flux.php +16 -16
  60. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Flux/Collection.php +14 -14
  61. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Updates.php +16 -16
  62. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Updates/Collection.php +14 -14
  63. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Export/Shipments.php +12 -12
  64. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Export/Shipments/Collection.php +13 -13
  65. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Log.php +14 -14
  66. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Log/Collection.php +14 -14
  67. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Shipping/Method.php +14 -14
  68. app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Shipping/Method/Collection.php +14 -14
  69. app/code/community/Profileolabs/Shoppingflux/Model/Sales/Service/Quote.php +34 -34
  70. app/code/community/Profileolabs/Shoppingflux/Model/Service.php +322 -322
  71. app/code/community/Profileolabs/Shoppingflux/Model/Service/Http/Client/Adapter/Curl.php +507 -507
  72. app/code/community/Profileolabs/Shoppingflux/Model/Service/Http/Client/Adapter/Stream.php +46 -46
  73. app/code/community/Profileolabs/Shoppingflux/Model/System/Config/Backend/Apikey.php +38 -38
  74. app/code/community/Profileolabs/Shoppingflux/Model/System/Config/Backend/Category.php +50 -50
  75. app/code/community/Profileolabs/Shoppingflux/Model/System/Config/Backend/Refresh.php +60 -60
  76. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Export/CategoryController.php +33 -33
  77. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/ExportController.php +134 -134
  78. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/GeneralController.php +52 -52
  79. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Order/CronController.php +41 -41
  80. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Order/ImportController.php +63 -63
  81. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Order/LogController.php +51 -51
  82. app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/OrderController.php +60 -60
  83. app/code/community/Profileolabs/Shoppingflux/controllers/Export/FluxController.php +239 -239
  84. app/code/community/Profileolabs/Shoppingflux/controllers/Manageorders/LaunchController.php +34 -34
  85. app/code/community/Profileolabs/Shoppingflux/etc/adminhtml.xml +118 -94
  86. app/code/community/Profileolabs/Shoppingflux/etc/config.xml +536 -521
  87. app/code/community/Profileolabs/Shoppingflux/etc/system.xml +668 -950
app/code/community/Profileolabs/.DS_Store DELETED
Binary file
app/code/community/Profileolabs/Shoppingflux/Block/Adminhtml/Register/Notification.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Block_Adminhtml_Register_Notification extends Mage_Adminhtml_Block_Template {
4
-
5
- protected function _toHtml() {
6
- if(Mage::helper('profileolabs_shoppingflux')->isRegistered()) {
7
- return '';
8
- }
9
- return parent::_toHtml();
10
- }
11
-
12
- }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Block_Adminhtml_Register_Notification extends Mage_Adminhtml_Block_Template {
4
+
5
+ protected function _toHtml() {
6
+ if(Mage::helper('profileolabs_shoppingflux')->isRegistered()) {
7
+ return '';
8
+ }
9
+ return parent::_toHtml();
10
+ }
11
+
12
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Adminhtml/System/Config/Form/Fieldset/Abstract.php CHANGED
@@ -1,60 +1,60 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
4
-
5
-
6
- public function getConfig() {
7
- return Mage::helper('profileolabs_shoppingflux')->getConfig();
8
- }
9
-
10
- public function shouldRenderUnregistered() {
11
- $storeCode = Mage::app()->getRequest()->getParam('store', null);
12
- $store = Mage::app()->getStore($storeCode);
13
- $apiKey = $this->getConfig()->getApiKey($store->getId());
14
- $wsUri = $this->getConfig()->getWsUri($store->getId());
15
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
16
- return $service->isClient();
17
- }
18
-
19
-
20
- public function render(Varien_Data_Form_Element_Abstract $element) {
21
- if($this->shouldRenderUnregistered()) {
22
- return parent::render($element);
23
- }
24
-
25
- return $this->renderUnregistered($element);
26
- }
27
-
28
- public function renderUnregistered(Varien_Data_Form_Element_Abstract $element) {
29
-
30
- if(Mage::registry('shoppingflux_unregistered_block')) {
31
- return '';
32
- }
33
- $block = Mage::app()->getLayout()->createBlock('adminhtml/template');
34
- $block->setTemplate('profileolabs/shoppingflux/register.phtml');
35
-
36
- Mage::register('shoppingflux_unregistered_block', true);
37
- return $block->toHtml();
38
- }
39
-
40
- protected function _getHeaderHtml($element) {
41
- $html = parent::_getHeaderHtml($element);
42
- return $html;
43
- }
44
-
45
- protected function _getFieldRenderer() {
46
- if (empty($this->_fieldRenderer)) {
47
- $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
48
- }
49
- return $this->_fieldRenderer;
50
- }
51
-
52
- protected function _getDummyElement() {
53
- if (empty($this->_dummyElement)) {
54
- $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
55
- }
56
- return $this->_dummyElement;
57
- }
58
-
59
-
60
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract extends Mage_Adminhtml_Block_System_Config_Form_Fieldset {
4
+
5
+
6
+ public function getConfig() {
7
+ return Mage::helper('profileolabs_shoppingflux')->getConfig();
8
+ }
9
+
10
+ public function shouldRenderUnregistered() {
11
+ $storeCode = Mage::app()->getRequest()->getParam('store', null);
12
+ $store = Mage::app()->getStore($storeCode);
13
+ $apiKey = $this->getConfig()->getApiKey($store->getId());
14
+ $wsUri = $this->getConfig()->getWsUri($store->getId());
15
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
16
+ return $service->isClient();
17
+ }
18
+
19
+
20
+ public function render(Varien_Data_Form_Element_Abstract $element) {
21
+ if($this->shouldRenderUnregistered()) {
22
+ return parent::render($element);
23
+ }
24
+
25
+ return $this->renderUnregistered($element);
26
+ }
27
+
28
+ public function renderUnregistered(Varien_Data_Form_Element_Abstract $element) {
29
+
30
+ if(Mage::registry('shoppingflux_unregistered_block')) {
31
+ return '';
32
+ }
33
+ $block = Mage::app()->getLayout()->createBlock('adminhtml/template');
34
+ $block->setTemplate('profileolabs/shoppingflux/register.phtml');
35
+
36
+ Mage::register('shoppingflux_unregistered_block', true);
37
+ return $block->toHtml();
38
+ }
39
+
40
+ protected function _getHeaderHtml($element) {
41
+ $html = parent::_getHeaderHtml($element);
42
+ return $html;
43
+ }
44
+
45
+ protected function _getFieldRenderer() {
46
+ if (empty($this->_fieldRenderer)) {
47
+ $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
48
+ }
49
+ return $this->_fieldRenderer;
50
+ }
51
+
52
+ protected function _getDummyElement() {
53
+ if (empty($this->_dummyElement)) {
54
+ $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
55
+ }
56
+ return $this->_dummyElement;
57
+ }
58
+
59
+
60
  }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Catalog/Category/Edit/Form.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Block for category page to assiocate products.
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author Vincent Enjalbert @ Web-cooking.net
8
- */
9
-
10
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Catalog_Category_Edit_Form extends Mage_Adminhtml_Block_Template {
11
-
12
- public function __construct() {
13
- parent::__construct();
14
- $this->setTemplate('profileolabs/shoppingflux/export/category/edit.phtml');
15
- }
16
-
17
- public function getCategory() {
18
- return Mage::registry('category');
19
- }
20
-
21
- public function getProductsJson() {
22
- $products = array();
23
- $collection = Mage::getModel('catalog/product')->getCollection()
24
- ->addAttributeToFilter('shoppingflux_default_category', $this->getCategory()->getId())
25
- ->addStoreFilter($this->getRequest()->getParam('store'));
26
- foreach ($collection as $_product) {
27
- $products[$_product->getId()] = 1;
28
- }
29
- if(!empty($products)) {
30
- $currentVersion = Mage::getVersion();
31
- if (version_compare($currentVersion, '1.4.0') < 0) {
32
- return Zend_Json::encode($products);
33
- }
34
- return Mage::helper('core')->jsonEncode($products);
35
- }
36
- return '{}';
37
- }
38
-
39
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Block for category page to assiocate products.
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author Vincent Enjalbert @ Web-cooking.net
8
+ */
9
+
10
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Catalog_Category_Edit_Form extends Mage_Adminhtml_Block_Template {
11
+
12
+ public function __construct() {
13
+ parent::__construct();
14
+ $this->setTemplate('profileolabs/shoppingflux/export/category/edit.phtml');
15
+ }
16
+
17
+ public function getCategory() {
18
+ return Mage::registry('category');
19
+ }
20
+
21
+ public function getProductsJson() {
22
+ $products = array();
23
+ $collection = Mage::getModel('catalog/product')->getCollection()
24
+ ->addAttributeToFilter('shoppingflux_default_category', $this->getCategory()->getId())
25
+ ->addStoreFilter($this->getRequest()->getParam('store'));
26
+ foreach ($collection as $_product) {
27
+ $products[$_product->getId()] = 1;
28
+ }
29
+ if(!empty($products)) {
30
+ $currentVersion = Mage::getVersion();
31
+ if (version_compare($currentVersion, '1.4.0') < 0) {
32
+ return Zend_Json::encode($products);
33
+ }
34
+ return Mage::helper('core')->jsonEncode($products);
35
+ }
36
+ return '{}';
37
+ }
38
+
39
  }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Catalog/Category/Tab/Default.php CHANGED
@@ -1,192 +1,192 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Block for category page to assiocate products.
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author Vincent Enjalbert @ Web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Catalog_Category_Tab_Default extends Mage_Adminhtml_Block_Widget_Grid {
10
-
11
- public function __construct() {
12
- parent::__construct();
13
- $this->setId('shoppingflux_default_category_products');
14
- $this->setDefaultSort('entity_id');
15
- $this->setUseAjax(true);
16
- }
17
-
18
- public function getCategory()
19
- {
20
- return Mage::registry('category');
21
- }
22
-
23
- protected function _afterToHtml($html) {
24
- $html = parent::_afterToHtml($html);
25
- if($this->getRequest()->getActionName() != 'edit') return $html;
26
- $scriptData = $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_catalog_category_edit_form', 'category.edit.shoppingflux')->toHtml();
27
- //Mage::log($html .
28
- // $scriptData
29
- // .
30
- // '<input type="hidden" name="shoppingflux_category_products" id="shoppingflux_in_category_products" value="" />');
31
- return $html .
32
- $scriptData
33
- .
34
- '<input type="hidden" name="shoppingflux_category_products" id="shoppingflux_in_category_products" value="" />';
35
- }
36
-
37
- protected function _addColumnFilterToCollection($column)
38
- {
39
- // Set custom filter for in category flag
40
- if ($column->getId() == 'in_shoppingflux_category') {
41
- $productIds = $this->_getSelectedProducts();
42
- if (empty($productIds)) {
43
- $productIds = 0;
44
- }
45
- if ($column->getFilter()->getValue()) {
46
- $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
47
- }
48
- elseif(!empty($productIds)) {
49
- $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
50
- }
51
- }
52
- else if ($column->getId() == 'is_in_category') {
53
- $productIds = $this->_getInCategoryProducts();
54
- if (empty($productIds)) {
55
- $productIds = 0;
56
- }
57
- if ($column->getFilter()->getValue()) {
58
- $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
59
- }
60
- elseif(!empty($productIds)) {
61
- $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
62
- }
63
- } else {
64
- parent::_addColumnFilterToCollection($column);
65
- }
66
- return $this;
67
- }
68
-
69
- protected function _getSelectedProducts() {
70
- $products = $this->getRequest()->getPost('sf_selected_products');
71
- if (is_null($products)) {
72
- $products = array();
73
- $collection = Mage::getModel('catalog/product')->getCollection()
74
- ->setStore($this->getRequest()->getParam('store'))
75
- ->setStoreId($this->getRequest()->getParam('store'))
76
- ->addAttributeToFilter('shoppingflux_default_category', $this->getCategory()->getId())
77
- ->addStoreFilter($this->getRequest()->getParam('store'));
78
- foreach($collection as $_product) {
79
- $products[] = $_product->getId();
80
- }
81
- return $products;
82
- }
83
- return $products;
84
- }
85
-
86
- protected function _getInCategoryProducts()
87
- {
88
- $products = $this->getRequest()->getPost('selected_products');
89
- if (is_null($products)) {
90
- $products = $this->getCategory()->getProductsPosition();
91
- return array_keys($products);
92
- }
93
- return $products;
94
- }
95
-
96
- protected function _prepareCollection() {
97
- if ($this->getCategory()->getId()) {
98
- $this->setDefaultFilter(array('in_shoppingflux_category' => 1));
99
- }
100
- $collection = Mage::getModel('catalog/product')->getCollection()
101
- ->setStore($this->getRequest()->getParam('store'))
102
- ->setStoreId($this->getRequest()->getParam('store'))
103
- ->addAttributeToSelect('name')
104
- ->addAttributeToSelect('sku')
105
- ->addAttributeToSelect('price')
106
- //->addAttributeToSelect('shoppingflux_default_category')
107
- ->addExpressionAttributeToSelect('shoppingflux_default_category','IF({{shoppingflux_default_category}}, {{shoppingflux_default_category}}, -1)', 'shoppingflux_default_category')
108
- ->addAttributeToSelect('shoppingflux_product')
109
- ->addStoreFilter($this->getRequest()->getParam('store'));
110
- $this->setCollection($collection);
111
-
112
-
113
- return parent::_prepareCollection();
114
- }
115
-
116
- protected function _prepareColumns() {
117
-
118
-
119
-
120
- $this->addColumn('in_shoppingflux_category', array(
121
- 'header_css_class' => 'a-center',
122
- 'type' => 'checkbox',
123
- 'name' => 'in_shoppingflux_category',
124
- 'values' => $this->_getSelectedProducts(),
125
- 'align' => 'center',
126
- 'index' => 'entity_id'
127
- ));
128
- $this->addColumn('is_in_category', array(
129
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('In category ?'),
130
- 'type' => 'bool',
131
- 'name' => 'is_in_category',
132
- 'values' => $this->_getInCategoryProducts(),
133
- 'align' => 'center',
134
- 'index' => 'entity_id',
135
- 'filter' => 'adminhtml/widget_grid_column_filter_checkbox'
136
- ));
137
-
138
- $this->addColumn('entity_id', array(
139
- 'header' => Mage::helper('catalog')->__('ID'),
140
- 'sortable' => true,
141
- 'width' => '60',
142
- 'index' => 'entity_id'
143
- ));
144
- $this->addColumn('name', array(
145
- 'header' => Mage::helper('catalog')->__('Name'),
146
- 'index' => 'name'
147
- ));
148
- $this->addColumn('sku', array(
149
- 'header' => Mage::helper('catalog')->__('SKU'),
150
- 'width' => '80',
151
- 'index' => 'sku'
152
- ));
153
- $this->addColumn('price', array(
154
- 'header' => Mage::helper('catalog')->__('Price'),
155
- 'type' => 'currency',
156
- 'width' => '1',
157
- 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
158
- 'index' => 'price'
159
- ));
160
-
161
- $optionsCategories = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents('name');
162
- $optionsCategories = array_reverse($optionsCategories, true);
163
- $optionsCategories[-1] = '__';
164
- $optionsCategories = array_reverse($optionsCategories, true);
165
- $this->addColumn('shoppingflux_default_category', array(
166
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('Current default category'),
167
- 'width' => '80',
168
- 'type' => 'options',
169
- 'options' => $optionsCategories,
170
- 'index' => 'shoppingflux_default_category'
171
- ));
172
-
173
- $optionsSf = array(0 => Mage::helper('profileolabs_shoppingflux')->__('No'), 1 => Mage::helper('profileolabs_shoppingflux')->__('Yes'));
174
- $this->addColumn('shoppingflux_product', array(
175
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('Send to Shoppingflux ?'),
176
- 'width' => '80',
177
- 'index' => 'shoppingflux_product',
178
- 'type' => 'options',
179
- 'options' => $optionsSf
180
- ));
181
- return parent::_prepareColumns();
182
- }
183
-
184
- public function getGridUrl() {
185
- return $this->getUrl('adminhtml/shoppingfeed_export_category/grid', array('_current' => true));
186
- }
187
-
188
- public function getColumnRenderers() {
189
- return array('bool'=>'profileolabs_shoppingflux/export_adminhtml_widget_grid_column_renderer_bool');
190
- }
191
-
192
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Block for category page to assiocate products.
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author Vincent Enjalbert @ Web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Catalog_Category_Tab_Default extends Mage_Adminhtml_Block_Widget_Grid {
10
+
11
+ public function __construct() {
12
+ parent::__construct();
13
+ $this->setId('shoppingflux_default_category_products');
14
+ $this->setDefaultSort('entity_id');
15
+ $this->setUseAjax(true);
16
+ }
17
+
18
+ public function getCategory()
19
+ {
20
+ return Mage::registry('category');
21
+ }
22
+
23
+ protected function _afterToHtml($html) {
24
+ $html = parent::_afterToHtml($html);
25
+ if($this->getRequest()->getActionName() != 'edit') return $html;
26
+ $scriptData = $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_catalog_category_edit_form', 'category.edit.shoppingflux')->toHtml();
27
+ //Mage::log($html .
28
+ // $scriptData
29
+ // .
30
+ // '<input type="hidden" name="shoppingflux_category_products" id="shoppingflux_in_category_products" value="" />');
31
+ return $html .
32
+ $scriptData
33
+ .
34
+ '<input type="hidden" name="shoppingflux_category_products" id="shoppingflux_in_category_products" value="" />';
35
+ }
36
+
37
+ protected function _addColumnFilterToCollection($column)
38
+ {
39
+ // Set custom filter for in category flag
40
+ if ($column->getId() == 'in_shoppingflux_category') {
41
+ $productIds = $this->_getSelectedProducts();
42
+ if (empty($productIds)) {
43
+ $productIds = 0;
44
+ }
45
+ if ($column->getFilter()->getValue()) {
46
+ $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
47
+ }
48
+ elseif(!empty($productIds)) {
49
+ $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
50
+ }
51
+ }
52
+ else if ($column->getId() == 'is_in_category') {
53
+ $productIds = $this->_getInCategoryProducts();
54
+ if (empty($productIds)) {
55
+ $productIds = 0;
56
+ }
57
+ if ($column->getFilter()->getValue()) {
58
+ $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
59
+ }
60
+ elseif(!empty($productIds)) {
61
+ $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
62
+ }
63
+ } else {
64
+ parent::_addColumnFilterToCollection($column);
65
+ }
66
+ return $this;
67
+ }
68
+
69
+ protected function _getSelectedProducts() {
70
+ $products = $this->getRequest()->getPost('sf_selected_products');
71
+ if (is_null($products)) {
72
+ $products = array();
73
+ $collection = Mage::getModel('catalog/product')->getCollection()
74
+ ->setStore($this->getRequest()->getParam('store'))
75
+ ->setStoreId($this->getRequest()->getParam('store'))
76
+ ->addAttributeToFilter('shoppingflux_default_category', $this->getCategory()->getId())
77
+ ->addStoreFilter($this->getRequest()->getParam('store'));
78
+ foreach($collection as $_product) {
79
+ $products[] = $_product->getId();
80
+ }
81
+ return $products;
82
+ }
83
+ return $products;
84
+ }
85
+
86
+ protected function _getInCategoryProducts()
87
+ {
88
+ $products = $this->getRequest()->getPost('selected_products');
89
+ if (is_null($products)) {
90
+ $products = $this->getCategory()->getProductsPosition();
91
+ return array_keys($products);
92
+ }
93
+ return $products;
94
+ }
95
+
96
+ protected function _prepareCollection() {
97
+ if ($this->getCategory()->getId()) {
98
+ $this->setDefaultFilter(array('in_shoppingflux_category' => 1));
99
+ }
100
+ $collection = Mage::getModel('catalog/product')->getCollection()
101
+ ->setStore($this->getRequest()->getParam('store'))
102
+ ->setStoreId($this->getRequest()->getParam('store'))
103
+ ->addAttributeToSelect('name')
104
+ ->addAttributeToSelect('sku')
105
+ ->addAttributeToSelect('price')
106
+ //->addAttributeToSelect('shoppingflux_default_category')
107
+ ->addExpressionAttributeToSelect('shoppingflux_default_category','IF({{shoppingflux_default_category}}, {{shoppingflux_default_category}}, -1)', 'shoppingflux_default_category')
108
+ ->addAttributeToSelect('shoppingflux_product')
109
+ ->addStoreFilter($this->getRequest()->getParam('store'));
110
+ $this->setCollection($collection);
111
+
112
+
113
+ return parent::_prepareCollection();
114
+ }
115
+
116
+ protected function _prepareColumns() {
117
+
118
+
119
+
120
+ $this->addColumn('in_shoppingflux_category', array(
121
+ 'header_css_class' => 'a-center',
122
+ 'type' => 'checkbox',
123
+ 'name' => 'in_shoppingflux_category',
124
+ 'values' => $this->_getSelectedProducts(),
125
+ 'align' => 'center',
126
+ 'index' => 'entity_id'
127
+ ));
128
+ $this->addColumn('is_in_category', array(
129
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('In category ?'),
130
+ 'type' => 'bool',
131
+ 'name' => 'is_in_category',
132
+ 'values' => $this->_getInCategoryProducts(),
133
+ 'align' => 'center',
134
+ 'index' => 'entity_id',
135
+ 'filter' => 'adminhtml/widget_grid_column_filter_checkbox'
136
+ ));
137
+
138
+ $this->addColumn('entity_id', array(
139
+ 'header' => Mage::helper('catalog')->__('ID'),
140
+ 'sortable' => true,
141
+ 'width' => '60',
142
+ 'index' => 'entity_id'
143
+ ));
144
+ $this->addColumn('name', array(
145
+ 'header' => Mage::helper('catalog')->__('Name'),
146
+ 'index' => 'name'
147
+ ));
148
+ $this->addColumn('sku', array(
149
+ 'header' => Mage::helper('catalog')->__('SKU'),
150
+ 'width' => '80',
151
+ 'index' => 'sku'
152
+ ));
153
+ $this->addColumn('price', array(
154
+ 'header' => Mage::helper('catalog')->__('Price'),
155
+ 'type' => 'currency',
156
+ 'width' => '1',
157
+ 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
158
+ 'index' => 'price'
159
+ ));
160
+
161
+ $optionsCategories = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents('name');
162
+ $optionsCategories = array_reverse($optionsCategories, true);
163
+ $optionsCategories[-1] = '__';
164
+ $optionsCategories = array_reverse($optionsCategories, true);
165
+ $this->addColumn('shoppingflux_default_category', array(
166
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('Current default category'),
167
+ 'width' => '80',
168
+ 'type' => 'options',
169
+ 'options' => $optionsCategories,
170
+ 'index' => 'shoppingflux_default_category'
171
+ ));
172
+
173
+ $optionsSf = array(0 => Mage::helper('profileolabs_shoppingflux')->__('No'), 1 => Mage::helper('profileolabs_shoppingflux')->__('Yes'));
174
+ $this->addColumn('shoppingflux_product', array(
175
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('Send to Shoppingflux ?'),
176
+ 'width' => '80',
177
+ 'index' => 'shoppingflux_product',
178
+ 'type' => 'options',
179
+ 'options' => $optionsSf
180
+ ));
181
+ return parent::_prepareColumns();
182
+ }
183
+
184
+ public function getGridUrl() {
185
+ return $this->getUrl('adminhtml/shoppingfeed_export_category/grid', array('_current' => true));
186
+ }
187
+
188
+ public function getColumnRenderers() {
189
+ return array('bool'=>'profileolabs_shoppingflux/export_adminhtml_widget_grid_column_renderer_bool');
190
+ }
191
+
192
  }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Feed.php CHANGED
@@ -1,27 +1,27 @@
1
- <?php
2
- /**
3
- * Shoppingflux select products block
4
- *
5
- * @category Profileolabs
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait kassim@profileo.com
8
- */
9
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Feed extends Mage_Adminhtml_Block_Widget_Container
10
- {
11
- /**
12
- * Set template
13
- */
14
- public function __construct()
15
- {
16
- parent::__construct();
17
- $this->setTemplate('profileolabs/shoppingflux/export/feed.phtml');
18
- }
19
-
20
- public function getFeedUrl($store) {
21
- return Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store);
22
- }
23
-
24
- public function storeHasFeed($store) {
25
- return Mage::getSingleton('profileolabs_shoppingflux/config')->isExportEnabled($store->getId());
26
- }
27
- }
1
+ <?php
2
+ /**
3
+ * Shoppingflux select products block
4
+ *
5
+ * @category Profileolabs
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait kassim@profileo.com
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Feed extends Mage_Adminhtml_Block_Widget_Container
10
+ {
11
+ /**
12
+ * Set template
13
+ */
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ $this->setTemplate('profileolabs/shoppingflux/export/feed.phtml');
18
+ }
19
+
20
+ public function getFeedUrl($store) {
21
+ return Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store);
22
+ }
23
+
24
+ public function storeHasFeed($store) {
25
+ return Mage::getSingleton('profileolabs_shoppingflux/config')->isExportEnabled($store->getId());
26
+ }
27
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Process.php CHANGED
@@ -1,150 +1,150 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_ShoppingFlux
5
- * @author kassim belghait
6
- * @deprecated deprecated since 0.1.1
7
- */
8
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Process extends Mage_Adminhtml_Block_Abstract
9
- {
10
-
11
- /**
12
- * Flag for flow model
13
- * @var boolean
14
- */
15
- protected $_flowModelPrepared = false;
16
- /**
17
- * flow model instance
18
- * @var Profileolabs_Shoppingflux_Model_Export_Flow
19
- */
20
- protected $_flowModel = null;
21
-
22
- public function _getFlowModel()
23
- {
24
- return $this->_flowModel;
25
- }
26
-
27
- /**
28
- * Return batch model and initialize it if need
29
- * @return Profileolabs_Shoppingflux_Model_Export_Flow
30
- */
31
- public function getFlowModel()
32
- {
33
- return $this->_prepareFlowModel()
34
- ->_getFlowModel();
35
- }
36
-
37
- /**
38
- * Preparing flow model (initialization)
39
- * @return Profileolabs_Shoppingflux_Block_Export_Adminhtml_Process
40
- */
41
- protected function _prepareFlowModel()
42
- {
43
- if ($this->_flowModelPrepared) {
44
- return $this;
45
- }
46
- $this->setShowFinished(true);
47
- /* @var $this->_flowModel Profileolabs_Shoppingflux_Model_Export_Flow */
48
-
49
- $this->_flowModel = Mage::getSingleton('profileolabs_shoppingflux/export_flow')->reset();;
50
- $storeId = $this->getRequest()->getParam('store',0);
51
- $this->_flowModel->setStoreId($storeId);
52
- $flowItemsCount = $this->_flowModel->getProductCollection()->getSize();
53
-
54
-
55
-
56
- $this->_flowModel->setException(Mage::helper("profileolabs_shoppingflux")->__("%d products found.(in stock + out of stock)",$flowItemsCount));
57
- $soldOutTxt = "";
58
- if(!$this->_flowModel->getConfig()->isExportSoldout())
59
- {
60
- $soldOutTxt = Mage::helper('profileolabs_shoppingflux')->__('Only instock products will be exported');
61
- $this->_flowModel->setException($soldOutTxt);
62
- }
63
-
64
- $numberOfRecords = $this->_flowModel->getCollectionByOffset(1)->count();
65
- $this->setNumberOfRecords($numberOfRecords);
66
- $this->setShowFinished(false);
67
- $offsets = ceil((int)$flowItemsCount/ $this->_flowModel->getLimit());
68
- if($offsets == 0)
69
- $offsets =1;
70
-
71
- $this->_flowModel->setException(Mage::helper("profileolabs_shoppingflux")->__("Generation will be done in %d part(s) of %d product(s)",$offsets,$this->_flowModel->getLimit()));
72
-
73
- $this->setFlowItemsCount( $flowItemsCount);
74
- $this->setFlowConfig(
75
- array(
76
- 'styles' => array(
77
- 'error' => array(
78
- 'icon' => Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif'),
79
- 'bg' => '#FDD'
80
- ),
81
- 'message' => array(
82
- 'icon' => Mage::getDesign()->getSkinUrl('images/fam_bullet_success.gif'),
83
- 'bg' => '#DDF'
84
- ),
85
- 'loader' => Mage::getDesign()->getSkinUrl('images/ajax-loader.gif')
86
- ),
87
- 'template' => '<li style="#{style}" id="#{id}">'
88
- . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
89
- . '<span id="#{id}_status" class="text">#{text}</span>'
90
- . '</li>',
91
- 'text' => $this->__('Step <strong>%s/%s. %s/%s</strong> product(s)','#{offset}', $offsets, '#{updated}', '#{savedRows}'),
92
- 'successText' => $this->__('<strong>%s</strong> exported products.', '#{updated}')
93
- )
94
- );
95
-
96
- $importData = array();
97
-
98
- for($i=1;$i<=$offsets;$i++)
99
- {
100
- $nbProducts = $this->_flowModel->getLimit();
101
- if($i==$offsets)
102
- $nbProducts = $this->_flowModel->getCollectionByOffset($i)->count();
103
-
104
- $importData[] = array("offset"=>$i,"nbProducts"=>$nbProducts,"store"=>$this->getRequest()->getParam('store'));
105
- }
106
-
107
- $this->setImportData($importData);
108
-
109
- $this->_flowModelPrepared = true;
110
- return $this;
111
- }
112
-
113
- public function getExceptions()
114
- {
115
- return $this->getFlowModel()->getExceptions();
116
- }
117
-
118
-
119
-
120
- /**
121
- * Generating form key
122
- * @return string
123
- */
124
- public function getFormKey()
125
- {
126
- return Mage::getSingleton('core/session')->getFormKey();
127
- }
128
-
129
- /**
130
- * Return a flow model config JSON
131
- * @return string
132
- */
133
- public function getFlowConfigJson()
134
- {
135
- return Zend_Json::encode(
136
- $this->getflowConfig()
137
- );
138
- }
139
-
140
- /**
141
- * Encoding to JSON
142
- * @param string $source
143
- * @return string JSON
144
- */
145
- public function jsonEncode($source)
146
- {
147
- return Zend_Json::encode($source);
148
- }
149
-
150
  }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_ShoppingFlux
5
+ * @author kassim belghait
6
+ * @deprecated deprecated since 0.1.1
7
+ */
8
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Process extends Mage_Adminhtml_Block_Abstract
9
+ {
10
+
11
+ /**
12
+ * Flag for flow model
13
+ * @var boolean
14
+ */
15
+ protected $_flowModelPrepared = false;
16
+ /**
17
+ * flow model instance
18
+ * @var Profileolabs_Shoppingflux_Model_Export_Flow
19
+ */
20
+ protected $_flowModel = null;
21
+
22
+ public function _getFlowModel()
23
+ {
24
+ return $this->_flowModel;
25
+ }
26
+
27
+ /**
28
+ * Return batch model and initialize it if need
29
+ * @return Profileolabs_Shoppingflux_Model_Export_Flow
30
+ */
31
+ public function getFlowModel()
32
+ {
33
+ return $this->_prepareFlowModel()
34
+ ->_getFlowModel();
35
+ }
36
+
37
+ /**
38
+ * Preparing flow model (initialization)
39
+ * @return Profileolabs_Shoppingflux_Block_Export_Adminhtml_Process
40
+ */
41
+ protected function _prepareFlowModel()
42
+ {
43
+ if ($this->_flowModelPrepared) {
44
+ return $this;
45
+ }
46
+ $this->setShowFinished(true);
47
+ /* @var $this->_flowModel Profileolabs_Shoppingflux_Model_Export_Flow */
48
+
49
+ $this->_flowModel = Mage::getSingleton('profileolabs_shoppingflux/export_flow')->reset();;
50
+ $storeId = $this->getRequest()->getParam('store',0);
51
+ $this->_flowModel->setStoreId($storeId);
52
+ $flowItemsCount = $this->_flowModel->getProductCollection()->getSize();
53
+
54
+
55
+
56
+ $this->_flowModel->setException(Mage::helper("profileolabs_shoppingflux")->__("%d products found.(in stock + out of stock)",$flowItemsCount));
57
+ $soldOutTxt = "";
58
+ if(!$this->_flowModel->getConfig()->isExportSoldout())
59
+ {
60
+ $soldOutTxt = Mage::helper('profileolabs_shoppingflux')->__('Only instock products will be exported');
61
+ $this->_flowModel->setException($soldOutTxt);
62
+ }
63
+
64
+ $numberOfRecords = $this->_flowModel->getCollectionByOffset(1)->count();
65
+ $this->setNumberOfRecords($numberOfRecords);
66
+ $this->setShowFinished(false);
67
+ $offsets = ceil((int)$flowItemsCount/ $this->_flowModel->getLimit());
68
+ if($offsets == 0)
69
+ $offsets =1;
70
+
71
+ $this->_flowModel->setException(Mage::helper("profileolabs_shoppingflux")->__("Generation will be done in %d part(s) of %d product(s)",$offsets,$this->_flowModel->getLimit()));
72
+
73
+ $this->setFlowItemsCount( $flowItemsCount);
74
+ $this->setFlowConfig(
75
+ array(
76
+ 'styles' => array(
77
+ 'error' => array(
78
+ 'icon' => Mage::getDesign()->getSkinUrl('images/error_msg_icon.gif'),
79
+ 'bg' => '#FDD'
80
+ ),
81
+ 'message' => array(
82
+ 'icon' => Mage::getDesign()->getSkinUrl('images/fam_bullet_success.gif'),
83
+ 'bg' => '#DDF'
84
+ ),
85
+ 'loader' => Mage::getDesign()->getSkinUrl('images/ajax-loader.gif')
86
+ ),
87
+ 'template' => '<li style="#{style}" id="#{id}">'
88
+ . '<img id="#{id}_img" src="#{image}" class="v-middle" style="margin-right:5px"/>'
89
+ . '<span id="#{id}_status" class="text">#{text}</span>'
90
+ . '</li>',
91
+ 'text' => $this->__('Step <strong>%s/%s. %s/%s</strong> product(s)','#{offset}', $offsets, '#{updated}', '#{savedRows}'),
92
+ 'successText' => $this->__('<strong>%s</strong> exported products.', '#{updated}')
93
+ )
94
+ );
95
+
96
+ $importData = array();
97
+
98
+ for($i=1;$i<=$offsets;$i++)
99
+ {
100
+ $nbProducts = $this->_flowModel->getLimit();
101
+ if($i==$offsets)
102
+ $nbProducts = $this->_flowModel->getCollectionByOffset($i)->count();
103
+
104
+ $importData[] = array("offset"=>$i,"nbProducts"=>$nbProducts,"store"=>$this->getRequest()->getParam('store'));
105
+ }
106
+
107
+ $this->setImportData($importData);
108
+
109
+ $this->_flowModelPrepared = true;
110
+ return $this;
111
+ }
112
+
113
+ public function getExceptions()
114
+ {
115
+ return $this->getFlowModel()->getExceptions();
116
+ }
117
+
118
+
119
+
120
+ /**
121
+ * Generating form key
122
+ * @return string
123
+ */
124
+ public function getFormKey()
125
+ {
126
+ return Mage::getSingleton('core/session')->getFormKey();
127
+ }
128
+
129
+ /**
130
+ * Return a flow model config JSON
131
+ * @return string
132
+ */
133
+ public function getFlowConfigJson()
134
+ {
135
+ return Zend_Json::encode(
136
+ $this->getflowConfig()
137
+ );
138
+ }
139
+
140
+ /**
141
+ * Encoding to JSON
142
+ * @param string $source
143
+ * @return string JSON
144
+ */
145
+ public function jsonEncode($source)
146
+ {
147
+ return Zend_Json::encode($source);
148
+ }
149
+
150
  }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Product.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Shoppingflux select products block
4
- *
5
- * @category Profileolabs
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait kassim@profileo.com
8
- */
9
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_Container
10
- {
11
- /**
12
- * Set template
13
- */
14
- public function __construct()
15
- {
16
- parent::__construct();
17
- $this->setTemplate('profileolabs/shoppingflux/export/product.phtml');
18
- }
19
-
20
- /**
21
- * Prepare button and grid
22
- *
23
- * @return Mage_Adminhtml_Block_Catalog_Product
24
- */
25
- protected function _prepareLayout()
26
- {
27
-
28
- $this->setChild('grid', $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_product_grid', 'product.grid'));
29
- return parent::_prepareLayout();
30
- }
31
-
32
- /**
33
- * Deprecated since 1.3.2
34
- *
35
- * @return string
36
- */
37
- public function getAddNewButtonHtml()
38
- {
39
- return $this->getChildHtml('add_new_button');
40
- }
41
-
42
- /**
43
- * Render grid
44
- *
45
- * @return string
46
- */
47
- public function getGridHtml()
48
- {
49
- return $this->getChildHtml('grid');
50
- }
51
-
52
- /**
53
- * Check whether it is single store mode
54
- *
55
- * @return bool
56
- */
57
- public function isSingleStoreMode()
58
- {
59
- if (!Mage::app()->isSingleStoreMode()) {
60
- return false;
61
- }
62
- return true;
63
- }
64
- }
1
+ <?php
2
+ /**
3
+ * Shoppingflux select products block
4
+ *
5
+ * @category Profileolabs
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait kassim@profileo.com
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Product extends Mage_Adminhtml_Block_Widget_Container
10
+ {
11
+ /**
12
+ * Set template
13
+ */
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ $this->setTemplate('profileolabs/shoppingflux/export/product.phtml');
18
+ }
19
+
20
+ /**
21
+ * Prepare button and grid
22
+ *
23
+ * @return Mage_Adminhtml_Block_Catalog_Product
24
+ */
25
+ protected function _prepareLayout()
26
+ {
27
+
28
+ $this->setChild('grid', $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_product_grid', 'product.grid'));
29
+ return parent::_prepareLayout();
30
+ }
31
+
32
+ /**
33
+ * Deprecated since 1.3.2
34
+ *
35
+ * @return string
36
+ */
37
+ public function getAddNewButtonHtml()
38
+ {
39
+ return $this->getChildHtml('add_new_button');
40
+ }
41
+
42
+ /**
43
+ * Render grid
44
+ *
45
+ * @return string
46
+ */
47
+ public function getGridHtml()
48
+ {
49
+ return $this->getChildHtml('grid');
50
+ }
51
+
52
+ /**
53
+ * Check whether it is single store mode
54
+ *
55
+ * @return bool
56
+ */
57
+ public function isSingleStoreMode()
58
+ {
59
+ if (!Mage::app()->isSingleStoreMode()) {
60
+ return false;
61
+ }
62
+ return true;
63
+ }
64
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Product/Grid.php CHANGED
@@ -1,260 +1,260 @@
1
- <?php
2
-
3
- /**
4
- * Shoppingflux grid products block
5
- *
6
- * @category Profileolabs
7
- * @package Profileolabs_Shoppingflux
8
- * @author kassim belghait kassim@profileo.com
9
- */
10
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
11
- {
12
-
13
- public function __construct()
14
- {
15
- parent::__construct();
16
- $this->setId('productGrid');
17
- $this->setDefaultSort('entity_id');
18
- $this->setDefaultDir('desc');
19
- $this->setSaveParametersInSession(true);
20
- $this->setUseAjax(true);
21
- $this->setVarNameFilter('product_filter');
22
-
23
- }
24
-
25
- protected function _getStore()
26
- {
27
- $storeId = (int) $this->getRequest()->getParam('store', 0);
28
- return Mage::app()->getStore($storeId);
29
- }
30
-
31
- protected function _prepareCollection()
32
- {
33
- $store = $this->_getStore();
34
- $collection = Mage::getModel('profileolabs_shoppingflux/catalog_product_collection')
35
- ->addAttributeToSelect('sku')
36
- ->addAttributeToSelect('name')
37
- ->addAttributeToSelect('attribute_set_id')
38
- ->addAttributeToSelect('type_id')
39
- ->joinField('qty',
40
- 'cataloginventory/stock_item',
41
- 'qty',
42
- 'product_id=entity_id',
43
- '{{table}}.stock_id=1',
44
- 'left');
45
-
46
- if ($store->getId()) {
47
- $collection->setStoreId($store->getId());
48
- $collection->addStoreFilter($store);
49
- $collection->joinAttribute('shoppingflux_product', 'catalog_product/shoppingflux_product', 'entity_id', null, 'inner', $store->getId());
50
- $collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store->getId());
51
- $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId());
52
- $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId());
53
- $collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId());
54
- }
55
- else {
56
- $collection->addAttributeToSelect('price');
57
- $collection->addAttributeToSelect('status');
58
- $collection->addAttributeToSelect('visibility');
59
- $collection->addAttributeToSelect('shoppingflux_product');
60
- }
61
-
62
- $collection->getSelect()->joinLeft(
63
- array('category_product' => $collection->getTable('catalog/category_product')), 'category_product.product_id = e.entity_id', array('categories' => new Zend_Db_Expr('group_concat(category_product.category_id)'))
64
- );
65
-
66
- $collection->groupByAttribute('entity_id');
67
-
68
- $this->setCollection($collection);
69
-
70
- parent::_prepareCollection();
71
- $this->getCollection()->addWebsiteNamesToResult();
72
- return $this;
73
- }
74
-
75
- protected function _afterLoadCollection()
76
- {
77
- foreach($this->getCollection() as $item) {
78
- $item->setCategories(explode(',',$item->getCategories()));
79
- }
80
- }
81
-
82
- protected function _addColumnFilterToCollection($column)
83
- {
84
- if ($this->getCollection()) {
85
- if ($column->getId() == 'websites') {
86
- $this->getCollection()->joinField('websites',
87
- 'catalog/product_website',
88
- 'website_id',
89
- 'product_id=entity_id',
90
- null,
91
- 'left');
92
- }
93
- }
94
- return parent::_addColumnFilterToCollection($column);
95
- }
96
-
97
- protected function _prepareColumns()
98
- {
99
- $this->addColumn('entity_id',
100
- array(
101
- 'header'=> Mage::helper('catalog')->__('ID'),
102
- 'width' => '50px',
103
- 'type' => 'number',
104
- 'index' => 'entity_id',
105
- ));
106
- $this->addColumn('name',
107
- array(
108
- 'header'=> Mage::helper('catalog')->__('Name'),
109
- 'index' => 'name',
110
- ));
111
-
112
- $store = $this->_getStore();
113
- if ($store->getId()) {
114
- $this->addColumn('custom_name',
115
- array(
116
- 'header'=> Mage::helper('profileolabs_shoppingflux')->__('Name In %s', $store->getName()),
117
- 'index' => 'custom_name',
118
- ));
119
- }
120
-
121
- $categories = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents('name', Mage::app()->getRequest()->getParam('store', null));
122
- $this->addColumn('categories',
123
- array(
124
- 'header'=> Mage::helper('catalog')->__('Categories'),
125
- 'index' => 'categories',
126
- 'type' => 'options',
127
- 'options' => $categories,
128
- 'filter_condition_callback' => array($this, '_filterCategoriesCondition')
129
- ));
130
-
131
- $this->addColumn('type',
132
- array(
133
- 'header'=> Mage::helper('catalog')->__('Type'),
134
- 'width' => '60px',
135
- 'index' => 'type_id',
136
- 'type' => 'options',
137
- 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
138
- ));
139
-
140
- $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
141
- ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
142
- ->load()
143
- ->toOptionHash();
144
-
145
- $this->addColumn('set_name',
146
- array(
147
- 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
148
- 'width' => '100px',
149
- 'index' => 'attribute_set_id',
150
- 'type' => 'options',
151
- 'options' => $sets,
152
- ));
153
-
154
- $this->addColumn('sku',
155
- array(
156
- 'header'=> Mage::helper('catalog')->__('SKU'),
157
- 'width' => '80px',
158
- 'index' => 'sku',
159
- ));
160
-
161
- $store = $this->_getStore();
162
- $this->addColumn('price',
163
- array(
164
- 'header'=> Mage::helper('catalog')->__('Price'),
165
- 'type' => 'price',
166
- 'currency_code' => $store->getBaseCurrency()->getCode(),
167
- 'index' => 'price',
168
- ));
169
-
170
- $this->addColumn('qty',
171
- array(
172
- 'header'=> Mage::helper('catalog')->__('Qty'),
173
- 'width' => '100px',
174
- 'type' => 'number',
175
- 'index' => 'qty',
176
- ));
177
-
178
- $this->addColumn('visibility',
179
- array(
180
- 'header'=> Mage::helper('catalog')->__('Visibility'),
181
- 'width' => '70px',
182
- 'index' => 'visibility',
183
- 'type' => 'options',
184
- 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
185
- ));
186
-
187
- $this->addColumn('status',
188
- array(
189
- 'header'=> Mage::helper('catalog')->__('Status'),
190
- 'width' => '70px',
191
- 'index' => 'status',
192
- 'type' => 'options',
193
- 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
194
- ));
195
- $optionsSf = array(0=>Mage::helper('profileolabs_shoppingflux')->__('No'),1=>Mage::helper('profileolabs_shoppingflux')->__('Yes'));
196
- $this->addColumn('shoppingflux_product',
197
- array(
198
- 'header'=> Mage::helper('profileolabs_shoppingflux')->__('Send to Shoppingflux ?'),
199
- 'width' => '70px',
200
- 'index' => 'shoppingflux_product',
201
- 'type' => 'options',
202
- 'options' => $optionsSf,
203
- ));
204
-
205
- if (!Mage::app()->isSingleStoreMode()) {
206
- $this->addColumn('websites',
207
- array(
208
- 'header'=> Mage::helper('catalog')->__('Websites'),
209
- 'width' => '100px',
210
- 'sortable' => false,
211
- 'index' => 'websites',
212
- 'type' => 'options',
213
- 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
214
- ));
215
- }
216
-
217
- return parent::_prepareColumns();
218
- }
219
-
220
- protected function _prepareMassaction()
221
- {
222
- $this->setMassactionIdField('entity_id');
223
- $this->getMassactionBlock()->setFormFieldName('product');
224
-
225
- $optionsSf = array(0=>"Non",1=>"Oui");
226
- $this->getMassactionBlock()->addItem('publish', array(
227
- 'label'=> Mage::helper('profileolabs_shoppingflux')->__('Change publication'),
228
- 'url' => $this->getUrl('*/*/massPublish', array('_current'=>true)),
229
- 'additional' => array(
230
- 'visibility' => array(
231
- 'name' => 'publish',
232
- 'type' => 'select',
233
- 'class' => 'required-entry',
234
- 'label' => Mage::helper('profileolabs_shoppingflux')->__('Publication'),
235
- 'values' => $optionsSf
236
- )
237
- )
238
- ));
239
-
240
- return $this;
241
- }
242
-
243
- public function getGridUrl()
244
- {
245
- return $this->getUrl('*/*/grid', array('_current'=>true));
246
- }
247
-
248
- public function getRowUrl($row)
249
- {
250
- return '';
251
- }
252
-
253
- protected function _filterCategoriesCondition($collection, $column) {
254
- if (!$value = $column->getFilter()->getValue()) {
255
- return;
256
- }
257
-
258
- $this->getCollection()->getSelect()->where('category_product.category_id = ?', $value);
259
- }
260
- }
1
+ <?php
2
+
3
+ /**
4
+ * Shoppingflux grid products block
5
+ *
6
+ * @category Profileolabs
7
+ * @package Profileolabs_Shoppingflux
8
+ * @author kassim belghait kassim@profileo.com
9
+ */
10
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid
11
+ {
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ $this->setId('productGrid');
17
+ $this->setDefaultSort('entity_id');
18
+ $this->setDefaultDir('desc');
19
+ $this->setSaveParametersInSession(true);
20
+ $this->setUseAjax(true);
21
+ $this->setVarNameFilter('product_filter');
22
+
23
+ }
24
+
25
+ protected function _getStore()
26
+ {
27
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
28
+ return Mage::app()->getStore($storeId);
29
+ }
30
+
31
+ protected function _prepareCollection()
32
+ {
33
+ $store = $this->_getStore();
34
+ $collection = Mage::getModel('profileolabs_shoppingflux/catalog_product_collection')
35
+ ->addAttributeToSelect('sku')
36
+ ->addAttributeToSelect('name')
37
+ ->addAttributeToSelect('attribute_set_id')
38
+ ->addAttributeToSelect('type_id')
39
+ ->joinField('qty',
40
+ 'cataloginventory/stock_item',
41
+ 'qty',
42
+ 'product_id=entity_id',
43
+ '{{table}}.stock_id=1',
44
+ 'left');
45
+
46
+ if ($store->getId()) {
47
+ $collection->setStoreId($store->getId());
48
+ $collection->addStoreFilter($store);
49
+ $collection->joinAttribute('shoppingflux_product', 'catalog_product/shoppingflux_product', 'entity_id', null, 'left', $store->getId());
50
+ $collection->joinAttribute('custom_name', 'catalog_product/name', 'entity_id', null, 'inner', $store->getId());
51
+ $collection->joinAttribute('status', 'catalog_product/status', 'entity_id', null, 'inner', $store->getId());
52
+ $collection->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $store->getId());
53
+ $collection->joinAttribute('price', 'catalog_product/price', 'entity_id', null, 'left', $store->getId());
54
+ }
55
+ else {
56
+ $collection->addAttributeToSelect('price');
57
+ $collection->addAttributeToSelect('status');
58
+ $collection->addAttributeToSelect('visibility');
59
+ $collection->addAttributeToSelect('shoppingflux_product');
60
+ }
61
+
62
+ $collection->getSelect()->joinLeft(
63
+ array('category_product' => $collection->getTable('catalog/category_product')), 'category_product.product_id = e.entity_id', array('categories' => new Zend_Db_Expr('group_concat(category_product.category_id)'))
64
+ );
65
+
66
+ $collection->groupByAttribute('entity_id');
67
+
68
+ $this->setCollection($collection);
69
+
70
+ parent::_prepareCollection();
71
+ $this->getCollection()->addWebsiteNamesToResult();
72
+ return $this;
73
+ }
74
+
75
+ protected function _afterLoadCollection()
76
+ {
77
+ foreach($this->getCollection() as $item) {
78
+ $item->setCategories(explode(',',$item->getCategories()));
79
+ }
80
+ }
81
+
82
+ protected function _addColumnFilterToCollection($column)
83
+ {
84
+ if ($this->getCollection()) {
85
+ if ($column->getId() == 'websites') {
86
+ $this->getCollection()->joinField('websites',
87
+ 'catalog/product_website',
88
+ 'website_id',
89
+ 'product_id=entity_id',
90
+ null,
91
+ 'left');
92
+ }
93
+ }
94
+ return parent::_addColumnFilterToCollection($column);
95
+ }
96
+
97
+ protected function _prepareColumns()
98
+ {
99
+ $this->addColumn('entity_id',
100
+ array(
101
+ 'header'=> Mage::helper('catalog')->__('ID'),
102
+ 'width' => '50px',
103
+ 'type' => 'number',
104
+ 'index' => 'entity_id',
105
+ ));
106
+ $this->addColumn('name',
107
+ array(
108
+ 'header'=> Mage::helper('catalog')->__('Name'),
109
+ 'index' => 'name',
110
+ ));
111
+
112
+ $store = $this->_getStore();
113
+ if ($store->getId()) {
114
+ $this->addColumn('custom_name',
115
+ array(
116
+ 'header'=> Mage::helper('profileolabs_shoppingflux')->__('Name In %s', $store->getName()),
117
+ 'index' => 'custom_name',
118
+ ));
119
+ }
120
+
121
+ $categories = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents('name', Mage::app()->getRequest()->getParam('store', null));
122
+ $this->addColumn('categories',
123
+ array(
124
+ 'header'=> Mage::helper('catalog')->__('Categories'),
125
+ 'index' => 'categories',
126
+ 'type' => 'options',
127
+ 'options' => $categories,
128
+ 'filter_condition_callback' => array($this, '_filterCategoriesCondition')
129
+ ));
130
+
131
+ $this->addColumn('type',
132
+ array(
133
+ 'header'=> Mage::helper('catalog')->__('Type'),
134
+ 'width' => '60px',
135
+ 'index' => 'type_id',
136
+ 'type' => 'options',
137
+ 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
138
+ ));
139
+
140
+ $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
141
+ ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
142
+ ->load()
143
+ ->toOptionHash();
144
+
145
+ $this->addColumn('set_name',
146
+ array(
147
+ 'header'=> Mage::helper('catalog')->__('Attrib. Set Name'),
148
+ 'width' => '100px',
149
+ 'index' => 'attribute_set_id',
150
+ 'type' => 'options',
151
+ 'options' => $sets,
152
+ ));
153
+
154
+ $this->addColumn('sku',
155
+ array(
156
+ 'header'=> Mage::helper('catalog')->__('SKU'),
157
+ 'width' => '80px',
158
+ 'index' => 'sku',
159
+ ));
160
+
161
+ $store = $this->_getStore();
162
+ $this->addColumn('price',
163
+ array(
164
+ 'header'=> Mage::helper('catalog')->__('Price'),
165
+ 'type' => 'price',
166
+ 'currency_code' => $store->getBaseCurrency()->getCode(),
167
+ 'index' => 'price',
168
+ ));
169
+
170
+ $this->addColumn('qty',
171
+ array(
172
+ 'header'=> Mage::helper('catalog')->__('Qty'),
173
+ 'width' => '100px',
174
+ 'type' => 'number',
175
+ 'index' => 'qty',
176
+ ));
177
+
178
+ $this->addColumn('visibility',
179
+ array(
180
+ 'header'=> Mage::helper('catalog')->__('Visibility'),
181
+ 'width' => '70px',
182
+ 'index' => 'visibility',
183
+ 'type' => 'options',
184
+ 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
185
+ ));
186
+
187
+ $this->addColumn('status',
188
+ array(
189
+ 'header'=> Mage::helper('catalog')->__('Status'),
190
+ 'width' => '70px',
191
+ 'index' => 'status',
192
+ 'type' => 'options',
193
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
194
+ ));
195
+ $optionsSf = array(0=>Mage::helper('profileolabs_shoppingflux')->__('No'),1=>Mage::helper('profileolabs_shoppingflux')->__('Yes'));
196
+ $this->addColumn('shoppingflux_product',
197
+ array(
198
+ 'header'=> Mage::helper('profileolabs_shoppingflux')->__('Send to Shoppingflux ?'),
199
+ 'width' => '70px',
200
+ 'index' => 'shoppingflux_product',
201
+ 'type' => 'options',
202
+ 'options' => $optionsSf,
203
+ ));
204
+
205
+ if (!Mage::app()->isSingleStoreMode()) {
206
+ $this->addColumn('websites',
207
+ array(
208
+ 'header'=> Mage::helper('catalog')->__('Websites'),
209
+ 'width' => '100px',
210
+ 'sortable' => false,
211
+ 'index' => 'websites',
212
+ 'type' => 'options',
213
+ 'options' => Mage::getModel('core/website')->getCollection()->toOptionHash(),
214
+ ));
215
+ }
216
+
217
+ return parent::_prepareColumns();
218
+ }
219
+
220
+ protected function _prepareMassaction()
221
+ {
222
+ $this->setMassactionIdField('entity_id');
223
+ $this->getMassactionBlock()->setFormFieldName('product');
224
+
225
+ $optionsSf = array(0=>"Non",1=>"Oui");
226
+ $this->getMassactionBlock()->addItem('publish', array(
227
+ 'label'=> Mage::helper('profileolabs_shoppingflux')->__('Change publication'),
228
+ 'url' => $this->getUrl('*/*/massPublish', array('_current'=>true)),
229
+ 'additional' => array(
230
+ 'visibility' => array(
231
+ 'name' => 'publish',
232
+ 'type' => 'select',
233
+ 'class' => 'required-entry',
234
+ 'label' => Mage::helper('profileolabs_shoppingflux')->__('Publication'),
235
+ 'values' => $optionsSf
236
+ )
237
+ )
238
+ ));
239
+
240
+ return $this;
241
+ }
242
+
243
+ public function getGridUrl()
244
+ {
245
+ return $this->getUrl('*/*/grid', array('_current'=>true));
246
+ }
247
+
248
+ public function getRowUrl($row)
249
+ {
250
+ return '';
251
+ }
252
+
253
+ protected function _filterCategoriesCondition($collection, $column) {
254
+ if (!$value = $column->getFilter()->getValue()) {
255
+ return;
256
+ }
257
+
258
+ $this->getCollection()->getSelect()->where('category_product.category_id = ?', $value);
259
+ }
260
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Adminhtml/Widget/Grid/Column/Renderer/Bool.php CHANGED
@@ -1,33 +1,33 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Block for category page to assiocate products.
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author Vincent Enjalbert @ Web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Widget_Grid_Column_Renderer_Bool
10
- extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
11
- {
12
- protected $_defaultWidth = 55;
13
- /**
14
- * Renders grid column
15
- *
16
- * @param Varien_Object $row
17
- * @return string
18
- */
19
- public function render(Varien_Object $row)
20
- {
21
- $values = $this->getColumn()->getValues();
22
- $value = $row->getData($this->getColumn()->getIndex());
23
- if (is_array($values)) {
24
- $checked = in_array($value, $values);
25
- }
26
- else {
27
- $checked = ($value === $this->getColumn()->getValue());
28
- }
29
-
30
- return $checked?Mage::helper('profileolabs_shoppingflux')->__('Yes'):Mage::helper('profileolabs_shoppingflux')->__('No');
31
- }
32
-
33
- }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Block for category page to assiocate products.
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author Vincent Enjalbert @ Web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Export_Adminhtml_Widget_Grid_Column_Renderer_Bool
10
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
11
+ {
12
+ protected $_defaultWidth = 55;
13
+ /**
14
+ * Renders grid column
15
+ *
16
+ * @param Varien_Object $row
17
+ * @return string
18
+ */
19
+ public function render(Varien_Object $row)
20
+ {
21
+ $values = $this->getColumn()->getValues();
22
+ $value = $row->getData($this->getColumn()->getIndex());
23
+ if (is_array($values)) {
24
+ $checked = in_array($value, $values);
25
+ }
26
+ else {
27
+ $checked = ($value === $this->getColumn()->getValue());
28
+ }
29
+
30
+ return $checked?Mage::helper('profileolabs_shoppingflux')->__('Yes'):Mage::helper('profileolabs_shoppingflux')->__('No');
31
+ }
32
+
33
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Flow.php CHANGED
@@ -1,985 +1,985 @@
1
- <?php
2
- // V1 DEPRECATED
3
- /**
4
- * @deprecated
5
- */
6
- class Profileolabs_Shoppingflux_Block_Export_Flow extends Mage_Core_Block_Template {
7
-
8
- protected $_attributes = null;
9
- protected $_attributesConfigurable = array();
10
- protected $_attributesOptions = array();
11
- protected $_fileName = "flow2.xml";
12
- protected $_storeCategories = array();
13
-
14
- public function __construct() {
15
- $this->forceStore();
16
- }
17
-
18
- protected function _getStoreId() {
19
- //store id is store view id
20
-
21
- return $this->_getStore()->getId();
22
- ;
23
- }
24
-
25
- protected function _getStore() {
26
-
27
- $storeId = (int) $this->getRequest()->getParam('store', Mage::app()->getStore()->getId());
28
- return Mage::app()->getStore($storeId);
29
- }
30
-
31
- protected function forceStore() {
32
- if (( $storeId = (int) $this->getRequest()->getParam('store', 0) ) != 0) {
33
- Mage::app()->setCurrentStore(Mage::app()->getStore($storeId));
34
- }
35
- }
36
-
37
- protected function _writeXml($xml, $start = false) {
38
- $mode = "a+";
39
- if ($start)
40
- $mode = "w+";
41
- $storeId = $this->_getStoreId();
42
- $storeCode = Mage::app()->getStore($storeId)->getCode();
43
- $dir = Mage::getBaseDir('media') . DS . "shoppingflux" . DS . $storeCode . DS;
44
- $file = new Varien_Io_File;
45
- $file->checkAndCreateFolder($dir);
46
- $file->cd($dir);
47
- $file->streamOpen($this->_fileName, $mode);
48
- $file->streamLock();
49
- $file->streamWrite($xml);
50
- $file->streamUnlock();
51
- $file->streamClose();
52
-
53
- if ($file->fileExists($this->_fileName)) {
54
- return $this->_fileName;
55
- }
56
-
57
- return false;
58
- }
59
-
60
- protected $_exludeProductIds = null;
61
-
62
- protected function _getExcludeProductIds($store = null) {
63
- Varien_Profiler::start("SF::Flow::_getExcludeProductIds");
64
- if (is_null($this->_exludeProductIds)) {
65
- $mageCacheKey = 'sf_exclude_pids';
66
- $fromCache = Mage::app()->loadCache($mageCacheKey);
67
- if ($fromCache) {
68
- $this->_exludeProductIds = unserialize($fromCache);
69
- } else {
70
-
71
- $this->_exludeProductIds = array();
72
- $collection = Mage::getModel('catalog/product')
73
- ->getCollection()
74
- ->addFieldToFilter('type_id', array('neq' => 'simple'));
75
- if ($store) {
76
- $collection->setStore($store)
77
- ->addStoreFilter($store);
78
- }
79
-
80
- $product = Mage::getModel('catalog/product');
81
- Mage::getSingleton('core/resource_iterator')
82
- ->walk($collection->getSelect(), array(array($this, '_excludeProductIds')), array('product' => $product));
83
- Mage::app()->saveCache(serialize($this->_exludeProductIds), $mageCacheKey, array('shoppingflux', Mage_Catalog_Model_Product::CACHE_TAG));
84
- }
85
- }
86
-
87
- Varien_Profiler::stop("SF::Flow::_getExcludeProductIds");
88
- return $this->_exludeProductIds;
89
- }
90
-
91
- public function _excludeProductIds($args) {
92
- $product = $args['product'];
93
- $product->reset()->setTypeInstance(null, true);
94
- $product->setData($args['row']);
95
-
96
- if ($product->getTypeId() == 'configurable') {
97
- $childrenIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getChildrenIds($product->getEntityId());
98
- if ($childrenIds && is_array($childrenIds) && !empty($childrenIds))
99
- $this->_exludeProductIds = array_merge($this->_exludeProductIds, $childrenIds[0]);
100
- }
101
- if ($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle' || $product->getTypeId() == 'virtual') {
102
- $this->_exludeProductIds = array_merge($this->_exludeProductIds, array($product->getEntityId()));
103
- }
104
- //sometimes magento return empty id, so we filter the array
105
- $this->_exludeProductIds = array_filter($this->_exludeProductIds);
106
- }
107
-
108
- protected function _toHtml() {
109
- Varien_Profiler::start("SF::Flow::toHtml");
110
- ini_set("memory_limit", $this->getConfig()->getMemoryLimit() . "M");
111
- $storeId = $this->_getStoreId();
112
-
113
- /*
114
- oringinal price - getPrice() - inputed in admin
115
- special price - getSpecialPrice()
116
- getFinalPrice() - used in shopping cart calculations
117
- */
118
- $product = Mage::getModel('catalog/product');
119
-
120
- $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/price', $this->_getStoreId());
121
- $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/special_price', $this->_getStoreId());
122
-
123
-
124
- $otherAttributes = array(
125
- "shoppingflux_product" => "shoppingflux_product",
126
- "shoppingflux_default_category" => "shoppingflux_default_category",
127
- "tax_class_id" => "tax_class_id",
128
- "special_price" => "special_price",
129
- "minimal_price" => "minimal_price",
130
- "special_from_date" => "special_from_date",
131
- "special_to_date" => "special_to_date",
132
- "image" => "image",
133
- $priceAttributeCode => $priceAttributeCode,
134
- $specialPriceAttributeCode => $specialPriceAttributeCode
135
- );
136
- $attributesToSelect = array_merge($this->getAttributesFromConfig(true), $otherAttributes);
137
-
138
-
139
- $stockItemWhere = null;
140
- if (!$this->getConfig()->isExportSoldout()) {
141
-
142
- $_configManageStock = (int) Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
143
- $stockItemWhere = "({{table}}.is_in_stock = 1) "
144
- . " OR IF({{table}}.use_config_manage_stock=1," . $_configManageStock . ",{{table}}.manage_stock)=0";
145
- }
146
-
147
-
148
- $products = $product->getCollection()
149
- ->addStoreFilter($storeId)
150
- // ->addAttributeToFilter('status',1)
151
- ->addAttributeToSelect($this->getRequiredAttributes(), 'left')
152
- ->joinTable('cataloginventory/stock_item', 'product_id=entity_id', array('qty' => 'qty', 'is_in_stock' => 'is_in_stock'), $stockItemWhere, 'left');
153
-
154
-
155
-
156
-
157
- //->addAttributeToSelect($attributesToSelect, 'left')
158
- foreach ($attributesToSelect as $key => $attributeCode) {
159
- $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
160
- if ($attributeCode == 'image' || $attributeCode == 'sku' || ($this->getFlatHelper()->isEnabled($storeId) && $attribute->getUsedInProductListing())) {
161
- $products->addAttributeToSelect($attributeCode);
162
- } else {
163
- try {
164
- $products->joinAttribute($attributeCode, 'catalog_product/' . $attributeCode, 'entity_id', null, 'left', $storeId);
165
- } catch (Exception $e) {
166
- //die($attributeCode);
167
- }
168
- }
169
- }
170
-
171
- /*
172
- if ($this->getFlatHelper()->isEnabled($storeId)) {
173
- /*->addAttributeToSelect($attributesToSelect, 'left') shouldnt be enough ?
174
-
175
- $allAttributesToSelect = array_unique($attributesToSelect);
176
- foreach ($allAttributesToSelect as $attributeToSelect) {
177
- if ($attributeToSelect == "sku")
178
- continue;
179
-
180
- $products->joinAttribute($attributeToSelect, 'catalog_product/' . $attributeToSelect, 'entity_id', null, 'left', $storeId);
181
- }
182
- } */
183
-
184
-
185
- //FILTER BY SHOPPING FLUX FLAG
186
- $sfProductFilterAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'shoppingflux_product');
187
- if ($this->getConfig()->isExportFilteredByAttribute()) {
188
- if ($this->getFlatHelper()->isEnabled($storeId) && $sfProductFilterAttribute->getUsedInProductListing()) {
189
- $products->addAttributeToFilter('shoppingflux_product', 1);
190
- } else {
191
- $prefixAttribute = 'at_';
192
- $currentVersion = Mage::getVersion();
193
- if (version_compare($currentVersion, '1.6.0') < 0)
194
- $prefixAttribute = '_table_';
195
-
196
- $fieldName = $prefixAttribute . "shoppingflux_product";
197
- $products->getSelect()->where("if(`{$fieldName}`.`value`, `{$fieldName}`.`value`, `{$fieldName}_default`.`value`)=1");
198
- //$products->addAttributeToFilter('shoppingflux_product',1);
199
- }
200
- }
201
-
202
- Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
203
- $products->setVisibility($this->getConfig()->getVisibilitiesToExport($this->_getStoreId()));
204
- //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
205
-
206
- $products->addIdFilter($this->_getExcludeProductIds(), true);
207
-
208
- if ($this->getProductSku()) {
209
- $products->addAttributeToFilter('sku', $this->getProductSku());
210
- }
211
-
212
-
213
- if ($this->getLimit()) {
214
- //$products->setPageSize($this->getLimit());
215
- $products->getSelect()->limit($this->getLimit());
216
- }
217
-
218
-
219
- // if($_SERVER['REMOTE_ADDR'] == "127.0.0.1" || $_SERVER['REMOTE_ADDR']=="90.2.197.14")
220
- //die('>'.$products->getSize().' '.$products->getSelect().' ');
221
-
222
-
223
- $this->iterateProducts($products);
224
-
225
- //$output = $xmlObj->createXml();
226
- // $this->_writeXml($output,true);
227
- Varien_Profiler::stop("SF::Flow::toHtml");
228
- //return $output;
229
- }
230
-
231
- public function iterateProducts($products, $withLoad = false) {
232
-
233
- Varien_Profiler::start("SF::Flow::iterateProducts");
234
- Varien_Profiler::start("SF::Flow::iterateProducts-0");
235
- $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xmlflow');
236
- $xmlObj->startXml();
237
- Varien_Profiler::stop("SF::Flow::iterateProducts-0");
238
- if (!$withLoad) {
239
-
240
- $product = Mage::getModel('catalog/product');
241
- /*
242
- using resource iterator to load the data one by one
243
- instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
244
- */
245
- Varien_Profiler::start("SF::Flow::iterateProducts-1");
246
- Mage::getSingleton('core/resource_iterator')
247
- ->walk($products->getSelect(), array(array($this, 'addNewItemXmlCallback')), array('xmlObj' => $xmlObj, 'product' => $product));
248
- Varien_Profiler::stop("SF::Flow::iterateProducts-1");
249
- } else {
250
- $products->addMinimalPrice()
251
- ->addFinalPrice()
252
- ->addTaxPercents();
253
- }
254
-
255
- unset($products);
256
- $xmlObj->endXml();
257
- Varien_Profiler::stop("SF::Flow::iterateProducts");
258
- return $xmlObj;
259
- }
260
-
261
- public function addNewItemXml($args) {
262
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback");
263
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-1");
264
- $product = $args['product'];
265
- $product->reset()->setTypeInstance(null, true);
266
- // $product = Mage::getModel('catalog/product');
267
- $product->setData($args['row']);
268
-
269
-
270
- //To get isinstock correct value
271
- // Mage::getModel('cataloginventory/stock_item')->assignProduct($product);
272
-
273
-
274
- /* @var $xmlObj Profileolabs_Shoppingflux_Model_Export_Xmlflow */
275
- $xmlObj = $args['xmlObj'];
276
- $data = array(
277
- 'id' => $product->getId(),
278
- 'sku' => $product->getSku(),
279
- 'product-url' => $this->cleanUrl($product->getProductUrl(false)),
280
- 'is-in-stock' => $product->getIsInStock(),
281
- 'qty' => round($product->getQty()),
282
- );
283
-
284
- foreach ($this->getConfig()->getMappingAttributes($this->_getStoreId()) as $nameNode => $code) {
285
- $data[$nameNode] = trim($xmlObj->extractData($nameNode, $code, $product));
286
- }
287
-
288
-
289
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-1");
290
-
291
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-2");
292
- $data = $this->getPrices($data, $product);
293
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-2");
294
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-3");
295
- $data = $this->getImages($data, $product);
296
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-3");
297
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-4");
298
- $data = $this->getCategories($data, $product);
299
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-4");
300
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-5");
301
- $data = $this->getShippingInfo($data, $product);
302
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-5");
303
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-6");
304
- $data = $this->getConfigurableAttributes($data, $product);
305
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-6");
306
- Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-7");
307
- ini_set('display_errors', true);
308
- error_reporting(-1);
309
- foreach ($this->getConfig()->getAdditionalAttributes() as $attributeCode) {
310
- if (!$attributeCode)
311
- continue;
312
- $data[$attributeCode] = trim($xmlObj->extractData($attributeCode, $attributeCode, $product));
313
- /*$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
314
- if ($attribute->usesSource()) {
315
- $value = $product->getAttributeText($attributeCode);
316
- } else {
317
- $value = $product->getData($attributeCode);
318
- }
319
- if (is_array($value)) {
320
- $value = explode(',', $value);
321
- }
322
- if ($value) {
323
- $data[$attributeCode] = trim($value);
324
- }*/
325
- }
326
-
327
-
328
- //Exceptions data shipping_delay
329
- if (!isset($data['shipping_delay']) && empty($data['shipping_delay']))
330
- $data['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
331
-
332
- if (!$this->getConfig()->isExportSoldout()) {
333
-
334
- if (!$data["is-in-stock"]) {
335
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-7");
336
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback");
337
- return;
338
- }
339
- }
340
-
341
-
342
- $dataObj = new Varien_Object(array('entry' => $data));
343
- Mage::dispatchEvent('shoppingflux_before_add_entry', array('data_obj' => $dataObj));
344
-
345
- $entry = $dataObj->getEntry();
346
-
347
- $xmlObj->_addEntry($entry);
348
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-7");
349
- Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback");
350
- }
351
-
352
- public function addNewItemXmlCallback($args) {
353
- return $this->addNewItemXml($args);
354
- /* if (! function_exists('pcntl_fork')) {
355
- return $this->addNewItemXml($args);
356
- }
357
- switch ($pid = pcntl_fork()) {
358
- case -1:
359
- //fork failed, just do as usual
360
- return $this->addNewItemXml($args);
361
- break;
362
-
363
- case 0:
364
- // @child
365
- return $this->addNewItemXml($args);
366
- break;
367
-
368
- default:
369
- // @parent
370
- pcntl_waitpid($pid, $status);
371
- break;
372
- }*/
373
-
374
- }
375
-
376
- protected function getShippingInfo($data, $product) {
377
-
378
- $data["shipping-name"] = "";
379
- $data["shipping-price"] = "";
380
-
381
- $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
382
- if (empty($carrier)) {
383
- $data["shipping-price"] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
384
- return $data;
385
- }
386
-
387
- $carrierTab = explode('_', $carrier);
388
- list($carrierCode, $methodCode) = $carrierTab;
389
- $data["shipping-name"] = ucfirst($methodCode);
390
-
391
-
392
- $shippingPrice = 0;
393
- if($this->getConfig()->getConfigData('shoppingflux_export/general/try_use_real_shipping_price')) {
394
- $countryCode = $this->getConfig()->getConfigData('shoppingflux_export/general/shipping_price_based_on');
395
- Varien_Profiler::start("SF::Flow::getShippingInfo-1");
396
- $shippingPrice = $this->helper('profileolabs_shoppingflux')->getShippingPrice($product, $carrier, $countryCode);
397
- Varien_Profiler::stop("SF::Flow::getShippingInfo-1");
398
- }
399
-
400
- if (!$shippingPrice) {
401
- $shippingPrice = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
402
- }
403
-
404
- $data["shipping-price"] = $shippingPrice;
405
-
406
- return $data;
407
- }
408
-
409
- protected function getConfigurableAttributes($data, $product) {
410
-
411
- Varien_Profiler::start("SF::Flow::getConfigurableAttributes");
412
- $data["configurable_attributes"] = "";
413
- $data["childs_product"] = "";
414
- $images = array();
415
-
416
- $labels = array();
417
- if ($product->getTypeId() == "configurable") {
418
-
419
-
420
- $attributes = $this->helper('profileolabs_shoppingflux')->getAttributesConfigurable($product);
421
-
422
- $attributesToSelect = array();
423
- $attributesToOptions = array();
424
-
425
- foreach ($attributes as $attribute) {
426
- $attributesToSelect[] = $attribute['attribute_code'];
427
-
428
- $attributesToOptions[$attribute['attribute_code']] = array();
429
- }
430
-
431
-
432
- $attributesToSelect[] = "sku";
433
- $attributesToSelect[] = "status";
434
-
435
-
436
-
437
- $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/price', $this->_getStoreId());
438
- $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/special_price', $this->_getStoreId());
439
-
440
-
441
- $otherAttributes = array(
442
- "shoppingflux_product" => "shoppingflux_product",
443
- "shoppingflux_default_category" => "shoppingflux_default_category",
444
- "tax_class_id" => "tax_class_id",
445
- "special_price" => "special_price",
446
- "minimal_price" => "minimal_price",
447
- "special_from_date" => "special_from_date",
448
- "special_to_date" => "special_to_date",
449
- "image" => "image",
450
- $priceAttributeCode => $priceAttributeCode,
451
- $specialPriceAttributeCode => $specialPriceAttributeCode
452
- );
453
-
454
- $attributesFromConfig = $this->getAttributesFromConfig(true, true);
455
- $attributesFromConfig = array_slice($attributesFromConfig, 0, 42);// Too much attributes causes too much joins, which can overload mysql limits
456
- $attributesToSelect = array_merge($otherAttributes, $attributesFromConfig);
457
- //$attributesFromConfig = $this->getAttributesFromConfig(true, true);
458
- //if (isset($attributesFromConfig['ean']))
459
- // $attributesToSelect[] = $attributesFromConfig['ean'];
460
- //$attributesToSelect = array_merge($attributesToSelect, $attributesFromConfig);
461
-
462
- $usedProducts = $product->getTypeInstance(true)
463
- ->getUsedProductCollection($product);
464
- foreach($attributesToSelect as $attributeCode) {
465
- $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
466
- if ($attributeCode == 'image' || $attributeCode == 'sku' || ($this->getFlatHelper()->isEnabled($this->_getStoreId()) && $attribute->getUsedInProductListing())) {
467
- $usedProducts->addAttributeToSelect($attributeCode, 'left');
468
- } else {
469
- try {
470
- $usedProducts->joinAttribute( $attributeCode, 'catalog_product/'.$attributeCode, 'entity_id', null, 'left' );
471
- } catch (Exception $e) {
472
-
473
- }
474
- }
475
- }
476
-
477
- if ($this->getConfig()->isExportFilteredByAttribute()) {
478
- $usedProducts->addAttributeToFilter('shoppingflux_product', 1);
479
- }
480
-
481
- $configurableAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
482
-
483
- // var_dump($usedProducts->getSelect().'');die();
484
-
485
-
486
- $usedProductsArray = array();
487
- $salable = false;
488
- foreach ($usedProducts as $usedProduct) {
489
- $salable = $salable || $usedProduct->isSalable();
490
-
491
-
492
- if (Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('OrganicInternet_SimpleConfigurableProducts')
493
- || Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('DerModPro_BCP')) {
494
-
495
- $tmpData = $this->getPrices(array(), $usedProduct);
496
- $price = $tmpData['price-ttc'] > 0 ? $tmpData['price-ttc'] : $data['price-ttc'];
497
- if ($data['price-ttc'] <= 0 || ($price > 0 && $price < $data['price-ttc'])) {
498
- $data['price-ttc'] = $price;
499
- }
500
- $priceBeforeDiscount = $tmpData["price-before-discount"];
501
- $discountAmount = $tmpData["discount-amount"];
502
- $startDateDiscount = $tmpData["start-date-discount"];
503
- $endDateDiscount = $tmpData["end-date-discount"];
504
- } else {
505
-
506
- $price = $data['price-ttc'];
507
- $priceBeforeDiscount = $data["price-before-discount"];
508
- $discountAmount = $data["discount-amount"];
509
- $startDateDiscount = $data["start-date-discount"];
510
- $endDateDiscount = $data["end-date-discount"];
511
-
512
- foreach ($configurableAttributes as $configurableAttribute) {
513
- $attributeCode = $configurableAttribute['attribute_code'];
514
- foreach ($configurableAttribute['values'] as $confAttributeValue) {
515
- if ($confAttributeValue['pricing_value'] && $usedProduct->getData($attributeCode) == $confAttributeValue['value_index']) {
516
- if ($confAttributeValue['is_percent']) {
517
- $price += $data['price-ttc'] * $confAttributeValue['pricing_value'] / 100;
518
- $priceBeforeDiscount += $data['price-before-discount'] * $confAttributeValue['pricing_value'] / 100;
519
- } else {
520
- $price += $confAttributeValue['pricing_value'];
521
- $priceBeforeDiscount += $confAttributeValue['pricing_value'];
522
- }
523
- }
524
- }
525
- }
526
- }
527
-
528
-
529
-
530
- $discountPercent = round((($priceBeforeDiscount - $price) * 100) / $priceBeforeDiscount);
531
-
532
- $isInStock = 0;
533
- $qty = 0;
534
- if ($usedProduct->getStockItem()) {
535
- $isInStock = $usedProduct->getStockItem()->getIsInStock();
536
- $qty = $usedProduct->getStockItem()->getQty();
537
- }
538
-
539
- $usedProductsArray[$usedProduct->getId()]['child']["sku"] = $usedProduct->getSku();
540
- $usedProductsArray[$usedProduct->getId()]['child']["id"] = $usedProduct->getId();
541
- $usedProductsArray[$usedProduct->getId()]['child']["price-ttc"] = $price;
542
- $usedProductsArray[$usedProduct->getId()]['child']["price-before-discount"] = $priceBeforeDiscount;
543
- $usedProductsArray[$usedProduct->getId()]['child']["discount-amount"] = $discountAmount;
544
- $usedProductsArray[$usedProduct->getId()]['child']["discount-percent"] = $discountPercent;
545
- $usedProductsArray[$usedProduct->getId()]['child']["start-date-discount"] = $startDateDiscount;
546
- $usedProductsArray[$usedProduct->getId()]['child']["end-date-discount"] = $endDateDiscount;
547
- $usedProductsArray[$usedProduct->getId()]['child']['is-in-stock'] = $isInStock;
548
- $usedProductsArray[$usedProduct->getId()]['child']['qty'] = round($qty);
549
- if ($qty > 0 && $qty > $data['qty']) {
550
- $data['qty'] = round($qty);
551
- }
552
- $usedProductsArray[$usedProduct->getId()]['child']["ean"] = isset($attributesFromConfig['ean']) ? $usedProduct->getData($attributesFromConfig['ean']) : '';
553
-
554
- $images = $this->getImages($images, $usedProduct);
555
- if (!$images['image-url-1']) {
556
- $images = $this->getImages($images, $product);
557
- }
558
- foreach ($images as $key => $value) {
559
- $usedProductsArray[$usedProduct->getId()]['child'][$key] = trim($value);
560
- }
561
-
562
-
563
-
564
- foreach ($this->getConfig()->getMappingAttributes($this->_getStoreId()) as $nameNode => $attributeCode) {
565
- $attributeId = Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product', $attributeCode);
566
- $found = false;
567
- foreach ($attributes as $attribute) {
568
- if ($attribute['attribute_id'] == $attributeId) {
569
- $found = true;
570
- }
571
- }
572
- if (!$found) {
573
- if (!isset($this->_attributesConfigurable[$attributeId]))
574
- $this->_attributesConfigurable[$attributeId] = $product->getResource()->getAttribute($attributeId);
575
-
576
- $attributeModel = $this->_attributesConfigurable[$attributeId];
577
-
578
- $value = '';
579
- if ($usedProduct->getData($attributeCode)) {
580
- $value = $attributeModel->getFrontend()->getValue($usedProduct);
581
- }
582
-
583
-
584
- $usedProductsArray[$usedProduct->getId()]['child'][$nameNode] = trim($value);
585
- }
586
- }
587
-
588
-
589
- //$usedProductsArray[$usedProduct->getId()]['child']['price'] = $usedProduct->getPrice();
590
-
591
- foreach ($attributes as $attribute) {
592
- $attributeCode = $attribute['attribute_code'];
593
- $attributeId = $attribute['attribute_id'];
594
-
595
- if (!isset($this->_attributesConfigurable[$attributeId]))
596
- $this->_attributesConfigurable[$attributeId] = $product->getResource()->getAttribute($attributeId);
597
-
598
- $attributeModel = $this->_attributesConfigurable[$attributeId];
599
-
600
- $value = '';
601
- if ($usedProduct->getData($attributeCode)) {
602
- $value = $attributeModel->getFrontend()->getValue($usedProduct);
603
- }
604
-
605
- if (!in_array($value, $attributesToOptions[$attributeCode]))
606
- $attributesToOptions[$attributeCode][] = $value;
607
-
608
- $usedProductsArray[$usedProduct->getId()]['child'][$attributeCode] = trim($value);
609
- }
610
-
611
-
612
- if (!isset($usedProductsArray[$usedProduct->getId()]['child']['shipping_delay']) || !$usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'])
613
- $usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
614
- }
615
-
616
-
617
-
618
-
619
- $data['is-in-stock'] = (int) $salable;
620
-
621
- foreach ($attributesToOptions as $attributeCode => $value) {
622
-
623
- $data["configurable_attributes"][$attributeCode] = implode(",", $value);
624
- }
625
-
626
- $data["childs_product"] = $usedProductsArray;
627
-
628
- unset($usedProducts);
629
- unset($usedProductsArray);
630
- }
631
-
632
- Varien_Profiler::stop("SF::Flow::getConfigurableAttributes");
633
-
634
- return $data;
635
- }
636
-
637
- /**
638
- * Get prices of product
639
- * @param Mage_Catalog_Model_Product $product
640
- * @return string $nodes
641
- */
642
- protected function getPrices($data, $product) {
643
-
644
- Varien_Profiler::start("SF::Flow::getPrice");
645
- $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/price', $this->_getStoreId());
646
- $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/special_price', $this->_getStoreId());
647
- if (!$product->getData($priceAttributeCode)) {
648
- $priceAttributeCode = 'price';
649
- $specialPriceAttributeCode = 'special_price';
650
- }
651
-
652
- $discountAmount = 0;
653
- $finalPrice = $product->getData($priceAttributeCode);
654
- $priceBeforeDiscount = $product->getData($priceAttributeCode);
655
- if ($product->getData($specialPriceAttributeCode) > 0 && $product->getData($specialPriceAttributeCode) < $finalPrice) {
656
- $finalPrice = $product->getData($specialPriceAttributeCode);
657
- $discountAmount = $product->getData($priceAttributeCode) - $product->getData($specialPriceAttributeCode);
658
- }
659
- $discountFromDate = $product->getSpecialFromDate();
660
- $discountToDate = $product->getSpecialToDate();
661
-
662
-
663
- $product->setCalculatedFinalPrice($finalPrice);
664
- $product->setData('final_price', $finalPrice);
665
-
666
- $currentVersion = Mage::getVersion();
667
- if (version_compare($currentVersion, '1.5.0') < 0) {
668
-
669
- } else {
670
- $catalogPriceRulePrice = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice());
671
- if($catalogPriceRulePrice>0 && $catalogPriceRulePrice<$discountAmount) {
672
- $discountAmount = $catalogPriceRulePrice;
673
- $discountFromDate = '';
674
- $discountToDate = '';
675
- }
676
- }
677
-
678
- $data["price-ttc"] = $this->helper('tax')->getPrice($product, $finalPrice, true); //$finalPrice;
679
- $data["price-before-discount"] = $this->helper('tax')->getPrice($product, $priceBeforeDiscount, true); //$priceBeforeDiscount;
680
- $data["discount-amount"] = $product->getTypeId() != 'bundle' ? $discountAmount : 0;
681
- $data["discount-percent"] = $this->getPercent($product);
682
-
683
- $data["start-date-discount"] = "";
684
- $data["end-date-discount"] = "";
685
- if ($discountFromDate) {
686
- $data["start-date-discount"] = $discountFromDate;
687
- }
688
- if ($discountToDate) {
689
- $data["end-date-discount"] = $discountToDate;
690
- }
691
- Varien_Profiler::stop("SF::Flow::getPrice");
692
- return $data;
693
- }
694
-
695
- /**
696
- * Get categories of product
697
- * @param Mage_Catalog_Model_Product $product
698
- * @return string $nodes
699
- */
700
- protected function getCategories($data, $product) {
701
- if ($product->getData('shoppingflux_default_category') && $product->getData('shoppingflux_default_category') > 0) {
702
- return $this->getCategoriesViaShoppingfluxCategory($data, $product);
703
- }
704
- return $this->getCategoriesViaProductCategories($data, $product);
705
- }
706
-
707
- protected function getCategoriesViaShoppingfluxCategory($data, $product) {
708
-
709
- $categoryId = $product->getData('shoppingflux_default_category');
710
- $category = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents();
711
- if (!isset($category['name'][$categoryId])) {
712
- return $this->getCategoriesViaProductCategories($data, $product);
713
- }
714
- Varien_Profiler::start("SF::Flow::getCategoriesViaShoppingfluxCategory");
715
-
716
- $categoryNames = explode(' > ', $category['name'][$categoryId]);
717
- $categoryUrls = explode(' > ', $category['url'][$categoryId]);
718
-
719
-
720
- //we drop root category, which is useless here
721
- array_shift($categoryNames);
722
- array_shift($categoryUrls);
723
-
724
- $data['category-breadcrumb'] = trim(implode(' > ', $categoryNames));
725
-
726
- $data["category"] = trim($categoryNames[0]);
727
- $data["category-url"] = $categoryUrls[0];
728
-
729
-
730
- for ($i = 1; $i <= 5; $i++) {
731
- if (isset($categoryNames[$i]) && isset($categoryUrls[$i])) {
732
- $data["category-sub-" . ($i)] = trim($categoryNames[$i]);
733
- $data["category-url-sub-" . ($i)] = $categoryUrls[$i];
734
- } else {
735
- $data["category-sub-" . ($i)] = '';
736
- $data["category-url-sub-" . ($i)] = '';
737
- }
738
- }
739
-
740
- Varien_Profiler::stop("SF::Flow::getCategoriesViaShoppingfluxCategory");
741
- return $data;
742
- }
743
-
744
- protected function getCategoriesViaProductCategories($data, $product) {
745
-
746
- Varien_Profiler::start("SF::Flow::getCategoriesViaProductCategories");
747
- $sorted = false;
748
- $asCollection = true;
749
- $toLoad = false;
750
- $parent = Mage::app()->getStore()->getRootCategoryId();
751
-
752
- $cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
753
- if (!isset($this->_storeCategories[$cacheKey])) {
754
-
755
- /**
756
- * Check if parent node of the store still exists
757
- */
758
- $category = Mage::getModel('catalog/category');
759
- /* @var $category Mage_Catalog_Model_Category */
760
- if (!$category->checkId($parent)) {
761
- /* if ($asCollection) {
762
- return new Varien_Data_Collection();
763
- } */
764
-
765
-
766
- Varien_Profiler::stop("SF::Flow::getCategoriesViaProductCategories");
767
- return $data;
768
- }
769
-
770
- $recursionLevel = 0;
771
- $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
772
-
773
- $storeCategoriesIds = array();
774
- foreach ($storeCategories as $cat) {
775
- $storeCategoriesIds[] = $cat['entity_id'];
776
- }
777
- $this->_storeCategories[$cacheKey] = $storeCategoriesIds;
778
- }
779
-
780
- Varien_Profiler::start("SF::Flow::getCategoriesViaProductCategories-1");
781
- $storeCategoriesIds = $this->_storeCategories[$cacheKey];
782
-
783
-
784
-
785
- $categoryCollection = $product->getCategoryCollection()
786
- ->addAttributeToSelect(array('name'))
787
- ->addFieldToFilter('level', array('lteq' => 5))
788
- ->addUrlRewriteToResult()
789
- ->groupByAttribute('level')
790
- ->setOrder('level', 'ASC');
791
-
792
- if (count($storeCategoriesIds) > 0)
793
- $categoryCollection->addFieldToFilter("entity_id", array("in" => $storeCategoriesIds));
794
-
795
- $nbCategories = $categoryCollection->count();
796
-
797
- $cnt = 0;
798
- $lastCategory = null;
799
- foreach ($categoryCollection as $category) {
800
- $name = $category->getName();
801
- $level = $category->getLevel();
802
- $url = $this->cleanUrl($category->getUrl());
803
- if ($cnt == 0) {
804
-
805
- $data["category"] = trim($name);
806
- $data["category-url"] = $url;
807
- } else {
808
-
809
- $data["category-sub-" . ($cnt)] = trim($name);
810
- $data["category-url-sub-" . ($cnt)] = $url;
811
- }
812
-
813
- $lastCategory = $category;
814
-
815
- $cnt++;
816
- }
817
- $data['category-breadcrumb'] = "";
818
- if (!is_null($lastCategory) && is_object($lastCategory)) {
819
-
820
- $breadCrumb = array();
821
-
822
- $pathInStore = $category->getPathInStore();
823
- $pathIds = array_reverse(explode(',', $pathInStore));
824
-
825
- $categories = $category->getParentCategories();
826
-
827
- // add category path breadcrumb
828
- foreach ($pathIds as $categoryId) {
829
- if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
830
- $breadCrumb[] = trim($categories[$categoryId]->getName());
831
- }
832
- }
833
- unset($categories);
834
- $data['category-breadcrumb'] = trim(implode(" > ", $breadCrumb));
835
- }
836
-
837
-
838
-
839
- unset($categoryCollection);
840
-
841
-
842
- if ($nbCategories == 0) {
843
- $data["category"] = "";
844
- $data["category-url"] = "";
845
-
846
- $cnt++;
847
- }
848
-
849
-
850
- for ($i = ($cnt); $i <= 5; $i++) {
851
- $data["category-sub-" . ($i)] = "";
852
- $data["category-url-sub-" . ($i)] = "";
853
- }
854
-
855
-
856
- Varien_Profiler::stop("SF::Flow::getCategoriesViaProductCategories-1");
857
- Varien_Profiler::stop("SF::Flow::getCategoriesViaProductCategories");
858
- return $data;
859
- }
860
-
861
- public function cleanUrl($url) {
862
- $url = str_replace("index.php/", "", $url);
863
-
864
- return $url;
865
- }
866
-
867
- public function getImages($data, $product) {
868
-
869
- Varien_Profiler::start("SF::Flow::getImages");
870
-
871
- $mediaUrl = Mage::getBaseUrl('media') . 'catalog/product';
872
-
873
- $i = 1;
874
-
875
- if ($product->getImage() != "" && $product->getImage() != 'no_selection') {
876
- $data["image-url-" . $i++] = $mediaUrl . $product->getImage();
877
- }
878
-
879
-
880
-
881
- //LOAD media gallery for this product
882
- $mediaGallery = $product->getResource()->getAttribute('media_gallery');
883
- $mediaGallery->getBackend()->afterLoad($product);
884
-
885
-
886
- foreach ($product->getMediaGallery('images') as $image) {
887
- if ($mediaUrl . $product->getImage() == $product->getMediaConfig()->getMediaUrl($image['file']))
888
- continue;
889
-
890
- $data["image-url-" . $i++] = $product->getMediaConfig()->getMediaUrl($image['file']);
891
- if (($i - 6) == 0)
892
- break;
893
- }
894
-
895
-
896
- //Complet with empty nodes
897
- for ($j = $i; $j < 6; $j++) {
898
- $data["image-url-" . $i++] = "";
899
- }
900
- Varien_Profiler::stop("SF::Flow::getImages");
901
- return $data;
902
- }
903
-
904
- /**
905
- * Get singleton config for Export
906
- * @return Profileolabs_Shoppingflux_Model_Export_Config
907
- */
908
- public function getConfig() {
909
- return Mage::getSingleton('profileolabs_shoppingflux/config');
910
- }
911
-
912
- protected function getPercent($product) {
913
-
914
- /* if($product->getTypeId() == 'bundle')
915
- return 0; */
916
- $price = round($product->getPrice(), 2);
917
- if ($price == "0") {
918
- $price = round($product->getMinimalPrice(), 2);
919
- }
920
-
921
- if ($price == "0")
922
- return 0;
923
-
924
- $special = round($product->getFinalPrice(), 2);
925
- $tmp = $price - $special;
926
- $tmp = ($tmp * 100) / $price;
927
- return round($tmp);
928
- }
929
-
930
- /**
931
- *
932
- */
933
- protected function getAttributesFromConfig($checkIfExist = false, $withAdditional = true) {
934
-
935
- Varien_Profiler::start("SF::Flow::getAttributesFromConfig");
936
- if (is_null($this->_attributes)) {
937
- $attributes = $this->getConfig()->getMappingAttributes();
938
- if ($withAdditional) {
939
- $additionalAttributes = $this->getConfig()->getAdditionalAttributes();
940
- foreach ($additionalAttributes as $attributeCode) {
941
- $attributes[$attributeCode] = trim($attributeCode);
942
- }
943
- }
944
-
945
- if ($checkIfExist) {
946
- $product = Mage::getModel('catalog/product');
947
- foreach ($attributes as $key => $code) {
948
-
949
- $attribute = $product->getResource()->getAttribute($code);
950
- if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute && $attribute->getId() && $attribute->getFrontendInput() != 'weee') {
951
- $this->_attributes[$key] = $code;
952
- }
953
- }
954
- }
955
- else
956
- $this->_attributes = $attributes;
957
- }
958
-
959
- Varien_Profiler::stop("SF::Flow::getAttributesFromConfig");
960
- return $this->_attributes;
961
- }
962
-
963
- protected function getRequiredAttributes() {
964
-
965
- $requiredAttributes = array("sku" => "sku",
966
- "price" => "price",
967
- "image" => "image");
968
-
969
- return $requiredAttributes;
970
- }
971
-
972
- protected function getAllAttributes() {
973
- return array_merge($this->getAttributesFromConfig(true), $this->getRequiredAttributes());
974
- }
975
-
976
- /**
977
- * Retrieve Catalog Product Flat Helper object
978
- *
979
- * @return Mage_Catalog_Helper_Product_Flat
980
- */
981
- public function getFlatHelper() {
982
- return Mage::helper('catalog/product_flat');
983
- }
984
-
985
  }
1
+ <?php
2
+ // V1 DEPRECATED
3
+ /**
4
+ * @deprecated
5
+ */
6
+ class Profileolabs_Shoppingflux_Block_Export_Flow extends Mage_Core_Block_Template {
7
+
8
+ protected $_attributes = null;
9
+ protected $_attributesConfigurable = array();
10
+ protected $_attributesOptions = array();
11
+ protected $_fileName = "flow2.xml";
12
+ protected $_storeCategories = array();
13
+
14
+ public function __construct() {
15
+ $this->forceStore();
16
+ }
17
+
18
+ protected function _getStoreId() {
19
+ //store id is store view id
20
+
21
+ return $this->_getStore()->getId();
22
+ ;
23
+ }
24
+
25
+ protected function _getStore() {
26
+
27
+ $storeId = (int) $this->getRequest()->getParam('store', Mage::app()->getStore()->getId());
28
+ return Mage::app()->getStore($storeId);
29
+ }
30
+
31
+ protected function forceStore() {
32
+ if (( $storeId = (int) $this->getRequest()->getParam('store', 0) ) != 0) {
33
+ Mage::app()->setCurrentStore(Mage::app()->getStore($storeId));
34
+ }
35
+ }
36
+
37
+ protected function _writeXml($xml, $start = false) {
38
+ $mode = "a+";
39
+ if ($start)
40
+ $mode = "w+";
41
+ $storeId = $this->_getStoreId();
42
+ $storeCode = Mage::app()->getStore($storeId)->getCode();
43
+ $dir = Mage::getBaseDir('media') . DS . "shoppingflux" . DS . $storeCode . DS;
44
+ $file = new Varien_Io_File;
45
+ $file->checkAndCreateFolder($dir);
46
+ $file->cd($dir);
47
+ $file->streamOpen($this->_fileName, $mode);
48
+ $file->streamLock();
49
+ $file->streamWrite($xml);
50
+ $file->streamUnlock();
51
+ $file->streamClose();
52
+
53
+ if ($file->fileExists($this->_fileName)) {
54
+ return $this->_fileName;
55
+ }
56
+
57
+ return false;
58
+ }
59
+
60
+ protected $_exludeProductIds = null;
61
+
62
+ protected function _getExcludeProductIds($store = null) {
63
+ Varien_Profiler::start("SF::Flow::_getExcludeProductIds");
64
+ if (is_null($this->_exludeProductIds)) {
65
+ $mageCacheKey = 'sf_exclude_pids';
66
+ $fromCache = Mage::app()->loadCache($mageCacheKey);
67
+ if ($fromCache) {
68
+ $this->_exludeProductIds = unserialize($fromCache);
69
+ } else {
70
+
71
+ $this->_exludeProductIds = array();
72
+ $collection = Mage::getModel('catalog/product')
73
+ ->getCollection()
74
+ ->addFieldToFilter('type_id', array('neq' => 'simple'));
75
+ if ($store) {
76
+ $collection->setStore($store)
77
+ ->addStoreFilter($store);
78
+ }
79
+
80
+ $product = Mage::getModel('catalog/product');
81
+ Mage::getSingleton('core/resource_iterator')
82
+ ->walk($collection->getSelect(), array(array($this, '_excludeProductIds')), array('product' => $product));
83
+ Mage::app()->saveCache(serialize($this->_exludeProductIds), $mageCacheKey, array('shoppingflux', Mage_Catalog_Model_Product::CACHE_TAG));
84
+ }
85
+ }
86
+
87
+ Varien_Profiler::stop("SF::Flow::_getExcludeProductIds");
88
+ return $this->_exludeProductIds;
89
+ }
90
+
91
+ public function _excludeProductIds($args) {
92
+ $product = $args['product'];
93
+ $product->reset()->setTypeInstance(null, true);
94
+ $product->setData($args['row']);
95
+
96
+ if ($product->getTypeId() == 'configurable') {
97
+ $childrenIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getChildrenIds($product->getEntityId());
98
+ if ($childrenIds && is_array($childrenIds) && !empty($childrenIds))
99
+ $this->_exludeProductIds = array_merge($this->_exludeProductIds, $childrenIds[0]);
100
+ }
101
+ if ($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle' || $product->getTypeId() == 'virtual') {
102
+ $this->_exludeProductIds = array_merge($this->_exludeProductIds, array($product->getEntityId()));
103
+ }
104
+ //sometimes magento return empty id, so we filter the array
105
+ $this->_exludeProductIds = array_filter($this->_exludeProductIds);
106
+ }
107
+
108
+ protected function _toHtml() {
109
+ Varien_Profiler::start("SF::Flow::toHtml");
110
+ ini_set("memory_limit", $this->getConfig()->getMemoryLimit() . "M");
111
+ $storeId = $this->_getStoreId();
112
+
113
+ /*
114
+ oringinal price - getPrice() - inputed in admin
115
+ special price - getSpecialPrice()
116
+ getFinalPrice() - used in shopping cart calculations
117
+ */
118
+ $product = Mage::getModel('catalog/product');
119
+
120
+ $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/price', $this->_getStoreId());
121
+ $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/special_price', $this->_getStoreId());
122
+
123
+
124
+ $otherAttributes = array(
125
+ "shoppingflux_product" => "shoppingflux_product",
126
+ "shoppingflux_default_category" => "shoppingflux_default_category",
127
+ "tax_class_id" => "tax_class_id",
128
+ "special_price" => "special_price",
129
+ "minimal_price" => "minimal_price",
130
+ "special_from_date" => "special_from_date",
131
+ "special_to_date" => "special_to_date",
132
+ "image" => "image",
133
+ $priceAttributeCode => $priceAttributeCode,
134
+ $specialPriceAttributeCode => $specialPriceAttributeCode
135
+ );
136
+ $attributesToSelect = array_merge($this->getAttributesFromConfig(true), $otherAttributes);
137
+
138
+
139
+ $stockItemWhere = null;
140
+ if (!$this->getConfig()->isExportSoldout()) {
141
+
142
+ $_configManageStock = (int) Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
143
+ $stockItemWhere = "({{table}}.is_in_stock = 1) "
144
+ . " OR IF({{table}}.use_config_manage_stock=1," . $_configManageStock . ",{{table}}.manage_stock)=0";
145
+ }
146
+
147
+
148
+ $products = $product->getCollection()
149
+ ->addStoreFilter($storeId)
150
+ // ->addAttributeToFilter('status',1)
151
+ ->addAttributeToSelect($this->getRequiredAttributes(), 'left')
152
+ ->joinTable('cataloginventory/stock_item', 'product_id=entity_id', array('qty' => 'qty', 'is_in_stock' => 'is_in_stock'), $stockItemWhere, 'left');
153
+
154
+
155
+
156
+
157
+ //->addAttributeToSelect($attributesToSelect, 'left')
158
+ foreach ($attributesToSelect as $key => $attributeCode) {
159
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
160
+ if ($attributeCode == 'image' || $attributeCode == 'sku' || ($this->getFlatHelper()->isEnabled($storeId) && $attribute->getUsedInProductListing())) {
161
+ $products->addAttributeToSelect($attributeCode);
162
+ } else {
163
+ try {
164
+ $products->joinAttribute($attributeCode, 'catalog_product/' . $attributeCode, 'entity_id', null, 'left', $storeId);
165
+ } catch (Exception $e) {
166
+ //die($attributeCode);
167
+ }
168
+ }
169
+ }
170
+
171
+ /*
172
+ if ($this->getFlatHelper()->isEnabled($storeId)) {
173
+ /*->addAttributeToSelect($attributesToSelect, 'left') shouldnt be enough ?
174
+
175
+ $allAttributesToSelect = array_unique($attributesToSelect);
176
+ foreach ($allAttributesToSelect as $attributeToSelect) {
177
+ if ($attributeToSelect == "sku")
178
+ continue;
179
+
180
+ $products->joinAttribute($attributeToSelect, 'catalog_product/' . $attributeToSelect, 'entity_id', null, 'left', $storeId);
181
+ }
182
+ } */
183
+
184
+
185
+ //FILTER BY SHOPPING FLUX FLAG
186
+ $sfProductFilterAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'shoppingflux_product');
187
+ if ($this->getConfig()->isExportFilteredByAttribute()) {
188
+ if ($this->getFlatHelper()->isEnabled($storeId) && $sfProductFilterAttribute->getUsedInProductListing()) {
189
+ $products->addAttributeToFilter('shoppingflux_product', 1);
190
+ } else {
191
+ $prefixAttribute = 'at_';
192
+ $currentVersion = Mage::getVersion();
193
+ if (version_compare($currentVersion, '1.6.0') < 0)
194
+ $prefixAttribute = '_table_';
195
+
196
+ $fieldName = $prefixAttribute . "shoppingflux_product";
197
+ $products->getSelect()->where("if(`{$fieldName}`.`value`, `{$fieldName}`.`value`, `{$fieldName}_default`.`value`)=1");
198
+ //$products->addAttributeToFilter('shoppingflux_product',1);
199
+ }
200
+ }
201
+
202
+ Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
203
+ $products->setVisibility($this->getConfig()->getVisibilitiesToExport($this->_getStoreId()));
204
+ //Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
205
+
206
+ $products->addIdFilter($this->_getExcludeProductIds(), true);
207
+
208
+ if ($this->getProductSku()) {
209
+ $products->addAttributeToFilter('sku', $this->getProductSku());
210
+ }
211
+
212
+
213
+ if ($this->getLimit()) {
214
+ //$products->setPageSize($this->getLimit());
215
+ $products->getSelect()->limit($this->getLimit());
216
+ }
217
+
218
+
219
+ // if($_SERVER['REMOTE_ADDR'] == "127.0.0.1" || $_SERVER['REMOTE_ADDR']=="90.2.197.14")
220
+ //die('>'.$products->getSize().' '.$products->getSelect().' ');
221
+
222
+
223
+ $this->iterateProducts($products);
224
+
225
+ //$output = $xmlObj->createXml();
226
+ // $this->_writeXml($output,true);
227
+ Varien_Profiler::stop("SF::Flow::toHtml");
228
+ //return $output;
229
+ }
230
+
231
+ public function iterateProducts($products, $withLoad = false) {
232
+
233
+ Varien_Profiler::start("SF::Flow::iterateProducts");
234
+ Varien_Profiler::start("SF::Flow::iterateProducts-0");
235
+ $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xmlflow');
236
+ $xmlObj->startXml();
237
+ Varien_Profiler::stop("SF::Flow::iterateProducts-0");
238
+ if (!$withLoad) {
239
+
240
+ $product = Mage::getModel('catalog/product');
241
+ /*
242
+ using resource iterator to load the data one by one
243
+ instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
244
+ */
245
+ Varien_Profiler::start("SF::Flow::iterateProducts-1");
246
+ Mage::getSingleton('core/resource_iterator')
247
+ ->walk($products->getSelect(), array(array($this, 'addNewItemXmlCallback')), array('xmlObj' => $xmlObj, 'product' => $product));
248
+ Varien_Profiler::stop("SF::Flow::iterateProducts-1");
249
+ } else {
250
+ $products->addMinimalPrice()
251
+ ->addFinalPrice()
252
+ ->addTaxPercents();
253
+ }
254
+
255
+ unset($products);
256
+ $xmlObj->endXml();
257
+ Varien_Profiler::stop("SF::Flow::iterateProducts");
258
+ return $xmlObj;
259
+ }
260
+
261
+ public function addNewItemXml($args) {
262
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback");
263
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-1");
264
+ $product = $args['product'];
265
+ $product->reset()->setTypeInstance(null, true);
266
+ // $product = Mage::getModel('catalog/product');
267
+ $product->setData($args['row']);
268
+
269
+
270
+ //To get isinstock correct value
271
+ // Mage::getModel('cataloginventory/stock_item')->assignProduct($product);
272
+
273
+
274
+ /* @var $xmlObj Profileolabs_Shoppingflux_Model_Export_Xmlflow */
275
+ $xmlObj = $args['xmlObj'];
276
+ $data = array(
277
+ 'id' => $product->getId(),
278
+ 'sku' => $product->getSku(),
279
+ 'product-url' => $this->cleanUrl($product->getProductUrl(false)),
280
+ 'is-in-stock' => $product->getIsInStock(),
281
+ 'qty' => round($product->getQty()),
282
+ );
283
+
284
+ foreach ($this->getConfig()->getMappingAttributes($this->_getStoreId()) as $nameNode => $code) {
285
+ $data[$nameNode] = trim($xmlObj->extractData($nameNode, $code, $product));
286
+ }
287
+
288
+
289
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-1");
290
+
291
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-2");
292
+ $data = $this->getPrices($data, $product);
293
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-2");
294
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-3");
295
+ $data = $this->getImages($data, $product);
296
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-3");
297
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-4");
298
+ $data = $this->getCategories($data, $product);
299
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-4");
300
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-5");
301
+ $data = $this->getShippingInfo($data, $product);
302
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-5");
303
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-6");
304
+ $data = $this->getConfigurableAttributes($data, $product);
305
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-6");
306
+ Varien_Profiler::start("SF::Flow::addNewItemXmlCallback-7");
307
+ ini_set('display_errors', true);
308
+ error_reporting(-1);
309
+ foreach ($this->getConfig()->getAdditionalAttributes() as $attributeCode) {
310
+ if (!$attributeCode)
311
+ continue;
312
+ $data[$attributeCode] = trim($xmlObj->extractData($attributeCode, $attributeCode, $product));
313
+ /*$attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
314
+ if ($attribute->usesSource()) {
315
+ $value = $product->getAttributeText($attributeCode);
316
+ } else {
317
+ $value = $product->getData($attributeCode);
318
+ }
319
+ if (is_array($value)) {
320
+ $value = explode(',', $value);
321
+ }
322
+ if ($value) {
323
+ $data[$attributeCode] = trim($value);
324
+ }*/
325
+ }
326
+
327
+
328
+ //Exceptions data shipping_delay
329
+ if (!isset($data['shipping_delay']) && empty($data['shipping_delay']))
330
+ $data['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
331
+
332
+ if (!$this->getConfig()->isExportSoldout()) {
333
+
334
+ if (!$data["is-in-stock"]) {
335
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-7");
336
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback");
337
+ return;
338
+ }
339
+ }
340
+
341
+
342
+ $dataObj = new Varien_Object(array('entry' => $data));
343
+ Mage::dispatchEvent('shoppingflux_before_add_entry', array('data_obj' => $dataObj));
344
+
345
+ $entry = $dataObj->getEntry();
346
+
347
+ $xmlObj->_addEntry($entry);
348
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback-7");
349
+ Varien_Profiler::stop("SF::Flow::addNewItemXmlCallback");
350
+ }
351
+
352
+ public function addNewItemXmlCallback($args) {
353
+ return $this->addNewItemXml($args);
354
+ /* if (! function_exists('pcntl_fork')) {
355
+ return $this->addNewItemXml($args);
356
+ }
357
+ switch ($pid = pcntl_fork()) {
358
+ case -1:
359
+ //fork failed, just do as usual
360
+ return $this->addNewItemXml($args);
361
+ break;
362
+
363
+ case 0:
364
+ // @child
365
+ return $this->addNewItemXml($args);
366
+ break;
367
+
368
+ default:
369
+ // @parent
370
+ pcntl_waitpid($pid, $status);
371
+ break;
372
+ }*/
373
+
374
+ }
375
+
376
+ protected function getShippingInfo($data, $product) {
377
+
378
+ $data["shipping-name"] = "";
379
+ $data["shipping-price"] = "";
380
+
381
+ $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
382
+ if (empty($carrier)) {
383
+ $data["shipping-price"] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
384
+ return $data;
385
+ }
386
+
387
+ $carrierTab = explode('_', $carrier);
388
+ list($carrierCode, $methodCode) = $carrierTab;
389
+ $data["shipping-name"] = ucfirst($methodCode);
390
+
391
+
392
+ $shippingPrice = 0;
393
+ if($this->getConfig()->getConfigData('shoppingflux_export/general/try_use_real_shipping_price')) {
394
+ $countryCode = $this->getConfig()->getConfigData('shoppingflux_export/general/shipping_price_based_on');
395
+ Varien_Profiler::start("SF::Flow::getShippingInfo-1");
396
+ $shippingPrice = $this->helper('profileolabs_shoppingflux')->getShippingPrice($product, $carrier, $countryCode);
397
+ Varien_Profiler::stop("SF::Flow::getShippingInfo-1");
398
+ }
399
+
400
+ if (!$shippingPrice) {
401
+ $shippingPrice = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
402
+ }
403
+
404
+ $data["shipping-price"] = $shippingPrice;
405
+
406
+ return $data;
407
+ }
408
+
409
+ protected function getConfigurableAttributes($data, $product) {
410
+
411
+ Varien_Profiler::start("SF::Flow::getConfigurableAttributes");
412
+ $data["configurable_attributes"] = "";
413
+ $data["childs_product"] = "";
414
+ $images = array();
415
+
416
+ $labels = array();
417
+ if ($product->getTypeId() == "configurable") {
418
+
419
+
420
+ $attributes = $this->helper('profileolabs_shoppingflux')->getAttributesConfigurable($product);
421
+
422
+ $attributesToSelect = array();
423
+ $attributesToOptions = array();
424
+
425
+ foreach ($attributes as $attribute) {
426
+ $attributesToSelect[] = $attribute['attribute_code'];
427
+
428
+ $attributesToOptions[$attribute['attribute_code']] = array();
429
+ }
430
+
431
+
432
+ $attributesToSelect[] = "sku";
433
+ $attributesToSelect[] = "status";
434
+
435
+
436
+
437
+ $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/price', $this->_getStoreId());
438
+ $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/special_price', $this->_getStoreId());
439
+
440
+
441
+ $otherAttributes = array(
442
+ "shoppingflux_product" => "shoppingflux_product",
443
+ "shoppingflux_default_category" => "shoppingflux_default_category",
444
+ "tax_class_id" => "tax_class_id",
445
+ "special_price" => "special_price",
446
+ "minimal_price" => "minimal_price",
447
+ "special_from_date" => "special_from_date",
448
+ "special_to_date" => "special_to_date",
449
+ "image" => "image",
450
+ $priceAttributeCode => $priceAttributeCode,
451
+ $specialPriceAttributeCode => $specialPriceAttributeCode
452
+ );
453
+
454
+ $attributesFromConfig = $this->getAttributesFromConfig(true, true);
455
+ $attributesFromConfig = array_slice($attributesFromConfig, 0, 42);// Too much attributes causes too much joins, which can overload mysql limits
456
+ $attributesToSelect = array_merge($otherAttributes, $attributesFromConfig);
457
+ //$attributesFromConfig = $this->getAttributesFromConfig(true, true);
458
+ //if (isset($attributesFromConfig['ean']))
459
+ // $attributesToSelect[] = $attributesFromConfig['ean'];
460
+ //$attributesToSelect = array_merge($attributesToSelect, $attributesFromConfig);
461
+
462
+ $usedProducts = $product->getTypeInstance(true)
463
+ ->getUsedProductCollection($product);
464
+ foreach($attributesToSelect as $attributeCode) {
465
+ $attribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
466
+ if ($attributeCode == 'image' || $attributeCode == 'sku' || ($this->getFlatHelper()->isEnabled($this->_getStoreId()) && $attribute->getUsedInProductListing())) {
467
+ $usedProducts->addAttributeToSelect($attributeCode, 'left');
468
+ } else {
469
+ try {
470
+ $usedProducts->joinAttribute( $attributeCode, 'catalog_product/'.$attributeCode, 'entity_id', null, 'left' );
471
+ } catch (Exception $e) {
472
+
473
+ }
474
+ }
475
+ }
476
+
477
+ if ($this->getConfig()->isExportFilteredByAttribute()) {
478
+ $usedProducts->addAttributeToFilter('shoppingflux_product', 1);
479
+ }
480
+
481
+ $configurableAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
482
+
483
+ // var_dump($usedProducts->getSelect().'');die();
484
+
485
+
486
+ $usedProductsArray = array();
487
+ $salable = false;
488
+ foreach ($usedProducts as $usedProduct) {
489
+ $salable = $salable || $usedProduct->isSalable();
490
+
491
+
492
+ if (Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('OrganicInternet_SimpleConfigurableProducts')
493
+ || Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('DerModPro_BCP')) {
494
+
495
+ $tmpData = $this->getPrices(array(), $usedProduct);
496
+ $price = $tmpData['price-ttc'] > 0 ? $tmpData['price-ttc'] : $data['price-ttc'];
497
+ if ($data['price-ttc'] <= 0 || ($price > 0 && $price < $data['price-ttc'])) {
498
+ $data['price-ttc'] = $price;
499
+ }
500
+ $priceBeforeDiscount = $tmpData["price-before-discount"];
501
+ $discountAmount = $tmpData["discount-amount"];
502
+ $startDateDiscount = $tmpData["start-date-discount"];
503
+ $endDateDiscount = $tmpData["end-date-discount"];
504
+ } else {
505
+
506
+ $price = $data['price-ttc'];
507
+ $priceBeforeDiscount = $data["price-before-discount"];
508
+ $discountAmount = $data["discount-amount"];
509
+ $startDateDiscount = $data["start-date-discount"];
510
+ $endDateDiscount = $data["end-date-discount"];
511
+
512
+ foreach ($configurableAttributes as $configurableAttribute) {
513
+ $attributeCode = $configurableAttribute['attribute_code'];
514
+ foreach ($configurableAttribute['values'] as $confAttributeValue) {
515
+ if ($confAttributeValue['pricing_value'] && $usedProduct->getData($attributeCode) == $confAttributeValue['value_index']) {
516
+ if ($confAttributeValue['is_percent']) {
517
+ $price += $data['price-ttc'] * $confAttributeValue['pricing_value'] / 100;
518
+ $priceBeforeDiscount += $data['price-before-discount'] * $confAttributeValue['pricing_value'] / 100;
519
+ } else {
520
+ $price += $confAttributeValue['pricing_value'];
521
+ $priceBeforeDiscount += $confAttributeValue['pricing_value'];
522
+ }
523
+ }
524
+ }
525
+ }
526
+ }
527
+
528
+
529
+
530
+ $discountPercent = round((($priceBeforeDiscount - $price) * 100) / $priceBeforeDiscount);
531
+
532
+ $isInStock = 0;
533
+ $qty = 0;
534
+ if ($usedProduct->getStockItem()) {
535
+ $isInStock = $usedProduct->getStockItem()->getIsInStock();
536
+ $qty = $usedProduct->getStockItem()->getQty();
537
+ }
538
+
539
+ $usedProductsArray[$usedProduct->getId()]['child']["sku"] = $usedProduct->getSku();
540
+ $usedProductsArray[$usedProduct->getId()]['child']["id"] = $usedProduct->getId();
541
+ $usedProductsArray[$usedProduct->getId()]['child']["price-ttc"] = $price;
542
+ $usedProductsArray[$usedProduct->getId()]['child']["price-before-discount"] = $priceBeforeDiscount;
543
+ $usedProductsArray[$usedProduct->getId()]['child']["discount-amount"] = $discountAmount;
544
+ $usedProductsArray[$usedProduct->getId()]['child']["discount-percent"] = $discountPercent;
545
+ $usedProductsArray[$usedProduct->getId()]['child']["start-date-discount"] = $startDateDiscount;
546
+ $usedProductsArray[$usedProduct->getId()]['child']["end-date-discount"] = $endDateDiscount;
547
+ $usedProductsArray[$usedProduct->getId()]['child']['is-in-stock'] = $isInStock;
548
+ $usedProductsArray[$usedProduct->getId()]['child']['qty'] = round($qty);
549
+ if ($qty > 0 && $qty > $data['qty']) {
550
+ $data['qty'] = round($qty);
551
+ }
552
+ $usedProductsArray[$usedProduct->getId()]['child']["ean"] = isset($attributesFromConfig['ean']) ? $usedProduct->getData($attributesFromConfig['ean']) : '';
553
+
554
+ $images = $this->getImages($images, $usedProduct);
555
+ if (!$images['image-url-1']) {
556
+ $images = $this->getImages($images, $product);
557
+ }
558
+ foreach ($images as $key => $value) {
559
+ $usedProductsArray[$usedProduct->getId()]['child'][$key] = trim($value);
560
+ }
561
+
562
+
563
+
564
+ foreach ($this->getConfig()->getMappingAttributes($this->_getStoreId()) as $nameNode => $attributeCode) {
565
+ $attributeId = Mage::getModel('eav/entity_attribute')->getIdByCode('catalog_product', $attributeCode);
566
+ $found = false;
567
+ foreach ($attributes as $attribute) {
568
+ if ($attribute['attribute_id'] == $attributeId) {
569
+ $found = true;
570
+ }
571
+ }
572
+ if (!$found) {
573
+ if (!isset($this->_attributesConfigurable[$attributeId]))
574
+ $this->_attributesConfigurable[$attributeId] = $product->getResource()->getAttribute($attributeId);
575
+
576
+ $attributeModel = $this->_attributesConfigurable[$attributeId];
577
+
578
+ $value = '';
579
+ if ($usedProduct->getData($attributeCode)) {
580
+ $value = $attributeModel->getFrontend()->getValue($usedProduct);
581
+ }
582
+
583
+
584
+ $usedProductsArray[$usedProduct->getId()]['child'][$nameNode] = trim($value);
585
+ }
586
+ }
587
+
588
+
589
+ //$usedProductsArray[$usedProduct->getId()]['child']['price'] = $usedProduct->getPrice();
590
+
591
+ foreach ($attributes as $attribute) {
592
+ $attributeCode = $attribute['attribute_code'];
593
+ $attributeId = $attribute['attribute_id'];
594
+
595
+ if (!isset($this->_attributesConfigurable[$attributeId]))
596
+ $this->_attributesConfigurable[$attributeId] = $product->getResource()->getAttribute($attributeId);
597
+
598
+ $attributeModel = $this->_attributesConfigurable[$attributeId];
599
+
600
+ $value = '';
601
+ if ($usedProduct->getData($attributeCode)) {
602
+ $value = $attributeModel->getFrontend()->getValue($usedProduct);
603
+ }
604
+
605
+ if (!in_array($value, $attributesToOptions[$attributeCode]))
606
+ $attributesToOptions[$attributeCode][] = $value;
607
+
608
+ $usedProductsArray[$usedProduct->getId()]['child'][$attributeCode] = trim($value);
609
+ }
610
+
611
+
612
+ if (!isset($usedProductsArray[$usedProduct->getId()]['child']['shipping_delay']) || !$usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'])
613
+ $usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
614
+ }
615
+
616
+
617
+
618
+
619
+ $data['is-in-stock'] = (int) $salable;
620
+
621
+ foreach ($attributesToOptions as $attributeCode => $value) {
622
+
623
+ $data["configurable_attributes"][$attributeCode] = implode(",", $value);
624
+ }
625
+
626
+ $data["childs_product"] = $usedProductsArray;
627
+
628
+ unset($usedProducts);
629
+ unset($usedProductsArray);
630
+ }
631
+
632
+ Varien_Profiler::stop("SF::Flow::getConfigurableAttributes");
633
+
634
+ return $data;
635
+ }
636
+
637
+ /**
638
+ * Get prices of product
639
+ * @param Mage_Catalog_Model_Product $product
640
+ * @return string $nodes
641
+ */
642
+ protected function getPrices($data, $product) {
643
+
644
+ Varien_Profiler::start("SF::Flow::getPrice");
645
+ $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/price', $this->_getStoreId());
646
+ $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/specific_prices/special_price', $this->_getStoreId());
647
+ if (!$product->getData($priceAttributeCode)) {
648
+ $priceAttributeCode = 'price';
649
+ $specialPriceAttributeCode = 'special_price';
650
+ }
651
+
652
+ $discountAmount = 0;
653
+ $finalPrice = $product->getData($priceAttributeCode);
654
+ $priceBeforeDiscount = $product->getData($priceAttributeCode);
655
+ if ($product->getData($specialPriceAttributeCode) > 0 && $product->getData($specialPriceAttributeCode) < $finalPrice) {
656
+ $finalPrice = $product->getData($specialPriceAttributeCode);
657
+ $discountAmount = $product->getData($priceAttributeCode) - $product->getData($specialPriceAttributeCode);
658
+ }
659
+ $discountFromDate = $product->getSpecialFromDate();
660
+ $discountToDate = $product->getSpecialToDate();
661
+
662
+
663
+ $product->setCalculatedFinalPrice($finalPrice);
664
+ $product->setData('final_price', $finalPrice);
665
+
666
+ $currentVersion = Mage::getVersion();
667
+ if (version_compare($currentVersion, '1.5.0') < 0) {
668
+
669
+ } else {
670
+ $catalogPriceRulePrice = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice());
671
+ if($catalogPriceRulePrice>0 && $catalogPriceRulePrice<$discountAmount) {
672
+ $discountAmount = $catalogPriceRulePrice;
673
+ $discountFromDate = '';
674
+ $discountToDate = '';
675
+ }
676
+ }
677
+
678
+ $data["price-ttc"] = $this->helper('tax')->getPrice($product, $finalPrice, true); //$finalPrice;
679
+ $data["price-before-discount"] = $this->helper('tax')->getPrice($product, $priceBeforeDiscount, true); //$priceBeforeDiscount;
680
+ $data["discount-amount"] = $product->getTypeId() != 'bundle' ? $discountAmount : 0;
681
+ $data["discount-percent"] = $this->getPercent($product);
682
+
683
+ $data["start-date-discount"] = "";
684
+ $data["end-date-discount"] = "";
685
+ if ($discountFromDate) {
686
+ $data["start-date-discount"] = $discountFromDate;
687
+ }
688
+ if ($discountToDate) {
689
+ $data["end-date-discount"] = $discountToDate;
690
+ }
691
+ Varien_Profiler::stop("SF::Flow::getPrice");
692
+ return $data;
693
+ }
694
+
695
+ /**
696
+ * Get categories of product
697
+ * @param Mage_Catalog_Model_Product $product
698
+ * @return string $nodes
699
+ */
700
+ protected function getCategories($data, $product) {
701
+ if ($product->getData('shoppingflux_default_category') && $product->getData('shoppingflux_default_category') > 0) {
702
+ return $this->getCategoriesViaShoppingfluxCategory($data, $product);
703
+ }
704
+ return $this->getCategoriesViaProductCategories($data, $product);
705
+ }
706
+
707
+ protected function getCategoriesViaShoppingfluxCategory($data, $product) {
708
+
709
+ $categoryId = $product->getData('shoppingflux_default_category');
710
+ $category = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents();
711
+ if (!isset($category['name'][$categoryId])) {
712
+ return $this->getCategoriesViaProductCategories($data, $product);
713
+ }
714
+ Varien_Profiler::start("SF::Flow::getCategoriesViaShoppingfluxCategory");
715
+
716
+ $categoryNames = explode(' > ', $category['name'][$categoryId]);
717
+ $categoryUrls = explode(' > ', $category['url'][$categoryId]);
718
+
719
+
720
+ //we drop root category, which is useless here
721
+ array_shift($categoryNames);
722
+ array_shift($categoryUrls);
723
+
724
+ $data['category-breadcrumb'] = trim(implode(' > ', $categoryNames));
725
+
726
+ $data["category"] = trim($categoryNames[0]);
727
+ $data["category-url"] = $categoryUrls[0];
728
+
729
+
730
+ for ($i = 1; $i <= 5; $i++) {
731
+ if (isset($categoryNames[$i]) && isset($categoryUrls[$i])) {
732
+ $data["category-sub-" . ($i)] = trim($categoryNames[$i]);
733
+ $data["category-url-sub-" . ($i)] = $categoryUrls[$i];
734
+ } else {
735
+ $data["category-sub-" . ($i)] = '';
736
+ $data["category-url-sub-" . ($i)] = '';
737
+ }
738
+ }
739
+
740
+ Varien_Profiler::stop("SF::Flow::getCategoriesViaShoppingfluxCategory");
741
+ return $data;
742
+ }
743
+
744
+ protected function getCategoriesViaProductCategories($data, $product) {
745
+
746
+ Varien_Profiler::start("SF::Flow::getCategoriesViaProductCategories");
747
+ $sorted = false;
748
+ $asCollection = true;
749
+ $toLoad = false;
750
+ $parent = Mage::app()->getStore()->getRootCategoryId();
751
+
752
+ $cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
753
+ if (!isset($this->_storeCategories[$cacheKey])) {
754
+
755
+ /**
756
+ * Check if parent node of the store still exists
757
+ */
758
+ $category = Mage::getModel('catalog/category');
759
+ /* @var $category Mage_Catalog_Model_Category */
760
+ if (!$category->checkId($parent)) {
761
+ /* if ($asCollection) {
762
+ return new Varien_Data_Collection();
763
+ } */
764
+
765
+
766
+ Varien_Profiler::stop("SF::Flow::getCategoriesViaProductCategories");
767
+ return $data;
768
+ }
769
+
770
+ $recursionLevel = 0;
771
+ $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);
772
+
773
+ $storeCategoriesIds = array();
774
+ foreach ($storeCategories as $cat) {
775
+ $storeCategoriesIds[] = $cat['entity_id'];
776
+ }
777
+ $this->_storeCategories[$cacheKey] = $storeCategoriesIds;
778
+ }
779
+
780
+ Varien_Profiler::start("SF::Flow::getCategoriesViaProductCategories-1");
781
+ $storeCategoriesIds = $this->_storeCategories[$cacheKey];
782
+
783
+
784
+
785
+ $categoryCollection = $product->getCategoryCollection()
786
+ ->addAttributeToSelect(array('name'))
787
+ ->addFieldToFilter('level', array('lteq' => 5))
788
+ ->addUrlRewriteToResult()
789
+ ->groupByAttribute('level')
790
+ ->setOrder('level', 'ASC');
791
+
792
+ if (count($storeCategoriesIds) > 0)
793
+ $categoryCollection->addFieldToFilter("entity_id", array("in" => $storeCategoriesIds));
794
+
795
+ $nbCategories = $categoryCollection->count();
796
+
797
+ $cnt = 0;
798
+ $lastCategory = null;
799
+ foreach ($categoryCollection as $category) {
800
+ $name = $category->getName();
801
+ $level = $category->getLevel();
802
+ $url = $this->cleanUrl($category->getUrl());
803
+ if ($cnt == 0) {
804
+
805
+ $data["category"] = trim($name);
806
+ $data["category-url"] = $url;
807
+ } else {
808
+
809
+ $data["category-sub-" . ($cnt)] = trim($name);
810
+ $data["category-url-sub-" . ($cnt)] = $url;
811
+ }
812
+
813
+ $lastCategory = $category;
814
+
815
+ $cnt++;
816
+ }
817
+ $data['category-breadcrumb'] = "";
818
+ if (!is_null($lastCategory) && is_object($lastCategory)) {
819
+
820
+ $breadCrumb = array();
821
+
822
+ $pathInStore = $category->getPathInStore();
823
+ $pathIds = array_reverse(explode(',', $pathInStore));
824
+
825
+ $categories = $category->getParentCategories();
826
+
827
+ // add category path breadcrumb
828
+ foreach ($pathIds as $categoryId) {
829
+ if (isset($categories[$categoryId]) && $categories[$categoryId]->getName()) {
830
+ $breadCrumb[] = trim($categories[$categoryId]->getName());
831
+ }
832
+ }
833
+ unset($categories);
834
+ $data['category-breadcrumb'] = trim(implode(" > ", $breadCrumb));
835
+ }
836
+
837
+
838
+
839
+ unset($categoryCollection);
840
+
841
+
842
+ if ($nbCategories == 0) {
843
+ $data["category"] = "";
844
+ $data["category-url"] = "";
845
+
846
+ $cnt++;
847
+ }
848
+
849
+
850
+ for ($i = ($cnt); $i <= 5; $i++) {
851
+ $data["category-sub-" . ($i)] = "";
852
+ $data["category-url-sub-" . ($i)] = "";
853
+ }
854
+
855
+
856
+ Varien_Profiler::stop("SF::Flow::getCategoriesViaProductCategories-1");
857
+ Varien_Profiler::stop("SF::Flow::getCategoriesViaProductCategories");
858
+ return $data;
859
+ }
860
+
861
+ public function cleanUrl($url) {
862
+ $url = str_replace("index.php/", "", $url);
863
+
864
+ return $url;
865
+ }
866
+
867
+ public function getImages($data, $product) {
868
+
869
+ Varien_Profiler::start("SF::Flow::getImages");
870
+
871
+ $mediaUrl = Mage::getBaseUrl('media') . 'catalog/product';
872
+
873
+ $i = 1;
874
+
875
+ if ($product->getImage() != "" && $product->getImage() != 'no_selection') {
876
+ $data["image-url-" . $i++] = $mediaUrl . $product->getImage();
877
+ }
878
+
879
+
880
+
881
+ //LOAD media gallery for this product
882
+ $mediaGallery = $product->getResource()->getAttribute('media_gallery');
883
+ $mediaGallery->getBackend()->afterLoad($product);
884
+
885
+
886
+ foreach ($product->getMediaGallery('images') as $image) {
887
+ if ($mediaUrl . $product->getImage() == $product->getMediaConfig()->getMediaUrl($image['file']))
888
+ continue;
889
+
890
+ $data["image-url-" . $i++] = $product->getMediaConfig()->getMediaUrl($image['file']);
891
+ if (($i - 6) == 0)
892
+ break;
893
+ }
894
+
895
+
896
+ //Complet with empty nodes
897
+ for ($j = $i; $j < 6; $j++) {
898
+ $data["image-url-" . $i++] = "";
899
+ }
900
+ Varien_Profiler::stop("SF::Flow::getImages");
901
+ return $data;
902
+ }
903
+
904
+ /**
905
+ * Get singleton config for Export
906
+ * @return Profileolabs_Shoppingflux_Model_Export_Config
907
+ */
908
+ public function getConfig() {
909
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
910
+ }
911
+
912
+ protected function getPercent($product) {
913
+
914
+ /* if($product->getTypeId() == 'bundle')
915
+ return 0; */
916
+ $price = round($product->getPrice(), 2);
917
+ if ($price == "0") {
918
+ $price = round($product->getMinimalPrice(), 2);
919
+ }
920
+
921
+ if ($price == "0")
922
+ return 0;
923
+
924
+ $special = round($product->getFinalPrice(), 2);
925
+ $tmp = $price - $special;
926
+ $tmp = ($tmp * 100) / $price;
927
+ return round($tmp);
928
+ }
929
+
930
+ /**
931
+ *
932
+ */
933
+ protected function getAttributesFromConfig($checkIfExist = false, $withAdditional = true) {
934
+
935
+ Varien_Profiler::start("SF::Flow::getAttributesFromConfig");
936
+ if (is_null($this->_attributes)) {
937
+ $attributes = $this->getConfig()->getMappingAttributes();
938
+ if ($withAdditional) {
939
+ $additionalAttributes = $this->getConfig()->getAdditionalAttributes();
940
+ foreach ($additionalAttributes as $attributeCode) {
941
+ $attributes[$attributeCode] = trim($attributeCode);
942
+ }
943
+ }
944
+
945
+ if ($checkIfExist) {
946
+ $product = Mage::getModel('catalog/product');
947
+ foreach ($attributes as $key => $code) {
948
+
949
+ $attribute = $product->getResource()->getAttribute($code);
950
+ if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute && $attribute->getId() && $attribute->getFrontendInput() != 'weee') {
951
+ $this->_attributes[$key] = $code;
952
+ }
953
+ }
954
+ }
955
+ else
956
+ $this->_attributes = $attributes;
957
+ }
958
+
959
+ Varien_Profiler::stop("SF::Flow::getAttributesFromConfig");
960
+ return $this->_attributes;
961
+ }
962
+
963
+ protected function getRequiredAttributes() {
964
+
965
+ $requiredAttributes = array("sku" => "sku",
966
+ "price" => "price",
967
+ "image" => "image");
968
+
969
+ return $requiredAttributes;
970
+ }
971
+
972
+ protected function getAllAttributes() {
973
+ return array_merge($this->getAttributesFromConfig(true), $this->getRequiredAttributes());
974
+ }
975
+
976
+ /**
977
+ * Retrieve Catalog Product Flat Helper object
978
+ *
979
+ * @return Mage_Catalog_Helper_Product_Flat
980
+ */
981
+ public function getFlatHelper() {
982
+ return Mage::helper('catalog/product_flat');
983
+ }
984
+
985
  }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Flux.php CHANGED
@@ -1,107 +1,112 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Block_Export_Flux extends Mage_Core_Block_Abstract {
4
-
5
- protected function _loadCache() {
6
- return false;
7
- }
8
-
9
- protected function _saveCache($data)
10
- {
11
- return;
12
- }
13
-
14
- protected function _toHtml() {
15
- $this->displayOutput();
16
- return '';
17
- }
18
-
19
-
20
- public function displayOutput() {
21
- Profileolabs_Shoppingflux_Model_Export_Observer::checkStock();
22
-
23
- $useAllStores = $this->getForceMultiStores() || $this->getConfig()->getUseAllStoreProducts();
24
- if ($this->getProductSku() && $this->getRequest()->getParam('update') == 1) {
25
- if(!$this->getConfig()->getUseAllStoreProducts()) {
26
- Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFlux($this->getProductSku(), Mage::app()->getStore()->getId());
27
- } else {
28
- Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFluxForAllStores($this->getProductSku());
29
- }
30
- }
31
-
32
- $maxImportLimit = 1000;
33
- $memoryLimit = ini_get('memory_limit');
34
- if (preg_match('%M$%', $memoryLimit)) {
35
- $memoryLimit = intval($memoryLimit) * 1024 * 1024;
36
- } else if (preg_match('%G$%', $memoryLimit)) {
37
- $memoryLimit = intval($memoryLimit) * 1024 * 1024 * 1024;
38
- } else {
39
- $memoryLimit = false;
40
- }
41
- if($memoryLimit > 0) {
42
- if($memoryLimit <= 128 * 1024 * 1024) {
43
- $maxImportLimit = 100;
44
- } else if($memoryLimit <= 256 * 1024 * 1024) {
45
- $maxImportLimit = 500;
46
- } else if($memoryLimit >= 1024 * 1024 * 1024) {
47
- $maxImportLimit = 3000;
48
- }else if($memoryLimit >= 2048 * 1024 * 1024) {
49
- $maxImportLimit = 6000;
50
- }
51
- }
52
-
53
- Mage::getModel('profileolabs_shoppingflux/export_flux')->updateFlux($useAllStores?false:Mage::app()->getStore()->getId(), $this->getLimit() ? $this->getLimit() : $maxImportLimit);
54
- $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
55
- $collection->addFieldToFilter('should_export', 1);
56
- if($useAllStores) {
57
- $collection->getSelect()->group(array('sku'));
58
- } else {
59
- $collection->addFieldToFilter('store_id', Mage::app()->getStore()->getId());
60
- }
61
- $sizeTotal = $collection->count();
62
- $collection->clear();
63
-
64
- if (!$this->getConfig()->isExportNotSalable()) {
65
- $collection->addFieldToFilter('salable', 1);
66
- }
67
- if (!$this->getConfig()->isExportSoldout()) {
68
- $collection->addFieldToFilter('is_in_stock', 1);
69
- }
70
- if ($this->getConfig()->isExportFilteredByAttribute()) {
71
- $collection->addFieldToFilter('is_in_flux', 1);
72
- }
73
- $visibilities = $this->getConfig()->getVisibilitiesToExport();
74
- $visibilities = array_filter($visibilities);
75
- $collection->getSelect()->where("find_in_set(visibility, '" . implode(',', $visibilities) . "')");
76
-
77
-
78
- $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
79
- echo $xmlObj->startXml(array('store_id'=>Mage::app()->getStore()->getId(),'generated-at' => date('d/m/Y H:i:s', Mage::getModel('core/date')->timestamp(time())), 'size-exportable' => $sizeTotal, 'size-xml' => $collection->count(), 'with-out-of-stock' => intval($this->getConfig()->isExportSoldout()), 'with-not-salable'=> intval($this->getConfig()->isExportNotSalable()) , 'selected-only' => intval($this->getConfig()->isExportFilteredByAttribute()), 'visibilities' => implode(',', $visibilities)));
80
-
81
-
82
- if ($this->getProductSku()) {
83
- $collection->addFieldToFilter('sku', $this->getProductSku());
84
- }
85
- if ($this->getLimit()) {
86
- $collection->getSelect()->limit($this->getLimit());
87
- }
88
-
89
-
90
- Mage::getSingleton('core/resource_iterator')
91
- ->walk($collection->getSelect(), array(array($this, 'displayProductXml')), array());
92
- echo $xmlObj->endXml();
93
- return;
94
- }
95
-
96
- public function displayProductXml($args) {
97
- if (Mage::app()->getRequest()->getActionName() == 'profile') {
98
- Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFlux($args['row']['sku'], Mage::app()->getStore()->getId());
99
- }
100
- echo $args['row']['xml'];
101
- }
102
-
103
- public function getConfig() {
104
- return Mage::getSingleton('profileolabs_shoppingflux/config');
105
- }
106
-
107
- }
 
 
 
 
 
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Block_Export_Flux extends Mage_Core_Block_Abstract {
4
+
5
+ protected function _loadCache() {
6
+ return false;
7
+ }
8
+
9
+ protected function _saveCache($data)
10
+ {
11
+ return;
12
+ }
13
+
14
+ protected function _toHtml() {
15
+ $this->displayOutput();
16
+ return '';
17
+ }
18
+
19
+
20
+ public function displayOutput() {
21
+ Profileolabs_Shoppingflux_Model_Export_Observer::checkStock();
22
+
23
+ $useAllStores = $this->getForceMultiStores() || $this->getConfig()->getUseAllStoreProducts();
24
+ if ($this->getProductSku() && $this->getRequest()->getParam('update') == 1) {
25
+ if(!$this->getConfig()->getUseAllStoreProducts()) {
26
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFlux($this->getProductSku(), Mage::app()->getStore()->getId());
27
+ } else {
28
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFluxForAllStores($this->getProductSku());
29
+ }
30
+ }
31
+
32
+ $maxImportLimit = 1000;
33
+ $memoryLimit = ini_get('memory_limit');
34
+ if (preg_match('%M$%', $memoryLimit)) {
35
+ $memoryLimit = intval($memoryLimit) * 1024 * 1024;
36
+ } else if (preg_match('%G$%', $memoryLimit)) {
37
+ $memoryLimit = intval($memoryLimit) * 1024 * 1024 * 1024;
38
+ } else {
39
+ $memoryLimit = false;
40
+ }
41
+ if($memoryLimit > 0) {
42
+ if($memoryLimit <= 128 * 1024 * 1024) {
43
+ $maxImportLimit = 100;
44
+ } else if($memoryLimit <= 256 * 1024 * 1024) {
45
+ $maxImportLimit = 500;
46
+ } else if($memoryLimit >= 1024 * 1024 * 1024) {
47
+ $maxImportLimit = 3000;
48
+ }else if($memoryLimit >= 2048 * 1024 * 1024) {
49
+ $maxImportLimit = 6000;
50
+ }
51
+ }
52
+
53
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->updateFlux($useAllStores?false:Mage::app()->getStore()->getId(), $this->getLimit() ? $this->getLimit() : $maxImportLimit);
54
+ $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
55
+ $collection->addFieldToFilter('should_export', 1);
56
+ $withNotSalableRetention = $this->getConfig()->isNotSalableRetentionEnabled();
57
+
58
+ if($useAllStores) {
59
+ $collection->getSelect()->group(array('sku'));
60
+ } else {
61
+ $collection->addFieldToFilter('store_id', Mage::app()->getStore()->getId());
62
+ }
63
+ $sizeTotal = $collection->count();
64
+ $collection->clear();
65
+
66
+ if (!$this->getConfig()->isExportNotSalable() && !$withNotSalableRetention) {
67
+ $collection->addFieldToFilter('salable', 1);
68
+ }
69
+ if (!$this->getConfig()->isExportSoldout() && !$withNotSalableRetention) {
70
+ $collection->addFieldToFilter('is_in_stock', 1);
71
+ }
72
+ if ($this->getConfig()->isExportFilteredByAttribute()) {
73
+ $collection->addFieldToFilter('is_in_flux', 1);
74
+ }
75
+ $visibilities = $this->getConfig()->getVisibilitiesToExport();
76
+ $visibilities = array_filter($visibilities);
77
+ $collection->getSelect()->where("find_in_set(visibility, '" . implode(',', $visibilities) . "')");
78
+
79
+
80
+ $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
81
+ echo $xmlObj->startXml(array('store_id'=>Mage::app()->getStore()->getId(),'generated-at' => date('d/m/Y H:i:s', Mage::getModel('core/date')->timestamp(time())), 'size-exportable' => $sizeTotal, 'size-xml' => $collection->count(), 'with-out-of-stock' => intval($this->getConfig()->isExportSoldout()), 'with-not-salable'=> intval($this->getConfig()->isExportNotSalable()) , 'selected-only' => intval($this->getConfig()->isExportFilteredByAttribute()), 'visibilities' => implode(',', $visibilities)));
82
+
83
+
84
+ if ($this->getProductSku()) {
85
+ $collection->addFieldToFilter('sku', $this->getProductSku());
86
+ }
87
+ if ($this->getLimit()) {
88
+ $collection->getSelect()->limit($this->getLimit());
89
+ }
90
+
91
+
92
+ Mage::getSingleton('core/resource_iterator')
93
+ ->walk($collection->getSelect(), array(array($this, 'displayProductXml')), array());
94
+ echo $xmlObj->endXml();
95
+ return;
96
+ }
97
+
98
+ public function displayProductXml($args) {
99
+ if (Mage::app()->getRequest()->getActionName() == 'profile') {
100
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFlux($args['row']['sku'], Mage::app()->getStore()->getId());
101
+ }
102
+ echo $args['row']['xml'];
103
+ }
104
+
105
+ /**
106
+ * @return Profileolabs_Shoppingflux_Model_Config
107
+ */
108
+ public function getConfig() {
109
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
110
+ }
111
+
112
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Export/Tracking.php CHANGED
@@ -1,68 +1,68 @@
1
- <?php
2
- /**
3
- * Profileolabs_Shoppingflux Tracking Block
4
- *
5
- * @category Profileolabs
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait <kassim@profileo.com>
8
- * @deprecated since version 0.5.6
9
- */
10
- class Profileolabs_Shoppingflux_Block_Export_Tracking extends Mage_Core_Block_Text
11
- {
12
-
13
- /**
14
- * Retrieve Shopping flux Account Identifier
15
- *
16
- * @return string
17
- */
18
- public function getLogin()
19
- {
20
- if (!$this->hasData('login')) {
21
- $this->setLogin(Mage::getStoreConfig('shoppingflux_export/general/login'));
22
- }
23
- return $this->getData('login');
24
- }
25
-
26
- /**
27
- * Prepare and return block's html output
28
- *
29
- * @return string
30
- */
31
- protected function _toHtml()
32
- {
33
- if (!Mage::getStoreConfigFlag('shoppingflux_export/general/active')) {
34
- return '';
35
- }
36
-
37
- if($this->getLogin() == "")
38
- return '';
39
-
40
- $quoteId = Mage::getSingleton('checkout/session')->getLastQuoteId();
41
- if(!$quoteId)
42
- return '';
43
-
44
- $quote = Mage::getModel('sales/quote')->load($quoteId);
45
-
46
- $orders = Mage::getResourceModel('sales/order_collection')
47
- ->addAttributeToFilter('quote_id', $quoteId)
48
- ->load();
49
-
50
- foreach($orders as $order)
51
- {
52
- $grandTotal = $order->getBaseGrandTotal();
53
- $incrementId = $order->getIncrementId();
54
-
55
- $this->addText('
56
- <!-- BEGIN Shopping flux Tracking -->
57
- <script type="text/javascript">
58
- //<![CDATA[
59
- document.write(\'<img src="http://www.shopping-flux.com/tracking/?cl='.$this->getLogin().'&mt='.$grandTotal.'&cmd='.$incrementId.'" />\');//]]>
60
- </script>
61
- <!-- END Shopping flux Tracking -->
62
- ');
63
-
64
- }
65
-
66
- return parent::_toHtml();
67
- }
68
- }
1
+ <?php
2
+ /**
3
+ * Profileolabs_Shoppingflux Tracking Block
4
+ *
5
+ * @category Profileolabs
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait <kassim@profileo.com>
8
+ * @deprecated since version 0.5.6
9
+ */
10
+ class Profileolabs_Shoppingflux_Block_Export_Tracking extends Mage_Core_Block_Text
11
+ {
12
+
13
+ /**
14
+ * Retrieve Shopping flux Account Identifier
15
+ *
16
+ * @return string
17
+ */
18
+ public function getLogin()
19
+ {
20
+ if (!$this->hasData('login')) {
21
+ $this->setLogin(Mage::getStoreConfig('shoppingflux_export/general/login'));
22
+ }
23
+ return $this->getData('login');
24
+ }
25
+
26
+ /**
27
+ * Prepare and return block's html output
28
+ *
29
+ * @return string
30
+ */
31
+ protected function _toHtml()
32
+ {
33
+ if (!Mage::getStoreConfigFlag('shoppingflux_export/general/active')) {
34
+ return '';
35
+ }
36
+
37
+ if($this->getLogin() == "")
38
+ return '';
39
+
40
+ $quoteId = Mage::getSingleton('checkout/session')->getLastQuoteId();
41
+ if(!$quoteId)
42
+ return '';
43
+
44
+ $quote = Mage::getModel('sales/quote')->load($quoteId);
45
+
46
+ $orders = Mage::getResourceModel('sales/order_collection')
47
+ ->addAttributeToFilter('quote_id', $quoteId)
48
+ ->load();
49
+
50
+ foreach($orders as $order)
51
+ {
52
+ $grandTotal = $order->getBaseGrandTotal();
53
+ $incrementId = $order->getIncrementId();
54
+
55
+ $this->addText('
56
+ <!-- BEGIN Shopping flux Tracking -->
57
+ <script type="text/javascript">
58
+ //<![CDATA[
59
+ document.write(\'<img src="http://www.shopping-flux.com/tracking/?cl='.$this->getLogin().'&mt='.$grandTotal.'&cmd='.$incrementId.'" />\');//]]>
60
+ </script>
61
+ <!-- END Shopping flux Tracking -->
62
+ ');
63
+
64
+ }
65
+
66
+ return parent::_toHtml();
67
+ }
68
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Cron.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Log grid container
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux_ManageOrders
7
- * @author Vincent Enjalbert
8
- */
9
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Cron extends Mage_Adminhtml_Block_Widget_Grid_Container {
10
-
11
- public function __construct() {
12
- parent::__construct();
13
-
14
- $this->_controller = 'manageorders_adminhtml_cron';
15
- $this->_blockGroup = 'profileolabs_shoppingflux';
16
- $this->_headerText = $this->__('Crons');
17
-
18
- $this->_removeButton('add');
19
- }
20
-
21
- }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Log grid container
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux_ManageOrders
7
+ * @author Vincent Enjalbert
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Cron extends Mage_Adminhtml_Block_Widget_Grid_Container {
10
+
11
+ public function __construct() {
12
+ parent::__construct();
13
+
14
+ $this->_controller = 'manageorders_adminhtml_cron';
15
+ $this->_blockGroup = 'profileolabs_shoppingflux';
16
+ $this->_headerText = $this->__('Crons');
17
+
18
+ $this->_removeButton('add');
19
+ }
20
+
21
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Cron/Grid.php CHANGED
@@ -1,107 +1,107 @@
1
- <?php
2
- /**
3
- * Adminhtml log shopping flux grid
4
- *
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux_ManageOrders
7
- * @author Vincent Enjalbert
8
- */
9
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
- {
11
-
12
-
13
- public function __construct()
14
- {
15
- parent::__construct();
16
- $this->setId('shoppingflux_cron_grid');
17
- $this->setUseAjax(true);
18
- $this->setDefaultSort('date');
19
- $this->setDefaultDir('DESC');
20
- $this->setSaveParametersInSession(true);
21
- $this->setDefaultFilter(
22
- array(
23
- 'job_code' => 'shoppingflux'
24
- )
25
- );
26
- }
27
-
28
-
29
- protected function _prepareCollection()
30
- {
31
- $collection = Mage::getModel("cron/schedule")->getCollection();
32
- $collection->getSelect()->order('schedule_id desc');
33
-
34
- $this->setCollection($collection);
35
- return parent::_prepareCollection();
36
- }
37
-
38
- protected function _prepareColumns()
39
- {
40
-
41
- $this->addColumn('schedule_id', array(
42
- 'header'=> Mage::helper('cron')->__('Schedule Id'),
43
- 'width' => '80px',
44
- 'type' => 'text',
45
- 'index' => 'schedule_id',
46
- ));
47
-
48
- $this->addColumn('job_code', array(
49
- 'header'=> Mage::helper('cron')->__('Job Code'),
50
- 'width' => '80px',
51
- 'type' => 'text',
52
- 'index' => 'job_code',
53
- ));
54
-
55
- $this->addColumn('status', array(
56
- 'header'=> Mage::helper('cron')->__('Status'),
57
- 'width' => '80px',
58
- 'type' => 'text',
59
- 'index' => 'status',
60
- ));
61
-
62
- $this->addColumn('messages', array(
63
- 'header'=> Mage::helper('cron')->__('Messages'),
64
- 'width' => '80px',
65
- 'type' => 'text',
66
- 'index' => 'messages',
67
- ));
68
-
69
- $this->addColumn('scheduled_at', array(
70
- 'header'=> Mage::helper('cron')->__('Scheduled at'),
71
- 'width' => '80px',
72
- 'type' => 'datetime',
73
- 'index' => 'scheduled_at',
74
- ));
75
-
76
-
77
- $this->addColumn('created_at', array(
78
- 'header'=> Mage::helper('cron')->__('Created at'),
79
- 'width' => '80px',
80
- 'type' => 'datetime',
81
- 'index' => 'created_at',
82
- ));
83
-
84
- $this->addColumn('executed_at', array(
85
- 'header'=> Mage::helper('cron')->__('Executed at'),
86
- 'width' => '80px',
87
- 'type' => 'datetime',
88
- 'index' => 'executed_at',
89
- ));
90
-
91
- $this->addColumn('finished_at', array(
92
- 'header'=> Mage::helper('cron')->__('Finished at'),
93
- 'width' => '80px',
94
- 'type' => 'datetime',
95
- 'index' => 'finished_at',
96
- ));
97
-
98
-
99
- return parent::_prepareColumns();
100
- }
101
-
102
- public function getGridUrl()
103
- {
104
- return $this->getUrl('*/*/grid', array('_current'=>true));
105
- }
106
-
107
- }
1
+ <?php
2
+ /**
3
+ * Adminhtml log shopping flux grid
4
+ *
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux_ManageOrders
7
+ * @author Vincent Enjalbert
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Cron_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ $this->setId('shoppingflux_cron_grid');
17
+ $this->setUseAjax(true);
18
+ $this->setDefaultSort('date');
19
+ $this->setDefaultDir('DESC');
20
+ $this->setSaveParametersInSession(true);
21
+ $this->setDefaultFilter(
22
+ array(
23
+ 'job_code' => 'shoppingflux'
24
+ )
25
+ );
26
+ }
27
+
28
+
29
+ protected function _prepareCollection()
30
+ {
31
+ $collection = Mage::getModel("cron/schedule")->getCollection();
32
+ $collection->getSelect()->order('schedule_id desc');
33
+
34
+ $this->setCollection($collection);
35
+ return parent::_prepareCollection();
36
+ }
37
+
38
+ protected function _prepareColumns()
39
+ {
40
+
41
+ $this->addColumn('schedule_id', array(
42
+ 'header'=> Mage::helper('cron')->__('Schedule Id'),
43
+ 'width' => '80px',
44
+ 'type' => 'text',
45
+ 'index' => 'schedule_id',
46
+ ));
47
+
48
+ $this->addColumn('job_code', array(
49
+ 'header'=> Mage::helper('cron')->__('Job Code'),
50
+ 'width' => '80px',
51
+ 'type' => 'text',
52
+ 'index' => 'job_code',
53
+ ));
54
+
55
+ $this->addColumn('status', array(
56
+ 'header'=> Mage::helper('cron')->__('Status'),
57
+ 'width' => '80px',
58
+ 'type' => 'text',
59
+ 'index' => 'status',
60
+ ));
61
+
62
+ $this->addColumn('messages', array(
63
+ 'header'=> Mage::helper('cron')->__('Messages'),
64
+ 'width' => '80px',
65
+ 'type' => 'text',
66
+ 'index' => 'messages',
67
+ ));
68
+
69
+ $this->addColumn('scheduled_at', array(
70
+ 'header'=> Mage::helper('cron')->__('Scheduled at'),
71
+ 'width' => '80px',
72
+ 'type' => 'datetime',
73
+ 'index' => 'scheduled_at',
74
+ ));
75
+
76
+
77
+ $this->addColumn('created_at', array(
78
+ 'header'=> Mage::helper('cron')->__('Created at'),
79
+ 'width' => '80px',
80
+ 'type' => 'datetime',
81
+ 'index' => 'created_at',
82
+ ));
83
+
84
+ $this->addColumn('executed_at', array(
85
+ 'header'=> Mage::helper('cron')->__('Executed at'),
86
+ 'width' => '80px',
87
+ 'type' => 'datetime',
88
+ 'index' => 'executed_at',
89
+ ));
90
+
91
+ $this->addColumn('finished_at', array(
92
+ 'header'=> Mage::helper('cron')->__('Finished at'),
93
+ 'width' => '80px',
94
+ 'type' => 'datetime',
95
+ 'index' => 'finished_at',
96
+ ));
97
+
98
+
99
+ return parent::_prepareColumns();
100
+ }
101
+
102
+ public function getGridUrl()
103
+ {
104
+ return $this->getUrl('*/*/grid', array('_current'=>true));
105
+ }
106
+
107
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Import.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Import extends Mage_Adminhtml_Block_Template
3
- {
4
-
5
-
6
- public function getImportOrdersUrl()
7
- {
8
- return $this->getUrl('*/*/importOrders');
9
- }
10
-
11
-
12
- }
1
+ <?php
2
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Import extends Mage_Adminhtml_Block_Template
3
+ {
4
+
5
+
6
+ public function getImportOrdersUrl()
7
+ {
8
+ return $this->getUrl('*/*/importOrders');
9
+ }
10
+
11
+
12
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Log.php CHANGED
@@ -1,25 +1,25 @@
1
- <?php
2
- /**
3
- * Shopping Flux Log grid container
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux_ManageOrders
6
- * @author kassim belghait
7
- */
8
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Log extends Mage_Adminhtml_Block_Widget_Grid_Container
9
- {
10
- public function __construct()
11
- {
12
- parent::__construct();
13
-
14
- $this->_controller = 'manageorders_adminhtml_log';
15
- $this->_blockGroup = 'profileolabs_shoppingflux';
16
- $this->_headerText = $this->__('Shopping flux log');
17
-
18
- $this->_removeButton('add');
19
- $this->_addButton("deleteAll",array(
20
- 'label' => Mage::helper('profileolabs_shoppingflux')->__('Delete'),
21
- 'onclick' => "setLocation('{$this->getUrl('*/*/delete')}')",
22
- 'class' => 'delete'
23
- ));
24
- }
25
  }
1
+ <?php
2
+ /**
3
+ * Shopping Flux Log grid container
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux_ManageOrders
6
+ * @author kassim belghait
7
+ */
8
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Log extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $this->_controller = 'manageorders_adminhtml_log';
15
+ $this->_blockGroup = 'profileolabs_shoppingflux';
16
+ $this->_headerText = $this->__('Shopping flux log');
17
+
18
+ $this->_removeButton('add');
19
+ $this->_addButton("deleteAll",array(
20
+ 'label' => Mage::helper('profileolabs_shoppingflux')->__('Delete'),
21
+ 'onclick' => "setLocation('{$this->getUrl('*/*/delete')}')",
22
+ 'class' => 'delete'
23
+ ));
24
+ }
25
  }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Log/Grid.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
- /**
3
- * Adminhtml log shopping flux grid
4
- *
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux_ManageOrders
7
- * @author kassim belghait
8
- */
9
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Log_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
- {
11
-
12
-
13
- public function __construct()
14
- {
15
- parent::__construct();
16
- $this->setId('shoppingflux_log_grid');
17
- $this->setUseAjax(true);
18
- $this->setDefaultSort('date');
19
- $this->setDefaultDir('DESC');
20
- $this->setSaveParametersInSession(true);
21
- }
22
-
23
-
24
- protected function _prepareCollection()
25
- {
26
- $collection = Mage::getModel("profileolabs_shoppingflux/manageorders_log")->getCollection();
27
-
28
- $this->setCollection($collection);
29
- return parent::_prepareCollection();
30
- }
31
-
32
- protected function _prepareColumns()
33
- {
34
-
35
- $this->addColumn('id', array(
36
- 'header'=> Mage::helper('profileolabs_shoppingflux')->__('ID'),
37
- 'width' => '80px',
38
- 'type' => 'text',
39
- 'index' => 'id',
40
- ));
41
-
42
-
43
- $this->addColumn('date', array(
44
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('Created at'),
45
- 'index' => 'date',
46
- 'type' => 'datetime',
47
- 'width' => '100px',
48
- ));
49
-
50
- $this->addColumn('message', array(
51
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('Message'),
52
- 'index' => 'message',
53
- ));
54
-
55
-
56
- return parent::_prepareColumns();
57
- }
58
-
59
- public function getGridUrl()
60
- {
61
- return $this->getUrl('*/*/grid', array('_current'=>true));
62
- }
63
-
64
- }
1
+ <?php
2
+ /**
3
+ * Adminhtml log shopping flux grid
4
+ *
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux_ManageOrders
7
+ * @author kassim belghait
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Log_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+
12
+
13
+ public function __construct()
14
+ {
15
+ parent::__construct();
16
+ $this->setId('shoppingflux_log_grid');
17
+ $this->setUseAjax(true);
18
+ $this->setDefaultSort('date');
19
+ $this->setDefaultDir('DESC');
20
+ $this->setSaveParametersInSession(true);
21
+ }
22
+
23
+
24
+ protected function _prepareCollection()
25
+ {
26
+ $collection = Mage::getModel("profileolabs_shoppingflux/manageorders_log")->getCollection();
27
+
28
+ $this->setCollection($collection);
29
+ return parent::_prepareCollection();
30
+ }
31
+
32
+ protected function _prepareColumns()
33
+ {
34
+
35
+ $this->addColumn('id', array(
36
+ 'header'=> Mage::helper('profileolabs_shoppingflux')->__('ID'),
37
+ 'width' => '80px',
38
+ 'type' => 'text',
39
+ 'index' => 'id',
40
+ ));
41
+
42
+
43
+ $this->addColumn('date', array(
44
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('Created at'),
45
+ 'index' => 'date',
46
+ 'type' => 'datetime',
47
+ 'width' => '100px',
48
+ ));
49
+
50
+ $this->addColumn('message', array(
51
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('Message'),
52
+ 'index' => 'message',
53
+ ));
54
+
55
+
56
+ return parent::_prepareColumns();
57
+ }
58
+
59
+ public function getGridUrl()
60
+ {
61
+ return $this->getUrl('*/*/grid', array('_current'=>true));
62
+ }
63
+
64
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Order.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- /**
3
- * Shopping Flux Service
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux_ManageOrders
6
- * @author kassim belghait
7
- */
8
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
9
- {
10
- public function __construct()
11
- {
12
- parent::__construct();
13
-
14
- $this->_controller = 'manageorders_adminhtml_order';
15
- $this->_blockGroup = 'profileolabs_shoppingflux';
16
- $this->_headerText = $this->__('Shopping flux orders');
17
-
18
- $this->_removeButton('add');
19
- }
20
  }
1
+ <?php
2
+ /**
3
+ * Shopping Flux Service
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux_ManageOrders
6
+ * @author kassim belghait
7
+ */
8
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Order extends Mage_Adminhtml_Block_Widget_Grid_Container
9
+ {
10
+ public function __construct()
11
+ {
12
+ parent::__construct();
13
+
14
+ $this->_controller = 'manageorders_adminhtml_order';
15
+ $this->_blockGroup = 'profileolabs_shoppingflux';
16
+ $this->_headerText = $this->__('Shopping flux orders');
17
+
18
+ $this->_removeButton('add');
19
+ }
20
  }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Order/Grid.php CHANGED
@@ -1,235 +1,235 @@
1
- <?php
2
- /**
3
- * Adminhtml sales orders shopping flux grid
4
- *
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux_ManageOrders
7
- * @author kassim belghait
8
- */
9
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
- {
11
-
12
- protected $_withGrid = true;
13
-
14
- public function __construct()
15
- {
16
- parent::__construct();
17
- $this->setId('sales_order_grid');
18
- $this->setUseAjax(true);
19
- $this->setDefaultSort('created_at');
20
- $this->setDefaultDir('DESC');
21
- $this->setSaveParametersInSession(true);
22
- }
23
-
24
- /**
25
- * Retrieve collection class
26
- *
27
- * @return string
28
- */
29
- protected function _getCollectionClass()
30
- {
31
- $path = Mage::getBaseDir()."/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php";
32
- //die($path);
33
- if(file_exists($path))
34
- return 'sales/order_grid_collection';
35
-
36
- $this->_withGrid = false;
37
- return 'sales/order_collection';
38
- }
39
-
40
- protected function _prepareCollection()
41
- {
42
- $collection = Mage::getResourceModel($this->_getCollectionClass());
43
- $collection->addAttributeToFilter('from_shoppingflux',1);
44
-
45
- if(!$this->_withGrid)
46
- {
47
- $collection->addAttributeToSelect('*')
48
- ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
49
- ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
50
- ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
51
- ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
52
- ->addExpressionAttributeToSelect('billing_name',
53
- 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
54
- array('billing_firstname', 'billing_lastname'))
55
- ->addExpressionAttributeToSelect('shipping_name',
56
- 'CONCAT({{shipping_firstname}}, IFNULL(CONCAT(\' \', {{shipping_lastname}}), \'\'))',
57
- array('shipping_firstname', 'shipping_lastname'));
58
- }
59
-
60
- $this->setCollection($collection);
61
- return parent::_prepareCollection();
62
- }
63
-
64
- protected function _prepareColumns()
65
- {
66
-
67
- $this->addColumn('real_order_id', array(
68
- 'header'=> Mage::helper('sales')->__('Order #'),
69
- 'width' => '80px',
70
- 'type' => 'text',
71
- 'index' => 'increment_id',
72
- ));
73
-
74
- if (!Mage::app()->isSingleStoreMode()) {
75
- $this->addColumn('store_id', array(
76
- 'header' => Mage::helper('sales')->__('Purchased From (Store)'),
77
- 'index' => 'store_id',
78
- 'type' => 'store',
79
- 'store_view'=> true,
80
- 'display_deleted' => true,
81
- ));
82
- }
83
-
84
- $this->addColumn('created_at', array(
85
- 'header' => Mage::helper('sales')->__('Purchased On'),
86
- 'index' => 'created_at',
87
- 'type' => 'datetime',
88
- 'width' => '100px',
89
- ));
90
-
91
- $this->addColumn('billing_name', array(
92
- 'header' => Mage::helper('sales')->__('Bill to Name'),
93
- 'index' => 'billing_name',
94
- ));
95
-
96
- $this->addColumn('shipping_name', array(
97
- 'header' => Mage::helper('sales')->__('Ship to Name'),
98
- 'index' => 'shipping_name',
99
- ));
100
-
101
- $this->addColumn('base_grand_total', array(
102
- 'header' => Mage::helper('sales')->__('G.T. (Base)'),
103
- 'index' => 'base_grand_total',
104
- 'type' => 'currency',
105
- 'currency' => 'base_currency_code',
106
- ));
107
-
108
- $this->addColumn('grand_total', array(
109
- 'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
110
- 'index' => 'grand_total',
111
- 'type' => 'currency',
112
- 'currency' => 'order_currency_code',
113
- ));
114
-
115
- //Data shopping flux
116
-
117
- $this->addColumn('order_id_shoppingflux', array(
118
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux ID'),
119
- 'index' => 'order_id_shoppingflux',
120
- ));
121
-
122
- $this->addColumn('marketplace_shoppingflux', array(
123
- 'header' => Mage::helper('profileolabs_shoppingflux')->__('Marketplace'),
124
- 'index' => 'marketplace_shoppingflux',
125
- ));
126
-
127
- $this->addColumn('fees_shoppingflux', array(
128
- 'header'=> Mage::helper('profileolabs_shoppingflux')->__('Fees'),
129
- 'type' => 'currency',
130
- 'index' => 'fees_shoppingflux',
131
- 'currency' => 'base_currency_code',
132
- ));
133
-
134
- //END data Shopping flux
135
-
136
- $this->addColumn('status', array(
137
- 'header' => Mage::helper('sales')->__('Status'),
138
- 'index' => 'status',
139
- 'type' => 'options',
140
- 'width' => '70px',
141
- 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
142
- ));
143
-
144
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
145
- $this->addColumn('action',
146
- array(
147
- 'header' => Mage::helper('sales')->__('Action'),
148
- 'width' => '50px',
149
- 'type' => 'action',
150
- 'getter' => 'getId',
151
- 'actions' => array(
152
- array(
153
- 'caption' => Mage::helper('sales')->__('View'),
154
- 'url' => array('base'=>'adminhtml/sales_order/view'),
155
- 'field' => 'order_id'
156
- )
157
- ),
158
- 'filter' => false,
159
- 'sortable' => false,
160
- 'index' => 'stores',
161
- 'is_system' => true,
162
- ));
163
- }
164
- //$this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));
165
-
166
- $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
167
- $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
168
-
169
- return parent::_prepareColumns();
170
- }
171
-
172
- protected function _prepareMassaction()
173
- {
174
- $this->setMassactionIdField('entity_id');
175
- $this->getMassactionBlock()->setFormFieldName('order_ids');
176
- $this->getMassactionBlock()->setUseSelectAll(false);
177
-
178
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
179
- $this->getMassactionBlock()->addItem('cancel_order', array(
180
- 'label'=> Mage::helper('sales')->__('Cancel'),
181
- 'url' => $this->getUrl('adminhtml/sales_order/massCancel'),
182
- ));
183
- }
184
-
185
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
186
- $this->getMassactionBlock()->addItem('hold_order', array(
187
- 'label'=> Mage::helper('sales')->__('Hold'),
188
- 'url' => $this->getUrl('adminhtml/sales_order/massHold'),
189
- ));
190
- }
191
-
192
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
193
- $this->getMassactionBlock()->addItem('unhold_order', array(
194
- 'label'=> Mage::helper('sales')->__('Unhold'),
195
- 'url' => $this->getUrl('adminhtml/sales_order/massUnhold'),
196
- ));
197
- }
198
-
199
- $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
200
- 'label'=> Mage::helper('sales')->__('Print Invoices'),
201
- 'url' => $this->getUrl('adminhtml/sales_order/pdfinvoices'),
202
- ));
203
-
204
- $this->getMassactionBlock()->addItem('pdfshipments_order', array(
205
- 'label'=> Mage::helper('sales')->__('Print Packingslips'),
206
- 'url' => $this->getUrl('adminhtml/sales_order/pdfshipments'),
207
- ));
208
-
209
- $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
210
- 'label'=> Mage::helper('sales')->__('Print Credit Memos'),
211
- 'url' => $this->getUrl('adminhtml/sales_order/pdfcreditmemos'),
212
- ));
213
-
214
- $this->getMassactionBlock()->addItem('pdfdocs_order', array(
215
- 'label'=> Mage::helper('sales')->__('Print All'),
216
- 'url' => $this->getUrl('adminhtml/sales_order/pdfdocs'),
217
- ));
218
-
219
- return $this;
220
- }
221
-
222
- public function getRowUrl($row)
223
- {
224
- if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
225
- return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId()));
226
- }
227
- return false;
228
- }
229
-
230
- public function getGridUrl()
231
- {
232
- return $this->getUrl('*/*/grid', array('_current'=>true));
233
- }
234
-
235
- }
1
+ <?php
2
+ /**
3
+ * Adminhtml sales orders shopping flux grid
4
+ *
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux_ManageOrders
7
+ * @author kassim belghait
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
10
+ {
11
+
12
+ protected $_withGrid = true;
13
+
14
+ public function __construct()
15
+ {
16
+ parent::__construct();
17
+ $this->setId('sales_order_grid');
18
+ $this->setUseAjax(true);
19
+ $this->setDefaultSort('created_at');
20
+ $this->setDefaultDir('DESC');
21
+ $this->setSaveParametersInSession(true);
22
+ }
23
+
24
+ /**
25
+ * Retrieve collection class
26
+ *
27
+ * @return string
28
+ */
29
+ protected function _getCollectionClass()
30
+ {
31
+ $path = Mage::getBaseDir()."/app/code/core/Mage/Sales/Model/Mysql4/Order/Grid/Collection.php";
32
+ //die($path);
33
+ if(file_exists($path))
34
+ return 'sales/order_grid_collection';
35
+
36
+ $this->_withGrid = false;
37
+ return 'sales/order_collection';
38
+ }
39
+
40
+ protected function _prepareCollection()
41
+ {
42
+ $collection = Mage::getResourceModel($this->_getCollectionClass());
43
+ $collection->addAttributeToFilter('from_shoppingflux',1);
44
+
45
+ if(!$this->_withGrid)
46
+ {
47
+ $collection->addAttributeToSelect('*')
48
+ ->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left')
49
+ ->joinAttribute('billing_lastname', 'order_address/lastname', 'billing_address_id', null, 'left')
50
+ ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
51
+ ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
52
+ ->addExpressionAttributeToSelect('billing_name',
53
+ 'CONCAT({{billing_firstname}}, " ", {{billing_lastname}})',
54
+ array('billing_firstname', 'billing_lastname'))
55
+ ->addExpressionAttributeToSelect('shipping_name',
56
+ 'CONCAT({{shipping_firstname}}, IFNULL(CONCAT(\' \', {{shipping_lastname}}), \'\'))',
57
+ array('shipping_firstname', 'shipping_lastname'));
58
+ }
59
+
60
+ $this->setCollection($collection);
61
+ return parent::_prepareCollection();
62
+ }
63
+
64
+ protected function _prepareColumns()
65
+ {
66
+
67
+ $this->addColumn('real_order_id', array(
68
+ 'header'=> Mage::helper('sales')->__('Order #'),
69
+ 'width' => '80px',
70
+ 'type' => 'text',
71
+ 'index' => 'increment_id',
72
+ ));
73
+
74
+ if (!Mage::app()->isSingleStoreMode()) {
75
+ $this->addColumn('store_id', array(
76
+ 'header' => Mage::helper('sales')->__('Purchased From (Store)'),
77
+ 'index' => 'store_id',
78
+ 'type' => 'store',
79
+ 'store_view'=> true,
80
+ 'display_deleted' => true,
81
+ ));
82
+ }
83
+
84
+ $this->addColumn('created_at', array(
85
+ 'header' => Mage::helper('sales')->__('Purchased On'),
86
+ 'index' => 'created_at',
87
+ 'type' => 'datetime',
88
+ 'width' => '100px',
89
+ ));
90
+
91
+ $this->addColumn('billing_name', array(
92
+ 'header' => Mage::helper('sales')->__('Bill to Name'),
93
+ 'index' => 'billing_name',
94
+ ));
95
+
96
+ $this->addColumn('shipping_name', array(
97
+ 'header' => Mage::helper('sales')->__('Ship to Name'),
98
+ 'index' => 'shipping_name',
99
+ ));
100
+
101
+ $this->addColumn('base_grand_total', array(
102
+ 'header' => Mage::helper('sales')->__('G.T. (Base)'),
103
+ 'index' => 'base_grand_total',
104
+ 'type' => 'currency',
105
+ 'currency' => 'base_currency_code',
106
+ ));
107
+
108
+ $this->addColumn('grand_total', array(
109
+ 'header' => Mage::helper('sales')->__('G.T. (Purchased)'),
110
+ 'index' => 'grand_total',
111
+ 'type' => 'currency',
112
+ 'currency' => 'order_currency_code',
113
+ ));
114
+
115
+ //Data shopping flux
116
+
117
+ $this->addColumn('order_id_shoppingflux', array(
118
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux ID'),
119
+ 'index' => 'order_id_shoppingflux',
120
+ ));
121
+
122
+ $this->addColumn('marketplace_shoppingflux', array(
123
+ 'header' => Mage::helper('profileolabs_shoppingflux')->__('Marketplace'),
124
+ 'index' => 'marketplace_shoppingflux',
125
+ ));
126
+
127
+ $this->addColumn('fees_shoppingflux', array(
128
+ 'header'=> Mage::helper('profileolabs_shoppingflux')->__('Fees'),
129
+ 'type' => 'currency',
130
+ 'index' => 'fees_shoppingflux',
131
+ 'currency' => 'base_currency_code',
132
+ ));
133
+
134
+ //END data Shopping flux
135
+
136
+ $this->addColumn('status', array(
137
+ 'header' => Mage::helper('sales')->__('Status'),
138
+ 'index' => 'status',
139
+ 'type' => 'options',
140
+ 'width' => '70px',
141
+ 'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
142
+ ));
143
+
144
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
145
+ $this->addColumn('action',
146
+ array(
147
+ 'header' => Mage::helper('sales')->__('Action'),
148
+ 'width' => '50px',
149
+ 'type' => 'action',
150
+ 'getter' => 'getId',
151
+ 'actions' => array(
152
+ array(
153
+ 'caption' => Mage::helper('sales')->__('View'),
154
+ 'url' => array('base'=>'adminhtml/sales_order/view'),
155
+ 'field' => 'order_id'
156
+ )
157
+ ),
158
+ 'filter' => false,
159
+ 'sortable' => false,
160
+ 'index' => 'stores',
161
+ 'is_system' => true,
162
+ ));
163
+ }
164
+ //$this->addRssList('rss/order/new', Mage::helper('sales')->__('New Order RSS'));
165
+
166
+ $this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
167
+ $this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel XML'));
168
+
169
+ return parent::_prepareColumns();
170
+ }
171
+
172
+ protected function _prepareMassaction()
173
+ {
174
+ $this->setMassactionIdField('entity_id');
175
+ $this->getMassactionBlock()->setFormFieldName('order_ids');
176
+ $this->getMassactionBlock()->setUseSelectAll(false);
177
+
178
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/cancel')) {
179
+ $this->getMassactionBlock()->addItem('cancel_order', array(
180
+ 'label'=> Mage::helper('sales')->__('Cancel'),
181
+ 'url' => $this->getUrl('adminhtml/sales_order/massCancel'),
182
+ ));
183
+ }
184
+
185
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/hold')) {
186
+ $this->getMassactionBlock()->addItem('hold_order', array(
187
+ 'label'=> Mage::helper('sales')->__('Hold'),
188
+ 'url' => $this->getUrl('adminhtml/sales_order/massHold'),
189
+ ));
190
+ }
191
+
192
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/unhold')) {
193
+ $this->getMassactionBlock()->addItem('unhold_order', array(
194
+ 'label'=> Mage::helper('sales')->__('Unhold'),
195
+ 'url' => $this->getUrl('adminhtml/sales_order/massUnhold'),
196
+ ));
197
+ }
198
+
199
+ $this->getMassactionBlock()->addItem('pdfinvoices_order', array(
200
+ 'label'=> Mage::helper('sales')->__('Print Invoices'),
201
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfinvoices'),
202
+ ));
203
+
204
+ $this->getMassactionBlock()->addItem('pdfshipments_order', array(
205
+ 'label'=> Mage::helper('sales')->__('Print Packingslips'),
206
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfshipments'),
207
+ ));
208
+
209
+ $this->getMassactionBlock()->addItem('pdfcreditmemos_order', array(
210
+ 'label'=> Mage::helper('sales')->__('Print Credit Memos'),
211
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfcreditmemos'),
212
+ ));
213
+
214
+ $this->getMassactionBlock()->addItem('pdfdocs_order', array(
215
+ 'label'=> Mage::helper('sales')->__('Print All'),
216
+ 'url' => $this->getUrl('adminhtml/sales_order/pdfdocs'),
217
+ ));
218
+
219
+ return $this;
220
+ }
221
+
222
+ public function getRowUrl($row)
223
+ {
224
+ if (Mage::getSingleton('admin/session')->isAllowed('sales/order/actions/view')) {
225
+ return $this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId()));
226
+ }
227
+ return false;
228
+ }
229
+
230
+ public function getGridUrl()
231
+ {
232
+ return $this->getUrl('*/*/grid', array('_current'=>true));
233
+ }
234
+
235
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/Order/View/Tab/Shoppingflux.php CHANGED
@@ -1,47 +1,47 @@
1
- <?php
2
- /**
3
- * Adminhtml sales orders shopping flux grid
4
- *
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux_ManageOrders
7
- * @author kassim belghait
8
- */
9
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Order_View_Tab_Shoppingflux
10
- extends Mage_Adminhtml_Block_Sales_Order_Abstract
11
- implements Mage_Adminhtml_Block_Widget_Tab_Interface
12
- {
13
- protected function _construct()
14
- {
15
- parent::_construct();
16
- $this->setTemplate('profileolabs/shoppingflux/manageorders/sales/order/view/tab/shoppingflux.phtml');
17
- }
18
-
19
-
20
- public function getOrder()
21
- {
22
- return Mage::registry('current_order');
23
- }
24
-
25
- public function getTabTitle()
26
- {
27
- return $this->getTabLabel();
28
- }
29
-
30
- public function getTabLabel()
31
- {
32
- return Mage::helper('profileolabs_shoppingflux')->__('Shopping Flux');
33
- }
34
-
35
- public function canShowTab()
36
- {
37
- return $this->getOrder()->getFromShoppingflux();
38
- }
39
-
40
-
41
- public function isHidden()
42
- {
43
- return false;
44
- }
45
-
46
-
47
- }
1
+ <?php
2
+ /**
3
+ * Adminhtml sales orders shopping flux grid
4
+ *
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux_ManageOrders
7
+ * @author kassim belghait
8
+ */
9
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_Order_View_Tab_Shoppingflux
10
+ extends Mage_Adminhtml_Block_Sales_Order_Abstract
11
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
12
+ {
13
+ protected function _construct()
14
+ {
15
+ parent::_construct();
16
+ $this->setTemplate('profileolabs/shoppingflux/manageorders/sales/order/view/tab/shoppingflux.phtml');
17
+ }
18
+
19
+
20
+ public function getOrder()
21
+ {
22
+ return Mage::registry('current_order');
23
+ }
24
+
25
+ public function getTabTitle()
26
+ {
27
+ return $this->getTabLabel();
28
+ }
29
+
30
+ public function getTabLabel()
31
+ {
32
+ return Mage::helper('profileolabs_shoppingflux')->__('Shopping Flux');
33
+ }
34
+
35
+ public function canShowTab()
36
+ {
37
+ return $this->getOrder()->getFromShoppingflux();
38
+ }
39
+
40
+
41
+ public function isHidden()
42
+ {
43
+ return false;
44
+ }
45
+
46
+
47
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/System/Config/Form/Fieldset/Customer/Group.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_System_Config_Form_Fieldset_Customer_Group extends Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract {
4
-
5
- public function render(Varien_Data_Form_Element_Abstract $element) {
6
- if(!$this->shouldRenderUnregistered()) {
7
- return parent::render($element);
8
- }
9
-
10
- $html = $this->_getHeaderHtml($element);
11
-
12
-
13
- $marketplaceCsvFile = Mage::getModuleDir( '', 'Profileolabs_Shoppingflux' ) . DS . 'etc' . DS . 'marketplaces.csv';
14
- $marketplaces = file($marketplaceCsvFile);
15
-
16
-
17
-
18
- $i = 1;
19
- foreach($marketplaces as $marketplace) {
20
- $this->_addCustomerGroupField($element, $marketplace, 10*$i++);
21
- }
22
-
23
-
24
- foreach ($element->getSortedElements() as $field) {
25
- $html .= $field->toHtml();
26
- }
27
-
28
- $html .= $this->_getFooterHtml($element);
29
-
30
- return $html;
31
- }
32
-
33
- protected function _getHeaderHtml($element) {
34
- $html = parent::_getHeaderHtml($element);
35
- return $html;
36
- }
37
-
38
- protected function _getFieldRenderer() {
39
- if (empty($this->_fieldRenderer)) {
40
- $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
41
- }
42
- return $this->_fieldRenderer;
43
- }
44
-
45
- protected function _getDummyElement() {
46
- if (empty($this->_dummyElement)) {
47
- $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
48
- }
49
- return $this->_dummyElement;
50
- }
51
-
52
- protected function _getNiceName($index) {
53
- return ucwords(str_replace('_', ' ', $index));
54
- }
55
-
56
-
57
- protected function _addCustomerGroupField($fieldset, $marketplace, $sortOrder) {
58
- $customerGroup = strtolower(preg_replace('%[^a-zA-Z0-9_]%', '', $marketplace))."_group";
59
- $configData = $this->getConfigData();
60
- $path = 'shoppingflux_mo/import_customer/' . $customerGroup;
61
- $data = '';
62
- $inherit = false;
63
- if (isset($configData[$path])) {
64
- $data = $configData[$path];
65
- $inherit = false;
66
- } else {
67
- if($this->getForm()->getConfigRoot()) {
68
- $data = (string) $this->getForm()->getConfigRoot()->descend($path);
69
- $inherit = true;
70
- }
71
- }
72
- $e = $this->_getDummyElement();
73
- $fieldset->addField($customerGroup, 'select', array(
74
- 'name' => 'groups[import_customer][fields][' . $customerGroup . '][value]',
75
- 'label' => Mage::helper('profileolabs_shoppingflux')->__('%s customer group', $this->_getNiceName($marketplace)),
76
- 'comment' => Mage::helper('profileolabs_shoppingflux')->__('Leave empty to use default group'),
77
- 'value' => $data,
78
- 'values' => Mage::getSingleton('adminhtml/system_config_source_customer_group')->toOptionArray(),
79
- 'sort_order' => $sortOrder,
80
- 'inherit' => $inherit,
81
- 'can_use_default_value' => 0,
82
- 'can_use_website_value' => 0,
83
- ))->setRenderer($this->_getFieldRenderer());
84
-
85
- }
86
-
87
-
88
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_System_Config_Form_Fieldset_Customer_Group extends Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract {
4
+
5
+ public function render(Varien_Data_Form_Element_Abstract $element) {
6
+ if(!$this->shouldRenderUnregistered()) {
7
+ return parent::render($element);
8
+ }
9
+
10
+ $html = $this->_getHeaderHtml($element);
11
+
12
+
13
+ $marketplaceCsvFile = Mage::getModuleDir( '', 'Profileolabs_Shoppingflux' ) . DS . 'etc' . DS . 'marketplaces.csv';
14
+ $marketplaces = file($marketplaceCsvFile);
15
+
16
+
17
+
18
+ $i = 1;
19
+ foreach($marketplaces as $marketplace) {
20
+ $this->_addCustomerGroupField($element, $marketplace, 10*$i++);
21
+ }
22
+
23
+
24
+ foreach ($element->getSortedElements() as $field) {
25
+ $html .= $field->toHtml();
26
+ }
27
+
28
+ $html .= $this->_getFooterHtml($element);
29
+
30
+ return $html;
31
+ }
32
+
33
+ protected function _getHeaderHtml($element) {
34
+ $html = parent::_getHeaderHtml($element);
35
+ return $html;
36
+ }
37
+
38
+ protected function _getFieldRenderer() {
39
+ if (empty($this->_fieldRenderer)) {
40
+ $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
41
+ }
42
+ return $this->_fieldRenderer;
43
+ }
44
+
45
+ protected function _getDummyElement() {
46
+ if (empty($this->_dummyElement)) {
47
+ $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
48
+ }
49
+ return $this->_dummyElement;
50
+ }
51
+
52
+ protected function _getNiceName($index) {
53
+ return ucwords(str_replace('_', ' ', $index));
54
+ }
55
+
56
+
57
+ protected function _addCustomerGroupField($fieldset, $marketplace, $sortOrder) {
58
+ $customerGroup = strtolower(preg_replace('%[^a-zA-Z0-9_]%', '', $marketplace))."_group";
59
+ $configData = $this->getConfigData();
60
+ $path = 'shoppingflux_mo/import_customer/' . $customerGroup;
61
+ $data = '';
62
+ $inherit = false;
63
+ if (isset($configData[$path])) {
64
+ $data = $configData[$path];
65
+ $inherit = false;
66
+ } else {
67
+ if($this->getForm()->getConfigRoot()) {
68
+ $data = (string) $this->getForm()->getConfigRoot()->descend($path);
69
+ $inherit = true;
70
+ }
71
+ }
72
+ $e = $this->_getDummyElement();
73
+ $fieldset->addField($customerGroup, 'select', array(
74
+ 'name' => 'groups[import_customer][fields][' . $customerGroup . '][value]',
75
+ 'label' => Mage::helper('profileolabs_shoppingflux')->__('%s customer group', $this->_getNiceName($marketplace)),
76
+ 'comment' => Mage::helper('profileolabs_shoppingflux')->__('Leave empty to use default group'),
77
+ 'value' => $data,
78
+ 'values' => Mage::getSingleton('adminhtml/system_config_source_customer_group')->toOptionArray(),
79
+ 'sort_order' => $sortOrder,
80
+ 'inherit' => $inherit,
81
+ 'can_use_default_value' => 0,
82
+ 'can_use_website_value' => 0,
83
+ ))->setRenderer($this->_getFieldRenderer());
84
+
85
+ }
86
+
87
+
88
  }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/System/Config/Form/Fieldset/Shipping/Method.php CHANGED
@@ -1,88 +1,88 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_System_Config_Form_Fieldset_Shipping_Method extends Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract {
4
-
5
- public function render(Varien_Data_Form_Element_Abstract $element) {
6
- if(!$this->shouldRenderUnregistered()) {
7
- return parent::render($element);
8
- }
9
-
10
- $html = $this->_getHeaderHtml($element);
11
-
12
-
13
- $marketplaceCsvFile = Mage::getModuleDir( '', 'Profileolabs_Shoppingflux' ) . DS . 'etc' . DS . 'marketplaces.csv';
14
- $marketplaces = file($marketplaceCsvFile);
15
-
16
- $i = 1;
17
- foreach($marketplaces as $marketplace) {
18
- $this->_addShippingMethodField($element, $marketplace, 10*$i++);
19
- }
20
-
21
-
22
- foreach ($element->getSortedElements() as $field) {
23
- $html .= $field->toHtml();
24
- }
25
-
26
- $html .= $this->_getFooterHtml($element);
27
-
28
- return $html;
29
- }
30
-
31
- protected function _getHeaderHtml($element) {
32
- $html = parent::_getHeaderHtml($element);
33
- return $html;
34
- }
35
-
36
- protected function _getFieldRenderer() {
37
- if (empty($this->_fieldRenderer)) {
38
- $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
39
- }
40
- return $this->_fieldRenderer;
41
- }
42
-
43
- protected function _getDummyElement() {
44
- if (empty($this->_dummyElement)) {
45
- $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
46
- }
47
- return $this->_dummyElement;
48
- }
49
-
50
- protected function _getNiceName($index) {
51
- return ucwords(str_replace('_', ' ', $index));
52
- }
53
-
54
-
55
- protected function _addShippingMethodField($fieldset, $marketplace, $sortOrder) {
56
- $shippingMethod = strtolower(preg_replace('%[^a-zA-Z0-9_]%', '', $marketplace))."_method";
57
- $configData = $this->getConfigData();
58
- $path = 'shoppingflux_mo/shipping_method/' . $shippingMethod;
59
- $data = '';
60
- $inherit = false;
61
- if (isset($configData[$path])) {
62
- $data = $configData[$path];
63
- $inherit = false;
64
- } else {
65
- if($this->getForm()->getConfigRoot()) {
66
- $data = (string) $this->getForm()->getConfigRoot()->descend($path);
67
- $inherit = true;
68
- }
69
- }
70
- $e = $this->_getDummyElement();
71
- $fieldset->addField($shippingMethod, 'select', array(
72
- 'name' => 'groups[shipping_method][fields][' . $shippingMethod . '][value]',
73
- 'label' => Mage::helper('profileolabs_shoppingflux')->__('Shipping Method for %s', $this->_getNiceName($marketplace)),
74
- 'comment' => Mage::helper('profileolabs_shoppingflux')->__('Leave empty to use default shipping method.'),
75
- 'value' => $data,
76
- 'values' => Mage::getSingleton('adminhtml/system_config_source_shipping_allmethods')->toOptionArray(),
77
- 'sort_order' => $sortOrder,
78
- 'inherit' => $inherit,
79
- 'can_use_default_value' => 0,
80
- 'can_use_website_value' => 0,
81
- ))->setRenderer($this->_getFieldRenderer());
82
-
83
- }
84
-
85
-
86
-
87
-
88
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_System_Config_Form_Fieldset_Shipping_Method extends Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract {
4
+
5
+ public function render(Varien_Data_Form_Element_Abstract $element) {
6
+ if(!$this->shouldRenderUnregistered()) {
7
+ return parent::render($element);
8
+ }
9
+
10
+ $html = $this->_getHeaderHtml($element);
11
+
12
+
13
+ $marketplaceCsvFile = Mage::getModuleDir( '', 'Profileolabs_Shoppingflux' ) . DS . 'etc' . DS . 'marketplaces.csv';
14
+ $marketplaces = file($marketplaceCsvFile);
15
+
16
+ $i = 1;
17
+ foreach($marketplaces as $marketplace) {
18
+ $this->_addShippingMethodField($element, $marketplace, 10*$i++);
19
+ }
20
+
21
+
22
+ foreach ($element->getSortedElements() as $field) {
23
+ $html .= $field->toHtml();
24
+ }
25
+
26
+ $html .= $this->_getFooterHtml($element);
27
+
28
+ return $html;
29
+ }
30
+
31
+ protected function _getHeaderHtml($element) {
32
+ $html = parent::_getHeaderHtml($element);
33
+ return $html;
34
+ }
35
+
36
+ protected function _getFieldRenderer() {
37
+ if (empty($this->_fieldRenderer)) {
38
+ $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
39
+ }
40
+ return $this->_fieldRenderer;
41
+ }
42
+
43
+ protected function _getDummyElement() {
44
+ if (empty($this->_dummyElement)) {
45
+ $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
46
+ }
47
+ return $this->_dummyElement;
48
+ }
49
+
50
+ protected function _getNiceName($index) {
51
+ return ucwords(str_replace('_', ' ', $index));
52
+ }
53
+
54
+
55
+ protected function _addShippingMethodField($fieldset, $marketplace, $sortOrder) {
56
+ $shippingMethod = strtolower(preg_replace('%[^a-zA-Z0-9_]%', '', $marketplace))."_method";
57
+ $configData = $this->getConfigData();
58
+ $path = 'shoppingflux_mo/shipping_method/' . $shippingMethod;
59
+ $data = '';
60
+ $inherit = false;
61
+ if (isset($configData[$path])) {
62
+ $data = $configData[$path];
63
+ $inherit = false;
64
+ } else {
65
+ if($this->getForm()->getConfigRoot()) {
66
+ $data = (string) $this->getForm()->getConfigRoot()->descend($path);
67
+ $inherit = true;
68
+ }
69
+ }
70
+ $e = $this->_getDummyElement();
71
+ $fieldset->addField($shippingMethod, 'select', array(
72
+ 'name' => 'groups[shipping_method][fields][' . $shippingMethod . '][value]',
73
+ 'label' => Mage::helper('profileolabs_shoppingflux')->__('Shipping Method for %s', $this->_getNiceName($marketplace)),
74
+ 'comment' => Mage::helper('profileolabs_shoppingflux')->__('Leave empty to use default shipping method.'),
75
+ 'value' => $data,
76
+ 'values' => Mage::getSingleton('adminhtml/system_config_source_shipping_allmethods')->toOptionArray(),
77
+ 'sort_order' => $sortOrder,
78
+ 'inherit' => $inherit,
79
+ 'can_use_default_value' => 0,
80
+ 'can_use_website_value' => 0,
81
+ ))->setRenderer($this->_getFieldRenderer());
82
+
83
+ }
84
+
85
+
86
+
87
+
88
  }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Adminhtml/System/Config/Form/Fieldset/Shipping/Method/Extra.php CHANGED
@@ -1,98 +1,98 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_System_Config_Form_Fieldset_Shipping_Method_Extra extends Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract {
4
-
5
- public function render(Varien_Data_Form_Element_Abstract $element) {
6
- if(!$this->shouldRenderUnregistered()) {
7
- return parent::render($element);
8
- }
9
-
10
- $html = $this->_getHeaderHtml($element);
11
-
12
- $collection = Mage::getModel('profileolabs_shoppingflux/manageorders_shipping_method')->getCollection();
13
-
14
- if($collection->count()<=0) {
15
- $this->_addEmptyField($element);
16
- }
17
-
18
- $i = 1;
19
- foreach($collection as $shippingMethod) {
20
- $this->_addShippingMethodField($element, $shippingMethod->getFullShippingMethodCode(), 10*$i++);
21
- }
22
-
23
-
24
- foreach ($element->getSortedElements() as $field) {
25
- $html .= $field->toHtml();
26
- }
27
-
28
- $html .= $this->_getFooterHtml($element);
29
-
30
- return $html;
31
- }
32
-
33
- protected function _getHeaderHtml($element) {
34
- $html = parent::_getHeaderHtml($element);
35
- return $html;
36
- }
37
-
38
- protected function _getFieldRenderer() {
39
- if (empty($this->_fieldRenderer)) {
40
- $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
41
- }
42
- return $this->_fieldRenderer;
43
- }
44
-
45
- protected function _getDummyElement() {
46
- if (empty($this->_dummyElement)) {
47
- $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
48
- }
49
- return $this->_dummyElement;
50
- }
51
-
52
- protected function _getNiceName($index) {
53
- return ucwords(str_replace('_', ' ', $index));
54
- }
55
-
56
-
57
- protected function _addShippingMethodField($fieldset, $shippingMethod, $sortOrder) {
58
- $shippingMethod = preg_replace('%[^a-zA-Z0-9_]%', '', $shippingMethod);
59
- $configData = $this->getConfigData();
60
- $path = 'shoppingflux_mo/advanced_shipping_method/' . $shippingMethod;
61
- $data = '';
62
- $inherit = false;
63
- if (isset($configData[$path])) {
64
- $data = $configData[$path];
65
- $inherit = false;
66
- } else {
67
- if($this->getForm()->getConfigRoot()) {
68
- $data = (string) $this->getForm()->getConfigRoot()->descend($path);
69
- $inherit = true;
70
- }
71
- }
72
- $e = $this->_getDummyElement();
73
- $fieldset->addField($shippingMethod, 'select', array(
74
- 'name' => 'groups[advanced_shipping_method][fields][' . $shippingMethod . '][value]',
75
- 'label' => Mage::helper('profileolabs_shoppingflux')->__('Shipping Method for %s', $this->_getNiceName($shippingMethod)),
76
- 'value' => $data,
77
- 'values' => Mage::getSingleton('adminhtml/system_config_source_shipping_allmethods')->toOptionArray(),
78
- 'sort_order' => $sortOrder,
79
- 'inherit' => $inherit,
80
- 'can_use_default_value' => $this->getForm()->canUseDefaultValue($e),
81
- 'can_use_website_value' => $this->getForm()->canUseWebsiteValue($e),
82
- ))->setRenderer($this->_getFieldRenderer());
83
-
84
- }
85
-
86
-
87
- protected function _addEmptyField($fieldset) {
88
- $configData = $this->getConfigData();
89
- $path = 'shoppingflux_mo/advanced_shipping_method/zzzzzz';
90
- $e = $this->_getDummyElement();
91
- $fieldset->addField('zzzzzz', 'note', array(
92
- 'name' => 'groups[advanced_shipping_method][fields][zzzzzz][value]',
93
- 'label' => Mage::helper('profileolabs_shoppingflux')->__('There is no marketplace shipping method registered yet.'),
94
- ))->setRenderer($this->_getFieldRenderer());
95
-
96
- }
97
-
98
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Block_Manageorders_Adminhtml_System_Config_Form_Fieldset_Shipping_Method_Extra extends Profileolabs_Shoppingflux_Block_Adminhtml_System_Config_Form_Fieldset_Abstract {
4
+
5
+ public function render(Varien_Data_Form_Element_Abstract $element) {
6
+ if(!$this->shouldRenderUnregistered()) {
7
+ return parent::render($element);
8
+ }
9
+
10
+ $html = $this->_getHeaderHtml($element);
11
+
12
+ $collection = Mage::getModel('profileolabs_shoppingflux/manageorders_shipping_method')->getCollection();
13
+
14
+ if($collection->count()<=0) {
15
+ $this->_addEmptyField($element);
16
+ }
17
+
18
+ $i = 1;
19
+ foreach($collection as $shippingMethod) {
20
+ $this->_addShippingMethodField($element, $shippingMethod->getFullShippingMethodCode(), 10*$i++);
21
+ }
22
+
23
+
24
+ foreach ($element->getSortedElements() as $field) {
25
+ $html .= $field->toHtml();
26
+ }
27
+
28
+ $html .= $this->_getFooterHtml($element);
29
+
30
+ return $html;
31
+ }
32
+
33
+ protected function _getHeaderHtml($element) {
34
+ $html = parent::_getHeaderHtml($element);
35
+ return $html;
36
+ }
37
+
38
+ protected function _getFieldRenderer() {
39
+ if (empty($this->_fieldRenderer)) {
40
+ $this->_fieldRenderer = Mage::getBlockSingleton('adminhtml/system_config_form_field');
41
+ }
42
+ return $this->_fieldRenderer;
43
+ }
44
+
45
+ protected function _getDummyElement() {
46
+ if (empty($this->_dummyElement)) {
47
+ $this->_dummyElement = new Varien_Object(array('show_in_default' => 1, 'show_in_website' => 1, 'show_in_store' => 0));
48
+ }
49
+ return $this->_dummyElement;
50
+ }
51
+
52
+ protected function _getNiceName($index) {
53
+ return ucwords(str_replace('_', ' ', $index));
54
+ }
55
+
56
+
57
+ protected function _addShippingMethodField($fieldset, $shippingMethod, $sortOrder) {
58
+ $shippingMethod = preg_replace('%[^a-zA-Z0-9_]%', '', $shippingMethod);
59
+ $configData = $this->getConfigData();
60
+ $path = 'shoppingflux_mo/advanced_shipping_method/' . $shippingMethod;
61
+ $data = '';
62
+ $inherit = false;
63
+ if (isset($configData[$path])) {
64
+ $data = $configData[$path];
65
+ $inherit = false;
66
+ } else {
67
+ if($this->getForm()->getConfigRoot()) {
68
+ $data = (string) $this->getForm()->getConfigRoot()->descend($path);
69
+ $inherit = true;
70
+ }
71
+ }
72
+ $e = $this->_getDummyElement();
73
+ $fieldset->addField($shippingMethod, 'select', array(
74
+ 'name' => 'groups[advanced_shipping_method][fields][' . $shippingMethod . '][value]',
75
+ 'label' => Mage::helper('profileolabs_shoppingflux')->__('Shipping Method for %s', $this->_getNiceName($shippingMethod)),
76
+ 'value' => $data,
77
+ 'values' => Mage::getSingleton('adminhtml/system_config_source_shipping_allmethods')->toOptionArray(),
78
+ 'sort_order' => $sortOrder,
79
+ 'inherit' => $inherit,
80
+ 'can_use_default_value' => $this->getForm()->canUseDefaultValue($e),
81
+ 'can_use_website_value' => $this->getForm()->canUseWebsiteValue($e),
82
+ ))->setRenderer($this->_getFieldRenderer());
83
+
84
+ }
85
+
86
+
87
+ protected function _addEmptyField($fieldset) {
88
+ $configData = $this->getConfigData();
89
+ $path = 'shoppingflux_mo/advanced_shipping_method/zzzzzz';
90
+ $e = $this->_getDummyElement();
91
+ $fieldset->addField('zzzzzz', 'note', array(
92
+ 'name' => 'groups[advanced_shipping_method][fields][zzzzzz][value]',
93
+ 'label' => Mage::helper('profileolabs_shoppingflux')->__('There is no marketplace shipping method registered yet.'),
94
+ ))->setRenderer($this->_getFieldRenderer());
95
+
96
+ }
97
+
98
  }
app/code/community/Profileolabs/Shoppingflux/Block/Manageorders/Payment/Info/Purchaseorder.php CHANGED
@@ -1,17 +1,17 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_ShoppingFlux
5
- * @author kassim belghait
6
- */
7
-
8
-
9
- class Profileolabs_Shoppingflux_Block_Manageorders_Payment_Info_Purchaseorder extends Mage_Payment_Block_Info
10
- {
11
- protected function _construct()
12
- {
13
- parent::_construct();
14
- $this->setTemplate('profileolabs/shoppingflux/manageorders/payment/info/purchaseorder.phtml');
15
- }
16
-
17
- }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_ShoppingFlux
5
+ * @author kassim belghait
6
+ */
7
+
8
+
9
+ class Profileolabs_Shoppingflux_Block_Manageorders_Payment_Info_Purchaseorder extends Mage_Payment_Block_Info
10
+ {
11
+ protected function _construct()
12
+ {
13
+ parent::_construct();
14
+ $this->setTemplate('profileolabs/shoppingflux/manageorders/payment/info/purchaseorder.phtml');
15
+ }
16
+
17
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Tracking/Buyline.php CHANGED
@@ -1,40 +1,40 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_Shoppingflux
5
- * @author Vincent Enjalbert @ Web-cooking.net
6
- */
7
- class Profileolabs_Shoppingflux_Block_Tracking_Buyline extends Mage_Core_Block_Text {
8
-
9
- protected function _toHtml() {
10
- $idTracking = Mage::getSingleton('profileolabs_shoppingflux/config')->getIdTracking();
11
-
12
- if (!$idTracking) {
13
- return '';
14
- }
15
-
16
- if(Mage::getSingleton('profileolabs_shoppingflux/config')->isBuylineEnabled()) {
17
- $this->addText("
18
- <!-- BEGIN Shopping flux Tracking -->
19
- <script type=\"text/javascript\">
20
- var sf2 = sf2 || [];
21
- sf2.push(['".$idTracking."'],[escape(document.referrer)]);
22
- (function() {
23
- var sf_script = document.createElement('script');
24
- sf_script.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'tag.shopping-feed.com/buyline.js';
25
- sf_script.setAttribute('async', 'true');
26
- document.documentElement.firstChild.appendChild(sf_script);
27
- })();
28
- </script>
29
- <!-- END Shopping flux Tracking -->
30
- ");
31
- /*$this->addText('
32
- <!-- BEGIN Shopping flux Tracking -->
33
- <script type="text/javascript" src="http://tracking.shopping-flux.com/gg.js"></script>
34
- <!-- END Shopping flux Tracking -->
35
- ');*/
36
- }
37
- return parent::_toHtml();
38
- }
39
-
40
- }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_Shoppingflux
5
+ * @author Vincent Enjalbert @ Web-cooking.net
6
+ */
7
+ class Profileolabs_Shoppingflux_Block_Tracking_Buyline extends Mage_Core_Block_Text {
8
+
9
+ protected function _toHtml() {
10
+ $idTracking = Mage::getSingleton('profileolabs_shoppingflux/config')->getIdTracking();
11
+
12
+ if (!$idTracking) {
13
+ return '';
14
+ }
15
+
16
+ if(Mage::getSingleton('profileolabs_shoppingflux/config')->isBuylineEnabled()) {
17
+ $this->addText("
18
+ <!-- BEGIN Shopping flux Tracking -->
19
+ <script type=\"text/javascript\">
20
+ var sf2 = sf2 || [];
21
+ sf2.push(['".$idTracking."'],[escape(document.referrer)]);
22
+ (function() {
23
+ var sf_script = document.createElement('script');
24
+ sf_script.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'tag.shopping-feed.com/buyline.js';
25
+ sf_script.setAttribute('async', 'true');
26
+ document.documentElement.firstChild.appendChild(sf_script);
27
+ })();
28
+ </script>
29
+ <!-- END Shopping flux Tracking -->
30
+ ");
31
+ /*$this->addText('
32
+ <!-- BEGIN Shopping flux Tracking -->
33
+ <script type="text/javascript" src="http://tracking.shopping-flux.com/gg.js"></script>
34
+ <!-- END Shopping flux Tracking -->
35
+ ');*/
36
+ }
37
+ return parent::_toHtml();
38
+ }
39
+
40
+ }
app/code/community/Profileolabs/Shoppingflux/Block/Tracking/Roi.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_Shoppingflux
5
- * @author Vincent Enjalbert @ Web-cooking.net
6
- */
7
- class Profileolabs_Shoppingflux_Block_Tracking_Roi extends Mage_Core_Block_Text
8
- {
9
-
10
-
11
- protected function _toHtml()
12
- {
13
- $idTracking = Mage::getSingleton('profileolabs_shoppingflux/config')->getIdTracking();
14
-
15
- if (!$idTracking) {
16
- return '';
17
- }
18
-
19
- $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
20
- if ($orderId) {
21
- $order = Mage::getModel('sales/order')->load($orderId);
22
- if ($order->getId()) {
23
- $grandTotal = $order->getBaseGrandTotal();
24
- $incrementId = $order->getIncrementId();
25
- $this->addText("
26
- <!-- BEGIN Shopping flux Tracking -->
27
- <script>
28
- var sf = sf || [];
29
- sf.push(['" . $idTracking . "'], ['" . $incrementId . "'], ['" . $grandTotal . "']);
30
-
31
- (function() {
32
- var sf_script = document.createElement('script');
33
- sf_script.src = 'https://tag.shopping-flux.com/async.js';
34
- sf_script.setAttribute('async', 'true');
35
- document.documentElement.firstChild.appendChild(sf_script);
36
- })();
37
- </script>
38
- <!-- END Shopping flux Tracking -->
39
- ");
40
- }
41
- }
42
- return parent::_toHtml();
43
- }
44
- }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_Shoppingflux
5
+ * @author Vincent Enjalbert @ Web-cooking.net
6
+ */
7
+ class Profileolabs_Shoppingflux_Block_Tracking_Roi extends Mage_Core_Block_Text
8
+ {
9
+
10
+
11
+ protected function _toHtml()
12
+ {
13
+ $idTracking = Mage::getSingleton('profileolabs_shoppingflux/config')->getIdTracking();
14
+
15
+ if (!$idTracking) {
16
+ return '';
17
+ }
18
+
19
+ $orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
20
+ if ($orderId) {
21
+ $order = Mage::getModel('sales/order')->load($orderId);
22
+ if ($order->getId()) {
23
+ $grandTotal = $order->getBaseGrandTotal();
24
+ $incrementId = $order->getIncrementId();
25
+ $this->addText("
26
+ <!-- BEGIN Shopping flux Tracking -->
27
+ <script>
28
+ var sf = sf || [];
29
+ sf.push(['" . $idTracking . "'], ['" . $incrementId . "'], ['" . $grandTotal . "']);
30
+
31
+ (function() {
32
+ var sf_script = document.createElement('script');
33
+ sf_script.src = 'https://tag.shopping-flux.com/async.js';
34
+ sf_script.setAttribute('async', 'true');
35
+ document.documentElement.firstChild.appendChild(sf_script);
36
+ })();
37
+ </script>
38
+ <!-- END Shopping flux Tracking -->
39
+ ");
40
+ }
41
+ }
42
+ return parent::_toHtml();
43
+ }
44
+ }
app/code/community/Profileolabs/Shoppingflux/Helper/Data.php CHANGED
@@ -1,491 +1,492 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Helper
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait / Vincent Enjalbert
8
- */
9
- class Profileolabs_Shoppingflux_Helper_Data extends Mage_Core_Helper_Abstract {
10
-
11
- protected $_config = null;
12
-
13
- public function getFeedUrl($store, $action = 'index') {
14
- return preg_replace('%^(.*)\?.*$%i', '$1', $store->getUrl('shoppingflux/export_flux/'.$action));
15
- }
16
-
17
- public function generateTokens() {
18
- foreach(Mage::app()->getStores() as $store) {
19
- if(!trim(Mage::getConfig()->getNode('stores/'.$store->getCode().'/shoppingflux/configuration/api_key'))) {
20
- $shoppingFluxToken = Mage::getStoreConfig('shoppingflux/configuration/api_key', 0);
21
- if(!$shoppingFluxToken) {
22
- $shoppingFluxToken = Mage::helper('profileolabs_shoppingflux')->generateToken($store->getId());
23
- }
24
- Mage::getConfig()->saveConfig('shoppingflux/configuration/api_key', $shoppingFluxToken, 'stores', $store->getId());
25
- Mage::getConfig()->cleanCache();
26
- }
27
- }
28
- Mage::getConfig()->saveConfig('shoppingflux/configuration/api_key', '', 'default');
29
- }
30
-
31
- public function generateToken($prefix='0') {
32
- return md5($prefix.$_SERVER['SERVER_ADDR'].time());
33
- }
34
-
35
- public function formatFeesDescription($fees, $marketplace) {
36
- return $this->__('%s fees', $marketplace);
37
- }
38
-
39
- public function truncateAddress($street, $lineMaxLength=35, $res = array()) {
40
- $street = trim($street);
41
- if(!$street) return array();
42
- if(preg_match('/^.{1,'.$lineMaxLength.'}(\s|$)/u', $street, $match)) {
43
- $line = trim($match[0]);
44
- } else {
45
- $line = mb_substr($street, 0 , $lineMaxLength);
46
- }
47
- $street = trim(mb_substr($street, strlen($line)));
48
- return array_merge(array($line), $this->truncateAddress($street, $lineMaxLength), $res);
49
- }
50
-
51
- /**
52
- * Returns the node and children as an array
53
- * values ares trimed
54
- *
55
- * @param bool $isCanonical - whether to ignore attributes
56
- * @return array|string
57
- */
58
- public function asArray(SimpleXMLElement $xml, $isCanonical = true) {
59
- $result = array();
60
- if (!$isCanonical) {
61
- // add attributes
62
- foreach ($xml->attributes() as $attributeName => $attribute) {
63
- if ($attribute) {
64
- $result['@'][$attributeName] = trim((string) $attribute);
65
- }
66
- }
67
- }
68
- // add children values
69
- if ($xml->hasChildren()) {
70
- foreach ($xml->children() as $childName => $child) {
71
- if (!$child->hasChildren())
72
- $result[$childName] = $this->asArray($child, $isCanonical);
73
- else
74
- $result[$childName][] = $this->asArray($child, $isCanonical);
75
- }
76
- } else {
77
- if (empty($result)) {
78
- // return as string, if nothing was found
79
- $result = trim((string) $xml);
80
- } else {
81
- // value has zero key element
82
- $result[0] = trim((string) $xml);
83
- }
84
- }
85
- return $result;
86
- }
87
-
88
- public function log($message, $orderId = null) {
89
- $modelLog = Mage::getModel('profileolabs_shoppingflux/manageorders_log');
90
-
91
- $modelLog->log($message, $orderId);
92
-
93
- return $this;
94
- }
95
-
96
- public function isUnderVersion14() {
97
- $currentVersion = Mage::getVersion();
98
- if (version_compare($currentVersion, '1.4.0') < 0)
99
- return true;
100
-
101
- return false;
102
- }
103
-
104
- public function getShippingPrice($product, $carrierValue, $countryCode = "FR") {
105
- $carrierTab = explode('_', $carrierValue);
106
- list($carrierCode, $methodCode) = $carrierTab;
107
- $shipping = Mage::getModel('shipping/shipping');
108
- $methodModel = $shipping->getCarrierByCode($carrierCode);
109
- if ($methodModel) {
110
- $result = $methodModel->collectRates($this->getRequest($product, $countryCode = "FR"));
111
- if ($result->getError()) {
112
- Mage::logException(new Exception($result->getError()));
113
- } else {
114
- foreach ($result->getAllRates() as $rate) {
115
- return $rate->getPrice();
116
- }
117
- }
118
- }
119
-
120
- return false;
121
- }
122
-
123
- protected function getRequest($product, $countryCode = "FR") {
124
- /** @var $request Mage_Shipping_Model_Rate_Request */
125
- $request = Mage::getModel('shipping/rate_request');
126
- $storeId = $request->getStoreId();
127
- if (!$request->getOrig()) {
128
- $request
129
- ->setCountryId($countryCode)
130
- ->setRegionId("")
131
- ->setCity("")
132
- ->setPostcode("")
133
- ;
134
- }
135
-
136
- $item = Mage::getModel('sales/quote_item');
137
- $item->setStoreId($storeId);
138
- $item->setOptions($product->getCustomOptions())
139
- ->setProduct($product);
140
-
141
- $request->setAllItems(array($item));
142
-
143
- $request->setDestCountryId($countryCode);
144
- $request->setDestRegionId("");
145
- $request->setDestRegionCode("");
146
- $request->setDestPostcode("");
147
- $request->setPackageValue($product->getPrice());
148
-
149
- $request->setPackageValueWithDiscount($product->getFinalPrice());
150
- $request->setPackageWeight($product->getWeight());
151
- $request->setFreeMethodWeight(0);
152
- $request->setPackageQty(1);
153
-
154
- $request->setStoreId(Mage::app()->getStore()->getId());
155
- $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
156
- $request->setBaseCurrency(Mage::app()->getStore()->getBaseCurrency());
157
- $request->setPackageCurrency(Mage::app()->getStore()->getCurrentCurrency());
158
-
159
- //$request->setLimitCarrier($limitCarrier);
160
-
161
- return $request;
162
- }
163
-
164
- public function getFilesGenerated() {
165
- $dirStores = array();
166
- $links = array();
167
- if (!is_dir(Mage::getBaseDir('media') . DS . 'shoppingflux')) {
168
- mkdir(Mage::getBaseDir('media') . DS . 'shoppingflux');
169
- }
170
- if ($handle = opendir(Mage::getBaseDir('media') . DS . 'shoppingflux' . DS)) {
171
-
172
- /* This is the correct way to loop over the directory. */
173
- while (false !== ($file = readdir($handle))) {
174
- if ($file == "." || $file == "..")
175
- continue;
176
- $dirStores[] = $file;
177
- }
178
-
179
- closedir($handle);
180
- }
181
-
182
- foreach ($dirStores as $store) {
183
- $links[] = Mage::getBaseUrl('media') . "shoppingflux/" . $store . "/flow.xml";
184
- }
185
- return $links;
186
- }
187
-
188
- /**
189
- * Clean None utf-8 characters
190
- * @param string $value
191
- * @return string $value
192
- */
193
- public function cleanNotUtf8($value) {
194
- if (method_exists(Mage::helper('core/string'), "cleanString"))
195
- $value = Mage::helper('core/string')->cleanString($value);
196
-
197
-
198
- //reject overly long 2 byte sequences, as well as characters above U+10000 and replace with blank
199
- $value = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
200
- '|[\x00-\x7F][\x80-\xBF]+' .
201
- '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
202
- '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' .
203
- '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S', '', $value);
204
-
205
- //reject overly long 3 byte sequences and UTF-16 surrogates and replace with blank
206
- $value = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' .
207
- '|\xED[\xA0-\xBF][\x80-\xBF]/S', '', $value);
208
-
209
- /* $value = preg_replace("/([\x80-\xFF])/e",
210
- "chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
211
- $value); */
212
-
213
-
214
- $value = str_replace(chr(31), "", $value);
215
- $value = str_replace(chr(30), "", $value);
216
- $value = str_replace(chr(29), "", $value);
217
- $value = str_replace(chr(28), "", $value);
218
-
219
-
220
- //$value = iconv("UTF-8","UTF-8//IGNORE",$value);
221
-
222
-
223
- return $value;
224
- }
225
-
226
- function _convert($content) {
227
- if (!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {
228
-
229
- $content = mb_convert_encoding($content, 'UTF-8');
230
-
231
- if (mb_check_encoding($content, 'UTF-8')) {
232
- // log('Converted to UTF-8');
233
- } else {
234
- // log('Could not converted to UTF-8');
235
- }
236
- }
237
- return $content;
238
- }
239
-
240
- public function getAttributesConfigurable($product) {
241
-
242
- if (is_object($product))
243
- $product = $product->getId();
244
-
245
- $resource = Mage::getSingleton('core/resource');
246
- $read = $resource->getConnection('catalog_read');
247
-
248
- $superAttributeTable = $resource->getTableName('catalog_product_super_attribute');
249
- $eavAttributeTable = $resource->getTableName('eav/attribute');
250
-
251
- $select = $read->select('attribute_id')
252
- ->from($superAttributeTable)
253
- ->join(array("att" => $eavAttributeTable), $superAttributeTable . '.attribute_id=att.attribute_id', array("attribute_code" => "attribute_code"))
254
- ->where("product_id = " . $product);
255
-
256
- $result = $read->fetchAll($select);
257
- return $result;
258
- }
259
-
260
- protected $_categoriesWithParents = null;
261
- public function getCategoriesWithParents($key = false, $storeId=null, $withInactive=false, $withNotInMenu=true) {
262
-
263
-
264
- if(is_null($this->_categoriesWithParents)) {
265
- $mageCacheKey = 'shoppingflux_category_list' . (Mage::app()->getStore()->isAdmin() ? '_admin'.intval($storeId) : '_' . intval($storeId)) ;
266
- $mageCacheKey .= $withInactive?'_inactive_':'_active_';
267
- $mageCacheKey .= $withNotInMenu?'all':'inmenu';
268
- $cacheTags = array(/*Mage_Catalog_Model_Category::CACHE_TAG,If On, cause this cache to be invalidated on product duplication :( Commenting this will maybe cause un-updated category list, but will improve performances*/ 'shoppingflux');
269
- $this->_categoriesWithParents = unserialize(Mage::app()->loadCache($mageCacheKey));
270
- if (!$this->_categoriesWithParents) {
271
-
272
- $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
273
- $this->_categoriesWithParents = array('name' => array(), 'url' => array(), 'id' => array());
274
-
275
-
276
- $categories = Mage::getResourceModel('catalog/category_collection');
277
- if($storeId) {
278
- $categories->setStoreId($storeId);
279
- }
280
- $categories->addAttributeToSelect('name')
281
- ->addAttributeToSelect('meta_title')
282
- ->addAttributeToSelect('meta_description')
283
- ->addAttributeToSelect('meta_keywords')
284
- ->addAttributeToFilter('sf_exclude', array(array('is'=>new Zend_Db_Expr('NULL')),array('eq' => 0)), 'left')
285
- ->addAttributeToFilter('entity_id', array('neq' => 1))
286
- ->addAttributeToSort('path', 'ASC')
287
- ->addAttributeToSort('name', 'ASC');
288
-
289
- //echo $categories->getSelect().'';
290
- if(!$withInactive) {
291
- $categories->addFieldToFilter('is_active', array('eq'=>'1'));
292
- }
293
- if(!$withNotInMenu) {
294
- if(version_compare($currentVersion, '1.4.0') > 0) {
295
- $categories->addFieldToFilter('include_in_menu', array('eq'=>'1'));
296
- }
297
- }
298
-
299
- if(!Mage::getSingleton('profileolabs_shoppingflux/config')->getUseAllStoreCategories()) {
300
- $categories
301
- ->addAttributeToFilter('entity_id', array('neq' => $rootCategoryId));
302
- if($rootCategoryId!=0) {
303
- $categories->addFieldToFilter('path', array('like' => "1/{$rootCategoryId}/%"));
304
- }
305
- }
306
-
307
- foreach ($categories as $category) {
308
- $parent = $category->getParentId();
309
- while ($parent > 1) {
310
- $parentCategory = Mage::getModel('catalog/category')->setStoreId($storeId)->load($parent);
311
- if(!$parentCategory->getSfExclude()) {
312
- $category->setName($parentCategory->getName() . " > " . $category->getName());
313
- $category->setMetaTitle($parentCategory->getMetaTitle() . " > " . $category->getMetaTitle());
314
- $category->setMetaDescription($parentCategory->getMetaDescription() . " > " . $category->getMetaDescription());
315
- $category->setMetaKeywords($parentCategory->getMetaKeywords() . " > " . $category->getMetaKeywords());
316
- if (!Mage::app()->getStore()->isAdmin()) {
317
- //To avoid exception launched by third part module : ManaPro_FilterSeoLinks
318
- $category->setUrl($parentCategory->getUrl() . " > " . $category->getUrl());
319
- }
320
- $category->setIds($parentCategory->getId() . " > " . $category->getIds() ? $category->getIds() : $category->getId());
321
- }
322
- $parent = $parentCategory->getParentId();
323
- }
324
- }
325
-
326
- foreach ($categories as $_category) {
327
- $this->_categoriesWithParents['name'][$_category->getId()] = $_category->getName();
328
- $this->_categoriesWithParents['meta_title'][$_category->getId()] = $_category->getMetaTitle();
329
- $this->_categoriesWithParents['meta_description'][$_category->getId()] = $_category->getMetaDescription();
330
- $this->_categoriesWithParents['meta_keywords'][$_category->getId()] = $_category->getMetaKeywords();
331
- if ($this->isModuleInstalled('ManaPro_FilterSeoLinks') && Mage::app()->getStore()->isAdmin()) {
332
- $this->_categoriesWithParents['url'][$_category->getId()] = '';
333
- } else {
334
- $this->_categoriesWithParents['url'][$_category->getId()] = $_category->getUrl();
335
- }
336
- $this->_categoriesWithParents['id'][$_category->getId()] = $_category->getIds();
337
- }
338
- Mage::app()->saveCache(serialize($this->_categoriesWithParents), $mageCacheKey, $cacheTags);
339
-
340
- unset($categories);
341
- }
342
- }
343
-
344
- if ($key && isset($this->_categoriesWithParents[$key]))
345
- return $this->_categoriesWithParents[$key];
346
- return $this->_categoriesWithParents;
347
- }
348
-
349
- public function isModuleInstalled($module) {
350
- $modules = Mage::getConfig()->getNode('modules')->children();
351
- $modulesArray = (array) $modules;
352
-
353
- return isset($modulesArray[$module]);
354
- }
355
-
356
- public function notifyError($message) {
357
- //MAIL
358
- $emailTemplate = Mage::getModel('core/email_template')
359
- ->loadDefault('shoppingflux_alert');
360
- $emailTemplateVariables = array();
361
- $emailTemplateVariables['message'] = $message;
362
- $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
363
- $emailTemplate->setSenderName('Magento/ShoppingFlux');
364
- $emailTemplate->setSenderEmail('no-reply@magento-shoppingflux.com');
365
- $emailTemplate->send(Mage::getStoreConfig('shoppingflux/configuration/alert_email'), Mage::getStoreConfig('shoppingflux/configuration/alert_email'), $emailTemplateVariables);
366
-
367
- // Notification
368
- try {
369
- $notification = Mage::getModel('adminnotification/inbox');
370
- $notification->setseverity(Mage_AdminNotification_Model_Inbox::SEVERITY_CRITICAL);
371
- $notification->setTitle(Mage::helper('profileolabs_shoppingflux')->__('Shoppingflux alert'));
372
- $notification->setDateAdded(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
373
- $notification->setDescription(Mage::helper('profileolabs_shoppingflux')->__('Shoppingflux alert : <br/> %s', $message));
374
- $notification->save();
375
- } catch (Exception $e) {
376
- //var_dump($e->getMessage());die();
377
- }
378
- }
379
-
380
-
381
- public function getConfig() {
382
- if (is_null($this->_config)) {
383
- $this->_config = Mage::getSingleton('profileolabs_shoppingflux/config');
384
- }
385
-
386
- return $this->_config;
387
- }
388
-
389
- public function isRegistered() {
390
- if(Mage::getStoreConfigFlag('shoppingflux/configuration/has_registered')) {
391
- return true;
392
- } else if(time() - intval(Mage::getStoreConfig('shoppingflux/configuration/registration_last_check')) > 24*60*60) {
393
- foreach(Mage::app()->getStores() as $store) {
394
- $apiKey = $this->getConfig()->getApiKey($store->getId());
395
- $wsUri = $this->getConfig()->getWsUri($store->getId());
396
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
397
- if($service->isClient()) {
398
- return true;
399
- }
400
- }
401
- $config = new Mage_Core_Model_Config();
402
- $config->saveConfig('shoppingflux/configuration/registration_last_check', time());
403
- }
404
- return false;
405
- }
406
-
407
- public function newInstallation() {
408
- try {
409
- $sendTo = array('olivier@shopping-feed.com', 'andy@shopping-feed.com');
410
- $mailContent = array();
411
- $mailContent['Magento URL'] = Mage::helper("adminhtml")->getUrl();
412
- if(!preg_match('%HTTP%', $mailContent['Magento URL'])) {
413
- $mailContent['Magento URL'] = @$_SERVER['HTTP_HOST'].' / ' .@$_SERVER['HTTP_REFERER']." / ".@$_SERVER['SERVER_NAME'];
414
- }
415
- $mailContent['Module Version'] = Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
416
- $mailContent['Email'] = Mage::getStoreConfig('trans_email/ident_general/email');
417
- $mailContent['Config Country'] = Mage::getStoreConfig('shipping/origin/country_id');
418
- $mailContent['Config Address'] = Mage::getStoreConfig('shipping/origin/street_line1') .' ' . Mage::getStoreConfig('shipping/origin/street_line2') . ' ' . Mage::getStoreConfig('shipping/origin/postcode') . ' ' . Mage::getStoreConfig('shipping/origin/city');
419
-
420
-
421
- $stores = Mage::app()->getStores();
422
- if(count($stores) == 0) {
423
- Mage::app()->reinitStores();
424
- $stores = Mage::app()->getStores();
425
- }
426
- foreach($stores as $store) {
427
- $mailContent['Store #'.$store->getId(). ' Name '] = $store->getWebsite()->getName(). ' > ' . $store->getGroup()->getName(). ' > ' . $store->getName();
428
- $mailContent['Store #'.$store->getId(). ' Url '] = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
429
- $mailContent['Store #'.$store->getId(). ' Feed '] = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store);
430
- $mailContent['Store #'.$store->getId(). ' Refresh Url '] = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store, 'refreshEverything');
431
- $mailContent['Store #'.$store->getId(). ' Status Url '] = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store, 'status');
432
- $mailContent['Store #'.$store->getId(). ' is default ?'] = (Mage::app()->getDefaultStoreView()->getId() == $store->getId() ? 'Yes' : 'No');
433
- }
434
- $productCollection = Mage::getModel('catalog/product')->getCollection();
435
- $mailContent['Products count'] = $productCollection->count();
436
-
437
- $productCollection = Mage::getModel('catalog/product')->getCollection();
438
- Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productCollection);
439
- $mailContent['Active products count'] = $productCollection->count();
440
-
441
- $productCollection = Mage::getModel('catalog/product')->getCollection();
442
- $productCollection->addAttributeToFilter('type_id', 'configurable');
443
- $mailContent['Configurable products count'] = $productCollection->count();
444
-
445
-
446
- $productCollection = Mage::getModel('catalog/product')->getCollection();
447
- $productCollection->addAttributeToFilter('type_id', 'simple');
448
- $mailContent['Simple products count'] = $productCollection->count();
449
-
450
-
451
- $productCollection = Mage::getModel('catalog/product')->getCollection();
452
- $productCollection->addAttributeToFilter('type_id', 'vitual');
453
- $mailContent['Virtuals products count'] = $productCollection->count();
454
-
455
-
456
- $productCollection = Mage::getModel('catalog/product')->getCollection();
457
- $productCollection->addAttributeToFilter('type_id', 'downloadable');
458
- $mailContent['Downloadable products count'] = $productCollection->count();
459
-
460
-
461
- $productCollection = Mage::getModel('catalog/product')->getCollection();
462
- $productCollection->addAttributeToFilter('type_id', 'grouped');
463
- $mailContent['Grouped products count'] = $productCollection->count();
464
-
465
-
466
- $productCollection = Mage::getModel('catalog/product')->getCollection();
467
- $productCollection->addAttributeToFilter('type_id', 'bundle');
468
- $mailContent['Bundle products count'] = $productCollection->count();
469
-
470
- $mailLines = array();
471
- foreach($mailContent as $k=>$v) {
472
- $mailLines[] = '<strong>' . $k . ' : </strong>' . $v;
473
- }
474
- $mailContent = implode("<br>", $mailLines);
475
-
476
- $mail = new Zend_Mail();
477
- $mail->setBodyHtml($mailContent);
478
- $mail->setFrom('no-reply@shopping-feed.com', 'Shopping Feed Magento Extension');
479
- foreach($sendTo as $email) {
480
- $mail->addTo($email,$email);
481
- }
482
- $mail->setSubject('ShoppingFeed installation on Magento');
483
- $mail->send();
484
-
485
- } catch(Exception $e) {
486
-
487
- }
488
- }
489
-
490
-
491
- }
 
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Helper
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait / Vincent Enjalbert
8
+ */
9
+ class Profileolabs_Shoppingflux_Helper_Data extends Mage_Core_Helper_Abstract {
10
+
11
+ protected $_config = null;
12
+
13
+ public function getFeedUrl($store, $action = 'index') {
14
+ return preg_replace('%^(.*)\?.*$%i', '$1', $store->getUrl('shoppingflux/export_flux/'.$action));
15
+ }
16
+
17
+ public function generateTokens() {
18
+ foreach(Mage::app()->getStores() as $store) {
19
+ if(!trim(Mage::getConfig()->getNode('stores/'.$store->getCode().'/shoppingflux/configuration/api_key'))) {
20
+ $shoppingFluxToken = Mage::getStoreConfig('shoppingflux/configuration/api_key', 0);
21
+ if(!$shoppingFluxToken) {
22
+ $shoppingFluxToken = Mage::helper('profileolabs_shoppingflux')->generateToken($store->getId());
23
+ }
24
+ Mage::getConfig()->saveConfig('shoppingflux/configuration/api_key', $shoppingFluxToken, 'stores', $store->getId());
25
+ Mage::getConfig()->cleanCache();
26
+ }
27
+ }
28
+ Mage::getConfig()->saveConfig('shoppingflux/configuration/api_key', '', 'default');
29
+ }
30
+
31
+ public function generateToken($prefix='0') {
32
+ return md5($prefix.$_SERVER['SERVER_ADDR'].time());
33
+ }
34
+
35
+ public function formatFeesDescription($fees, $marketplace) {
36
+ return $this->__('%s fees', $marketplace);
37
+ }
38
+
39
+ public function truncateAddress($street, $lineMaxLength=35, $res = array()) {
40
+ $street = trim($street);
41
+ if(!$street) return array();
42
+ if(preg_match('/^.{1,'.$lineMaxLength.'}(\s|$)/u', $street, $match)) {
43
+ $line = trim($match[0]);
44
+ } else {
45
+ $line = mb_substr($street, 0 , $lineMaxLength);
46
+ }
47
+ $street = trim(mb_substr($street, strlen($line)));
48
+ return array_merge(array($line), $this->truncateAddress($street, $lineMaxLength), $res);
49
+ }
50
+
51
+ /**
52
+ * Returns the node and children as an array
53
+ * values ares trimed
54
+ *
55
+ * @param bool $isCanonical - whether to ignore attributes
56
+ * @return array|string
57
+ */
58
+ public function asArray(SimpleXMLElement $xml, $isCanonical = true) {
59
+ $result = array();
60
+ if (!$isCanonical) {
61
+ // add attributes
62
+ foreach ($xml->attributes() as $attributeName => $attribute) {
63
+ if ($attribute) {
64
+ $result['@'][$attributeName] = trim((string) $attribute);
65
+ }
66
+ }
67
+ }
68
+ // add children values
69
+ if ($xml->hasChildren()) {
70
+ foreach ($xml->children() as $childName => $child) {
71
+ if (!$child->hasChildren())
72
+ $result[$childName] = $this->asArray($child, $isCanonical);
73
+ else
74
+ $result[$childName][] = $this->asArray($child, $isCanonical);
75
+ }
76
+ } else {
77
+ if (empty($result)) {
78
+ // return as string, if nothing was found
79
+ $result = trim((string) $xml);
80
+ } else {
81
+ // value has zero key element
82
+ $result[0] = trim((string) $xml);
83
+ }
84
+ }
85
+ return $result;
86
+ }
87
+
88
+ public function log($message, $orderId = null) {
89
+ $modelLog = Mage::getModel('profileolabs_shoppingflux/manageorders_log');
90
+
91
+ $modelLog->log($message, $orderId);
92
+
93
+ return $this;
94
+ }
95
+
96
+ public function isUnderVersion14() {
97
+ $currentVersion = Mage::getVersion();
98
+ if (version_compare($currentVersion, '1.4.0') < 0)
99
+ return true;
100
+
101
+ return false;
102
+ }
103
+
104
+ public function getShippingPrice($product, $carrierValue, $countryCode = "FR") {
105
+ $carrierTab = explode('_', $carrierValue);
106
+ list($carrierCode, $methodCode) = $carrierTab;
107
+ $shipping = Mage::getModel('shipping/shipping');
108
+ $methodModel = $shipping->getCarrierByCode($carrierCode);
109
+ if ($methodModel) {
110
+ if (is_object($result = $methodModel->collectRates($this->getRequest($product, $countryCode = "FR")))) {
111
+ if ($result->getError()) {
112
+ Mage::logException(new Exception($result->getError()));
113
+ } else {
114
+ foreach ($result->getAllRates() as $rate) {
115
+ return $rate->getPrice();
116
+ }
117
+ }
118
+ }
119
+ }
120
+
121
+ return false;
122
+ }
123
+
124
+ protected function getRequest($product, $countryCode = "FR") {
125
+ /** @var $request Mage_Shipping_Model_Rate_Request */
126
+ $request = Mage::getModel('shipping/rate_request');
127
+ $storeId = $request->getStoreId();
128
+ if (!$request->getOrig()) {
129
+ $request
130
+ ->setCountryId($countryCode)
131
+ ->setRegionId("")
132
+ ->setCity("")
133
+ ->setPostcode("")
134
+ ;
135
+ }
136
+
137
+ $item = Mage::getModel('sales/quote_item');
138
+ $item->setStoreId($storeId);
139
+ $item->setOptions($product->getCustomOptions())
140
+ ->setProduct($product);
141
+
142
+ $request->setAllItems(array($item));
143
+
144
+ $request->setDestCountryId($countryCode);
145
+ $request->setDestRegionId("");
146
+ $request->setDestRegionCode("");
147
+ $request->setDestPostcode("");
148
+ $request->setPackageValue($product->getPrice());
149
+
150
+ $request->setPackageValueWithDiscount($product->getFinalPrice());
151
+ $request->setPackageWeight($product->getWeight());
152
+ $request->setFreeMethodWeight(0);
153
+ $request->setPackageQty(1);
154
+
155
+ $request->setStoreId(Mage::app()->getStore()->getId());
156
+ $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
157
+ $request->setBaseCurrency(Mage::app()->getStore()->getBaseCurrency());
158
+ $request->setPackageCurrency(Mage::app()->getStore()->getCurrentCurrency());
159
+
160
+ //$request->setLimitCarrier($limitCarrier);
161
+
162
+ return $request;
163
+ }
164
+
165
+ public function getFilesGenerated() {
166
+ $dirStores = array();
167
+ $links = array();
168
+ if (!is_dir(Mage::getBaseDir('media') . DS . 'shoppingflux')) {
169
+ mkdir(Mage::getBaseDir('media') . DS . 'shoppingflux');
170
+ }
171
+ if ($handle = opendir(Mage::getBaseDir('media') . DS . 'shoppingflux' . DS)) {
172
+
173
+ /* This is the correct way to loop over the directory. */
174
+ while (false !== ($file = readdir($handle))) {
175
+ if ($file == "." || $file == "..")
176
+ continue;
177
+ $dirStores[] = $file;
178
+ }
179
+
180
+ closedir($handle);
181
+ }
182
+
183
+ foreach ($dirStores as $store) {
184
+ $links[] = Mage::getBaseUrl('media') . "shoppingflux/" . $store . "/flow.xml";
185
+ }
186
+ return $links;
187
+ }
188
+
189
+ /**
190
+ * Clean None utf-8 characters
191
+ * @param string $value
192
+ * @return string $value
193
+ */
194
+ public function cleanNotUtf8($value) {
195
+ if (method_exists(Mage::helper('core/string'), "cleanString"))
196
+ $value = Mage::helper('core/string')->cleanString($value);
197
+
198
+
199
+ //reject overly long 2 byte sequences, as well as characters above U+10000 and replace with blank
200
+ $value = preg_replace('/[\x00-\x08\x10\x0B\x0C\x0E-\x19\x7F]' .
201
+ '|[\x00-\x7F][\x80-\xBF]+' .
202
+ '|([\xC0\xC1]|[\xF0-\xFF])[\x80-\xBF]*' .
203
+ '|[\xC2-\xDF]((?![\x80-\xBF])|[\x80-\xBF]{2,})' .
204
+ '|[\xE0-\xEF](([\x80-\xBF](?![\x80-\xBF]))|(?![\x80-\xBF]{2})|[\x80-\xBF]{3,})/S', '', $value);
205
+
206
+ //reject overly long 3 byte sequences and UTF-16 surrogates and replace with blank
207
+ $value = preg_replace('/\xE0[\x80-\x9F][\x80-\xBF]' .
208
+ '|\xED[\xA0-\xBF][\x80-\xBF]/S', '', $value);
209
+
210
+ /* $value = preg_replace("/([\x80-\xFF])/e",
211
+ "chr(0xC0|ord('\\1')>>6).chr(0x80|ord('\\1')&0x3F)",
212
+ $value); */
213
+
214
+
215
+ $value = str_replace(chr(31), "", $value);
216
+ $value = str_replace(chr(30), "", $value);
217
+ $value = str_replace(chr(29), "", $value);
218
+ $value = str_replace(chr(28), "", $value);
219
+
220
+
221
+ //$value = iconv("UTF-8","UTF-8//IGNORE",$value);
222
+
223
+
224
+ return $value;
225
+ }
226
+
227
+ function _convert($content) {
228
+ if (!mb_check_encoding($content, 'UTF-8') OR !($content === mb_convert_encoding(mb_convert_encoding($content, 'UTF-32', 'UTF-8'), 'UTF-8', 'UTF-32'))) {
229
+
230
+ $content = mb_convert_encoding($content, 'UTF-8');
231
+
232
+ if (mb_check_encoding($content, 'UTF-8')) {
233
+ // log('Converted to UTF-8');
234
+ } else {
235
+ // log('Could not converted to UTF-8');
236
+ }
237
+ }
238
+ return $content;
239
+ }
240
+
241
+ public function getAttributesConfigurable($product) {
242
+
243
+ if (is_object($product))
244
+ $product = $product->getId();
245
+
246
+ $resource = Mage::getSingleton('core/resource');
247
+ $read = $resource->getConnection('catalog_read');
248
+
249
+ $superAttributeTable = $resource->getTableName('catalog_product_super_attribute');
250
+ $eavAttributeTable = $resource->getTableName('eav/attribute');
251
+
252
+ $select = $read->select('attribute_id')
253
+ ->from($superAttributeTable)
254
+ ->join(array("att" => $eavAttributeTable), $superAttributeTable . '.attribute_id=att.attribute_id', array("attribute_code" => "attribute_code"))
255
+ ->where("product_id = " . $product);
256
+
257
+ $result = $read->fetchAll($select);
258
+ return $result;
259
+ }
260
+
261
+ protected $_categoriesWithParents = null;
262
+ public function getCategoriesWithParents($key = false, $storeId=null, $withInactive=false, $withNotInMenu=true) {
263
+
264
+
265
+ if(is_null($this->_categoriesWithParents)) {
266
+ $mageCacheKey = 'shoppingflux_category_list' . (Mage::app()->getStore()->isAdmin() ? '_admin'.intval($storeId) : '_' . intval($storeId)) ;
267
+ $mageCacheKey .= $withInactive?'_inactive_':'_active_';
268
+ $mageCacheKey .= $withNotInMenu?'all':'inmenu';
269
+ $cacheTags = array(/*Mage_Catalog_Model_Category::CACHE_TAG,If On, cause this cache to be invalidated on product duplication :( Commenting this will maybe cause un-updated category list, but will improve performances*/ 'shoppingflux');
270
+ $this->_categoriesWithParents = unserialize(Mage::app()->loadCache($mageCacheKey));
271
+ if (!$this->_categoriesWithParents) {
272
+
273
+ $rootCategoryId = Mage::app()->getStore($storeId)->getRootCategoryId();
274
+ $this->_categoriesWithParents = array('name' => array(), 'url' => array(), 'id' => array());
275
+
276
+
277
+ $categories = Mage::getResourceModel('catalog/category_collection');
278
+ if($storeId) {
279
+ $categories->setStoreId($storeId);
280
+ }
281
+ $categories->addAttributeToSelect('name')
282
+ ->addAttributeToSelect('meta_title')
283
+ ->addAttributeToSelect('meta_description')
284
+ ->addAttributeToSelect('meta_keywords')
285
+ ->addAttributeToFilter('sf_exclude', array(array('is'=>new Zend_Db_Expr('NULL')),array('eq' => 0)), 'left')
286
+ ->addAttributeToFilter('entity_id', array('neq' => 1))
287
+ ->addAttributeToSort('path', 'ASC')
288
+ ->addAttributeToSort('name', 'ASC');
289
+
290
+ //echo $categories->getSelect().'';
291
+ if(!$withInactive) {
292
+ $categories->addFieldToFilter('is_active', array('eq'=>'1'));
293
+ }
294
+ if(!$withNotInMenu) {
295
+ if(version_compare($currentVersion, '1.4.0') > 0) {
296
+ $categories->addFieldToFilter('include_in_menu', array('eq'=>'1'));
297
+ }
298
+ }
299
+
300
+ if(!Mage::getSingleton('profileolabs_shoppingflux/config')->getUseAllStoreCategories()) {
301
+ $categories
302
+ ->addAttributeToFilter('entity_id', array('neq' => $rootCategoryId));
303
+ if($rootCategoryId!=0) {
304
+ $categories->addFieldToFilter('path', array('like' => "1/{$rootCategoryId}/%"));
305
+ }
306
+ }
307
+
308
+ foreach ($categories as $category) {
309
+ $parent = $category->getParentId();
310
+ while ($parent > 1) {
311
+ $parentCategory = Mage::getModel('catalog/category')->setStoreId($storeId)->load($parent);
312
+ if(!$parentCategory->getSfExclude()) {
313
+ $category->setName($parentCategory->getName() . " > " . $category->getName());
314
+ $category->setMetaTitle($parentCategory->getMetaTitle() . " > " . $category->getMetaTitle());
315
+ $category->setMetaDescription($parentCategory->getMetaDescription() . " > " . $category->getMetaDescription());
316
+ $category->setMetaKeywords($parentCategory->getMetaKeywords() . " > " . $category->getMetaKeywords());
317
+ if (!Mage::app()->getStore()->isAdmin()) {
318
+ //To avoid exception launched by third part module : ManaPro_FilterSeoLinks
319
+ $category->setUrl($parentCategory->getUrl() . " > " . $category->getUrl());
320
+ }
321
+ $category->setIds($parentCategory->getId() . " > " . $category->getIds() ? $category->getIds() : $category->getId());
322
+ }
323
+ $parent = $parentCategory->getParentId();
324
+ }
325
+ }
326
+
327
+ foreach ($categories as $_category) {
328
+ $this->_categoriesWithParents['name'][$_category->getId()] = $_category->getName();
329
+ $this->_categoriesWithParents['meta_title'][$_category->getId()] = $_category->getMetaTitle();
330
+ $this->_categoriesWithParents['meta_description'][$_category->getId()] = $_category->getMetaDescription();
331
+ $this->_categoriesWithParents['meta_keywords'][$_category->getId()] = $_category->getMetaKeywords();
332
+ if ($this->isModuleInstalled('ManaPro_FilterSeoLinks') && Mage::app()->getStore()->isAdmin()) {
333
+ $this->_categoriesWithParents['url'][$_category->getId()] = '';
334
+ } else {
335
+ $this->_categoriesWithParents['url'][$_category->getId()] = $_category->getUrl();
336
+ }
337
+ $this->_categoriesWithParents['id'][$_category->getId()] = $_category->getIds();
338
+ }
339
+ Mage::app()->saveCache(serialize($this->_categoriesWithParents), $mageCacheKey, $cacheTags);
340
+
341
+ unset($categories);
342
+ }
343
+ }
344
+
345
+ if ($key && isset($this->_categoriesWithParents[$key]))
346
+ return $this->_categoriesWithParents[$key];
347
+ return $this->_categoriesWithParents;
348
+ }
349
+
350
+ public function isModuleInstalled($module) {
351
+ $modules = Mage::getConfig()->getNode('modules')->children();
352
+ $modulesArray = (array) $modules;
353
+
354
+ return isset($modulesArray[$module]);
355
+ }
356
+
357
+ public function notifyError($message) {
358
+ //MAIL
359
+ $emailTemplate = Mage::getModel('core/email_template')
360
+ ->loadDefault('shoppingflux_alert');
361
+ $emailTemplateVariables = array();
362
+ $emailTemplateVariables['message'] = $message;
363
+ $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);
364
+ $emailTemplate->setSenderName('Magento/ShoppingFlux');
365
+ $emailTemplate->setSenderEmail('no-reply@magento-shoppingflux.com');
366
+ $emailTemplate->send(Mage::getStoreConfig('shoppingflux/configuration/alert_email'), Mage::getStoreConfig('shoppingflux/configuration/alert_email'), $emailTemplateVariables);
367
+
368
+ // Notification
369
+ try {
370
+ $notification = Mage::getModel('adminnotification/inbox');
371
+ $notification->setseverity(Mage_AdminNotification_Model_Inbox::SEVERITY_CRITICAL);
372
+ $notification->setTitle(Mage::helper('profileolabs_shoppingflux')->__('Shoppingflux alert'));
373
+ $notification->setDateAdded(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
374
+ $notification->setDescription(Mage::helper('profileolabs_shoppingflux')->__('Shoppingflux alert : <br/> %s', $message));
375
+ $notification->save();
376
+ } catch (Exception $e) {
377
+ //var_dump($e->getMessage());die();
378
+ }
379
+ }
380
+
381
+
382
+ public function getConfig() {
383
+ if (is_null($this->_config)) {
384
+ $this->_config = Mage::getSingleton('profileolabs_shoppingflux/config');
385
+ }
386
+
387
+ return $this->_config;
388
+ }
389
+
390
+ public function isRegistered() {
391
+ if(Mage::getStoreConfigFlag('shoppingflux/configuration/has_registered')) {
392
+ return true;
393
+ } else if(time() - intval(Mage::getStoreConfig('shoppingflux/configuration/registration_last_check')) > 24*60*60) {
394
+ foreach(Mage::app()->getStores() as $store) {
395
+ $apiKey = $this->getConfig()->getApiKey($store->getId());
396
+ $wsUri = $this->getConfig()->getWsUri($store->getId());
397
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
398
+ if($service->isClient()) {
399
+ return true;
400
+ }
401
+ }
402
+ $config = new Mage_Core_Model_Config();
403
+ $config->saveConfig('shoppingflux/configuration/registration_last_check', time());
404
+ }
405
+ return false;
406
+ }
407
+
408
+ public function newInstallation() {
409
+ try {
410
+ $sendTo = array('olivier@shopping-feed.com', 'andy@shopping-feed.com');
411
+ $mailContent = array();
412
+ $mailContent['Magento URL'] = Mage::helper("adminhtml")->getUrl();
413
+ if(!preg_match('%HTTP%', $mailContent['Magento URL'])) {
414
+ $mailContent['Magento URL'] = @$_SERVER['HTTP_HOST'].' / ' .@$_SERVER['HTTP_REFERER']." / ".@$_SERVER['SERVER_NAME'];
415
+ }
416
+ $mailContent['Module Version'] = Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
417
+ $mailContent['Email'] = Mage::getStoreConfig('trans_email/ident_general/email');
418
+ $mailContent['Config Country'] = Mage::getStoreConfig('shipping/origin/country_id');
419
+ $mailContent['Config Address'] = Mage::getStoreConfig('shipping/origin/street_line1') .' ' . Mage::getStoreConfig('shipping/origin/street_line2') . ' ' . Mage::getStoreConfig('shipping/origin/postcode') . ' ' . Mage::getStoreConfig('shipping/origin/city');
420
+
421
+
422
+ $stores = Mage::app()->getStores();
423
+ if(count($stores) == 0) {
424
+ Mage::app()->reinitStores();
425
+ $stores = Mage::app()->getStores();
426
+ }
427
+ foreach($stores as $store) {
428
+ $mailContent['Store #'.$store->getId(). ' Name '] = $store->getWebsite()->getName(). ' > ' . $store->getGroup()->getName(). ' > ' . $store->getName();
429
+ $mailContent['Store #'.$store->getId(). ' Url '] = $store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
430
+ $mailContent['Store #'.$store->getId(). ' Feed '] = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store);
431
+ $mailContent['Store #'.$store->getId(). ' Refresh Url '] = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store, 'refreshEverything');
432
+ $mailContent['Store #'.$store->getId(). ' Status Url '] = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store, 'status');
433
+ $mailContent['Store #'.$store->getId(). ' is default ?'] = (Mage::app()->getDefaultStoreView()->getId() == $store->getId() ? 'Yes' : 'No');
434
+ }
435
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
436
+ $mailContent['Products count'] = $productCollection->count();
437
+
438
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
439
+ Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($productCollection);
440
+ $mailContent['Active products count'] = $productCollection->count();
441
+
442
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
443
+ $productCollection->addAttributeToFilter('type_id', 'configurable');
444
+ $mailContent['Configurable products count'] = $productCollection->count();
445
+
446
+
447
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
448
+ $productCollection->addAttributeToFilter('type_id', 'simple');
449
+ $mailContent['Simple products count'] = $productCollection->count();
450
+
451
+
452
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
453
+ $productCollection->addAttributeToFilter('type_id', 'vitual');
454
+ $mailContent['Virtuals products count'] = $productCollection->count();
455
+
456
+
457
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
458
+ $productCollection->addAttributeToFilter('type_id', 'downloadable');
459
+ $mailContent['Downloadable products count'] = $productCollection->count();
460
+
461
+
462
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
463
+ $productCollection->addAttributeToFilter('type_id', 'grouped');
464
+ $mailContent['Grouped products count'] = $productCollection->count();
465
+
466
+
467
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
468
+ $productCollection->addAttributeToFilter('type_id', 'bundle');
469
+ $mailContent['Bundle products count'] = $productCollection->count();
470
+
471
+ $mailLines = array();
472
+ foreach($mailContent as $k=>$v) {
473
+ $mailLines[] = '<strong>' . $k . ' : </strong>' . $v;
474
+ }
475
+ $mailContent = implode("<br>", $mailLines);
476
+
477
+ $mail = new Zend_Mail();
478
+ $mail->setBodyHtml($mailContent);
479
+ $mail->setFrom('no-reply@shopping-feed.com', 'Shopping Feed Magento Extension');
480
+ foreach($sendTo as $email) {
481
+ $mail->addTo($email,$email);
482
+ }
483
+ $mail->setSubject('ShoppingFeed installation on Magento');
484
+ $mail->send();
485
+
486
+ } catch(Exception $e) {
487
+
488
+ }
489
+ }
490
+
491
+
492
+ }
app/code/community/Profileolabs/Shoppingflux/Helper/String.php ADDED
@@ -0,0 +1,217 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magento.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magento.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Core
23
+ * @copyright Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * Shopping Flux String Helper
29
+ *
30
+ * @category ShoppingFlux
31
+ * @package Profileolabs_Shoppingflux
32
+ * @author Shopping Feed
33
+ */
34
+ class Profileolabs_Shoppingflux_Helper_String extends Mage_Core_Helper_String
35
+ {
36
+ /**
37
+ * Parse query string to array
38
+ *
39
+ * @param string $str
40
+ * @return array
41
+ */
42
+ public function parseQueryStr($str)
43
+ {
44
+ /** @var Mage_Core_Helper_String $baseHelper */
45
+ $baseHelper = Mage::helper('core/string');
46
+
47
+ if (is_callable(array($baseHelper, 'parseQueryStr'))) {
48
+ $result = $baseHelper->parseQueryStr($str);
49
+ } else {
50
+ $result = array();
51
+ $argSeparator = '&';
52
+ $partsQueryStr = explode($argSeparator, $str);
53
+
54
+ foreach ($partsQueryStr as $partQueryStr) {
55
+ if ($this->_validateQueryStr($partQueryStr)) {
56
+ $param = $this->_explodeAndDecodeParam($partQueryStr);
57
+ $param = $this->_handleRecursiveParamForQueryStr($param);
58
+ $result = $this->_appendParam($result, $param);
59
+ }
60
+ }
61
+ }
62
+
63
+ return $result;
64
+ }
65
+
66
+ /**
67
+ * Validate query pair string
68
+ *
69
+ * @param string $str
70
+ * @return bool
71
+ */
72
+ protected function _validateQueryStr($str)
73
+ {
74
+ if (!$str || (strpos($str, '=') === false)) {
75
+ return false;
76
+ }
77
+ return true;
78
+ }
79
+
80
+ /**
81
+ * Prepare param
82
+ *
83
+ * @param string $str
84
+ * @return array
85
+ */
86
+ protected function _explodeAndDecodeParam($str)
87
+ {
88
+ $preparedParam = array();
89
+ $param = explode('=', $str);
90
+ $preparedParam['key'] = urldecode(array_shift($param));
91
+ $preparedParam['value'] = urldecode(array_shift($param));
92
+ return $preparedParam;
93
+ }
94
+
95
+ /**
96
+ * Merge array recursive without overwrite keys.
97
+ * PHP function array_merge_recursive merge array
98
+ * with overwrite num keys
99
+ *
100
+ * @param array $baseArray
101
+ * @param array $mergeArray
102
+ * @return array
103
+ */
104
+ protected function _mergeRecursiveWithoutOverwriteNumKeys(array $baseArray, array $mergeArray)
105
+ {
106
+ foreach ($mergeArray as $key => $value) {
107
+ if (is_array($value)) {
108
+ if (array_key_exists($key, $baseArray)) {
109
+ $baseArray[$key] = $this->_mergeRecursiveWithoutOverwriteNumKeys($baseArray[$key], $value);
110
+ } else {
111
+ $baseArray[$key] = $value;
112
+ }
113
+ } else {
114
+ if ($key) {
115
+ $baseArray[$key] = $value;
116
+ } else {
117
+ $baseArray[] = $value;
118
+ }
119
+ }
120
+ }
121
+ return $baseArray;
122
+ }
123
+
124
+ /**
125
+ * Append param to general result
126
+ *
127
+ * @param array $result
128
+ * @param array $param
129
+ * @return array
130
+ */
131
+ protected function _appendParam(array $result, array $param)
132
+ {
133
+ $key = $param['key'];
134
+ $value = $param['value'];
135
+
136
+ if ($key) {
137
+ if (is_array($value) && array_key_exists($key, $result)) {
138
+ $result[$key] = $this->_mergeRecursiveWithoutOverwriteNumKeys($result[$key], $value);
139
+ } else {
140
+ $result[$key] = $value;
141
+ }
142
+ }
143
+
144
+ return $result;
145
+ }
146
+
147
+ /**
148
+ * Handle param recursively
149
+ *
150
+ * @param array $param
151
+ * @return array
152
+ */
153
+ protected function _handleRecursiveParamForQueryStr(array $param)
154
+ {
155
+ $value = $param['value'];
156
+ $key = $param['key'];
157
+
158
+ $subKeyBrackets = $this->_getLastSubkey($key);
159
+ $subKey = $this->_getLastSubkey($key, false);
160
+
161
+ if ($subKeyBrackets) {
162
+ if ($subKey) {
163
+ $param['value'] = array($subKey => $value);
164
+ } else {
165
+ $param['value'] = array($value);
166
+ }
167
+
168
+ $param['key'] = $this->_removeSubkeyPartFromKey($key, $subKeyBrackets);
169
+ $param = $this->_handleRecursiveParamForQueryStr($param);
170
+ }
171
+
172
+ return $param;
173
+ }
174
+
175
+ /**
176
+ * Remove subkey part from key
177
+ *
178
+ * @param string $key
179
+ * @param string $subKeyBrackets
180
+ * @return string
181
+ */
182
+ protected function _removeSubkeyPartFromKey($key, $subKeyBrackets)
183
+ {
184
+ return substr($key, 0, strrpos($key, $subKeyBrackets));
185
+ }
186
+
187
+ /**
188
+ * Get last part key from query array
189
+ *
190
+ * @param string $key
191
+ * @param bool $withBrackets
192
+ * @return string
193
+ */
194
+ protected function _getLastSubkey($key, $withBrackets = true)
195
+ {
196
+ $subKey = '';
197
+ $leftBracketSymbol = '[';
198
+ $rightBracketSymbol = ']';
199
+
200
+ $firstPos = strrpos($key, $leftBracketSymbol);
201
+ $lastPos = strrpos($key, $rightBracketSymbol);
202
+
203
+ if (($firstPos !== false || $lastPos !== false)
204
+ && ($firstPos < $lastPos)
205
+ ) {
206
+ $keyLength = $lastPos - $firstPos + 1;
207
+ $subKey = substr($key, $firstPos, $keyLength);
208
+
209
+ if (!$withBrackets) {
210
+ $subKey = ltrim($subKey, $leftBracketSymbol);
211
+ $subKey = rtrim($subKey, $rightBracketSymbol);
212
+ }
213
+ }
214
+
215
+ return $subKey;
216
+ }
217
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Attribute/Source/Category.php CHANGED
@@ -1,67 +1,67 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Categories source for product attribute
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author Vincent Enjalbert @ Web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Attribute_Source_Category extends Mage_Eav_Model_Entity_Attribute_Source_Abstract {
10
-
11
- protected $_options = null;
12
-
13
-
14
-
15
- public function getAllOptions($withEmpty = false) {
16
- if (is_null($this->_options)) {
17
- $this->_options = array();
18
- $categories = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents('name', Mage::app()->getRequest()->getParam('store', null));
19
- foreach($categories as $categoryId=>$categoryName)
20
- $this->_options[] = array('label'=>$categoryName, 'value'=>$categoryId);
21
- }
22
- $options = $this->_options;
23
- if ($withEmpty) {
24
- array_unshift($options, array('value' => '', 'label' => ''));
25
- }
26
- return $options;
27
- }
28
-
29
- public function getOptionText($value) {
30
- $options = $this->getAllOptions(false);
31
-
32
- foreach ($options as $item) {
33
- if ($item['value'] == $value) {
34
- return $item['label'];
35
- }
36
- }
37
- return false;
38
- }
39
-
40
- public function getFlatColums() {
41
- $attributeCode = $this->getAttribute()->getAttributeCode();
42
- $column = array(
43
- 'unsigned' => false,
44
- 'default' => null,
45
- 'extra' => null
46
- );
47
-
48
- $currentVersion = Mage::getVersion();
49
- if (version_compare($currentVersion, '1.6.0') < 0 || Mage::helper('core')->useDbCompatibleMode()) {
50
- $column['type'] = 'int(10)';
51
- $column['is_null'] = true;
52
- } else {
53
- $column['type'] = Varien_Db_Ddl_Table::TYPE_SMALLINT;
54
- $column['length'] = 10;
55
- $column['nullable'] = true;
56
- $column['comment'] = $attributeCode . ' column';
57
- }
58
-
59
- return array($attributeCode => $column);
60
- }
61
-
62
- public function getFlatUpdateSelect($store) {
63
- return Mage::getResourceModel('eav/entity_attribute')
64
- ->getFlatUpdateSelect($this->getAttribute(), $store);
65
- }
66
-
67
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Categories source for product attribute
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author Vincent Enjalbert @ Web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Attribute_Source_Category extends Mage_Eav_Model_Entity_Attribute_Source_Abstract {
10
+
11
+ protected $_options = null;
12
+
13
+
14
+
15
+ public function getAllOptions($withEmpty = false) {
16
+ if (is_null($this->_options)) {
17
+ $this->_options = array();
18
+ $categories = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents('name', Mage::app()->getRequest()->getParam('store', null));
19
+ foreach($categories as $categoryId=>$categoryName)
20
+ $this->_options[] = array('label'=>$categoryName, 'value'=>$categoryId);
21
+ }
22
+ $options = $this->_options;
23
+ if ($withEmpty) {
24
+ array_unshift($options, array('value' => '', 'label' => ''));
25
+ }
26
+ return $options;
27
+ }
28
+
29
+ public function getOptionText($value) {
30
+ $options = $this->getAllOptions(false);
31
+
32
+ foreach ($options as $item) {
33
+ if ($item['value'] == $value) {
34
+ return $item['label'];
35
+ }
36
+ }
37
+ return false;
38
+ }
39
+
40
+ public function getFlatColums() {
41
+ $attributeCode = $this->getAttribute()->getAttributeCode();
42
+ $column = array(
43
+ 'unsigned' => false,
44
+ 'default' => null,
45
+ 'extra' => null
46
+ );
47
+
48
+ $currentVersion = Mage::getVersion();
49
+ if (version_compare($currentVersion, '1.6.0') < 0 || Mage::helper('core')->useDbCompatibleMode()) {
50
+ $column['type'] = 'int(10)';
51
+ $column['is_null'] = true;
52
+ } else {
53
+ $column['type'] = Varien_Db_Ddl_Table::TYPE_SMALLINT;
54
+ $column['length'] = 10;
55
+ $column['nullable'] = true;
56
+ $column['comment'] = $attributeCode . ' column';
57
+ }
58
+
59
+ return array($attributeCode => $column);
60
+ }
61
+
62
+ public function getFlatUpdateSelect($store) {
63
+ return Mage::getResourceModel('eav/entity_attribute')
64
+ ->getFlatUpdateSelect($this->getAttribute(), $store);
65
+ }
66
+
67
  }
app/code/community/Profileolabs/Shoppingflux/Model/Catalog/Product/Collection.php CHANGED
@@ -1,26 +1,26 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Catalog_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection {
10
-
11
- /* WebCooking Fix to rewrite Varien_Data_Collection_Db::getSize() in order to solve pagination error caused by the groupBy clause */
12
- public function getSize() {
13
- if (is_null($this->_totalRecords)) {
14
- $sql = $this->getSelectCountSql();
15
-
16
- $result = $this->getConnection()->fetchAll($sql, $this->_bindParams);
17
-
18
-
19
- foreach ($result as $row) {
20
- $this->_totalRecords += reset($row);
21
- }
22
- }
23
- return intval($this->_totalRecords);
24
- }
25
-
26
- }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Catalog_Product_Collection extends Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection {
10
+
11
+ /* WebCooking Fix to rewrite Varien_Data_Collection_Db::getSize() in order to solve pagination error caused by the groupBy clause */
12
+ public function getSize() {
13
+ if (is_null($this->_totalRecords)) {
14
+ $sql = $this->getSelectCountSql();
15
+
16
+ $result = $this->getConnection()->fetchAll($sql, $this->_bindParams);
17
+
18
+
19
+ foreach ($result as $row) {
20
+ $this->_totalRecords += reset($row);
21
+ }
22
+ }
23
+ return intval($this->_totalRecords);
24
+ }
25
+
26
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Catalog/Resource/Eav/Attribute.php CHANGED
@@ -1,12 +1,12 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Model_Catalog_Resource_Eav_Attribute extends Mage_Eav_Model_Entity_Attribute {
4
-
5
- public function getSourceModel() {
6
- if($this->getAttributeCode() == 'shoppingflux_default_category') {
7
- return 'profileolabs_shoppingflux/attribute_source_category';
8
- }
9
- return parent::getSourceModel();
10
- }
11
-
12
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Model_Catalog_Resource_Eav_Attribute extends Mage_Eav_Model_Entity_Attribute {
4
+
5
+ public function getSourceModel() {
6
+ if($this->getAttributeCode() == 'shoppingflux_default_category') {
7
+ return 'profileolabs_shoppingflux/attribute_source_category';
8
+ }
9
+ return parent::getSourceModel();
10
+ }
11
+
12
  }
app/code/community/Profileolabs/Shoppingflux/Model/Config.php CHANGED
@@ -1,324 +1,356 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait, vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Config extends Varien_Object {
10
-
11
- public function getConfigData($key, $storeId = null) {
12
- $dataKey = str_replace('/', '_', 'conf/' . $key . '/' . (is_null($storeId) ? '0' : $storeId));
13
- if (!$this->hasData($dataKey)) {
14
- $value = Mage::getStoreConfig($key, $storeId);
15
- $this->setData($dataKey, $value);
16
- }
17
- return $this->getData($dataKey);
18
- }
19
-
20
- public function getConfigFlag($key, $storeId = null) {
21
- $dataKey = str_replace('/', '_', 'flag/' . $key . '/' . (is_null($storeId) ? '0' : $storeId));
22
- if (!$this->hasData($dataKey)) {
23
- $value = Mage::getStoreConfigFlag($key, $storeId);
24
- $this->setData($dataKey, $value);
25
- }
26
- return $this->getData($dataKey);
27
- }
28
-
29
- /**
30
- * Return API KEY
31
- * @return string
32
- */
33
- public function getApiKey($storeId = null) {
34
- return $this->getConfigData('shoppingflux/configuration/api_key', $storeId);
35
- }
36
-
37
- public function getIdClient($storeId = null) {
38
- return $this->getConfigData('shoppingflux/configuration/login', $storeId);
39
- }
40
-
41
- public function getIdTracking($storeId = null) {
42
- return $this->getConfigData('shoppingflux/configuration/id_tracking', $storeId);
43
- }
44
-
45
-
46
-
47
- public function isBuylineEnabled($storeId = null) {
48
- return $this->getConfigFlag('shoppingflux_export/configuration/enable_buyline', $storeId);
49
- }
50
-
51
- /*
52
- * Define is in test mode
53
- * @return boolean
54
- */
55
-
56
- public function isSandbox() {
57
- return $this->getConfigFlag('shoppingflux/configuration/is_sandbox');
58
- }
59
-
60
- /**
61
- * Get WS URI
62
- * @return string uri of web service
63
- */
64
- public function getWsUri() {
65
- if ($this->isSandbox())
66
- return $this->getConfigData('shoppingflux/configuration/ws_uri_sandbox');
67
- return $this->getConfigData('shoppingflux/configuration/ws_uri_prod');
68
- }
69
-
70
- public function isExportEnabled($storeId = null) {
71
- return $this->getConfigFlag('shoppingflux_export/general/active', $storeId);
72
- }
73
-
74
- public function isExportFilteredByAttribute($storeId = null) {
75
- return $this->getConfigFlag('shoppingflux_export/general/filter_by_attribute', $storeId);
76
- }
77
-
78
- /**
79
- * Retrieve if export sold out products
80
- *
81
- * @return boolean
82
- */
83
- public function isExportSoldout($storeId = null) {
84
- return $this->getConfigFlag('shoppingflux_export/general/export_soldout', $storeId);
85
- }
86
-
87
- public function isExportNotSalable($storeId = null) {
88
- return $this->getConfigFlag('shoppingflux_export/general/export_not_salable', $storeId);
89
- }
90
-
91
-
92
- public function getVisibilitiesToExport($storeId = null) {
93
- return explode(',', $this->getConfigData('shoppingflux_export/general/export_visibility', $storeId));
94
- }
95
-
96
- /**
97
- * Retrieve limit of product in query
98
- *
99
- * @return int
100
- */
101
- public function getExportProductLimit($storeId = null) {
102
- return (int) $this->getConfigData('shoppingflux_export/general/limit_product', $storeId);
103
- }
104
-
105
- public function getUseAllStoreCategories($storeId = null) {
106
- return $this->getConfigFlag('shoppingflux_export/category/all_store_categories', $storeId);
107
- }
108
-
109
- public function getUseAllStoreProducts($storeId = null) {
110
- return $this->getConfigFlag('shoppingflux_export/general/all_store_products', $storeId);
111
- }
112
-
113
- public function getUseOnlySFCategory($storeId = null) {
114
- return $this->getConfigFlag('shoppingflux_export/category/use_only_shoppingflux_category', $storeId);
115
- }
116
-
117
- public function getMaxCategoryLevel($storeId = null) {
118
- return $this->getConfigData('shoppingflux_export/category/max_category_level', $storeId);
119
- }
120
-
121
- public function getEnableEvents($storeId = null) {
122
- return $this->getConfigFlag('shoppingflux_export/general/enable_events', $storeId);
123
- }
124
-
125
- public function getManageConfigurables($storeId = null) {
126
- return $this->getConfigFlag('shoppingflux_export/general/manage_configurable', $storeId);
127
- }
128
-
129
- public function getManageCatalogRules($storeId = null) {
130
- return $this->getConfigFlag('shoppingflux_export/general/manage_catalog_rules', $storeId);
131
- }
132
-
133
- public function getManageMediaGallery($storeId = null) {
134
- return $this->getConfigFlag('shoppingflux_export/general/manage_media_gallery', $storeId);
135
- }
136
-
137
- public function getQtyIncrements($product) {
138
- if(!$product->getStockItem()->getData('enable_qty_increments')) {
139
- return 1;
140
- }
141
- return max(1, intval($product->getStockItem()->getData('qty_increments')));
142
- }
143
-
144
- public function getTransformQtyIncrements($product, $storeId = null) {
145
- if(!$this->getConfigFlag('shoppingflux_export/general/transform_qty_increments', $storeId)) {
146
- return false;
147
- }
148
- return $this->getQtyIncrements($product) > 1;
149
- }
150
-
151
-
152
-
153
- /**
154
- * Return Attributes Knowed in array with key=>value
155
- * key = node adn value = inner text
156
- * @return array
157
- * @deprecated since version 0.8.0
158
- */
159
- public function getMappingAttributesKnow($storeId = null) {
160
- return $this->getConfigData('shoppingflux_export/attributes_know', $storeId);
161
- }
162
-
163
- /**
164
- * Return Attributes Unknowed in array with key=>value
165
- * key = node adn value = inner text
166
- * @param int $storeId
167
- * @return array
168
- * @deprecated since version 0.8.0
169
- */
170
- public function getMappgingAttributesUnKnow($storeId = null) {
171
- return $this->getConfigData('shoppingflux_export/attributes_unknow', $storeId);
172
- }
173
-
174
-
175
- public function getMappingAttributes($storeId = null) {
176
- $data = $this->getConfigData('shoppingflux_export/attributes_mapping', $storeId);
177
- unset($data['additional']);
178
- unset($data['additional,']);
179
- return $data;
180
- }
181
-
182
- /**
183
- * Return Attributes Unknowed in array with key=>value
184
- * key = node adn value = inner text
185
- * @param int $storeId
186
- * @return array
187
- */
188
- public function getAdditionalAttributes($storeId = null) {
189
- $additionnal = $this->getConfigData('shoppingflux_export/attributes_mapping/additional', $storeId);
190
- $additionnal = explode(',',$additionnal);
191
- $additionnal = array_filter($additionnal);
192
- $allAttributes = $this->getMappingAttributes($storeId);
193
- //We do not want attributes that are already in known or unknown lists
194
- $additionnal = array_diff($additionnal, $allAttributes);
195
- return $additionnal;
196
- }
197
-
198
- /**
199
- * Return ALL Attributes Knowed and Unknowed in array with key=>value
200
- * key = node adn value = inner text
201
- * @return array
202
- * @param int $storeId
203
- * @deprecated since version 0.8.0
204
- */
205
- public function getMappingAllAttributes($storeId = null) {
206
- return $this->getMappingAttributes($storeId);
207
- //return array_merge($this->getMappingAttributesKnow($storeId), $this->getMappgingAttributesUnKnow($storeId));
208
- }
209
-
210
- public function getMemoryLimit() {
211
- $memoryLimit = intval($this->getConfigData('shoppingflux_export/general/memory_limit'));
212
- if($memoryLimit>10) {
213
- return $memoryLimit;
214
- }
215
- return 2048;
216
- }
217
-
218
- public function isSyncEnabled() {
219
- foreach(Mage::app()->getStores() as $store) {
220
- if($this->getConfigFlag('shoppingflux_export/general/enable_sync', $store->getId())) {
221
- return true;
222
- }
223
- }
224
- return false;
225
- }
226
-
227
- public function useManageStock($storeId = null) {
228
- return $this->getConfigFlag('shoppingflux_export/general/use_manage_stock', $storeId);
229
- }
230
-
231
- /** ORDERS * */
232
- public function isOrdersEnabled($storeId = null) {
233
- return $this->getConfigFlag('shoppingflux_mo/manageorders/enabled', $storeId);
234
- }
235
-
236
- /**
237
- * Get Limit orders
238
- * @return int
239
- */
240
- public function getLimitOrders($storeId = null) {
241
- $limit = $this->getConfigData('shoppingflux_mo/manageorders/limit_orders', $storeId);
242
- if ($limit < 1)
243
- $limit = 10;
244
- return $limit;
245
- }
246
-
247
- public function getAddressLengthLimit($storeId = null) {
248
- $limit = $this->getConfigData('shoppingflux_mo/import_customer/limit_address_length');
249
- if(!$limit || $limit < 20)
250
- return false;
251
- return $limit;
252
- }
253
-
254
- /**
255
- * get customer Group
256
- */
257
- public function getCustomerGroupIdFor($marketplace = false, $storeId = null) {
258
- if ($marketplace) {
259
- $marketplace = strtolower($marketplace);
260
- $customerGroupId = $this->getConfigData('shoppingflux_mo/import_customer/' . $marketplace . "_group", $storeId);
261
- if ($customerGroupId)
262
- return $customerGroupId;
263
- }
264
- $customerGroupId = $this->getConfigData("shoppingflux_mo/import_customer/default_group", $storeId);
265
- if ($customerGroupId)
266
- return $customerGroupId;
267
- return false;
268
- }
269
-
270
-
271
-
272
- public function getShippingMethodFor($marketplace = false, $sfShippingMethod = false, $storeId = null) {
273
- $defaultShippingMethod = Mage::getStoreConfig('shoppingflux_mo/shipping_method/default_method', $storeId);
274
- if(!$marketplace) {
275
- return $defaultShippingMethod;
276
- }
277
- $marketplace = strtolower($marketplace);
278
- $marketplaceShippingMode = Mage::getStoreConfig('shoppingflux_mo/shipping_method/' . $marketplace . '_method', $storeId);
279
- if(!$sfShippingMethod) {
280
- return $marketplaceShippingMode?$marketplaceShippingMode:$defaultShippingMethod;
281
- }
282
- $sfShippingMethodCode = Mage::getModel('profileolabs_shoppingflux/manageorders_shipping_method')->getFullShippingMethodCodeFor($marketplace, $sfShippingMethod);
283
- $sfShippingMethodCode = preg_replace('%[^a-zA-Z0-9_]%', '', $sfShippingMethodCode);
284
- $shippingMethod = Mage::getStoreConfig('shoppingflux_mo/advanced_shipping_method/' . $sfShippingMethodCode, $storeId);
285
- return $shippingMethod?$shippingMethod:($marketplaceShippingMode?$marketplaceShippingMode:$defaultShippingMethod);
286
- }
287
-
288
- public function getShipmentUpdateLimit($storeId=null) {
289
- $nbHours = Mage::getStoreConfig('shoppingflux_mo/shipment_update/limit_hours', $storeId);
290
- $nbHours = intval($nbHours);
291
- if(!$nbHours) {
292
- return date('Y-m-d H:i:s', strtotime('-20 minutes'));
293
- }
294
- return date('Y-m-d H:i:s', strtotime('-'.$nbHours.' hours'));
295
- }
296
-
297
- /**
298
- * Retrieve if we must to create invoice
299
- *
300
- * @return boolean
301
- */
302
- public function createInvoice($storeId = null) {
303
- return $this->getConfigFlag('shoppingflux_mo/manageorders/create_invoice', $storeId);
304
- }
305
-
306
- /**
307
- * Retrieve if we must to apply tax
308
- *
309
- * @return boolean
310
- */
311
- public function applyTax($storeId = null) {
312
- return true;
313
- //return $this->getConfigFlag('shoppingflux_mo/manageorders/apply_tax', $storeId);
314
- }
315
-
316
- public function preferMobilePhone($storeId = null) {
317
- return $this->getConfigFlag("shoppingflux_mo/import_customer/prefer_mobile_phone", $storeId);
318
- }
319
-
320
- public function getMobilePhoneAttribute($storeId = null) {
321
- return $this->getConfigData("shoppingflux_mo/import_customer/mobile_attribute", $storeId);
322
- }
323
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
324
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait, vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Config extends Varien_Object {
10
+
11
+ public function getConfigData($key, $storeId = null) {
12
+ $dataKey = str_replace('/', '_', 'conf/' . $key . '/' . (is_null($storeId) ? '0' : $storeId));
13
+ if (!$this->hasData($dataKey)) {
14
+ $value = Mage::getStoreConfig($key, $storeId);
15
+ $this->setData($dataKey, $value);
16
+ }
17
+ return $this->getData($dataKey);
18
+ }
19
+
20
+ public function getConfigFlag($key, $storeId = null) {
21
+ $dataKey = str_replace('/', '_', 'flag/' . $key . '/' . (is_null($storeId) ? '0' : $storeId));
22
+ if (!$this->hasData($dataKey)) {
23
+ $value = Mage::getStoreConfigFlag($key, $storeId);
24
+ $this->setData($dataKey, $value);
25
+ }
26
+ return $this->getData($dataKey);
27
+ }
28
+
29
+ /**
30
+ * Return API KEY
31
+ * @return string
32
+ */
33
+ public function getApiKey($storeId = null) {
34
+ return $this->getConfigData('shoppingflux/configuration/api_key', $storeId);
35
+ }
36
+
37
+ public function getIdClient($storeId = null) {
38
+ return $this->getConfigData('shoppingflux/configuration/login', $storeId);
39
+ }
40
+
41
+ public function getIdTracking($storeId = null) {
42
+ return $this->getConfigData('shoppingflux/configuration/id_tracking', $storeId);
43
+ }
44
+
45
+
46
+
47
+ public function isBuylineEnabled($storeId = null) {
48
+ return $this->getConfigFlag('shoppingflux_export/configuration/enable_buyline', $storeId);
49
+ }
50
+
51
+ /*
52
+ * Define is in test mode
53
+ * @return boolean
54
+ */
55
+
56
+ public function isSandbox() {
57
+ return $this->getConfigFlag('shoppingflux/configuration/is_sandbox');
58
+ }
59
+
60
+ /**
61
+ * Get WS URI
62
+ * @return string uri of web service
63
+ */
64
+ public function getWsUri() {
65
+ if ($this->isSandbox())
66
+ return $this->getConfigData('shoppingflux/configuration/ws_uri_sandbox');
67
+ return $this->getConfigData('shoppingflux/configuration/ws_uri_prod');
68
+ }
69
+
70
+ public function isExportEnabled($storeId = null) {
71
+ return $this->getConfigFlag('shoppingflux_export/general/active', $storeId);
72
+ }
73
+
74
+ public function isExportFilteredByAttribute($storeId = null) {
75
+ return $this->getConfigFlag('shoppingflux_export/general/filter_by_attribute', $storeId);
76
+ }
77
+
78
+ /**
79
+ * Retrieve if export sold out products
80
+ *
81
+ * @return boolean
82
+ */
83
+ public function isExportSoldout($storeId = null) {
84
+ return $this->getConfigFlag('shoppingflux_export/general/export_soldout', $storeId);
85
+ }
86
+
87
+ public function isExportNotSalable($storeId = null) {
88
+ return $this->getConfigFlag('shoppingflux_export/general/export_not_salable', $storeId);
89
+ }
90
+
91
+ /**
92
+ * @param int|null $storeId
93
+ * @return int|false
94
+ */
95
+ public function getNotSalableRetentionDuration($storeId = null)
96
+ {
97
+ $seconds = 0;
98
+
99
+ if (!$this->isExportSoldout($storeId) && !$this->isExportNotSalable($storeId)) {
100
+ if ($this->getConfigFlag('shoppingflux_export/general/enable_not_salable_retention', $storeId)) {
101
+ $hours = $this->getConfigData('shoppingflux_export/general/not_salable_retention_duration', $storeId);
102
+ $seconds = max(0, min((int) trim($hours), 168)) * 3600;
103
+ }
104
+ }
105
+
106
+ return ($seconds > 0 ? $seconds : false);
107
+ }
108
+
109
+ /**
110
+ * @param int|null $storeId
111
+ * @return bool
112
+ */
113
+ public function isNotSalableRetentionEnabled($storeId = null)
114
+ {
115
+ return ($this->getNotSalableRetentionDuration($storeId) !== false);
116
+ }
117
+
118
+ public function getVisibilitiesToExport($storeId = null) {
119
+ return explode(',', $this->getConfigData('shoppingflux_export/general/export_visibility', $storeId));
120
+ }
121
+
122
+ /**
123
+ * Retrieve limit of product in query
124
+ *
125
+ * @return int
126
+ */
127
+ public function getExportProductLimit($storeId = null) {
128
+ return (int) $this->getConfigData('shoppingflux_export/general/limit_product', $storeId);
129
+ }
130
+
131
+ public function getUseAllStoreCategories($storeId = null) {
132
+ return $this->getConfigFlag('shoppingflux_export/category/all_store_categories', $storeId);
133
+ }
134
+
135
+ public function getUseAllStoreProducts($storeId = null) {
136
+ return $this->getConfigFlag('shoppingflux_export/general/all_store_products', $storeId);
137
+ }
138
+
139
+ public function getUseOnlySFCategory($storeId = null) {
140
+ return $this->getConfigFlag('shoppingflux_export/category/use_only_shoppingflux_category', $storeId);
141
+ }
142
+
143
+ public function getMaxCategoryLevel($storeId = null) {
144
+ return $this->getConfigData('shoppingflux_export/category/max_category_level', $storeId);
145
+ }
146
+
147
+ public function getEnableEvents($storeId = null) {
148
+ return $this->getConfigFlag('shoppingflux_export/general/enable_events', $storeId);
149
+ }
150
+
151
+ public function getManageConfigurables($storeId = null) {
152
+ return $this->getConfigFlag('shoppingflux_export/general/manage_configurable', $storeId);
153
+ }
154
+
155
+ public function getManageCatalogRules($storeId = null) {
156
+ return $this->getConfigFlag('shoppingflux_export/general/manage_catalog_rules', $storeId);
157
+ }
158
+
159
+ public function getManageMediaGallery($storeId = null) {
160
+ return $this->getConfigFlag('shoppingflux_export/general/manage_media_gallery', $storeId);
161
+ }
162
+
163
+ public function getQtyIncrements($product) {
164
+ if(!$product->getStockItem()->getData('enable_qty_increments')) {
165
+ return 1;
166
+ }
167
+ return max(1, intval($product->getStockItem()->getData('qty_increments')));
168
+ }
169
+
170
+ public function getTransformQtyIncrements($product, $storeId = null) {
171
+ if(!$this->getConfigFlag('shoppingflux_export/general/transform_qty_increments', $storeId)) {
172
+ return false;
173
+ }
174
+ return $this->getQtyIncrements($product) > 1;
175
+ }
176
+
177
+
178
+
179
+ /**
180
+ * Return Attributes Knowed in array with key=>value
181
+ * key = node adn value = inner text
182
+ * @return array
183
+ * @deprecated since version 0.8.0
184
+ */
185
+ public function getMappingAttributesKnow($storeId = null) {
186
+ return $this->getConfigData('shoppingflux_export/attributes_know', $storeId);
187
+ }
188
+
189
+ /**
190
+ * Return Attributes Unknowed in array with key=>value
191
+ * key = node adn value = inner text
192
+ * @param int $storeId
193
+ * @return array
194
+ * @deprecated since version 0.8.0
195
+ */
196
+ public function getMappgingAttributesUnKnow($storeId = null) {
197
+ return $this->getConfigData('shoppingflux_export/attributes_unknow', $storeId);
198
+ }
199
+
200
+
201
+ public function getMappingAttributes($storeId = null) {
202
+ $data = $this->getConfigData('shoppingflux_export/attributes_mapping', $storeId);
203
+ unset($data['additional']);
204
+ unset($data['additional,']);
205
+ return $data;
206
+ }
207
+
208
+ /**
209
+ * Return Attributes Unknowed in array with key=>value
210
+ * key = node adn value = inner text
211
+ * @param int $storeId
212
+ * @return array
213
+ */
214
+ public function getAdditionalAttributes($storeId = null) {
215
+ $additionnal = $this->getConfigData('shoppingflux_export/attributes_mapping/additional', $storeId);
216
+ $additionnal = explode(',',$additionnal);
217
+ $additionnal = array_filter($additionnal);
218
+ $allAttributes = $this->getMappingAttributes($storeId);
219
+ //We do not want attributes that are already in known or unknown lists
220
+ $additionnal = array_diff($additionnal, $allAttributes);
221
+ return $additionnal;
222
+ }
223
+
224
+ /**
225
+ * Return ALL Attributes Knowed and Unknowed in array with key=>value
226
+ * key = node adn value = inner text
227
+ * @return array
228
+ * @param int $storeId
229
+ * @deprecated since version 0.8.0
230
+ */
231
+ public function getMappingAllAttributes($storeId = null) {
232
+ return $this->getMappingAttributes($storeId);
233
+ //return array_merge($this->getMappingAttributesKnow($storeId), $this->getMappgingAttributesUnKnow($storeId));
234
+ }
235
+
236
+ public function getMemoryLimit() {
237
+ $memoryLimit = intval($this->getConfigData('shoppingflux_export/general/memory_limit'));
238
+ if($memoryLimit>10) {
239
+ return $memoryLimit;
240
+ }
241
+ return 2048;
242
+ }
243
+
244
+ public function isSyncEnabled() {
245
+ foreach(Mage::app()->getStores() as $store) {
246
+ if($this->getConfigFlag('shoppingflux_export/general/enable_sync', $store->getId())) {
247
+ return true;
248
+ }
249
+ }
250
+ return false;
251
+ }
252
+
253
+ public function useManageStock($storeId = null) {
254
+ return $this->getConfigFlag('shoppingflux_export/general/use_manage_stock', $storeId);
255
+ }
256
+
257
+ public function getExportedImageCount($storeId = null) {
258
+ $exportAll = $this->getConfigFlag('shoppingflux_export/general/export_all_images', $storeId);
259
+ $count = (int) $this->getConfigData('shoppingflux_export/general/exported_image_count', $storeId);
260
+ return (!$exportAll && ($count > 0) ? $count : false);
261
+ }
262
+
263
+ /** ORDERS * */
264
+ public function isOrdersEnabled($storeId = null) {
265
+ return $this->getConfigFlag('shoppingflux_mo/manageorders/enabled', $storeId);
266
+ }
267
+
268
+ /**
269
+ * Get Limit orders
270
+ * @return int
271
+ */
272
+ public function getLimitOrders($storeId = null) {
273
+ $limit = $this->getConfigData('shoppingflux_mo/manageorders/limit_orders', $storeId);
274
+ if ($limit < 1)
275
+ $limit = 10;
276
+ return $limit;
277
+ }
278
+
279
+ public function getAddressLengthLimit($storeId = null) {
280
+ $limit = $this->getConfigData('shoppingflux_mo/import_customer/limit_address_length');
281
+ if(!$limit || $limit < 20)
282
+ return false;
283
+ return $limit;
284
+ }
285
+
286
+ /**
287
+ * get customer Group
288
+ */
289
+ public function getCustomerGroupIdFor($marketplace = false, $storeId = null) {
290
+ if ($marketplace) {
291
+ $marketplace = strtolower($marketplace);
292
+ $customerGroupId = $this->getConfigData('shoppingflux_mo/import_customer/' . $marketplace . "_group", $storeId);
293
+ if ($customerGroupId)
294
+ return $customerGroupId;
295
+ }
296
+ $customerGroupId = $this->getConfigData("shoppingflux_mo/import_customer/default_group", $storeId);
297
+ if ($customerGroupId)
298
+ return $customerGroupId;
299
+ return false;
300
+ }
301
+
302
+
303
+
304
+ public function getShippingMethodFor($marketplace = false, $sfShippingMethod = false, $storeId = null) {
305
+ $defaultShippingMethod = Mage::getStoreConfig('shoppingflux_mo/shipping_method/default_method', $storeId);
306
+ if(!$marketplace) {
307
+ return $defaultShippingMethod;
308
+ }
309
+ $marketplace = strtolower($marketplace);
310
+ $marketplaceShippingMode = Mage::getStoreConfig('shoppingflux_mo/shipping_method/' . $marketplace . '_method', $storeId);
311
+ if(!$sfShippingMethod) {
312
+ return $marketplaceShippingMode?$marketplaceShippingMode:$defaultShippingMethod;
313
+ }
314
+ $sfShippingMethodCode = Mage::getModel('profileolabs_shoppingflux/manageorders_shipping_method')->getFullShippingMethodCodeFor($marketplace, $sfShippingMethod);
315
+ $sfShippingMethodCode = preg_replace('%[^a-zA-Z0-9_]%', '', $sfShippingMethodCode);
316
+ $shippingMethod = Mage::getStoreConfig('shoppingflux_mo/advanced_shipping_method/' . $sfShippingMethodCode, $storeId);
317
+ return $shippingMethod?$shippingMethod:($marketplaceShippingMode?$marketplaceShippingMode:$defaultShippingMethod);
318
+ }
319
+
320
+ public function getShipmentUpdateLimit($storeId=null) {
321
+ $nbHours = Mage::getStoreConfig('shoppingflux_mo/shipment_update/limit_hours', $storeId);
322
+ $nbHours = intval($nbHours);
323
+ if(!$nbHours) {
324
+ return date('Y-m-d H:i:s', strtotime('-20 minutes'));
325
+ }
326
+ return date('Y-m-d H:i:s', strtotime('-'.$nbHours.' hours'));
327
+ }
328
+
329
+ /**
330
+ * Retrieve if we must to create invoice
331
+ *
332
+ * @return boolean
333
+ */
334
+ public function createInvoice($storeId = null) {
335
+ return $this->getConfigFlag('shoppingflux_mo/manageorders/create_invoice', $storeId);
336
+ }
337
+
338
+ /**
339
+ * Retrieve if we must to apply tax
340
+ *
341
+ * @return boolean
342
+ */
343
+ public function applyTax($storeId = null) {
344
+ return true;
345
+ //return $this->getConfigFlag('shoppingflux_mo/manageorders/apply_tax', $storeId);
346
+ }
347
+
348
+ public function preferMobilePhone($storeId = null) {
349
+ return $this->getConfigFlag("shoppingflux_mo/import_customer/prefer_mobile_phone", $storeId);
350
+ }
351
+
352
+ public function getMobilePhoneAttribute($storeId = null) {
353
+ return $this->getConfigData("shoppingflux_mo/import_customer/mobile_attribute", $storeId);
354
+ }
355
+
356
  }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Convert/Parser/Product.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
- class Profileolabs_Shoppingflux_Model_Export_Convert_Parser_Product
3
- extends Mage_Catalog_Model_Convert_Parser_Product
4
- {
5
-
6
-
7
- /**
8
- * Retrieve accessible external product attributes
9
- *
10
- * @return array
11
- */
12
- public function getExternalAttributes()
13
- {
14
- $productAttributes = array();
15
- if(file_exists(Mage::getModuleDir(null,'Mage_Catalog') ."Model/Resource/Eav/Mysql4/Product/Attribute/Collection")) {
16
- $productAttributes = Mage::getResourceModel('catalog/product_attribute_collection')->load();
17
- } else
18
- {
19
- $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId();
20
- $productAttributes = Mage::getResourceModel('eav/entity_attribute_collection')
21
- ->setEntityTypeFilter($entityTypeId)
22
- ->load();
23
- }
24
- $attributes = $this->_externalFields;
25
-
26
- foreach ($productAttributes as $attr) {
27
- $code = $attr->getAttributeCode();
28
- if (in_array($code, $this->_internalFields) || $attr->getFrontendInput() == 'hidden') {
29
- continue;
30
- }
31
- $attributes[$code] = $code;
32
- }
33
-
34
- foreach ($this->_inventoryFields as $field) {
35
- $attributes[$field] = $field;
36
- }
37
- return $attributes;
38
- }
39
- }
1
+ <?php
2
+ class Profileolabs_Shoppingflux_Model_Export_Convert_Parser_Product
3
+ extends Mage_Catalog_Model_Convert_Parser_Product
4
+ {
5
+
6
+
7
+ /**
8
+ * Retrieve accessible external product attributes
9
+ *
10
+ * @return array
11
+ */
12
+ public function getExternalAttributes()
13
+ {
14
+ $productAttributes = array();
15
+ if(file_exists(Mage::getModuleDir(null,'Mage_Catalog') ."Model/Resource/Eav/Mysql4/Product/Attribute/Collection")) {
16
+ $productAttributes = Mage::getResourceModel('catalog/product_attribute_collection')->load();
17
+ } else
18
+ {
19
+ $entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getId();
20
+ $productAttributes = Mage::getResourceModel('eav/entity_attribute_collection')
21
+ ->setEntityTypeFilter($entityTypeId)
22
+ ->load();
23
+ }
24
+ $attributes = $this->_externalFields;
25
+
26
+ foreach ($productAttributes as $attr) {
27
+ $code = $attr->getAttributeCode();
28
+ if (in_array($code, $this->_internalFields) || $attr->getFrontendInput() == 'hidden') {
29
+ continue;
30
+ }
31
+ $attributes[$code] = $code;
32
+ }
33
+
34
+ foreach ($this->_inventoryFields as $field) {
35
+ $attributes[$field] = $field;
36
+ }
37
+ return $attributes;
38
+ }
39
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Flow.php CHANGED
@@ -1,800 +1,800 @@
1
- <?php
2
-
3
- /**
4
- *
5
- * @deprecated deprecated since 0.1.1
6
- *
7
- */
8
- class Profileolabs_Shoppingflux_Model_Export_Flow {
9
-
10
- protected $_exceptions = array();
11
- protected $_lastCount = 0;
12
- protected $_totalCount = null;
13
- protected $_totalOffset = null;
14
- protected $_fileName = "flow.xml";
15
- protected $_xmlFlow = "";
16
- protected $_attributes = null;
17
- protected $_storeId = 0;
18
- protected $_errors = array();
19
-
20
-
21
-
22
- /*
23
- * Products collection
24
- * @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
25
- */
26
- protected $_productCollection = null;
27
-
28
- /**
29
- * Get node XML for a product
30
- * @param Mage_Catalog_Model_Product $product
31
- * @return string $nodeXml
32
- */
33
- protected function _getProductNode($product) {
34
-
35
- $_helper = Mage::helper('catalog/output');
36
-
37
- $product->setStoreId($this->getStoreId());
38
-
39
-
40
-
41
- $nodeXml = "<product>" . chr(10);
42
-
43
- $nodeXml .= $this->getNode("id-product", $product->getId());
44
-
45
- //$nodeXml .= $this->getNode("sku",$product->getSku());
46
-
47
- foreach ($this->getAttributesForXml() as $nameNode => $valueNode) {
48
-
49
- $data = $product->getData($valueNode);
50
-
51
-
52
-
53
- $attribute = $product->getResource()->getAttribute($valueNode);
54
- if ($attribute) {
55
-
56
- $data = $product->getResource()->getAttribute($valueNode)->getFrontend()->getValue($product);
57
- $data = $_helper->productAttribute($product, $data, $valueNode);
58
- }
59
-
60
-
61
-
62
- //Synthetize it
63
- $method = "get" . ucfirst($valueNode);
64
- if (method_exists($product, $method))
65
- $data = $product->$method();
66
-
67
- //TODO remove this
68
- if ($data == "No" || $data == "Non")
69
- $data = "";
70
-
71
- //Exceptions data
72
- if ($nameNode == 'shipping_delay' && empty($data))
73
- $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
74
-
75
- if ($nameNode == 'quantity')
76
- $data = round($data);
77
-
78
-
79
- $nodeXml .= $this->getNode($nameNode, $data);
80
- }
81
-
82
- //Add stock status
83
- $nodeXml .= $this->getNode("is-in-stock", (int) $product->isSaleable());
84
-
85
- //Add product url
86
- $nodeXml .= $this->getNode("product-url", $this->cleanUrl($product->getProductUrl(false)));
87
-
88
- //Add image's nodes
89
- $nodeXml .= $this->getImages($product);
90
-
91
- //Add categories
92
- $nodeXml .= $this->getCategories($product);
93
-
94
- //ADD Prices
95
- $nodeXml .= $this->getPrices($product);
96
-
97
- //ADD PARENT ID
98
- $nodeXml .= $this->getParentId($product);
99
-
100
- //ADD Shipping Name
101
- $nodeXml .= $this->getShippingName();
102
-
103
- //Add ShippingPrice
104
- $nodeXml .= $this->getShippingPrice($product);
105
-
106
- //Add Options
107
- $nodeXml .= $this->getOptions($product);
108
-
109
- $nodeXml .= $this->getNode("sku", $product->getSku());
110
-
111
- $nodeXml .= "</product>" . chr(10);
112
-
113
-
114
- return $nodeXml;
115
- }
116
-
117
- protected function getOptions($product) {
118
- $nodes = "<options>" . chr(10);
119
- $labels = array();
120
- if ($product->getTypeId() == "configurable") {
121
- $attributes = $product->getTypeInstance()->getConfigurableAttributes();
122
- foreach ($attributes as $attribute) {
123
- $options = $attribute->getProductAttribute()->getSource()->getAllOptions(false);
124
- if (count($options)) {
125
- $labels = array();
126
- foreach ($options as $option)
127
- $labels[] = $option['label'];
128
-
129
- $nodes .= $this->getNode($attribute->getProductAttribute()->getAttributeCode(), implode(',', $labels));
130
- }
131
- }
132
- }
133
- /* elseif(count($product->getOptions()))
134
- {
135
- $options = $product->getOptions();
136
- foreach($options as $option)
137
- {
138
- foreach($option->getValues() as $value)
139
- {
140
- $labels[] = $value->getTitle();
141
- }
142
-
143
- $nodes .= $this->getNode($option->getTitle(),implode(',',$labels));
144
-
145
- }
146
- } */
147
-
148
-
149
- $nodes .= "</options>" . chr(10);
150
- return $nodes;
151
- }
152
-
153
- protected function getShippingPrice($product) {
154
- $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
155
- $shippingPrice = 0;
156
- if (!empty($carrier)) {
157
-
158
- $countryCode = $this->getConfig()->getConfigData('shoppingflux_export/general/shipping_price_based_on');
159
- $shippingPrice = $this->getHelper()->getShippingPrice($product, $carrier, $countryCode);
160
- }
161
-
162
- if (!$shippingPrice) {
163
- $shippingPrice = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
164
- }
165
-
166
- $node = "";
167
- $node = $this->getNode("shipping-price", $shippingPrice);
168
-
169
- return $node;
170
- }
171
-
172
- protected function getShippingName() {
173
- $node = "";
174
- $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
175
- if (empty($carrier))
176
- return $node;
177
- $carrierTab = explode('_', $carrier);
178
- list($carrierCode, $methodCode) = $carrierTab;
179
-
180
- $node = $this->getNode("shipping-name", ucfirst($methodCode));
181
-
182
- return $node;
183
- }
184
-
185
- protected function getParentId($product, $raw = false) {
186
- $node = "";
187
- $ids = array();
188
- $ids = Mage::getResourceSingleton('catalog/product_type_configurable')
189
- ->getParentIdsByChild($product->getId());
190
-
191
- if (!count($ids))
192
- $ids = Mage::getResourceSingleton('bundle/selection')
193
- ->getParentIdsByChild($product->getId());
194
-
195
- $idParent = count($ids) ? current($ids) : "";
196
-
197
- if ($raw)
198
- return $idParent;
199
-
200
- $node = $this->getNode("parent-id", $idParent);
201
-
202
- return $node;
203
- }
204
-
205
- private function _getMediaGallery($product) {
206
- $media = $product->getData('media_gallery');
207
- if (is_null($media)) {
208
- if ($attribute = $product->getResource()->getAttribute('media_gallery')) {
209
- $attribute->getBackend()->afterLoad($product);
210
- $media = $product->getData('media_gallery');
211
- }
212
- }
213
- return $media;
214
- }
215
-
216
- private function _imageIsValid($url) {
217
- return (trim($url) != '' && !preg_match('%(no_selection|no_image\.jpg)$%i', $url));
218
- }
219
-
220
- /**
221
- * Get images of product
222
- * @param Mage_Catalog_Model_Product $product
223
- * @return string $nodes
224
- */
225
- protected function getImages($product) {
226
- $nodes = "";
227
-
228
- $mediaUrl = Mage::getBaseUrl('media') . 'catalog/product';
229
-
230
- $images = array();
231
-
232
- $baseImage = Mage::helper('catalog/product')->getImageUrl($product);
233
- if ($this->_imageIsValid($baseImage)) {
234
- $images[] = $baseImage;
235
- }
236
- $smallimage = Mage::helper('catalog/product')->getSmallImageUrl($product);
237
- if ($this->_imageIsValid($smallimage)) {
238
- $images[] = $smallimage;
239
- }
240
-
241
- $additionalImages = $this->_getMediaGallery($product);
242
- if ($additionalImages)
243
- $additionalImages = $additionalImages['images'];
244
- foreach ($additionalImages as $additionalImage) {
245
- $image = Mage::getSingleton('catalog/product_media_config')->getMediaUrl($additionalImage['file']);
246
- if ($this->_imageIsValid($image)) {
247
- $images[] = $image;
248
- }
249
- }
250
-
251
- $images = array_unique($images);
252
- $images = array_values($images);
253
-
254
- if (empty($images)) {
255
- $parentId = $this->getParentId($product, true);
256
- if (!empty($parentId)) {
257
- $parent = Mage::getModel('catalog/product')->load($parentId);
258
- return $this->getImages($parent);
259
- }
260
- }
261
-
262
- foreach ($images as $i => $image) {
263
- $nodes .= $this->getNode("image-url-" . ($i + 1), $image);
264
- }
265
-
266
-
267
- //Complet with empty nodes
268
- for ($j = $i+1; $j < 6; $j++) {
269
- $nodes .= $this->getNode("image-url-" . $j, '');
270
- }
271
-
272
- return $nodes;
273
-
274
-
275
-
276
-
277
-
278
-
279
- /*
280
- $i = 1;
281
- $imagesFound = false;
282
- if ($product->getImage() != "" && $product->getImage() != 'no_selection') {
283
- $nodes .= $this->getNode("image-url-" . $i++, $mediaUrl . $product->getImage());
284
- $imagesFound = true;
285
- }
286
-
287
- //LOAD media gallery for this product
288
- $mediaGallery = $product->getResource()->getAttribute('media_gallery');
289
- $mediaGallery->getBackend()->afterLoad($product);
290
-
291
- if ($product->getMediaGalleryImages() instanceof Varien_Data_Collection) {
292
- foreach ($product->getMediaGalleryImages() as $image) {
293
- $imagesFound = true;
294
- $nodes .= $this->getNode("image-url-" . $i++, $image->getUrl());
295
- if ($i == 6)
296
- break;
297
- }
298
- }
299
-
300
-
301
-
302
-
303
- if (!$imagesFound) {//Images not found, we try to get them from parent if exists
304
- $parentId = $this->getParentId($product, true);
305
- if (!empty($parentId)) {
306
- $parent = Mage::getModel('catalog/product')->load($parentId);
307
- if ($parent->getId()) {
308
- if ($parent->getImage() != "" && $parent->getImage() != 'no_selection') {
309
- $nodes .= $this->getNode("image-url-" . $i++, $mediaUrl . $parent->getImage());
310
- }
311
-
312
- $mediaGallery = $parent->getResource()->getAttribute('media_gallery');
313
- $mediaGallery->getBackend()->afterLoad($parent);
314
- if ($parent->getMediaGalleryImages() instanceof Varien_Data_Collection)
315
- foreach ($parent->getMediaGalleryImages() as $image) {
316
- $nodes .= $this->getNode("image-url-" . $i++, $image->getUrl());
317
- if ($i == 6)
318
- break;
319
- }
320
- }
321
- }
322
- }
323
-
324
- //Complet with empty nodes
325
- for ($j = $i; $j < 6; $j++) {
326
- $nodes .= $this->getNode("image-url-" . $i++, '');
327
- }
328
-
329
-
330
- return $nodes;*/
331
- }
332
-
333
- /**
334
- * Get categories of product
335
- * @param Mage_Catalog_Model_Product $product
336
- * @return string $nodes
337
- */
338
- protected function getCategories($product) {
339
- $nodes = "";
340
- $categoryCollection = $product->getCategoryCollection()
341
- ->addAttributeToSelect(array('name'))
342
- ->addFieldToFilter('level', array('lteq' => 5))
343
- ->addUrlRewriteToResult()
344
- ->groupByAttribute('level')
345
- ->setOrder('level', 'ASC')
346
- ;
347
-
348
- $nbCategories = $categoryCollection->count();
349
- //echo "pId = ".$product->getId()." nb = {$nbCategories}<br />";
350
- if ($nbCategories < 1) {
351
- //Get categories from parent if exist
352
- $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
353
- ->getParentIdsByChild($product->getId());
354
-
355
- foreach ($parentIds as $parentId) {
356
- $categoryCollection = Mage::getResourceSingleton('catalog/product')
357
- ->getCategoryCollection(new Varien_Object(array("id" => $parentId)))
358
- ->addAttributeToSelect(array('name'))
359
- ->addFieldToFilter('level', array('lteq' => 5))
360
- ->addUrlRewriteToResult()
361
- ->groupByAttribute('level')
362
- ->setOrder('level', 'ASC');
363
-
364
- if (($nbCategories = $categoryCollection->count()) > 0)
365
- break;
366
- }
367
- }
368
-
369
-
370
- $cnt = 0;
371
-
372
- foreach ($categoryCollection as $category) {
373
- //$category->setStoreId($this->getStoreId()); //When store is setted the rewrite url don't found
374
- $category->getUrlInstance()->setStore($this->getStoreId());
375
- $category->getUrlInstance()->setUseSession(false);
376
-
377
- $name = $category->getName();
378
- $level = $category->getLevel();
379
- $url = $this->cleanUrl($category->getUrl());
380
- if ($cnt == 0) {
381
-
382
- $nodes .= $this->getNode("category", $name);
383
- $nodes .= $this->getNode("category-url", $url);
384
- } else {
385
-
386
- $nodes .= $this->getNode("category-sub-" . ($cnt), $name);
387
- $nodes .= $this->getNode("category-url-sub-" . ($cnt), $url);
388
- }
389
-
390
- $cnt++;
391
- }
392
- if ($nbCategories == 0) {
393
- $nodes .= $this->getNode("category", "");
394
- $nodes .= $this->getNode("category-url", "");
395
-
396
- $cnt++;
397
- }
398
-
399
-
400
- for ($i = ($cnt); $i <= 5; $i++) {
401
- $nodes .= $this->getNode("category-sub-" . $i, "");
402
- $nodes .= $this->getNode("category-url-sub-" . $i, "");
403
- }
404
-
405
- return $nodes;
406
- }
407
-
408
- /**
409
- * Get prices of product
410
- * @param Mage_Catalog_Model_Product $product
411
- * @return string $nodes
412
- */
413
- protected function getPrices($product) {
414
- $nodes = "";
415
-
416
- $finalPrice = $product->getFinalPrice() != 0 ? $product->getFinalPrice() : $product->getData('price');
417
-
418
- $nodes .= $this->getNode("price-ttc", $finalPrice);
419
- $nodes .= $this->getNode("price-before-discount", $product->getPrice());
420
- $nodes .= $this->getNode("discount-amount", $product->getTypeId() != 'bundle' ? $product->getSpecialPrice() : 0);
421
-
422
-
423
-
424
- $nodes .= $this->getNode("discount-percent", $this->getPercent($product));
425
-
426
- if ($product->getSpecialFromDate() != "" && Zend_Date::isDate($product->getSpecialFromDate())) {
427
- $startDate = new Zend_Date($product->getSpecialFromDate());
428
- $nodes .= $this->getNode("start-date-discount", $startDate->toString(Zend_Date::ISO_8601));
429
- }
430
- if ($product->getSpecialToDate() != "" && Zend_Date::isDate($product->getSpecialToDate())) {
431
-
432
- $endDate = new Zend_Date($product->getSpecialToDate());
433
- $nodes .= $this->getNode("end-date-discount", $endDate->toString(Zend_Date::ISO_8601));
434
- }
435
-
436
- return $nodes;
437
- }
438
-
439
- protected function getPercent($product) {
440
-
441
- /* if($product->getTypeId() == 'bundle')
442
- return 0; */
443
- $price = round($product->getPrice(), 2);
444
- if ($price == "0") {
445
- $price = round($product->getMinimalPrice(), 2);
446
- }
447
-
448
- if ($price == "0")
449
- return 0;
450
-
451
- $special = round($product->getFinalPrice(), 2);
452
- $tmp = $price - $special;
453
- $tmp = ($tmp * 100) / $price;
454
- return round($tmp);
455
- }
456
-
457
- /*
458
- * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
459
- */
460
-
461
- public function getProductCollection() {
462
- if (is_null($this->_productCollection)) {
463
- $this->_productCollection = Mage::getResourceModel('catalog/product_collection');
464
- $this->_productCollection->addStoreFilter($this->getStoreId())
465
- ->addAttributeToSelect($this->getAllAttributes())
466
- ->addAttributeToFilter('status', 1)
467
- ->addAttributeToSort('entity_id', 'asc')
468
- ->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left')
469
- //->addAttributeToFilter('visibility',array('nin' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE));
470
- ;
471
-
472
- $this->_productCollection->joinTable(
473
- 'core/url_rewrite', 'product_id=entity_id', array('request_path'), '{{table}}.category_id IS NULL AND {{table}}.is_system = 1 AND {{table}}.store_id = ' . $this->getStoreId() . '', 'left'
474
- );
475
-
476
-
477
-
478
- if ($this->getConfig()->isExportFilteredByAttribute()) {
479
- $this->_productCollection->addAttributeToFilter('shoppingflux_product', array('eq' => 1));
480
- }
481
- $this->_totalCount = $this->_productCollection->getSize();
482
-
483
- $this->_totalOffset = ceil((int) $this->_totalCount / $this->getLimit());
484
- }
485
-
486
- return $this->_productCollection;
487
- }
488
-
489
- public function getCollectionByOffset($offset = 1) {
490
- $this->getProductCollection()->clear()->setPage($offset, $this->getLimit());
491
- //$this->_productCollection->addOptionsToResult();
492
- Mage::getModel('cataloginventory/stock_status')->addStockStatusToProducts($this->getProductCollection(), Mage::app()->getStore($this->getStoreId())->getWebsiteId());
493
- $this->_lastCount = $this->getProductCollection()->count();
494
-
495
- return $this->getProductCollection();
496
- }
497
-
498
- public function generateProductsNodes($offset = 1) {
499
- $start = false;
500
- if ($offset == 1) {
501
-
502
- $this->_xmlFlow = '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
503
- $this->_xmlFlow .= "<products>" . chr(10);
504
- $start = true;
505
- }
506
-
507
- foreach ($this->getCollectionByOffset($offset) as $product) {
508
- try {
509
-
510
- if (!$this->_validate($product)) {
511
- $this->_lastCount--;
512
- continue;
513
- }
514
-
515
- $this->_xmlFlow .= $this->_getProductNode($product);
516
- } catch (Exception $e) {
517
- $this->_errors[] = 'Product ID = ' . $product->getId() . "<br />" . $e->getMessage();
518
- }
519
- }
520
-
521
- if ($offset == $this->_totalOffset) {
522
- $this->closeFlow();
523
- }
524
-
525
- $this->_writeXml($start);
526
-
527
- return $this;
528
- //TODO maybe unset product collection
529
- }
530
-
531
- public function getErrors() {
532
- return $this->_errors;
533
- }
534
-
535
- public function reset() {
536
- unset($this->_productCollection);
537
- $this->_productCollection = null;
538
- $this->_xmlFlow = null;
539
-
540
- return $this;
541
- }
542
-
543
- protected function getNode($name, $value, $withCDATA = 1) {
544
- $value = $this->getHelper()->cleanNotUtf8($value);
545
- $openCDATA = "";
546
- $closeCDATA = "";
547
- if ($withCDATA) {
548
- $openCDATA = "<![CDATA[";
549
- $closeCDATA = "]]>";
550
- }
551
- return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>" . chr(10);
552
- }
553
-
554
- public function closeFlow() {
555
- $this->_xmlFlow .= "</products>";
556
- //$this->_writeXml();
557
- }
558
-
559
- protected function _writeXml($start = false) {
560
- $mode = "a+";
561
- if ($start)
562
- $mode = "w+";
563
- $storeId = $this->getStoreId();
564
- $storeCode = Mage::app()->getStore($storeId)->getCode();
565
- $dir = Mage::getBaseDir('media') . DS . "shoppingflux" . DS . $storeCode . DS;
566
- $file = new Varien_Io_File;
567
- $file->checkAndCreateFolder($dir);
568
- $file->cd($dir);
569
- $file->streamOpen($this->_fileName, $mode);
570
- $file->streamLock();
571
- $file->streamWrite($this->_xmlFlow);
572
- $file->streamUnlock();
573
- $file->streamClose();
574
-
575
- if ($file->fileExists($this->_fileName)) {
576
- return $this->_fileName;
577
- }
578
-
579
- return false;
580
- }
581
-
582
- public function getXml() {
583
- return $this->_xmlFlow;
584
- }
585
-
586
- public function getLastCount() {
587
- return $this->_lastCount;
588
- }
589
-
590
- public function getLimit() {
591
- return $this->getConfig()->getExportProductLimit();
592
- }
593
-
594
- public function setException($error, $level = null, $position = 0) {
595
-
596
- $e = new Mage_Dataflow_Model_Convert_Exception($error);
597
- $e->setLevel(!is_null($level) ? $level : Mage_Dataflow_Model_Convert_Exception::NOTICE);
598
- // $e->setContainer($this);
599
- $e->setPosition($position);
600
-
601
- $this->_exceptions[] = $e;
602
- return $this;
603
- }
604
-
605
- public function getExceptions() {
606
- $exceptions = array();
607
- foreach ($this->_exceptions as $e) {
608
-
609
- switch ($e->getLevel()) {
610
- case Varien_Convert_Exception::FATAL:
611
- $img = 'error_msg_icon.gif';
612
- $liStyle = 'background-color:#FBB; ';
613
- break;
614
- case Varien_Convert_Exception::ERROR:
615
- $img = 'error_msg_icon.gif';
616
- $liStyle = 'background-color:#FDD; ';
617
- break;
618
- case Varien_Convert_Exception::WARNING:
619
- $img = 'fam_bullet_error.gif';
620
- $liStyle = 'background-color:#FFD; ';
621
- break;
622
- case Varien_Convert_Exception::NOTICE:
623
- $img = 'fam_bullet_success.gif';
624
- $liStyle = 'background-color:#DDF; ';
625
- break;
626
- }
627
-
628
- $exceptions[] = array(
629
- "style" => $liStyle,
630
- "src" => Mage::getDesign()->getSkinUrl('images/' . $img),
631
- "message" => $e->getMessage(),
632
- "position" => $e->getPosition()
633
- );
634
- }
635
-
636
- return $exceptions;
637
- }
638
-
639
- /**
640
- * Get singleton config for Export
641
- * @return Profileolabs_Shoppingflux_Model_Export_Config
642
- */
643
- public function getConfig() {
644
- return Mage::getSingleton('profileolabs_shoppingflux/config');
645
- }
646
-
647
- /**
648
- *
649
- */
650
- protected function getAttributesForXml() {
651
- if (is_null($this->_attributes)) {
652
- $this->_attributes = $this->getConfig()->getMappingAllAttributes();
653
- }
654
-
655
- return $this->_attributes;
656
- }
657
-
658
- protected function getAllAttributes() {
659
- $requiredAttributes = array(
660
- "sku" => "sku",
661
- "price" => "price",
662
- "special_price" => "special_price",
663
- "minimal_price" => "minimal_price",
664
- "special_from_date" => "special_from_date",
665
- "special_to_date" => "special_to_date",
666
- "image" => "image");
667
-
668
- return array_merge($this->getAttributesForXml(), $requiredAttributes);
669
- }
670
-
671
- public function generateDirectly() {
672
-
673
- if (!$this->getConfig()->isExportEnabled())
674
- return $this;
675
-
676
- try {
677
- $stores = Mage::getModel('core/store')->getCollection();
678
- $product = Mage::getModel('catalog/product');
679
- foreach ($stores as $store) {
680
- if ($store->getId() == 0)
681
- continue;
682
-
683
- $this->setStoreId($store->getId());
684
-
685
- $flowItemsCount = $this->getProductCollection()->getSize();
686
- $offsets = ceil((int) $flowItemsCount / $this->getLimit());
687
- if ($offsets == 0)
688
- $offsets = 1;
689
-
690
- $this->_xmlFlow = '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
691
- $this->_xmlFlow .= "<products>" . chr(10);
692
-
693
- for ($i = 1; $i <= $offsets; $i++) {
694
-
695
- //Mage::log('offset = '.$i,null,"test_flow.log");
696
- $collection = $this->getCollectionByOffset($i);
697
- foreach ($collection as $product) {
698
- //Mage::log('pId = '.$product,null,"test_flow.log");
699
- try {
700
-
701
- if (!$this->_validate($product)) {
702
- $this->_lastCount--;
703
- continue;
704
- }
705
-
706
- $this->_xmlFlow .= $this->_getProductNode($product);
707
- } catch (Exception $e) {
708
- $this->_errors[] = 'Product ID = ' . $product->getId() . "<br />" . $e->getMessage();
709
- }
710
- }
711
-
712
- /*
713
- using resource iterator to load the data one by one
714
- instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
715
- */
716
- /* Mage::getSingleton('core/resource_iterator')
717
- ->walk($collection->getSelect(), array(array($this, 'addItemXmlCallback')), array('xml'=> $this->_xmlFlow, 'product'=>$product));
718
- */
719
-
720
- unset($collection);
721
- }
722
-
723
- $this->closeFlow();
724
- $this->_writeXml(true);
725
- $this->reset();
726
- }
727
- } catch (Exception $e) {
728
- Mage::logException($e);
729
- Mage::throwException($e);
730
- }
731
- return $this;
732
- }
733
-
734
- public function addItemXmlCallback($args) {
735
- $product = $args['product'];
736
- $product->setData($args['row']);
737
- $xmlFlow = $args['xml'];
738
-
739
- try {
740
-
741
- if (!$this->_validate($product)) {
742
-
743
- //Mage::log("noValid = ".$product,null,'test_callback.log'); $this->_lastCount--;
744
- continue;
745
- }
746
-
747
-
748
- //Mage::log('ID P = ' . $product->getId(), null, 'test_callback.log');
749
- $xmlFlow .= $this->_getProductNode($product);
750
- //Mage::log($xmlFlow, null, 'test_callback.log');
751
- } catch (Exception $e) {
752
- $this->_errors[] = 'Product ID = ' . $product->getId() . "<br />" . $e->getMessage();
753
- }
754
- }
755
-
756
- /**
757
- * Return Shoppingflu Helper
758
- * @return Profileolabs_Shoppingflux_Helper_Data
759
- */
760
- protected function getHelper() {
761
- return Mage::helper('profileolabs_shoppingflux');
762
- }
763
-
764
- public function setStoreId($storeId) {
765
- $this->_storeId = $storeId;
766
- return $this;
767
- }
768
-
769
- public function getStoreId() {
770
- return $this->_storeId;
771
- return $this;
772
- }
773
-
774
- public function getTotalCount() {
775
- if (is_null($this->_totalCount))
776
- $this->getProductCollection();
777
-
778
- return $this->_totalCount;
779
- }
780
-
781
- protected function _validate($product) {
782
- /* if($product->getType() != "bundle" && $product->getPrice() == 0 && $product->getMinimalPrice() == 0)
783
- return false; */
784
-
785
- if (!$this->getConfig()->isExportSoldout() && !$product->isSaleable()) {
786
- //$this->setException("Le produit {$product->getSku()} est hors stock. Il n'a pas été importé.",Varien_Convert_Exception::NOTICE);
787
- $this->_errors[] = Mage::helper('profileolabs_shoppingflux')->__("Product %s is out of stock. Product has not been imported.", $product->getSku());
788
- return false;
789
- }
790
-
791
- return true;
792
- }
793
-
794
- public function cleanUrl($url) {
795
- $url = str_replace("index.php/", "", $url);
796
-
797
- return $url;
798
- }
799
-
800
  }
1
+ <?php
2
+
3
+ /**
4
+ *
5
+ * @deprecated deprecated since 0.1.1
6
+ *
7
+ */
8
+ class Profileolabs_Shoppingflux_Model_Export_Flow {
9
+
10
+ protected $_exceptions = array();
11
+ protected $_lastCount = 0;
12
+ protected $_totalCount = null;
13
+ protected $_totalOffset = null;
14
+ protected $_fileName = "flow.xml";
15
+ protected $_xmlFlow = "";
16
+ protected $_attributes = null;
17
+ protected $_storeId = 0;
18
+ protected $_errors = array();
19
+
20
+
21
+
22
+ /*
23
+ * Products collection
24
+ * @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
25
+ */
26
+ protected $_productCollection = null;
27
+
28
+ /**
29
+ * Get node XML for a product
30
+ * @param Mage_Catalog_Model_Product $product
31
+ * @return string $nodeXml
32
+ */
33
+ protected function _getProductNode($product) {
34
+
35
+ $_helper = Mage::helper('catalog/output');
36
+
37
+ $product->setStoreId($this->getStoreId());
38
+
39
+
40
+
41
+ $nodeXml = "<product>" . chr(10);
42
+
43
+ $nodeXml .= $this->getNode("id-product", $product->getId());
44
+
45
+ //$nodeXml .= $this->getNode("sku",$product->getSku());
46
+
47
+ foreach ($this->getAttributesForXml() as $nameNode => $valueNode) {
48
+
49
+ $data = $product->getData($valueNode);
50
+
51
+
52
+
53
+ $attribute = $product->getResource()->getAttribute($valueNode);
54
+ if ($attribute) {
55
+
56
+ $data = $product->getResource()->getAttribute($valueNode)->getFrontend()->getValue($product);
57
+ $data = $_helper->productAttribute($product, $data, $valueNode);
58
+ }
59
+
60
+
61
+
62
+ //Synthetize it
63
+ $method = "get" . ucfirst($valueNode);
64
+ if (method_exists($product, $method))
65
+ $data = $product->$method();
66
+
67
+ //TODO remove this
68
+ if ($data == "No" || $data == "Non")
69
+ $data = "";
70
+
71
+ //Exceptions data
72
+ if ($nameNode == 'shipping_delay' && empty($data))
73
+ $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
74
+
75
+ if ($nameNode == 'quantity')
76
+ $data = round($data);
77
+
78
+
79
+ $nodeXml .= $this->getNode($nameNode, $data);
80
+ }
81
+
82
+ //Add stock status
83
+ $nodeXml .= $this->getNode("is-in-stock", (int) $product->isSaleable());
84
+
85
+ //Add product url
86
+ $nodeXml .= $this->getNode("product-url", $this->cleanUrl($product->getProductUrl(false)));
87
+
88
+ //Add image's nodes
89
+ $nodeXml .= $this->getImages($product);
90
+
91
+ //Add categories
92
+ $nodeXml .= $this->getCategories($product);
93
+
94
+ //ADD Prices
95
+ $nodeXml .= $this->getPrices($product);
96
+
97
+ //ADD PARENT ID
98
+ $nodeXml .= $this->getParentId($product);
99
+
100
+ //ADD Shipping Name
101
+ $nodeXml .= $this->getShippingName();
102
+
103
+ //Add ShippingPrice
104
+ $nodeXml .= $this->getShippingPrice($product);
105
+
106
+ //Add Options
107
+ $nodeXml .= $this->getOptions($product);
108
+
109
+ $nodeXml .= $this->getNode("sku", $product->getSku());
110
+
111
+ $nodeXml .= "</product>" . chr(10);
112
+
113
+
114
+ return $nodeXml;
115
+ }
116
+
117
+ protected function getOptions($product) {
118
+ $nodes = "<options>" . chr(10);
119
+ $labels = array();
120
+ if ($product->getTypeId() == "configurable") {
121
+ $attributes = $product->getTypeInstance()->getConfigurableAttributes();
122
+ foreach ($attributes as $attribute) {
123
+ $options = $attribute->getProductAttribute()->getSource()->getAllOptions(false);
124
+ if (count($options)) {
125
+ $labels = array();
126
+ foreach ($options as $option)
127
+ $labels[] = $option['label'];
128
+
129
+ $nodes .= $this->getNode($attribute->getProductAttribute()->getAttributeCode(), implode(',', $labels));
130
+ }
131
+ }
132
+ }
133
+ /* elseif(count($product->getOptions()))
134
+ {
135
+ $options = $product->getOptions();
136
+ foreach($options as $option)
137
+ {
138
+ foreach($option->getValues() as $value)
139
+ {
140
+ $labels[] = $value->getTitle();
141
+ }
142
+
143
+ $nodes .= $this->getNode($option->getTitle(),implode(',',$labels));
144
+
145
+ }
146
+ } */
147
+
148
+
149
+ $nodes .= "</options>" . chr(10);
150
+ return $nodes;
151
+ }
152
+
153
+ protected function getShippingPrice($product) {
154
+ $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
155
+ $shippingPrice = 0;
156
+ if (!empty($carrier)) {
157
+
158
+ $countryCode = $this->getConfig()->getConfigData('shoppingflux_export/general/shipping_price_based_on');
159
+ $shippingPrice = $this->getHelper()->getShippingPrice($product, $carrier, $countryCode);
160
+ }
161
+
162
+ if (!$shippingPrice) {
163
+ $shippingPrice = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
164
+ }
165
+
166
+ $node = "";
167
+ $node = $this->getNode("shipping-price", $shippingPrice);
168
+
169
+ return $node;
170
+ }
171
+
172
+ protected function getShippingName() {
173
+ $node = "";
174
+ $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
175
+ if (empty($carrier))
176
+ return $node;
177
+ $carrierTab = explode('_', $carrier);
178
+ list($carrierCode, $methodCode) = $carrierTab;
179
+
180
+ $node = $this->getNode("shipping-name", ucfirst($methodCode));
181
+
182
+ return $node;
183
+ }
184
+
185
+ protected function getParentId($product, $raw = false) {
186
+ $node = "";
187
+ $ids = array();
188
+ $ids = Mage::getResourceSingleton('catalog/product_type_configurable')
189
+ ->getParentIdsByChild($product->getId());
190
+
191
+ if (!count($ids))
192
+ $ids = Mage::getResourceSingleton('bundle/selection')
193
+ ->getParentIdsByChild($product->getId());
194
+
195
+ $idParent = count($ids) ? current($ids) : "";
196
+
197
+ if ($raw)
198
+ return $idParent;
199
+
200
+ $node = $this->getNode("parent-id", $idParent);
201
+
202
+ return $node;
203
+ }
204
+
205
+ private function _getMediaGallery($product) {
206
+ $media = $product->getData('media_gallery');
207
+ if (is_null($media)) {
208
+ if ($attribute = $product->getResource()->getAttribute('media_gallery')) {
209
+ $attribute->getBackend()->afterLoad($product);
210
+ $media = $product->getData('media_gallery');
211
+ }
212
+ }
213
+ return $media;
214
+ }
215
+
216
+ private function _imageIsValid($url) {
217
+ return (trim($url) != '' && !preg_match('%(no_selection|no_image\.jpg)$%i', $url));
218
+ }
219
+
220
+ /**
221
+ * Get images of product
222
+ * @param Mage_Catalog_Model_Product $product
223
+ * @return string $nodes
224
+ */
225
+ protected function getImages($product) {
226
+ $nodes = "";
227
+
228
+ $mediaUrl = Mage::getBaseUrl('media') . 'catalog/product';
229
+
230
+ $images = array();
231
+
232
+ $baseImage = Mage::helper('catalog/product')->getImageUrl($product);
233
+ if ($this->_imageIsValid($baseImage)) {
234
+ $images[] = $baseImage;
235
+ }
236
+ $smallimage = Mage::helper('catalog/product')->getSmallImageUrl($product);
237
+ if ($this->_imageIsValid($smallimage)) {
238
+ $images[] = $smallimage;
239
+ }
240
+
241
+ $additionalImages = $this->_getMediaGallery($product);
242
+ if ($additionalImages)
243
+ $additionalImages = $additionalImages['images'];
244
+ foreach ($additionalImages as $additionalImage) {
245
+ $image = Mage::getSingleton('catalog/product_media_config')->getMediaUrl($additionalImage['file']);
246
+ if ($this->_imageIsValid($image)) {
247
+ $images[] = $image;
248
+ }
249
+ }
250
+
251
+ $images = array_unique($images);
252
+ $images = array_values($images);
253
+
254
+ if (empty($images)) {
255
+ $parentId = $this->getParentId($product, true);
256
+ if (!empty($parentId)) {
257
+ $parent = Mage::getModel('catalog/product')->load($parentId);
258
+ return $this->getImages($parent);
259
+ }
260
+ }
261
+
262
+ foreach ($images as $i => $image) {
263
+ $nodes .= $this->getNode("image-url-" . ($i + 1), $image);
264
+ }
265
+
266
+
267
+ //Complet with empty nodes
268
+ for ($j = $i+1; $j < 6; $j++) {
269
+ $nodes .= $this->getNode("image-url-" . $j, '');
270
+ }
271
+
272
+ return $nodes;
273
+
274
+
275
+
276
+
277
+
278
+
279
+ /*
280
+ $i = 1;
281
+ $imagesFound = false;
282
+ if ($product->getImage() != "" && $product->getImage() != 'no_selection') {
283
+ $nodes .= $this->getNode("image-url-" . $i++, $mediaUrl . $product->getImage());
284
+ $imagesFound = true;
285
+ }
286
+
287
+ //LOAD media gallery for this product
288
+ $mediaGallery = $product->getResource()->getAttribute('media_gallery');
289
+ $mediaGallery->getBackend()->afterLoad($product);
290
+
291
+ if ($product->getMediaGalleryImages() instanceof Varien_Data_Collection) {
292
+ foreach ($product->getMediaGalleryImages() as $image) {
293
+ $imagesFound = true;
294
+ $nodes .= $this->getNode("image-url-" . $i++, $image->getUrl());
295
+ if ($i == 6)
296
+ break;
297
+ }
298
+ }
299
+
300
+
301
+
302
+
303
+ if (!$imagesFound) {//Images not found, we try to get them from parent if exists
304
+ $parentId = $this->getParentId($product, true);
305
+ if (!empty($parentId)) {
306
+ $parent = Mage::getModel('catalog/product')->load($parentId);
307
+ if ($parent->getId()) {
308
+ if ($parent->getImage() != "" && $parent->getImage() != 'no_selection') {
309
+ $nodes .= $this->getNode("image-url-" . $i++, $mediaUrl . $parent->getImage());
310
+ }
311
+
312
+ $mediaGallery = $parent->getResource()->getAttribute('media_gallery');
313
+ $mediaGallery->getBackend()->afterLoad($parent);
314
+ if ($parent->getMediaGalleryImages() instanceof Varien_Data_Collection)
315
+ foreach ($parent->getMediaGalleryImages() as $image) {
316
+ $nodes .= $this->getNode("image-url-" . $i++, $image->getUrl());
317
+ if ($i == 6)
318
+ break;
319
+ }
320
+ }
321
+ }
322
+ }
323
+
324
+ //Complet with empty nodes
325
+ for ($j = $i; $j < 6; $j++) {
326
+ $nodes .= $this->getNode("image-url-" . $i++, '');
327
+ }
328
+
329
+
330
+ return $nodes;*/
331
+ }
332
+
333
+ /**
334
+ * Get categories of product
335
+ * @param Mage_Catalog_Model_Product $product
336
+ * @return string $nodes
337
+ */
338
+ protected function getCategories($product) {
339
+ $nodes = "";
340
+ $categoryCollection = $product->getCategoryCollection()
341
+ ->addAttributeToSelect(array('name'))
342
+ ->addFieldToFilter('level', array('lteq' => 5))
343
+ ->addUrlRewriteToResult()
344
+ ->groupByAttribute('level')
345
+ ->setOrder('level', 'ASC')
346
+ ;
347
+
348
+ $nbCategories = $categoryCollection->count();
349
+ //echo "pId = ".$product->getId()." nb = {$nbCategories}<br />";
350
+ if ($nbCategories < 1) {
351
+ //Get categories from parent if exist
352
+ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')
353
+ ->getParentIdsByChild($product->getId());
354
+
355
+ foreach ($parentIds as $parentId) {
356
+ $categoryCollection = Mage::getResourceSingleton('catalog/product')
357
+ ->getCategoryCollection(new Varien_Object(array("id" => $parentId)))
358
+ ->addAttributeToSelect(array('name'))
359
+ ->addFieldToFilter('level', array('lteq' => 5))
360
+ ->addUrlRewriteToResult()
361
+ ->groupByAttribute('level')
362
+ ->setOrder('level', 'ASC');
363
+
364
+ if (($nbCategories = $categoryCollection->count()) > 0)
365
+ break;
366
+ }
367
+ }
368
+
369
+
370
+ $cnt = 0;
371
+
372
+ foreach ($categoryCollection as $category) {
373
+ //$category->setStoreId($this->getStoreId()); //When store is setted the rewrite url don't found
374
+ $category->getUrlInstance()->setStore($this->getStoreId());
375
+ $category->getUrlInstance()->setUseSession(false);
376
+
377
+ $name = $category->getName();
378
+ $level = $category->getLevel();
379
+ $url = $this->cleanUrl($category->getUrl());
380
+ if ($cnt == 0) {
381
+
382
+ $nodes .= $this->getNode("category", $name);
383
+ $nodes .= $this->getNode("category-url", $url);
384
+ } else {
385
+
386
+ $nodes .= $this->getNode("category-sub-" . ($cnt), $name);
387
+ $nodes .= $this->getNode("category-url-sub-" . ($cnt), $url);
388
+ }
389
+
390
+ $cnt++;
391
+ }
392
+ if ($nbCategories == 0) {
393
+ $nodes .= $this->getNode("category", "");
394
+ $nodes .= $this->getNode("category-url", "");
395
+
396
+ $cnt++;
397
+ }
398
+
399
+
400
+ for ($i = ($cnt); $i <= 5; $i++) {
401
+ $nodes .= $this->getNode("category-sub-" . $i, "");
402
+ $nodes .= $this->getNode("category-url-sub-" . $i, "");
403
+ }
404
+
405
+ return $nodes;
406
+ }
407
+
408
+ /**
409
+ * Get prices of product
410
+ * @param Mage_Catalog_Model_Product $product
411
+ * @return string $nodes
412
+ */
413
+ protected function getPrices($product) {
414
+ $nodes = "";
415
+
416
+ $finalPrice = $product->getFinalPrice() != 0 ? $product->getFinalPrice() : $product->getData('price');
417
+
418
+ $nodes .= $this->getNode("price-ttc", $finalPrice);
419
+ $nodes .= $this->getNode("price-before-discount", $product->getPrice());
420
+ $nodes .= $this->getNode("discount-amount", $product->getTypeId() != 'bundle' ? $product->getSpecialPrice() : 0);
421
+
422
+
423
+
424
+ $nodes .= $this->getNode("discount-percent", $this->getPercent($product));
425
+
426
+ if ($product->getSpecialFromDate() != "" && Zend_Date::isDate($product->getSpecialFromDate())) {
427
+ $startDate = new Zend_Date($product->getSpecialFromDate());
428
+ $nodes .= $this->getNode("start-date-discount", $startDate->toString(Zend_Date::ISO_8601));
429
+ }
430
+ if ($product->getSpecialToDate() != "" && Zend_Date::isDate($product->getSpecialToDate())) {
431
+
432
+ $endDate = new Zend_Date($product->getSpecialToDate());
433
+ $nodes .= $this->getNode("end-date-discount", $endDate->toString(Zend_Date::ISO_8601));
434
+ }
435
+
436
+ return $nodes;
437
+ }
438
+
439
+ protected function getPercent($product) {
440
+
441
+ /* if($product->getTypeId() == 'bundle')
442
+ return 0; */
443
+ $price = round($product->getPrice(), 2);
444
+ if ($price == "0") {
445
+ $price = round($product->getMinimalPrice(), 2);
446
+ }
447
+
448
+ if ($price == "0")
449
+ return 0;
450
+
451
+ $special = round($product->getFinalPrice(), 2);
452
+ $tmp = $price - $special;
453
+ $tmp = ($tmp * 100) / $price;
454
+ return round($tmp);
455
+ }
456
+
457
+ /*
458
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
459
+ */
460
+
461
+ public function getProductCollection() {
462
+ if (is_null($this->_productCollection)) {
463
+ $this->_productCollection = Mage::getResourceModel('catalog/product_collection');
464
+ $this->_productCollection->addStoreFilter($this->getStoreId())
465
+ ->addAttributeToSelect($this->getAllAttributes())
466
+ ->addAttributeToFilter('status', 1)
467
+ ->addAttributeToSort('entity_id', 'asc')
468
+ ->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left')
469
+ //->addAttributeToFilter('visibility',array('nin' => Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE));
470
+ ;
471
+
472
+ $this->_productCollection->joinTable(
473
+ 'core/url_rewrite', 'product_id=entity_id', array('request_path'), '{{table}}.category_id IS NULL AND {{table}}.is_system = 1 AND {{table}}.store_id = ' . $this->getStoreId() . '', 'left'
474
+ );
475
+
476
+
477
+
478
+ if ($this->getConfig()->isExportFilteredByAttribute()) {
479
+ $this->_productCollection->addAttributeToFilter('shoppingflux_product', array('eq' => 1));
480
+ }
481
+ $this->_totalCount = $this->_productCollection->getSize();
482
+
483
+ $this->_totalOffset = ceil((int) $this->_totalCount / $this->getLimit());
484
+ }
485
+
486
+ return $this->_productCollection;
487
+ }
488
+
489
+ public function getCollectionByOffset($offset = 1) {
490
+ $this->getProductCollection()->clear()->setPage($offset, $this->getLimit());
491
+ //$this->_productCollection->addOptionsToResult();
492
+ Mage::getModel('cataloginventory/stock_status')->addStockStatusToProducts($this->getProductCollection(), Mage::app()->getStore($this->getStoreId())->getWebsiteId());
493
+ $this->_lastCount = $this->getProductCollection()->count();
494
+
495
+ return $this->getProductCollection();
496
+ }
497
+
498
+ public function generateProductsNodes($offset = 1) {
499
+ $start = false;
500
+ if ($offset == 1) {
501
+
502
+ $this->_xmlFlow = '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
503
+ $this->_xmlFlow .= "<products>" . chr(10);
504
+ $start = true;
505
+ }
506
+
507
+ foreach ($this->getCollectionByOffset($offset) as $product) {
508
+ try {
509
+
510
+ if (!$this->_validate($product)) {
511
+ $this->_lastCount--;
512
+ continue;
513
+ }
514
+
515
+ $this->_xmlFlow .= $this->_getProductNode($product);
516
+ } catch (Exception $e) {
517
+ $this->_errors[] = 'Product ID = ' . $product->getId() . "<br />" . $e->getMessage();
518
+ }
519
+ }
520
+
521
+ if ($offset == $this->_totalOffset) {
522
+ $this->closeFlow();
523
+ }
524
+
525
+ $this->_writeXml($start);
526
+
527
+ return $this;
528
+ //TODO maybe unset product collection
529
+ }
530
+
531
+ public function getErrors() {
532
+ return $this->_errors;
533
+ }
534
+
535
+ public function reset() {
536
+ unset($this->_productCollection);
537
+ $this->_productCollection = null;
538
+ $this->_xmlFlow = null;
539
+
540
+ return $this;
541
+ }
542
+
543
+ protected function getNode($name, $value, $withCDATA = 1) {
544
+ $value = $this->getHelper()->cleanNotUtf8($value);
545
+ $openCDATA = "";
546
+ $closeCDATA = "";
547
+ if ($withCDATA) {
548
+ $openCDATA = "<![CDATA[";
549
+ $closeCDATA = "]]>";
550
+ }
551
+ return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>" . chr(10);
552
+ }
553
+
554
+ public function closeFlow() {
555
+ $this->_xmlFlow .= "</products>";
556
+ //$this->_writeXml();
557
+ }
558
+
559
+ protected function _writeXml($start = false) {
560
+ $mode = "a+";
561
+ if ($start)
562
+ $mode = "w+";
563
+ $storeId = $this->getStoreId();
564
+ $storeCode = Mage::app()->getStore($storeId)->getCode();
565
+ $dir = Mage::getBaseDir('media') . DS . "shoppingflux" . DS . $storeCode . DS;
566
+ $file = new Varien_Io_File;
567
+ $file->checkAndCreateFolder($dir);
568
+ $file->cd($dir);
569
+ $file->streamOpen($this->_fileName, $mode);
570
+ $file->streamLock();
571
+ $file->streamWrite($this->_xmlFlow);
572
+ $file->streamUnlock();
573
+ $file->streamClose();
574
+
575
+ if ($file->fileExists($this->_fileName)) {
576
+ return $this->_fileName;
577
+ }
578
+
579
+ return false;
580
+ }
581
+
582
+ public function getXml() {
583
+ return $this->_xmlFlow;
584
+ }
585
+
586
+ public function getLastCount() {
587
+ return $this->_lastCount;
588
+ }
589
+
590
+ public function getLimit() {
591
+ return $this->getConfig()->getExportProductLimit();
592
+ }
593
+
594
+ public function setException($error, $level = null, $position = 0) {
595
+
596
+ $e = new Mage_Dataflow_Model_Convert_Exception($error);
597
+ $e->setLevel(!is_null($level) ? $level : Mage_Dataflow_Model_Convert_Exception::NOTICE);
598
+ // $e->setContainer($this);
599
+ $e->setPosition($position);
600
+
601
+ $this->_exceptions[] = $e;
602
+ return $this;
603
+ }
604
+
605
+ public function getExceptions() {
606
+ $exceptions = array();
607
+ foreach ($this->_exceptions as $e) {
608
+
609
+ switch ($e->getLevel()) {
610
+ case Varien_Convert_Exception::FATAL:
611
+ $img = 'error_msg_icon.gif';
612
+ $liStyle = 'background-color:#FBB; ';
613
+ break;
614
+ case Varien_Convert_Exception::ERROR:
615
+ $img = 'error_msg_icon.gif';
616
+ $liStyle = 'background-color:#FDD; ';
617
+ break;
618
+ case Varien_Convert_Exception::WARNING:
619
+ $img = 'fam_bullet_error.gif';
620
+ $liStyle = 'background-color:#FFD; ';
621
+ break;
622
+ case Varien_Convert_Exception::NOTICE:
623
+ $img = 'fam_bullet_success.gif';
624
+ $liStyle = 'background-color:#DDF; ';
625
+ break;
626
+ }
627
+
628
+ $exceptions[] = array(
629
+ "style" => $liStyle,
630
+ "src" => Mage::getDesign()->getSkinUrl('images/' . $img),
631
+ "message" => $e->getMessage(),
632
+ "position" => $e->getPosition()
633
+ );
634
+ }
635
+
636
+ return $exceptions;
637
+ }
638
+
639
+ /**
640
+ * Get singleton config for Export
641
+ * @return Profileolabs_Shoppingflux_Model_Export_Config
642
+ */
643
+ public function getConfig() {
644
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
645
+ }
646
+
647
+ /**
648
+ *
649
+ */
650
+ protected function getAttributesForXml() {
651
+ if (is_null($this->_attributes)) {
652
+ $this->_attributes = $this->getConfig()->getMappingAllAttributes();
653
+ }
654
+
655
+ return $this->_attributes;
656
+ }
657
+
658
+ protected function getAllAttributes() {
659
+ $requiredAttributes = array(
660
+ "sku" => "sku",
661
+ "price" => "price",
662
+ "special_price" => "special_price",
663
+ "minimal_price" => "minimal_price",
664
+ "special_from_date" => "special_from_date",
665
+ "special_to_date" => "special_to_date",
666
+ "image" => "image");
667
+
668
+ return array_merge($this->getAttributesForXml(), $requiredAttributes);
669
+ }
670
+
671
+ public function generateDirectly() {
672
+
673
+ if (!$this->getConfig()->isExportEnabled())
674
+ return $this;
675
+
676
+ try {
677
+ $stores = Mage::getModel('core/store')->getCollection();
678
+ $product = Mage::getModel('catalog/product');
679
+ foreach ($stores as $store) {
680
+ if ($store->getId() == 0)
681
+ continue;
682
+
683
+ $this->setStoreId($store->getId());
684
+
685
+ $flowItemsCount = $this->getProductCollection()->getSize();
686
+ $offsets = ceil((int) $flowItemsCount / $this->getLimit());
687
+ if ($offsets == 0)
688
+ $offsets = 1;
689
+
690
+ $this->_xmlFlow = '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
691
+ $this->_xmlFlow .= "<products>" . chr(10);
692
+
693
+ for ($i = 1; $i <= $offsets; $i++) {
694
+
695
+ //Mage::log('offset = '.$i,null,"test_flow.log");
696
+ $collection = $this->getCollectionByOffset($i);
697
+ foreach ($collection as $product) {
698
+ //Mage::log('pId = '.$product,null,"test_flow.log");
699
+ try {
700
+
701
+ if (!$this->_validate($product)) {
702
+ $this->_lastCount--;
703
+ continue;
704
+ }
705
+
706
+ $this->_xmlFlow .= $this->_getProductNode($product);
707
+ } catch (Exception $e) {
708
+ $this->_errors[] = 'Product ID = ' . $product->getId() . "<br />" . $e->getMessage();
709
+ }
710
+ }
711
+
712
+ /*
713
+ using resource iterator to load the data one by one
714
+ instead of loading all at the same time. loading all data at the same time can cause the big memory allocation.
715
+ */
716
+ /* Mage::getSingleton('core/resource_iterator')
717
+ ->walk($collection->getSelect(), array(array($this, 'addItemXmlCallback')), array('xml'=> $this->_xmlFlow, 'product'=>$product));
718
+ */
719
+
720
+ unset($collection);
721
+ }
722
+
723
+ $this->closeFlow();
724
+ $this->_writeXml(true);
725
+ $this->reset();
726
+ }
727
+ } catch (Exception $e) {
728
+ Mage::logException($e);
729
+ Mage::throwException($e);
730
+ }
731
+ return $this;
732
+ }
733
+
734
+ public function addItemXmlCallback($args) {
735
+ $product = $args['product'];
736
+ $product->setData($args['row']);
737
+ $xmlFlow = $args['xml'];
738
+
739
+ try {
740
+
741
+ if (!$this->_validate($product)) {
742
+
743
+ //Mage::log("noValid = ".$product,null,'test_callback.log'); $this->_lastCount--;
744
+ continue;
745
+ }
746
+
747
+
748
+ //Mage::log('ID P = ' . $product->getId(), null, 'test_callback.log');
749
+ $xmlFlow .= $this->_getProductNode($product);
750
+ //Mage::log($xmlFlow, null, 'test_callback.log');
751
+ } catch (Exception $e) {
752
+ $this->_errors[] = 'Product ID = ' . $product->getId() . "<br />" . $e->getMessage();
753
+ }
754
+ }
755
+
756
+ /**
757
+ * Return Shoppingflu Helper
758
+ * @return Profileolabs_Shoppingflux_Helper_Data
759
+ */
760
+ protected function getHelper() {
761
+ return Mage::helper('profileolabs_shoppingflux');
762
+ }
763
+
764
+ public function setStoreId($storeId) {
765
+ $this->_storeId = $storeId;
766
+ return $this;
767
+ }
768
+
769
+ public function getStoreId() {
770
+ return $this->_storeId;
771
+ return $this;
772
+ }
773
+
774
+ public function getTotalCount() {
775
+ if (is_null($this->_totalCount))
776
+ $this->getProductCollection();
777
+
778
+ return $this->_totalCount;
779
+ }
780
+
781
+ protected function _validate($product) {
782
+ /* if($product->getType() != "bundle" && $product->getPrice() == 0 && $product->getMinimalPrice() == 0)
783
+ return false; */
784
+
785
+ if (!$this->getConfig()->isExportSoldout() && !$product->isSaleable()) {
786
+ //$this->setException("Le produit {$product->getSku()} est hors stock. Il n'a pas été importé.",Varien_Convert_Exception::NOTICE);
787
+ $this->_errors[] = Mage::helper('profileolabs_shoppingflux')->__("Product %s is out of stock. Product has not been imported.", $product->getSku());
788
+ return false;
789
+ }
790
+
791
+ return true;
792
+ }
793
+
794
+ public function cleanUrl($url) {
795
+ $url = str_replace("index.php/", "", $url);
796
+
797
+ return $url;
798
+ }
799
+
800
  }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Flux.php CHANGED
@@ -1,1152 +1,1181 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Export_Flux extends Mage_Core_Model_Abstract {
10
-
11
- protected $_attributesFromConfig = array();
12
- protected $_attributesConfigurable = array();
13
- protected $_storeCategories = array();
14
-
15
- protected function _construct() {
16
- $this->_init('profileolabs_shoppingflux/export_flux');
17
- }
18
-
19
- public function getEntry($productSku, $storeId) {
20
- $collection = $this->getCollection();
21
- $collection->addFieldToFilter('sku', $productSku);
22
- $collection->addFieldToFilter('store_id', $storeId);
23
- if ($collection->count() > 0) {
24
- return $collection->getFirstItem();
25
- }
26
- $model = Mage::getModel('profileolabs_shoppingflux/export_flux')
27
- ->setStoreId($storeId)
28
- ->setSku($productSku)
29
- ->setProductId(Mage::getModel('catalog/product')->getIdBySku($productSku))
30
- ->setUpdateNeeded(0);
31
- return $model;
32
- }
33
-
34
- protected function _getProductBySku($productSku, $storeId) {
35
- $pId = Mage::getModel('catalog/product')->getIdBySku($productSku);
36
- if (!$pId) {
37
- return false;
38
- }
39
- return $this->_getProduct($pId, $storeId);
40
- }
41
-
42
- protected function _getProduct($product, $storeId) {
43
- if (is_numeric($product)) {
44
- $productId = $product;
45
- } else if (is_object($product)) {
46
- $productId = $product->getId();
47
- } else {
48
- return false;
49
- }
50
-
51
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
52
- $select = $read->select()
53
- ->distinct()
54
- ->from(Mage::getConfig()->getTablePrefix() . 'catalog_product_website', array('website_id'))
55
- ->where('product_id = ?', $productId);
56
- $result = $read->fetchAll($select);
57
- $websiteIds = array();
58
- foreach ($result as $row) {
59
- $websiteIds[] = $row['website_id'];
60
- }
61
-
62
- if (!in_array(Mage::app()->getStore($storeId)->getWebsiteId(), $websiteIds)) {
63
- return false;
64
- }
65
-
66
- $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
67
- if (!$product->getId()) {
68
- return false;
69
- }
70
-
71
- return $product;
72
- }
73
-
74
- public function getConfig() {
75
- return Mage::getSingleton('profileolabs_shoppingflux/config');
76
- }
77
-
78
- public function addMissingProduct($args) {
79
- $storeId = $args['store_id'];
80
- $this->updateProductInFlux($args['row']['sku'], $storeId);
81
- }
82
-
83
- public function checkForDeletedProducts() {
84
- $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
85
- $collection->getSelect()->joinLeft(
86
- array('p' => $collection->getTable('catalog/product')),
87
- 'p.entity_id = main_table.product_id',
88
- array()
89
- );
90
- $existingStoreIds = array();
91
- foreach(Mage::app()->getStores() as $store) {
92
- $existingStoreIds[] = $store->getId();
93
- }
94
- $collection->getSelect()->where("p.entity_id IS NULL or main_table.store_id NOT IN (".implode(',',$existingStoreIds).")");
95
- //$collection->walk('delete');
96
- Mage::getSingleton('core/resource_iterator')
97
- ->walk($collection->getSelect(), array(array($this, 'removeDeletedProduct')));
98
- }
99
-
100
- public function removeDeletedProduct($args) {
101
- $fluxItem = Mage::getModel('profileolabs_shoppingflux/export_flux')->load($args['row']['id']);
102
- $fluxItem->delete();
103
- }
104
-
105
-
106
- public function checkForMissingProducts($store_id = false, $maxImport = 1000) {
107
- ini_set('display_errors', 1);
108
- error_reporting(-1);
109
- foreach (Mage::app()->getStores() as $store) {
110
- $storeId = $store->getId();
111
- if (!$this->getConfig()->isExportEnabled($storeId)) {
112
- continue;
113
- }
114
- if (!$store_id || $storeId == $store_id) {
115
- $productCollection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($storeId)->setStoreId($storeId);
116
- $productCollection->addAttributeToSelect('sku', 'left');
117
- $currentVersion = Mage::getVersion();
118
- $tableName = Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux');
119
- $productCollection->getSelect()->joinLeft(
120
- array('sf'=>$tableName),
121
- "entity_id=sf.product_id and store_id = '" . $storeId . "'",
122
- array('skusf' => 'sku')
123
- );
124
- //not compatible with mage 1.3
125
- //$productCollection->joinTable(array('sf'=>'profileolabs_shoppingflux/export_flux'), "sku=sku", array('skusf'=>'sku'), "{{table}}.store_id = '".$storeId."'", 'left');
126
- $productCollection->setPage(1, $maxImport);
127
- $productCollection->getSelect()->where('sf.product_id IS NULL');
128
- //$productCollection->load();
129
- //echo $productCollection->getSelect();
130
- Mage::getSingleton('core/resource_iterator')
131
- ->walk($productCollection->getSelect(), array(array($this, 'addMissingProduct')), array('store_id' => $storeId));
132
- }
133
- }
134
-
135
- }
136
-
137
- public function updateFlux($store_id = false, $maxImportLimit = 1000, $shouldExportOnly = false) {
138
- //if(rand(0,100) == 50) {
139
- //no need to execute this every time. todo : move to cron task
140
- // $this->checkForDeletedProducts();
141
- //}
142
- foreach (Mage::app()->getStores() as $store) {
143
- $storeId = $store->getId();
144
- $isCurrentStore = (Mage::app()->getStore()->getId() == $storeId);
145
- if (!$store_id || $store_id == $storeId) {
146
- if (!$isCurrentStore) {
147
- $appEmulation = Mage::getSingleton('core/app_emulation');
148
- if ($appEmulation) { // not available in 1.4
149
- $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
150
- }
151
- }
152
- try {
153
- $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
154
- $collection->addFieldToFilter('update_needed', 1);
155
- $collection->addFieldToFilter('store_id', $storeId);
156
- $collection->getSelect()->order('rand()');//if concurrent calls, this will avoid updating the same products..
157
- if ($shouldExportOnly) {
158
- $collection->addFieldToFilter('should_export', 1);
159
- }
160
- foreach ($collection as $item) {
161
- $this->updateProductInFlux($item->getSku(), $storeId);
162
- }
163
- $this->checkForMissingProducts($storeId, $maxImportLimit);
164
- if (!$isCurrentStore && $appEmulation) {
165
- $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
166
- }
167
- } catch (Exception $e) {
168
- if (!$isCurrentStore && $appEmulation) {
169
- $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
170
- }
171
- }
172
- }
173
- }
174
- }
175
-
176
- public function productNeedUpdateForStore($productId, $storeId, $ignoreRelations = false) {
177
- $product = $this->_getProduct($productId, $storeId);
178
- if ($product && $product->getId()) {
179
- $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($product->getSku(), $storeId);
180
- if ($fluxEntry->getUpdateNeeded() != 1) {
181
- $fluxEntry->setUpdateNeeded(1);
182
- $fluxEntry->save();
183
- }
184
- if(!$ignoreRelations) {
185
- // update also parents
186
- $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
187
- foreach ($parentIds as $parentId) {
188
- $this->productNeedUpdateForStore($parentId, $storeId, true);
189
- }
190
- // ... and child
191
- if($product->getTypeId() == 'configurable') {
192
- $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
193
- foreach($childProducts as $childProduct) {
194
- if($childProduct->getTypeId() == 'simple') {
195
- $this->productNeedUpdateForStore($childProduct->getId(), $storeId, true);
196
- }
197
- }
198
- }
199
- }
200
- }
201
- }
202
-
203
- public function productNeedUpdate($productId) {
204
- foreach (Mage::app()->getStores() as $store) {
205
- $storeId = $store->getId();
206
- $this->productNeedUpdateForStore($productId, $storeId);
207
- }
208
- return;
209
- }
210
-
211
- protected function _shouldUpdate($product, $storeId) {
212
- if (!$this->getConfig()->isExportEnabled($storeId)) {
213
- return false;
214
- }
215
-
216
- if ($product->getStatus() == 2)
217
- return false;
218
-
219
- if ($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle' || $product->getTypeId() == 'virtual') {
220
- return false;
221
- }
222
-
223
- if (!$this->getConfig()->isExportNotSalable() && !$product->isSalable()) {
224
- return false;
225
- }
226
-
227
- if ($product->getTypeId() == 'simple') {
228
- $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
229
-
230
- //FIX Added on 2014-08-14 to solve a case : unexistant parent found, so product is never exported...
231
- foreach ($parentIds as $k => $parentId) {
232
- if (!Mage::getModel('catalog/product')->getCollection()->addStoreFilter($storeId)->addFieldToFilter('entity_id', $parentId)->count()) {
233
- unset($parentIds[$k]);
234
- }
235
- }
236
- //END FIX
237
-
238
- if (!empty($parentIds))
239
- return false;
240
- }
241
-
242
-
243
-
244
- $store = Mage::app()->getStore($storeId);
245
- if (!in_array($store->getWebsiteId(), $product->getWebsiteIds())) {
246
- return false;
247
- }
248
-
249
- return true;
250
- }
251
-
252
- protected $_attributes = array();
253
-
254
- protected function _getAttribute($attributeCode, $storeId = null) {
255
- if (!isset($this->_attributes[$attributeCode])) {
256
- $this->_attributes[$attributeCode] = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
257
- if ($storeId) {
258
- $this->_attributes[$attributeCode]->setStoreId($storeId);
259
- }
260
- }
261
- return $this->_attributes[$attributeCode];
262
- }
263
-
264
- protected function _getAttributeDataForProduct($nameNode, $attributeCode, $product, $storeId = null) {
265
- $_helper = Mage::helper('catalog/output');
266
- if(!$attributeCode) {
267
- return '';
268
- }
269
-
270
- $data = $product->getData($attributeCode);
271
-
272
- $attribute = $this->_getAttribute($attributeCode, $storeId);
273
- if ($attribute) {
274
- if ($attribute->getFrontendInput() == 'date') {
275
- return $data;
276
- }
277
-
278
- //$data = $attribute->getFrontend()->getValue($product);
279
- //$data = $_helper->productAttribute($product, $data, $attributeCode);
280
- if ($attribute->usesSource()) {
281
- $data = $attribute->getSource()->getOptionText($data);
282
- if (is_array($data)) {
283
- $data = implode(', ', $data);
284
- }
285
- //$data = $product->getAttributeText($attributeCode);
286
- }
287
-
288
-
289
- if ($attribute->getFrontendInput() == 'weee') {
290
- $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
291
- if(isset($data[0]['value'])) {//in case weeeAttributes is empty
292
- $data = $data[0]['value'];
293
- }
294
-
295
- foreach ($weeeAttributes as $wa) {
296
- if ($wa->getCode() == $attributeCode) {
297
- $data = round($wa->getAmount(), 2);
298
- break;
299
- }
300
- }
301
- }
302
- }
303
-
304
- //TODO remove this
305
- if ($data == "No" || $data == "Non")
306
- $data = "";
307
-
308
- //Exceptions data
309
- if ($nameNode == 'shipping_delay' && empty($data))
310
- $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay', $storeId);
311
-
312
- if ($nameNode == 'quantity')
313
- $data = round($data);
314
-
315
- if(is_array($data)) {
316
- $data = implode(',', $data);
317
- }
318
- return trim($data);
319
- }
320
-
321
- protected $_memoryLimit = null;
322
- protected $_maxExecutionTime = null;
323
-
324
- protected function _checkMemory() {
325
- $request = Mage::app()->getRequest();
326
- if ($request->getControllerName() == 'export_flux' && $request->getActionName() == 'index') {
327
- if (is_null($this->_memoryLimit)) {
328
- $memoryLimit = ini_get('memory_limit');
329
- if (preg_match('%M$%', $memoryLimit)) {
330
- $memoryLimit = intval($memoryLimit) * 1024 * 1024;
331
- } else if (preg_match('%G$%', $memoryLimit)) {
332
- $memoryLimit = intval($memoryLimit) * 1024 * 1024 * 1024;
333
- } else {
334
- $memoryLimit = false;
335
- }
336
- $this->_memoryLimit = $memoryLimit;
337
- if(intval(Mage::getStoreConfig('shoppingflux_export/general/execution_time_limit')) > 1) {
338
- $this->_maxExecutionTime = intval(Mage::getStoreConfig('shoppingflux_export/general/execution_time_limit'));
339
- } else {
340
- $this->_maxExecutionTime = (ini_get('max_execution_time')>1)?ini_get('max_execution_time'):600;
341
- }
342
- $this->_maxExecutionTime = min($this->_maxExecutionTime, 9 * 60); //There is a 10min timeout on SF side. We took 9 for margin.
343
-
344
- }
345
- $isTimeToDie = (microtime(true) - Mage::registry('export_feed_start_at') > $this->_maxExecutionTime);
346
- if ($this->_memoryLimit > 0 || $isTimeToDie) {
347
- $currentMemoryUsage = memory_get_usage(true);
348
- if ($isTimeToDie || $this->_memoryLimit - 15 * 1024 * 1024 <= $currentMemoryUsage) {
349
- header('Content-type: text/html; charset=UTF-8');
350
- header('Refresh: 0;');
351
- $reasons = array();
352
- if($isTimeToDie) {
353
- $reasons[] = 'Is Time to die : Execution time : '.(round(microtime(true) - Mage::registry('export_feed_start_at'), 2)).' - Max execution time : ' . $this->_maxExecutionTime;
354
- }
355
- if($this->_memoryLimit-10*1024*1024 <= $currentMemoryUsage) {
356
- $reasons[] = 'Memory limit : Used '.$currentMemoryUsage.' of '.$this->_memoryLimit;
357
- }
358
-
359
- die('<html><head><meta http-equiv="refresh" content="0"/></head><body><!--Reason : '.implode(',', $reasons).'--></body></html>');
360
- }
361
- }
362
- }
363
- }
364
-
365
- public function updateProductInFluxForAllStores($productSku) {
366
- foreach (Mage::app()->getStores() as $store) {
367
- $storeId = $store->getId();
368
- $isCurrentStore = (Mage::app()->getStore()->getId() == $storeId);
369
- try {
370
- if (!$isCurrentStore) {
371
- $appEmulation = Mage::getSingleton('core/app_emulation');
372
- if ($appEmulation) {
373
- $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
374
- }
375
- }
376
- $this->updateProductInFlux($productSku, $storeId);
377
- if (!$isCurrentStore && $appEmulation) {
378
- $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
379
- }
380
- } catch (Exception $e) {
381
- if (!$isCurrentStore && $appEmulation) {
382
- $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
383
- }
384
- }
385
- }
386
- }
387
-
388
- public function updateProductInFlux($productSku, $storeId) {
389
-
390
- //$this->_checkMemory();
391
-
392
- $product = $this->_getProductBySku($productSku, $storeId);
393
-
394
- if (!$product || !$product->getSku()) {
395
- $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($productSku, $storeId);
396
- $fluxEntry->setShouldExport(0);
397
- $fluxEntry->setUpdateNeeded(0);
398
- $fluxEntry->setUpdatedAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
399
- $fluxEntry->save();
400
- return;
401
- }
402
-
403
-
404
- if (!$this->_shouldUpdate($product, $storeId)) {
405
- $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($product->getSku(), $storeId);
406
- $fluxEntry->setShouldExport(0);
407
- $fluxEntry->setStockValue($product->getStockItem()->getQty());
408
- $fluxEntry->setUpdateNeeded(0);
409
- $fluxEntry->setUpdatedAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
410
- $fluxEntry->save();
411
- return;
412
- }
413
- //Varien_Profiler::start("SF::Flux::updateProductInFlux");
414
-
415
- $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
416
- $xml = '';
417
-
418
- if ($this->getConfig()->useManageStock()) {
419
- $_configManageStock = (int) Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId);
420
- $_manageStock = ($product->getStockItem()->getUseConfigManageStock() ? $_configManageStock : $product->getStockItem()->getManageStock());
421
- } else {
422
- $_manageStock = true;
423
- }
424
-
425
- $data = array(
426
- 'id' => $product->getId(),
427
- 'last-feed-update' => date('Y-m-d H:i:s'),
428
- 'mage-sku' => $product->getSku(),
429
- 'product-url' => $this->cleanUrl($product->getProductUrl(false)),
430
- 'is-in-stock' => $_manageStock ? $product->getStockItem()->getIsInStock() : 1,
431
- 'salable' => intval($product->isSalable()),
432
- 'qty' => $product->isSalable() ? ($_manageStock ? round($product->getStockItem()->getQty()) : 100) : 0,
433
- 'qty-increments' => $this->getConfig()->getTransformQtyIncrements($product) ? 1 : $this->getConfig()->getQtyIncrements($product),
434
- 'tax-rate' => $product->getTaxPercent(),
435
- );
436
-
437
- if ($this->getConfig()->getTransformQtyIncrements($product)) {
438
- $qtyIncrements = $this->getConfig()->getQtyIncrements($product);
439
- $data['qty'] = $data['qty'] / $qtyIncrements;
440
- }
441
-
442
-
443
- foreach ($this->getConfig()->getMappingAttributes($storeId) as $nameNode => $code) {
444
- $data[$nameNode] = $this->_getAttributeDataForProduct($nameNode, $code, $product, $storeId); //trim($xmlObj->extractData($nameNode, $code, $product));
445
- if ($this->getConfig()->getTransformQtyIncrements($product)) {
446
- $qtyIncrements = $this->getConfig()->getQtyIncrements($product);
447
- if ($nameNode == 'name') {
448
- $data[$nameNode] = $data[$nameNode] . Mage::helper('profileolabs_shoppingflux')->__(' - Set of %d', $qtyIncrements);
449
- } else if ($nameNode == 'sku') {
450
- $data[$nameNode] = '_SFQI_' . $qtyIncrements . '_' . $data[$nameNode];
451
- } else if ($nameNode == 'weight') {
452
- $data[$nameNode] = $qtyIncrements * $data[$nameNode];
453
- }
454
- }
455
- }
456
-
457
- //Varien_Profiler::start("SF::Flux::getPrices");
458
- $data = $this->getPrices($data, $product, $storeId);
459
- //Varien_Profiler::stop("SF::Flux::getPrices");
460
- //Varien_Profiler::start("SF::Flux::getImages");
461
- $data = $this->getImages($data, $product, $storeId);
462
- //Varien_Profiler::stop("SF::Flux::getImages");
463
- //Varien_Profiler::start("SF::Flux::getCategories");
464
- $data = $this->getCategories($data, $product, $storeId);
465
- //Varien_Profiler::stop("SF::Flux::getCategories");
466
- //Varien_Profiler::start("SF::Flux::getShippingInfo");
467
- $data = $this->getShippingInfo($data, $product, $storeId);
468
- //Varien_Profiler::stop("SF::Flux::getShippingInfo");
469
- if ($this->getConfig()->getManageConfigurables()) {
470
- //Varien_Profiler::start("SF::Flux::getConfigurableAttributes");
471
- $data = $this->getConfigurableAttributes($data, $product, $storeId);
472
- //Varien_Profiler::stop("SF::Flux::getConfigurableAttributes");
473
- }
474
- //Varien_Profiler::start("SF::Flux::getAdditionalAttributes");
475
- foreach ($this->getConfig()->getAdditionalAttributes($storeId) as $attributeCode) {
476
- $data[$attributeCode] = $this->_getAttributeDataForProduct($attributeCode, $attributeCode, $product, $storeId);
477
- }
478
-
479
- //Varien_Profiler::stop("SF::Flux::getAdditionalAttributes");
480
- //Varien_Profiler::start("SF::Flux::addEntry1");
481
- if (!isset($data['shipping_delay']) && empty($data['shipping_delay']))
482
- $data['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
483
-
484
-
485
- if ($this->getConfig()->getEnableEvents()) {
486
- $dataObj = new Varien_Object(array('entry' => $data, 'store_id' => $storeId, 'product' => $product));
487
- Mage::dispatchEvent('shoppingflux_before_update_entry', array('data_obj' => $dataObj));
488
-
489
- $entry = $dataObj->getEntry();
490
- } else {
491
- $entry = $data;
492
- }
493
-
494
-
495
- //Varien_Profiler::stop("SF::Flux::addEntry1");
496
- //Varien_Profiler::start("SF::Flux::addEntry2");
497
- $xml .= $xmlObj->_addEntry($entry);
498
- //Varien_Profiler::stop("SF::Flux::addEntry2");
499
- //Varien_Profiler::start("SF::Flux::saveProductFlux");
500
- $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($product->getSku(), $storeId);
501
- $fluxEntry->setUpdatedAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
502
- $fluxEntry->setXml($xml);
503
- $fluxEntry->setUpdateNeeded(0);
504
- $fluxEntry->setProductId($product->getId());
505
- $fluxEntry->setStockValue($product->getStockItem()->getQty());
506
- $fluxEntry->setPriceValue($product->getFinalPrice());
507
- $fluxEntry->setIsInStock($data['is-in-stock']);
508
- $fluxEntry->setSalable($product->isSalable());
509
- $fluxEntry->setIsInFlux(intval($product->getData('shoppingflux_product')));
510
- $fluxEntry->setType($product->getTypeId());
511
- $fluxEntry->setVisibility($product->getVisibility());
512
- $fluxEntry->setShouldExport(1);
513
- $fluxEntry->save();
514
- // Faster
515
- /*
516
- $tableName = Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux');
517
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
518
- $request = "INSERT INTO " . $tableName . " (sku, store_id, updated_at, xml, update_needed, is_in_stock, is_in_flux, type, visibility, should_export) VALUES ";
519
- $request .= "(" . $write->quote($product->getSku()) . ", " . $write->quote($storeId) . ", " . $write->quote(date('Y-m-d H:i:s')) . ", " . $write->quote($xml) . ", '0', " . $write->quote($data['is-in-stock']) . ", " . $write->quote($product->getData('shoppingflux_product')) . ", '" . $product->getTypeId() . "', '" . $product->getVisibility() . "', '1')";
520
- $request .= " on duplicate key update updated_at = VALUES(updated_at), xml = VALUES(xml), update_needed = VALUES(update_needed), is_in_stock = VALUES(is_in_stock), is_in_flux = VALUES(is_in_flux), type = VALUES(type), visibility = VALUES(visibility), should_export = VALUES(should_export) ";
521
- $write->query($request);
522
- */
523
- //Varien_Profiler::stop("SF::Flux::saveProductFlux");
524
- //Varien_Profiler::stop("SF::Flux::updateProductInFlux");
525
- }
526
-
527
- /**
528
- * Get prices of product
529
- * @param Mage_Catalog_Model_Product $product
530
- * @return string $nodes
531
- */
532
- protected function getPrices($data, $product, $storeId) {
533
-
534
- $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/attributes_mapping/price', $storeId);
535
- $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/attributes_mapping/special_price', $storeId);
536
- if (!$product->getData($priceAttributeCode)) {
537
- $priceAttributeCode = 'price';
538
- $specialPriceAttributeCode = 'special_price';
539
- }
540
-
541
- $discountAmount = 0;
542
- $finalPrice = $product->getData($priceAttributeCode);
543
- $priceBeforeDiscount = $product->getData($priceAttributeCode);
544
- if ($product->getData($specialPriceAttributeCode) > 0 && $product->getData($specialPriceAttributeCode) < $finalPrice) {
545
- $finalPrice = $product->getData($specialPriceAttributeCode);
546
- $discountAmount = $priceBeforeDiscount - $finalPrice;
547
- }
548
- $discountFromDate = $product->getSpecialFromDate();
549
- $discountToDate = $product->getSpecialToDate();
550
-
551
-
552
- $product->setCalculatedFinalPrice($finalPrice);
553
- $product->setData('final_price', $finalPrice);
554
- $currentVersion = Mage::getVersion();
555
- if (version_compare($currentVersion, '1.5.0') < 0) {
556
- if ($this->getConfig()->getManageCatalogRules()) {
557
- Mage::dispatchEvent('catalog_product_get_final_price', array('product'=>$product));
558
- $finalPrice = $product->getFinalPrice();
559
- $discountAmount = $priceBeforeDiscount - $finalPrice;
560
- $discountFromDate = '';
561
- $discountToDate = '';
562
- }
563
- } else {
564
- if ($this->getConfig()->getManageCatalogRules()) {
565
- $catalogPriceRulePrice = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product, $product->getPrice());
566
- if ($catalogPriceRulePrice > 0 && $catalogPriceRulePrice < $finalPrice) {
567
- $finalPrice = $catalogPriceRulePrice;
568
- $discountAmount = $priceBeforeDiscount - $catalogPriceRulePrice;
569
- $discountFromDate = '';
570
- $discountToDate = '';
571
- }
572
- }
573
- }
574
-
575
- if ($this->getConfig()->getTransformQtyIncrements($product)) {
576
- $qtyIncrements = $this->getConfig()->getQtyIncrements($product);
577
- $finalPrice *= $qtyIncrements;
578
- $priceBeforeDiscount *= $qtyIncrements;
579
- }
580
-
581
- $data["price-ttc"] = Mage::helper('tax')->getPrice($product, $finalPrice, true); //$finalPrice;
582
- $data["price-before-discount"] = Mage::helper('tax')->getPrice($product, $priceBeforeDiscount, true); //$priceBeforeDiscount;
583
- $data["discount-amount"] = $product->getTypeId() != 'bundle' ? $discountAmount : 0;
584
- $data["discount-percent"] = $this->getPercent($product);
585
-
586
- $data["start-date-discount"] = "";
587
- $data["end-date-discount"] = "";
588
- if ($discountFromDate) {
589
- $data["start-date-discount"] = $discountFromDate;
590
- }
591
- if ($discountToDate) {
592
- $data["end-date-discount"] = $discountToDate;
593
- }
594
- unset($data['price']);
595
- unset($data['special_price']);
596
- return $data;
597
- }
598
-
599
- /**
600
- * Get categories of product
601
- * @param Mage_Catalog_Model_Product $product
602
- * @return string $nodes
603
- */
604
- protected function getCategories($data, $product, $storeId) {
605
- if ($product->getData('shoppingflux_default_category') && $product->getData('shoppingflux_default_category') > 0) {
606
- $data = $this->getCategoriesViaShoppingfluxCategory($data, $product);
607
- } else {
608
- $data = $this->getCategoriesViaProductCategories($data, $product);
609
- }
610
- if(!$data['category-breadcrumb']) {
611
- $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
612
- $parentIds = array_merge($parentIds, Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId()));
613
- $parentIds = array_merge($parentIds, Mage::getModel('bundle/product_type')->getParentIdsByChild($product->getId()));
614
- $parentIds = array_unique($parentIds);
615
- foreach ($parentIds as $parentId) {
616
- if(!$data['category-breadcrumb']) {
617
- $parentProduct = $this->_getProduct($parentId, $storeId);
618
- if($parentProduct && is_object($parentProduct) && $parentProduct->getId()) {
619
- $data = $this->getCategories($data, $parentProduct, $storeId);
620
- }
621
- }
622
-
623
- }
624
- }
625
- return $data;
626
- }
627
-
628
- protected function getCategoriesViaShoppingfluxCategory($data, $product) {
629
-
630
- //Varien_Profiler::start("SF::Flux::getCategoriesViaShoppingfluxCategory-1");
631
- $categoryId = $product->getData('shoppingflux_default_category');
632
- if (!$categoryId) {
633
- $categoryId = $product->getData('main_category');//Compatibility with Webcooking_MainCategory
634
- if (!$categoryId) {
635
- return $this->getCategoriesViaProductCategories($data, $product);
636
- }
637
- }
638
- $category = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents(false, $product->getStoreId());
639
- //Varien_Profiler::stop("SF::Flux::getCategoriesViaShoppingfluxCategory-1");
640
- if (!isset($category['name'][$categoryId])) {
641
- return $this->getCategoriesViaProductCategories($data, $product);
642
- }
643
-
644
- //Varien_Profiler::start("SF::Flux::getCategoriesViaShoppingfluxCategory");
645
-
646
- $categoryNames = explode(' > ', $category['name'][$categoryId]);
647
- $categoryMetaTitles = explode(' > ', $category['meta_title'][$categoryId]);
648
- $categoryMetaDescriptions = explode(' > ', $category['meta_description'][$categoryId]);
649
- $categoryMetaKeywords = explode(' > ', $category['meta_keywords'][$categoryId]);
650
- $categoryUrls = explode(' > ', $category['url'][$categoryId]);
651
-
652
-
653
- //we drop root category, which is useless here
654
- array_shift($categoryNames);
655
- array_shift($categoryMetaTitles);
656
- array_shift($categoryMetaDescriptions);
657
- array_shift($categoryMetaKeywords);
658
- array_shift($categoryUrls);
659
-
660
-
661
- $data['category-breadcrumb'] = trim(implode(' > ', $categoryNames));
662
-
663
- $data["category-main"] = isset($categoryNames[0]) ? trim($categoryNames[0]) : '';
664
- $data["category-url-main"] = isset($categoryUrls[0]) ? $categoryUrls[0] : '';
665
- $data["category-metatitle-main"] = isset($categoryMetaTitles[0]) ? $categoryMetaTitles[0] : '';
666
- $data["category-metadescription-main"] = isset($categoryMetaDescriptions[0]) ? $categoryMetaDescriptions[0] : '';
667
- $data["category-metakeywords-main"] = isset($categoryMetaKeywords[0]) ? $categoryMetaKeywords[0] : '';
668
-
669
-
670
- for ($i = 1; $i <= 5; $i++) {
671
- if (isset($categoryNames[$i])) {
672
- $data["category-sub-" . ($i)] = trim($categoryNames[$i]);
673
- } else {
674
- $data["category-sub-" . ($i)] = '';
675
- }
676
- if (isset($categoryUrls[$i])) {
677
- $data["category-url-sub-" . ($i)] = $categoryUrls[$i];
678
- } else {
679
- $data["category-url-sub-" . ($i)] = '';
680
- }
681
- if (isset($categoryMetaTitles[$i])) {
682
- $data["category-metatitle-sub-" . ($i)] = $categoryMetaTitles[$i];
683
- } else {
684
- $data["category-metatitle-sub-" . ($i)] = '';
685
- }
686
- if (isset($categoryMetaDescriptions[$i])) {
687
- $data["category-metadescription-sub-" . ($i)] = $categoryMetaDescriptions[$i];
688
- } else {
689
- $data["category-metadescription-sub-" . ($i)] = '';
690
- }
691
- if (isset($categoryMetaKeywords[$i])) {
692
- $data["category-metakeywords-sub-" . ($i)] = $categoryMetaKeywords[$i];
693
- } else {
694
- $data["category-metakeywords-sub-" . ($i)] = '';
695
- }
696
- }
697
-
698
- //Varien_Profiler::stop("SF::Flux::getCategoriesViaShoppingfluxCategory");
699
- return $data;
700
- }
701
-
702
- protected function getCategoriesViaProductCategories($data, $product) {
703
-
704
- //Varien_Profiler::start("SF::Flux::getCategoriesViaProductCategories");
705
- $cnt = 0;
706
-
707
- if (!$this->getConfig()->getUseOnlySFCategory()) {
708
- $rootCategoryId = Mage::app()->getStore($product->getStoreId())->getRootCategoryId();
709
-
710
- $categoryWithParents = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents(false, $product->getStoreId(), false, false);
711
- $maxLevelCategory = $this->getConfig()->getMaxCategoryLevel() > 0 ? $this->getConfig()->getMaxCategoryLevel() : 5;
712
-
713
-
714
- //Selection of the deepest category
715
- $productCategoryIds = $product->getCategoryIds();
716
- $choosenProductCategoryId = false;
717
- $choosenCategoryLevel = 0;
718
- foreach ($productCategoryIds as $productCategoryId) {
719
- if (isset($categoryWithParents['name'][$productCategoryId])) {
720
- $categoryNames = explode(' > ', $categoryWithParents['name'][$productCategoryId]);
721
- if (count($categoryNames) > $choosenCategoryLevel) {
722
- $choosenProductCategoryId = $productCategoryId;
723
- }
724
- }
725
- }
726
-
727
- //Adding the deepest category to breadcrumb
728
- if ($choosenProductCategoryId) {
729
- $categoryNames = explode(' > ', $categoryWithParents['name'][$choosenProductCategoryId]);
730
- $categoryMetaTitles = explode(' > ', $categoryWithParents['meta_title'][$choosenProductCategoryId]);
731
- $categoryMetaDescriptions = explode(' > ', $categoryWithParents['meta_description'][$choosenProductCategoryId]);
732
- $categoryMetaKeywords = explode(' > ', $categoryWithParents['meta_keywords'][$choosenProductCategoryId]);
733
- $categoryUrls = explode(' > ', $categoryWithParents['url'][$choosenProductCategoryId]);
734
- //we drop root category, which is useless here
735
- array_shift($categoryNames);
736
- array_shift($categoryMetaTitles);
737
- array_shift($categoryMetaDescriptions);
738
- array_shift($categoryMetaKeywords);
739
- array_shift($categoryUrls);
740
- $categoryNames = array_slice($categoryNames, 0, $maxLevelCategory, true);
741
- $categoryUrls = array_slice($categoryUrls, 0, $maxLevelCategory, true);
742
- $data['category-breadcrumb'] = trim(implode(' > ', $categoryNames));
743
-
744
- $data["category-main"] = trim($categoryNames[0]);
745
- $data["category-url-main"] = $categoryUrls[0];
746
- $data["category-metatitle-main"] = $categoryMetaTitles[0];
747
- $data["category-metadescription-main"] = $categoryMetaDescriptions[0];
748
- $data["category-metakeywords-main"] = $categoryMetaKeywords[0];
749
-
750
-
751
- for ($i = 1; $i <= 5; $i++) {
752
- if (isset($categoryNames[$i])) {
753
- $data["category-sub-" . ($i)] = trim($categoryNames[$i]);
754
- } else {
755
- $data["category-sub-" . ($i)] = '';
756
- }
757
- if (isset($categoryUrls[$i])) {
758
- $data["category-url-sub-" . ($i)] = $categoryUrls[$i];
759
- } else {
760
- $data["category-url-sub-" . ($i)] = '';
761
- }
762
- if (isset($categoryMetaTitles[$i])) {
763
- $data["category-metatitle-sub-" . ($i)] = $categoryMetaTitles[$i];
764
- } else {
765
- $data["category-metatitle-sub-" . ($i)] = '';
766
- }
767
- if (isset($categoryMetaDescriptions[$i])) {
768
- $data["category-metadescription-sub-" . ($i)] = $categoryMetaDescriptions[$i];
769
- } else {
770
- $data["category-metadescription-sub-" . ($i)] = '';
771
- }
772
- if (isset($categoryMetaKeywords[$i])) {
773
- $data["category-metakeywords-sub-" . ($i)] = $categoryMetaKeywords[$i];
774
- } else {
775
- $data["category-metakeywords-sub-" . ($i)] = '';
776
- }
777
- }
778
- }
779
- }
780
-
781
- if (!isset($data["category-main"])) {
782
- $data["category-breadcrumb"] = "";
783
- $data["category-main"] = "";
784
- $data["category-url-main"] = "";
785
- $cnt++;
786
- }
787
-
788
-
789
- for ($i = 1; $i <= 5; $i++) {
790
- if (!isset($data["category-sub-" . ($i)])) {
791
- $data["category-sub-" . ($i)] = "";
792
- $data["category-url-sub-" . ($i)] = "";
793
- }
794
- }
795
-
796
-
797
- //Varien_Profiler::stop("SF::Flux::getCategoriesViaProductCategories");
798
- return $data;
799
- }
800
-
801
- public function cleanUrl($url) {
802
- $url = str_replace("index.php/", "", $url);
803
- $url = preg_replace('%(.*)\?.*$%i', '$1', $url);
804
- return $url;
805
- }
806
-
807
- public function getImages($data, $product, $storeId, $checkParentIfNone = true) {
808
-
809
-
810
-
811
- $mediaUrl = Mage::getBaseUrl('media') . 'catalog/product';
812
-
813
- $i = 1;
814
-
815
- if ($product->getImage() != "" && $product->getImage() != 'no_selection') {
816
- $data["image-url-" . $i] = $mediaUrl . $product->getImage();
817
- $data["image-label-" . $i] = $product->getImageLabel();
818
- $i++;
819
- }
820
-
821
-
822
- if ($this->getConfig()->getManageMediaGallery()) {
823
- //LOAD media gallery for this product
824
- $mediaGallery = $product->getResource()->getAttribute('media_gallery');
825
- $mediaGallery->getBackend()->afterLoad($product);
826
-
827
-
828
- foreach ($product->getMediaGallery('images') as $image) {
829
- if ($mediaUrl . $product->getImage() == $product->getMediaConfig()->getMediaUrl($image['file']))
830
- continue;
831
- if($image['disabled'])
832
- continue;
833
-
834
- $data["image-url-" . $i] = $product->getMediaConfig()->getMediaUrl($image['file']);
835
- $data["image-label-" . $i] = $image['label'];
836
- $i++;
837
- if (($i - 6) == 0)
838
- break;
839
- }
840
- }
841
-
842
-
843
- //Complet with empty nodes
844
- for ($j = $i; $j < 6; $j++) {
845
- $data["image-url-" . $i] = "";
846
- $data["image-label-" . $i] = "";
847
- $i++;
848
- }
849
-
850
- if(!$data['image-url-1'] && $checkParentIfNone) {
851
- $groupedParentsIds = Mage::getResourceSingleton('catalog/product_link')
852
- ->getParentIdsByChild($product->getId(), Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED);
853
- $parentId = current($groupedParentsIds);
854
- $parentProduct = $this->_getProduct($parentId, $storeId);
855
- if($parentProduct && $parentProduct->getId()) {
856
- return $this->getImages($data, $parentProduct, $storeId, false);
857
- }
858
- }
859
-
860
-
861
- return $data;
862
- }
863
-
864
- protected function getPercent($product) {
865
-
866
- /* if($product->getTypeId() == 'bundle')
867
- return 0; */
868
- $price = round($product->getPrice(), 2);
869
- if ($price == "0") {
870
- $price = round($product->getMinimalPrice(), 2);
871
- }
872
-
873
- if ($price == "0")
874
- return 0;
875
-
876
- $special = round($product->getFinalPrice(), 2);
877
- $tmp = $price - $special;
878
- $tmp = ($tmp * 100) / $price;
879
- return round($tmp);
880
- }
881
-
882
- /**
883
- *
884
- */
885
- protected function getAttributesFromConfig($checkIfExist = false, $withAdditional = true, $storeId = null) {
886
-
887
- if (!isset($this->_attributesFromConfig[$storeId])) {
888
- $this->_attributesFromConfig[$storeId] = array();
889
- $attributes = $this->getConfig()->getMappingAttributes($storeId);
890
- if ($withAdditional) {
891
- $additionalAttributes = $this->getConfig()->getAdditionalAttributes($storeId);
892
- foreach ($additionalAttributes as $attributeCode) {
893
- $attributes[$attributeCode] = trim($attributeCode);
894
- }
895
- }
896
-
897
- if ($checkIfExist) {
898
- $product = Mage::getModel('catalog/product');
899
- foreach ($attributes as $key => $code) {
900
- $attribute = $this->_getAttribute($code);
901
- if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute && $attribute->getId() && $attribute->getFrontendInput() != 'weee') {
902
- $this->_attributesFromConfig[$storeId][$key] = $code;
903
- }
904
- }
905
- } else {
906
- $this->_attributesFromConfig[$storeId] = $attributes;
907
- }
908
- }
909
-
910
- return $this->_attributesFromConfig[$storeId];
911
- }
912
-
913
- protected function getRequiredAttributes() {
914
-
915
- $requiredAttributes = array("sku" => "sku",
916
- "price" => "price",
917
- "image" => "image");
918
-
919
- return $requiredAttributes;
920
- }
921
-
922
- /**
923
- *
924
- * @deprecated
925
- */
926
- protected function getAllAttributes() {
927
- return array_merge($this->getAttributesFromConfig(true), $this->getRequiredAttributes());
928
- }
929
-
930
- /**
931
- * Retrieve Catalog Product Flat Helper object
932
- *
933
- * @return Mage_Catalog_Helper_Product_Flat
934
- */
935
- public function getFlatHelper() {
936
- return Mage::helper('catalog/product_flat');
937
- }
938
-
939
- protected function getShippingInfo($data, $product, $storeId) {
940
-
941
- $data["shipping-name"] = "";
942
- $data["shipping-price"] = "";
943
-
944
- $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
945
- if (empty($carrier)) {
946
- $data["shipping-price"] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
947
- return $data;
948
- }
949
-
950
- $carrierTab = explode('_', $carrier);
951
- list($carrierCode, $methodCode) = $carrierTab;
952
- $data["shipping-name"] = ucfirst($methodCode);
953
-
954
-
955
- $shippingPrice = 0;
956
- if ($this->getConfig()->getConfigData('shoppingflux_export/general/try_use_real_shipping_price')) {
957
- $countryCode = $this->getConfig()->getConfigData('shoppingflux_export/general/shipping_price_based_on');
958
- $shippingPrice = Mage::helper('profileolabs_shoppingflux')->getShippingPrice($product, $carrier, $countryCode);
959
- }
960
-
961
- if (!$shippingPrice) {
962
- $shippingPrice = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
963
- }
964
-
965
- $data["shipping-price"] = $shippingPrice;
966
-
967
- return $data;
968
- }
969
-
970
- protected function getConfigurableAttributes($data, $product, $storeId) {
971
-
972
- $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
973
- $data["configurable_attributes"] = "";
974
- $data["childs_product"] = "";
975
- $images = array();
976
-
977
- $labels = array();
978
- if ($product->getTypeId() == "configurable") {
979
-
980
- $attributes = Mage::helper('profileolabs_shoppingflux')->getAttributesConfigurable($product);
981
-
982
- $attributesToOptions = array();
983
-
984
- foreach ($attributes as $attribute) {
985
- $attributesToOptions[$attribute['attribute_code']] = array();
986
- }
987
-
988
- $usedProducts = $product->getTypeInstance(true)
989
- ->getUsedProductCollection($product);
990
-
991
-
992
- $configurableAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
993
-
994
-
995
- $usedProductsArray = array();
996
- $salable = false;
997
- foreach (Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($usedProducts->getSelect()) as $usedProduct) { //Prevent Old magento bug
998
- $usedProduct = $this->_getProduct($usedProduct['entity_id'], $storeId);
999
-
1000
- if (!$usedProduct) {
1001
- continue;
1002
- }
1003
- if ($usedProduct->getStatus() == 2) {
1004
- continue;
1005
- }
1006
-
1007
- $salable = $salable || $usedProduct->isSalable();
1008
-
1009
-
1010
- if (Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('OrganicInternet_SimpleConfigurableProducts') || Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('DerModPro_BCP')) {
1011
-
1012
- $tmpData = $this->getPrices(array(), $usedProduct, $storeId);
1013
- $price = $tmpData['price-ttc'] > 0 ? $tmpData['price-ttc'] : $data['price-ttc'];
1014
- if ($data['price-ttc'] <= 0 || ($price > 0 && $price < $data['price-ttc'])) {
1015
- $data['price-ttc'] = $price;
1016
- }
1017
- $priceBeforeDiscount = $tmpData["price-before-discount"];
1018
- $discountAmount = $tmpData["discount-amount"];
1019
- $startDateDiscount = $tmpData["start-date-discount"];
1020
- $endDateDiscount = $tmpData["end-date-discount"];
1021
- } else {
1022
-
1023
- $price = $data['price-ttc'];
1024
- $priceBeforeDiscount = $data["price-before-discount"];
1025
- $discountAmount = $data["discount-amount"];
1026
- $startDateDiscount = $data["start-date-discount"];
1027
- $endDateDiscount = $data["end-date-discount"];
1028
-
1029
- foreach ($configurableAttributes as $configurableAttribute) {
1030
- $attributeCode = $configurableAttribute['attribute_code'];
1031
- foreach ($configurableAttribute['values'] as $confAttributeValue) {
1032
- if ($confAttributeValue['pricing_value'] && $usedProduct->getData($attributeCode) == $confAttributeValue['value_index']) {
1033
- if ($confAttributeValue['is_percent']) {
1034
- $price += $data['price-ttc'] * $confAttributeValue['pricing_value'] / 100;
1035
- $priceBeforeDiscount += $data['price-before-discount'] * $confAttributeValue['pricing_value'] / 100;
1036
- } else {
1037
- $price += $confAttributeValue['pricing_value'];
1038
- $priceBeforeDiscount += $confAttributeValue['pricing_value'];
1039
- }
1040
- }
1041
- }
1042
- }
1043
- }
1044
-
1045
- $attributesFromConfig = $this->getAttributesFromConfig(true, true, $storeId);
1046
-
1047
- $discountPercent = 0;
1048
- if ($priceBeforeDiscount) {
1049
- $discountPercent = round((($priceBeforeDiscount - $price) * 100) / $priceBeforeDiscount);
1050
- }
1051
-
1052
- $isInStock = 0;
1053
- $qty = 0;
1054
- if ($usedProduct->getStockItem()) {
1055
- if ($this->getConfig()->useManageStock()) {
1056
- $_configManageStock = (int) Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId);
1057
- $_manageStock = $usedProduct->getStockItem()->getUseConfigManageStock() ? $_configManageStock : $usedProduct->getStockItem()->getManageStock();
1058
- } else {
1059
- $_manageStock = true;
1060
- }
1061
-
1062
- $isInStock = $_manageStock ? $usedProduct->getStockItem()->getIsInStock() : 1;
1063
-
1064
- if ($usedProduct->isSalable()) {
1065
- $qty = $_manageStock ? $usedProduct->getStockItem()->getQty() : 100;
1066
- } else {
1067
- $qty = 0;
1068
- }
1069
- }
1070
-
1071
- $usedProductsArray[$usedProduct->getId()]['child']["sku"] = $usedProduct->getSku();
1072
- $usedProductsArray[$usedProduct->getId()]['child']["id"] = $usedProduct->getId();
1073
- $usedProductsArray[$usedProduct->getId()]['child']["child-url"] = $this->cleanUrl($usedProduct->getProductUrl(false));
1074
- $usedProductsArray[$usedProduct->getId()]['child']["price-ttc"] = $price;
1075
- $usedProductsArray[$usedProduct->getId()]['child']["price-before-discount"] = $priceBeforeDiscount;
1076
- $usedProductsArray[$usedProduct->getId()]['child']["discount-amount"] = $discountAmount;
1077
- $usedProductsArray[$usedProduct->getId()]['child']["discount-percent"] = $discountPercent;
1078
- $usedProductsArray[$usedProduct->getId()]['child']["start-date-discount"] = $startDateDiscount;
1079
- $usedProductsArray[$usedProduct->getId()]['child']["end-date-discount"] = $endDateDiscount;
1080
- $usedProductsArray[$usedProduct->getId()]['child']['is-in-stock'] = $isInStock;
1081
- $usedProductsArray[$usedProduct->getId()]['child']['qty'] = round($qty);
1082
- $usedProductsArray[$usedProduct->getId()]['child']['tax-rate'] = $usedProduct->getTaxPercent();
1083
- if (!$data['tax-rate'] && $usedProductsArray[$usedProduct->getId()]['child']['tax-rate']) {
1084
- $data['tax-rate'] = $usedProductsArray[$usedProduct->getId()]['child']['tax-rate'];
1085
- }
1086
- if ($qty > 0 && $qty > $data['qty']) {
1087
- $data['qty'] = round($qty);
1088
- }
1089
- $usedProductsArray[$usedProduct->getId()]['child']["ean"] = isset($attributesFromConfig['ean']) ? $usedProduct->getData($attributesFromConfig['ean']) : '';
1090
-
1091
- $images = $this->getImages($images, $usedProduct, $storeId, false);
1092
- if (!$images['image-url-1']) {
1093
- $images = $this->getImages($images, $product, $storeId);
1094
- }
1095
- foreach ($images as $key => $value) {
1096
- $usedProductsArray[$usedProduct->getId()]['child'][$key] = trim($value);
1097
- }
1098
-
1099
- foreach ($attributesFromConfig as $nameNode => $attributeCode) {
1100
- if($attributeCode) {
1101
- $usedProductsArray[$usedProduct->getId()]['child'][$nameNode] = $this->_getAttributeDataForProduct($nameNode, $attributeCode, $usedProduct, $storeId); //$xmlObj->extractData($nameNode, $attributeCode, $usedProduct);
1102
- }
1103
- }
1104
-
1105
-
1106
- $attributes = Mage::helper('profileolabs_shoppingflux')->getAttributesConfigurable($product);
1107
- foreach ($attributes as $attribute) {
1108
- $attributeCode = $attribute['attribute_code'];
1109
- $attributeId = $attribute['attribute_id'];
1110
-
1111
- if (!isset($this->_attributesConfigurable[$attributeId]))
1112
- $this->_attributesConfigurable[$attributeId] = $product->getResource()->getAttribute($attributeId);
1113
-
1114
- $attributeModel = $this->_attributesConfigurable[$attributeId];
1115
-
1116
- $value = '';
1117
- if ($usedProduct->getData($attributeCode)) {
1118
- $value = $attributeModel->getFrontend()->getValue($usedProduct);
1119
- }
1120
-
1121
- if (!isset($attributesToOptions[$attributeCode]) || !in_array($value, $attributesToOptions[$attributeCode]))
1122
- $attributesToOptions[$attributeCode][] = $value;
1123
-
1124
- $usedProductsArray[$usedProduct->getId()]['child'][$attributeCode] = trim($value);
1125
- }
1126
-
1127
-
1128
- if (!isset($usedProductsArray[$usedProduct->getId()]['child']['shipping_delay']) || !$usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'])
1129
- $usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
1130
-
1131
- unset($usedProductsArray[$usedProduct->getId()]['child']['price']);
1132
- unset($usedProductsArray[$usedProduct->getId()]['child']['special_price']);
1133
- }
1134
-
1135
-
1136
-
1137
-
1138
- $data['is-in-stock'] = (int) $salable;
1139
-
1140
- foreach ($attributesToOptions as $attributeCode => $value) {
1141
-
1142
- $data["configurable_attributes"][$attributeCode] = implode(",", $value);
1143
- }
1144
- $data["childs_product"] = $usedProductsArray;
1145
-
1146
- unset($usedProducts);
1147
- unset($usedProductsArray);
1148
- }
1149
- return $data;
1150
- }
1151
-
1152
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Export_Flux extends Mage_Core_Model_Abstract {
10
+
11
+ protected $_attributesFromConfig = array();
12
+ protected $_attributesConfigurable = array();
13
+ protected $_storeCategories = array();
14
+ protected $_excludedNotSalableProductsIds = array();
15
+
16
+ protected function _construct() {
17
+ $this->_init('profileolabs_shoppingflux/export_flux');
18
+ }
19
+
20
+ public function getEntry($productSku, $storeId) {
21
+ $collection = $this->getCollection();
22
+ $collection->addFieldToFilter('sku', $productSku);
23
+ $collection->addFieldToFilter('store_id', $storeId);
24
+ if ($collection->count() > 0) {
25
+ return $collection->getFirstItem();
26
+ }
27
+ $model = Mage::getModel('profileolabs_shoppingflux/export_flux')
28
+ ->setStoreId($storeId)
29
+ ->setSku($productSku)
30
+ ->setProductId(Mage::getModel('catalog/product')->getIdBySku($productSku))
31
+ ->setUpdateNeeded(0);
32
+ return $model;
33
+ }
34
+
35
+ protected function _getProductBySku($productSku, $storeId) {
36
+ $pId = Mage::getModel('catalog/product')->getIdBySku($productSku);
37
+ if (!$pId) {
38
+ return false;
39
+ }
40
+ return $this->_getProduct($pId, $storeId);
41
+ }
42
+
43
+ protected function _getProduct($product, $storeId) {
44
+ if (is_numeric($product)) {
45
+ $productId = $product;
46
+ } else if (is_object($product)) {
47
+ $productId = $product->getId();
48
+ } else {
49
+ return false;
50
+ }
51
+
52
+ $read = Mage::getSingleton('core/resource')->getConnection('core_read');
53
+ $select = $read->select()
54
+ ->distinct()
55
+ ->from(Mage::getConfig()->getTablePrefix() . 'catalog_product_website', array('website_id'))
56
+ ->where('product_id = ?', $productId);
57
+ $result = $read->fetchAll($select);
58
+ $websiteIds = array();
59
+ foreach ($result as $row) {
60
+ $websiteIds[] = $row['website_id'];
61
+ }
62
+
63
+ if (!in_array(Mage::app()->getStore($storeId)->getWebsiteId(), $websiteIds)) {
64
+ return false;
65
+ }
66
+
67
+ $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($productId);
68
+ if (!$product->getId()) {
69
+ return false;
70
+ }
71
+
72
+ return $product;
73
+ }
74
+
75
+ /**
76
+ * @return Profileolabs_Shoppingflux_Model_Config
77
+ */
78
+ public function getConfig() {
79
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
80
+ }
81
+
82
+ public function addMissingProduct($args) {
83
+ $storeId = $args['store_id'];
84
+ $this->updateProductInFlux($args['row']['sku'], $storeId);
85
+ }
86
+
87
+ public function checkForDeletedProducts() {
88
+ $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
89
+ $collection->getSelect()->joinLeft(
90
+ array('p' => $collection->getTable('catalog/product')),
91
+ 'p.entity_id = main_table.product_id',
92
+ array()
93
+ );
94
+ $existingStoreIds = array();
95
+ foreach(Mage::app()->getStores() as $store) {
96
+ $existingStoreIds[] = $store->getId();
97
+ }
98
+ $collection->getSelect()->where("p.entity_id IS NULL or main_table.store_id NOT IN (".implode(',',$existingStoreIds).")");
99
+ //$collection->walk('delete');
100
+ Mage::getSingleton('core/resource_iterator')
101
+ ->walk($collection->getSelect(), array(array($this, 'removeDeletedProduct')));
102
+ }
103
+
104
+ public function removeDeletedProduct($args) {
105
+ $fluxItem = Mage::getModel('profileolabs_shoppingflux/export_flux')->load($args['row']['id']);
106
+ $fluxItem->delete();
107
+ }
108
+
109
+
110
+ public function checkForMissingProducts($store_id = false, $maxImport = 1000) {
111
+ ini_set('display_errors', 1);
112
+ error_reporting(-1);
113
+ foreach (Mage::app()->getStores() as $store) {
114
+ $storeId = $store->getId();
115
+ if (!$this->getConfig()->isExportEnabled($storeId)) {
116
+ continue;
117
+ }
118
+ if (!$store_id || $storeId == $store_id) {
119
+ $productCollection = Mage::getModel('catalog/product')->getCollection()->addStoreFilter($storeId)->setStoreId($storeId);
120
+ $productCollection->addAttributeToSelect('sku', 'left');
121
+ $currentVersion = Mage::getVersion();
122
+ $tableName = Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux');
123
+ $productCollection->getSelect()->joinLeft(
124
+ array('sf'=>$tableName),
125
+ "entity_id=sf.product_id and store_id = '" . $storeId . "'",
126
+ array('skusf' => 'sku')
127
+ );
128
+ //not compatible with mage 1.3
129
+ //$productCollection->joinTable(array('sf'=>'profileolabs_shoppingflux/export_flux'), "sku=sku", array('skusf'=>'sku'), "{{table}}.store_id = '".$storeId."'", 'left');
130
+ $productCollection->setPage(1, $maxImport);
131
+ $productCollection->getSelect()->where('sf.product_id IS NULL');
132
+ //$productCollection->load();
133
+ //echo $productCollection->getSelect();
134
+ Mage::getSingleton('core/resource_iterator')
135
+ ->walk($productCollection->getSelect(), array(array($this, 'addMissingProduct')), array('store_id' => $storeId));
136
+ }
137
+ }
138
+
139
+ }
140
+
141
+ public function updateFlux($store_id = false, $maxImportLimit = 1000, $shouldExportOnly = false) {
142
+ //if(rand(0,100) == 50) {
143
+ //no need to execute this every time. todo : move to cron task
144
+ // $this->checkForDeletedProducts();
145
+ //}
146
+ foreach (Mage::app()->getStores() as $store) {
147
+ $storeId = $store->getId();
148
+ $isCurrentStore = (Mage::app()->getStore()->getId() == $storeId);
149
+ if (!$store_id || $store_id == $storeId) {
150
+ if (!$isCurrentStore) {
151
+ $appEmulation = Mage::getSingleton('core/app_emulation');
152
+ if ($appEmulation) { // not available in 1.4
153
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
154
+ }
155
+ }
156
+ try {
157
+ $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
158
+ $collection->addFieldToFilter('update_needed', 1);
159
+ $collection->addFieldToFilter('store_id', $storeId);
160
+ $collection->getSelect()->order('rand()');//if concurrent calls, this will avoid updating the same products..
161
+ if ($shouldExportOnly) {
162
+ $collection->addFieldToFilter('should_export', 1);
163
+ }
164
+ foreach ($collection as $item) {
165
+ $this->updateProductInFlux($item->getSku(), $storeId);
166
+ }
167
+ $this->checkForMissingProducts($storeId, $maxImportLimit);
168
+ if (!$isCurrentStore && $appEmulation) {
169
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
170
+ }
171
+ } catch (Exception $e) {
172
+ if (!$isCurrentStore && $appEmulation) {
173
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+
180
+ /**
181
+ * @param int $storeId
182
+ * @return int[]
183
+ */
184
+ protected function _getExcludedNotSalableProductsIds($storeId)
185
+ {
186
+ if (!isset($this->_excludedNotSalableProductsIds[$storeId])) {
187
+ if ($seconds = $this->getConfig()->getNotSalableRetentionDuration($storeId)) {
188
+ $resource = $this->getResource();
189
+ $connection = $resource->getReadConnection();
190
+
191
+ $this->_excludedNotSalableProductsIds[$storeId] = $connection->fetchCol(
192
+ $connection->select()
193
+ ->from(
194
+ $resource->getTable('profileolabs_shoppingflux/not_salable_product'),
195
+ array('product_id')
196
+ )
197
+ ->where('UNIX_TIMESTAMP(not_salable_from) <= ?', time() - $seconds)
198
+ );
199
+ } else {
200
+ $this->_excludedNotSalableProductsIds[$storeId] = array();
201
+ }
202
+ }
203
+ return $this->_excludedNotSalableProductsIds[$storeId];
204
+ }
205
+
206
+ public function productNeedUpdateForStore($productId, $storeId, $ignoreRelations = false) {
207
+ $product = $this->_getProduct($productId, $storeId);
208
+ if ($product && $product->getId()) {
209
+ $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($product->getSku(), $storeId);
210
+ if ($fluxEntry->getUpdateNeeded() != 1) {
211
+ $fluxEntry->setUpdateNeeded(1);
212
+ $fluxEntry->save();
213
+ }
214
+ if(!$ignoreRelations) {
215
+ // update also parents
216
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
217
+ foreach ($parentIds as $parentId) {
218
+ $this->productNeedUpdateForStore($parentId, $storeId, true);
219
+ }
220
+ // ... and child
221
+ if($product->getTypeId() == 'configurable') {
222
+ $childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);
223
+ foreach($childProducts as $childProduct) {
224
+ if($childProduct->getTypeId() == 'simple') {
225
+ $this->productNeedUpdateForStore($childProduct->getId(), $storeId, true);
226
+ }
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+
233
+ public function productNeedUpdate($productId) {
234
+ foreach (Mage::app()->getStores() as $store) {
235
+ $storeId = $store->getId();
236
+ $this->productNeedUpdateForStore($productId, $storeId);
237
+ }
238
+ return;
239
+ }
240
+
241
+ protected function _shouldUpdate($product, $storeId) {
242
+ if (!$this->getConfig()->isExportEnabled($storeId)) {
243
+ return false;
244
+ }
245
+
246
+ if ($product->getStatus() == 2)
247
+ return false;
248
+
249
+ if ($product->getTypeId() == 'grouped' || $product->getTypeId() == 'bundle' || $product->getTypeId() == 'virtual') {
250
+ return false;
251
+ }
252
+
253
+ $exportNotSalable = $this->getConfig()->isExportNotSalable();
254
+ $retainNotSalable = $this->getConfig()->isNotSalableRetentionEnabled();
255
+
256
+ if (!$product->isSalable()) {
257
+ if ((!$exportNotSalable && !$retainNotSalable)
258
+ || ($retainNotSalable && in_array($product->getId(), $this->_getExcludedNotSalableProductsIds($storeId)))) {
259
+ return false;
260
+ }
261
+ }
262
+
263
+ if ($product->getTypeId() == 'simple') {
264
+ $parentIds = Mage::getResourceSingleton('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
265
+
266
+ //FIX Added on 2014-08-14 to solve a case : unexistant parent found, so product is never exported...
267
+ foreach ($parentIds as $k => $parentId) {
268
+ if (!Mage::getModel('catalog/product')->getCollection()->addStoreFilter($storeId)->addFieldToFilter('entity_id', $parentId)->count()) {
269
+ unset($parentIds[$k]);
270
+ }
271
+ }
272
+ //END FIX
273
+
274
+ if (!empty($parentIds))
275
+ return false;
276
+ }
277
+
278
+
279
+
280
+ $store = Mage::app()->getStore($storeId);
281
+ if (!in_array($store->getWebsiteId(), $product->getWebsiteIds())) {
282
+ return false;
283
+ }
284
+
285
+ return true;
286
+ }
287
+
288
+ protected $_attributes = array();
289
+
290
+ protected function _getAttribute($attributeCode, $storeId = null) {
291
+ if (!isset($this->_attributes[$attributeCode])) {
292
+ $this->_attributes[$attributeCode] = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
293
+ if ($storeId) {
294
+ $this->_attributes[$attributeCode]->setStoreId($storeId);
295
+ }
296
+ }
297
+ return $this->_attributes[$attributeCode];
298
+ }
299
+
300
+ protected function _getAttributeDataForProduct($nameNode, $attributeCode, $product, $storeId = null) {
301
+ $_helper = Mage::helper('catalog/output');
302
+ if(!$attributeCode) {
303
+ return '';
304
+ }
305
+
306
+ $data = $product->getData($attributeCode);
307
+
308
+ $attribute = $this->_getAttribute($attributeCode, $storeId);
309
+ if ($attribute) {
310
+ if ($attribute->getFrontendInput() == 'date') {
311
+ return $data;
312
+ }
313
+
314
+ //$data = $attribute->getFrontend()->getValue($product);
315
+ //$data = $_helper->productAttribute($product, $data, $attributeCode);
316
+ if ($attribute->usesSource()) {
317
+ $data = $attribute->getSource()->getOptionText($data);
318
+ if (is_array($data)) {
319
+ $data = implode(', ', $data);
320
+ }
321
+ //$data = $product->getAttributeText($attributeCode);
322
+ }
323
+
324
+
325
+ if ($attribute->getFrontendInput() == 'weee') {
326
+ $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
327
+ if(isset($data[0]['value'])) {//in case weeeAttributes is empty
328
+ $data = $data[0]['value'];
329
+ }
330
+
331
+ foreach ($weeeAttributes as $wa) {
332
+ if ($wa->getCode() == $attributeCode) {
333
+ $data = round($wa->getAmount(), 2);
334
+ break;
335
+ }
336
+ }
337
+ }
338
+ }
339
+
340
+ //TODO remove this
341
+ if ($data == "No" || $data == "Non")
342
+ $data = "";
343
+
344
+ //Exceptions data
345
+ if ($nameNode == 'shipping_delay' && empty($data))
346
+ $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay', $storeId);
347
+
348
+ if ($nameNode == 'quantity')
349
+ $data = round($data);
350
+
351
+ if(is_array($data)) {
352
+ $data = implode(',', $data);
353
+ }
354
+ return trim($data);
355
+ }
356
+
357
+ protected $_memoryLimit = null;
358
+ protected $_maxExecutionTime = null;
359
+
360
+ protected function _checkMemory() {
361
+ $request = Mage::app()->getRequest();
362
+ if ($request->getControllerName() == 'export_flux' && $request->getActionName() == 'index') {
363
+ if (is_null($this->_memoryLimit)) {
364
+ $memoryLimit = ini_get('memory_limit');
365
+ if (preg_match('%M$%', $memoryLimit)) {
366
+ $memoryLimit = intval($memoryLimit) * 1024 * 1024;
367
+ } else if (preg_match('%G$%', $memoryLimit)) {
368
+ $memoryLimit = intval($memoryLimit) * 1024 * 1024 * 1024;
369
+ } else {
370
+ $memoryLimit = false;
371
+ }
372
+ $this->_memoryLimit = $memoryLimit;
373
+ if(intval(Mage::getStoreConfig('shoppingflux_export/general/execution_time_limit')) > 1) {
374
+ $this->_maxExecutionTime = intval(Mage::getStoreConfig('shoppingflux_export/general/execution_time_limit'));
375
+ } else {
376
+ $this->_maxExecutionTime = (ini_get('max_execution_time')>1)?ini_get('max_execution_time'):600;
377
+ }
378
+ $this->_maxExecutionTime = min($this->_maxExecutionTime, 9 * 60); //There is a 10min timeout on SF side. We took 9 for margin.
379
+
380
+ }
381
+ $isTimeToDie = (microtime(true) - Mage::registry('export_feed_start_at') > $this->_maxExecutionTime);
382
+ if ($this->_memoryLimit > 0 || $isTimeToDie) {
383
+ $currentMemoryUsage = memory_get_usage(true);
384
+ if ($isTimeToDie || $this->_memoryLimit - 15 * 1024 * 1024 <= $currentMemoryUsage) {
385
+ header('Content-type: text/html; charset=UTF-8');
386
+ header('Refresh: 0;');
387
+ $reasons = array();
388
+ if($isTimeToDie) {
389
+ $reasons[] = 'Is Time to die : Execution time : '.(round(microtime(true) - Mage::registry('export_feed_start_at'), 2)).' - Max execution time : ' . $this->_maxExecutionTime;
390
+ }
391
+ if($this->_memoryLimit-10*1024*1024 <= $currentMemoryUsage) {
392
+ $reasons[] = 'Memory limit : Used '.$currentMemoryUsage.' of '.$this->_memoryLimit;
393
+ }
394
+
395
+ die('<html><head><meta http-equiv="refresh" content="0"/></head><body><!--Reason : '.implode(',', $reasons).'--></body></html>');
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+ public function updateProductInFluxForAllStores($productSku) {
402
+ foreach (Mage::app()->getStores() as $store) {
403
+ $storeId = $store->getId();
404
+ $isCurrentStore = (Mage::app()->getStore()->getId() == $storeId);
405
+ try {
406
+ if (!$isCurrentStore) {
407
+ $appEmulation = Mage::getSingleton('core/app_emulation');
408
+ if ($appEmulation) {
409
+ $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
410
+ }
411
+ }
412
+ $this->updateProductInFlux($productSku, $storeId);
413
+ if (!$isCurrentStore && $appEmulation) {
414
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
415
+ }
416
+ } catch (Exception $e) {
417
+ if (!$isCurrentStore && $appEmulation) {
418
+ $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
419
+ }
420
+ }
421
+ }
422
+ }
423
+
424
+ public function updateProductInFlux($productSku, $storeId) {
425
+
426
+ //$this->_checkMemory();
427
+
428
+ $product = $this->_getProductBySku($productSku, $storeId);
429
+
430
+ if (!$product || !$product->getSku()) {
431
+ $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($productSku, $storeId);
432
+ $fluxEntry->setShouldExport(0);
433
+ $fluxEntry->setUpdateNeeded(0);
434
+ $fluxEntry->setUpdatedAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
435
+ $fluxEntry->save();
436
+ return;
437
+ }
438
+
439
+
440
+ if (!$this->_shouldUpdate($product, $storeId)) {
441
+ $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($product->getSku(), $storeId);
442
+ $fluxEntry->setShouldExport(0);
443
+ $fluxEntry->setStockValue($product->getStockItem()->getQty());
444
+ $fluxEntry->setUpdateNeeded(0);
445
+ $fluxEntry->setUpdatedAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
446
+ $fluxEntry->save();
447
+ return;
448
+ }
449
+ //Varien_Profiler::start("SF::Flux::updateProductInFlux");
450
+
451
+ $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
452
+ $xml = '';
453
+
454
+ if ($this->getConfig()->useManageStock()) {
455
+ $_configManageStock = (int) Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId);
456
+ $_manageStock = ($product->getStockItem()->getUseConfigManageStock() ? $_configManageStock : $product->getStockItem()->getManageStock());
457
+ } else {
458
+ $_manageStock = true;
459
+ }
460
+
461
+ $data = array(
462
+ 'id' => $product->getId(),
463
+ 'last-feed-update' => date('Y-m-d H:i:s'),
464
+ 'mage-sku' => $product->getSku(),
465
+ 'product-url' => $this->cleanUrl($product->getProductUrl(false)),
466
+ 'is-in-stock' => $_manageStock ? $product->getStockItem()->getIsInStock() : 1,
467
+ 'salable' => intval($product->isSalable()),
468
+ 'qty' => $product->isSalable() ? ($_manageStock ? round($product->getStockItem()->getQty()) : 100) : 0,
469
+ 'qty-increments' => $this->getConfig()->getTransformQtyIncrements($product) ? 1 : $this->getConfig()->getQtyIncrements($product),
470
+ 'tax-rate' => $product->getTaxPercent(),
471
+ );
472
+
473
+ if ($this->getConfig()->getTransformQtyIncrements($product)) {
474
+ $qtyIncrements = $this->getConfig()->getQtyIncrements($product);
475
+ $data['qty'] = $data['qty'] / $qtyIncrements;
476
+ }
477
+
478
+
479
+ foreach ($this->getConfig()->getMappingAttributes($storeId) as $nameNode => $code) {
480
+ $data[$nameNode] = $this->_getAttributeDataForProduct($nameNode, $code, $product, $storeId); //trim($xmlObj->extractData($nameNode, $code, $product));
481
+ if ($this->getConfig()->getTransformQtyIncrements($product)) {
482
+ $qtyIncrements = $this->getConfig()->getQtyIncrements($product);
483
+ if ($nameNode == 'name') {
484
+ $data[$nameNode] = $data[$nameNode] . Mage::helper('profileolabs_shoppingflux')->__(' - Set of %d', $qtyIncrements);
485
+ } else if ($nameNode == 'sku') {
486
+ $data[$nameNode] = '_SFQI_' . $qtyIncrements . '_' . $data[$nameNode];
487
+ } else if ($nameNode == 'weight') {
488
+ $data[$nameNode] = $qtyIncrements * $data[$nameNode];
489
+ }
490
+ }
491
+ }
492
+
493
+ //Varien_Profiler::start("SF::Flux::getPrices");
494
+ $data = $this->getPrices($data, $product, $storeId);
495
+ //Varien_Profiler::stop("SF::Flux::getPrices");
496
+ //Varien_Profiler::start("SF::Flux::getImages");
497
+ $data = $this->getImages($data, $product, $storeId);
498
+ //Varien_Profiler::stop("SF::Flux::getImages");
499
+ //Varien_Profiler::start("SF::Flux::getCategories");
500
+ $data = $this->getCategories($data, $product, $storeId);
501
+ //Varien_Profiler::stop("SF::Flux::getCategories");
502
+ //Varien_Profiler::start("SF::Flux::getShippingInfo");
503
+ $data = $this->getShippingInfo($data, $product, $storeId);
504
+ //Varien_Profiler::stop("SF::Flux::getShippingInfo");
505
+ if ($this->getConfig()->getManageConfigurables()) {
506
+ //Varien_Profiler::start("SF::Flux::getConfigurableAttributes");
507
+ $data = $this->getConfigurableAttributes($data, $product, $storeId);
508
+ //Varien_Profiler::stop("SF::Flux::getConfigurableAttributes");
509
+ }
510
+ //Varien_Profiler::start("SF::Flux::getAdditionalAttributes");
511
+ foreach ($this->getConfig()->getAdditionalAttributes($storeId) as $attributeCode) {
512
+ $data[$attributeCode] = $this->_getAttributeDataForProduct($attributeCode, $attributeCode, $product, $storeId);
513
+ }
514
+
515
+ //Varien_Profiler::stop("SF::Flux::getAdditionalAttributes");
516
+ //Varien_Profiler::start("SF::Flux::addEntry1");
517
+ if (!isset($data['shipping_delay']) || empty($data['shipping_delay']))
518
+ $data['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
519
+
520
+
521
+ if ($this->getConfig()->getEnableEvents()) {
522
+ $dataObj = new Varien_Object(array('entry' => $data, 'store_id' => $storeId, 'product' => $product));
523
+ Mage::dispatchEvent('shoppingflux_before_update_entry', array('data_obj' => $dataObj));
524
+
525
+ $entry = $dataObj->getEntry();
526
+ } else {
527
+ $entry = $data;
528
+ }
529
+
530
+
531
+ //Varien_Profiler::stop("SF::Flux::addEntry1");
532
+ //Varien_Profiler::start("SF::Flux::addEntry2");
533
+ $xml .= $xmlObj->_addEntry($entry);
534
+ //Varien_Profiler::stop("SF::Flux::addEntry2");
535
+ //Varien_Profiler::start("SF::Flux::saveProductFlux");
536
+ $fluxEntry = Mage::getModel('profileolabs_shoppingflux/export_flux')->getEntry($product->getSku(), $storeId);
537
+ $fluxEntry->setUpdatedAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
538
+ $fluxEntry->setXml($xml);
539
+ $fluxEntry->setUpdateNeeded(0);
540
+ $fluxEntry->setProductId($product->getId());
541
+ $fluxEntry->setStockValue($product->getStockItem()->getQty());
542
+ $fluxEntry->setPriceValue($product->getFinalPrice());
543
+ $fluxEntry->setIsInStock($data['is-in-stock']);
544
+ $fluxEntry->setSalable($product->isSalable());
545
+ $fluxEntry->setIsInFlux(intval($product->getData('shoppingflux_product')));
546
+ $fluxEntry->setType($product->getTypeId());
547
+ $fluxEntry->setVisibility($product->getVisibility());
548
+ $fluxEntry->setShouldExport(1);
549
+ $fluxEntry->save();
550
+ // Faster
551
+ /*
552
+ $tableName = Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux');
553
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
554
+ $request = "INSERT INTO " . $tableName . " (sku, store_id, updated_at, xml, update_needed, is_in_stock, is_in_flux, type, visibility, should_export) VALUES ";
555
+ $request .= "(" . $write->quote($product->getSku()) . ", " . $write->quote($storeId) . ", " . $write->quote(date('Y-m-d H:i:s')) . ", " . $write->quote($xml) . ", '0', " . $write->quote($data['is-in-stock']) . ", " . $write->quote($product->getData('shoppingflux_product')) . ", '" . $product->getTypeId() . "', '" . $product->getVisibility() . "', '1')";
556
+ $request .= " on duplicate key update updated_at = VALUES(updated_at), xml = VALUES(xml), update_needed = VALUES(update_needed), is_in_stock = VALUES(is_in_stock), is_in_flux = VALUES(is_in_flux), type = VALUES(type), visibility = VALUES(visibility), should_export = VALUES(should_export) ";
557
+ $write->query($request);
558
+ */
559
+ //Varien_Profiler::stop("SF::Flux::saveProductFlux");
560
+ //Varien_Profiler::stop("SF::Flux::updateProductInFlux");
561
+ }
562
+
563
+ /**
564
+ * Get prices of product
565
+ * @param Mage_Catalog_Model_Product $product
566
+ * @return string $nodes
567
+ */
568
+ protected function getPrices($data, $product, $storeId) {
569
+
570
+ $priceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/attributes_mapping/price', $storeId);
571
+ $specialPriceAttributeCode = $this->getConfig()->getConfigData('shoppingflux_export/attributes_mapping/special_price', $storeId);
572
+ if (!$product->getData($priceAttributeCode)) {
573
+ $priceAttributeCode = 'price';
574
+ $specialPriceAttributeCode = 'special_price';
575
+ }
576
+
577
+ $discountAmount = 0;
578
+ $finalPrice = $product->getData($priceAttributeCode);
579
+ $priceBeforeDiscount = $product->getData($priceAttributeCode);
580
+ if ($product->getData($specialPriceAttributeCode) > 0 && $product->getData($specialPriceAttributeCode) < $finalPrice) {
581
+ $finalPrice = $product->getData($specialPriceAttributeCode);
582
+ $discountAmount = $priceBeforeDiscount - $finalPrice;
583
+ }
584
+ $discountFromDate = $product->getSpecialFromDate();
585
+ $discountToDate = $product->getSpecialToDate();
586
+
587
+
588
+ $product->setCalculatedFinalPrice($finalPrice);
589
+ $product->setData('final_price', $finalPrice);
590
+ $currentVersion = Mage::getVersion();
591
+ if (version_compare($currentVersion, '1.5.0') < 0) {
592
+ if ($this->getConfig()->getManageCatalogRules()) {
593
+ Mage::dispatchEvent('catalog_product_get_final_price', array('product'=>$product));
594
+ $finalPrice = $product->getFinalPrice();
595
+ $discountAmount = $priceBeforeDiscount - $finalPrice;
596
+ $discountFromDate = '';
597
+ $discountToDate = '';
598
+ }
599
+ } else {
600
+ if ($this->getConfig()->getManageCatalogRules()) {
601
+ $catalogPriceRulePrice = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product, $product->getPrice());
602
+ if ($catalogPriceRulePrice > 0 && $catalogPriceRulePrice < $finalPrice) {
603
+ $finalPrice = $catalogPriceRulePrice;
604
+ $discountAmount = $priceBeforeDiscount - $catalogPriceRulePrice;
605
+ $discountFromDate = '';
606
+ $discountToDate = '';
607
+ }
608
+ }
609
+ }
610
+
611
+ if ($this->getConfig()->getTransformQtyIncrements($product)) {
612
+ $qtyIncrements = $this->getConfig()->getQtyIncrements($product);
613
+ $finalPrice *= $qtyIncrements;
614
+ $priceBeforeDiscount *= $qtyIncrements;
615
+ }
616
+
617
+ $data["price-ttc"] = Mage::helper('tax')->getPrice($product, $finalPrice, true); //$finalPrice;
618
+ $data["price-before-discount"] = Mage::helper('tax')->getPrice($product, $priceBeforeDiscount, true); //$priceBeforeDiscount;
619
+ $data["discount-amount"] = $product->getTypeId() != 'bundle' ? $discountAmount : 0;
620
+ $data["discount-percent"] = $this->getPercent($product);
621
+
622
+ $data["start-date-discount"] = "";
623
+ $data["end-date-discount"] = "";
624
+ if ($discountFromDate) {
625
+ $data["start-date-discount"] = $discountFromDate;
626
+ }
627
+ if ($discountToDate) {
628
+ $data["end-date-discount"] = $discountToDate;
629
+ }
630
+ unset($data['price']);
631
+ unset($data['special_price']);
632
+ return $data;
633
+ }
634
+
635
+ /**
636
+ * Get categories of product
637
+ * @param Mage_Catalog_Model_Product $product
638
+ * @return string $nodes
639
+ */
640
+ protected function getCategories($data, $product, $storeId) {
641
+ if ($product->getData('shoppingflux_default_category') && $product->getData('shoppingflux_default_category') > 0) {
642
+ $data = $this->getCategoriesViaShoppingfluxCategory($data, $product);
643
+ } else {
644
+ $data = $this->getCategoriesViaProductCategories($data, $product);
645
+ }
646
+ if(!$data['category-breadcrumb']) {
647
+ $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
648
+ $parentIds = array_merge($parentIds, Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId()));
649
+ $parentIds = array_merge($parentIds, Mage::getModel('bundle/product_type')->getParentIdsByChild($product->getId()));
650
+ $parentIds = array_unique($parentIds);
651
+ foreach ($parentIds as $parentId) {
652
+ if(!$data['category-breadcrumb']) {
653
+ $parentProduct = $this->_getProduct($parentId, $storeId);
654
+ if($parentProduct && is_object($parentProduct) && $parentProduct->getId()) {
655
+ $data = $this->getCategories($data, $parentProduct, $storeId);
656
+ }
657
+ }
658
+
659
+ }
660
+ }
661
+ return $data;
662
+ }
663
+
664
+ protected function getCategoriesViaShoppingfluxCategory($data, $product) {
665
+
666
+ //Varien_Profiler::start("SF::Flux::getCategoriesViaShoppingfluxCategory-1");
667
+ $categoryId = $product->getData('shoppingflux_default_category');
668
+ if (!$categoryId) {
669
+ $categoryId = $product->getData('main_category');//Compatibility with Webcooking_MainCategory
670
+ if (!$categoryId) {
671
+ return $this->getCategoriesViaProductCategories($data, $product);
672
+ }
673
+ }
674
+ $category = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents(false, $product->getStoreId());
675
+ //Varien_Profiler::stop("SF::Flux::getCategoriesViaShoppingfluxCategory-1");
676
+ if (!isset($category['name'][$categoryId])) {
677
+ return $this->getCategoriesViaProductCategories($data, $product);
678
+ }
679
+
680
+ //Varien_Profiler::start("SF::Flux::getCategoriesViaShoppingfluxCategory");
681
+
682
+ $categoryNames = explode(' > ', $category['name'][$categoryId]);
683
+ $categoryMetaTitles = explode(' > ', $category['meta_title'][$categoryId]);
684
+ $categoryMetaDescriptions = explode(' > ', $category['meta_description'][$categoryId]);
685
+ $categoryMetaKeywords = explode(' > ', $category['meta_keywords'][$categoryId]);
686
+ $categoryUrls = explode(' > ', $category['url'][$categoryId]);
687
+
688
+
689
+ //we drop root category, which is useless here
690
+ array_shift($categoryNames);
691
+ array_shift($categoryMetaTitles);
692
+ array_shift($categoryMetaDescriptions);
693
+ array_shift($categoryMetaKeywords);
694
+ array_shift($categoryUrls);
695
+
696
+
697
+ $data['category-breadcrumb'] = trim(implode(' > ', $categoryNames));
698
+
699
+ $data["category-main"] = isset($categoryNames[0]) ? trim($categoryNames[0]) : '';
700
+ $data["category-url-main"] = isset($categoryUrls[0]) ? $categoryUrls[0] : '';
701
+ $data["category-metatitle-main"] = isset($categoryMetaTitles[0]) ? $categoryMetaTitles[0] : '';
702
+ $data["category-metadescription-main"] = isset($categoryMetaDescriptions[0]) ? $categoryMetaDescriptions[0] : '';
703
+ $data["category-metakeywords-main"] = isset($categoryMetaKeywords[0]) ? $categoryMetaKeywords[0] : '';
704
+
705
+
706
+ for ($i = 1; $i <= 5; $i++) {
707
+ if (isset($categoryNames[$i])) {
708
+ $data["category-sub-" . ($i)] = trim($categoryNames[$i]);
709
+ } else {
710
+ $data["category-sub-" . ($i)] = '';
711
+ }
712
+ if (isset($categoryUrls[$i])) {
713
+ $data["category-url-sub-" . ($i)] = $categoryUrls[$i];
714
+ } else {
715
+ $data["category-url-sub-" . ($i)] = '';
716
+ }
717
+ if (isset($categoryMetaTitles[$i])) {
718
+ $data["category-metatitle-sub-" . ($i)] = $categoryMetaTitles[$i];
719
+ } else {
720
+ $data["category-metatitle-sub-" . ($i)] = '';
721
+ }
722
+ if (isset($categoryMetaDescriptions[$i])) {
723
+ $data["category-metadescription-sub-" . ($i)] = $categoryMetaDescriptions[$i];
724
+ } else {
725
+ $data["category-metadescription-sub-" . ($i)] = '';
726
+ }
727
+ if (isset($categoryMetaKeywords[$i])) {
728
+ $data["category-metakeywords-sub-" . ($i)] = $categoryMetaKeywords[$i];
729
+ } else {
730
+ $data["category-metakeywords-sub-" . ($i)] = '';
731
+ }
732
+ }
733
+
734
+ //Varien_Profiler::stop("SF::Flux::getCategoriesViaShoppingfluxCategory");
735
+ return $data;
736
+ }
737
+
738
+ protected function getCategoriesViaProductCategories($data, $product) {
739
+
740
+ //Varien_Profiler::start("SF::Flux::getCategoriesViaProductCategories");
741
+ $cnt = 0;
742
+
743
+ if (!$this->getConfig()->getUseOnlySFCategory()) {
744
+ $rootCategoryId = Mage::app()->getStore($product->getStoreId())->getRootCategoryId();
745
+
746
+ $categoryWithParents = Mage::helper('profileolabs_shoppingflux')->getCategoriesWithParents(false, $product->getStoreId(), false, false);
747
+ $maxLevelCategory = $this->getConfig()->getMaxCategoryLevel() > 0 ? $this->getConfig()->getMaxCategoryLevel() : 5;
748
+
749
+
750
+ //Selection of the deepest category
751
+ $productCategoryIds = $product->getCategoryIds();
752
+ $choosenProductCategoryId = false;
753
+ $choosenCategoryLevel = 0;
754
+ foreach ($productCategoryIds as $productCategoryId) {
755
+ if (isset($categoryWithParents['name'][$productCategoryId])) {
756
+ $categoryNames = explode(' > ', $categoryWithParents['name'][$productCategoryId]);
757
+ if (count($categoryNames) > $choosenCategoryLevel) {
758
+ $choosenProductCategoryId = $productCategoryId;
759
+ }
760
+ }
761
+ }
762
+
763
+ //Adding the deepest category to breadcrumb
764
+ if ($choosenProductCategoryId) {
765
+ $categoryNames = explode(' > ', $categoryWithParents['name'][$choosenProductCategoryId]);
766
+ $categoryMetaTitles = explode(' > ', $categoryWithParents['meta_title'][$choosenProductCategoryId]);
767
+ $categoryMetaDescriptions = explode(' > ', $categoryWithParents['meta_description'][$choosenProductCategoryId]);
768
+ $categoryMetaKeywords = explode(' > ', $categoryWithParents['meta_keywords'][$choosenProductCategoryId]);
769
+ $categoryUrls = explode(' > ', $categoryWithParents['url'][$choosenProductCategoryId]);
770
+ //we drop root category, which is useless here
771
+ array_shift($categoryNames);
772
+ array_shift($categoryMetaTitles);
773
+ array_shift($categoryMetaDescriptions);
774
+ array_shift($categoryMetaKeywords);
775
+ array_shift($categoryUrls);
776
+ $categoryNames = array_slice($categoryNames, 0, $maxLevelCategory, true);
777
+ $categoryUrls = array_slice($categoryUrls, 0, $maxLevelCategory, true);
778
+ $data['category-breadcrumb'] = trim(implode(' > ', $categoryNames));
779
+
780
+ $data["category-main"] = trim($categoryNames[0]);
781
+ $data["category-url-main"] = $categoryUrls[0];
782
+ $data["category-metatitle-main"] = $categoryMetaTitles[0];
783
+ $data["category-metadescription-main"] = $categoryMetaDescriptions[0];
784
+ $data["category-metakeywords-main"] = $categoryMetaKeywords[0];
785
+
786
+
787
+ for ($i = 1; $i <= 5; $i++) {
788
+ if (isset($categoryNames[$i])) {
789
+ $data["category-sub-" . ($i)] = trim($categoryNames[$i]);
790
+ } else {
791
+ $data["category-sub-" . ($i)] = '';
792
+ }
793
+ if (isset($categoryUrls[$i])) {
794
+ $data["category-url-sub-" . ($i)] = $categoryUrls[$i];
795
+ } else {
796
+ $data["category-url-sub-" . ($i)] = '';
797
+ }
798
+ if (isset($categoryMetaTitles[$i])) {
799
+ $data["category-metatitle-sub-" . ($i)] = $categoryMetaTitles[$i];
800
+ } else {
801
+ $data["category-metatitle-sub-" . ($i)] = '';
802
+ }
803
+ if (isset($categoryMetaDescriptions[$i])) {
804
+ $data["category-metadescription-sub-" . ($i)] = $categoryMetaDescriptions[$i];
805
+ } else {
806
+ $data["category-metadescription-sub-" . ($i)] = '';
807
+ }
808
+ if (isset($categoryMetaKeywords[$i])) {
809
+ $data["category-metakeywords-sub-" . ($i)] = $categoryMetaKeywords[$i];
810
+ } else {
811
+ $data["category-metakeywords-sub-" . ($i)] = '';
812
+ }
813
+ }
814
+ }
815
+ }
816
+
817
+ if (!isset($data["category-main"])) {
818
+ $data["category-breadcrumb"] = "";
819
+ $data["category-main"] = "";
820
+ $data["category-url-main"] = "";
821
+ $cnt++;
822
+ }
823
+
824
+
825
+ for ($i = 1; $i <= 5; $i++) {
826
+ if (!isset($data["category-sub-" . ($i)])) {
827
+ $data["category-sub-" . ($i)] = "";
828
+ $data["category-url-sub-" . ($i)] = "";
829
+ }
830
+ }
831
+
832
+
833
+ //Varien_Profiler::stop("SF::Flux::getCategoriesViaProductCategories");
834
+ return $data;
835
+ }
836
+
837
+ public function cleanUrl($url) {
838
+ $url = str_replace("index.php/", "", $url);
839
+ $url = preg_replace('%(.*)\?.*$%i', '$1', $url);
840
+ return $url;
841
+ }
842
+
843
+ public function getImages($data, $product, $storeId, $checkParentIfNone = true) {
844
+
845
+
846
+
847
+ $mediaUrl = Mage::getBaseUrl('media') . 'catalog/product';
848
+ $i = 1;
849
+ $count = $this->getConfig()->getExportedImageCount();
850
+
851
+ if ($product->getImage() != "" && $product->getImage() != 'no_selection') {
852
+ $data["image-url-" . $i] = $mediaUrl . $product->getImage();
853
+ $data["image-label-" . $i] = $product->getImageLabel();
854
+ $i++;
855
+ }
856
+
857
+
858
+ if ($this->getConfig()->getManageMediaGallery()) {
859
+ //LOAD media gallery for this product
860
+ $mediaGallery = $product->getResource()->getAttribute('media_gallery');
861
+ $mediaGallery->getBackend()->afterLoad($product);
862
+
863
+
864
+ foreach ($product->getMediaGallery('images') as $image) {
865
+ if ($mediaUrl . $product->getImage() == $product->getMediaConfig()->getMediaUrl($image['file']))
866
+ continue;
867
+ if($image['disabled'])
868
+ continue;
869
+
870
+ $data["image-url-" . $i] = $product->getMediaConfig()->getMediaUrl($image['file']);
871
+ $data["image-label-" . $i] = $image['label'];
872
+
873
+ if (($count !== false) && ($i++ >= $count)) {
874
+ break;
875
+ }
876
+ }
877
+ }
878
+
879
+ if ((!isset($data['image-url-1']) || !$data['image-url-1']) && $checkParentIfNone) {
880
+ $groupedParentsIds = Mage::getResourceSingleton('catalog/product_link')
881
+ ->getParentIdsByChild($product->getId(), Mage_Catalog_Model_Product_Link::LINK_TYPE_GROUPED);
882
+ $parentId = current($groupedParentsIds);
883
+ $parentProduct = $this->_getProduct($parentId, $storeId);
884
+ if($parentProduct && $parentProduct->getId()) {
885
+ return $this->getImages($data, $parentProduct, $storeId, false);
886
+ }
887
+ }
888
+
889
+
890
+ return $data;
891
+ }
892
+
893
+ protected function getPercent($product) {
894
+
895
+ /* if($product->getTypeId() == 'bundle')
896
+ return 0; */
897
+ $price = round($product->getPrice(), 2);
898
+ if ($price == "0") {
899
+ $price = round($product->getMinimalPrice(), 2);
900
+ }
901
+
902
+ if ($price == "0")
903
+ return 0;
904
+
905
+ $special = round($product->getFinalPrice(), 2);
906
+ $tmp = $price - $special;
907
+ $tmp = ($tmp * 100) / $price;
908
+ return round($tmp);
909
+ }
910
+
911
+ /**
912
+ *
913
+ */
914
+ protected function getAttributesFromConfig($checkIfExist = false, $withAdditional = true, $storeId = null) {
915
+
916
+ if (!isset($this->_attributesFromConfig[$storeId])) {
917
+ $this->_attributesFromConfig[$storeId] = array();
918
+ $attributes = $this->getConfig()->getMappingAttributes($storeId);
919
+ if ($withAdditional) {
920
+ $additionalAttributes = $this->getConfig()->getAdditionalAttributes($storeId);
921
+ foreach ($additionalAttributes as $attributeCode) {
922
+ $attributes[$attributeCode] = trim($attributeCode);
923
+ }
924
+ }
925
+
926
+ if ($checkIfExist) {
927
+ $product = Mage::getModel('catalog/product');
928
+ foreach ($attributes as $key => $code) {
929
+ $attribute = $this->_getAttribute($code);
930
+ if ($attribute instanceof Mage_Catalog_Model_Resource_Eav_Attribute && $attribute->getId() && $attribute->getFrontendInput() != 'weee') {
931
+ $this->_attributesFromConfig[$storeId][$key] = $code;
932
+ }
933
+ }
934
+ } else {
935
+ $this->_attributesFromConfig[$storeId] = $attributes;
936
+ }
937
+ }
938
+
939
+ return $this->_attributesFromConfig[$storeId];
940
+ }
941
+
942
+ protected function getRequiredAttributes() {
943
+
944
+ $requiredAttributes = array("sku" => "sku",
945
+ "price" => "price",
946
+ "image" => "image");
947
+
948
+ return $requiredAttributes;
949
+ }
950
+
951
+ /**
952
+ *
953
+ * @deprecated
954
+ */
955
+ protected function getAllAttributes() {
956
+ return array_merge($this->getAttributesFromConfig(true), $this->getRequiredAttributes());
957
+ }
958
+
959
+ /**
960
+ * Retrieve Catalog Product Flat Helper object
961
+ *
962
+ * @return Mage_Catalog_Helper_Product_Flat
963
+ */
964
+ public function getFlatHelper() {
965
+ return Mage::helper('catalog/product_flat');
966
+ }
967
+
968
+ protected function getShippingInfo($data, $product, $storeId) {
969
+
970
+ $data["shipping-name"] = "";
971
+ $data["shipping-price"] = "";
972
+
973
+ $carrier = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_method');
974
+ if (empty($carrier)) {
975
+ $data["shipping-price"] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
976
+ return $data;
977
+ }
978
+
979
+ $carrierTab = explode('_', $carrier);
980
+ list($carrierCode, $methodCode) = $carrierTab;
981
+ $data["shipping-name"] = ucfirst($methodCode);
982
+
983
+
984
+ $shippingPrice = 0;
985
+ if ($this->getConfig()->getConfigData('shoppingflux_export/general/try_use_real_shipping_price')) {
986
+ $countryCode = $this->getConfig()->getConfigData('shoppingflux_export/general/shipping_price_based_on');
987
+ $shippingPrice = Mage::helper('profileolabs_shoppingflux')->getShippingPrice($product, $carrier, $countryCode);
988
+ }
989
+
990
+ if (!$shippingPrice) {
991
+ $shippingPrice = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_price');
992
+ }
993
+
994
+ $data["shipping-price"] = $shippingPrice;
995
+
996
+ return $data;
997
+ }
998
+
999
+ protected function getConfigurableAttributes($data, $product, $storeId) {
1000
+
1001
+ $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
1002
+ $data["configurable_attributes"] = "";
1003
+ $data["childs_product"] = "";
1004
+ $images = array();
1005
+
1006
+ $labels = array();
1007
+ if ($product->getTypeId() == "configurable") {
1008
+
1009
+ $attributes = Mage::helper('profileolabs_shoppingflux')->getAttributesConfigurable($product);
1010
+
1011
+ $attributesToOptions = array();
1012
+
1013
+ foreach ($attributes as $attribute) {
1014
+ $attributesToOptions[$attribute['attribute_code']] = array();
1015
+ }
1016
+
1017
+ $usedProducts = $product->getTypeInstance(true)
1018
+ ->getUsedProductCollection($product);
1019
+
1020
+
1021
+ $configurableAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
1022
+
1023
+
1024
+ $usedProductsArray = array();
1025
+ $salable = false;
1026
+ foreach (Mage::getSingleton('core/resource')->getConnection('core_read')->fetchAll($usedProducts->getSelect()) as $usedProduct) { //Prevent Old magento bug
1027
+ $usedProduct = $this->_getProduct($usedProduct['entity_id'], $storeId);
1028
+
1029
+ if (!$usedProduct) {
1030
+ continue;
1031
+ }
1032
+ if ($usedProduct->getStatus() == 2) {
1033
+ continue;
1034
+ }
1035
+
1036
+ $salable = $salable || $usedProduct->isSalable();
1037
+
1038
+
1039
+ if (Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('OrganicInternet_SimpleConfigurableProducts') || Mage::helper('profileolabs_shoppingflux')->isModuleInstalled('DerModPro_BCP')) {
1040
+
1041
+ $tmpData = $this->getPrices(array(), $usedProduct, $storeId);
1042
+ $price = $tmpData['price-ttc'] > 0 ? $tmpData['price-ttc'] : $data['price-ttc'];
1043
+ if ($data['price-ttc'] <= 0 || ($price > 0 && $price < $data['price-ttc'])) {
1044
+ $data['price-ttc'] = $price;
1045
+ }
1046
+ $priceBeforeDiscount = $tmpData["price-before-discount"];
1047
+ $discountAmount = $tmpData["discount-amount"];
1048
+ $startDateDiscount = $tmpData["start-date-discount"];
1049
+ $endDateDiscount = $tmpData["end-date-discount"];
1050
+ } else {
1051
+
1052
+ $price = $data['price-ttc'];
1053
+ $priceBeforeDiscount = $data["price-before-discount"];
1054
+ $discountAmount = $data["discount-amount"];
1055
+ $startDateDiscount = $data["start-date-discount"];
1056
+ $endDateDiscount = $data["end-date-discount"];
1057
+
1058
+ foreach ($configurableAttributes as $configurableAttribute) {
1059
+ $attributeCode = $configurableAttribute['attribute_code'];
1060
+ foreach ($configurableAttribute['values'] as $confAttributeValue) {
1061
+ if ($confAttributeValue['pricing_value'] && $usedProduct->getData($attributeCode) == $confAttributeValue['value_index']) {
1062
+ if ($confAttributeValue['is_percent']) {
1063
+ $price += $data['price-ttc'] * $confAttributeValue['pricing_value'] / 100;
1064
+ $priceBeforeDiscount += $data['price-before-discount'] * $confAttributeValue['pricing_value'] / 100;
1065
+ } else {
1066
+ $price += $confAttributeValue['pricing_value'];
1067
+ $priceBeforeDiscount += $confAttributeValue['pricing_value'];
1068
+ }
1069
+ }
1070
+ }
1071
+ }
1072
+ }
1073
+
1074
+ $attributesFromConfig = $this->getAttributesFromConfig(true, true, $storeId);
1075
+
1076
+ $discountPercent = 0;
1077
+ if ($priceBeforeDiscount) {
1078
+ $discountPercent = round((($priceBeforeDiscount - $price) * 100) / $priceBeforeDiscount);
1079
+ }
1080
+
1081
+ $isInStock = 0;
1082
+ $qty = 0;
1083
+ if ($usedProduct->getStockItem()) {
1084
+ if ($this->getConfig()->useManageStock()) {
1085
+ $_configManageStock = (int) Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId);
1086
+ $_manageStock = $usedProduct->getStockItem()->getUseConfigManageStock() ? $_configManageStock : $usedProduct->getStockItem()->getManageStock();
1087
+ } else {
1088
+ $_manageStock = true;
1089
+ }
1090
+
1091
+ $isInStock = $_manageStock ? $usedProduct->getStockItem()->getIsInStock() : 1;
1092
+
1093
+ if ($usedProduct->isSalable()) {
1094
+ $qty = $_manageStock ? $usedProduct->getStockItem()->getQty() : 100;
1095
+ } else {
1096
+ $qty = 0;
1097
+ }
1098
+ }
1099
+
1100
+ $usedProductsArray[$usedProduct->getId()]['child']["sku"] = $usedProduct->getSku();
1101
+ $usedProductsArray[$usedProduct->getId()]['child']["id"] = $usedProduct->getId();
1102
+ $usedProductsArray[$usedProduct->getId()]['child']["child-url"] = $this->cleanUrl($usedProduct->getProductUrl(false));
1103
+ $usedProductsArray[$usedProduct->getId()]['child']["price-ttc"] = $price;
1104
+ $usedProductsArray[$usedProduct->getId()]['child']["price-before-discount"] = $priceBeforeDiscount;
1105
+ $usedProductsArray[$usedProduct->getId()]['child']["discount-amount"] = $discountAmount;
1106
+ $usedProductsArray[$usedProduct->getId()]['child']["discount-percent"] = $discountPercent;
1107
+ $usedProductsArray[$usedProduct->getId()]['child']["start-date-discount"] = $startDateDiscount;
1108
+ $usedProductsArray[$usedProduct->getId()]['child']["end-date-discount"] = $endDateDiscount;
1109
+ $usedProductsArray[$usedProduct->getId()]['child']['is-in-stock'] = $isInStock;
1110
+ $usedProductsArray[$usedProduct->getId()]['child']['qty'] = round($qty);
1111
+ $usedProductsArray[$usedProduct->getId()]['child']['tax-rate'] = $usedProduct->getTaxPercent();
1112
+ if (!$data['tax-rate'] && $usedProductsArray[$usedProduct->getId()]['child']['tax-rate']) {
1113
+ $data['tax-rate'] = $usedProductsArray[$usedProduct->getId()]['child']['tax-rate'];
1114
+ }
1115
+ if ($qty > 0 && $qty > $data['qty']) {
1116
+ $data['qty'] = round($qty);
1117
+ }
1118
+ $usedProductsArray[$usedProduct->getId()]['child']["ean"] = isset($attributesFromConfig['ean']) ? $usedProduct->getData($attributesFromConfig['ean']) : '';
1119
+
1120
+ $images = $this->getImages($images, $usedProduct, $storeId, false);
1121
+ if (!$images['image-url-1']) {
1122
+ $images = $this->getImages($images, $product, $storeId);
1123
+ }
1124
+ foreach ($images as $key => $value) {
1125
+ $usedProductsArray[$usedProduct->getId()]['child'][$key] = trim($value);
1126
+ }
1127
+
1128
+ foreach ($attributesFromConfig as $nameNode => $attributeCode) {
1129
+ if($attributeCode) {
1130
+ $usedProductsArray[$usedProduct->getId()]['child'][$nameNode] = $this->_getAttributeDataForProduct($nameNode, $attributeCode, $usedProduct, $storeId); //$xmlObj->extractData($nameNode, $attributeCode, $usedProduct);
1131
+ }
1132
+ }
1133
+
1134
+
1135
+ $attributes = Mage::helper('profileolabs_shoppingflux')->getAttributesConfigurable($product);
1136
+ foreach ($attributes as $attribute) {
1137
+ $attributeCode = $attribute['attribute_code'];
1138
+ $attributeId = $attribute['attribute_id'];
1139
+
1140
+ if (!isset($this->_attributesConfigurable[$attributeId]))
1141
+ $this->_attributesConfigurable[$attributeId] = $product->getResource()->getAttribute($attributeId);
1142
+
1143
+ $attributeModel = $this->_attributesConfigurable[$attributeId];
1144
+
1145
+ $value = '';
1146
+ if ($usedProduct->getData($attributeCode)) {
1147
+ $value = $attributeModel->getFrontend()->getValue($usedProduct);
1148
+ }
1149
+
1150
+ if (!isset($attributesToOptions[$attributeCode]) || !in_array($value, $attributesToOptions[$attributeCode]))
1151
+ $attributesToOptions[$attributeCode][] = $value;
1152
+
1153
+ $usedProductsArray[$usedProduct->getId()]['child'][$attributeCode] = trim($value);
1154
+ }
1155
+
1156
+
1157
+ if (!isset($usedProductsArray[$usedProduct->getId()]['child']['shipping_delay']) || !$usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'])
1158
+ $usedProductsArray[$usedProduct->getId()]['child']['shipping_delay'] = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
1159
+
1160
+ unset($usedProductsArray[$usedProduct->getId()]['child']['price']);
1161
+ unset($usedProductsArray[$usedProduct->getId()]['child']['special_price']);
1162
+ }
1163
+
1164
+
1165
+
1166
+
1167
+ $data['is-in-stock'] = (int) $salable;
1168
+
1169
+ foreach ($attributesToOptions as $attributeCode => $value) {
1170
+
1171
+ $data["configurable_attributes"][$attributeCode] = implode(",", $value);
1172
+ }
1173
+ $data["childs_product"] = $usedProductsArray;
1174
+
1175
+ unset($usedProducts);
1176
+ unset($usedProductsArray);
1177
+ }
1178
+ return $data;
1179
+ }
1180
+
1181
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Observer.php CHANGED
@@ -1,444 +1,715 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait, vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Export_Observer {
10
-
11
- public function getConfig() {
12
- return Mage::getSingleton('profileolabs_shoppingflux/config');
13
- }
14
-
15
- public function catalogruleAfterApply($observer) {
16
- return; //Disabled because it invalidate all the feed at each product / inventory save...
17
- if(!$this->getConfig()->getManageCatalogRules()) {
18
- return;
19
- }
20
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
21
- $write->beginTransaction();
22
- try {
23
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 ";
24
- $write->query($query);
25
- $write->commit();
26
- } catch (Exception $e) {
27
- $write->rollback();
28
- }
29
- }
30
-
31
-
32
- public static function checkStock($storeId = false) {
33
- if(!$storeId || !is_numeric($storeId)) {
34
- $storeId = Mage::app()->getStore()->getId();
35
- }
36
- $productCollection = Mage::getModel('catalog/product')->getCollection();
37
- $productCollection->getSelect()->join(
38
- array('sf_stock' => $productCollection->getTable('cataloginventory/stock_item')), 'e.entity_id = sf_stock.product_id', array('qty', 'actual_qty'=>'qty')
39
- );
40
- $productCollection->getSelect()->join(
41
- array('flux' => $productCollection->getTable('profileolabs_shoppingflux/export_flux')), "e.entity_id = flux.product_id and flux.store_id = '".$storeId."'", array('stock_value', 'sku')
42
- );
43
- $productCollection->getSelect()->where('CAST(sf_stock.qty AS SIGNED) != flux.stock_value');
44
- if (Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId)) {
45
- $productCollection->getSelect()->where('(sf_stock.use_config_manage_stock = 0 and sf_stock.manage_stock = 1) OR (sf_stock.use_config_manage_stock = 1)');
46
- } else {
47
- $productCollection->getSelect()->where('(sf_stock.use_config_manage_stock = 0 and sf_stock.manage_stock = 1)');
48
- }
49
- $productCollection->getSelect()->where('flux.update_needed = 0');
50
- $productCollection->getSelect()->group('e.entity_id');
51
- foreach($productCollection as $product) {
52
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($product);
53
- }
54
- }
55
-
56
-
57
-
58
- public function updateFlux() {
59
- if(Mage::getStoreConfigFlag('shoppingflux_export/general/enable_cron')) {
60
- foreach(Mage::app()->getStores() as $store) {
61
- $feedUrl = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store);
62
- if($feedUrl) {
63
- file_get_contents($feedUrl);
64
- }
65
- }
66
- }
67
- }
68
-
69
-
70
- protected function generateFluxInFileForStore($storeId) {
71
- $filePath = Mage::getBaseDir('media') . DS . 'shoppingflux_'.$storeId.'.xml';
72
- $handle = fopen($filePath, 'a');
73
- ftruncate($handle, 0);
74
-
75
- //Mage::getModel('profileolabs_shoppingflux/export_flux')->updateFlux($storeId, 1000000);
76
- $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
77
- $collection->addFieldToFilter('should_export', 1);
78
- $collection->addFieldToFilter('store_id', $storeId);
79
- $sizeTotal = $collection->count();
80
- $collection->clear();
81
-
82
- if (!$this->getConfig()->isExportNotSalable($storeId)) {
83
- $collection->addFieldToFilter('salable', 1);
84
- }
85
- if (!$this->getConfig()->isExportSoldout($storeId)) {
86
- $collection->addFieldToFilter('is_in_stock', 1);
87
- }
88
- if ($this->getConfig()->isExportFilteredByAttribute($storeId)) {
89
- $collection->addFieldToFilter('is_in_flux', 1);
90
- }
91
- $visibilities = $this->getConfig()->getVisibilitiesToExport($storeId);
92
- $collection->getSelect()->where("find_in_set(visibility, '" . implode(',', $visibilities) . "')");
93
-
94
-
95
-
96
- $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
97
- $startXml = $xmlObj->startXml(array('size-exportable' => $sizeTotal, 'size-xml' => $collection->count(), 'with-out-of-stock' => intval($this->getConfig()->isExportSoldout()), 'with-not-salable'=> intval($this->getConfig()->isExportNotSalable()), 'selected-only' => intval($this->getConfig()->isExportFilteredByAttribute()), 'visibilities' => implode(',', $visibilities)));
98
- fwrite($handle, $startXml);
99
- Mage::getSingleton('core/resource_iterator')
100
- ->walk($collection->getSelect(), array(array($this, 'saveProductXml')), array('handle'=>$handle));
101
- $endXml = $xmlObj->endXml();
102
- fwrite($handle, $endXml);
103
- fclose($handle);
104
- }
105
-
106
- public function saveProductXml($args) {
107
- fwrite($args['handle'], $args['row']['xml']);
108
- }
109
-
110
- public function generateFluxInFile() {
111
- //foreach(Mage::app()->getStores() as $store) {
112
- // $this->generateFluxInFileForStore($store->getId());
113
- //}
114
- $this->generateFluxInFileForStore(Mage::app()->getDefaultStoreView()->getId());
115
- }
116
-
117
-
118
- /**
119
- * Add shoppingflux product tab in category edit page
120
- * @param $observer
121
- */
122
- public function addShoppingfluxProductsTab($observer) {
123
- $tabs = $observer->getTabs();
124
- $tabs->addTab('shoppingflux_products', array(
125
- 'label' => Mage::helper('catalog')->__('Shoppingflux Category Products'),
126
- 'content' => $tabs->getLayout()->createBlock(
127
- 'profileolabs_shoppingflux/export_adminhtml_catalog_category_tab_default', 'shoppingflux.product.grid'
128
- )->toHtml(),
129
- ));
130
- }
131
-
132
- public function catalogProductAttributeUpdateBefore($observer) {
133
- $productIds = $observer->getEvent()->getProductIds();
134
- foreach ($productIds as $productId) {
135
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($productId);
136
- }
137
- }
138
-
139
- public function catalogProductSaveCommitAfter($observer) {
140
- $product = $observer->getEvent()->getProduct();
141
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($product->getId());
142
- }
143
-
144
- /**
145
- * update default category for selected products
146
- */
147
- public function saveShoppingfluxCategoryProducts($observer) {
148
- $category = $observer->getEvent()->getCategory();
149
- $request = $observer->getEvent()->getRequest();
150
- $postedProducts = $request->getParam('shoppingflux_category_products');
151
- $products = array();
152
- $storeId = intval($request->getParam('store', 0));
153
- parse_str($postedProducts, $products);
154
- if (isset($products['on']))
155
- unset($products['on']);
156
- $products = array_keys($products);
157
- if (!empty($products)) {
158
- $currentVersion = Mage::getVersion();
159
- $product = Mage::getModel('catalog/product');
160
- foreach ($products as $productId) {
161
-
162
- $product->setData(array());
163
- $product->setStoreId($storeId)
164
- ->load($productId)
165
- ->setIsMassupdate(true)
166
- ->setExcludeUrlRewrite(true);
167
-
168
- if (!$product->getId()) {
169
- continue;
170
- }
171
-
172
- $product->addData(array('shoppingflux_default_category' => $category->getId()));
173
- $dataChanged = $product->dataHasChangedFor('shoppingflux_default_category');
174
-
175
- if ($dataChanged) {
176
- if (version_compare($currentVersion, '1.4.0') < 0) {
177
- $product->save();
178
- } else {
179
- //Note: we could use this directly, but it will put all updated products to "Need Update" even if no changes
180
- Mage::getSingleton('catalog/product_action')
181
- ->updateAttributes($products, array('shoppingflux_default_category' => $category->getId()), $storeId);
182
- }
183
- }
184
- }
185
- }
186
- }
187
-
188
-
189
- /**
190
- * @deprecated Not used anymore. Caused problems and was not so helpfull..
191
- */
192
- public function fillMainCategory() {
193
- $productCollection = Mage::getModel('catalog/product')->getCollection();
194
- $productCollection->addAttributeToSelect('shoppingflux_default_category', 'left');
195
- $productCollection->addAttributeToFilter('shoppingflux_default_category', array(array('null'=>true), array('eq'=>'')));
196
- foreach($productCollection as $product) {
197
- $categories = $product->getCategoryIds();
198
- if(!empty($categories)) {
199
- shuffle($categories);
200
- $categoryId = array_shift($categories);
201
- Mage::getSingleton('catalog/product_action')
202
- ->updateAttributes(array($product->getId()), array('shoppingflux_default_category' => $categoryId), 0);
203
- }
204
- }
205
- }
206
-
207
- public function manageUpdates() {
208
- $apiKeyManaged = array();
209
- foreach (Mage::app()->getStores() as $store) {
210
- $apiKey = $this->getConfig()->getApiKey($store->getId());
211
- if (!$apiKey || in_array($apiKey, $apiKeyManaged))
212
- continue;
213
- $apiKeyManaged[] = $apiKey;
214
-
215
-
216
- $updates = Mage::getModel('profileolabs_shoppingflux/export_updates')->getCollection();
217
- $updates->addFieldToFilter('store_id', $store->getId());
218
-
219
- $wsUri = $this->getConfig()->getWsUri();
220
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
221
- try {
222
- $service->updateProducts($updates);
223
- $updates->walk('delete');
224
- } catch (Exception $e) {
225
-
226
- }
227
- }
228
- }
229
-
230
- protected function _scheduleProductUpdate(array $data) {
231
- /* * REALTIME* */
232
- $object = new Varien_Object();
233
- $object->setData($data);
234
- $collection = new Varien_Data_Collection();
235
- $collection->addItem($object);
236
- $apiKey = $this->getConfig()->getApiKey($data['store_id']);
237
- $wsUri = $this->getConfig()->getWsUri();
238
- try {
239
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
240
- $service->updateProducts($collection);
241
- } catch(Exception $e) {
242
-
243
- }
244
- /* * SCHEDULED* */
245
- /*
246
- $data['updated_at'] = date('Y-m-d H:i:s');
247
- $updates = Mage::getModel('profileolabs_shoppingflux/export_updates');
248
- $updates->loadWithData($data);
249
- foreach ($data as $k => $v)
250
- $updates->setData($k, $v);
251
- $updates->save();
252
- * *
253
- */
254
- }
255
-
256
- /**
257
- * @param mixed $product product id, or Mage_Catalog_Model_Product
258
- */
259
- protected function _scheduleProductUpdates($product, array $forceData = array()) {
260
- if ($product) {
261
- if (is_numeric($product))
262
- $product = Mage::getModel('catalog/product')->load($product);
263
- $productStoresIds = $product->getStoreIds();
264
- $apiKeyManaged = array();
265
- foreach ($productStoresIds as $storeId) {
266
- $apiKey = $this->getConfig()->getApiKey($storeId);
267
- if (!$apiKey || in_array($apiKey, $apiKeyManaged))
268
- continue;
269
- $apiKeyManaged[] = $apiKey;
270
- $storeProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product->getId());
271
-
272
- $stock = $storeProduct->getStockItem()->getQty();
273
- if ($this->getConfig()->isExportFilteredByAttribute($storeId) && $storeProduct->getData('shoppingflux_product') != 1) {
274
- $stock = 0;
275
- }
276
- if ($storeProduct->getStatus() != 1) {
277
- $stock = 0;
278
- }
279
- $data = array(
280
- 'store_id' => $storeId,
281
- 'product_sku' => $storeProduct->getSku(),
282
- 'stock_value' => $stock,
283
- 'price_value' => $storeProduct->getFinalPrice(),
284
- 'old_price_value' => $storeProduct->getPrice()
285
- );
286
- foreach ($forceData as $key => $val) {
287
- $data[$key] = $val;
288
- }
289
- $this->_scheduleProductUpdate($data);
290
- }
291
- }
292
- }
293
-
294
- /**
295
- * cataloginventory_stock_item_save_after (adminhtml,frontend)
296
- * @param type $observer
297
- */
298
- public function realtimeUpdateStock($observer) {
299
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getItem()->getProductId());
300
- if (!$this->getConfig()->isSyncEnabled())
301
- return;
302
-
303
- $oldStock = (int) $observer->getItem()->getOrigData('qty');
304
- $newStock = (int) $observer->getItem()->getData('qty');
305
- if ($oldStock != $newStock) {
306
-
307
- //Mage::log('realtimeUpdateStock');
308
- $productId = $observer->getItem()->getProductId();
309
- $this->_scheduleProductUpdates($productId);
310
- }
311
- }
312
-
313
- /**
314
- * catalog_product_save_after (adminhtml)
315
- * @param type $observer
316
- */
317
- public function realtimeUpdatePrice($observer) {
318
- if ($observer->getProduct()->getSku() != $observer->getProduct()->getOrigData('sku')) {
319
- Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFluxForAllStores($observer->getProduct()->getOrigData('sku'));
320
- Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFluxForAllStores($observer->getProduct()->getSku());
321
- }
322
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getProduct());
323
-
324
-
325
- if (!$this->getConfig()->isSyncEnabled())
326
- return;
327
-
328
- $product = $observer->getProduct();
329
- $storeId = $product->getStoreId();
330
- $attributesToCheck = array('price', 'tax_class_id', 'special_price', 'special_to_date', 'special_from_date');
331
-
332
- $somePriceChanged = false;
333
- foreach ($attributesToCheck as $attributeCode) {
334
- if ($product->getData($attributeCode) != $product->getOrigData($attributeCode)) {
335
- $somePriceChanged = true;
336
- }
337
- }
338
-
339
- if ($somePriceChanged) {
340
- //Mage::log('realtimeUpdatePrice');
341
- if ($storeId == 0) { // update for all stores
342
- $this->_scheduleProductUpdates($product);
343
- } else { // change happened in one store, update only this one
344
- $stock = $product->getStockItem()->getQty();
345
- $this->_scheduleProductUpdate(array(
346
- 'store_id' => $storeId,
347
- 'product_sku' => $product->getSku(),
348
- 'stock_value' => $stock,
349
- 'price_value' => $product->getFinalPrice(),
350
- 'old_price_value' => $product->getPrice()
351
- ));
352
- }
353
- }
354
- }
355
-
356
- /**
357
- * catalog_product_save_after (adminhtml)
358
- * @param type $observer
359
- */
360
- public function realtimeUpdateDeletedProduct($observer) {
361
- if (!$this->getConfig()->isSyncEnabled())
362
- return;
363
-
364
- $product = $observer->getProduct();
365
- $apiKeyManaged = array();
366
- foreach (Mage::app()->getStores() as $store) {
367
- $apiKey = $this->getConfig()->getApiKey($store->getId());
368
- if (!$apiKey || in_array($apiKey, $apiKeyManaged))
369
- continue;
370
- $apiKeyManaged[] = $apiKey;
371
- //Mage::log('realtimeUpdateDeletedProduct');
372
-
373
- $this->_scheduleProductUpdate(array(
374
- 'store_id' => $store->getId(),
375
- 'product_sku' => $product->getSku(),
376
- 'stock_value' => 0,
377
- 'price_value' => $product->getPrice(),
378
- 'old_price_value' => $product->getPrice()
379
- ));
380
- }
381
- }
382
-
383
- /**
384
- * catalog_product_status_update (adminhtml)
385
- * @param type $observer
386
- */
387
- public function realtimeUpdateDisabledProduct($observer) {
388
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getProductId());
389
- if (!$this->getConfig()->isSyncEnabled())
390
- return;
391
-
392
- //Mage::log('realtimeUpdateDisabledProduct');
393
- $this->_scheduleProductUpdates($observer->getProductId());
394
- }
395
-
396
- /**
397
- * catalog_product_save_after (adminhtml)
398
- * @param type $observer
399
- */
400
- public function realtimeUpdateDisabledProductSave($observer) {
401
- if (!$this->getConfig()->isSyncEnabled())
402
- return;
403
-
404
- $product = $observer->getProduct();
405
- if ($product->getStatus() != $product->getOrigData('status')) {
406
- //Mage::log('realtimeUpdateDisabledProductSave');
407
- $this->_scheduleProductUpdates($product);
408
- }
409
- }
410
-
411
- /**
412
- * catalog_product_save_after (adminhtml)
413
- * @param type $observer
414
- */
415
- public function realtimeUpdateInSf($observer) {
416
- if (!$this->getConfig()->isSyncEnabled())
417
- return;
418
-
419
- $product = $observer->getProduct();
420
- if ($product->getData('shoppingflux_product') != 1 && $product->getOrigData('shoppingflux_product') == 1) {
421
- //Mage::log('realtimeUpdateInSf');
422
- $this->_scheduleProductUpdates($product, array('stock_value' => 0));
423
- }
424
- }
425
-
426
- /**
427
- * shoppingflux_mass_publish_save_item (adminhtml)
428
- * @param type $observer
429
- */
430
- public function realtimeUpdateInSfMass($observer) {
431
- Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getProductId());
432
- if (!$this->getConfig()->isSyncEnabled())
433
- return;
434
-
435
- $productId = $observer->getProductId();
436
- $publish = $observer->getShoppingfluxProduct();
437
- if ($publish != 1) {
438
- //Mage::log('realtimeUpdateInSfMass');
439
- $this->_scheduleProductUpdates($productId, array('stock_value' => 0));
440
- }
441
- }
442
-
443
-
444
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait, vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Export_Observer {
10
+
11
+ /**
12
+ * @return Profileolabs_Shoppingflux_Model_Config
13
+ */
14
+ public function getConfig() {
15
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
16
+ }
17
+
18
+ public function catalogruleAfterApply($observer) {
19
+ return; //Disabled because it invalidate all the feed at each product / inventory save...
20
+ if(!$this->getConfig()->getManageCatalogRules()) {
21
+ return;
22
+ }
23
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
24
+ $write->beginTransaction();
25
+ try {
26
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 ";
27
+ $write->query($query);
28
+ $write->commit();
29
+ } catch (Exception $e) {
30
+ $write->rollback();
31
+ }
32
+ }
33
+
34
+
35
+ public static function checkStock($storeId = false) {
36
+ if(!$storeId || !is_numeric($storeId)) {
37
+ $storeId = Mage::app()->getStore()->getId();
38
+ }
39
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
40
+ $productCollection->getSelect()->join(
41
+ array('sf_stock' => $productCollection->getTable('cataloginventory/stock_item')), 'e.entity_id = sf_stock.product_id', array('qty', 'actual_qty'=>'qty')
42
+ );
43
+ $productCollection->getSelect()->join(
44
+ array('flux' => $productCollection->getTable('profileolabs_shoppingflux/export_flux')), "e.entity_id = flux.product_id and flux.store_id = '".$storeId."'", array('stock_value', 'sku')
45
+ );
46
+ $productCollection->getSelect()->where('CAST(sf_stock.qty AS SIGNED) != flux.stock_value');
47
+ if (Mage::getStoreConfigFlag(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK, $storeId)) {
48
+ $productCollection->getSelect()->where('(sf_stock.use_config_manage_stock = 0 and sf_stock.manage_stock = 1) OR (sf_stock.use_config_manage_stock = 1)');
49
+ } else {
50
+ $productCollection->getSelect()->where('(sf_stock.use_config_manage_stock = 0 and sf_stock.manage_stock = 1)');
51
+ }
52
+ $productCollection->getSelect()->where('flux.update_needed = 0');
53
+ $productCollection->getSelect()->group('e.entity_id');
54
+ foreach($productCollection as $product) {
55
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($product);
56
+ }
57
+ }
58
+
59
+
60
+
61
+ public function updateFlux() {
62
+ if(Mage::getStoreConfigFlag('shoppingflux_export/general/enable_cron')) {
63
+ foreach(Mage::app()->getStores() as $store) {
64
+ $feedUrl = Mage::helper('profileolabs_shoppingflux')->getFeedUrl($store);
65
+ if($feedUrl) {
66
+ file_get_contents($feedUrl);
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+
73
+ protected function generateFluxInFileForStore($storeId) {
74
+ $filePath = Mage::getBaseDir('media') . DS . 'shoppingflux_'.$storeId.'.xml';
75
+ $handle = fopen($filePath, 'a');
76
+ ftruncate($handle, 0);
77
+
78
+ //Mage::getModel('profileolabs_shoppingflux/export_flux')->updateFlux($storeId, 1000000);
79
+ $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
80
+ $collection->addFieldToFilter('should_export', 1);
81
+ $collection->addFieldToFilter('store_id', $storeId);
82
+ $sizeTotal = $collection->count();
83
+ $collection->clear();
84
+ $withNotSalableRetention = $this->getConfig()->isNotSalableRetentionEnabled($storeId);
85
+
86
+ if (!$this->getConfig()->isExportNotSalable($storeId) && !$withNotSalableRetention) {
87
+ $collection->addFieldToFilter('salable', 1);
88
+ }
89
+ if (!$this->getConfig()->isExportSoldout($storeId) && !$withNotSalableRetention) {
90
+ $collection->addFieldToFilter('is_in_stock', 1);
91
+ }
92
+ if ($this->getConfig()->isExportFilteredByAttribute($storeId)) {
93
+ $collection->addFieldToFilter('is_in_flux', 1);
94
+ }
95
+ $visibilities = $this->getConfig()->getVisibilitiesToExport($storeId);
96
+ $collection->getSelect()->where("find_in_set(visibility, '" . implode(',', $visibilities) . "')");
97
+
98
+
99
+
100
+ $xmlObj = Mage::getModel('profileolabs_shoppingflux/export_xml');
101
+ $startXml = $xmlObj->startXml(array('size-exportable' => $sizeTotal, 'size-xml' => $collection->count(), 'with-out-of-stock' => intval($this->getConfig()->isExportSoldout()), 'with-not-salable'=> intval($this->getConfig()->isExportNotSalable()), 'selected-only' => intval($this->getConfig()->isExportFilteredByAttribute()), 'visibilities' => implode(',', $visibilities)));
102
+ fwrite($handle, $startXml);
103
+ Mage::getSingleton('core/resource_iterator')
104
+ ->walk($collection->getSelect(), array(array($this, 'saveProductXml')), array('handle'=>$handle));
105
+ $endXml = $xmlObj->endXml();
106
+ fwrite($handle, $endXml);
107
+ fclose($handle);
108
+ }
109
+
110
+ public function saveProductXml($args) {
111
+ fwrite($args['handle'], $args['row']['xml']);
112
+ }
113
+
114
+ public function generateFluxInFile() {
115
+ //foreach(Mage::app()->getStores() as $store) {
116
+ // $this->generateFluxInFileForStore($store->getId());
117
+ //}
118
+ $this->generateFluxInFileForStore(Mage::app()->getDefaultStoreView()->getId());
119
+ }
120
+
121
+
122
+ /**
123
+ * Add shoppingflux product tab in category edit page
124
+ * @param $observer
125
+ */
126
+ public function addShoppingfluxProductsTab($observer) {
127
+ $tabs = $observer->getTabs();
128
+ $tabs->addTab('shoppingflux_products', array(
129
+ 'label' => Mage::helper('catalog')->__('Shoppingflux Category Products'),
130
+ 'content' => $tabs->getLayout()->createBlock(
131
+ 'profileolabs_shoppingflux/export_adminhtml_catalog_category_tab_default', 'shoppingflux.product.grid'
132
+ )->toHtml(),
133
+ ));
134
+ }
135
+
136
+ public function catalogProductAttributeUpdateBefore($observer) {
137
+ $productIds = $observer->getEvent()->getProductIds();
138
+ foreach ($productIds as $productId) {
139
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($productId);
140
+ }
141
+ }
142
+
143
+ public function catalogProductSaveCommitAfter($observer) {
144
+ $product = $observer->getEvent()->getProduct();
145
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($product->getId());
146
+ }
147
+
148
+ /**
149
+ * update default category for selected products
150
+ */
151
+ public function saveShoppingfluxCategoryProducts($observer) {
152
+ $category = $observer->getEvent()->getCategory();
153
+ $request = $observer->getEvent()->getRequest();
154
+ $postedProducts = $request->getParam('shoppingflux_category_products');
155
+ $storeId = intval($request->getParam('store', 0));
156
+
157
+ /** @var Profileolabs_Shoppingflux_Helper_String $stringHelper */
158
+ $stringHelper = Mage::helper('profileolabs_shoppingflux/string');
159
+ $products = $stringHelper->parseQueryStr($postedProducts);
160
+
161
+ if (isset($products['on']))
162
+ unset($products['on']);
163
+ $products = array_keys($products);
164
+ if (!empty($products)) {
165
+ $currentVersion = Mage::getVersion();
166
+ $product = Mage::getModel('catalog/product');
167
+ foreach ($products as $productId) {
168
+
169
+ $product->setData(array());
170
+ $product->setStoreId($storeId)
171
+ ->load($productId)
172
+ ->setIsMassupdate(true)
173
+ ->setExcludeUrlRewrite(true);
174
+
175
+ if (!$product->getId()) {
176
+ continue;
177
+ }
178
+
179
+ $product->addData(array('shoppingflux_default_category' => $category->getId()));
180
+ $dataChanged = $product->dataHasChangedFor('shoppingflux_default_category');
181
+
182
+ if ($dataChanged) {
183
+ if (version_compare($currentVersion, '1.4.0') < 0) {
184
+ $product->save();
185
+ } else {
186
+ //Note: we could use this directly, but it will put all updated products to "Need Update" even if no changes
187
+ Mage::getSingleton('catalog/product_action')
188
+ ->updateAttributes($products, array('shoppingflux_default_category' => $category->getId()), $storeId);
189
+ }
190
+ }
191
+ }
192
+ }
193
+ }
194
+
195
+
196
+ /**
197
+ * @deprecated Not used anymore. Caused problems and was not so helpfull..
198
+ */
199
+ public function fillMainCategory() {
200
+ $productCollection = Mage::getModel('catalog/product')->getCollection();
201
+ $productCollection->addAttributeToSelect('shoppingflux_default_category', 'left');
202
+ $productCollection->addAttributeToFilter('shoppingflux_default_category', array(array('null'=>true), array('eq'=>'')));
203
+ foreach($productCollection as $product) {
204
+ $categories = $product->getCategoryIds();
205
+ if(!empty($categories)) {
206
+ shuffle($categories);
207
+ $categoryId = array_shift($categories);
208
+ Mage::getSingleton('catalog/product_action')
209
+ ->updateAttributes(array($product->getId()), array('shoppingflux_default_category' => $categoryId), 0);
210
+ }
211
+ }
212
+ }
213
+
214
+ public function manageUpdates() {
215
+ $apiKeyManaged = array();
216
+ foreach (Mage::app()->getStores() as $store) {
217
+ $apiKey = $this->getConfig()->getApiKey($store->getId());
218
+ if (!$apiKey || in_array($apiKey, $apiKeyManaged))
219
+ continue;
220
+ $apiKeyManaged[] = $apiKey;
221
+
222
+
223
+ $updates = Mage::getModel('profileolabs_shoppingflux/export_updates')->getCollection();
224
+ $updates->addFieldToFilter('store_id', $store->getId());
225
+
226
+ $wsUri = $this->getConfig()->getWsUri();
227
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
228
+ try {
229
+ $service->updateProducts($updates);
230
+ $updates->walk('delete');
231
+ } catch (Exception $e) {
232
+
233
+ }
234
+ }
235
+ }
236
+
237
+ protected function _scheduleProductUpdate(array $data) {
238
+ /* * REALTIME* */
239
+ $object = new Varien_Object();
240
+ $object->setData($data);
241
+ $collection = new Varien_Data_Collection();
242
+ $collection->addItem($object);
243
+ $apiKey = $this->getConfig()->getApiKey($data['store_id']);
244
+ $wsUri = $this->getConfig()->getWsUri();
245
+ try {
246
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
247
+ $service->updateProducts($collection);
248
+ } catch(Exception $e) {
249
+
250
+ }
251
+ /* * SCHEDULED* */
252
+ /*
253
+ $data['updated_at'] = date('Y-m-d H:i:s');
254
+ $updates = Mage::getModel('profileolabs_shoppingflux/export_updates');
255
+ $updates->loadWithData($data);
256
+ foreach ($data as $k => $v)
257
+ $updates->setData($k, $v);
258
+ $updates->save();
259
+ * *
260
+ */
261
+ }
262
+
263
+ /**
264
+ * @param mixed $product product id, or Mage_Catalog_Model_Product
265
+ */
266
+ protected function _scheduleProductUpdates($product, array $forceData = array()) {
267
+ if ($product) {
268
+ if (is_numeric($product))
269
+ $product = Mage::getModel('catalog/product')->load($product);
270
+ $productStoresIds = $product->getStoreIds();
271
+ $apiKeyManaged = array();
272
+ foreach ($productStoresIds as $storeId) {
273
+ $apiKey = $this->getConfig()->getApiKey($storeId);
274
+ if (!$apiKey || in_array($apiKey, $apiKeyManaged))
275
+ continue;
276
+ $apiKeyManaged[] = $apiKey;
277
+ $storeProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($product->getId());
278
+
279
+ $stock = $storeProduct->getStockItem()->getQty();
280
+ if ($this->getConfig()->isExportFilteredByAttribute($storeId) && $storeProduct->getData('shoppingflux_product') != 1) {
281
+ $stock = 0;
282
+ }
283
+ if ($storeProduct->getStatus() != 1) {
284
+ $stock = 0;
285
+ }
286
+ $data = array(
287
+ 'store_id' => $storeId,
288
+ 'product_sku' => $storeProduct->getSku(),
289
+ 'stock_value' => $stock,
290
+ 'price_value' => $storeProduct->getFinalPrice(),
291
+ 'old_price_value' => $storeProduct->getPrice()
292
+ );
293
+ foreach ($forceData as $key => $val) {
294
+ $data[$key] = $val;
295
+ }
296
+ $this->_scheduleProductUpdate($data);
297
+ }
298
+ }
299
+ }
300
+
301
+ /**
302
+ * cataloginventory_stock_item_save_after (adminhtml,frontend)
303
+ * @param type $observer
304
+ */
305
+ public function realtimeUpdateStock($observer) {
306
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getItem()->getProductId());
307
+ if (!$this->getConfig()->isSyncEnabled())
308
+ return;
309
+
310
+ $oldStock = (int) $observer->getItem()->getOrigData('qty');
311
+ $newStock = (int) $observer->getItem()->getData('qty');
312
+ if ($oldStock != $newStock) {
313
+
314
+ //Mage::log('realtimeUpdateStock');
315
+ $productId = $observer->getItem()->getProductId();
316
+ $this->_scheduleProductUpdates($productId);
317
+ }
318
+ }
319
+
320
+ /**
321
+ * catalog_product_save_after (adminhtml)
322
+ * @param type $observer
323
+ */
324
+ public function realtimeUpdatePrice($observer) {
325
+ if ($observer->getProduct()->getSku() != $observer->getProduct()->getOrigData('sku')) {
326
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFluxForAllStores($observer->getProduct()->getOrigData('sku'));
327
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->updateProductInFluxForAllStores($observer->getProduct()->getSku());
328
+ }
329
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getProduct());
330
+
331
+
332
+ if (!$this->getConfig()->isSyncEnabled())
333
+ return;
334
+
335
+ $product = $observer->getProduct();
336
+ $storeId = $product->getStoreId();
337
+ $attributesToCheck = array('price', 'tax_class_id', 'special_price', 'special_to_date', 'special_from_date');
338
+
339
+ $somePriceChanged = false;
340
+ foreach ($attributesToCheck as $attributeCode) {
341
+ if ($product->getData($attributeCode) != $product->getOrigData($attributeCode)) {
342
+ $somePriceChanged = true;
343
+ }
344
+ }
345
+
346
+ if ($somePriceChanged) {
347
+ //Mage::log('realtimeUpdatePrice');
348
+ if ($storeId == 0) { // update for all stores
349
+ $this->_scheduleProductUpdates($product);
350
+ } else { // change happened in one store, update only this one
351
+ $stock = $product->getStockItem()->getQty();
352
+ $this->_scheduleProductUpdate(array(
353
+ 'store_id' => $storeId,
354
+ 'product_sku' => $product->getSku(),
355
+ 'stock_value' => $stock,
356
+ 'price_value' => $product->getFinalPrice(),
357
+ 'old_price_value' => $product->getPrice()
358
+ ));
359
+ }
360
+ }
361
+ }
362
+
363
+ /**
364
+ * catalog_product_save_after (adminhtml)
365
+ * @param type $observer
366
+ */
367
+ public function realtimeUpdateDeletedProduct($observer) {
368
+ if (!$this->getConfig()->isSyncEnabled())
369
+ return;
370
+
371
+ $product = $observer->getProduct();
372
+ $apiKeyManaged = array();
373
+ foreach (Mage::app()->getStores() as $store) {
374
+ $apiKey = $this->getConfig()->getApiKey($store->getId());
375
+ if (!$apiKey || in_array($apiKey, $apiKeyManaged))
376
+ continue;
377
+ $apiKeyManaged[] = $apiKey;
378
+ //Mage::log('realtimeUpdateDeletedProduct');
379
+
380
+ $this->_scheduleProductUpdate(array(
381
+ 'store_id' => $store->getId(),
382
+ 'product_sku' => $product->getSku(),
383
+ 'stock_value' => 0,
384
+ 'price_value' => $product->getPrice(),
385
+ 'old_price_value' => $product->getPrice()
386
+ ));
387
+ }
388
+ }
389
+
390
+ /**
391
+ * catalog_product_status_update (adminhtml)
392
+ * @param type $observer
393
+ */
394
+ public function realtimeUpdateDisabledProduct($observer) {
395
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getProductId());
396
+ if (!$this->getConfig()->isSyncEnabled())
397
+ return;
398
+
399
+ //Mage::log('realtimeUpdateDisabledProduct');
400
+ $this->_scheduleProductUpdates($observer->getProductId());
401
+ }
402
+
403
+ /**
404
+ * catalog_product_save_after (adminhtml)
405
+ * @param type $observer
406
+ */
407
+ public function realtimeUpdateDisabledProductSave($observer) {
408
+ if (!$this->getConfig()->isSyncEnabled())
409
+ return;
410
+
411
+ $product = $observer->getProduct();
412
+ if ($product->getStatus() != $product->getOrigData('status')) {
413
+ //Mage::log('realtimeUpdateDisabledProductSave');
414
+ $this->_scheduleProductUpdates($product);
415
+ }
416
+ }
417
+
418
+ /**
419
+ * catalog_product_save_after (adminhtml)
420
+ * @param type $observer
421
+ */
422
+ public function realtimeUpdateInSf($observer) {
423
+ if (!$this->getConfig()->isSyncEnabled())
424
+ return;
425
+
426
+ $product = $observer->getProduct();
427
+ if ($product->getData('shoppingflux_product') != 1 && $product->getOrigData('shoppingflux_product') == 1) {
428
+ //Mage::log('realtimeUpdateInSf');
429
+ $this->_scheduleProductUpdates($product, array('stock_value' => 0));
430
+ }
431
+ }
432
+
433
+ /**
434
+ * shoppingflux_mass_publish_save_item (adminhtml)
435
+ * @param type $observer
436
+ */
437
+ public function realtimeUpdateInSfMass($observer) {
438
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->productNeedUpdate($observer->getProductId());
439
+ if (!$this->getConfig()->isSyncEnabled())
440
+ return;
441
+
442
+ $productId = $observer->getProductId();
443
+ $publish = $observer->getShoppingfluxProduct();
444
+ if ($publish != 1) {
445
+ //Mage::log('realtimeUpdateInSfMass');
446
+ $this->_scheduleProductUpdates($productId, array('stock_value' => 0));
447
+ }
448
+ }
449
+
450
+ /**
451
+ * @param int $storeId
452
+ * @param string $stockAlias
453
+ * @return Zend_Db_Select
454
+ */
455
+ protected function _getSalableProductsSelect($storeId, $stockAlias)
456
+ {
457
+ /** @var Mage_Catalog_Model_Resource_Product $productResource */
458
+ $productResource = Mage::getResourceModel('catalog/product');
459
+
460
+ /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
461
+ $collection = Mage::getResourceModel('catalog/product_collection');
462
+ $collection->addStoreFilter($storeId);
463
+ $collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
464
+
465
+ $collection->joinTable(
466
+ array($stockAlias => $productResource->getTable('cataloginventory/stock_item')),
467
+ 'product_id=entity_id',
468
+ array('product_id')
469
+ );
470
+
471
+ $select = $collection->getSelect();
472
+
473
+ if (Mage::getStoreConfigFlag('cataloginventory/item_options/manage_stock')) {
474
+ $select->where(
475
+ '(' . $stockAlias . '.use_config_manage_stock = 0 AND ' . $stockAlias . '.manage_stock = 0)'
476
+ . ' OR '
477
+ . $stockAlias . '.is_in_stock = 1'
478
+ );
479
+ } else {
480
+ $select->where(
481
+ $stockAlias . '.use_config_manage_stock = 1'
482
+ . ' OR '
483
+ . $stockAlias . '.manage_stock = 0'
484
+ . ' OR '
485
+ . $stockAlias . '.is_in_stock = 1'
486
+ );
487
+ }
488
+
489
+ return $select;
490
+ }
491
+
492
+ /**
493
+ * @param int $storeId
494
+ */
495
+ protected function _refreshNotSalableProducts($storeId)
496
+ {
497
+ /** @var Mage_Catalog_Model_Resource_Product $productResource */
498
+ $productResource = Mage::getResourceModel('catalog/product');
499
+ $readConnection = $productResource->getReadConnection();
500
+ $writeConnection = $productResource->getWriteConnection();
501
+
502
+ $salableGlobalSelect = $this->_getSalableProductsSelect($storeId, '_ciss');
503
+ $typeConditions = array();
504
+
505
+ // Specific conditions for configurable products
506
+
507
+ $inStockChildrenSelect = $this->_getSalableProductsSelect($storeId, '_cciss');
508
+
509
+ $inStockChildrenSelect->reset(Varien_Db_Select::COLUMNS)
510
+ ->columns(array('count' => new Zend_Db_Expr('COUNT(*)')))
511
+ ->joinInner(
512
+ array('_ccsl' => $productResource->getTable('catalog/product_super_link')),
513
+ '_ccsl.product_id = e.entity_id',
514
+ array()
515
+ )
516
+ ->where('_ccsl.parent_id = e.entity_id');
517
+
518
+ $typeConditions[] = '('
519
+ . $readConnection->quoteInto('(e.type_id != ?)', Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
520
+ . ' OR '
521
+ . '(' . $inStockChildrenSelect->assemble() . ' > 0)'
522
+ . ')';
523
+
524
+ // Global select finalization
525
+
526
+ $salableGlobalSelect->reset(Varien_Db_Select::COLUMNS)
527
+ ->columns(array('e.entity_id'))
528
+ ->where(implode(' OR ', $typeConditions));
529
+
530
+ $notSalableGlobalSelect = $readConnection->select()
531
+ ->from(
532
+ array('_main_table' => $productResource->getTable('catalog/product')),
533
+ array(
534
+ 'product_id' => '_main_table.entity_id',
535
+ 'store_id' => new Zend_Db_Expr($storeId),
536
+ 'not_salable_from' => new Zend_Db_Expr($writeConnection->quote(now())),
537
+ )
538
+ )
539
+ ->where('_main_table.entity_id NOT IN (' . $salableGlobalSelect->assemble() . ')');
540
+
541
+ $nowTime = time();
542
+ $writeConnection->beginTransaction();
543
+
544
+ try {
545
+ // Retrieve products that were already updated in the flux
546
+
547
+ $updatedIds = $readConnection->fetchCol(
548
+ $readConnection->select()
549
+ ->from(
550
+ $productResource->getTable('profileolabs_shoppingflux/updated_not_salable_product'),
551
+ array('product_id')
552
+ )
553
+ ->where('store_id = ?', $storeId)
554
+ );
555
+
556
+ // Remember new not salable products
557
+
558
+ $writeConnection->query(
559
+ $notSalableGlobalSelect->insertIgnoreFromSelect(
560
+ $productResource->getTable('profileolabs_shoppingflux/not_salable_product'),
561
+ array('product_id', 'store_id', 'not_salable_from')
562
+ )
563
+ );
564
+
565
+ // Forget products that are salable again
566
+
567
+ $writeConnection->delete(
568
+ $productResource->getTable('profileolabs_shoppingflux/not_salable_product'),
569
+ 'product_id IN (' . $salableGlobalSelect->assemble() . ')'
570
+ . ' AND ' . $writeConnection->quoteInto('store_id = ?', $storeId)
571
+ );
572
+
573
+ if ($seconds = $this->getConfig()->getNotSalableRetentionDuration($storeId)) {
574
+ // Retrieve products that are updatable, no matter if they have already been,
575
+ // because they have been not salable long enough
576
+
577
+ $updatableSelect = $readConnection->select()
578
+ ->from(
579
+ $productResource->getTable('profileolabs_shoppingflux/not_salable_product'),
580
+ array('product_id', 'store_id')
581
+ )
582
+ ->where('store_id = ?', $storeId)
583
+ ->where('UNIX_TIMESTAMP(not_salable_from) <= ?', $nowTime - $seconds);
584
+
585
+ $updatableIds = $readConnection->fetchCol($updatableSelect);
586
+
587
+ // Remember the products that will soon be updated in the flux
588
+
589
+ $writeConnection->query(
590
+ $updatableSelect->insertFromSelect(
591
+ $productResource->getTable('profileolabs_shoppingflux/updated_not_salable_product'),
592
+ array('product_id', 'store_id')
593
+ )
594
+ );
595
+ } else {
596
+ $updatableIds = array();
597
+ }
598
+
599
+ // Reset the products that had exceeded delay, but do not anymore because of a change in the configuration
600
+
601
+ $resettableIdsSelect = $readConnection->select()
602
+ ->from(
603
+ $productResource->getTable('profileolabs_shoppingflux/not_salable_product'),
604
+ array('product_id')
605
+ )
606
+ ->where('store_id = ?', $storeId);
607
+
608
+ if ($seconds) {
609
+ $resettableIdsSelect->where('UNIX_TIMESTAMP(not_salable_from) >= ?', $nowTime - $seconds);
610
+ }
611
+
612
+ $writeConnection->delete(
613
+ $productResource->getTable('profileolabs_shoppingflux/updated_not_salable_product'),
614
+ 'product_id IN (' . $resettableIdsSelect->assemble() . ')'
615
+ . ' AND ' . $writeConnection->quoteInto('store_id = ?', $storeId)
616
+ );
617
+
618
+ // Ensure that will be updated products that were updated because they had exceeded not salable delay,
619
+ // but that either are now salable again, either now have a delay shorter than the newly configured one, ..
620
+
621
+ $fluxUpdatableIds = array_diff($updatedIds, $updatableIds);
622
+
623
+ // .. and new not salable products
624
+
625
+ $fluxUpdatableIds = array_unique(
626
+ array_merge(
627
+ $fluxUpdatableIds,
628
+ array_diff($updatableIds, $updatedIds)
629
+ )
630
+ );
631
+
632
+ /*
633
+ * Example:
634
+ * $updatedIds = [1, 2, 3, 4] - IDs that had previously exceeded not salable delay
635
+ * $updatableIds = [3, 4, 5, 6] - IDs that currently exceed not salable delay
636
+ *
637
+ * First diff = [1, 2] => products that are salable again, or do not exceed delay anymore
638
+ * Second diff = [5, 6] => products that were not exceeding delay, but now do
639
+ * Remaining = [3, 4] => products that have not changed since last time
640
+ **/
641
+
642
+ // Mark the necessary flux products as updatable
643
+
644
+ $sliceSize = 500;
645
+
646
+ $productsSkus = $readConnection->fetchPairs(
647
+ $readConnection->select()
648
+ ->from(
649
+ $productResource->getTable('catalog/product'),
650
+ array('entity_id', 'sku')
651
+ )
652
+ );
653
+
654
+ $sliceCount = ceil(count($fluxUpdatableIds) / $sliceSize);
655
+
656
+ for ($i = 0; $i < $sliceCount; $i++) {
657
+ $productsIds = array_slice($fluxUpdatableIds, $i * $sliceSize, $sliceSize);
658
+ $updatedSkus = array();
659
+
660
+ foreach ($productsIds as $productId) {
661
+ if (isset($productsSkus[$productId])) {
662
+ $updatedSkus[] = $productsSkus[$productId];
663
+ }
664
+ }
665
+
666
+ $writeConnection->update(
667
+ $productResource->getTable('profileolabs_shoppingflux/export_flux'),
668
+ array('update_needed' => 1),
669
+ $writeConnection->quoteInto('sku IN (?)', $updatedSkus)
670
+ . ' AND ' . $writeConnection->quoteInto('store_id = ?', $storeId)
671
+ );
672
+ }
673
+
674
+ $writeConnection->commit();
675
+
676
+ /** @var Mage_Core_Model_Config $mageConfig */
677
+ $mageConfig = Mage::getSingleton('core/config');
678
+
679
+ $mageConfig->saveConfig(
680
+ 'shoppingflux_export/not_salable_retention/last_refresh',
681
+ time(),
682
+ 'stores',
683
+ $storeId
684
+ );
685
+ } catch (Exception $e) {
686
+ $writeConnection->rollback();
687
+ }
688
+ }
689
+
690
+ public function refreshNotSalableProducts()
691
+ {
692
+ /** @var Mage_Core_Model_Config $mageConfig */
693
+ $config = $this->getConfig();
694
+ $storeLastRefreshes = array();
695
+
696
+ /** @var Mage_Core_Model_Store $store */
697
+ foreach (Mage::app()->getStores(false) as $store) {
698
+ $storeId = $store->getId();
699
+
700
+ if ($config->isExportEnabled($storeId) && $config->isNotSalableRetentionEnabled($storeId)) {
701
+ $storeLastRefreshes[$store->getId()] = (int) Mage::getStoreConfig(
702
+ 'shoppingflux_export/not_salable_retention/last_refresh',
703
+ $storeId
704
+ );
705
+ }
706
+ }
707
+
708
+ if (!empty($storeLastRefreshes)) {
709
+ asort($storeLastRefreshes, SORT_NUMERIC);
710
+ reset($storeLastRefreshes);
711
+ $storeId = key($storeLastRefreshes);
712
+ $this->_refreshNotSalableProducts($storeId);
713
+ }
714
+ }
715
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Rewrite/Catalog/Config.php CHANGED
@@ -1,58 +1,58 @@
1
- <?php
2
-
3
- /**
4
- * Magento
5
- *
6
- * NOTICE OF LICENSE
7
- *
8
- * This source file is subject to the Open Software License (OSL 3.0)
9
- * that is bundled with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://opensource.org/licenses/osl-3.0.php
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@magentocommerce.com so we can send you a copy immediately.
15
- *
16
- * DISCLAIMER
17
- *
18
- * Do not edit or add to this file if you wish to upgrade Magento to newer
19
- * versions in the future. If you wish to customize Magento for your
20
- * needs please refer to http://www.magentocommerce.com for more information.
21
- *
22
- * @category Mage
23
- * @package Mage_Catalog
24
- * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
- */
27
- if (file_exists(BP . '/app/code/local/Amasty/Improved/Model/Rewrite/Config.php')) {
28
-
29
- class Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config_Compatibility extends Amasty_ImprovedSorting_Model_Rewrite_Config {
30
-
31
- }
32
-
33
- } else {
34
-
35
- class Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config_Compatibility extends Mage_Catalog_Model_Config {
36
-
37
- }
38
-
39
- }
40
-
41
- class Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config extends Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config_Compatibility {
42
-
43
- /**
44
- * Get attribute by code for entity type
45
- *
46
- * @param mixed $entityType
47
- * @param mixed $code
48
- * @return Mage_Eav_Model_Entity_Attribute_Abstract
49
- */
50
- public function getAttribute($entityType, $code) {
51
- $attribute = parent::getAttribute($entityType, $code);
52
- if (is_object($attribute) && $attribute->getAttributeCode() == "") {
53
- $attribute->setAttributeCode($code);
54
- }
55
- return $attribute;
56
- }
57
-
58
- }
1
+ <?php
2
+
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category Mage
23
+ * @package Mage_Catalog
24
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
25
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
26
+ */
27
+ if (file_exists(BP . '/app/code/local/Amasty/Improved/Model/Rewrite/Config.php')) {
28
+
29
+ class Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config_Compatibility extends Amasty_ImprovedSorting_Model_Rewrite_Config {
30
+
31
+ }
32
+
33
+ } else {
34
+
35
+ class Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config_Compatibility extends Mage_Catalog_Model_Config {
36
+
37
+ }
38
+
39
+ }
40
+
41
+ class Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config extends Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config_Compatibility {
42
+
43
+ /**
44
+ * Get attribute by code for entity type
45
+ *
46
+ * @param mixed $entityType
47
+ * @param mixed $code
48
+ * @return Mage_Eav_Model_Entity_Attribute_Abstract
49
+ */
50
+ public function getAttribute($entityType, $code) {
51
+ $attribute = parent::getAttribute($entityType, $code);
52
+ if (is_object($attribute) && $attribute->getAttributeCode() == "") {
53
+ $attribute->setAttributeCode($code);
54
+ }
55
+ return $attribute;
56
+ }
57
+
58
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Rewrite/CatalogInventory/Stock/Item.php CHANGED
@@ -1,33 +1,33 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
-
10
-
11
- if(file_exists(BP.'/app/code/community/MDN/AdvancedStock/Model/CatalogInventory/Stock/Item.php') || file_exists(BP.'/app/code/local/MDN/AdvancedStock/Model/CatalogInventory/Stock/Item.php')) {
12
- class Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item_Compatibility extends MDN_AdvancedStock_Model_CatalogInventory_Stock_Item {}
13
- } else {
14
- class Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item_Compatibility extends Mage_CatalogInventory_Model_Stock_Item {}
15
- }
16
-
17
- class Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item
18
- extends Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item_Compatibility {
19
-
20
- /**
21
- * cataloginventory_stock_item_save_before simply ceases to exist on Magento 1.4.0.0 and up
22
- */
23
- protected function _beforeSave() {
24
- if(version_compare(Mage::getVersion(),'1.4.0.0') >= 0) {
25
- parent::_beforeSave();
26
- Mage::dispatchEvent('cataloginventory_stock_item_save_before', array('item' => $this));
27
- return $this;
28
- } else {
29
- return parent::_beforeSave();
30
- }
31
- }
32
-
33
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+
10
+
11
+ if (Mage::helper('core')->isModuleEnabled('MDN_AdvancedStock') && class_exists('MDN_AdvancedStock_Model_CatalogInventory_Stock_Item')) {
12
+ class Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item_Compatibility extends MDN_AdvancedStock_Model_CatalogInventory_Stock_Item {}
13
+ } else {
14
+ class Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item_Compatibility extends Mage_CatalogInventory_Model_Stock_Item {}
15
+ }
16
+
17
+ class Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item
18
+ extends Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item_Compatibility {
19
+
20
+ /**
21
+ * cataloginventory_stock_item_save_before simply ceases to exist on Magento 1.4.0.0 and up
22
+ */
23
+ protected function _beforeSave() {
24
+ if(version_compare(Mage::getVersion(),'1.4.0.0') >= 0) {
25
+ parent::_beforeSave();
26
+ Mage::dispatchEvent('cataloginventory_stock_item_save_before', array('item' => $this));
27
+ return $this;
28
+ } else {
29
+ return parent::_beforeSave();
30
+ }
31
+ }
32
+
33
  }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Attributes.php CHANGED
@@ -1,56 +1,56 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait - Vincent Enjalbert
7
- */
8
- class Profileolabs_Shoppingflux_Model_Export_Source_Attributes
9
- {
10
-
11
- protected $_exceptions = array(
12
- 'store',
13
- 'websites',
14
- 'attribute_set',
15
- 'type',
16
- 'news_from_date',
17
- 'news_to_date',
18
- 'gallery',
19
- 'media_gallery',
20
- 'url_key',
21
- 'url_path',
22
- 'minimal_price',
23
- 'custom_design',
24
- 'custom_design_from',
25
- 'custom_design_to',
26
- 'category_ids',
27
- 'options_container',
28
- 'required_options',
29
- 'has_options',
30
- 'tax_class_id',
31
- 'custom_layout_update',
32
- 'page_layout',
33
- 'recurring_profile',
34
- 'is_recurring',
35
- 'is_in_stock',
36
- 'qty'
37
- );
38
-
39
- protected $_attributes = null;
40
-
41
- public function toOptionArray()
42
- {
43
- if(is_null($this->_attributes)) {
44
- $this->_attributes = array();
45
-
46
- $attributesArray= Mage::getSingleton('profileolabs_shoppingflux/export_convert_parser_product')->getExternalAttributes();
47
- foreach($attributesArray as $k=>$v) {
48
- if(!in_array($k, $this->_exceptions)) {
49
- $this->_attributes[] = array('value'=>$k, 'label'=>$v);
50
- }
51
- }
52
- array_unshift($this->_attributes, array("value"=>"","label"=>""));
53
- }
54
- return $this->_attributes;
55
- }
56
- }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait - Vincent Enjalbert
7
+ */
8
+ class Profileolabs_Shoppingflux_Model_Export_Source_Attributes
9
+ {
10
+
11
+ protected $_exceptions = array(
12
+ 'store',
13
+ 'websites',
14
+ 'attribute_set',
15
+ 'type',
16
+ 'news_from_date',
17
+ 'news_to_date',
18
+ 'gallery',
19
+ 'media_gallery',
20
+ 'url_key',
21
+ 'url_path',
22
+ 'minimal_price',
23
+ 'custom_design',
24
+ 'custom_design_from',
25
+ 'custom_design_to',
26
+ 'category_ids',
27
+ 'options_container',
28
+ 'required_options',
29
+ 'has_options',
30
+ 'tax_class_id',
31
+ 'custom_layout_update',
32
+ 'page_layout',
33
+ 'recurring_profile',
34
+ 'is_recurring',
35
+ 'is_in_stock',
36
+ 'qty'
37
+ );
38
+
39
+ protected $_attributes = null;
40
+
41
+ public function toOptionArray()
42
+ {
43
+ if(is_null($this->_attributes)) {
44
+ $this->_attributes = array();
45
+
46
+ $attributesArray= Mage::getSingleton('profileolabs_shoppingflux/export_convert_parser_product')->getExternalAttributes();
47
+ foreach($attributesArray as $k=>$v) {
48
+ if(!in_array($k, $this->_exceptions)) {
49
+ $this->_attributes[] = array('value'=>$k, 'label'=>$v);
50
+ }
51
+ }
52
+ array_unshift($this->_attributes, array("value"=>"","label"=>""));
53
+ }
54
+ return $this->_attributes;
55
+ }
56
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Attributesprice.php CHANGED
@@ -1,31 +1,31 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- */
8
- class Profileolabs_Shoppingflux_Model_Export_Source_Attributesprice
9
- {
10
-
11
-
12
- public function toOptionArray()
13
- {
14
- $model = Mage::getResourceModel('catalog/product');
15
- $typeId = $model->getTypeId();
16
-
17
- $attributesCollection = Mage::getResourceModel('eav/entity_attribute_collection')
18
- ->setEntityTypeFilter($typeId)
19
- ->load();
20
- $attributes = array();
21
- $attributes[] = array('value' => '', 'label' => '');
22
- foreach ($attributesCollection as $attribute) {
23
- if($attribute->getFrontendInput() == 'price') {
24
- $code = $attribute->getAttributeCode();
25
- $attributes[] = array('value' => $code, 'label' => $code);
26
- }
27
- }
28
-
29
- return $attributes;
30
- }
31
- }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ */
8
+ class Profileolabs_Shoppingflux_Model_Export_Source_Attributesprice
9
+ {
10
+
11
+
12
+ public function toOptionArray()
13
+ {
14
+ $model = Mage::getResourceModel('catalog/product');
15
+ $typeId = $model->getTypeId();
16
+
17
+ $attributesCollection = Mage::getResourceModel('eav/entity_attribute_collection')
18
+ ->setEntityTypeFilter($typeId)
19
+ ->load();
20
+ $attributes = array();
21
+ $attributes[] = array('value' => '', 'label' => '');
22
+ foreach ($attributesCollection as $attribute) {
23
+ if($attribute->getFrontendInput() == 'price') {
24
+ $code = $attribute->getAttributeCode();
25
+ $attributes[] = array('value' => $code, 'label' => $code);
26
+ }
27
+ }
28
+
29
+ return $attributes;
30
+ }
31
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Category/Level.php CHANGED
@@ -1,18 +1,18 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Model_Export_Source_Category_Level
4
- {
5
-
6
-
7
- public function toOptionArray()
8
- {
9
- return array(
10
- array('label'=>5, 'value'=>5),
11
- array('label'=>4, 'value'=>4),
12
- array('label'=>3, 'value'=>3),
13
- array('label'=>2, 'value'=>2),
14
- array('label'=>1, 'value'=>1),
15
- );
16
-
17
- }
18
- }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Model_Export_Source_Category_Level
4
+ {
5
+
6
+
7
+ public function toOptionArray()
8
+ {
9
+ return array(
10
+ array('label'=>5, 'value'=>5),
11
+ array('label'=>4, 'value'=>4),
12
+ array('label'=>3, 'value'=>3),
13
+ array('label'=>2, 'value'=>2),
14
+ array('label'=>1, 'value'=>1),
15
+ );
16
+
17
+ }
18
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Tracking/Delay.php CHANGED
@@ -1,28 +1,28 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Model_Export_Source_Tracking_Delay
4
- {
5
-
6
-
7
- public function toOptionArray()
8
- {
9
- return array(
10
- array('label'=>30, 'value'=>30),
11
- array('label'=>25, 'value'=>25),
12
- array('label'=>20, 'value'=>20),
13
- array('label'=>15, 'value'=>15),
14
- array('label'=>10, 'value'=>10),
15
- array('label'=>9, 'value'=>9),
16
- array('label'=>8, 'value'=>8),
17
- array('label'=>7, 'value'=>7),
18
- array('label'=>6, 'value'=>6),
19
- array('label'=>5, 'value'=>5),
20
- array('label'=>4, 'value'=>4),
21
- array('label'=>3, 'value'=>3),
22
- array('label'=>2, 'value'=>2),
23
- array('label'=>1, 'value'=>1),
24
- array('label'=>'Immediate', 'value'=>0),
25
- );
26
-
27
- }
28
- }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Model_Export_Source_Tracking_Delay
4
+ {
5
+
6
+
7
+ public function toOptionArray()
8
+ {
9
+ return array(
10
+ array('label'=>30, 'value'=>30),
11
+ array('label'=>25, 'value'=>25),
12
+ array('label'=>20, 'value'=>20),
13
+ array('label'=>15, 'value'=>15),
14
+ array('label'=>10, 'value'=>10),
15
+ array('label'=>9, 'value'=>9),
16
+ array('label'=>8, 'value'=>8),
17
+ array('label'=>7, 'value'=>7),
18
+ array('label'=>6, 'value'=>6),
19
+ array('label'=>5, 'value'=>5),
20
+ array('label'=>4, 'value'=>4),
21
+ array('label'=>3, 'value'=>3),
22
+ array('label'=>2, 'value'=>2),
23
+ array('label'=>1, 'value'=>1),
24
+ array('label'=>'Immediate', 'value'=>0),
25
+ );
26
+
27
+ }
28
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Source/Visibility.php CHANGED
@@ -1,21 +1,21 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- */
8
- class Profileolabs_Shoppingflux_Model_Export_Source_Visibility
9
- {
10
-
11
-
12
- public function toOptionArray()
13
- {
14
- $options = Mage_Catalog_Model_Product_Visibility::getOptionArray();
15
- $result = array();
16
- foreach ($options as $optionValue=>$optionLabel) {
17
- $result[] = array('label'=>$optionLabel, 'value'=>$optionValue);
18
- }
19
- return $result;
20
- }
21
- }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ */
8
+ class Profileolabs_Shoppingflux_Model_Export_Source_Visibility
9
+ {
10
+
11
+
12
+ public function toOptionArray()
13
+ {
14
+ $options = Mage_Catalog_Model_Product_Visibility::getOptionArray();
15
+ $result = array();
16
+ foreach ($options as $optionValue=>$optionLabel) {
17
+ $result[] = array('label'=>$optionLabel, 'value'=>$optionValue);
18
+ }
19
+ return $result;
20
+ }
21
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Updates.php CHANGED
@@ -1,32 +1,32 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Export_Updates extends Mage_Core_Model_Abstract {
10
-
11
- protected function _construct() {
12
- $this->_init('profileolabs_shoppingflux/export_updates');
13
- }
14
-
15
- public function loadWithData($data) {
16
- if (!isset($data['product_sku']) || !isset($data['store_id']))
17
- return;
18
- $productSku = $data['product_sku'];
19
- $storeId = $data['store_id'];
20
-
21
- $collection = $this->getCollection();
22
- $select = $collection->getSelect();
23
- $select->where('product_sku = ?', $productSku);
24
- $select->where('store_id = ?', $storeId);
25
- $collection->load();
26
- if ($collection->getSize() <= 0)
27
- return;
28
- $this->load($collection->getFirstItem()->getId());
29
- return;
30
- }
31
-
32
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Export_Updates extends Mage_Core_Model_Abstract {
10
+
11
+ protected function _construct() {
12
+ $this->_init('profileolabs_shoppingflux/export_updates');
13
+ }
14
+
15
+ public function loadWithData($data) {
16
+ if (!isset($data['product_sku']) || !isset($data['store_id']))
17
+ return;
18
+ $productSku = $data['product_sku'];
19
+ $storeId = $data['store_id'];
20
+
21
+ $collection = $this->getCollection();
22
+ $select = $collection->getSelect();
23
+ $select->where('product_sku = ?', $productSku);
24
+ $select->where('store_id = ?', $storeId);
25
+ $collection->load();
26
+ if ($collection->getSize() <= 0)
27
+ return;
28
+ $this->load($collection->getFirstItem()->getId());
29
+ return;
30
+ }
31
+
32
  }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Xml.php CHANGED
@@ -1,150 +1,150 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Model_Export_Xml {
4
-
5
-
6
- public function __construct() {
7
-
8
- }
9
-
10
- public function _addEntries($entries) {
11
- foreach($entries as $entry) {
12
- $this->_addEntry($entry);
13
- }
14
- }
15
-
16
- public function _addEntry($entry) {
17
- return "<product>" . chr(10) .
18
- $this->arrayToNode($entry) .
19
- "</product>" . chr(10);
20
- }
21
-
22
-
23
- public function getVersion() {
24
- return Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
25
- }
26
-
27
- public function startXml($params=array()) {
28
- $xml = '<?xml version="1.0" encoding="utf-8"?>' . chr(10) .
29
- '<products version="' . $this->getVersion() . '"';
30
- foreach($params as $attrName=>$attrValue) {
31
- $xml .= ' ' . $attrName . '="' . $attrValue . '"';
32
- }
33
- $xml .= '>' . chr(10);
34
- return $xml;
35
- }
36
-
37
- public function endXml() {
38
- return "</products>" . chr(10);
39
- }
40
-
41
- protected $_attributes = array();
42
- protected function _getAttribute($attributeCode) {
43
- if(!isset($this->_attributes[$attributeCode])) {
44
- $this->_attributes[$attributeCode] = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
45
- }
46
- return $this->_attributes[$attributeCode];
47
- }
48
-
49
- /*obsolete*/
50
- public function extractData($nameNode, $attributeCode, $product) {
51
-
52
- $_helper = Mage::helper('catalog/output');
53
-
54
- $data = $product->getData($attributeCode);
55
-
56
- $attribute = $this->_getAttribute($attributeCode);
57
- if ($attribute) {
58
- if($attribute->getFrontendInput() == 'date') {
59
- return $data;
60
- }
61
-
62
- $data = $attribute->getFrontend()->getValue($product);
63
- $data = $_helper->productAttribute($product, $data, $attributeCode);
64
-
65
- if ($nameNode == 'ecotaxe' && $attribute->getFrontendInput() == 'weee') {
66
- $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
67
-
68
- foreach ($weeeAttributes as $wa) {
69
- if ($wa->getCode() == $attributeCode) {
70
- $data = round($wa->getAmount(), 2);
71
- break;
72
- }
73
- }
74
- }
75
- }
76
-
77
-
78
-
79
-
80
- //$_helper = Mage::helper('catalog/output');
81
- //if($nameNode == 'description' || $nameNode == 'short_description')
82
- //$data = $_helper->productAttribute($product, $data, $attributeCode);
83
- //Synthetize it
84
- /* $method = "get".ucfirst($attributeCode);
85
- if(method_exists($product,$method))
86
- $data = $product->$method(); */
87
-
88
- //TODO remove this
89
- if ($data == "No" || $data == "Non")
90
- $data = "";
91
-
92
- //Exceptions data
93
- if ($nameNode == 'shipping_delay' && empty($data))
94
- $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
95
-
96
- if ($nameNode == 'quantity')
97
- $data = round($data);
98
-
99
- return $data;
100
- }
101
-
102
- /**
103
- * Get singleton config for Export
104
- * @return Profileolabs_Shoppingflux_Model_Export_Config
105
- */
106
- public function getConfig() {
107
- return Mage::getSingleton('profileolabs_shoppingflux/config');
108
- }
109
-
110
- protected function arrayToNode($entry) {
111
- $node = "";
112
-
113
- foreach ($entry as $key => $value) {
114
-
115
- if (is_array($value)) {
116
- if (is_string($key))
117
- $node.= $this->getNode($key, $this->arrayToNode($value), 0);
118
- elseif (is_string(($subKey = current($value))))
119
- $node.= $this->getNode($subKey, $this->arrayToNode($value), 0);
120
- else
121
- $node.= $this->arrayToNode($value);
122
- }
123
- else
124
- $node .= $this->getNode($key, $value);
125
- }
126
-
127
-
128
- return $node;
129
- }
130
-
131
- protected function getNode($name, $value, $withCDATA = 1) {
132
- $value = $this->getHelper()->cleanNotUtf8($value);
133
- $openCDATA = "";
134
- $closeCDATA = "";
135
- if ($withCDATA) {
136
- $openCDATA = "<![CDATA[";
137
- $closeCDATA = "]]>";
138
- }
139
- return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>" . chr(10);
140
- }
141
-
142
- /**
143
- * Return Shoppingflu Helper
144
- * @return Profileolabs_Shoppingflux_Helper_Data
145
- */
146
- protected function getHelper() {
147
- return Mage::helper('profileolabs_shoppingflux');
148
- }
149
-
150
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Model_Export_Xml {
4
+
5
+
6
+ public function __construct() {
7
+
8
+ }
9
+
10
+ public function _addEntries($entries) {
11
+ foreach($entries as $entry) {
12
+ $this->_addEntry($entry);
13
+ }
14
+ }
15
+
16
+ public function _addEntry($entry) {
17
+ return "<product>" . chr(10) .
18
+ $this->arrayToNode($entry) .
19
+ "</product>" . chr(10);
20
+ }
21
+
22
+
23
+ public function getVersion() {
24
+ return Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
25
+ }
26
+
27
+ public function startXml($params=array()) {
28
+ $xml = '<?xml version="1.0" encoding="utf-8"?>' . chr(10) .
29
+ '<products version="' . $this->getVersion() . '"';
30
+ foreach($params as $attrName=>$attrValue) {
31
+ $xml .= ' ' . $attrName . '="' . $attrValue . '"';
32
+ }
33
+ $xml .= '>' . chr(10);
34
+ return $xml;
35
+ }
36
+
37
+ public function endXml() {
38
+ return "</products>" . chr(10);
39
+ }
40
+
41
+ protected $_attributes = array();
42
+ protected function _getAttribute($attributeCode) {
43
+ if(!isset($this->_attributes[$attributeCode])) {
44
+ $this->_attributes[$attributeCode] = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
45
+ }
46
+ return $this->_attributes[$attributeCode];
47
+ }
48
+
49
+ /*obsolete*/
50
+ public function extractData($nameNode, $attributeCode, $product) {
51
+
52
+ $_helper = Mage::helper('catalog/output');
53
+
54
+ $data = $product->getData($attributeCode);
55
+
56
+ $attribute = $this->_getAttribute($attributeCode);
57
+ if ($attribute) {
58
+ if($attribute->getFrontendInput() == 'date') {
59
+ return $data;
60
+ }
61
+
62
+ $data = $attribute->getFrontend()->getValue($product);
63
+ $data = $_helper->productAttribute($product, $data, $attributeCode);
64
+
65
+ if ($nameNode == 'ecotaxe' && $attribute->getFrontendInput() == 'weee') {
66
+ $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
67
+
68
+ foreach ($weeeAttributes as $wa) {
69
+ if ($wa->getCode() == $attributeCode) {
70
+ $data = round($wa->getAmount(), 2);
71
+ break;
72
+ }
73
+ }
74
+ }
75
+ }
76
+
77
+
78
+
79
+
80
+ //$_helper = Mage::helper('catalog/output');
81
+ //if($nameNode == 'description' || $nameNode == 'short_description')
82
+ //$data = $_helper->productAttribute($product, $data, $attributeCode);
83
+ //Synthetize it
84
+ /* $method = "get".ucfirst($attributeCode);
85
+ if(method_exists($product,$method))
86
+ $data = $product->$method(); */
87
+
88
+ //TODO remove this
89
+ if ($data == "No" || $data == "Non")
90
+ $data = "";
91
+
92
+ //Exceptions data
93
+ if ($nameNode == 'shipping_delay' && empty($data))
94
+ $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
95
+
96
+ if ($nameNode == 'quantity')
97
+ $data = round($data);
98
+
99
+ return $data;
100
+ }
101
+
102
+ /**
103
+ * Get singleton config for Export
104
+ * @return Profileolabs_Shoppingflux_Model_Export_Config
105
+ */
106
+ public function getConfig() {
107
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
108
+ }
109
+
110
+ protected function arrayToNode($entry) {
111
+ $node = "";
112
+
113
+ foreach ($entry as $key => $value) {
114
+
115
+ if (is_array($value)) {
116
+ if (is_string($key))
117
+ $node.= $this->getNode($key, $this->arrayToNode($value), 0);
118
+ elseif (is_string(($subKey = current($value))))
119
+ $node.= $this->getNode($subKey, $this->arrayToNode($value), 0);
120
+ else
121
+ $node.= $this->arrayToNode($value);
122
+ }
123
+ else
124
+ $node .= $this->getNode($key, $value);
125
+ }
126
+
127
+
128
+ return $node;
129
+ }
130
+
131
+ protected function getNode($name, $value, $withCDATA = 1) {
132
+ $value = $this->getHelper()->cleanNotUtf8($value);
133
+ $openCDATA = "";
134
+ $closeCDATA = "";
135
+ if ($withCDATA) {
136
+ $openCDATA = "<![CDATA[";
137
+ $closeCDATA = "]]>";
138
+ }
139
+ return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>" . chr(10);
140
+ }
141
+
142
+ /**
143
+ * Return Shoppingflu Helper
144
+ * @return Profileolabs_Shoppingflux_Helper_Data
145
+ */
146
+ protected function getHelper() {
147
+ return Mage::helper('profileolabs_shoppingflux');
148
+ }
149
+
150
  }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Xmlflow.deprecated.php CHANGED
@@ -1,251 +1,251 @@
1
- <?php
2
- class Profileolabs_Shoppingflux_Model_Export_Xmlflow
3
- {
4
- protected $_xmlArray = array();
5
-
6
- protected $_backendCacheAttributes = array();
7
-
8
- protected $_memoryManager = null;
9
-
10
- public function __construct()
11
- {
12
- $backendAttributes = array(
13
- 'cache_dir' => Mage::getBaseDir('cache'),
14
- 'hashed_directory_level' => 1,
15
- 'hashed_directory_umask' => 0777,
16
- 'file_name_prefix' => 'mage',
17
- );
18
- }
19
-
20
- public function getMemoryManager()
21
- {
22
- if(is_null($this->_memoryManager))
23
- {
24
- $this->_memoryManager = Zend_Memory::factory('File',$this->_backendCacheAttributes);
25
- }
26
-
27
- return $this->_memoryManager;
28
- }
29
-
30
- public function _addEntries($entries)
31
- {
32
- $this->_xmlArray = $entries;
33
- return $this;
34
- }
35
-
36
- public function _addEntry($entry)
37
- {
38
- $this->_xmlArray[] = $entry;
39
- return $this;
40
- }
41
-
42
- public function getXmlArray()
43
- {
44
- return $this->_xmlArray;
45
- }
46
-
47
-
48
- public function getVersion()
49
- {
50
- return Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
51
- }
52
-
53
- public function createXml()
54
- {
55
- try {
56
- if($this->useZendMemory())
57
- {
58
- $xmlFlow = "";
59
- $mem = $this->getMemoryManager()->create($xmlFlow);
60
-
61
- $mem->value = '<?xml version="1.0" encoding="utf-8"?>'.chr(10);
62
- $mem->value .= '<products count="'.count($this->_xmlArray).'" version="'.$this->getVersion().'">'.chr(10);
63
-
64
-
65
- foreach ($this->_xmlArray as $key=>$entry)
66
- {
67
-
68
- $mem->value .= "<product>".chr(10);
69
-
70
- $mem->value .= $this->arrayToNode($entry);
71
-
72
- $mem->value .= "</product>".chr(10);
73
- //unset($this->_xmlArray[$key]);
74
- }
75
-
76
- $mem->value .= "</products>".chr(10);
77
-
78
- return $mem->value;
79
- }
80
- else
81
- {
82
-
83
- $xmlFlow = '<?xml version="1.0" encoding="utf-8"?>'.chr(10);
84
- $xmlFlow .= '<products count="'.count($this->_xmlArray).'" version="'.$this->getVersion().'">'.chr(10);
85
-
86
- $i= 0;
87
- foreach ($this->_xmlArray as $key=>$entry)
88
- {
89
- //Mage::log("i = ".$i++,null,"test_sf.log");
90
- $xmlFlow .= "<product>".chr(10);
91
-
92
- $xmlFlow .= $this->arrayToNode($entry);
93
-
94
- $xmlFlow .= "</product>".chr(10);
95
- //unset($this->_xmlArray[$key]);
96
- }
97
-
98
- $xmlFlow .= "</products>".chr(10);
99
-
100
- return $xmlFlow;
101
- }
102
-
103
- } catch (Exception $e) {
104
- return $this->getHelper()->__('Error in processing xml. %s',$e->getMessage());
105
- }
106
- }
107
-
108
-
109
-
110
-
111
-
112
- public function extractData($nameNode,$attributeCode,$product)
113
- {
114
-
115
- $_helper = Mage::helper('catalog/output');
116
-
117
- $data = $product->getData($attributeCode);
118
-
119
- $attribute = $product->getResource()->getAttribute($attributeCode);
120
- if($attribute)
121
- {
122
- $data = $attribute->getFrontend()->getValue($product);
123
- $data = $_helper->productAttribute($product, $data, $attributeCode);
124
-
125
- if($nameNode == 'ecotaxe' && $attribute->getFrontendInput() == 'weee')
126
- {
127
- $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
128
-
129
- foreach ($weeeAttributes as $wa)
130
- {
131
- if($wa->getCode() == $attributeCode)
132
- {
133
- $data = round($wa->getAmount(),2);
134
- break;
135
- }
136
- }
137
- }
138
- }
139
-
140
-
141
-
142
-
143
- //$_helper = Mage::helper('catalog/output');
144
- //if($nameNode == 'description' || $nameNode == 'short_description')
145
- //$data = $_helper->productAttribute($product, $data, $attributeCode);
146
-
147
- //Synthetize it
148
- /*$method = "get".ucfirst($attributeCode);
149
- if(method_exists($product,$method))
150
- $data = $product->$method();*/
151
-
152
- //TODO remove this
153
- if($data== "No" || $data == "Non")
154
- $data = "";
155
-
156
- //Exceptions data
157
- if($nameNode == 'shipping_delay' && empty($data))
158
- $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
159
-
160
- if($nameNode == 'quantity')
161
- $data = round($data);
162
-
163
- return $data;
164
- }
165
-
166
- /**
167
- * Get singleton config for Export
168
- * @return Profileolabs_Shoppingflux_Model_Export_Config
169
- */
170
- public function getConfig()
171
- {
172
- return Mage::getSingleton('profileolabs_shoppingflux/config');
173
- }
174
-
175
- protected function arrayToNode($entry)
176
- {
177
- $node = "";
178
-
179
- if($this->useZendMemory())
180
- {
181
- $mem = $this->getMemoryManager()->create($node);
182
- foreach ($entry as $key=>$value) {
183
-
184
- if(is_array($value))
185
- {
186
- if(is_string($key))
187
- $mem->value.= $this->getNode($key, $this->arrayToNode($value),0);
188
- elseif(is_string(($subKey =current($value))))
189
- $mem->value.= $this->getNode($subKey, $this->arrayToNode($value),0);
190
- else
191
- $mem->value.= $this->arrayToNode($value);
192
- }
193
- else
194
- $mem->value .= $this->getNode($key, $value);
195
- }
196
-
197
-
198
- return $mem->value;
199
- }
200
- else
201
- {
202
-
203
- foreach ($entry as $key=>$value) {
204
-
205
- if(is_array($value))
206
- {
207
- if(is_string($key))
208
- $node.= $this->getNode($key, $this->arrayToNode($value),0);
209
- elseif(is_string(($subKey =current($value))))
210
- $node.= $this->getNode($subKey, $this->arrayToNode($value),0);
211
- else
212
- $node.= $this->arrayToNode($value);
213
- }
214
- else
215
- $node .= $this->getNode($key, $value);
216
- }
217
-
218
-
219
- return $node;
220
- }
221
- }
222
-
223
- protected function useZendMemory()
224
- {
225
- return false;
226
- }
227
-
228
- protected function getNode($name,$value,$withCDATA = 1)
229
- {
230
- $value = $this->getHelper()->cleanNotUtf8($value);
231
- $openCDATA = "";
232
- $closeCDATA = "";
233
- if($withCDATA)
234
- {
235
- $openCDATA = "<![CDATA[";
236
- $closeCDATA = "]]>";
237
- }
238
- return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>".chr(10);
239
- }
240
-
241
- /**
242
- * Return Shoppingflu Helper
243
- * @return Profileolabs_Shoppingflux_Helper_Data
244
- */
245
- protected function getHelper()
246
- {
247
- return Mage::helper('profileolabs_shoppingflux');
248
- }
249
-
250
-
251
  }
1
+ <?php
2
+ class Profileolabs_Shoppingflux_Model_Export_Xmlflow
3
+ {
4
+ protected $_xmlArray = array();
5
+
6
+ protected $_backendCacheAttributes = array();
7
+
8
+ protected $_memoryManager = null;
9
+
10
+ public function __construct()
11
+ {
12
+ $backendAttributes = array(
13
+ 'cache_dir' => Mage::getBaseDir('cache'),
14
+ 'hashed_directory_level' => 1,
15
+ 'hashed_directory_umask' => 0777,
16
+ 'file_name_prefix' => 'mage',
17
+ );
18
+ }
19
+
20
+ public function getMemoryManager()
21
+ {
22
+ if(is_null($this->_memoryManager))
23
+ {
24
+ $this->_memoryManager = Zend_Memory::factory('File',$this->_backendCacheAttributes);
25
+ }
26
+
27
+ return $this->_memoryManager;
28
+ }
29
+
30
+ public function _addEntries($entries)
31
+ {
32
+ $this->_xmlArray = $entries;
33
+ return $this;
34
+ }
35
+
36
+ public function _addEntry($entry)
37
+ {
38
+ $this->_xmlArray[] = $entry;
39
+ return $this;
40
+ }
41
+
42
+ public function getXmlArray()
43
+ {
44
+ return $this->_xmlArray;
45
+ }
46
+
47
+
48
+ public function getVersion()
49
+ {
50
+ return Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
51
+ }
52
+
53
+ public function createXml()
54
+ {
55
+ try {
56
+ if($this->useZendMemory())
57
+ {
58
+ $xmlFlow = "";
59
+ $mem = $this->getMemoryManager()->create($xmlFlow);
60
+
61
+ $mem->value = '<?xml version="1.0" encoding="utf-8"?>'.chr(10);
62
+ $mem->value .= '<products count="'.count($this->_xmlArray).'" version="'.$this->getVersion().'">'.chr(10);
63
+
64
+
65
+ foreach ($this->_xmlArray as $key=>$entry)
66
+ {
67
+
68
+ $mem->value .= "<product>".chr(10);
69
+
70
+ $mem->value .= $this->arrayToNode($entry);
71
+
72
+ $mem->value .= "</product>".chr(10);
73
+ //unset($this->_xmlArray[$key]);
74
+ }
75
+
76
+ $mem->value .= "</products>".chr(10);
77
+
78
+ return $mem->value;
79
+ }
80
+ else
81
+ {
82
+
83
+ $xmlFlow = '<?xml version="1.0" encoding="utf-8"?>'.chr(10);
84
+ $xmlFlow .= '<products count="'.count($this->_xmlArray).'" version="'.$this->getVersion().'">'.chr(10);
85
+
86
+ $i= 0;
87
+ foreach ($this->_xmlArray as $key=>$entry)
88
+ {
89
+ //Mage::log("i = ".$i++,null,"test_sf.log");
90
+ $xmlFlow .= "<product>".chr(10);
91
+
92
+ $xmlFlow .= $this->arrayToNode($entry);
93
+
94
+ $xmlFlow .= "</product>".chr(10);
95
+ //unset($this->_xmlArray[$key]);
96
+ }
97
+
98
+ $xmlFlow .= "</products>".chr(10);
99
+
100
+ return $xmlFlow;
101
+ }
102
+
103
+ } catch (Exception $e) {
104
+ return $this->getHelper()->__('Error in processing xml. %s',$e->getMessage());
105
+ }
106
+ }
107
+
108
+
109
+
110
+
111
+
112
+ public function extractData($nameNode,$attributeCode,$product)
113
+ {
114
+
115
+ $_helper = Mage::helper('catalog/output');
116
+
117
+ $data = $product->getData($attributeCode);
118
+
119
+ $attribute = $product->getResource()->getAttribute($attributeCode);
120
+ if($attribute)
121
+ {
122
+ $data = $attribute->getFrontend()->getValue($product);
123
+ $data = $_helper->productAttribute($product, $data, $attributeCode);
124
+
125
+ if($nameNode == 'ecotaxe' && $attribute->getFrontendInput() == 'weee')
126
+ {
127
+ $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
128
+
129
+ foreach ($weeeAttributes as $wa)
130
+ {
131
+ if($wa->getCode() == $attributeCode)
132
+ {
133
+ $data = round($wa->getAmount(),2);
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+
141
+
142
+
143
+ //$_helper = Mage::helper('catalog/output');
144
+ //if($nameNode == 'description' || $nameNode == 'short_description')
145
+ //$data = $_helper->productAttribute($product, $data, $attributeCode);
146
+
147
+ //Synthetize it
148
+ /*$method = "get".ucfirst($attributeCode);
149
+ if(method_exists($product,$method))
150
+ $data = $product->$method();*/
151
+
152
+ //TODO remove this
153
+ if($data== "No" || $data == "Non")
154
+ $data = "";
155
+
156
+ //Exceptions data
157
+ if($nameNode == 'shipping_delay' && empty($data))
158
+ $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
159
+
160
+ if($nameNode == 'quantity')
161
+ $data = round($data);
162
+
163
+ return $data;
164
+ }
165
+
166
+ /**
167
+ * Get singleton config for Export
168
+ * @return Profileolabs_Shoppingflux_Model_Export_Config
169
+ */
170
+ public function getConfig()
171
+ {
172
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
173
+ }
174
+
175
+ protected function arrayToNode($entry)
176
+ {
177
+ $node = "";
178
+
179
+ if($this->useZendMemory())
180
+ {
181
+ $mem = $this->getMemoryManager()->create($node);
182
+ foreach ($entry as $key=>$value) {
183
+
184
+ if(is_array($value))
185
+ {
186
+ if(is_string($key))
187
+ $mem->value.= $this->getNode($key, $this->arrayToNode($value),0);
188
+ elseif(is_string(($subKey =current($value))))
189
+ $mem->value.= $this->getNode($subKey, $this->arrayToNode($value),0);
190
+ else
191
+ $mem->value.= $this->arrayToNode($value);
192
+ }
193
+ else
194
+ $mem->value .= $this->getNode($key, $value);
195
+ }
196
+
197
+
198
+ return $mem->value;
199
+ }
200
+ else
201
+ {
202
+
203
+ foreach ($entry as $key=>$value) {
204
+
205
+ if(is_array($value))
206
+ {
207
+ if(is_string($key))
208
+ $node.= $this->getNode($key, $this->arrayToNode($value),0);
209
+ elseif(is_string(($subKey =current($value))))
210
+ $node.= $this->getNode($subKey, $this->arrayToNode($value),0);
211
+ else
212
+ $node.= $this->arrayToNode($value);
213
+ }
214
+ else
215
+ $node .= $this->getNode($key, $value);
216
+ }
217
+
218
+
219
+ return $node;
220
+ }
221
+ }
222
+
223
+ protected function useZendMemory()
224
+ {
225
+ return false;
226
+ }
227
+
228
+ protected function getNode($name,$value,$withCDATA = 1)
229
+ {
230
+ $value = $this->getHelper()->cleanNotUtf8($value);
231
+ $openCDATA = "";
232
+ $closeCDATA = "";
233
+ if($withCDATA)
234
+ {
235
+ $openCDATA = "<![CDATA[";
236
+ $closeCDATA = "]]>";
237
+ }
238
+ return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>".chr(10);
239
+ }
240
+
241
+ /**
242
+ * Return Shoppingflu Helper
243
+ * @return Profileolabs_Shoppingflux_Helper_Data
244
+ */
245
+ protected function getHelper()
246
+ {
247
+ return Mage::helper('profileolabs_shoppingflux');
248
+ }
249
+
250
+
251
  }
app/code/community/Profileolabs/Shoppingflux/Model/Export/Xmlflow.php CHANGED
@@ -1,140 +1,140 @@
1
- <?php
2
- // V1 DEPRECATED
3
- class Profileolabs_Shoppingflux_Model_Export_Xmlflow {
4
-
5
-
6
- public function __construct() {
7
-
8
- }
9
-
10
- public function _addEntries($entries) {
11
- foreach($entries as $entry) {
12
- $this->_addEntry($entry);
13
- }
14
- }
15
-
16
- public function _addEntry($entry) {
17
- echo "<product>" . chr(10);
18
- echo $this->arrayToNode($entry);
19
- echo "</product>" . chr(10);
20
- }
21
-
22
-
23
- public function getVersion() {
24
- return Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
25
- }
26
-
27
- public function startXml($size) {
28
- echo '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
29
- echo '<products version="' . $this->getVersion() . '">' . chr(10);
30
- }
31
-
32
- public function endXml() {
33
- echo "</products>" . chr(10);
34
- }
35
-
36
- protected $_attributes = array();
37
- protected function _getAttribute($attributeCode) {
38
- if(!isset($this->_attributes[$attributeCode])) {
39
- $this->_attributes[$attributeCode] = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
40
- }
41
- return $this->_attributes[$attributeCode];
42
- }
43
-
44
- public function extractData($nameNode, $attributeCode, $product) {
45
-
46
- $_helper = Mage::helper('catalog/output');
47
-
48
- $data = $product->getData($attributeCode);
49
-
50
- $attribute = $this->_getAttribute($attributeCode);
51
- if ($attribute) {
52
- $data = $attribute->getFrontend()->getValue($product);
53
- $data = $_helper->productAttribute($product, $data, $attributeCode);
54
-
55
- if ($nameNode == 'ecotaxe' && $attribute->getFrontendInput() == 'weee') {
56
- $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
57
-
58
- foreach ($weeeAttributes as $wa) {
59
- if ($wa->getCode() == $attributeCode) {
60
- $data = round($wa->getAmount(), 2);
61
- break;
62
- }
63
- }
64
- }
65
- }
66
-
67
-
68
-
69
-
70
- //$_helper = Mage::helper('catalog/output');
71
- //if($nameNode == 'description' || $nameNode == 'short_description')
72
- //$data = $_helper->productAttribute($product, $data, $attributeCode);
73
- //Synthetize it
74
- /* $method = "get".ucfirst($attributeCode);
75
- if(method_exists($product,$method))
76
- $data = $product->$method(); */
77
-
78
- //TODO remove this
79
- if ($data == "No" || $data == "Non")
80
- $data = "";
81
-
82
- //Exceptions data
83
- if ($nameNode == 'shipping_delay' && empty($data))
84
- $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
85
-
86
- if ($nameNode == 'quantity')
87
- $data = round($data);
88
-
89
- return $data;
90
- }
91
-
92
- /**
93
- * Get singleton config for Export
94
- * @return Profileolabs_Shoppingflux_Model_Export_Config
95
- */
96
- public function getConfig() {
97
- return Mage::getSingleton('profileolabs_shoppingflux/config');
98
- }
99
-
100
- protected function arrayToNode($entry) {
101
- $node = "";
102
-
103
- foreach ($entry as $key => $value) {
104
-
105
- if (is_array($value)) {
106
- if (is_string($key))
107
- $node.= $this->getNode($key, $this->arrayToNode($value), 0);
108
- elseif (is_string(($subKey = current($value))))
109
- $node.= $this->getNode($subKey, $this->arrayToNode($value), 0);
110
- else
111
- $node.= $this->arrayToNode($value);
112
- }
113
- else
114
- $node .= $this->getNode($key, $value);
115
- }
116
-
117
-
118
- return $node;
119
- }
120
-
121
- protected function getNode($name, $value, $withCDATA = 1) {
122
- $value = $this->getHelper()->cleanNotUtf8($value);
123
- $openCDATA = "";
124
- $closeCDATA = "";
125
- if ($withCDATA) {
126
- $openCDATA = "<![CDATA[";
127
- $closeCDATA = "]]>";
128
- }
129
- return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>" . chr(10);
130
- }
131
-
132
- /**
133
- * Return Shoppingflu Helper
134
- * @return Profileolabs_Shoppingflux_Helper_Data
135
- */
136
- protected function getHelper() {
137
- return Mage::helper('profileolabs_shoppingflux');
138
- }
139
-
140
  }
1
+ <?php
2
+ // V1 DEPRECATED
3
+ class Profileolabs_Shoppingflux_Model_Export_Xmlflow {
4
+
5
+
6
+ public function __construct() {
7
+
8
+ }
9
+
10
+ public function _addEntries($entries) {
11
+ foreach($entries as $entry) {
12
+ $this->_addEntry($entry);
13
+ }
14
+ }
15
+
16
+ public function _addEntry($entry) {
17
+ echo "<product>" . chr(10);
18
+ echo $this->arrayToNode($entry);
19
+ echo "</product>" . chr(10);
20
+ }
21
+
22
+
23
+ public function getVersion() {
24
+ return Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version;
25
+ }
26
+
27
+ public function startXml($size) {
28
+ echo '<?xml version="1.0" encoding="utf-8"?>' . chr(10);
29
+ echo '<products version="' . $this->getVersion() . '">' . chr(10);
30
+ }
31
+
32
+ public function endXml() {
33
+ echo "</products>" . chr(10);
34
+ }
35
+
36
+ protected $_attributes = array();
37
+ protected function _getAttribute($attributeCode) {
38
+ if(!isset($this->_attributes[$attributeCode])) {
39
+ $this->_attributes[$attributeCode] = Mage::getSingleton('eav/config')->getAttribute('catalog_product', $attributeCode);
40
+ }
41
+ return $this->_attributes[$attributeCode];
42
+ }
43
+
44
+ public function extractData($nameNode, $attributeCode, $product) {
45
+
46
+ $_helper = Mage::helper('catalog/output');
47
+
48
+ $data = $product->getData($attributeCode);
49
+
50
+ $attribute = $this->_getAttribute($attributeCode);
51
+ if ($attribute) {
52
+ $data = $attribute->getFrontend()->getValue($product);
53
+ $data = $_helper->productAttribute($product, $data, $attributeCode);
54
+
55
+ if ($nameNode == 'ecotaxe' && $attribute->getFrontendInput() == 'weee') {
56
+ $weeeAttributes = Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product);
57
+
58
+ foreach ($weeeAttributes as $wa) {
59
+ if ($wa->getCode() == $attributeCode) {
60
+ $data = round($wa->getAmount(), 2);
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ }
66
+
67
+
68
+
69
+
70
+ //$_helper = Mage::helper('catalog/output');
71
+ //if($nameNode == 'description' || $nameNode == 'short_description')
72
+ //$data = $_helper->productAttribute($product, $data, $attributeCode);
73
+ //Synthetize it
74
+ /* $method = "get".ucfirst($attributeCode);
75
+ if(method_exists($product,$method))
76
+ $data = $product->$method(); */
77
+
78
+ //TODO remove this
79
+ if ($data == "No" || $data == "Non")
80
+ $data = "";
81
+
82
+ //Exceptions data
83
+ if ($nameNode == 'shipping_delay' && empty($data))
84
+ $data = $this->getConfig()->getConfigData('shoppingflux_export/general/default_shipping_delay');
85
+
86
+ if ($nameNode == 'quantity')
87
+ $data = round($data);
88
+
89
+ return $data;
90
+ }
91
+
92
+ /**
93
+ * Get singleton config for Export
94
+ * @return Profileolabs_Shoppingflux_Model_Export_Config
95
+ */
96
+ public function getConfig() {
97
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
98
+ }
99
+
100
+ protected function arrayToNode($entry) {
101
+ $node = "";
102
+
103
+ foreach ($entry as $key => $value) {
104
+
105
+ if (is_array($value)) {
106
+ if (is_string($key))
107
+ $node.= $this->getNode($key, $this->arrayToNode($value), 0);
108
+ elseif (is_string(($subKey = current($value))))
109
+ $node.= $this->getNode($subKey, $this->arrayToNode($value), 0);
110
+ else
111
+ $node.= $this->arrayToNode($value);
112
+ }
113
+ else
114
+ $node .= $this->getNode($key, $value);
115
+ }
116
+
117
+
118
+ return $node;
119
+ }
120
+
121
+ protected function getNode($name, $value, $withCDATA = 1) {
122
+ $value = $this->getHelper()->cleanNotUtf8($value);
123
+ $openCDATA = "";
124
+ $closeCDATA = "";
125
+ if ($withCDATA) {
126
+ $openCDATA = "<![CDATA[";
127
+ $closeCDATA = "]]>";
128
+ }
129
+ return "<{$name}>{$openCDATA}{$value}{$closeCDATA}</{$name}>" . chr(10);
130
+ }
131
+
132
+ /**
133
+ * Return Shoppingflu Helper
134
+ * @return Profileolabs_Shoppingflux_Helper_Data
135
+ */
136
+ protected function getHelper() {
137
+ return Mage::helper('profileolabs_shoppingflux');
138
+ }
139
+
140
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Convert/Customer.php CHANGED
@@ -1,118 +1,118 @@
1
- <?php
2
-
3
- /**
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux_Model_Manageorders
6
- * @author kassim belghait, vincent enjalbert @ web-cooking.net
7
- *
8
- */
9
- class Profileolabs_Shoppingflux_Model_Manageorders_Convert_Customer extends Varien_Object {
10
-
11
- /**
12
- * Convert xml node to customer model
13
- *
14
- * @param array $data
15
- * @return Mage_Customer_Model_Customer
16
- */
17
- public function toCustomer(array $data, $storeId, $customer = null) {
18
- /* @var $customer Mage_Customer_Model_Customer */
19
- $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
20
- if (!($customer instanceof Mage_Customer_Model_Customer)) {
21
- $customer = Mage::getModel('customer/customer')->setWebsiteId($websiteId)
22
- ->loadByEmail($data['Email']);
23
- $customer->setImportMode(true);
24
-
25
- if (!$customer->getId()) {
26
- $customer->setWebsiteId($websiteId);
27
- $customer->setConfirmation(null);
28
- $customer->setForceConfirmed(true);
29
- $customer->setPasswordHash($customer->hashPassword($customer->generatePassword(8)));
30
- $customer->setFromShoppingflux(1);
31
- }
32
- }
33
-
34
- Mage::helper('core')->copyFieldset('shoppingflux_convert_customer', 'to_customer', $data, $customer);
35
- if ($customer->getFirstname() == "")
36
- $customer->setFirstname('__');
37
-
38
-
39
-
40
- return $customer;
41
- }
42
-
43
- /**
44
- * Convert xml node to customer address model
45
- *
46
- * @param array $data
47
- * @return Mage_Customer_Model_Address
48
- */
49
- public function addresstoCustomer(array $data, $storeId, $customer = null, $type = 'billing') {
50
- /* @var $customer Mage_Customer_Model_Customer */
51
- if (!($customer instanceof Mage_Customer_Model_Customer)) {
52
-
53
- $customer = $this->toCustomer($data, $storeId);
54
- }
55
-
56
- /* @var $address Mage_Customer_Model_Address */
57
- $address = Mage::getModel('customer/address');
58
- $address->setId(null);
59
- $address->setIsDefaultBilling(true);
60
- $address->setIsDefaultShipping(false);
61
- if ($type == "shipping") {
62
- $address->setIsDefaultBilling(false);
63
- $address->setIsDefaultShipping(true);
64
- }
65
-
66
- Mage::helper('core')->copyFieldset('shoppingflux_convert_customer', 'to_customer_address', $data, $address);
67
-
68
- if ($address->getFirstname() == "")
69
- $address->setFirstname(' __ ');
70
-
71
- if (strpos(strtolower($address->getCountryId()), 'france') !== false)
72
- $address->setCountryId('FR');
73
-
74
- if ($address->getTelephone() == "" && $data['PhoneMobile'])
75
- $address->setTelephone($data['PhoneMobile']);
76
-
77
- $address->setStreet(array($data['Street1'], $data['Street2']));
78
-
79
- if($data['PhoneMobile'] && strlen(trim($data['PhoneMobile'])) >= 9) {
80
- if(Mage::getSingleton('profileolabs_shoppingflux/config')->getMobilePhoneAttribute($storeId)) {
81
- $customer->setData(Mage::getSingleton('profileolabs_shoppingflux/config')->getMobilePhoneAttribute(), $data['PhoneMobile']);
82
- } else if(Mage::getSingleton('profileolabs_shoppingflux/config')->preferMobilePhone($storeId)) {
83
- $address->setTelephone($data['PhoneMobile']);
84
- }
85
- }
86
-
87
- $codeRegion = substr(str_pad($address->getPostcode(), 5, "0", STR_PAD_LEFT), 0, 2);
88
-
89
- //$regionId = Mage::getModel('directory/region')->loadByCode($codeRegion,$address->getCountry())->getId();
90
- $regionId = Mage::getModel('directory/region')->getCollection()
91
- ->addRegionCodeFilter($codeRegion)
92
- ->addCountryFilter($address->getCountry())
93
- ->getFirstItem()
94
- ->getId();
95
-
96
- if ($regionId)
97
- $address->setRegionId($regionId);
98
- else
99
- $address->setRegionId(182); //Ain pour le pays FR
100
-
101
-
102
- if(Mage::getSingleton('profileolabs_shoppingflux/config')->getAddressLengthLimit($storeId)) {
103
- $limit = Mage::getSingleton('profileolabs_shoppingflux/config')->getAddressLengthLimit($storeId);
104
- $streets = $address->getStreet();
105
- $nStreets = array();
106
- foreach($streets as $street) {
107
- if(strlen($street) > $limit) {
108
- $nStreets = array_merge($nStreets, Mage::helper('profileolabs_shoppingflux')->truncateAddress($street, $limit));
109
- } else {
110
- $nStreets[] = $street;
111
- }
112
- }
113
- $address->setStreet($nStreets);
114
- }
115
- return $address;
116
- }
117
-
118
  }
1
+ <?php
2
+
3
+ /**
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux_Model_Manageorders
6
+ * @author kassim belghait, vincent enjalbert @ web-cooking.net
7
+ *
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Manageorders_Convert_Customer extends Varien_Object {
10
+
11
+ /**
12
+ * Convert xml node to customer model
13
+ *
14
+ * @param array $data
15
+ * @return Mage_Customer_Model_Customer
16
+ */
17
+ public function toCustomer(array $data, $storeId, $customer = null) {
18
+ /* @var $customer Mage_Customer_Model_Customer */
19
+ $websiteId = Mage::app()->getStore($storeId)->getWebsiteId();
20
+ if (!($customer instanceof Mage_Customer_Model_Customer)) {
21
+ $customer = Mage::getModel('customer/customer')->setWebsiteId($websiteId)
22
+ ->loadByEmail($data['Email']);
23
+ $customer->setImportMode(true);
24
+
25
+ if (!$customer->getId()) {
26
+ $customer->setWebsiteId($websiteId);
27
+ $customer->setConfirmation(null);
28
+ $customer->setForceConfirmed(true);
29
+ $customer->setPasswordHash($customer->hashPassword($customer->generatePassword(8)));
30
+ $customer->setFromShoppingflux(1);
31
+ }
32
+ }
33
+
34
+ Mage::helper('core')->copyFieldset('shoppingflux_convert_customer', 'to_customer', $data, $customer);
35
+ if ($customer->getFirstname() == "")
36
+ $customer->setFirstname('__');
37
+
38
+
39
+
40
+ return $customer;
41
+ }
42
+
43
+ /**
44
+ * Convert xml node to customer address model
45
+ *
46
+ * @param array $data
47
+ * @return Mage_Customer_Model_Address
48
+ */
49
+ public function addresstoCustomer(array $data, $storeId, $customer = null, $type = 'billing') {
50
+ /* @var $customer Mage_Customer_Model_Customer */
51
+ if (!($customer instanceof Mage_Customer_Model_Customer)) {
52
+
53
+ $customer = $this->toCustomer($data, $storeId);
54
+ }
55
+
56
+ /* @var $address Mage_Customer_Model_Address */
57
+ $address = Mage::getModel('customer/address');
58
+ $address->setId(null);
59
+ $address->setIsDefaultBilling(true);
60
+ $address->setIsDefaultShipping(false);
61
+ if ($type == "shipping") {
62
+ $address->setIsDefaultBilling(false);
63
+ $address->setIsDefaultShipping(true);
64
+ }
65
+
66
+ Mage::helper('core')->copyFieldset('shoppingflux_convert_customer', 'to_customer_address', $data, $address);
67
+
68
+ if ($address->getFirstname() == "")
69
+ $address->setFirstname(' __ ');
70
+
71
+ if (strpos(strtolower($address->getCountryId()), 'france') !== false)
72
+ $address->setCountryId('FR');
73
+
74
+ if ($address->getTelephone() == "" && $data['PhoneMobile'])
75
+ $address->setTelephone($data['PhoneMobile']);
76
+
77
+ $address->setStreet(array($data['Street1'], $data['Street2']));
78
+
79
+ if($data['PhoneMobile'] && strlen(trim($data['PhoneMobile'])) >= 9) {
80
+ if(Mage::getSingleton('profileolabs_shoppingflux/config')->getMobilePhoneAttribute($storeId)) {
81
+ $customer->setData(Mage::getSingleton('profileolabs_shoppingflux/config')->getMobilePhoneAttribute(), $data['PhoneMobile']);
82
+ } else if(Mage::getSingleton('profileolabs_shoppingflux/config')->preferMobilePhone($storeId)) {
83
+ $address->setTelephone($data['PhoneMobile']);
84
+ }
85
+ }
86
+
87
+ $codeRegion = substr(str_pad($address->getPostcode(), 5, "0", STR_PAD_LEFT), 0, 2);
88
+
89
+ //$regionId = Mage::getModel('directory/region')->loadByCode($codeRegion,$address->getCountry())->getId();
90
+ $regionId = Mage::getModel('directory/region')->getCollection()
91
+ ->addRegionCodeFilter($codeRegion)
92
+ ->addCountryFilter($address->getCountry())
93
+ ->getFirstItem()
94
+ ->getId();
95
+
96
+ if ($regionId)
97
+ $address->setRegionId($regionId);
98
+ else
99
+ $address->setRegionId(182); //Ain pour le pays FR
100
+
101
+
102
+ if(Mage::getSingleton('profileolabs_shoppingflux/config')->getAddressLengthLimit($storeId)) {
103
+ $limit = Mage::getSingleton('profileolabs_shoppingflux/config')->getAddressLengthLimit($storeId);
104
+ $streets = $address->getStreet();
105
+ $nStreets = array();
106
+ foreach($streets as $street) {
107
+ if(strlen($street) > $limit) {
108
+ $nStreets = array_merge($nStreets, Mage::helper('profileolabs_shoppingflux')->truncateAddress($street, $limit));
109
+ } else {
110
+ $nStreets[] = $street;
111
+ }
112
+ }
113
+ $address->setStreet($nStreets);
114
+ }
115
+ return $address;
116
+ }
117
+
118
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Export/Shipments.php CHANGED
@@ -1,20 +1,20 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_Shoppingflux
5
- * @author Vincent Enjalbert @ Web-cooking.net
6
- */
7
- class Profileolabs_Shoppingflux_Model_Manageorders_Export_Shipments extends Mage_Core_Model_Abstract
8
- {
9
- protected function _construct()
10
- {
11
- $this->_init('profileolabs_shoppingflux/manageorders_export_shipments');
12
- }
13
-
14
- public function scheduleShipmentExport($shipmentId) {
15
- $this->setUpdateId(null)->setShipmentId($shipmentId)->setUpdatedAt(date('Y-m-d H:i:s'))->save();
16
- return $this;
17
- }
18
-
19
-
20
  }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_Shoppingflux
5
+ * @author Vincent Enjalbert @ Web-cooking.net
6
+ */
7
+ class Profileolabs_Shoppingflux_Model_Manageorders_Export_Shipments extends Mage_Core_Model_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('profileolabs_shoppingflux/manageorders_export_shipments');
12
+ }
13
+
14
+ public function scheduleShipmentExport($shipmentId) {
15
+ $this->setUpdateId(null)->setShipmentId($shipmentId)->setUpdatedAt(date('Y-m-d H:i:s'))->save();
16
+ return $this;
17
+ }
18
+
19
+
20
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Log.php CHANGED
@@ -1,36 +1,36 @@
1
- <?php
2
- /**
3
- * Error Log
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- *
8
- */
9
- class Profileolabs_Shoppingflux_Model_Manageorders_Log extends Mage_Core_Model_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/manageorders_log');
14
- }
15
-
16
- /**
17
- * Save message event
18
- * @param $message string
19
- * @param $orderId int
20
- */
21
- public function log($message,$orderId = null)
22
- {
23
- $orderMessage ="";
24
- if(!is_null($orderId))
25
- {
26
- $orderMessage = Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux Order ID : #%s (store %s)', $orderId, Mage::app()->getStore()->getId());
27
- }
28
-
29
- $message = $orderMessage.' / '.$message;
30
-
31
- $this->setMessage($message);
32
-
33
- return $this->save();
34
- }
35
-
36
  }
1
+ <?php
2
+ /**
3
+ * Error Log
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ *
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Manageorders_Log extends Mage_Core_Model_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/manageorders_log');
14
+ }
15
+
16
+ /**
17
+ * Save message event
18
+ * @param $message string
19
+ * @param $orderId int
20
+ */
21
+ public function log($message,$orderId = null)
22
+ {
23
+ $orderMessage ="";
24
+ if(!is_null($orderId))
25
+ {
26
+ $orderMessage = Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux Order ID : #%s (store %s)', $orderId, Mage::app()->getStore()->getId());
27
+ }
28
+
29
+ $message = $orderMessage.' / '.$message;
30
+
31
+ $this->setMessage($message);
32
+
33
+ return $this->save();
34
+ }
35
+
36
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Observer.php CHANGED
@@ -1,253 +1,306 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Model_Manageorders_Observer {
4
-
5
- public function setCustomerTaxClassId($observer) {
6
- if (!$this->getConfig()->applyTax() && Mage::registry('is_shoppingfeed_import')/*Mage::getSingleton('checkout/session')->getIsShoppingFlux()*/) {
7
- $customerGroup = $observer->getEvent()->getObject();
8
- $customerGroup->setData('tax_class_id', 999);
9
- }
10
- }
11
-
12
- public function manageOrders($observer=false) {
13
- try {
14
- set_time_limit(0);
15
- Mage::getModel('profileolabs_shoppingflux/manageorders_order')->manageOrders();
16
- } catch (Exception $e) {
17
- Mage::throwException($e);
18
- }
19
-
20
- return $this;
21
- }
22
-
23
- public function getShipmentTrackingNumber($shipment) {
24
- $result = false;
25
- $tracks = $shipment->getAllTracks();
26
- $trackUrl = '';
27
- if (is_array($tracks) && !empty($tracks)) {
28
- $firstTrack = array_shift($tracks);
29
- if($firstTrack) {
30
- $carrierInstance = Mage::getSingleton('shipping/config')->getCarrierInstance($firstTrack->getCarrierCode());
31
- if ($carrierInstance) {
32
- $trackingInfo = $carrierInstance->getTrackingInfo($firstTrack->getData('number'));
33
- $status = $trackingInfo->getStatus();
34
- if (preg_match('%href="(.*)"%i', $status, $regs)) {
35
- $trackUrl = $regs[1];
36
- }
37
- }
38
- }
39
- if (trim($firstTrack->getData('number'))) {
40
- $result = array('trackUrl' => $trackUrl, 'trackId' => $firstTrack->getData('number'), 'trackTitle' => $firstTrack->getData('title'));
41
- }
42
- }
43
- $dataObj = new Varien_Object(array('result' => $result, 'shipment'=>$shipment));
44
- Mage::dispatchEvent('shoppingflux_get_shipment_tracking', array('data_obj' => $dataObj));
45
- $result = $dataObj->getResult();
46
-
47
- return $result;
48
- }
49
-
50
- public function sendStatusCanceled($observer) {
51
- $order = $observer->getEvent()->getOrder();
52
- if (!$order->getFromShoppingflux())
53
- return $this;
54
-
55
-
56
- $storeId = $order->getStoreId();
57
-
58
- $apiKey = $this->getConfig()->getApiKey($storeId);
59
- $wsUri = $this->getConfig()->getWsUri();
60
-
61
-
62
- $orderIdShoppingflux = $order->getOrderIdShoppingflux();
63
- $marketPlace = $order->getMarketplaceShoppingflux();
64
-
65
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
66
-
67
- try {
68
- $service->updateCanceledOrder(
69
- $orderIdShoppingflux, $marketPlace, Profileolabs_Shoppingflux_Model_Service::ORDER_STATUS_CANCELED
70
- );
71
- } catch(Exception $e) {
72
-
73
- }
74
-
75
- Mage::helper('profileolabs_shoppingflux')->log('Order ' . $orderIdShoppingflux . ' has been canceled. Information sent to ShoppingFlux.');
76
-
77
-
78
- }
79
-
80
-
81
- public function scheduleShipmentUpdate($observer) {
82
- $shipment = $observer->getShipment();
83
- Mage::getModel('profileolabs_shoppingflux/manageorders_export_shipments')->scheduleShipmentExport($shipment->getId());
84
- }
85
-
86
- public function sendScheduledShipments() {
87
- $collection = Mage::getModel('profileolabs_shoppingflux/manageorders_export_shipments')->getCollection();
88
- //$collection->addFieldToFilter('updated_at', array('lt'=>new Zend_Db_Expr("DATE_SUB('".date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time()))."', INTERVAL 60 MINUTE)")));
89
- foreach($collection as $item) {
90
- try {
91
- $shipment = Mage::getModel('sales/order_shipment')->load($item->getShipmentId());
92
- if(Mage::app()->getStore()->getCode() == 'admin' || Mage::app()->getStore()->getId() == $shipment->getStoreId()) {
93
- $trakingInfos = $this->getShipmentTrackingNumber($shipment);
94
- if($trakingInfos || $shipment->getUpdatedAt() < $this->getConfig()->getShipmentUpdateLimit()) {
95
- $this->sendStatusShipped($shipment);
96
- $item->delete();
97
- }
98
- }
99
- } catch(Exception $e) {
100
- $shipment = Mage::getModel('sales/order_shipment')->load($item->getShipmentId());
101
- $message = 'Erreur de mise à jour de l\'expédition #'.$shipment->getIncrementId().' (commande #'.$shipment->getOrder()->getIncrementId().') : <br/>' . $e->getMessage();
102
- $message .= "<br/><br/> Merci de vérifier les infos de votre commandes ou de contacter le support Shopping Flux ou celui de la place de marché";
103
- $this->getHelper()->notifyError($message);
104
- if($item->getId() && !preg_match('%Error in cURL request: connect.. timed out%', $message) && !preg_match('%Result is not Varien_Simplexml_Element%', $message)) {
105
- try {
106
- $item->delete();
107
- } catch(Exception $e) {}
108
- }
109
- }
110
- }
111
- return $this;
112
- }
113
-
114
- public function sendStatusShipped($shipment) {
115
- if(!$shipment->getId())
116
- return $this;
117
-
118
- $shipmentId = $shipment->getId();
119
- $order = $shipment->getOrder();
120
- $storeId = $order->getStoreId();
121
-
122
- $apiKey = $this->getConfig()->getApiKey($storeId);
123
- $wsUri = $this->getConfig()->getWsUri();
124
-
125
- //Mage::log("order = ".print_r($order->debug(),true),null,'debug_update_status_sf.log');
126
-
127
- if (!$order->getFromShoppingflux())
128
- return $this;
129
-
130
- if($order->getShoppingfluxShipmentFlag()) {
131
- return $this;
132
- }
133
-
134
- $trakingInfos = $this->getShipmentTrackingNumber($shipment);
135
-
136
-
137
-
138
- $orderIdShoppingflux = $order->getOrderIdShoppingflux();
139
- $marketPlace = $order->getMarketplaceShoppingflux();
140
-
141
-
142
- //Mage::log("OrderIdSF = ".$orderIdShoppingflux." MP: ".$marketPlace,null,'debug_update_status_sf.log');
143
-
144
- /* @var $service Profileolabs_Shoppingflux_Model_Service */
145
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
146
- $result = $service->updateShippedOrder(
147
- $orderIdShoppingflux, $marketPlace, Profileolabs_Shoppingflux_Model_Service::ORDER_STATUS_SHIPPED, $trakingInfos ? $trakingInfos['trackId'] : '', $trakingInfos ? $trakingInfos['trackTitle'] : '', $trakingInfos ? $trakingInfos['trackUrl'] : ''
148
- );
149
-
150
-
151
- if ($result) {
152
- if ($result->Response->Orders->Order->StatusUpdated == 'False') {
153
- Mage::throwException('Error in update status shipped to shopping flux');
154
- } else {
155
- $status = $result->Response->Orders->Order->StatusUpdated;
156
- //Mage::log("status = ".$status,null,'debug_update_status_sf.log');
157
-
158
- $order->setShoppingfluxShipmentFlag(1);
159
- $order->save();
160
- $this->getHelper()->log($this->getHelper()->__("Order %s has been updated in ShoppingFlux. Status returned : %s", $orderIdShoppingflux, $status));
161
- }
162
- } else {
163
- $this->getHelper()->log($this->getHelper()->__("Error in update status shipped to ShoppingFlux"));
164
- Mage::throwException($this->getHelper()->__("Error in update status shipped to ShoppingFlux"));
165
- }
166
-
167
- return $this;
168
- }
169
-
170
- /**
171
- * Retrieve config
172
- * @return Profileolabs_Shoppingflux_Model_Manageorders_Config
173
- */
174
- public function getConfig() {
175
- return Mage::getSingleton('profileolabs_shoppingflux/config');
176
- }
177
-
178
- /**
179
- * Get Helper
180
- * @return Profileolabs_Shoppingflux_Model_Manageorders_Helper_Data
181
- */
182
- public function getHelper() {
183
- return Mage::helper('profileolabs_shoppingflux');
184
- }
185
-
186
-
187
- public function observeSalesOrderPlaceAfter($observer) {
188
- $order = $observer->getEvent()->getOrder();
189
- $idTracking = Mage::getSingleton('profileolabs_shoppingflux/config')->getIdTracking();
190
-
191
- if (!$idTracking || !$order || !$order->getId()) {
192
- return;
193
- }
194
- try {
195
- if(version_compare(Mage::getVersion(), '1.6.0') > 0) {
196
- if(!$order->getRemoteIp() || $order->getFromShoppingflux()) {
197
- //backend order
198
- return;
199
- }
200
- } else if ($order->getFromShoppingflux()) {
201
- //backend order
202
- return;
203
- }
204
- $ip = $order->getRemoteIp()?$order->getRemoteIp():Mage::helper('core/http')->getRemoteAddr(false);
205
- $grandTotal = $order->getBaseGrandTotal();
206
- $incrementId = $order->getIncrementId();
207
- $tagUrl = 'https://tag.shopping-flux.com/order/'.base64_encode($idTracking.'|'.$incrementId.'|'.$grandTotal).'?ip='.$ip;
208
- file_get_contents($tagUrl);
209
- } catch (Exception $ex) {
210
-
211
- }
212
- }
213
-
214
- public function observeAdminhtmlBlockHtmlBefore($observer) {
215
- $block = $observer->getEvent()->getBlock();
216
- if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
217
- if (method_exists($block, 'addButton') && $block->getOrderId() && $block->getOrder() && $block->getOrder()->getShoppingfluxShipmentFlag() == 0 && $block->getOrder()->getFromShoppingflux() == 1 && $block->getOrder()->hasShipments()) {
218
- $block->addButton('shoppingflux_shipment', array(
219
- 'label' => $this->getHelper()->__('Send notification to ShoppingFeed'),
220
- 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('adminhtml/shoppingfeed_order_import/sendShipment', array('order_id'=>$block->getOrder()->getId())) . "')",
221
- 'class' => 'shoppingflux-shipment-notification',
222
- ), 0);
223
- }
224
- }
225
- }
226
-
227
- public function updateMarketplaceList() {
228
- $apiKey = false;
229
- foreach(Mage::app()->getStores() as $store) {
230
- if(!$apiKey) {
231
- $apiKey = $this->getConfig()->getApiKey($store->getId());
232
- $wsUri = $this->getConfig()->getWsUri();
233
- }
234
- }
235
-
236
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
237
-
238
- try {
239
- $marketplaces = $service->getMarketplaces();
240
- if(count($marketplaces) > 5) {
241
- $marketplaceCsvFile = Mage::getModuleDir( '', 'Profileolabs_Shoppingflux' ) . DS . 'etc' . DS . 'marketplaces.csv';
242
- $handle = fopen($marketplaceCsvFile, 'w+');
243
- foreach($marketplaces as $marketplace) {
244
- fwrite($handle, $marketplace."\n");
245
- }
246
- fclose($handle);
247
- }
248
- } catch(Exception $e) {
249
- echo $e->getMessage();
250
- }
251
- }
252
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Model_Manageorders_Observer {
4
+ /**
5
+ * @var array
6
+ */
7
+ protected $_trackingUrlCallbacks = array(
8
+ 'owebia' => '_extractOwebiaTrackingUrl',
9
+ 'dpdfrclassic' => '_extractDpdTrackingUrl',
10
+ 'dpdfrpredict' => '_extractDpdTrackingUrl',
11
+ 'dpdfrrelais' => '_extractDpdTrackingUrl',
12
+ );
13
+
14
+ public function setCustomerTaxClassId($observer) {
15
+ if (!$this->getConfig()->applyTax() && Mage::registry('is_shoppingfeed_import')/*Mage::getSingleton('checkout/session')->getIsShoppingFlux()*/) {
16
+ $customerGroup = $observer->getEvent()->getObject();
17
+ $customerGroup->setData('tax_class_id', 999);
18
+ }
19
+ }
20
+
21
+ public function manageOrders($observer=false) {
22
+ try {
23
+ set_time_limit(0);
24
+ Mage::getModel('profileolabs_shoppingflux/manageorders_order')->manageOrders();
25
+ } catch (Exception $e) {
26
+ Mage::throwException($e);
27
+ }
28
+
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * @param Varien_Object $trackingInfo
34
+ * @return string
35
+ */
36
+ protected function _extractOwebiaTrackingUrl(Varien_Object $trackingInfo)
37
+ {
38
+ return preg_match('%href="(.*?)"%i', $trackingInfo->getStatus(), $matches)
39
+ ? $matches[1]
40
+ : '';
41
+ }
42
+
43
+ /**
44
+ * @param Varien_Object $trackingInfo
45
+ * @return string
46
+ */
47
+ protected function _extractDpdTrackingUrl(Varien_Object $trackingInfo)
48
+ {
49
+ return preg_match('%iframe src="(.*?)"%i', $trackingInfo->getStatus(), $matches)
50
+ ? $matches[1]
51
+ : '';
52
+ }
53
+
54
+ /**
55
+ * @param Mage_Sales_Model_Order_Shipment_Track $shipmentTrack
56
+ * @return string
57
+ */
58
+ protected function _getShipmentTrackingUrl($shipmentTrack)
59
+ {
60
+ $trackingUrl = '';
61
+
62
+ if (preg_match('%^(owebia|(dpdfr)(classic|predict|relais))%i', $shipmentTrack->getCarrierCode(), $matches)
63
+ && isset($this->_trackingUrlCallbacks[$matches[1]])
64
+ ) {
65
+ /** @var Mage_Shipping_Model_Config $shippingConfig */
66
+ $shippingConfig = Mage::getSingleton('shipping/config');
67
+ $carrierInstance = $shippingConfig->getCarrierInstance($shipmentTrack->getCarrierCode());
68
+
69
+ if ($carrierInstance
70
+ && ($trackingInfo = $carrierInstance->getTrackingInfo($shipmentTrack->getData('number')))
71
+ && ($trackingInfo instanceof Varien_Object)
72
+ ) {
73
+ $trackingUrl = call_user_func(array($this, $this->_trackingUrlCallbacks[$matches[1]]), $trackingInfo);
74
+ }
75
+ }
76
+
77
+ return $trackingUrl;
78
+ }
79
+
80
+ public function getShipmentTrackingNumber($shipment) {
81
+ $result = false;
82
+ $tracks = $shipment->getAllTracks();
83
+
84
+ if (is_array($tracks) && !empty($tracks)) {
85
+ $firstTrack = array_shift($tracks);
86
+
87
+ if (trim($firstTrack->getData('number'))) {
88
+ $result = array(
89
+ 'trackUrl' => $this->_getShipmentTrackingUrl($firstTrack),
90
+ 'trackId' => $firstTrack->getData('number'),
91
+ 'trackTitle' => $firstTrack->getData('title'),
92
+ );
93
+ }
94
+ }
95
+
96
+ $dataObj = new Varien_Object(array('result' => $result, 'shipment'=>$shipment));
97
+ Mage::dispatchEvent('shoppingflux_get_shipment_tracking', array('data_obj' => $dataObj));
98
+ $result = $dataObj->getResult();
99
+
100
+ return $result;
101
+ }
102
+
103
+ public function sendStatusCanceled($observer) {
104
+ $order = $observer->getEvent()->getOrder();
105
+ if (!$order->getFromShoppingflux())
106
+ return $this;
107
+
108
+
109
+ $storeId = $order->getStoreId();
110
+
111
+ $apiKey = $this->getConfig()->getApiKey($storeId);
112
+ $wsUri = $this->getConfig()->getWsUri();
113
+
114
+
115
+ $orderIdShoppingflux = $order->getOrderIdShoppingflux();
116
+ $marketPlace = $order->getMarketplaceShoppingflux();
117
+
118
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
119
+
120
+ try {
121
+ $service->updateCanceledOrder(
122
+ $orderIdShoppingflux, $marketPlace, Profileolabs_Shoppingflux_Model_Service::ORDER_STATUS_CANCELED
123
+ );
124
+ } catch(Exception $e) {
125
+
126
+ }
127
+
128
+ Mage::helper('profileolabs_shoppingflux')->log('Order ' . $orderIdShoppingflux . ' has been canceled. Information sent to ShoppingFlux.');
129
+
130
+
131
+ }
132
+
133
+
134
+ public function scheduleShipmentUpdate($observer) {
135
+ $shipment = $observer->getShipment();
136
+ Mage::getModel('profileolabs_shoppingflux/manageorders_export_shipments')->scheduleShipmentExport($shipment->getId());
137
+ }
138
+
139
+ public function sendScheduledShipments() {
140
+ $collection = Mage::getModel('profileolabs_shoppingflux/manageorders_export_shipments')->getCollection();
141
+ //$collection->addFieldToFilter('updated_at', array('lt'=>new Zend_Db_Expr("DATE_SUB('".date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time()))."', INTERVAL 60 MINUTE)")));
142
+ foreach($collection as $item) {
143
+ try {
144
+ $shipment = Mage::getModel('sales/order_shipment')->load($item->getShipmentId());
145
+ if(Mage::app()->getStore()->getCode() == 'admin' || Mage::app()->getStore()->getId() == $shipment->getStoreId()) {
146
+ $trakingInfos = $this->getShipmentTrackingNumber($shipment);
147
+ if($trakingInfos || $shipment->getUpdatedAt() < $this->getConfig()->getShipmentUpdateLimit()) {
148
+ $this->sendStatusShipped($shipment);
149
+ $item->delete();
150
+ }
151
+ }
152
+ } catch(Exception $e) {
153
+ $shipment = Mage::getModel('sales/order_shipment')->load($item->getShipmentId());
154
+ $message = 'Erreur de mise à jour de l\'expédition #'.$shipment->getIncrementId().' (commande #'.$shipment->getOrder()->getIncrementId().') : <br/>' . $e->getMessage();
155
+ $message .= "<br/><br/> Merci de vérifier les infos de votre commandes ou de contacter le support Shopping Flux ou celui de la place de marché";
156
+ $this->getHelper()->notifyError($message);
157
+ if($item->getId() && !preg_match('%Error in cURL request: connect.. timed out%', $message) && !preg_match('%Result is not Varien_Simplexml_Element%', $message)) {
158
+ try {
159
+ $item->delete();
160
+ } catch(Exception $e) {}
161
+ }
162
+ }
163
+ }
164
+ return $this;
165
+ }
166
+
167
+ public function sendStatusShipped($shipment) {
168
+ if(!$shipment->getId())
169
+ return $this;
170
+
171
+ $shipmentId = $shipment->getId();
172
+ $order = $shipment->getOrder();
173
+ $storeId = $order->getStoreId();
174
+
175
+ $apiKey = $this->getConfig()->getApiKey($storeId);
176
+ $wsUri = $this->getConfig()->getWsUri();
177
+
178
+ //Mage::log("order = ".print_r($order->debug(),true),null,'debug_update_status_sf.log');
179
+
180
+ if (!$order->getFromShoppingflux())
181
+ return $this;
182
+
183
+ if($order->getShoppingfluxShipmentFlag()) {
184
+ return $this;
185
+ }
186
+
187
+ $trakingInfos = $this->getShipmentTrackingNumber($shipment);
188
+
189
+
190
+
191
+ $orderIdShoppingflux = $order->getOrderIdShoppingflux();
192
+ $marketPlace = $order->getMarketplaceShoppingflux();
193
+
194
+
195
+ //Mage::log("OrderIdSF = ".$orderIdShoppingflux." MP: ".$marketPlace,null,'debug_update_status_sf.log');
196
+
197
+ /* @var $service Profileolabs_Shoppingflux_Model_Service */
198
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
199
+ $result = $service->updateShippedOrder(
200
+ $orderIdShoppingflux, $marketPlace, Profileolabs_Shoppingflux_Model_Service::ORDER_STATUS_SHIPPED, $trakingInfos ? $trakingInfos['trackId'] : '', $trakingInfos ? $trakingInfos['trackTitle'] : '', $trakingInfos ? $trakingInfos['trackUrl'] : ''
201
+ );
202
+
203
+
204
+ if ($result) {
205
+ if ($result->Response->Orders->Order->StatusUpdated == 'False') {
206
+ Mage::throwException('Error in update status shipped to shopping flux');
207
+ } else {
208
+ $status = $result->Response->Orders->Order->StatusUpdated;
209
+ //Mage::log("status = ".$status,null,'debug_update_status_sf.log');
210
+
211
+ $order->setShoppingfluxShipmentFlag(1);
212
+ $order->save();
213
+ $this->getHelper()->log($this->getHelper()->__("Order %s has been updated in ShoppingFlux. Status returned : %s", $orderIdShoppingflux, $status));
214
+ }
215
+ } else {
216
+ $this->getHelper()->log($this->getHelper()->__("Error in update status shipped to ShoppingFlux"));
217
+ Mage::throwException($this->getHelper()->__("Error in update status shipped to ShoppingFlux"));
218
+ }
219
+
220
+ return $this;
221
+ }
222
+
223
+ /**
224
+ * Retrieve config
225
+ * @return Profileolabs_Shoppingflux_Model_Manageorders_Config
226
+ */
227
+ public function getConfig() {
228
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
229
+ }
230
+
231
+ /**
232
+ * Get Helper
233
+ * @return Profileolabs_Shoppingflux_Model_Manageorders_Helper_Data
234
+ */
235
+ public function getHelper() {
236
+ return Mage::helper('profileolabs_shoppingflux');
237
+ }
238
+
239
+
240
+ public function observeSalesOrderPlaceAfter($observer) {
241
+ $order = $observer->getEvent()->getOrder();
242
+ $idTracking = Mage::getSingleton('profileolabs_shoppingflux/config')->getIdTracking();
243
+
244
+ if (!$idTracking || !$order || !$order->getId()) {
245
+ return;
246
+ }
247
+ try {
248
+ if(version_compare(Mage::getVersion(), '1.6.0') > 0) {
249
+ if(!$order->getRemoteIp() || $order->getFromShoppingflux()) {
250
+ //backend order
251
+ return;
252
+ }
253
+ } else if ($order->getFromShoppingflux()) {
254
+ //backend order
255
+ return;
256
+ }
257
+ $ip = $order->getRemoteIp()?$order->getRemoteIp():Mage::helper('core/http')->getRemoteAddr(false);
258
+ $grandTotal = $order->getBaseGrandTotal();
259
+ $incrementId = $order->getIncrementId();
260
+ $tagUrl = 'https://tag.shopping-flux.com/order/'.base64_encode($idTracking.'|'.$incrementId.'|'.$grandTotal).'?ip='.$ip;
261
+ file_get_contents($tagUrl);
262
+ } catch (Exception $ex) {
263
+
264
+ }
265
+ }
266
+
267
+ public function observeAdminhtmlBlockHtmlBefore($observer) {
268
+ $block = $observer->getEvent()->getBlock();
269
+ if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View) {
270
+ if (method_exists($block, 'addButton') && $block->getOrderId() && $block->getOrder() && $block->getOrder()->getShoppingfluxShipmentFlag() == 0 && $block->getOrder()->getFromShoppingflux() == 1 && $block->getOrder()->hasShipments()) {
271
+ $block->addButton('shoppingflux_shipment', array(
272
+ 'label' => $this->getHelper()->__('Send notification to ShoppingFeed'),
273
+ 'onclick' => "setLocation('" . Mage::helper('adminhtml')->getUrl('adminhtml/shoppingfeed_order_import/sendShipment', array('order_id'=>$block->getOrder()->getId())) . "')",
274
+ 'class' => 'shoppingflux-shipment-notification',
275
+ ), 0);
276
+ }
277
+ }
278
+ }
279
+
280
+ public function updateMarketplaceList() {
281
+ $apiKey = false;
282
+ foreach(Mage::app()->getStores() as $store) {
283
+ if(!$apiKey) {
284
+ $apiKey = $this->getConfig()->getApiKey($store->getId());
285
+ $wsUri = $this->getConfig()->getWsUri();
286
+ }
287
+ }
288
+
289
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
290
+
291
+ try {
292
+ $marketplaces = $service->getMarketplaces();
293
+ if(count($marketplaces) > 5) {
294
+ $marketplaceCsvFile = Mage::getModuleDir( '', 'Profileolabs_Shoppingflux' ) . DS . 'etc' . DS . 'marketplaces.csv';
295
+ $handle = fopen($marketplaceCsvFile, 'w+');
296
+ foreach($marketplaces as $marketplace) {
297
+ fwrite($handle, $marketplace."\n");
298
+ }
299
+ fclose($handle);
300
+ }
301
+ } catch(Exception $e) {
302
+ echo $e->getMessage();
303
+ }
304
+ }
305
+
306
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Order.php CHANGED
@@ -1,924 +1,924 @@
1
- <?php
2
-
3
- /**
4
- * Orders getted here
5
- *
6
- * @category ShoppingFlux
7
- * @package Profileolabs_Shoppingflux
8
- * @author kassim belghait, vincent enjalbert @ web-cooking
9
- *
10
- */
11
- class Profileolabs_Shoppingflux_Model_Manageorders_Order extends Varien_Object {
12
-
13
- /**
14
- * @var Mage_Sales_Model_Quote
15
- */
16
- protected $_quote = null;
17
-
18
- /**
19
- * @var Mage_Customer_Model_Customer
20
- */
21
- protected $_customer = null;
22
-
23
- /**
24
- * Config Data of Module Manageorders
25
- * @var Profileolabs_Shoppingflux_Model_Manageorders_Config
26
- */
27
- protected $_config = null;
28
- protected $_paymentMethod = 'shoppingflux_purchaseorder';
29
- protected $_shippingMethod = 'shoppingflux_shoppingflux';
30
- protected $_nb_orders_imported = 0;
31
- protected $_nb_orders_read = 0;
32
- protected $_ordersIdsImported = array();
33
- //protected $_orderIdsAlreadyImported = null;
34
- protected $_result;
35
- protected $_resultSendOrder = "";
36
- protected $_isUnderVersion14 = null;
37
-
38
- //security for some mal-configured magento, or old ones.
39
- protected $_excludeConfigurableAttributes = array(
40
- 'weight',
41
- 'news_from_date',
42
- 'news_to_date',
43
- 'url_key',
44
- 'sku',
45
- 'description',
46
- 'short_description',
47
- 'meta_title',
48
- 'meta_description',
49
- 'meta_keyword',
50
- 'name',
51
- 'tax_class_id',
52
- 'status',
53
- 'price',
54
- 'special_price',
55
- 'special_from_date',
56
- 'special_to_date',
57
- 'cost',
58
- 'image',
59
- 'small_image',
60
- 'thumbnail',
61
- 'status',
62
- 'visibility',
63
- 'custom_design_from',
64
- 'options_container',
65
- 'msrp_enabled',
66
- 'msrp_display_actual_price_type',
67
- 'shoppingflux_default_category',
68
- 'shoppingflux_product',
69
- 'main_category'
70
- );
71
-
72
- /**
73
- * Product model
74
- *
75
- * @var Mage_Catalog_Model_Product
76
- */
77
- protected $_productModel;
78
-
79
- public function getResultSendOrder() {
80
- return $this->_resultSendOrder;
81
- }
82
-
83
- public function isUnderVersion14() {
84
- if (is_null($this->_isUnderVersion14)) {
85
- $this->_isUnderVersion14 = $this->getHelper()->isUnderVersion14();
86
- }
87
- return $this->_isUnderVersion14;
88
- }
89
-
90
- /**
91
- * Retrieve product model cache
92
- *
93
- * @return Mage_Catalog_Model_Product
94
- */
95
- public function getProductModel() {
96
- if (is_null($this->_productModel)) {
97
- $productModel = Mage::getModel('profileolabs_shoppingflux/manageorders_product');
98
- $this->_productModel = Mage::objects()->save($productModel);
99
- }
100
- return Mage::objects()->load($this->_productModel);
101
- }
102
-
103
- /**
104
- *
105
- * @deprecated
106
- */
107
- public function getOrderIdsAlreadyImported() {
108
- if (is_null($this->_orderIdsAlreadyImported)) {
109
- $orders = Mage::getModel('sales/order')->getCollection()
110
- ->addAttributeToFilter('from_shoppingflux', 1)
111
- ->addAttributeToSelect('order_id_shoppingflux');
112
-
113
- $this->_orderIdsAlreadyImported = array();
114
- foreach ($orders as $order) {
115
- $this->_orderIdsAlreadyImported[] = $order->getOrderIdShoppingflux();
116
- }
117
- }
118
-
119
- return $this->_orderIdsAlreadyImported;
120
- }
121
-
122
-
123
-
124
- public function isAlreadyImported($idShoppingflux) {
125
- $orders = Mage::getModel('sales/order')->getCollection()
126
- ->addAttributeToFilter('from_shoppingflux', 1)
127
- ->addAttributeToFilter('order_id_shoppingflux', $idShoppingflux)
128
- ->addAttributeToSelect('increment_id');
129
- if($orders->count() > 0) {
130
- return $orders->getFirstItem();
131
- }
132
-
133
- /* Double vérification, pour gérer un appel simultané. (qui ne devrait pas arriver, mais au cas ou..) */
134
- $config = new Mage_Core_Model_Config();
135
- $flagPath = Mage::getStoreConfig('shoppingflux/order_flags/order_'.$idShoppingflux);
136
- if ($flagPath) {
137
- $config->saveConfig('shoppingflux/order_flags/order_'.$idShoppingflux, 0);
138
- return true;
139
- }
140
- $config->saveConfig('shoppingflux/order_flags/order_'.$idShoppingflux, date('Y-m-d H:i:s'));
141
- /* end double check */
142
-
143
- return false;
144
- }
145
-
146
- public function getSession() {
147
- return Mage::getSingleton('checkout/session');
148
- }
149
-
150
- protected function _getQuote($storeId = null) {
151
- return $this->getSession()->getQuote();
152
- }
153
-
154
- /**
155
- * Retrieve config
156
- * @return Profileolabs_Shoppingflux_Model_Manageorders_Config
157
- */
158
- public function getConfig() {
159
- if (is_null($this->_config)) {
160
- $this->_config = Mage::getSingleton('profileolabs_shoppingflux/config');
161
- }
162
-
163
- return $this->_config;
164
- }
165
-
166
- /**
167
- * Get orders and create it
168
- */
169
- public function manageOrders() {
170
- //Set boolean shopping flux
171
- Mage::register('is_shoppingfeed_import', 1, true);
172
-
173
-
174
- //compatibility with AutoShipping extension
175
- Mage::app()->getStore()->setConfig('autoshipping/settings/enabled', "0");
176
-
177
- $stores = Mage::app()->getStores();
178
-
179
- $storeCode = Mage::app()->getStore()->getCode();
180
- $isAdmin = ($storeCode == 'admin');
181
- if (!$isAdmin) {
182
- Mage::app()->setCurrentStore('admin');
183
- }
184
-
185
- $apiKeyManaged = array();
186
-
187
- //old module version compliance. The goal is to use default store, as in previous versions, if api key is set in global scope.
188
- $defaultStoreId = Mage::app()->getDefaultStoreView()->getId();
189
- if (key($stores) != $defaultStoreId) {
190
- $tmpStores = array($defaultStoreId => $stores[$defaultStoreId]);
191
- foreach ($stores as $store) {
192
- if ($store->getId() != $defaultStoreId) {
193
- $tmpStores[$store->getId()] = $store;
194
- }
195
- }
196
- $stores = $tmpStores;
197
- }
198
- //old module version compliance end
199
-
200
-
201
- foreach ($stores as $_store) {
202
- if(!$isAdmin && $storeCode != $_store->getCode()) {
203
- continue;
204
- }
205
- $storeId = $_store->getId();
206
- if ($this->getConfig()->isOrdersEnabled($storeId)) {
207
- $apiKey = $this->getConfig()->getApiKey($storeId);
208
-
209
- if (!$apiKey || in_array($apiKey, $apiKeyManaged))
210
- continue;
211
- $apiKeyManaged[] = $apiKey;
212
-
213
- $wsUri = $this->getConfig()->getWsUri();
214
-
215
- //$isUnderVersion14 = $this->getHelper()->isUnderVersion14();
216
-
217
- /* @var $service Profileolabs_Shoppingflux_Model_Service */
218
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
219
- ini_set("memory_limit", $this->getConfig()->getMemoryLimit() . "M");
220
- try {
221
-
222
- /* @var $this->_result Varien_Simplexml_Element */
223
- $this->_result = $service->getOrders();
224
-
225
- $this->_nb_orders_imported = 0;
226
- } catch (Exception $e) {
227
- Mage::logException($e);
228
- $message = Mage::helper('profileolabs_shoppingflux')->__('Order import error : %s', $e->getMessage());
229
- $this->getHelper()->log($message);
230
- //Mage::throwException($message);
231
-
232
- Mage::throwException($e);
233
- }
234
-
235
- //We parse result
236
- //$nodes = current($this->_result->children());
237
- $nodes = $this->_result->children();
238
- if($nodes && count($nodes) > 0) {
239
- foreach ($nodes as $childName => $child) {
240
-
241
- $orderSf = $this->getHelper()->asArray($child);
242
-
243
-
244
- if (($importedOrder = $this->isAlreadyImported($orderSf['IdOrder']))) {
245
- $this->_ordersIdsImported[$orderSf['IdOrder']] = array(
246
- 'Marketplace' => $orderSf['Marketplace'],
247
- 'MageOrderId' => is_object($importedOrder)?$importedOrder->getIncrementId():'',
248
- 'ShippingMethod' => $orderSf['ShippingMethod'],
249
- 'ErrorOrder' => is_object($importedOrder)?false:true
250
- );
251
- continue;
252
- }
253
-
254
- $this->_nb_orders_read++;
255
-
256
- $this->createAllForOrder($orderSf, $storeId);
257
-
258
- if ($this->_nb_orders_imported == $this->getConfig()->getLimitOrders($storeId))
259
- break;
260
- }
261
- }
262
-
263
- try {
264
- if ($this->_nb_orders_imported > 0 || count($this->_ordersIdsImported)) {
265
-
266
- $result = $service->sendValidOrders($this->_ordersIdsImported);
267
- foreach($this->_ordersIdsImported as $importedOrder) {
268
- $shippingMethod = isset($importedOrder['ShippingMethod'])?$importedOrder['ShippingMethod']:'';
269
- $marketplace = $importedOrder['Marketplace'];
270
- try {
271
- Mage::getModel('profileolabs_shoppingflux/manageorders_shipping_method')->saveShippingMethod($marketplace, $shippingMethod);
272
- } catch(Exception $e) {
273
-
274
- }
275
- }
276
-
277
-
278
- if ($result) {
279
- if ($result->error) {
280
- Mage::throwException($result->error);
281
- }
282
-
283
- $this->_resultSendOrder = $result->status;
284
- } else {
285
- $this->getHelper()->log("Error in order ids validated");
286
- Mage::throwException("Error in order ids validated");
287
- }
288
- }
289
- } catch (Exception $e) {
290
- $this->getHelper()->log($e->getMessage());
291
- Mage::throwException($e);
292
- }
293
- }
294
- }
295
- $this->clearOldOrderFlagFiles();
296
- return $this;
297
- }
298
-
299
- public function clearOldOrderFlagFiles() {
300
- $config = new Mage_Core_Model_Config();
301
- $orderFlags = Mage::getStoreConfig('shoppingflux/order_flags');
302
- if(!$orderFlags || empty($orderFlags)) {
303
- return;
304
- }
305
- foreach($orderFlags as $orderId => $importDate) {
306
- if(strtotime($importDate) < time()-3*60*60) {
307
- $config->deleteConfig('shoppingflux/order_flags/' . $orderId);//retro-compatibility.
308
- $config->deleteConfig('shoppingflux/order_flags/order_' . $orderId);
309
- }
310
- }
311
- }
312
-
313
- /**
314
- * Inititalize the quote with minimum requirement
315
- * @param array $orderSf
316
- */
317
- protected function _initQuote(array $orderSf, $storeId) {
318
-
319
- if (is_null($storeId)) {//just in case..
320
- $storeId = Mage::app()->getDefaultStoreView()->getId();
321
- }
322
-
323
- $this->_getQuote()->setStoreId($storeId);
324
-
325
- //Super mode is setted to bypass check item qty ;)
326
- $this->_getQuote()->setIsSuperMode(true);
327
-
328
- $this->_getQuote()->setCustomer($this->_customer);
329
- }
330
-
331
- /**
332
- * Create or Update customer with converter
333
- * @param array $data Data From ShoppingFlux
334
- */
335
- protected function _createCustomer(array $data, $storeId) {
336
- try {
337
-
338
- /* @var $convert_customer Profileolabs_Shoppingflux_Model_Manageorders_Convert_Customer */
339
- $convert_customer = Mage::getModel('profileolabs_shoppingflux/manageorders_convert_customer');
340
-
341
- $this->_customer = $convert_customer->toCustomer(current($data['BillingAddress']), $storeId);
342
- $billingAddress = $convert_customer->addresstoCustomer(current($data['BillingAddress']), $storeId, $this->_customer);
343
-
344
- $this->_customer->addAddress($billingAddress);
345
-
346
- $shippingAddress = $convert_customer->addresstoCustomer(current($data['ShippingAddress']), $storeId, $this->_customer, 'shipping');
347
- $this->_customer->addAddress($shippingAddress);
348
- $customerGroupId = $this->getConfig()->getCustomerGroupIdFor($data['Marketplace'], $storeId);
349
- if ($customerGroupId) {
350
- $this->_customer->setGroupId($customerGroupId);
351
- }
352
- $this->_customer->save();
353
- } catch (Exception $e) {
354
- Mage::throwException($e);
355
- }
356
- }
357
-
358
- public function createAllForOrder($orderSf, $storeId) {
359
- try {
360
- $orderIdShoppingFlux = (string) $orderSf['IdOrder'];
361
-
362
- $dataObj = new Varien_Object(array('entry' => $orderSf, 'store_id'=>$storeId));
363
- Mage::dispatchEvent('shoppingflux_before_import_order', array('order_sf' => $dataObj));
364
- $orderSf = $dataObj->getEntry();
365
-
366
- //Set array with shopping flux ids
367
- $this->_ordersIdsImported[$orderIdShoppingFlux] = array(
368
- 'Marketplace' => $orderSf['Marketplace'],
369
- 'MageOrderId' => '',
370
- 'ShippingMethod' => $orderSf['ShippingMethod'],
371
- 'ErrorOrder' => false
372
- );
373
-
374
- //$this->_quote = null;
375
- $this->_customer = null;
376
-
377
-
378
- //Create or Update customer with addresses
379
- $this->_createCustomer($orderSf, $storeId);
380
-
381
- $this->_initQuote($orderSf, $storeId);
382
-
383
- if(Mage::registry('current_order_sf')) {
384
- Mage::unregister('current_order_sf');
385
- }
386
- Mage::register('current_order_sf', $orderSf);
387
-
388
- if(Mage::registry('current_quote_sf')) {
389
- Mage::unregister('current_quote_sf');
390
- }
391
- Mage::register('current_quote_sf', $this->_getQuote());
392
-
393
- //Add products to quote with data from ShoppingFlux
394
- $this->_addProductsToQuote($orderSf, $storeId);
395
-
396
- $order = null;
397
- if (!$this->isUnderVersion14())
398
- $order = $this->_saveOrder($orderSf, $storeId);
399
- else
400
- $order = $this->_saveOrder13($orderSf, $storeId);
401
-
402
- if($order) {
403
- $this->getHelper()->log('Order ' . $orderSf['IdOrder'] . ' has been created (' . $order->getIncrementId() . ' / ' . Mage::app()->getStore()->getId() . ')');
404
- $this->_nb_orders_imported++;
405
-
406
- if (!is_null($order) && $order->getId()) {
407
- $useMarketplaceDate = $this->getConfig()->getConfigFlag('shoppingflux_mo/manageorders/use_marketplace_date');
408
- //$orderDate = date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time()));
409
- if($useMarketplaceDate) {
410
- $orderDate = $orderSf['OrderDate'];
411
- $this->_changeDateCreatedAt($order, $orderDate);
412
- }
413
- }
414
-
415
- }
416
- //Erase session for the next order
417
- $this->getSession()->clear();
418
- } catch (Exception $e) {
419
- $this->getHelper()->log($e->getMessage() . ' Trace : ' . $e->getTraceAsString(), $orderSf['IdOrder']);
420
- $this->_ordersIdsImported[$orderIdShoppingFlux]['ErrorOrder'] = $e->getMessage();
421
- //$this->clearOrderFlagFile($orderSf['IdOrder']);
422
- //Erase session for the next order
423
- $this->getSession()->clear();
424
- }
425
- }
426
-
427
- protected function _changeDateCreatedAt($order, $date) {
428
- try {
429
- $order->setCreatedAt($date);
430
- //$order->setUpdatedAt($date);
431
- $order->save();
432
- } catch (Exception $e) {
433
- Mage::logException($e);
434
- Mage::throwException($message);
435
- }
436
- }
437
-
438
- /**
439
- * Add products to quote with data from ShoppinfFlux
440
- * @param array $orderSf
441
- */
442
- protected function _addProductsToQuote(array $orderSf, $storeId) {
443
- $totalAmount = $orderSf['TotalAmount'];
444
- $productsSf = current($orderSf['Products']);
445
- $productsToIterate = current($productsSf);
446
-
447
-
448
-
449
-
450
- if (!$this->_customer->getDefaultBilling() || !$this->_customer->getDefaultShipping() || (is_object($this->_customer->getDefaultShipping()) && !$this->_customer->getDefaultShipping()->getFirstname()))
451
- $this->_customer->load($this->_customer->getId());
452
-
453
- $customerAddressBillingId = $this->_customer->getDefaultBilling();
454
- $customerAddressShippingId = $this->_customer->getDefaultShipping();
455
-
456
- //Set billing Address
457
- $addressBilling = $this->_getQuote()->getBillingAddress();
458
- //Make sure addresses will be saved without validation errors
459
- $addressBilling->setShouldIgnoreValidation(true);
460
- $customerAddressBilling = Mage::getModel('customer/address')->load($customerAddressBillingId);
461
- $addressBilling->importCustomerAddress($customerAddressBilling)->setSaveInAddressBook(0);
462
-
463
- //Set shipping Address
464
- $addressShipping = $this->_getQuote()->getShippingAddress();
465
- //Make sure addresses will be saved without validation errors
466
- $addressShipping->setShouldIgnoreValidation(true);
467
- $customerAddressShipping = Mage::getModel('customer/address')->load($customerAddressShippingId);
468
- $addressShipping->importCustomerAddress($customerAddressShipping)->setSaveInAddressBook(0);
469
- $addressShipping->setSameAsBilling(0);
470
-
471
-
472
-
473
-
474
- //Set shipping Mehtod and collect shipping rates
475
- $addressShipping->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
476
-
477
-
478
-
479
-
480
- foreach ($productsToIterate as $key => $productSf) {
481
-
482
- $sku = $productSf['SKU'];
483
- $qtyIncrements = 1;
484
- if(preg_match('%^_SFQI_([0-9]+)_(.*)$%i', $sku, $pregResults)) {
485
- $sku = $pregResults[2];
486
- $qtyIncrements = $pregResults[1];
487
- }
488
-
489
- $useProductId = $this->getConfig()->getConfigData('shoppingflux_mo/manageorders/use_product_id', $storeId);
490
-
491
- if($useProductId) {
492
- $productId = $sku;
493
- } else {
494
- $productId = $this->getProductModel()->getResource()->getIdBySku($sku);
495
- }
496
-
497
- $product = Mage::getModel('profileolabs_shoppingflux/manageorders_product')->setStoreId($storeId)->load($productId);
498
-
499
- if ($product->getId()) {
500
-
501
- $request = new Varien_Object(array('qty' => $productSf['Quantity'] * $qtyIncrements));
502
-
503
-
504
-
505
- $item = $this->_getQuote()->addProduct($product, $request);
506
-
507
- if (!is_object($item)) {
508
- $this->getSession()->clear();
509
- Mage::throwException("le produit sku = " . $sku . " n'a pas pu être ajouté! Id = " . $product->getId() . " Item = " . (string) $item);
510
- }
511
-
512
-
513
- //Save the quote with the new product
514
- $this->_getQuote()->save();
515
-
516
-
517
- $unitPrice = $productSf['Price'] / $qtyIncrements;
518
- if($unitPrice <= 0) {
519
- $this->getHelper()->log('Order '.$orderSf['IdOrder'].' has a product with 0 price : '.$productSf['SKU']);
520
- }
521
- if ($this->getConfig()->applyTax() && !Mage::helper('tax')->priceIncludesTax()) {
522
- $taxClassId = $product->getTaxClassId();
523
- if($taxClassId > 0) {
524
- $request = Mage::getSingleton('tax/calculation')->getRateRequest($addressShipping, $addressBilling, null, null);
525
- $request->setProductClassId($taxClassId);
526
- $request->setCustomerClassId($this->_getQuote()->getCustomerTaxClassId());
527
- $percent = Mage::getSingleton('tax/calculation')->getRate($request);
528
- $unitPrice = $unitPrice / (1 + $percent / 100);
529
- if($unitPrice <= 0) {
530
- $this->getHelper()->log('Order '.$orderSf['IdOrder'].' has a product with 0 price after applying tax : '.$productSf['SKU']);
531
- }
532
- }
533
- }
534
-
535
-
536
-
537
-
538
- //Modify Item price
539
- $item->setCustomPrice($unitPrice);
540
- $item->setOriginalCustomPrice($unitPrice);
541
-
542
-
543
- //add configurable attributes informations
544
- $confAttributeValues = array();
545
- if($this->isUnderVersion14()) {
546
- $configurableAttributesCollection = Mage::getResourceModel('eav/entity_attribute_collection')
547
- ->setEntityTypeFilter( Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId() );
548
- } else {
549
- $configurableAttributesCollection = Mage::getResourceModel('catalog/product_attribute_collection');
550
- }
551
- $configurableAttributesCollection->addVisibleFilter()
552
- ->addFieldToFilter('is_configurable', 1);
553
-
554
-
555
- foreach($configurableAttributesCollection as $confAttribute) {
556
- if(!in_array($confAttribute->getAttributeCode(), $this->_excludeConfigurableAttributes) && $product->getData($confAttribute->getAttributeCode())) {
557
- if($confAttribute->usesSource()) {
558
- $confAttributeValue = $product->getAttributeText($confAttribute->getAttributeCode());
559
- } else {
560
- $confAttributeValue = $product->getData($confAttribute->getAttributeCode());
561
- }
562
- if(is_string($confAttributeValue)) {
563
- $confAttributeValues[] = $confAttributeValue;
564
- }
565
- }
566
- }
567
- if(!empty($confAttributeValues)) {
568
- $item->setDescription($item->getDescription() . implode(' - ', $confAttributeValues));
569
- }
570
-
571
- $item->save();
572
-
573
- if (is_object($parentItem = $item->getParentItem())) {
574
- $parentItem->setCustomPrice($unitPrice);
575
- $parentItem->setOriginalCustomPrice($unitPrice);
576
- $parentItem->save();
577
- }
578
-
579
- //Mage::log(print_r($item->debug(),true),null,'debug_items.log');
580
- } else {
581
-
582
- $this->getSession()->clear();
583
- Mage::throwException("le produit sku = '" . $sku . "' (ID= ".$productId.", Utilisation id = ".($useProductId?'Oui':'Non').") n'existe plus en base!");
584
- }
585
- }
586
-
587
- try {
588
- $this->_getQuote()->collectTotals();
589
- $this->_getQuote()->save();
590
- } catch(Exception $e) {
591
- if($e->getMessage() == Mage::helper('sales')->__('Please specify a shipping method.')) {
592
- $this->_getQuote()->getShippingAddress()->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
593
- $this->_getQuote()->setTotalsCollectedFlag(false)->collectTotals();
594
- $this->_getQuote()->save();
595
- } else {
596
- throw $e;
597
- }
598
- }
599
-
600
- //Set payment method
601
- /* @var $payment Mage_Sales_Quote_Payment */
602
- $this->_getQuote()->getShippingAddress()->setPaymentMethod($this->_paymentMethod);
603
- $payment = $this->_getQuote()->getPayment();
604
- $dataPayment = array('method' => $this->_paymentMethod, 'marketplace' => $orderSf['Marketplace']);
605
- $payment->importData($dataPayment);
606
- //$addressShipping->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
607
-
608
- try {
609
- $this->_getQuote()->collectTotals();
610
- $this->_getQuote()->save();
611
- } catch(Exception $e) {
612
- if($e->getMessage() == Mage::helper('sales')->__('Please specify a shipping method.')) {
613
- $this->_getQuote()->getShippingAddress()->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
614
-
615
- $this->_getQuote()->getShippingAddress()->setPaymentMethod($this->_paymentMethod);
616
- $payment = $this->_getQuote()->getPayment();
617
- $dataPayment = array('method' => $this->_paymentMethod, 'marketplace' => $orderSf['Marketplace']);
618
- $payment->importData($dataPayment);
619
-
620
- $this->_getQuote()->setTotalsCollectedFlag(false)->collectTotals();
621
- $this->_getQuote()->save();
622
- } else {
623
- throw $e;
624
- }
625
- }
626
- }
627
-
628
-
629
- /**
630
- * Save the new order with the quote
631
- * @param array $orderSf
632
- */
633
- protected function _saveOrder(array $orderSf, $storeId) {
634
- $orderIdShoppingFlux = (string) $orderSf['IdOrder'];
635
- $additionalData = array("from_shoppingflux" => 1,
636
- "marketplace_shoppingflux" => $orderSf['Marketplace'],
637
- "fees_shoppingflux" => (float) (isset($orderSf['TotalFees']) ? $orderSf['TotalFees'] : 0),
638
- "other_shoppingflux" => $orderSf['Other'],
639
- "order_id_shoppingflux" => $orderIdShoppingFlux,
640
- "grand_total" => $orderSf['TotalAmount'],
641
- "base_grand_total" => $orderSf['TotalAmount'],
642
- "order_currency_code" => isset($orderSf['Currency'])?$orderSf['Currency']:'EUR',
643
- "base_currency_code" => isset($orderSf['Currency'])?$orderSf['Currency']:'EUR',
644
- "store_currency_code" => isset($orderSf['Currency'])?$orderSf['Currency']:'EUR',
645
-
646
- );
647
-
648
- if(isset($orderSf['ShippingAddress'][0]['RelayID']) && $orderSf['ShippingAddress'][0]['RelayID']) {
649
- if($additionalData['other_shoppingflux']) {
650
- $additionalData['other_shoppingflux'] .= '<br/>';
651
- }
652
- $additionalData['other_shoppingflux'] .= 'Relay ID : ' . $orderSf['ShippingAddress'][0]['RelayID'];
653
- }
654
-
655
- $shippingMethod = $this->getConfig()->getShippingMethodFor($orderSf['Marketplace'], $orderSf['ShippingMethod'], $storeId);
656
- if($shippingMethod) {
657
- $additionalData['shipping_method'] = $shippingMethod;
658
- $additionalData['shipping_description'] = "Frais de port de la place de marché (" . $shippingMethod . ")";
659
- }
660
- /* @var $service Mage_Sales_Model_Service_Quote */
661
- $quote = $this->_getQuote();
662
- $service = Mage::getModel('sales/service_quote', $this->_getQuote());
663
- $service->setOrderData($additionalData);
664
- $order = false;
665
-
666
- ini_set('display_errors', 1);
667
- error_reporting(-1);
668
-
669
- try {
670
- if (method_exists($service, "submitAll")) {
671
-
672
- $service->submitAll();
673
- $order = $service->getOrder();
674
- } else {
675
-
676
- $order = $service->submit();
677
- }
678
- } catch(Exception $e) {
679
- throw $e;
680
- }
681
- try {
682
- $quote->setIsActive(0)->setUpdatedAt(date('Y-m-d H:i:s', strtotime('-1 year')))->save();
683
- } catch (Exception $ex) {
684
-
685
- }
686
-
687
- if ($order) {
688
-
689
- $newStatus = $this->getConfig()->getConfigData('shoppingflux_mo/manageorders/new_order_status', $order->getStoreId());
690
- if ($newStatus) {
691
- $order->setStatus($newStatus);
692
- $order->save();
693
- }
694
-
695
-
696
-
697
- $this->_saveInvoice($order);
698
-
699
-
700
- $processingStatus = $this->getConfig()->getConfigData('shoppingflux_mo/manageorders/processing_order_status', $order->getStoreId());
701
- if ($processingStatus && $order->getState() == 'processing') {
702
- $order->setStatus($processingStatus);
703
- $order->save();
704
- }
705
-
706
- foreach($order->getAllItems() as $orderItem) {
707
- if($orderItem->getWeeeTaxAppliedRowAmount()) {
708
- /*Mage::log('------order : ' . $order->getIncrementId(). '--------START', null, 'sf.debug.weee.log');
709
- Mage::log('------order : ' . $order->getIncrementId(). '---BEFORE', null, 'sf.debug.weee.log');
710
- Mage::log('row_total_incl_tax : ' . $orderItem->getData('row_total_incl_tax'), null, 'sf.debug.weee.log');
711
- Mage::log('base_row_total_incl_tax : ' . $orderItem->getData('base_row_total_incl_tax'), null, 'sf.debug.weee.log');
712
- Mage::log('row_total : ' . $orderItem->getData('row_total'), null, 'sf.debug.weee.log');
713
- Mage::log('base_row_total : ' . $orderItem->getData('base_row_total'), null, 'sf.debug.weee.log');
714
- Mage::log('price : ' . $orderItem->getData('price'), null, 'sf.debug.weee.log');
715
- Mage::log('base_price : ' . $orderItem->getData('base_price'), null, 'sf.debug.weee.log');
716
- Mage::log('weee_tax_applied_row_amount : ' . $orderItem->getData('weee_tax_applied_row_amount'), null, 'sf.debug.weee.log');
717
- Mage::log('base_weee_tax_applied_row_amnt : ' . $orderItem->getData('base_weee_tax_applied_row_amnt'), null, 'sf.debug.weee.log');
718
- Mage::log('weee_tax_applied_amount : ' . $orderItem->getData('weee_tax_applied_amount'), null, 'sf.debug.weee.log');
719
- Mage::log('base_weee_tax_applied_amount : ' . $orderItem->getData('base_weee_tax_applied_amount'), null, 'sf.debug.weee.log');*/
720
- if($orderItem->getData('row_total_incl_tax')) {
721
- $orderItem->setData('row_total_incl_tax', $orderItem->getData('row_total_incl_tax') - $orderItem->getWeeeTaxAppliedRowAmount());
722
- }
723
- if($orderItem->getData('base_row_total_incl_tax')) {
724
- $orderItem->setData('base_row_total_incl_tax', $orderItem->getData('base_row_total_incl_tax') - $orderItem->getBaseWeeeTaxAppliedRowAmnt());
725
- }
726
- $orderItem->setData('row_total', $orderItem->getData('row_total') - $orderItem->getWeeeTaxAppliedRowAmount());
727
- $orderItem->setData('base_row_total', $orderItem->getData('base_row_total') - $orderItem->getBaseWeeeTaxAppliedRowAmnt());
728
- $orderItem->setData('price', $orderItem->getData('price') - $orderItem->getWeeeTaxAppliedAmount());
729
- $orderItem->setData('base_price', $orderItem->getData('base_price') - $orderItem->getBaseWeeeTaxAppliedAmount());
730
- $orderItem->save();
731
-
732
- /*Mage::log('------order : ' . $order->getIncrementId(). '---AFTER', null, 'sf.debug.weee.log');
733
- Mage::log('row_total_incl_tax : ' . $orderItem->getData('row_total_incl_tax'), null, 'sf.debug.weee.log');
734
- Mage::log('base_row_total_incl_tax : ' . $orderItem->getData('base_row_total_incl_tax'), null, 'sf.debug.weee.log');
735
- Mage::log('row_total : ' . $orderItem->getData('row_total'), null, 'sf.debug.weee.log');
736
- Mage::log('base_row_total : ' . $orderItem->getData('base_row_total'), null, 'sf.debug.weee.log');
737
- Mage::log('price : ' . $orderItem->getData('price'), null, 'sf.debug.weee.log');
738
- Mage::log('base_price : ' . $orderItem->getData('base_price'), null, 'sf.debug.weee.log');
739
- Mage::log('------order : ' . $order->getIncrementId(). '--------STOP', null, 'sf.debug.weee.log');*/
740
-
741
- }
742
- }
743
-
744
-
745
- //$this->_orderIdsAlreadyImported[] = $orderIdShoppingFlux;
746
- $this->_ordersIdsImported[$orderIdShoppingFlux]['MageOrderId'] = $order->getIncrementId();
747
-
748
- //if(Mage::helper('sales')->canSendNewOrderEmail()) {
749
- //$order->sendNewOrderEmail();
750
- //}
751
-
752
- return $order;
753
- }
754
-
755
- return null;
756
- }
757
-
758
- protected function _saveOrder13(array $orderSf, $storeId) {
759
- $orderIdShoppingFlux = (string) $orderSf['IdOrder'];
760
- $additionalData = array("from_shoppingflux" => 1,
761
- "marketplace_shoppingflux" => $orderSf['Marketplace'],
762
- "fees_shoppingflux" => (float) (isset($orderSf['Fees']) ? $orderSf['Fees'] : 0.0),
763
- "other_shoppingflux" => $orderSf['Other'],
764
- "order_id_shoppingflux" => $orderIdShoppingFlux);
765
-
766
-
767
- $billing = $this->_getQuote()->getBillingAddress();
768
- $shipping = $this->_getQuote()->getShippingAddress();
769
-
770
- $this->_getQuote()->reserveOrderId();
771
- $convertQuote = Mage::getModel('sales/convert_quote');
772
- /* @var $convertQuote Mage_Sales_Model_Convert_Quote */
773
-
774
- $order = $convertQuote->addressToOrder($shipping);
775
-
776
- $order->addData($additionalData);
777
-
778
- /* @var $order Mage_Sales_Model_Order */
779
- $order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
780
- $order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
781
-
782
- $order->setPayment($convertQuote->paymentToOrderPayment($this->_getQuote()->getPayment()));
783
-
784
- foreach ($this->_getQuote()->getAllItems() as $item) {
785
- $orderItem = $convertQuote->itemToOrderItem($item);
786
- if ($item->getParentItem()) {
787
- $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
788
- }
789
- $order->addItem($orderItem);
790
- }
791
-
792
- /**
793
- * We can use configuration data for declare new order status
794
- */
795
- Mage::dispatchEvent('checkout_type_onepage_save_order', array('order' => $order, 'quote' => $this->getQuote()));
796
- //Mage::throwException(print_r($order->getData(),true));
797
- //die("<pre> DIE = ".print_r($order->getData()));
798
- $order->place();
799
-
800
- $order->setCustomerId($this->_getQuote()->getCustomer()->getId());
801
-
802
- $order->setEmailSent(false);
803
- $order->save();
804
-
805
- Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
806
-
807
- $this->_getQuote()->setIsActive(false);
808
- $this->_getQuote()->save();
809
-
810
- ///////////////////////////////////////////////////////////////////////////
811
-
812
- if ($order) {
813
-
814
- $this->_saveInvoice($order);
815
-
816
- //Set array with shopping flux ids
817
- $this->_ordersIdsImported[$orderIdShoppingFlux] = array('Marketplace' => $orderSf['Marketplace'], 'MageOrderId' => $order->getIncrementId());
818
-
819
- return $order;
820
- }
821
-
822
- return null;
823
- }
824
-
825
- /**
826
- * Create and Save invoice for the new order
827
- * @param Mage_Sales_Model_Order $order
828
- */
829
- protected function _saveInvoice($order) {
830
- Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->_getQuote()));
831
-
832
- if (!$this->getConfig()->createInvoice($order->getStoreId())) {
833
- return $this;
834
- }
835
-
836
- //Prepare invoice and save it
837
- $path = Mage::getBaseDir() . "/app/code/core/Mage/Sales/Model/Service/Order.php";
838
- $invoice = false;
839
- if (file_exists($path)) {
840
- $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
841
- } else {
842
- $invoice = $this->_initInvoice($order);
843
- }
844
-
845
- if ($invoice) {
846
- $invoice->setBaseGrandTotal($order->getBaseGrandTotal());
847
- $invoice->setGrandTotal($order->getGrandTotal());
848
- $invoice->register();
849
- $invoice->getOrder()->setCustomerNoteNotify(false);
850
- $invoice->getOrder()->setIsInProcess(true);
851
-
852
-
853
- $transactionSave = Mage::getModel('core/resource_transaction')
854
- ->addObject($invoice)
855
- ->addObject($invoice->getOrder());
856
- $transactionSave->save();
857
- }
858
- }
859
-
860
- /**
861
- * Initialize invoice
862
- * @param Mage_Sales_Model_Order $order
863
- * @return Mage_Sales_Model_Order_Invoice $invoice
864
- */
865
- protected function _initInvoice($order) {
866
-
867
- $convertor = Mage::getModel('sales/convert_order');
868
- $invoice = $convertor->toInvoice($order);
869
- $update = false;
870
- $savedQtys = array();
871
- $itemsToInvoice = 0;
872
- /* @var $orderItem Mage_Sales_Model_Order_Item */
873
- foreach ($order->getAllItems() as $orderItem) {
874
-
875
- if (!$orderItem->isDummy() && !$orderItem->getQtyToInvoice() && $orderItem->getLockedDoInvoice()) {
876
- continue;
877
- }
878
-
879
- if ($order->getForcedDoShipmentWithInvoice() && $orderItem->getLockedDoShip()) {
880
- continue;
881
- }
882
-
883
- if (!$update && $orderItem->isDummy() && !empty($savedQtys) && !$this->_needToAddDummy($orderItem, $savedQtys)) {
884
- continue;
885
- }
886
- $item = $convertor->itemToInvoiceItem($orderItem);
887
-
888
- if (isset($savedQtys[$orderItem->getId()])) {
889
- $qty = $savedQtys[$orderItem->getId()];
890
- } else {
891
- if ($orderItem->isDummy()) {
892
- $qty = 1;
893
- } else {
894
- $qty = $orderItem->getQtyToInvoice();
895
- }
896
- }
897
- $itemsToInvoice += floatval($qty);
898
- $item->setQty($qty);
899
- $invoice->addItem($item);
900
-
901
- if ($itemsToInvoice <= 0) {
902
- Mage::throwException($this->__('Invoice could not be created (no items).'));
903
- }
904
- }
905
-
906
-
907
- $invoice->collectTotals();
908
-
909
- return $invoice;
910
- }
911
-
912
- /**
913
- * Get Helper
914
- * @return Profileolabs_Shoppingflux_Model_Manageorders_Helper_Data
915
- */
916
- public function getHelper() {
917
- return Mage::helper('profileolabs_shoppingflux');
918
- }
919
-
920
- public function getNbOrdersImported() {
921
- return $this->_nb_orders_imported;
922
- }
923
-
924
  }
1
+ <?php
2
+
3
+ /**
4
+ * Orders getted here
5
+ *
6
+ * @category ShoppingFlux
7
+ * @package Profileolabs_Shoppingflux
8
+ * @author kassim belghait, vincent enjalbert @ web-cooking
9
+ *
10
+ */
11
+ class Profileolabs_Shoppingflux_Model_Manageorders_Order extends Varien_Object {
12
+
13
+ /**
14
+ * @var Mage_Sales_Model_Quote
15
+ */
16
+ protected $_quote = null;
17
+
18
+ /**
19
+ * @var Mage_Customer_Model_Customer
20
+ */
21
+ protected $_customer = null;
22
+
23
+ /**
24
+ * Config Data of Module Manageorders
25
+ * @var Profileolabs_Shoppingflux_Model_Manageorders_Config
26
+ */
27
+ protected $_config = null;
28
+ protected $_paymentMethod = 'shoppingflux_purchaseorder';
29
+ protected $_shippingMethod = 'shoppingflux_shoppingflux';
30
+ protected $_nb_orders_imported = 0;
31
+ protected $_nb_orders_read = 0;
32
+ protected $_ordersIdsImported = array();
33
+ //protected $_orderIdsAlreadyImported = null;
34
+ protected $_result;
35
+ protected $_resultSendOrder = "";
36
+ protected $_isUnderVersion14 = null;
37
+
38
+ //security for some mal-configured magento, or old ones.
39
+ protected $_excludeConfigurableAttributes = array(
40
+ 'weight',
41
+ 'news_from_date',
42
+ 'news_to_date',
43
+ 'url_key',
44
+ 'sku',
45
+ 'description',
46
+ 'short_description',
47
+ 'meta_title',
48
+ 'meta_description',
49
+ 'meta_keyword',
50
+ 'name',
51
+ 'tax_class_id',
52
+ 'status',
53
+ 'price',
54
+ 'special_price',
55
+ 'special_from_date',
56
+ 'special_to_date',
57
+ 'cost',
58
+ 'image',
59
+ 'small_image',
60
+ 'thumbnail',
61
+ 'status',
62
+ 'visibility',
63
+ 'custom_design_from',
64
+ 'options_container',
65
+ 'msrp_enabled',
66
+ 'msrp_display_actual_price_type',
67
+ 'shoppingflux_default_category',
68
+ 'shoppingflux_product',
69
+ 'main_category'
70
+ );
71
+
72
+ /**
73
+ * Product model
74
+ *
75
+ * @var Mage_Catalog_Model_Product
76
+ */
77
+ protected $_productModel;
78
+
79
+ public function getResultSendOrder() {
80
+ return $this->_resultSendOrder;
81
+ }
82
+
83
+ public function isUnderVersion14() {
84
+ if (is_null($this->_isUnderVersion14)) {
85
+ $this->_isUnderVersion14 = $this->getHelper()->isUnderVersion14();
86
+ }
87
+ return $this->_isUnderVersion14;
88
+ }
89
+
90
+ /**
91
+ * Retrieve product model cache
92
+ *
93
+ * @return Mage_Catalog_Model_Product
94
+ */
95
+ public function getProductModel() {
96
+ if (is_null($this->_productModel)) {
97
+ $productModel = Mage::getModel('profileolabs_shoppingflux/manageorders_product');
98
+ $this->_productModel = Mage::objects()->save($productModel);
99
+ }
100
+ return Mage::objects()->load($this->_productModel);
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @deprecated
106
+ */
107
+ public function getOrderIdsAlreadyImported() {
108
+ if (is_null($this->_orderIdsAlreadyImported)) {
109
+ $orders = Mage::getModel('sales/order')->getCollection()
110
+ ->addAttributeToFilter('from_shoppingflux', 1)
111
+ ->addAttributeToSelect('order_id_shoppingflux');
112
+
113
+ $this->_orderIdsAlreadyImported = array();
114
+ foreach ($orders as $order) {
115
+ $this->_orderIdsAlreadyImported[] = $order->getOrderIdShoppingflux();
116
+ }
117
+ }
118
+
119
+ return $this->_orderIdsAlreadyImported;
120
+ }
121
+
122
+
123
+
124
+ public function isAlreadyImported($idShoppingflux) {
125
+ $orders = Mage::getModel('sales/order')->getCollection()
126
+ ->addAttributeToFilter('from_shoppingflux', 1)
127
+ ->addAttributeToFilter('order_id_shoppingflux', $idShoppingflux)
128
+ ->addAttributeToSelect('increment_id');
129
+ if($orders->count() > 0) {
130
+ return $orders->getFirstItem();
131
+ }
132
+
133
+ /* Double vérification, pour gérer un appel simultané. (qui ne devrait pas arriver, mais au cas ou..) */
134
+ $config = new Mage_Core_Model_Config();
135
+ $flagPath = Mage::getStoreConfig('shoppingflux/order_flags/order_'.$idShoppingflux);
136
+ if ($flagPath) {
137
+ $config->saveConfig('shoppingflux/order_flags/order_'.$idShoppingflux, 0);
138
+ return true;
139
+ }
140
+ $config->saveConfig('shoppingflux/order_flags/order_'.$idShoppingflux, date('Y-m-d H:i:s'));
141
+ /* end double check */
142
+
143
+ return false;
144
+ }
145
+
146
+ public function getSession() {
147
+ return Mage::getSingleton('checkout/session');
148
+ }
149
+
150
+ protected function _getQuote($storeId = null) {
151
+ return $this->getSession()->getQuote();
152
+ }
153
+
154
+ /**
155
+ * Retrieve config
156
+ * @return Profileolabs_Shoppingflux_Model_Manageorders_Config
157
+ */
158
+ public function getConfig() {
159
+ if (is_null($this->_config)) {
160
+ $this->_config = Mage::getSingleton('profileolabs_shoppingflux/config');
161
+ }
162
+
163
+ return $this->_config;
164
+ }
165
+
166
+ /**
167
+ * Get orders and create it
168
+ */
169
+ public function manageOrders() {
170
+ //Set boolean shopping flux
171
+ Mage::register('is_shoppingfeed_import', 1, true);
172
+
173
+
174
+ //compatibility with AutoShipping extension
175
+ Mage::app()->getStore()->setConfig('autoshipping/settings/enabled', "0");
176
+
177
+ $stores = Mage::app()->getStores();
178
+
179
+ $storeCode = Mage::app()->getStore()->getCode();
180
+ $isAdmin = ($storeCode == 'admin');
181
+ if (!$isAdmin) {
182
+ Mage::app()->setCurrentStore('admin');
183
+ }
184
+
185
+ $apiKeyManaged = array();
186
+
187
+ //old module version compliance. The goal is to use default store, as in previous versions, if api key is set in global scope.
188
+ $defaultStoreId = Mage::app()->getDefaultStoreView()->getId();
189
+ if (key($stores) != $defaultStoreId) {
190
+ $tmpStores = array($defaultStoreId => $stores[$defaultStoreId]);
191
+ foreach ($stores as $store) {
192
+ if ($store->getId() != $defaultStoreId) {
193
+ $tmpStores[$store->getId()] = $store;
194
+ }
195
+ }
196
+ $stores = $tmpStores;
197
+ }
198
+ //old module version compliance end
199
+
200
+
201
+ foreach ($stores as $_store) {
202
+ if(!$isAdmin && $storeCode != $_store->getCode()) {
203
+ continue;
204
+ }
205
+ $storeId = $_store->getId();
206
+ if ($this->getConfig()->isOrdersEnabled($storeId)) {
207
+ $apiKey = $this->getConfig()->getApiKey($storeId);
208
+
209
+ if (!$apiKey || in_array($apiKey, $apiKeyManaged))
210
+ continue;
211
+ $apiKeyManaged[] = $apiKey;
212
+
213
+ $wsUri = $this->getConfig()->getWsUri();
214
+
215
+ //$isUnderVersion14 = $this->getHelper()->isUnderVersion14();
216
+
217
+ /* @var $service Profileolabs_Shoppingflux_Model_Service */
218
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
219
+ ini_set("memory_limit", $this->getConfig()->getMemoryLimit() . "M");
220
+ try {
221
+
222
+ /* @var $this->_result Varien_Simplexml_Element */
223
+ $this->_result = $service->getOrders();
224
+
225
+ $this->_nb_orders_imported = 0;
226
+ } catch (Exception $e) {
227
+ Mage::logException($e);
228
+ $message = Mage::helper('profileolabs_shoppingflux')->__('Order import error : %s', $e->getMessage());
229
+ $this->getHelper()->log($message);
230
+ //Mage::throwException($message);
231
+
232
+ Mage::throwException($e);
233
+ }
234
+
235
+ //We parse result
236
+ //$nodes = current($this->_result->children());
237
+ $nodes = $this->_result->children();
238
+ if($nodes && count($nodes) > 0) {
239
+ foreach ($nodes as $childName => $child) {
240
+
241
+ $orderSf = $this->getHelper()->asArray($child);
242
+
243
+
244
+ if (($importedOrder = $this->isAlreadyImported($orderSf['IdOrder']))) {
245
+ $this->_ordersIdsImported[$orderSf['IdOrder']] = array(
246
+ 'Marketplace' => $orderSf['Marketplace'],
247
+ 'MageOrderId' => is_object($importedOrder)?$importedOrder->getIncrementId():'',
248
+ 'ShippingMethod' => $orderSf['ShippingMethod'],
249
+ 'ErrorOrder' => is_object($importedOrder)?false:true
250
+ );
251
+ continue;
252
+ }
253
+
254
+ $this->_nb_orders_read++;
255
+
256
+ $this->createAllForOrder($orderSf, $storeId);
257
+
258
+ if ($this->_nb_orders_imported == $this->getConfig()->getLimitOrders($storeId))
259
+ break;
260
+ }
261
+ }
262
+
263
+ try {
264
+ if ($this->_nb_orders_imported > 0 || count($this->_ordersIdsImported)) {
265
+
266
+ $result = $service->sendValidOrders($this->_ordersIdsImported);
267
+ foreach($this->_ordersIdsImported as $importedOrder) {
268
+ $shippingMethod = isset($importedOrder['ShippingMethod'])?$importedOrder['ShippingMethod']:'';
269
+ $marketplace = $importedOrder['Marketplace'];
270
+ try {
271
+ Mage::getModel('profileolabs_shoppingflux/manageorders_shipping_method')->saveShippingMethod($marketplace, $shippingMethod);
272
+ } catch(Exception $e) {
273
+
274
+ }
275
+ }
276
+
277
+
278
+ if ($result) {
279
+ if ($result->error) {
280
+ Mage::throwException($result->error);
281
+ }
282
+
283
+ $this->_resultSendOrder = $result->status;
284
+ } else {
285
+ $this->getHelper()->log("Error in order ids validated");
286
+ Mage::throwException("Error in order ids validated");
287
+ }
288
+ }
289
+ } catch (Exception $e) {
290
+ $this->getHelper()->log($e->getMessage());
291
+ Mage::throwException($e);
292
+ }
293
+ }
294
+ }
295
+ $this->clearOldOrderFlagFiles();
296
+ return $this;
297
+ }
298
+
299
+ public function clearOldOrderFlagFiles() {
300
+ $config = new Mage_Core_Model_Config();
301
+ $orderFlags = Mage::getStoreConfig('shoppingflux/order_flags');
302
+ if(!$orderFlags || empty($orderFlags)) {
303
+ return;
304
+ }
305
+ foreach($orderFlags as $orderId => $importDate) {
306
+ if(strtotime($importDate) < time()-3*60*60) {
307
+ $config->deleteConfig('shoppingflux/order_flags/' . $orderId);//retro-compatibility.
308
+ $config->deleteConfig('shoppingflux/order_flags/order_' . $orderId);
309
+ }
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Inititalize the quote with minimum requirement
315
+ * @param array $orderSf
316
+ */
317
+ protected function _initQuote(array $orderSf, $storeId) {
318
+
319
+ if (is_null($storeId)) {//just in case..
320
+ $storeId = Mage::app()->getDefaultStoreView()->getId();
321
+ }
322
+
323
+ $this->_getQuote()->setStoreId($storeId);
324
+
325
+ //Super mode is setted to bypass check item qty ;)
326
+ $this->_getQuote()->setIsSuperMode(true);
327
+
328
+ $this->_getQuote()->setCustomer($this->_customer);
329
+ }
330
+
331
+ /**
332
+ * Create or Update customer with converter
333
+ * @param array $data Data From ShoppingFlux
334
+ */
335
+ protected function _createCustomer(array $data, $storeId) {
336
+ try {
337
+
338
+ /* @var $convert_customer Profileolabs_Shoppingflux_Model_Manageorders_Convert_Customer */
339
+ $convert_customer = Mage::getModel('profileolabs_shoppingflux/manageorders_convert_customer');
340
+
341
+ $this->_customer = $convert_customer->toCustomer(current($data['BillingAddress']), $storeId);
342
+ $billingAddress = $convert_customer->addresstoCustomer(current($data['BillingAddress']), $storeId, $this->_customer);
343
+
344
+ $this->_customer->addAddress($billingAddress);
345
+
346
+ $shippingAddress = $convert_customer->addresstoCustomer(current($data['ShippingAddress']), $storeId, $this->_customer, 'shipping');
347
+ $this->_customer->addAddress($shippingAddress);
348
+ $customerGroupId = $this->getConfig()->getCustomerGroupIdFor($data['Marketplace'], $storeId);
349
+ if ($customerGroupId) {
350
+ $this->_customer->setGroupId($customerGroupId);
351
+ }
352
+ $this->_customer->save();
353
+ } catch (Exception $e) {
354
+ Mage::throwException($e);
355
+ }
356
+ }
357
+
358
+ public function createAllForOrder($orderSf, $storeId) {
359
+ try {
360
+ $orderIdShoppingFlux = (string) $orderSf['IdOrder'];
361
+
362
+ $dataObj = new Varien_Object(array('entry' => $orderSf, 'store_id'=>$storeId));
363
+ Mage::dispatchEvent('shoppingflux_before_import_order', array('order_sf' => $dataObj));
364
+ $orderSf = $dataObj->getEntry();
365
+
366
+ //Set array with shopping flux ids
367
+ $this->_ordersIdsImported[$orderIdShoppingFlux] = array(
368
+ 'Marketplace' => $orderSf['Marketplace'],
369
+ 'MageOrderId' => '',
370
+ 'ShippingMethod' => $orderSf['ShippingMethod'],
371
+ 'ErrorOrder' => false
372
+ );
373
+
374
+ //$this->_quote = null;
375
+ $this->_customer = null;
376
+
377
+
378
+ //Create or Update customer with addresses
379
+ $this->_createCustomer($orderSf, $storeId);
380
+
381
+ $this->_initQuote($orderSf, $storeId);
382
+
383
+ if(Mage::registry('current_order_sf')) {
384
+ Mage::unregister('current_order_sf');
385
+ }
386
+ Mage::register('current_order_sf', $orderSf);
387
+
388
+ if(Mage::registry('current_quote_sf')) {
389
+ Mage::unregister('current_quote_sf');
390
+ }
391
+ Mage::register('current_quote_sf', $this->_getQuote());
392
+
393
+ //Add products to quote with data from ShoppingFlux
394
+ $this->_addProductsToQuote($orderSf, $storeId);
395
+
396
+ $order = null;
397
+ if (!$this->isUnderVersion14())
398
+ $order = $this->_saveOrder($orderSf, $storeId);
399
+ else
400
+ $order = $this->_saveOrder13($orderSf, $storeId);
401
+
402
+ if($order) {
403
+ $this->getHelper()->log('Order ' . $orderSf['IdOrder'] . ' has been created (' . $order->getIncrementId() . ' / ' . Mage::app()->getStore()->getId() . ')');
404
+ $this->_nb_orders_imported++;
405
+
406
+ if (!is_null($order) && $order->getId()) {
407
+ $useMarketplaceDate = $this->getConfig()->getConfigFlag('shoppingflux_mo/manageorders/use_marketplace_date');
408
+ //$orderDate = date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time()));
409
+ if($useMarketplaceDate) {
410
+ $orderDate = $orderSf['OrderDate'];
411
+ $this->_changeDateCreatedAt($order, $orderDate);
412
+ }
413
+ }
414
+
415
+ }
416
+ //Erase session for the next order
417
+ $this->getSession()->clear();
418
+ } catch (Exception $e) {
419
+ $this->getHelper()->log($e->getMessage() . ' Trace : ' . $e->getTraceAsString(), $orderSf['IdOrder']);
420
+ $this->_ordersIdsImported[$orderIdShoppingFlux]['ErrorOrder'] = $e->getMessage();
421
+ //$this->clearOrderFlagFile($orderSf['IdOrder']);
422
+ //Erase session for the next order
423
+ $this->getSession()->clear();
424
+ }
425
+ }
426
+
427
+ protected function _changeDateCreatedAt($order, $date) {
428
+ try {
429
+ $order->setCreatedAt($date);
430
+ //$order->setUpdatedAt($date);
431
+ $order->save();
432
+ } catch (Exception $e) {
433
+ Mage::logException($e);
434
+ Mage::throwException($message);
435
+ }
436
+ }
437
+
438
+ /**
439
+ * Add products to quote with data from ShoppinfFlux
440
+ * @param array $orderSf
441
+ */
442
+ protected function _addProductsToQuote(array $orderSf, $storeId) {
443
+ $totalAmount = $orderSf['TotalAmount'];
444
+ $productsSf = current($orderSf['Products']);
445
+ $productsToIterate = current($productsSf);
446
+
447
+
448
+
449
+
450
+ if (!$this->_customer->getDefaultBilling() || !$this->_customer->getDefaultShipping() || (is_object($this->_customer->getDefaultShipping()) && !$this->_customer->getDefaultShipping()->getFirstname()))
451
+ $this->_customer->load($this->_customer->getId());
452
+
453
+ $customerAddressBillingId = $this->_customer->getDefaultBilling();
454
+ $customerAddressShippingId = $this->_customer->getDefaultShipping();
455
+
456
+ //Set billing Address
457
+ $addressBilling = $this->_getQuote()->getBillingAddress();
458
+ //Make sure addresses will be saved without validation errors
459
+ $addressBilling->setShouldIgnoreValidation(true);
460
+ $customerAddressBilling = Mage::getModel('customer/address')->load($customerAddressBillingId);
461
+ $addressBilling->importCustomerAddress($customerAddressBilling)->setSaveInAddressBook(0);
462
+
463
+ //Set shipping Address
464
+ $addressShipping = $this->_getQuote()->getShippingAddress();
465
+ //Make sure addresses will be saved without validation errors
466
+ $addressShipping->setShouldIgnoreValidation(true);
467
+ $customerAddressShipping = Mage::getModel('customer/address')->load($customerAddressShippingId);
468
+ $addressShipping->importCustomerAddress($customerAddressShipping)->setSaveInAddressBook(0);
469
+ $addressShipping->setSameAsBilling(0);
470
+
471
+
472
+
473
+
474
+ //Set shipping Mehtod and collect shipping rates
475
+ $addressShipping->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
476
+
477
+
478
+
479
+
480
+ foreach ($productsToIterate as $key => $productSf) {
481
+
482
+ $sku = $productSf['SKU'];
483
+ $qtyIncrements = 1;
484
+ if(preg_match('%^_SFQI_([0-9]+)_(.*)$%i', $sku, $pregResults)) {
485
+ $sku = $pregResults[2];
486
+ $qtyIncrements = $pregResults[1];
487
+ }
488
+
489
+ $useProductId = $this->getConfig()->getConfigData('shoppingflux_mo/manageorders/use_product_id', $storeId);
490
+
491
+ if($useProductId) {
492
+ $productId = $sku;
493
+ } else {
494
+ $productId = $this->getProductModel()->getResource()->getIdBySku($sku);
495
+ }
496
+
497
+ $product = Mage::getModel('profileolabs_shoppingflux/manageorders_product')->setStoreId($storeId)->load($productId);
498
+
499
+ if ($product->getId()) {
500
+
501
+ $request = new Varien_Object(array('qty' => $productSf['Quantity'] * $qtyIncrements));
502
+
503
+
504
+
505
+ $item = $this->_getQuote()->addProduct($product, $request);
506
+
507
+ if (!is_object($item)) {
508
+ $this->getSession()->clear();
509
+ Mage::throwException("le produit sku = " . $sku . " n'a pas pu être ajouté! Id = " . $product->getId() . " Item = " . (string) $item);
510
+ }
511
+
512
+
513
+ //Save the quote with the new product
514
+ $this->_getQuote()->save();
515
+
516
+
517
+ $unitPrice = $productSf['Price'] / $qtyIncrements;
518
+ if($unitPrice <= 0) {
519
+ $this->getHelper()->log('Order '.$orderSf['IdOrder'].' has a product with 0 price : '.$productSf['SKU']);
520
+ }
521
+ if ($this->getConfig()->applyTax() && !Mage::helper('tax')->priceIncludesTax()) {
522
+ $taxClassId = $product->getTaxClassId();
523
+ if($taxClassId > 0) {
524
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest($addressShipping, $addressBilling, null, null);
525
+ $request->setProductClassId($taxClassId);
526
+ $request->setCustomerClassId($this->_getQuote()->getCustomerTaxClassId());
527
+ $percent = Mage::getSingleton('tax/calculation')->getRate($request);
528
+ $unitPrice = $unitPrice / (1 + $percent / 100);
529
+ if($unitPrice <= 0) {
530
+ $this->getHelper()->log('Order '.$orderSf['IdOrder'].' has a product with 0 price after applying tax : '.$productSf['SKU']);
531
+ }
532
+ }
533
+ }
534
+
535
+
536
+
537
+
538
+ //Modify Item price
539
+ $item->setCustomPrice($unitPrice);
540
+ $item->setOriginalCustomPrice($unitPrice);
541
+
542
+
543
+ //add configurable attributes informations
544
+ $confAttributeValues = array();
545
+ if($this->isUnderVersion14()) {
546
+ $configurableAttributesCollection = Mage::getResourceModel('eav/entity_attribute_collection')
547
+ ->setEntityTypeFilter( Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId() );
548
+ } else {
549
+ $configurableAttributesCollection = Mage::getResourceModel('catalog/product_attribute_collection');
550
+ }
551
+ $configurableAttributesCollection->addVisibleFilter()
552
+ ->addFieldToFilter('is_configurable', 1);
553
+
554
+
555
+ foreach($configurableAttributesCollection as $confAttribute) {
556
+ if(!in_array($confAttribute->getAttributeCode(), $this->_excludeConfigurableAttributes) && $product->getData($confAttribute->getAttributeCode())) {
557
+ if($confAttribute->usesSource()) {
558
+ $confAttributeValue = $product->getAttributeText($confAttribute->getAttributeCode());
559
+ } else {
560
+ $confAttributeValue = $product->getData($confAttribute->getAttributeCode());
561
+ }
562
+ if(is_string($confAttributeValue)) {
563
+ $confAttributeValues[] = $confAttributeValue;
564
+ }
565
+ }
566
+ }
567
+ if(!empty($confAttributeValues)) {
568
+ $item->setDescription($item->getDescription() . implode(' - ', $confAttributeValues));
569
+ }
570
+
571
+ $item->save();
572
+
573
+ if (is_object($parentItem = $item->getParentItem())) {
574
+ $parentItem->setCustomPrice($unitPrice);
575
+ $parentItem->setOriginalCustomPrice($unitPrice);
576
+ $parentItem->save();
577
+ }
578
+
579
+ //Mage::log(print_r($item->debug(),true),null,'debug_items.log');
580
+ } else {
581
+
582
+ $this->getSession()->clear();
583
+ Mage::throwException("le produit sku = '" . $sku . "' (ID= ".$productId.", Utilisation id = ".($useProductId?'Oui':'Non').") n'existe plus en base!");
584
+ }
585
+ }
586
+
587
+ try {
588
+ $this->_getQuote()->collectTotals();
589
+ $this->_getQuote()->save();
590
+ } catch(Exception $e) {
591
+ if($e->getMessage() == Mage::helper('sales')->__('Please specify a shipping method.')) {
592
+ $this->_getQuote()->getShippingAddress()->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
593
+ $this->_getQuote()->setTotalsCollectedFlag(false)->collectTotals();
594
+ $this->_getQuote()->save();
595
+ } else {
596
+ throw $e;
597
+ }
598
+ }
599
+
600
+ //Set payment method
601
+ /* @var $payment Mage_Sales_Quote_Payment */
602
+ $this->_getQuote()->getShippingAddress()->setPaymentMethod($this->_paymentMethod);
603
+ $payment = $this->_getQuote()->getPayment();
604
+ $dataPayment = array('method' => $this->_paymentMethod, 'marketplace' => $orderSf['Marketplace']);
605
+ $payment->importData($dataPayment);
606
+ //$addressShipping->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
607
+
608
+ try {
609
+ $this->_getQuote()->collectTotals();
610
+ $this->_getQuote()->save();
611
+ } catch(Exception $e) {
612
+ if($e->getMessage() == Mage::helper('sales')->__('Please specify a shipping method.')) {
613
+ $this->_getQuote()->getShippingAddress()->setShippingMethod($this->_shippingMethod)->setCollectShippingRates(true);
614
+
615
+ $this->_getQuote()->getShippingAddress()->setPaymentMethod($this->_paymentMethod);
616
+ $payment = $this->_getQuote()->getPayment();
617
+ $dataPayment = array('method' => $this->_paymentMethod, 'marketplace' => $orderSf['Marketplace']);
618
+ $payment->importData($dataPayment);
619
+
620
+ $this->_getQuote()->setTotalsCollectedFlag(false)->collectTotals();
621
+ $this->_getQuote()->save();
622
+ } else {
623
+ throw $e;
624
+ }
625
+ }
626
+ }
627
+
628
+
629
+ /**
630
+ * Save the new order with the quote
631
+ * @param array $orderSf
632
+ */
633
+ protected function _saveOrder(array $orderSf, $storeId) {
634
+ $orderIdShoppingFlux = (string) $orderSf['IdOrder'];
635
+ $additionalData = array("from_shoppingflux" => 1,
636
+ "marketplace_shoppingflux" => $orderSf['Marketplace'],
637
+ "fees_shoppingflux" => (float) (isset($orderSf['TotalFees']) ? $orderSf['TotalFees'] : 0),
638
+ "other_shoppingflux" => $orderSf['Other'],
639
+ "order_id_shoppingflux" => $orderIdShoppingFlux,
640
+ "grand_total" => $orderSf['TotalAmount'],
641
+ "base_grand_total" => $orderSf['TotalAmount'],
642
+ "order_currency_code" => isset($orderSf['Currency'])?$orderSf['Currency']:'EUR',
643
+ "base_currency_code" => isset($orderSf['Currency'])?$orderSf['Currency']:'EUR',
644
+ "store_currency_code" => isset($orderSf['Currency'])?$orderSf['Currency']:'EUR',
645
+
646
+ );
647
+
648
+ if(isset($orderSf['ShippingAddress'][0]['RelayID']) && $orderSf['ShippingAddress'][0]['RelayID']) {
649
+ if($additionalData['other_shoppingflux']) {
650
+ $additionalData['other_shoppingflux'] .= '<br/>';
651
+ }
652
+ $additionalData['other_shoppingflux'] .= 'Relay ID : ' . $orderSf['ShippingAddress'][0]['RelayID'];
653
+ }
654
+
655
+ $shippingMethod = $this->getConfig()->getShippingMethodFor($orderSf['Marketplace'], $orderSf['ShippingMethod'], $storeId);
656
+ if($shippingMethod) {
657
+ $additionalData['shipping_method'] = $shippingMethod;
658
+ $additionalData['shipping_description'] = "Frais de port de la place de marché (" . $shippingMethod . ")";
659
+ }
660
+ /* @var $service Mage_Sales_Model_Service_Quote */
661
+ $quote = $this->_getQuote();
662
+ $service = Mage::getModel('sales/service_quote', $this->_getQuote());
663
+ $service->setOrderData($additionalData);
664
+ $order = false;
665
+
666
+ ini_set('display_errors', 1);
667
+ error_reporting(-1);
668
+
669
+ try {
670
+ if (method_exists($service, "submitAll")) {
671
+
672
+ $service->submitAll();
673
+ $order = $service->getOrder();
674
+ } else {
675
+
676
+ $order = $service->submit();
677
+ }
678
+ } catch(Exception $e) {
679
+ throw $e;
680
+ }
681
+ try {
682
+ $quote->setIsActive(0)->setUpdatedAt(date('Y-m-d H:i:s', strtotime('-1 year')))->save();
683
+ } catch (Exception $ex) {
684
+
685
+ }
686
+
687
+ if ($order) {
688
+
689
+ $newStatus = $this->getConfig()->getConfigData('shoppingflux_mo/manageorders/new_order_status', $order->getStoreId());
690
+ if ($newStatus) {
691
+ $order->setStatus($newStatus);
692
+ $order->save();
693
+ }
694
+
695
+
696
+
697
+ $this->_saveInvoice($order);
698
+
699
+
700
+ $processingStatus = $this->getConfig()->getConfigData('shoppingflux_mo/manageorders/processing_order_status', $order->getStoreId());
701
+ if ($processingStatus && $order->getState() == 'processing') {
702
+ $order->setStatus($processingStatus);
703
+ $order->save();
704
+ }
705
+
706
+ foreach($order->getAllItems() as $orderItem) {
707
+ if($orderItem->getWeeeTaxAppliedRowAmount()) {
708
+ /*Mage::log('------order : ' . $order->getIncrementId(). '--------START', null, 'sf.debug.weee.log');
709
+ Mage::log('------order : ' . $order->getIncrementId(). '---BEFORE', null, 'sf.debug.weee.log');
710
+ Mage::log('row_total_incl_tax : ' . $orderItem->getData('row_total_incl_tax'), null, 'sf.debug.weee.log');
711
+ Mage::log('base_row_total_incl_tax : ' . $orderItem->getData('base_row_total_incl_tax'), null, 'sf.debug.weee.log');
712
+ Mage::log('row_total : ' . $orderItem->getData('row_total'), null, 'sf.debug.weee.log');
713
+ Mage::log('base_row_total : ' . $orderItem->getData('base_row_total'), null, 'sf.debug.weee.log');
714
+ Mage::log('price : ' . $orderItem->getData('price'), null, 'sf.debug.weee.log');
715
+ Mage::log('base_price : ' . $orderItem->getData('base_price'), null, 'sf.debug.weee.log');
716
+ Mage::log('weee_tax_applied_row_amount : ' . $orderItem->getData('weee_tax_applied_row_amount'), null, 'sf.debug.weee.log');
717
+ Mage::log('base_weee_tax_applied_row_amnt : ' . $orderItem->getData('base_weee_tax_applied_row_amnt'), null, 'sf.debug.weee.log');
718
+ Mage::log('weee_tax_applied_amount : ' . $orderItem->getData('weee_tax_applied_amount'), null, 'sf.debug.weee.log');
719
+ Mage::log('base_weee_tax_applied_amount : ' . $orderItem->getData('base_weee_tax_applied_amount'), null, 'sf.debug.weee.log');*/
720
+ if($orderItem->getData('row_total_incl_tax')) {
721
+ $orderItem->setData('row_total_incl_tax', $orderItem->getData('row_total_incl_tax') - $orderItem->getWeeeTaxAppliedRowAmount());
722
+ }
723
+ if($orderItem->getData('base_row_total_incl_tax')) {
724
+ $orderItem->setData('base_row_total_incl_tax', $orderItem->getData('base_row_total_incl_tax') - $orderItem->getBaseWeeeTaxAppliedRowAmnt());
725
+ }
726
+ $orderItem->setData('row_total', $orderItem->getData('row_total') - $orderItem->getWeeeTaxAppliedRowAmount());
727
+ $orderItem->setData('base_row_total', $orderItem->getData('base_row_total') - $orderItem->getBaseWeeeTaxAppliedRowAmnt());
728
+ $orderItem->setData('price', $orderItem->getData('price') - $orderItem->getWeeeTaxAppliedAmount());
729
+ $orderItem->setData('base_price', $orderItem->getData('base_price') - $orderItem->getBaseWeeeTaxAppliedAmount());
730
+ $orderItem->save();
731
+
732
+ /*Mage::log('------order : ' . $order->getIncrementId(). '---AFTER', null, 'sf.debug.weee.log');
733
+ Mage::log('row_total_incl_tax : ' . $orderItem->getData('row_total_incl_tax'), null, 'sf.debug.weee.log');
734
+ Mage::log('base_row_total_incl_tax : ' . $orderItem->getData('base_row_total_incl_tax'), null, 'sf.debug.weee.log');
735
+ Mage::log('row_total : ' . $orderItem->getData('row_total'), null, 'sf.debug.weee.log');
736
+ Mage::log('base_row_total : ' . $orderItem->getData('base_row_total'), null, 'sf.debug.weee.log');
737
+ Mage::log('price : ' . $orderItem->getData('price'), null, 'sf.debug.weee.log');
738
+ Mage::log('base_price : ' . $orderItem->getData('base_price'), null, 'sf.debug.weee.log');
739
+ Mage::log('------order : ' . $order->getIncrementId(). '--------STOP', null, 'sf.debug.weee.log');*/
740
+
741
+ }
742
+ }
743
+
744
+
745
+ //$this->_orderIdsAlreadyImported[] = $orderIdShoppingFlux;
746
+ $this->_ordersIdsImported[$orderIdShoppingFlux]['MageOrderId'] = $order->getIncrementId();
747
+
748
+ //if(Mage::helper('sales')->canSendNewOrderEmail()) {
749
+ //$order->sendNewOrderEmail();
750
+ //}
751
+
752
+ return $order;
753
+ }
754
+
755
+ return null;
756
+ }
757
+
758
+ protected function _saveOrder13(array $orderSf, $storeId) {
759
+ $orderIdShoppingFlux = (string) $orderSf['IdOrder'];
760
+ $additionalData = array("from_shoppingflux" => 1,
761
+ "marketplace_shoppingflux" => $orderSf['Marketplace'],
762
+ "fees_shoppingflux" => (float) (isset($orderSf['Fees']) ? $orderSf['Fees'] : 0.0),
763
+ "other_shoppingflux" => $orderSf['Other'],
764
+ "order_id_shoppingflux" => $orderIdShoppingFlux);
765
+
766
+
767
+ $billing = $this->_getQuote()->getBillingAddress();
768
+ $shipping = $this->_getQuote()->getShippingAddress();
769
+
770
+ $this->_getQuote()->reserveOrderId();
771
+ $convertQuote = Mage::getModel('sales/convert_quote');
772
+ /* @var $convertQuote Mage_Sales_Model_Convert_Quote */
773
+
774
+ $order = $convertQuote->addressToOrder($shipping);
775
+
776
+ $order->addData($additionalData);
777
+
778
+ /* @var $order Mage_Sales_Model_Order */
779
+ $order->setBillingAddress($convertQuote->addressToOrderAddress($billing));
780
+ $order->setShippingAddress($convertQuote->addressToOrderAddress($shipping));
781
+
782
+ $order->setPayment($convertQuote->paymentToOrderPayment($this->_getQuote()->getPayment()));
783
+
784
+ foreach ($this->_getQuote()->getAllItems() as $item) {
785
+ $orderItem = $convertQuote->itemToOrderItem($item);
786
+ if ($item->getParentItem()) {
787
+ $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
788
+ }
789
+ $order->addItem($orderItem);
790
+ }
791
+
792
+ /**
793
+ * We can use configuration data for declare new order status
794
+ */
795
+ Mage::dispatchEvent('checkout_type_onepage_save_order', array('order' => $order, 'quote' => $this->getQuote()));
796
+ //Mage::throwException(print_r($order->getData(),true));
797
+ //die("<pre> DIE = ".print_r($order->getData()));
798
+ $order->place();
799
+
800
+ $order->setCustomerId($this->_getQuote()->getCustomer()->getId());
801
+
802
+ $order->setEmailSent(false);
803
+ $order->save();
804
+
805
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
806
+
807
+ $this->_getQuote()->setIsActive(false);
808
+ $this->_getQuote()->save();
809
+
810
+ ///////////////////////////////////////////////////////////////////////////
811
+
812
+ if ($order) {
813
+
814
+ $this->_saveInvoice($order);
815
+
816
+ //Set array with shopping flux ids
817
+ $this->_ordersIdsImported[$orderIdShoppingFlux] = array('Marketplace' => $orderSf['Marketplace'], 'MageOrderId' => $order->getIncrementId());
818
+
819
+ return $order;
820
+ }
821
+
822
+ return null;
823
+ }
824
+
825
+ /**
826
+ * Create and Save invoice for the new order
827
+ * @param Mage_Sales_Model_Order $order
828
+ */
829
+ protected function _saveInvoice($order) {
830
+ Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->_getQuote()));
831
+
832
+ if (!$this->getConfig()->createInvoice($order->getStoreId())) {
833
+ return $this;
834
+ }
835
+
836
+ //Prepare invoice and save it
837
+ $path = Mage::getBaseDir() . "/app/code/core/Mage/Sales/Model/Service/Order.php";
838
+ $invoice = false;
839
+ if (file_exists($path)) {
840
+ $invoice = Mage::getModel('sales/service_order', $order)->prepareInvoice();
841
+ } else {
842
+ $invoice = $this->_initInvoice($order);
843
+ }
844
+
845
+ if ($invoice) {
846
+ $invoice->setBaseGrandTotal($order->getBaseGrandTotal());
847
+ $invoice->setGrandTotal($order->getGrandTotal());
848
+ $invoice->register();
849
+ $invoice->getOrder()->setCustomerNoteNotify(false);
850
+ $invoice->getOrder()->setIsInProcess(true);
851
+
852
+
853
+ $transactionSave = Mage::getModel('core/resource_transaction')
854
+ ->addObject($invoice)
855
+ ->addObject($invoice->getOrder());
856
+ $transactionSave->save();
857
+ }
858
+ }
859
+
860
+ /**
861
+ * Initialize invoice
862
+ * @param Mage_Sales_Model_Order $order
863
+ * @return Mage_Sales_Model_Order_Invoice $invoice
864
+ */
865
+ protected function _initInvoice($order) {
866
+
867
+ $convertor = Mage::getModel('sales/convert_order');
868
+ $invoice = $convertor->toInvoice($order);
869
+ $update = false;
870
+ $savedQtys = array();
871
+ $itemsToInvoice = 0;
872
+ /* @var $orderItem Mage_Sales_Model_Order_Item */
873
+ foreach ($order->getAllItems() as $orderItem) {
874
+
875
+ if (!$orderItem->isDummy() && !$orderItem->getQtyToInvoice() && $orderItem->getLockedDoInvoice()) {
876
+ continue;
877
+ }
878
+
879
+ if ($order->getForcedDoShipmentWithInvoice() && $orderItem->getLockedDoShip()) {
880
+ continue;
881
+ }
882
+
883
+ if (!$update && $orderItem->isDummy() && !empty($savedQtys) && !$this->_needToAddDummy($orderItem, $savedQtys)) {
884
+ continue;
885
+ }
886
+ $item = $convertor->itemToInvoiceItem($orderItem);
887
+
888
+ if (isset($savedQtys[$orderItem->getId()])) {
889
+ $qty = $savedQtys[$orderItem->getId()];
890
+ } else {
891
+ if ($orderItem->isDummy()) {
892
+ $qty = 1;
893
+ } else {
894
+ $qty = $orderItem->getQtyToInvoice();
895
+ }
896
+ }
897
+ $itemsToInvoice += floatval($qty);
898
+ $item->setQty($qty);
899
+ $invoice->addItem($item);
900
+
901
+ if ($itemsToInvoice <= 0) {
902
+ Mage::throwException($this->__('Invoice could not be created (no items).'));
903
+ }
904
+ }
905
+
906
+
907
+ $invoice->collectTotals();
908
+
909
+ return $invoice;
910
+ }
911
+
912
+ /**
913
+ * Get Helper
914
+ * @return Profileolabs_Shoppingflux_Model_Manageorders_Helper_Data
915
+ */
916
+ public function getHelper() {
917
+ return Mage::helper('profileolabs_shoppingflux');
918
+ }
919
+
920
+ public function getNbOrdersImported() {
921
+ return $this->_nb_orders_imported;
922
+ }
923
+
924
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Payment/Method/Purchaseorder.php CHANGED
@@ -1,44 +1,44 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_Shoppingflux
5
- * @author kassim belghait
6
- */
7
-
8
-
9
-
10
- class Profileolabs_Shoppingflux_Model_Manageorders_Payment_Method_Purchaseorder extends Mage_Payment_Model_Method_Abstract
11
- {
12
- protected $_code = 'shoppingflux_purchaseorder';
13
- //protected $_formBlockType = 'payment/form_purchaseorder';
14
- protected $_infoBlockType = 'profileolabs_shoppingflux/manageorders_payment_info_purchaseorder';
15
-
16
- /**
17
- * Assign data to info model instance
18
- *
19
- * @param mixed $data
20
- * @return Profileolabs_Shoppingflux_Model_Manageorders_Payment_Method_Purchaseorder
21
- */
22
- public function assignData($data)
23
- {
24
- if (!($data instanceof Varien_Object)) {
25
- $data = new Varien_Object($data);
26
- }
27
-
28
- $this->getInfoInstance()->setAdditionalData($data->getMarketplace());
29
- return $this;
30
- }
31
-
32
- /**
33
- * Check whether payment method can be used
34
- * TODO: payment method instance is not supposed to know about quote
35
- * @param Mage_Sales_Model_Quote
36
- * @return bool
37
- */
38
- public function isAvailable($quote = null)
39
- {
40
- if(Mage::registry('is_shoppingfeed_import')/*Mage::getSingleton('checkout/session')->getIsShoppingFlux()*/)
41
- return true;
42
- return parent::isAvailable($quote);
43
- }
44
- }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_Shoppingflux
5
+ * @author kassim belghait
6
+ */
7
+
8
+
9
+
10
+ class Profileolabs_Shoppingflux_Model_Manageorders_Payment_Method_Purchaseorder extends Mage_Payment_Model_Method_Abstract
11
+ {
12
+ protected $_code = 'shoppingflux_purchaseorder';
13
+ //protected $_formBlockType = 'payment/form_purchaseorder';
14
+ protected $_infoBlockType = 'profileolabs_shoppingflux/manageorders_payment_info_purchaseorder';
15
+
16
+ /**
17
+ * Assign data to info model instance
18
+ *
19
+ * @param mixed $data
20
+ * @return Profileolabs_Shoppingflux_Model_Manageorders_Payment_Method_Purchaseorder
21
+ */
22
+ public function assignData($data)
23
+ {
24
+ if (!($data instanceof Varien_Object)) {
25
+ $data = new Varien_Object($data);
26
+ }
27
+
28
+ $this->getInfoInstance()->setAdditionalData($data->getMarketplace());
29
+ return $this;
30
+ }
31
+
32
+ /**
33
+ * Check whether payment method can be used
34
+ * TODO: payment method instance is not supposed to know about quote
35
+ * @param Mage_Sales_Model_Quote
36
+ * @return bool
37
+ */
38
+ public function isAvailable($quote = null)
39
+ {
40
+ if(Mage::registry('is_shoppingfeed_import')/*Mage::getSingleton('checkout/session')->getIsShoppingFlux()*/)
41
+ return true;
42
+ return parent::isAvailable($quote);
43
+ }
44
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Product.php CHANGED
@@ -1,18 +1,18 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Manageorders_Product extends Mage_Catalog_Model_Product {
10
-
11
- public function getOptions() {
12
- return array();
13
- }
14
-
15
- public function getHasOptions() {
16
- return false;
17
- }
18
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Manageorders_Product extends Mage_Catalog_Model_Product {
10
+
11
+ public function getOptions() {
12
+ return array();
13
+ }
14
+
15
+ public function getHasOptions() {
16
+ return false;
17
+ }
18
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Shipping/Carrier/Shoppingflux.php CHANGED
@@ -1,106 +1,106 @@
1
- <?php
2
-
3
- /**
4
- * ShoppingFLux shipping model
5
- *
6
- * @category ShoppingFlux
7
- * @package Profileolabs_Shoppingflux
8
- * @author kassim belghait
9
- */
10
- class Profileolabs_Shoppingflux_Model_Manageorders_Shipping_Carrier_Shoppingflux
11
- extends Mage_Shipping_Model_Carrier_Abstract
12
- implements Mage_Shipping_Model_Carrier_Interface
13
- {
14
-
15
- protected $_code = 'shoppingflux';
16
- protected $_isFixed = true;
17
-
18
- /**
19
- * FreeShipping Rates Collector
20
- *
21
- * @param Mage_Shipping_Model_Rate_Request $request
22
- * @return Mage_Shipping_Model_Rate_Result
23
- */
24
- public function collectRates(Mage_Shipping_Model_Rate_Request $request)
25
- {
26
- if (!$this->isActive()) {
27
- return false;
28
- }
29
-
30
- $result = Mage::getModel('shipping/rate_result');
31
-
32
- $method = Mage::getModel('shipping/rate_result_method');
33
-
34
- $method->setCarrier('shoppingflux');
35
- $method->setCarrierTitle($this->getConfigData('title'));
36
-
37
- $method->setMethod('shoppingflux');
38
- $method->setMethodTitle($this->getConfigData('name'));
39
-
40
- $orderSf = Mage::registry('current_order_sf');
41
- $quoteSf = Mage::registry('current_quote_sf');
42
- $shippingPrice = $orderSf['TotalShipping'];
43
- if (!Mage::helper('tax')->shippingPriceIncludesTax() && Mage::helper('tax')->getShippingTaxClass(null)) {
44
- $percent = null;
45
- $pseudoProduct = new Varien_Object();
46
- $pseudoProduct->setTaxClassId(Mage::helper('tax')->getShippingTaxClass(null));
47
-
48
- $taxClassId = $pseudoProduct->getTaxClassId();
49
- if (is_null($percent)) {
50
- if ($taxClassId) {
51
- $request = Mage::getSingleton('tax/calculation')->getRateRequest($quoteSf->getShippingAddress(), $quoteSf->getBillingAddress(), null, null);
52
- $request->setProductClassId($taxClassId);
53
- $request->setCustomerClassId($quoteSf->getCustomerTaxClassId());
54
- $percent = Mage::getSingleton('tax/calculation')->getRate($request);
55
-
56
- if ($percent !== false || !is_null($percent)) {
57
-
58
- $shippingPrice = $shippingPrice - ($shippingPrice / (100 + $percent) * $percent);
59
- }
60
- }
61
- }
62
-
63
- //Mage::log("including tax = ".$includingTax." shipping price = ".$shippingPrice,null,'test_shipping_price.log');
64
- }
65
- $method->setPrice($shippingPrice);
66
- $method->setCost($shippingPrice);
67
-
68
- $result->append($method);
69
-
70
-
71
- return $result;
72
- }
73
-
74
- /**
75
- * Processing additional validation to check is carrier applicable.
76
- *
77
- * @param Mage_Shipping_Model_Rate_Request $request
78
- * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
79
- */
80
- public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
81
- {
82
- //if(Mage::getVersion() == '1.4.1.0')
83
- return $this->isActive();
84
-
85
- //return parent::proccessAdditionalValidation($request);
86
- }
87
-
88
- public function getSession()
89
- {
90
- return Mage::getSingleton('checkout/session');
91
- }
92
-
93
- public function isActive()
94
- {
95
- if(Mage::registry('is_shoppingfeed_import')/*$this->getSession()->getIsShoppingFlux()*/)
96
- return true;
97
-
98
- return false;
99
- }
100
-
101
- public function getAllowedMethods()
102
- {
103
- return array('shoppingflux'=>$this->getConfigData('name'));
104
- }
105
-
106
- }
1
+ <?php
2
+
3
+ /**
4
+ * ShoppingFLux shipping model
5
+ *
6
+ * @category ShoppingFlux
7
+ * @package Profileolabs_Shoppingflux
8
+ * @author kassim belghait
9
+ */
10
+ class Profileolabs_Shoppingflux_Model_Manageorders_Shipping_Carrier_Shoppingflux
11
+ extends Mage_Shipping_Model_Carrier_Abstract
12
+ implements Mage_Shipping_Model_Carrier_Interface
13
+ {
14
+
15
+ protected $_code = 'shoppingflux';
16
+ protected $_isFixed = true;
17
+
18
+ /**
19
+ * FreeShipping Rates Collector
20
+ *
21
+ * @param Mage_Shipping_Model_Rate_Request $request
22
+ * @return Mage_Shipping_Model_Rate_Result
23
+ */
24
+ public function collectRates(Mage_Shipping_Model_Rate_Request $request)
25
+ {
26
+ if (!$this->isActive()) {
27
+ return false;
28
+ }
29
+
30
+ $result = Mage::getModel('shipping/rate_result');
31
+
32
+ $method = Mage::getModel('shipping/rate_result_method');
33
+
34
+ $method->setCarrier('shoppingflux');
35
+ $method->setCarrierTitle($this->getConfigData('title'));
36
+
37
+ $method->setMethod('shoppingflux');
38
+ $method->setMethodTitle($this->getConfigData('name'));
39
+
40
+ $orderSf = Mage::registry('current_order_sf');
41
+ $quoteSf = Mage::registry('current_quote_sf');
42
+ $shippingPrice = $orderSf['TotalShipping'];
43
+ if (!Mage::helper('tax')->shippingPriceIncludesTax() && Mage::helper('tax')->getShippingTaxClass(null)) {
44
+ $percent = null;
45
+ $pseudoProduct = new Varien_Object();
46
+ $pseudoProduct->setTaxClassId(Mage::helper('tax')->getShippingTaxClass(null));
47
+
48
+ $taxClassId = $pseudoProduct->getTaxClassId();
49
+ if (is_null($percent)) {
50
+ if ($taxClassId) {
51
+ $request = Mage::getSingleton('tax/calculation')->getRateRequest($quoteSf->getShippingAddress(), $quoteSf->getBillingAddress(), null, null);
52
+ $request->setProductClassId($taxClassId);
53
+ $request->setCustomerClassId($quoteSf->getCustomerTaxClassId());
54
+ $percent = Mage::getSingleton('tax/calculation')->getRate($request);
55
+
56
+ if ($percent !== false || !is_null($percent)) {
57
+
58
+ $shippingPrice = $shippingPrice - ($shippingPrice / (100 + $percent) * $percent);
59
+ }
60
+ }
61
+ }
62
+
63
+ //Mage::log("including tax = ".$includingTax." shipping price = ".$shippingPrice,null,'test_shipping_price.log');
64
+ }
65
+ $method->setPrice($shippingPrice);
66
+ $method->setCost($shippingPrice);
67
+
68
+ $result->append($method);
69
+
70
+
71
+ return $result;
72
+ }
73
+
74
+ /**
75
+ * Processing additional validation to check is carrier applicable.
76
+ *
77
+ * @param Mage_Shipping_Model_Rate_Request $request
78
+ * @return Mage_Shipping_Model_Carrier_Abstract|Mage_Shipping_Model_Rate_Result_Error|boolean
79
+ */
80
+ public function proccessAdditionalValidation(Mage_Shipping_Model_Rate_Request $request)
81
+ {
82
+ //if(Mage::getVersion() == '1.4.1.0')
83
+ return $this->isActive();
84
+
85
+ //return parent::proccessAdditionalValidation($request);
86
+ }
87
+
88
+ public function getSession()
89
+ {
90
+ return Mage::getSingleton('checkout/session');
91
+ }
92
+
93
+ public function isActive()
94
+ {
95
+ if(Mage::registry('is_shoppingfeed_import')/*$this->getSession()->getIsShoppingFlux()*/)
96
+ return true;
97
+
98
+ return false;
99
+ }
100
+
101
+ public function getAllowedMethods()
102
+ {
103
+ return array('shoppingflux'=>$this->getConfigData('name'));
104
+ }
105
+
106
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Shipping/Method.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_Shoppingflux
5
- * @author Vincent Enjalbert @ Web-cooking.net
6
- */
7
- class Profileolabs_Shoppingflux_Model_Manageorders_Shipping_Method extends Mage_Core_Model_Abstract
8
- {
9
- protected function _construct()
10
- {
11
- $this->_init('profileolabs_shoppingflux/manageorders_shipping_method');
12
- }
13
-
14
-
15
-
16
- public function getFullShippingMethodCodeFor($marketplace, $shippingMethod) {
17
- $code = $marketplace . '_' . $shippingMethod;
18
- $code = strtolower($code);
19
- $code = preg_replace('%\s+%i', '_', $code);
20
- return $code;
21
- }
22
-
23
- public function getFullShippingMethodCode() {
24
- return $this->getFullShippingMethodCodeFor($this->getMarketplace(), $this->getShippingMethod());
25
- }
26
-
27
- public function loadByMethod($marketplace, $shippingMethod) {
28
- $collection = $this->getCollection();
29
- $collection->addFieldToFilter('marketplace', $marketplace);
30
- $collection->addFieldToFilter('shipping_method', $shippingMethod);
31
- if($collection->count() <= 0) {
32
- $this->setId(null);
33
- $this->setMarketplace($marketplace);
34
- $this->setShippingMethod($shippingMethod);
35
- return $this;
36
- }
37
- return $collection->getFirstItem();
38
- }
39
-
40
- public function saveShippingMethod($marketplace, $shippingMethod) {
41
- $model = $this->loadByMethod($marketplace, $shippingMethod);
42
- $model->setLastSeenAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
43
- $model->save();
44
- }
45
-
46
  }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_Shoppingflux
5
+ * @author Vincent Enjalbert @ Web-cooking.net
6
+ */
7
+ class Profileolabs_Shoppingflux_Model_Manageorders_Shipping_Method extends Mage_Core_Model_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('profileolabs_shoppingflux/manageorders_shipping_method');
12
+ }
13
+
14
+
15
+
16
+ public function getFullShippingMethodCodeFor($marketplace, $shippingMethod) {
17
+ $code = $marketplace . '_' . $shippingMethod;
18
+ $code = strtolower($code);
19
+ $code = preg_replace('%\s+%i', '_', $code);
20
+ return $code;
21
+ }
22
+
23
+ public function getFullShippingMethodCode() {
24
+ return $this->getFullShippingMethodCodeFor($this->getMarketplace(), $this->getShippingMethod());
25
+ }
26
+
27
+ public function loadByMethod($marketplace, $shippingMethod) {
28
+ $collection = $this->getCollection();
29
+ $collection->addFieldToFilter('marketplace', $marketplace);
30
+ $collection->addFieldToFilter('shipping_method', $shippingMethod);
31
+ if($collection->count() <= 0) {
32
+ $this->setId(null);
33
+ $this->setMarketplace($marketplace);
34
+ $this->setShippingMethod($shippingMethod);
35
+ return $this;
36
+ }
37
+ return $collection->getFirstItem();
38
+ }
39
+
40
+ public function saveShippingMethod($marketplace, $shippingMethod) {
41
+ $model = $this->loadByMethod($marketplace, $shippingMethod);
42
+ $model->setLastSeenAt(date('Y-m-d H:i:s', Mage::getModel('core/date')->timestamp(time())));
43
+ $model->save();
44
+ }
45
+
46
  }
app/code/community/Profileolabs/Shoppingflux/Model/Manageorders/Source/Attributes.php CHANGED
@@ -1,59 +1,59 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait - Vincent Enjalbert
8
- */
9
- class Profileolabs_Shoppingflux_Model_Manageorders_Source_Attributes {
10
-
11
- protected $_exceptions = array(
12
- 'website_id',
13
- 'store_id',
14
- 'created_in',
15
- 'prefix',
16
- 'suffix',
17
- 'firstname',
18
- 'middlename',
19
- 'lastname',
20
- 'email',
21
- 'group_id',
22
- 'dob',
23
- 'password_hash',
24
- 'default_shipping',
25
- 'default_billing',
26
- 'taxvat',
27
- 'confirmation',
28
- 'created_at',
29
- 'gender',
30
- 'rp_token',
31
- 'rp_token_created_at',
32
- 'disable_auto_group_change',
33
- 'from_shoppingflux',
34
- );
35
- protected $_attributes = null;
36
-
37
- public function toOptionArray() {
38
- if (is_null($this->_attributes)) {
39
- $this->_attributes = array();
40
-
41
- $model = Mage::getResourceModel('customer/customer');
42
- $typeId = $model->getTypeId();
43
-
44
- $attributesCollection = Mage::getResourceModel('eav/entity_attribute_collection')
45
- ->setEntityTypeFilter($typeId)
46
- ->load();
47
- $this->_attributes = array();
48
- $this->_attributes[] = array('value' => '', 'label' => '');
49
- foreach ($attributesCollection as $attribute) {
50
- $code = $attribute->getAttributeCode();
51
- if (!in_array($code, $this->_exceptions)) {
52
- $this->_attributes[] = array('value' => $code, 'label' => $code);
53
- }
54
- }
55
- }
56
- return $this->_attributes;
57
- }
58
-
59
- }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait - Vincent Enjalbert
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Manageorders_Source_Attributes {
10
+
11
+ protected $_exceptions = array(
12
+ 'website_id',
13
+ 'store_id',
14
+ 'created_in',
15
+ 'prefix',
16
+ 'suffix',
17
+ 'firstname',
18
+ 'middlename',
19
+ 'lastname',
20
+ 'email',
21
+ 'group_id',
22
+ 'dob',
23
+ 'password_hash',
24
+ 'default_shipping',
25
+ 'default_billing',
26
+ 'taxvat',
27
+ 'confirmation',
28
+ 'created_at',
29
+ 'gender',
30
+ 'rp_token',
31
+ 'rp_token_created_at',
32
+ 'disable_auto_group_change',
33
+ 'from_shoppingflux',
34
+ );
35
+ protected $_attributes = null;
36
+
37
+ public function toOptionArray() {
38
+ if (is_null($this->_attributes)) {
39
+ $this->_attributes = array();
40
+
41
+ $model = Mage::getResourceModel('customer/customer');
42
+ $typeId = $model->getTypeId();
43
+
44
+ $attributesCollection = Mage::getResourceModel('eav/entity_attribute_collection')
45
+ ->setEntityTypeFilter($typeId)
46
+ ->load();
47
+ $this->_attributes = array();
48
+ $this->_attributes[] = array('value' => '', 'label' => '');
49
+ foreach ($attributesCollection as $attribute) {
50
+ $code = $attribute->getAttributeCode();
51
+ if (!in_array($code, $this->_exceptions)) {
52
+ $this->_attributes[] = array('value' => $code, 'label' => $code);
53
+ }
54
+ }
55
+ }
56
+ return $this->_attributes;
57
+ }
58
+
59
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Flux.php CHANGED
@@ -1,17 +1,17 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Export_Flux extends Mage_Core_Model_Mysql4_Abstract {
10
-
11
- protected function _construct() {
12
- $this->_init('profileolabs_shoppingflux/export_flux', 'id');
13
- }
14
-
15
-
16
-
17
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Export_Flux extends Mage_Core_Model_Mysql4_Abstract {
10
+
11
+ protected function _construct() {
12
+ $this->_init('profileolabs_shoppingflux/export_flux', 'id');
13
+ }
14
+
15
+
16
+
17
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Flux/Collection.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Export_Flux_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/export_flux');
14
- }
15
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Export_Flux_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/export_flux');
14
+ }
15
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Updates.php CHANGED
@@ -1,17 +1,17 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Export_Updates extends Mage_Core_Model_Mysql4_Abstract {
10
-
11
- protected function _construct() {
12
- $this->_init('profileolabs_shoppingflux/export_updates', 'update_id');
13
- }
14
-
15
-
16
-
17
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Export_Updates extends Mage_Core_Model_Mysql4_Abstract {
10
+
11
+ protected function _construct() {
12
+ $this->_init('profileolabs_shoppingflux/export_updates', 'update_id');
13
+ }
14
+
15
+
16
+
17
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Export/Updates/Collection.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Export_Updates_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/export_updates');
14
- }
15
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Export_Updates_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/export_updates');
14
+ }
15
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Export/Shipments.php CHANGED
@@ -1,13 +1,13 @@
1
- <?php
2
- /**
3
- * @category ShoppingFlux
4
- * @package Profileolabs_Shoppingflux
5
- * @author Vincent Enjalbert @ Web-cooking.net
6
- */
7
- class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Export_Shipments extends Mage_Core_Model_Mysql4_Abstract
8
- {
9
- protected function _construct()
10
- {
11
- $this->_init('profileolabs_shoppingflux/manageorders_export_shipments','update_id');
12
- }
13
  }
1
+ <?php
2
+ /**
3
+ * @category ShoppingFlux
4
+ * @package Profileolabs_Shoppingflux
5
+ * @author Vincent Enjalbert @ Web-cooking.net
6
+ */
7
+ class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Export_Shipments extends Mage_Core_Model_Mysql4_Abstract
8
+ {
9
+ protected function _construct()
10
+ {
11
+ $this->_init('profileolabs_shoppingflux/manageorders_export_shipments','update_id');
12
+ }
13
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Export/Shipments/Collection.php CHANGED
@@ -1,14 +1,14 @@
1
- <?php
2
-
3
- /**
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author Vincent Enjalbert @ Web-cooking.net
7
- */
8
- class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Export_Shipments_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
9
-
10
- protected function _construct() {
11
- $this->_init('profileolabs_shoppingflux/manageorders_export_shipments');
12
- }
13
-
14
  }
1
+ <?php
2
+
3
+ /**
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author Vincent Enjalbert @ Web-cooking.net
7
+ */
8
+ class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Export_Shipments_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
9
+
10
+ protected function _construct() {
11
+ $this->_init('profileolabs_shoppingflux/manageorders_export_shipments');
12
+ }
13
+
14
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Log.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * Error Log
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- *
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Log extends Mage_Core_Model_Mysql4_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/manageorders_log','id');
14
- }
15
  }
1
+ <?php
2
+ /**
3
+ * Error Log
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ *
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Log extends Mage_Core_Model_Mysql4_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/manageorders_log','id');
14
+ }
15
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Log/Collection.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * Error Log
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- *
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/manageorders_log');
14
- }
15
  }
1
+ <?php
2
+ /**
3
+ * Error Log
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ *
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Log_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/manageorders_log');
14
+ }
15
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Shipping/Method.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * Error Log
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- *
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Shipping_Method extends Mage_Core_Model_Mysql4_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/manageorders_shipping_method','id');
14
- }
15
  }
1
+ <?php
2
+ /**
3
+ * Error Log
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ *
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Shipping_Method extends Mage_Core_Model_Mysql4_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/manageorders_shipping_method','id');
14
+ }
15
  }
app/code/community/Profileolabs/Shoppingflux/Model/Mysql4/Manageorders/Shipping/Method/Collection.php CHANGED
@@ -1,15 +1,15 @@
1
- <?php
2
- /**
3
- * Error Log
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author kassim belghait
7
- *
8
- */
9
- class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Shipping_Method_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
- {
11
- protected function _construct()
12
- {
13
- $this->_init('profileolabs_shoppingflux/manageorders_shipping_method');
14
- }
15
  }
1
+ <?php
2
+ /**
3
+ * Error Log
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author kassim belghait
7
+ *
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Mysql4_Manageorders_Shipping_Method_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
10
+ {
11
+ protected function _construct()
12
+ {
13
+ $this->_init('profileolabs_shoppingflux/manageorders_shipping_method');
14
+ }
15
  }
app/code/community/Profileolabs/Shoppingflux/Model/Sales/Service/Quote.php CHANGED
@@ -1,35 +1,35 @@
1
- <?php
2
-
3
- /**
4
- This rewrite is necessary for some very old magento versions compatibility. In newer versions, it is useless.
5
- */
6
- class Profileolabs_Shoppingflux_Model_Sales_Service_Quote extends Mage_Sales_Model_Service_Quote {
7
-
8
- protected function _validate()
9
- {
10
- if(!Mage::registry('is_shoppingfeed_import')) {
11
- return parent::_validate();
12
- }
13
- $helper = Mage::helper('sales');
14
- if (!$this->getQuote()->isVirtual()) {
15
- $address = $this->getQuote()->getShippingAddress();
16
- $addressValidation = $address->validate();
17
- if ($addressValidation !== true) {
18
- Mage::throwException(
19
- $helper->__('Please check shipping address information. %s', implode(' ', $addressValidation))
20
- );
21
- }
22
-
23
- }
24
-
25
- $addressValidation = $this->getQuote()->getBillingAddress()->validate();
26
- if ($addressValidation !== true) {
27
- Mage::throwException(
28
- $helper->__('Please check billing address information. %s', implode(' ', $addressValidation))
29
- );
30
- }
31
-
32
- return $this;
33
- }
34
-
35
  }
1
+ <?php
2
+
3
+ /**
4
+ This rewrite is necessary for some very old magento versions compatibility. In newer versions, it is useless.
5
+ */
6
+ class Profileolabs_Shoppingflux_Model_Sales_Service_Quote extends Mage_Sales_Model_Service_Quote {
7
+
8
+ protected function _validate()
9
+ {
10
+ if(!Mage::registry('is_shoppingfeed_import')) {
11
+ return parent::_validate();
12
+ }
13
+ $helper = Mage::helper('sales');
14
+ if (!$this->getQuote()->isVirtual()) {
15
+ $address = $this->getQuote()->getShippingAddress();
16
+ $addressValidation = $address->validate();
17
+ if ($addressValidation !== true) {
18
+ Mage::throwException(
19
+ $helper->__('Please check shipping address information. %s', implode(' ', $addressValidation))
20
+ );
21
+ }
22
+
23
+ }
24
+
25
+ $addressValidation = $this->getQuote()->getBillingAddress()->validate();
26
+ if ($addressValidation !== true) {
27
+ Mage::throwException(
28
+ $helper->__('Please check billing address information. %s', implode(' ', $addressValidation))
29
+ );
30
+ }
31
+
32
+ return $this;
33
+ }
34
+
35
  }
app/code/community/Profileolabs/Shoppingflux/Model/Service.php CHANGED
@@ -1,323 +1,323 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux Service
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait, vincent enjalbert @ web-cooking.net
8
- */
9
- class Profileolabs_Shoppingflux_Model_Service extends Varien_Object {
10
- /**
11
- * Order status
12
- */
13
-
14
- const ORDER_STATUS_SHIPPED = 'Shipped';
15
- const ORDER_STATUS_CANCELED = 'Canceled';
16
-
17
- /**
18
- * Method's names
19
- */
20
- const METHOD_GET_ORDERS = "GetOrders";
21
- const METHOD_VALIDATE_ORDERS = "ValidOrders";
22
- const METHOD_UPDATE_ORDERS = "UpdateOrders";
23
- const METHOD_UPDATE_PRODUCT = "UpdateProduct";
24
- const METHOD_LOGIN = "getLogin";
25
- const METHOD_IS_CLIENT = "IsClient";
26
- const METHOD_GET_MARKETPLACES = 'GetMarketplaces';
27
-
28
- /**
29
- *
30
- * @var Zend_Http_Client
31
- */
32
- protected $_client = null;
33
-
34
- /**
35
- *
36
- * @var SimpleXMLElement
37
- */
38
- protected $_xml = null;
39
- protected $_apiKey = null;
40
- protected $_wsUri = null;
41
-
42
- public function __construct($apiKey, $wsUri) {
43
- $this->_apiKey = $apiKey;
44
- $this->_wsUri = $wsUri;
45
- }
46
-
47
- protected function _getApiKey() {
48
- return $this->_apiKey;
49
- }
50
-
51
- /**
52
- * Get client HTTP
53
- * @return Zend_Http_Client
54
- */
55
- public function getClient() {
56
- if (is_null($this->_client)) {
57
- //adapter options
58
- $config = array('curloptions' => array(/* CURLOPT_FOLLOWLOCATION => true, */
59
- //CURLOPT_POST=>true,
60
- CURLOPT_SSL_VERIFYHOST => 0,
61
- CURLOPT_SSL_VERIFYPEER => 0,
62
- CURLOPT_HEADER => false,
63
- CURLOPT_RETURNTRANSFER => true,
64
- CURLOPT_CONNECTTIMEOUT => 10,
65
- CURLOPT_TIMEOUT => 100),
66
- );
67
- try {
68
-
69
- //innitialize http lcient and adapter curl
70
- //$adapter = new Zend_Http_Client_Adapter_Curl();
71
- $adapter = new Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Curl();
72
- $this->_client = new Zend_Http_Client($this->_wsUri);
73
- $this->_client->setAdapter($adapter);
74
- $adapter->setConfig($config);
75
- } catch (Exception $e) {
76
- Mage::throwException($e);
77
- }
78
- }
79
-
80
- return $this->_client;
81
- }
82
-
83
- /**
84
- * Connect to Shopping Flux and Call method
85
- *
86
- * @param string $apiKey
87
- * @param string $method
88
- */
89
- protected function _connect($apiKey, $method, $request='') {
90
- if (empty($apiKey)) {
91
- Mage::helper('profileolabs_shoppingflux')->generateTokens();
92
- Mage::throwException("API Key (Token) is empty");
93
- }
94
- $mode = Mage::getSingleton('profileolabs_shoppingflux/config')->isSandbox() ? 'Sandbox' : 'Production';
95
- $data = array("CALL" => $method, "TOKEN" => $apiKey, "MODE" => $mode, "REQUEST" => $request);
96
- /* @var $response Zend_Http_Response */
97
- //set Post Params
98
- foreach ($data as $key => $val)
99
- $this->getClient()->setParameterPost($key, $val);
100
- //send the request
101
- $response = $this->getClient()->request(Zend_Http_Client::POST);
102
- //die($response->getBody());
103
- //load response at xml (SimpleXMLElement)
104
-
105
-
106
- $responseText = $response->getBody();
107
-
108
- /* $responseText = '<?xml version="1.0" encoding="utf-8"?>
109
- <Result>
110
- <Request>
111
- <Date>2015-06-02T11:08:42+01:00</Date><Call>GetOrders</Call><Token>bezeezra17ee07d2a87e444827c18a77e01d</Token><Mode>Sandbox</Mode><Version>2</Version>
112
- </Request>
113
- <Response>
114
- <Orders>
115
- <Order>
116
- <IdOrder>402-81an7840e085-1568300</IdOrder>
117
- <Marketplace>Amazon</Marketplace>
118
- <Currency>EUR</Currency>
119
- <TotalAmount>299.00</TotalAmount>
120
- <TotalProducts>299</TotalProducts>
121
- <TotalShipping>0.00</TotalShipping>
122
- <TotalFees>0.49</TotalFees>
123
- <NumberOfProducts>1</NumberOfProducts>
124
- <OrderDate>2015-11-05T13:09:41+01:00</OrderDate>
125
- <Other></Other>
126
- <ShippingMethod>Nouvelle Shipping method</ShippingMethod>
127
- <BillingAddress><LastName>moon chan kim</LastName><FirstName></FirstName><Phone>0698750828</Phone><PhoneMobile></PhoneMobile><Street><![CDATA[121 rue du faubourg du temple etg 2, porte droit]]></Street><Street1><![CDATA[121 rue du faubourg du temple]]></Street1><Street2><![CDATA[etg 2, porte droit]]></Street2><Company><![CDATA[]]></Company><PostalCode>75010</PostalCode><Town><![CDATA[paris]]></Town><Country>FR</Country><Email>vbdels5s4sfpc98p7@marketplace.amazon.fr</Email></BillingAddress>
128
- <ShippingAddress><RelayID>1234</RelayID><LastName>moon chan kim</LastName><FirstName></FirstName><Phone>0698750828</Phone><PhoneMobile></PhoneMobile><Street><![CDATA[121 rue du faubourg du temple etg 2, porte droit]]></Street><Street1><![CDATA[121 rue du faubourg du temple]]></Street1><Street2><![CDATA[etg 2, porte droit]]></Street2><Company><![CDATA[]]></Company><PostalCode>75010</PostalCode><Town><![CDATA[paris]]></Town><Country>FR</Country><Email>vbldes5s4sfpc98p7@marketplace.amazon.fr</Email></ShippingAddress>
129
- <Products>
130
- <Product>
131
- <SKU>CLAVIER</SKU>
132
- <Quantity>1</Quantity>
133
- <Price>8.000000</Price>
134
- <Ecotax>0</Ecotax>
135
- </Product>
136
- </Products>
137
- </Order>
138
- </Orders>
139
- </Response>
140
- </Result>';
141
- */
142
-
143
-
144
- $this->_xml = simplexml_load_string($responseText, 'Varien_Simplexml_Element', LIBXML_NOCDATA);
145
-
146
-
147
-
148
- //Mage::log($this->_xml,null,"flux_order.log");
149
- //Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__('TEST KASSIM'));
150
-
151
-
152
- if (!($this->_xml instanceof Varien_Simplexml_Element)) {
153
- Mage::log($responseText, null, 'shoppingflux.log');
154
- Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__("Result is not Varien_Simplexml_Element"));
155
- } elseif ($this->_xml->error) {
156
- Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux API key (Token) is not valid'));
157
- }
158
-
159
- /* } catch (Exception $e) {
160
- Mage::throwException($e);
161
- } */
162
-
163
- return $this->_xml;
164
- }
165
-
166
-
167
- public function getMarketplaces() {
168
- $data = $this->_connect($this->_getApiKey(), self::METHOD_GET_MARKETPLACES);
169
- return $data->Response->Marketplaces->Marketplace;
170
- }
171
-
172
- /**
173
- * Retrieve orders
174
- *
175
- */
176
- public function getOrders() {
177
- $data = $this->_connect($this->_getApiKey(), self::METHOD_GET_ORDERS);
178
- return $data->Response->Orders;
179
- }
180
-
181
- /**
182
- * Send orders ids imported
183
- * @param array $orderIds
184
- */
185
- public function sendValidOrders(array $orderIds) {
186
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
187
- $xml .= '<ValidOrders>';
188
- foreach($orderIds as $orderId => $orderInfo) {
189
- if(isset($orderInfo['ErrorOrder']) && $orderInfo['ErrorOrder'] !== false && !$orderInfo['ErrorOrder']) {
190
- $orderInfo['ErrorOrder'] = 'Une erreur s\'est produite';
191
- }
192
- $xml .= '<Order>';
193
- $xml .= '<IdOrder>' . $orderId . '</IdOrder>';
194
- $xml .= '<Marketplace>' . $orderInfo['Marketplace'] . '</Marketplace>';
195
- $xml .= '<MerchantIdOrder>' . $orderInfo['MageOrderId'] . '</MerchantIdOrder>';
196
- if(isset($orderInfo['ErrorOrder']) && $orderInfo['ErrorOrder']) {
197
- $xml .= '<ErrorOrder>' . $orderInfo['ErrorOrder'] . '</ErrorOrder>';
198
- }
199
- $xml .= '</Order>';
200
- }
201
- $xml .= '</ValidOrders>';
202
-
203
-
204
- $dataObj = new Varien_Object(array('xml' => $xml));
205
- Mage::dispatchEvent('shoppingflux_send_valid_orders', array('data_obj' => $dataObj));
206
- $xml = $dataObj->getXml();
207
- return $this->_connect($this->_getApiKey(), self::METHOD_VALIDATE_ORDERS, $xml);
208
- }
209
-
210
- /**
211
- * Update orders id shipped
212
- * @param string $orderId
213
- */
214
- public function updateShippedOrder($orderId, $marketplace, $status, $trackNum = '', $trackCarrier = '', $trackUrl = '') {
215
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
216
- $xml .= '<UpdateOrders>';
217
- $xml .= '<Order>';
218
- $xml .= '<IdOrder>' . $orderId . '</IdOrder>';
219
- $xml .= '<Marketplace>' . $marketplace . '</Marketplace>';
220
- $xml .= '<Status>' . $status . '</Status>';
221
- if ($trackNum && !preg_match('%^http%i', $trackNum)) {
222
- $xml .= '<TrackingNumber><![CDATA[' . $trackNum . ']]></TrackingNumber>';
223
- }
224
- if ($trackUrl) {
225
- $xml .= '<TrackingUrl><![CDATA[' . $trackUrl . ']]></TrackingUrl>';
226
- } else if ($trackNum && preg_match('%^http%i', $trackNum)) {
227
- $xml .= '<TrackingUrl><![CDATA[' . $trackNum . ']]></TrackingUrl>';
228
- }
229
- if ($trackCarrier) {
230
- $xml .= '<CarrierName><![CDATA[' . $trackCarrier . ']]></CarrierName>';
231
- }
232
- $xml .= '</Order>';
233
- $xml .= '</UpdateOrders>';
234
- $dataObj = new Varien_Object(array('xml' => $xml));
235
- Mage::dispatchEvent('shoppingflux_update_shipped_orders', array('data_obj' => $dataObj));
236
- $xml = $dataObj->getXml();
237
- return $this->_connect(
238
- $this->_getApiKey(), self::METHOD_UPDATE_ORDERS, $xml
239
- );
240
- }
241
-
242
- public function updateCanceledOrder($orderId, $marketplace, $status) {
243
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
244
- $xml .= '<UpdateOrders>';
245
- $xml .= '<Order>';
246
- $xml .= '<IdOrder>' . $orderId . '</IdOrder>';
247
- $xml .= '<Marketplace>' . $marketplace . '</Marketplace>';
248
- $xml .= '<Status>' . $status . '</Status>';
249
- $xml .= '</Order>';
250
- $xml .= '</UpdateOrders>';
251
- $dataObj = new Varien_Object(array('xml' => $xml));
252
- Mage::dispatchEvent('shoppingflux_update_canceled_orders', array('data_obj' => $dataObj));
253
- $xml = $dataObj->getXml();
254
- return $this->_connect(
255
- $this->_getApiKey(), self::METHOD_UPDATE_ORDERS, $xml
256
- );
257
- }
258
-
259
-
260
- public function updateProducts($updates) {
261
- if($updates->getSize() <=0) return;
262
- $xml = '<?xml version="1.0" encoding="UTF-8"?>';
263
- $xml .= '<UpdateProduct>';
264
- foreach($updates as $update) {
265
- $xml .= '<Product>';
266
- $xml .= '<SKU>' . $update->getProductSku() . '</SKU>';
267
- $xml .= '<Quantity>' . $update->getStockValue() . '</Quantity>';
268
- $xml .= '<Price>' . $update->getPriceValue() . '</Price>';
269
- $xml .= '<OldPrice>' . $update->getOldPriceValue() . '</OldPrice>';
270
- $xml .= '</Product>';
271
- }
272
- $xml .= '</UpdateProduct>';
273
- $this->_connect(
274
- $this->_getApiKey(), self::METHOD_UPDATE_PRODUCT, $xml
275
- );
276
- }
277
-
278
- /**
279
- * Retrieve login
280
- * @param string|null $apiKey
281
- */
282
- public function getLogin($apiKey = null) {
283
- if (is_null($apiKey))
284
- $apiKey = $this->_getApiKey();
285
-
286
- return $this->_connect($apiKey, self::METHOD_LOGIN);
287
- }
288
-
289
- /**
290
- * Check if ApiKey is valid
291
- * @param string $apiKey
292
- */
293
- public function checkApiKey($apiKey) {
294
- if ($this->getLogin($apiKey)->error)
295
- return false;
296
-
297
- return true;
298
- }
299
-
300
-
301
- public function isClient() {
302
- try {
303
- $res = $this->_connect(
304
- $this->_getApiKey(), self::METHOD_IS_CLIENT
305
- );
306
- $status = (string) $res->Response->Status;
307
- if($status == 'Client') {
308
- if(!Mage::getStoreConfigFlag('shoppingflux/configuration/has_registered')) {
309
- $config = new Mage_Core_Model_Config();
310
- $config->saveConfig('shoppingflux/configuration/has_registered', 1);
311
- }
312
- return true;
313
- }
314
- }catch(Exception $e) {
315
- if($e->getMessage() == 'API Key (Token) is empty') {
316
- return false;
317
- }
318
- return true;
319
- }
320
- return false;
321
- }
322
-
323
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux Service
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait, vincent enjalbert @ web-cooking.net
8
+ */
9
+ class Profileolabs_Shoppingflux_Model_Service extends Varien_Object {
10
+ /**
11
+ * Order status
12
+ */
13
+
14
+ const ORDER_STATUS_SHIPPED = 'Shipped';
15
+ const ORDER_STATUS_CANCELED = 'Canceled';
16
+
17
+ /**
18
+ * Method's names
19
+ */
20
+ const METHOD_GET_ORDERS = "GetOrders";
21
+ const METHOD_VALIDATE_ORDERS = "ValidOrders";
22
+ const METHOD_UPDATE_ORDERS = "UpdateOrders";
23
+ const METHOD_UPDATE_PRODUCT = "UpdateProduct";
24
+ const METHOD_LOGIN = "getLogin";
25
+ const METHOD_IS_CLIENT = "IsClient";
26
+ const METHOD_GET_MARKETPLACES = 'GetMarketplaces';
27
+
28
+ /**
29
+ *
30
+ * @var Zend_Http_Client
31
+ */
32
+ protected $_client = null;
33
+
34
+ /**
35
+ *
36
+ * @var SimpleXMLElement
37
+ */
38
+ protected $_xml = null;
39
+ protected $_apiKey = null;
40
+ protected $_wsUri = null;
41
+
42
+ public function __construct($apiKey, $wsUri) {
43
+ $this->_apiKey = $apiKey;
44
+ $this->_wsUri = $wsUri;
45
+ }
46
+
47
+ protected function _getApiKey() {
48
+ return $this->_apiKey;
49
+ }
50
+
51
+ /**
52
+ * Get client HTTP
53
+ * @return Zend_Http_Client
54
+ */
55
+ public function getClient() {
56
+ if (is_null($this->_client)) {
57
+ //adapter options
58
+ $config = array('curloptions' => array(/* CURLOPT_FOLLOWLOCATION => true, */
59
+ //CURLOPT_POST=>true,
60
+ CURLOPT_SSL_VERIFYHOST => 0,
61
+ CURLOPT_SSL_VERIFYPEER => 0,
62
+ CURLOPT_HEADER => false,
63
+ CURLOPT_RETURNTRANSFER => true,
64
+ CURLOPT_CONNECTTIMEOUT => 10,
65
+ CURLOPT_TIMEOUT => 100),
66
+ );
67
+ try {
68
+
69
+ //innitialize http lcient and adapter curl
70
+ //$adapter = new Zend_Http_Client_Adapter_Curl();
71
+ $adapter = new Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Curl();
72
+ $this->_client = new Zend_Http_Client($this->_wsUri);
73
+ $this->_client->setAdapter($adapter);
74
+ $adapter->setConfig($config);
75
+ } catch (Exception $e) {
76
+ Mage::throwException($e);
77
+ }
78
+ }
79
+
80
+ return $this->_client;
81
+ }
82
+
83
+ /**
84
+ * Connect to Shopping Flux and Call method
85
+ *
86
+ * @param string $apiKey
87
+ * @param string $method
88
+ */
89
+ protected function _connect($apiKey, $method, $request='') {
90
+ if (empty($apiKey)) {
91
+ Mage::helper('profileolabs_shoppingflux')->generateTokens();
92
+ Mage::throwException("API Key (Token) is empty");
93
+ }
94
+ $mode = Mage::getSingleton('profileolabs_shoppingflux/config')->isSandbox() ? 'Sandbox' : 'Production';
95
+ $data = array("CALL" => $method, "TOKEN" => $apiKey, "MODE" => $mode, "REQUEST" => $request);
96
+ /* @var $response Zend_Http_Response */
97
+ //set Post Params
98
+ foreach ($data as $key => $val)
99
+ $this->getClient()->setParameterPost($key, $val);
100
+ //send the request
101
+ $response = $this->getClient()->request(Zend_Http_Client::POST);
102
+ //die($response->getBody());
103
+ //load response at xml (SimpleXMLElement)
104
+
105
+
106
+ $responseText = $response->getBody();
107
+
108
+ /* $responseText = '<?xml version="1.0" encoding="utf-8"?>
109
+ <Result>
110
+ <Request>
111
+ <Date>2015-06-02T11:08:42+01:00</Date><Call>GetOrders</Call><Token>bezeezra17ee07d2a87e444827c18a77e01d</Token><Mode>Sandbox</Mode><Version>2</Version>
112
+ </Request>
113
+ <Response>
114
+ <Orders>
115
+ <Order>
116
+ <IdOrder>402-81an7840e085-1568300</IdOrder>
117
+ <Marketplace>Amazon</Marketplace>
118
+ <Currency>EUR</Currency>
119
+ <TotalAmount>299.00</TotalAmount>
120
+ <TotalProducts>299</TotalProducts>
121
+ <TotalShipping>0.00</TotalShipping>
122
+ <TotalFees>0.49</TotalFees>
123
+ <NumberOfProducts>1</NumberOfProducts>
124
+ <OrderDate>2015-11-05T13:09:41+01:00</OrderDate>
125
+ <Other></Other>
126
+ <ShippingMethod>Nouvelle Shipping method</ShippingMethod>
127
+ <BillingAddress><LastName>moon chan kim</LastName><FirstName></FirstName><Phone>0698750828</Phone><PhoneMobile></PhoneMobile><Street><![CDATA[121 rue du faubourg du temple etg 2, porte droit]]></Street><Street1><![CDATA[121 rue du faubourg du temple]]></Street1><Street2><![CDATA[etg 2, porte droit]]></Street2><Company><![CDATA[]]></Company><PostalCode>75010</PostalCode><Town><![CDATA[paris]]></Town><Country>FR</Country><Email>vbdels5s4sfpc98p7@marketplace.amazon.fr</Email></BillingAddress>
128
+ <ShippingAddress><RelayID>1234</RelayID><LastName>moon chan kim</LastName><FirstName></FirstName><Phone>0698750828</Phone><PhoneMobile></PhoneMobile><Street><![CDATA[121 rue du faubourg du temple etg 2, porte droit]]></Street><Street1><![CDATA[121 rue du faubourg du temple]]></Street1><Street2><![CDATA[etg 2, porte droit]]></Street2><Company><![CDATA[]]></Company><PostalCode>75010</PostalCode><Town><![CDATA[paris]]></Town><Country>FR</Country><Email>vbldes5s4sfpc98p7@marketplace.amazon.fr</Email></ShippingAddress>
129
+ <Products>
130
+ <Product>
131
+ <SKU>CLAVIER</SKU>
132
+ <Quantity>1</Quantity>
133
+ <Price>8.000000</Price>
134
+ <Ecotax>0</Ecotax>
135
+ </Product>
136
+ </Products>
137
+ </Order>
138
+ </Orders>
139
+ </Response>
140
+ </Result>';
141
+ */
142
+
143
+
144
+ $this->_xml = simplexml_load_string($responseText, 'Varien_Simplexml_Element', LIBXML_NOCDATA);
145
+
146
+
147
+
148
+ //Mage::log($this->_xml,null,"flux_order.log");
149
+ //Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__('TEST KASSIM'));
150
+
151
+
152
+ if (!($this->_xml instanceof Varien_Simplexml_Element)) {
153
+ Mage::log($responseText, null, 'shoppingflux.log');
154
+ Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__("Result is not Varien_Simplexml_Element"));
155
+ } elseif ($this->_xml->error) {
156
+ Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux API key (Token) is not valid'));
157
+ }
158
+
159
+ /* } catch (Exception $e) {
160
+ Mage::throwException($e);
161
+ } */
162
+
163
+ return $this->_xml;
164
+ }
165
+
166
+
167
+ public function getMarketplaces() {
168
+ $data = $this->_connect($this->_getApiKey(), self::METHOD_GET_MARKETPLACES);
169
+ return $data->Response->Marketplaces->Marketplace;
170
+ }
171
+
172
+ /**
173
+ * Retrieve orders
174
+ *
175
+ */
176
+ public function getOrders() {
177
+ $data = $this->_connect($this->_getApiKey(), self::METHOD_GET_ORDERS);
178
+ return $data->Response->Orders;
179
+ }
180
+
181
+ /**
182
+ * Send orders ids imported
183
+ * @param array $orderIds
184
+ */
185
+ public function sendValidOrders(array $orderIds) {
186
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>';
187
+ $xml .= '<ValidOrders>';
188
+ foreach($orderIds as $orderId => $orderInfo) {
189
+ if(isset($orderInfo['ErrorOrder']) && $orderInfo['ErrorOrder'] !== false && !$orderInfo['ErrorOrder']) {
190
+ $orderInfo['ErrorOrder'] = 'Une erreur s\'est produite';
191
+ }
192
+ $xml .= '<Order>';
193
+ $xml .= '<IdOrder>' . $orderId . '</IdOrder>';
194
+ $xml .= '<Marketplace>' . $orderInfo['Marketplace'] . '</Marketplace>';
195
+ $xml .= '<MerchantIdOrder>' . $orderInfo['MageOrderId'] . '</MerchantIdOrder>';
196
+ if(isset($orderInfo['ErrorOrder']) && $orderInfo['ErrorOrder']) {
197
+ $xml .= '<ErrorOrder>' . $orderInfo['ErrorOrder'] . '</ErrorOrder>';
198
+ }
199
+ $xml .= '</Order>';
200
+ }
201
+ $xml .= '</ValidOrders>';
202
+
203
+
204
+ $dataObj = new Varien_Object(array('xml' => $xml));
205
+ Mage::dispatchEvent('shoppingflux_send_valid_orders', array('data_obj' => $dataObj));
206
+ $xml = $dataObj->getXml();
207
+ return $this->_connect($this->_getApiKey(), self::METHOD_VALIDATE_ORDERS, $xml);
208
+ }
209
+
210
+ /**
211
+ * Update orders id shipped
212
+ * @param string $orderId
213
+ */
214
+ public function updateShippedOrder($orderId, $marketplace, $status, $trackNum = '', $trackCarrier = '', $trackUrl = '') {
215
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>';
216
+ $xml .= '<UpdateOrders>';
217
+ $xml .= '<Order>';
218
+ $xml .= '<IdOrder>' . $orderId . '</IdOrder>';
219
+ $xml .= '<Marketplace>' . $marketplace . '</Marketplace>';
220
+ $xml .= '<Status>' . $status . '</Status>';
221
+ if ($trackNum && !preg_match('%^http%i', $trackNum)) {
222
+ $xml .= '<TrackingNumber><![CDATA[' . $trackNum . ']]></TrackingNumber>';
223
+ }
224
+ if ($trackUrl) {
225
+ $xml .= '<TrackingUrl><![CDATA[' . $trackUrl . ']]></TrackingUrl>';
226
+ } else if ($trackNum && preg_match('%^http%i', $trackNum)) {
227
+ $xml .= '<TrackingUrl><![CDATA[' . $trackNum . ']]></TrackingUrl>';
228
+ }
229
+ if ($trackCarrier) {
230
+ $xml .= '<CarrierName><![CDATA[' . $trackCarrier . ']]></CarrierName>';
231
+ }
232
+ $xml .= '</Order>';
233
+ $xml .= '</UpdateOrders>';
234
+ $dataObj = new Varien_Object(array('xml' => $xml));
235
+ Mage::dispatchEvent('shoppingflux_update_shipped_orders', array('data_obj' => $dataObj));
236
+ $xml = $dataObj->getXml();
237
+ return $this->_connect(
238
+ $this->_getApiKey(), self::METHOD_UPDATE_ORDERS, $xml
239
+ );
240
+ }
241
+
242
+ public function updateCanceledOrder($orderId, $marketplace, $status) {
243
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>';
244
+ $xml .= '<UpdateOrders>';
245
+ $xml .= '<Order>';
246
+ $xml .= '<IdOrder>' . $orderId . '</IdOrder>';
247
+ $xml .= '<Marketplace>' . $marketplace . '</Marketplace>';
248
+ $xml .= '<Status>' . $status . '</Status>';
249
+ $xml .= '</Order>';
250
+ $xml .= '</UpdateOrders>';
251
+ $dataObj = new Varien_Object(array('xml' => $xml));
252
+ Mage::dispatchEvent('shoppingflux_update_canceled_orders', array('data_obj' => $dataObj));
253
+ $xml = $dataObj->getXml();
254
+ return $this->_connect(
255
+ $this->_getApiKey(), self::METHOD_UPDATE_ORDERS, $xml
256
+ );
257
+ }
258
+
259
+
260
+ public function updateProducts($updates) {
261
+ if($updates->getSize() <=0) return;
262
+ $xml = '<?xml version="1.0" encoding="UTF-8"?>';
263
+ $xml .= '<UpdateProduct>';
264
+ foreach($updates as $update) {
265
+ $xml .= '<Product>';
266
+ $xml .= '<SKU>' . $update->getProductSku() . '</SKU>';
267
+ $xml .= '<Quantity>' . $update->getStockValue() . '</Quantity>';
268
+ $xml .= '<Price>' . $update->getPriceValue() . '</Price>';
269
+ $xml .= '<OldPrice>' . $update->getOldPriceValue() . '</OldPrice>';
270
+ $xml .= '</Product>';
271
+ }
272
+ $xml .= '</UpdateProduct>';
273
+ $this->_connect(
274
+ $this->_getApiKey(), self::METHOD_UPDATE_PRODUCT, $xml
275
+ );
276
+ }
277
+
278
+ /**
279
+ * Retrieve login
280
+ * @param string|null $apiKey
281
+ */
282
+ public function getLogin($apiKey = null) {
283
+ if (is_null($apiKey))
284
+ $apiKey = $this->_getApiKey();
285
+
286
+ return $this->_connect($apiKey, self::METHOD_LOGIN);
287
+ }
288
+
289
+ /**
290
+ * Check if ApiKey is valid
291
+ * @param string $apiKey
292
+ */
293
+ public function checkApiKey($apiKey) {
294
+ if ($this->getLogin($apiKey)->error)
295
+ return false;
296
+
297
+ return true;
298
+ }
299
+
300
+
301
+ public function isClient() {
302
+ try {
303
+ $res = $this->_connect(
304
+ $this->_getApiKey(), self::METHOD_IS_CLIENT
305
+ );
306
+ $status = (string) $res->Response->Status;
307
+ if($status == 'Client') {
308
+ if(!Mage::getStoreConfigFlag('shoppingflux/configuration/has_registered')) {
309
+ $config = new Mage_Core_Model_Config();
310
+ $config->saveConfig('shoppingflux/configuration/has_registered', 1);
311
+ }
312
+ return true;
313
+ }
314
+ }catch(Exception $e) {
315
+ if($e->getMessage() == 'API Key (Token) is empty') {
316
+ return false;
317
+ }
318
+ return true;
319
+ }
320
+ return false;
321
+ }
322
+
323
  }
app/code/community/Profileolabs/Shoppingflux/Model/Service/Http/Client/Adapter/Curl.php CHANGED
@@ -1,507 +1,507 @@
1
- <?php
2
-
3
- /**
4
- * Zend Framework
5
- *
6
- * LICENSE
7
- *
8
- * This source file is subject to the new BSD license that is bundled
9
- * with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://framework.zend.com/license/new-bsd
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@zend.com so we can send you a copy immediately.
15
- *
16
- * @category Zend
17
- * @package Zend_Http
18
- * @subpackage Client_Adapter
19
- * @version $Id: Curl.php 22216 2010-05-20 21:12:05Z dragonbe $
20
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
- * @license http://framework.zend.com/license/new-bsd New BSD License
22
- */
23
-
24
- /**
25
- * @see Zend_Uri_Http
26
- */
27
- #require_once 'Zend/Uri/Http.php';
28
-
29
- /**
30
- * @see Zend_Http_Client_Adapter_Interface
31
- */
32
- #require_once 'Zend/Http/Client/Adapter/Interface.php';
33
- /**
34
- * @see Zend_Http_Client_Adapter_Stream
35
- */
36
- #require_once 'Zend/Http/Client/Adapter/Stream.php';
37
-
38
- /**
39
- * An adapter class for Zend_Http_Client based on the curl extension.
40
- * Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl
41
- *
42
- * @category Zend
43
- * @package Zend_Http
44
- * @subpackage Client_Adapter
45
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
46
- * @license http://framework.zend.com/license/new-bsd New BSD License
47
- */
48
- class Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interface, Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Stream
49
- {
50
- /**
51
- * Parameters array
52
- *
53
- * @var array
54
- */
55
- protected $_config = array();
56
-
57
- /**
58
- * What host/port are we connected to?
59
- *
60
- * @var array
61
- */
62
- protected $_connected_to = array(null, null);
63
-
64
- /**
65
- * The curl session handle
66
- *
67
- * @var resource|null
68
- */
69
- protected $_curl = null;
70
-
71
- /**
72
- * List of cURL options that should never be overwritten
73
- *
74
- * @var array
75
- */
76
- protected $_invalidOverwritableCurlOptions;
77
-
78
- /**
79
- * Response gotten from server
80
- *
81
- * @var string
82
- */
83
- protected $_response = null;
84
-
85
- /**
86
- * Stream for storing output
87
- *
88
- * @var resource
89
- */
90
- protected $out_stream;
91
-
92
- /**
93
- * Adapter constructor
94
- *
95
- * Config is set using setConfig()
96
- *
97
- * @return void
98
- * @throws Zend_Http_Client_Adapter_Exception
99
- */
100
- public function __construct()
101
- {
102
- if (!extension_loaded('curl')) {
103
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
104
- throw new Zend_Http_Client_Adapter_Exception('cURL extension has to be loaded to use this Zend_Http_Client adapter.');
105
- }
106
- $this->_invalidOverwritableCurlOptions = array(
107
- CURLOPT_HTTPGET,
108
- CURLOPT_POST,
109
- CURLOPT_PUT,
110
- CURLOPT_CUSTOMREQUEST,
111
- CURLOPT_HEADER,
112
- CURLOPT_RETURNTRANSFER,
113
- CURLOPT_HTTPHEADER,
114
- CURLOPT_POSTFIELDS,
115
- CURLOPT_INFILE,
116
- CURLOPT_INFILESIZE,
117
- CURLOPT_PORT,
118
- CURLOPT_MAXREDIRS,
119
- CURLOPT_CONNECTTIMEOUT,
120
- CURL_HTTP_VERSION_1_1,
121
- CURL_HTTP_VERSION_1_0,
122
- );
123
- }
124
-
125
- /**
126
- * Set the configuration array for the adapter
127
- *
128
- * @throws Zend_Http_Client_Adapter_Exception
129
- * @param Zend_Config | array $config
130
- * @return Zend_Http_Client_Adapter_Curl
131
- */
132
- public function setConfig($config = array())
133
- {
134
- if ($config instanceof Zend_Config) {
135
- $config = $config->toArray();
136
-
137
- } elseif (! is_array($config)) {
138
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
139
- throw new Zend_Http_Client_Adapter_Exception(
140
- 'Array or Zend_Config object expected, got ' . gettype($config)
141
- );
142
- }
143
-
144
- if(isset($config['proxy_user']) && isset($config['proxy_pass'])) {
145
- $this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxy_user'].":".$config['proxy_pass']);
146
- unset($config['proxy_user'], $config['proxy_pass']);
147
- }
148
-
149
- foreach ($config as $k => $v) {
150
- $option = strtolower($k);
151
- switch($option) {
152
- case 'proxy_host':
153
- $this->setCurlOption(CURLOPT_PROXY, $v);
154
- break;
155
- case 'proxy_port':
156
- $this->setCurlOption(CURLOPT_PROXYPORT, $v);
157
- break;
158
- default:
159
- $this->_config[$option] = $v;
160
- break;
161
- }
162
- }
163
-
164
- return $this;
165
- }
166
-
167
- /**
168
- * Retrieve the array of all configuration options
169
- *
170
- * @return array
171
- */
172
- public function getConfig()
173
- {
174
- return $this->_config;
175
- }
176
-
177
- /**
178
- * Direct setter for cURL adapter related options.
179
- *
180
- * @param string|int $option
181
- * @param mixed $value
182
- * @return Zend_Http_Adapter_Curl
183
- */
184
- public function setCurlOption($option, $value)
185
- {
186
- if (!isset($this->_config['curloptions'])) {
187
- $this->_config['curloptions'] = array();
188
- }
189
- $this->_config['curloptions'][$option] = $value;
190
- return $this;
191
- }
192
-
193
- /**
194
- * Initialize curl
195
- *
196
- * @param string $host
197
- * @param int $port
198
- * @param boolean $secure
199
- * @return void
200
- * @throws Zend_Http_Client_Adapter_Exception if unable to connect
201
- */
202
- public function connect($host, $port = 80, $secure = false)
203
- {
204
- // If we're already connected, disconnect first
205
- if ($this->_curl) {
206
- $this->close();
207
- }
208
-
209
- // If we are connected to a different server or port, disconnect first
210
- if ($this->_curl
211
- && is_array($this->_connected_to)
212
- && ($this->_connected_to[0] != $host
213
- || $this->_connected_to[1] != $port)
214
- ) {
215
- $this->close();
216
- }
217
-
218
- // Do the actual connection
219
- $this->_curl = curl_init();
220
- if ($port != 80) {
221
- curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
222
- }
223
-
224
- // Set timeout
225
- curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
226
-
227
- // Set Max redirects
228
- curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
229
-
230
- if (!$this->_curl) {
231
- $this->close();
232
-
233
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
234
- throw new Zend_Http_Client_Adapter_Exception('Unable to Connect to ' . $host . ':' . $port);
235
- }
236
-
237
- if ($secure !== false) {
238
- // Behave the same like Zend_Http_Adapter_Socket on SSL options.
239
- if (isset($this->_config['sslcert'])) {
240
- curl_setopt($this->_curl, CURLOPT_SSLCERT, $this->_config['sslcert']);
241
- }
242
- if (isset($this->_config['sslpassphrase'])) {
243
- curl_setopt($this->_curl, CURLOPT_SSLCERTPASSWD, $this->_config['sslpassphrase']);
244
- }
245
- }
246
-
247
- // Update connected_to
248
- $this->_connected_to = array($host, $port);
249
- }
250
-
251
- /**
252
- * Send request to the remote server
253
- *
254
- * @param string $method
255
- * @param Zend_Uri_Http $uri
256
- * @param float $http_ver
257
- * @param array $headers
258
- * @param string $body
259
- * @return string $request
260
- * @throws Zend_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
261
- */
262
- public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
263
- {
264
- // Make sure we're properly connected
265
- if (!$this->_curl) {
266
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
267
- throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
268
- }
269
-
270
- if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
271
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
272
- throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
273
- }
274
-
275
- // set URL
276
- curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
277
-
278
- // ensure correct curl call
279
- $curlValue = true;
280
- switch ($method) {
281
- case Zend_Http_Client::GET:
282
- $curlMethod = CURLOPT_HTTPGET;
283
- break;
284
-
285
- case Zend_Http_Client::POST:
286
- $curlMethod = CURLOPT_POST;
287
- break;
288
-
289
- case Zend_Http_Client::PUT:
290
- // There are two different types of PUT request, either a Raw Data string has been set
291
- // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
292
- if(is_resource($body)) {
293
- $this->_config['curloptions'][CURLOPT_INFILE] = $body;
294
- }
295
- if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
296
- // Now we will probably already have Content-Length set, so that we have to delete it
297
- // from $headers at this point:
298
- foreach ($headers AS $k => $header) {
299
- if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
300
- if(is_resource($body)) {
301
- $this->_config['curloptions'][CURLOPT_INFILESIZE] = (int)$m[1];
302
- }
303
- unset($headers[$k]);
304
- }
305
- }
306
-
307
- if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
308
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
309
- throw new Zend_Http_Client_Adapter_Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
310
- }
311
-
312
- if(is_resource($body)) {
313
- $body = '';
314
- }
315
-
316
- $curlMethod = CURLOPT_PUT;
317
- } else {
318
- $curlMethod = CURLOPT_CUSTOMREQUEST;
319
- $curlValue = "PUT";
320
- }
321
- break;
322
-
323
- case Zend_Http_Client::DELETE:
324
- $curlMethod = CURLOPT_CUSTOMREQUEST;
325
- $curlValue = "DELETE";
326
- break;
327
-
328
- case Zend_Http_Client::OPTIONS:
329
- $curlMethod = CURLOPT_CUSTOMREQUEST;
330
- $curlValue = "OPTIONS";
331
- break;
332
-
333
- case Zend_Http_Client::TRACE:
334
- $curlMethod = CURLOPT_CUSTOMREQUEST;
335
- $curlValue = "TRACE";
336
- break;
337
-
338
- case Zend_Http_Client::HEAD:
339
- $curlMethod = CURLOPT_CUSTOMREQUEST;
340
- $curlValue = "HEAD";
341
- break;
342
-
343
- default:
344
- // For now, through an exception for unsupported request methods
345
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
346
- throw new Zend_Http_Client_Adapter_Exception("Method currently not supported");
347
- }
348
-
349
- if(is_resource($body) && $curlMethod != CURLOPT_PUT) {
350
- #require_once 'Zend/Http/Client/Adapter/Exception.php';
351
- throw new Zend_Http_Client_Adapter_Exception("Streaming requests are allowed only with PUT");
352
- }
353
-
354
- // get http version to use
355
- $curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
356
-
357
- // mark as HTTP request and set HTTP method
358
- curl_setopt($this->_curl, $curlHttp, true);
359
- curl_setopt($this->_curl, $curlMethod, $curlValue);
360
-
361
- if($this->out_stream) {
362
- // headers will be read into the response
363
- curl_setopt($this->_curl, CURLOPT_HEADER, false);
364
- curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
365
- // and data will be written into the file
366
- curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
367
- } else {
368
- // ensure headers are also returned
369
- curl_setopt($this->_curl, CURLOPT_HEADER, true);
370
-
371
- // ensure actual response is returned
372
- curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
373
- }
374
-
375
- // set additional headers
376
- $headers['Accept'] = '';
377
- curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
378
-
379
- /**
380
- * Make sure POSTFIELDS is set after $curlMethod is set:
381
- * @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
382
- */
383
- if ($method == Zend_Http_Client::POST) {
384
- curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
385
- } elseif ($curlMethod == CURLOPT_PUT) {
386
- // this covers a PUT by file-handle:
387
- // Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
388
- // to group common functionality together.
389
- curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
390
- curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
391
- unset($this->_config['curloptions'][CURLOPT_INFILE]);
392
- unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
393
- } elseif ($method == Zend_Http_Client::PUT) {
394
- // This is a PUT by a setRawData string, not by file-handle
395
- curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
396
- }
397
-
398
- // set additional curl options
399
- if (isset($this->_config['curloptions'])) {
400
- foreach ((array)$this->_config['curloptions'] as $k => $v) {
401
- if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
402
- if (curl_setopt($this->_curl, $k, $v) == false) {
403
- #require_once 'Zend/Http/Client/Exception.php';
404
- throw new Zend_Http_Client_Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
405
- }
406
- }
407
- }
408
- }
409
-
410
- // send the request
411
- $response = curl_exec($this->_curl);
412
-
413
- // if we used streaming, headers are already there
414
- if(!is_resource($this->out_stream)) {
415
- $this->_response = $response;
416
- }
417
-
418
- $request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
419
- $request .= $body;
420
-
421
- if (empty($this->_response)) {
422
- #require_once 'Zend/Http/Client/Exception.php';
423
- throw new Zend_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
424
- }
425
-
426
- // cURL automatically decodes chunked-messages, this means we have to disallow the Zend_Http_Response to do it again
427
- if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
428
- $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
429
- }
430
-
431
- // Eliminate multiple HTTP responses.
432
- do {
433
- $parts = preg_split('|(?:\r?\n){2}|m', $this->_response, 2);
434
- $again = false;
435
-
436
- if (isset($parts[1]) && preg_match("|^HTTP/1\.[01](.*?)\r\n|mi", $parts[1])) {
437
- $this->_response = $parts[1];
438
- $again = true;
439
- }
440
- } while ($again);
441
-
442
- // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
443
- if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
444
- $this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
445
- }
446
-
447
- return $request;
448
- }
449
-
450
- /**
451
- * Return read response from server
452
- *
453
- * @return string
454
- */
455
- public function read()
456
- {
457
- return $this->_response;
458
- }
459
-
460
- /**
461
- * Close the connection to the server
462
- *
463
- */
464
- public function close()
465
- {
466
- if(is_resource($this->_curl)) {
467
- curl_close($this->_curl);
468
- }
469
- $this->_curl = null;
470
- $this->_connected_to = array(null, null);
471
- }
472
-
473
- /**
474
- * Get cUrl Handle
475
- *
476
- * @return resource
477
- */
478
- public function getHandle()
479
- {
480
- return $this->_curl;
481
- }
482
-
483
- /**
484
- * Set output stream for the response
485
- *
486
- * @param resource $stream
487
- * @return Zend_Http_Client_Adapter_Socket
488
- */
489
- public function setOutputStream($stream)
490
- {
491
- $this->out_stream = $stream;
492
- return $this;
493
- }
494
-
495
- /**
496
- * Header reader function for CURL
497
- *
498
- * @param resource $curl
499
- * @param string $header
500
- * @return int
501
- */
502
- public function readHeader($curl, $header)
503
- {
504
- $this->_response .= $header;
505
- return strlen($header);
506
- }
507
- }
1
+ <?php
2
+
3
+ /**
4
+ * Zend Framework
5
+ *
6
+ * LICENSE
7
+ *
8
+ * This source file is subject to the new BSD license that is bundled
9
+ * with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://framework.zend.com/license/new-bsd
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@zend.com so we can send you a copy immediately.
15
+ *
16
+ * @category Zend
17
+ * @package Zend_Http
18
+ * @subpackage Client_Adapter
19
+ * @version $Id: Curl.php 22216 2010-05-20 21:12:05Z dragonbe $
20
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
+ * @license http://framework.zend.com/license/new-bsd New BSD License
22
+ */
23
+
24
+ /**
25
+ * @see Zend_Uri_Http
26
+ */
27
+ #require_once 'Zend/Uri/Http.php';
28
+
29
+ /**
30
+ * @see Zend_Http_Client_Adapter_Interface
31
+ */
32
+ #require_once 'Zend/Http/Client/Adapter/Interface.php';
33
+ /**
34
+ * @see Zend_Http_Client_Adapter_Stream
35
+ */
36
+ #require_once 'Zend/Http/Client/Adapter/Stream.php';
37
+
38
+ /**
39
+ * An adapter class for Zend_Http_Client based on the curl extension.
40
+ * Curl requires libcurl. See for full requirements the PHP manual: http://php.net/curl
41
+ *
42
+ * @category Zend
43
+ * @package Zend_Http
44
+ * @subpackage Client_Adapter
45
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
46
+ * @license http://framework.zend.com/license/new-bsd New BSD License
47
+ */
48
+ class Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interface, Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Stream
49
+ {
50
+ /**
51
+ * Parameters array
52
+ *
53
+ * @var array
54
+ */
55
+ protected $_config = array();
56
+
57
+ /**
58
+ * What host/port are we connected to?
59
+ *
60
+ * @var array
61
+ */
62
+ protected $_connected_to = array(null, null);
63
+
64
+ /**
65
+ * The curl session handle
66
+ *
67
+ * @var resource|null
68
+ */
69
+ protected $_curl = null;
70
+
71
+ /**
72
+ * List of cURL options that should never be overwritten
73
+ *
74
+ * @var array
75
+ */
76
+ protected $_invalidOverwritableCurlOptions;
77
+
78
+ /**
79
+ * Response gotten from server
80
+ *
81
+ * @var string
82
+ */
83
+ protected $_response = null;
84
+
85
+ /**
86
+ * Stream for storing output
87
+ *
88
+ * @var resource
89
+ */
90
+ protected $out_stream;
91
+
92
+ /**
93
+ * Adapter constructor
94
+ *
95
+ * Config is set using setConfig()
96
+ *
97
+ * @return void
98
+ * @throws Zend_Http_Client_Adapter_Exception
99
+ */
100
+ public function __construct()
101
+ {
102
+ if (!extension_loaded('curl')) {
103
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
104
+ throw new Zend_Http_Client_Adapter_Exception('cURL extension has to be loaded to use this Zend_Http_Client adapter.');
105
+ }
106
+ $this->_invalidOverwritableCurlOptions = array(
107
+ CURLOPT_HTTPGET,
108
+ CURLOPT_POST,
109
+ CURLOPT_PUT,
110
+ CURLOPT_CUSTOMREQUEST,
111
+ CURLOPT_HEADER,
112
+ CURLOPT_RETURNTRANSFER,
113
+ CURLOPT_HTTPHEADER,
114
+ CURLOPT_POSTFIELDS,
115
+ CURLOPT_INFILE,
116
+ CURLOPT_INFILESIZE,
117
+ CURLOPT_PORT,
118
+ CURLOPT_MAXREDIRS,
119
+ CURLOPT_CONNECTTIMEOUT,
120
+ CURL_HTTP_VERSION_1_1,
121
+ CURL_HTTP_VERSION_1_0,
122
+ );
123
+ }
124
+
125
+ /**
126
+ * Set the configuration array for the adapter
127
+ *
128
+ * @throws Zend_Http_Client_Adapter_Exception
129
+ * @param Zend_Config | array $config
130
+ * @return Zend_Http_Client_Adapter_Curl
131
+ */
132
+ public function setConfig($config = array())
133
+ {
134
+ if ($config instanceof Zend_Config) {
135
+ $config = $config->toArray();
136
+
137
+ } elseif (! is_array($config)) {
138
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
139
+ throw new Zend_Http_Client_Adapter_Exception(
140
+ 'Array or Zend_Config object expected, got ' . gettype($config)
141
+ );
142
+ }
143
+
144
+ if(isset($config['proxy_user']) && isset($config['proxy_pass'])) {
145
+ $this->setCurlOption(CURLOPT_PROXYUSERPWD, $config['proxy_user'].":".$config['proxy_pass']);
146
+ unset($config['proxy_user'], $config['proxy_pass']);
147
+ }
148
+
149
+ foreach ($config as $k => $v) {
150
+ $option = strtolower($k);
151
+ switch($option) {
152
+ case 'proxy_host':
153
+ $this->setCurlOption(CURLOPT_PROXY, $v);
154
+ break;
155
+ case 'proxy_port':
156
+ $this->setCurlOption(CURLOPT_PROXYPORT, $v);
157
+ break;
158
+ default:
159
+ $this->_config[$option] = $v;
160
+ break;
161
+ }
162
+ }
163
+
164
+ return $this;
165
+ }
166
+
167
+ /**
168
+ * Retrieve the array of all configuration options
169
+ *
170
+ * @return array
171
+ */
172
+ public function getConfig()
173
+ {
174
+ return $this->_config;
175
+ }
176
+
177
+ /**
178
+ * Direct setter for cURL adapter related options.
179
+ *
180
+ * @param string|int $option
181
+ * @param mixed $value
182
+ * @return Zend_Http_Adapter_Curl
183
+ */
184
+ public function setCurlOption($option, $value)
185
+ {
186
+ if (!isset($this->_config['curloptions'])) {
187
+ $this->_config['curloptions'] = array();
188
+ }
189
+ $this->_config['curloptions'][$option] = $value;
190
+ return $this;
191
+ }
192
+
193
+ /**
194
+ * Initialize curl
195
+ *
196
+ * @param string $host
197
+ * @param int $port
198
+ * @param boolean $secure
199
+ * @return void
200
+ * @throws Zend_Http_Client_Adapter_Exception if unable to connect
201
+ */
202
+ public function connect($host, $port = 80, $secure = false)
203
+ {
204
+ // If we're already connected, disconnect first
205
+ if ($this->_curl) {
206
+ $this->close();
207
+ }
208
+
209
+ // If we are connected to a different server or port, disconnect first
210
+ if ($this->_curl
211
+ && is_array($this->_connected_to)
212
+ && ($this->_connected_to[0] != $host
213
+ || $this->_connected_to[1] != $port)
214
+ ) {
215
+ $this->close();
216
+ }
217
+
218
+ // Do the actual connection
219
+ $this->_curl = curl_init();
220
+ if ($port != 80) {
221
+ curl_setopt($this->_curl, CURLOPT_PORT, intval($port));
222
+ }
223
+
224
+ // Set timeout
225
+ curl_setopt($this->_curl, CURLOPT_CONNECTTIMEOUT, $this->_config['timeout']);
226
+
227
+ // Set Max redirects
228
+ curl_setopt($this->_curl, CURLOPT_MAXREDIRS, $this->_config['maxredirects']);
229
+
230
+ if (!$this->_curl) {
231
+ $this->close();
232
+
233
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
234
+ throw new Zend_Http_Client_Adapter_Exception('Unable to Connect to ' . $host . ':' . $port);
235
+ }
236
+
237
+ if ($secure !== false) {
238
+ // Behave the same like Zend_Http_Adapter_Socket on SSL options.
239
+ if (isset($this->_config['sslcert'])) {
240
+ curl_setopt($this->_curl, CURLOPT_SSLCERT, $this->_config['sslcert']);
241
+ }
242
+ if (isset($this->_config['sslpassphrase'])) {
243
+ curl_setopt($this->_curl, CURLOPT_SSLCERTPASSWD, $this->_config['sslpassphrase']);
244
+ }
245
+ }
246
+
247
+ // Update connected_to
248
+ $this->_connected_to = array($host, $port);
249
+ }
250
+
251
+ /**
252
+ * Send request to the remote server
253
+ *
254
+ * @param string $method
255
+ * @param Zend_Uri_Http $uri
256
+ * @param float $http_ver
257
+ * @param array $headers
258
+ * @param string $body
259
+ * @return string $request
260
+ * @throws Zend_Http_Client_Adapter_Exception If connection fails, connected to wrong host, no PUT file defined, unsupported method, or unsupported cURL option
261
+ */
262
+ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $body = '')
263
+ {
264
+ // Make sure we're properly connected
265
+ if (!$this->_curl) {
266
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
267
+ throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are not connected");
268
+ }
269
+
270
+ if ($this->_connected_to[0] != $uri->getHost() || $this->_connected_to[1] != $uri->getPort()) {
271
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
272
+ throw new Zend_Http_Client_Adapter_Exception("Trying to write but we are connected to the wrong host");
273
+ }
274
+
275
+ // set URL
276
+ curl_setopt($this->_curl, CURLOPT_URL, $uri->__toString());
277
+
278
+ // ensure correct curl call
279
+ $curlValue = true;
280
+ switch ($method) {
281
+ case Zend_Http_Client::GET:
282
+ $curlMethod = CURLOPT_HTTPGET;
283
+ break;
284
+
285
+ case Zend_Http_Client::POST:
286
+ $curlMethod = CURLOPT_POST;
287
+ break;
288
+
289
+ case Zend_Http_Client::PUT:
290
+ // There are two different types of PUT request, either a Raw Data string has been set
291
+ // or CURLOPT_INFILE and CURLOPT_INFILESIZE are used.
292
+ if(is_resource($body)) {
293
+ $this->_config['curloptions'][CURLOPT_INFILE] = $body;
294
+ }
295
+ if (isset($this->_config['curloptions'][CURLOPT_INFILE])) {
296
+ // Now we will probably already have Content-Length set, so that we have to delete it
297
+ // from $headers at this point:
298
+ foreach ($headers AS $k => $header) {
299
+ if (preg_match('/Content-Length:\s*(\d+)/i', $header, $m)) {
300
+ if(is_resource($body)) {
301
+ $this->_config['curloptions'][CURLOPT_INFILESIZE] = (int)$m[1];
302
+ }
303
+ unset($headers[$k]);
304
+ }
305
+ }
306
+
307
+ if (!isset($this->_config['curloptions'][CURLOPT_INFILESIZE])) {
308
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
309
+ throw new Zend_Http_Client_Adapter_Exception("Cannot set a file-handle for cURL option CURLOPT_INFILE without also setting its size in CURLOPT_INFILESIZE.");
310
+ }
311
+
312
+ if(is_resource($body)) {
313
+ $body = '';
314
+ }
315
+
316
+ $curlMethod = CURLOPT_PUT;
317
+ } else {
318
+ $curlMethod = CURLOPT_CUSTOMREQUEST;
319
+ $curlValue = "PUT";
320
+ }
321
+ break;
322
+
323
+ case Zend_Http_Client::DELETE:
324
+ $curlMethod = CURLOPT_CUSTOMREQUEST;
325
+ $curlValue = "DELETE";
326
+ break;
327
+
328
+ case Zend_Http_Client::OPTIONS:
329
+ $curlMethod = CURLOPT_CUSTOMREQUEST;
330
+ $curlValue = "OPTIONS";
331
+ break;
332
+
333
+ case Zend_Http_Client::TRACE:
334
+ $curlMethod = CURLOPT_CUSTOMREQUEST;
335
+ $curlValue = "TRACE";
336
+ break;
337
+
338
+ case Zend_Http_Client::HEAD:
339
+ $curlMethod = CURLOPT_CUSTOMREQUEST;
340
+ $curlValue = "HEAD";
341
+ break;
342
+
343
+ default:
344
+ // For now, through an exception for unsupported request methods
345
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
346
+ throw new Zend_Http_Client_Adapter_Exception("Method currently not supported");
347
+ }
348
+
349
+ if(is_resource($body) && $curlMethod != CURLOPT_PUT) {
350
+ #require_once 'Zend/Http/Client/Adapter/Exception.php';
351
+ throw new Zend_Http_Client_Adapter_Exception("Streaming requests are allowed only with PUT");
352
+ }
353
+
354
+ // get http version to use
355
+ $curlHttp = ($httpVersion == 1.1) ? CURL_HTTP_VERSION_1_1 : CURL_HTTP_VERSION_1_0;
356
+
357
+ // mark as HTTP request and set HTTP method
358
+ curl_setopt($this->_curl, $curlHttp, true);
359
+ curl_setopt($this->_curl, $curlMethod, $curlValue);
360
+
361
+ if($this->out_stream) {
362
+ // headers will be read into the response
363
+ curl_setopt($this->_curl, CURLOPT_HEADER, false);
364
+ curl_setopt($this->_curl, CURLOPT_HEADERFUNCTION, array($this, "readHeader"));
365
+ // and data will be written into the file
366
+ curl_setopt($this->_curl, CURLOPT_FILE, $this->out_stream);
367
+ } else {
368
+ // ensure headers are also returned
369
+ curl_setopt($this->_curl, CURLOPT_HEADER, true);
370
+
371
+ // ensure actual response is returned
372
+ curl_setopt($this->_curl, CURLOPT_RETURNTRANSFER, true);
373
+ }
374
+
375
+ // set additional headers
376
+ $headers['Accept'] = '';
377
+ curl_setopt($this->_curl, CURLOPT_HTTPHEADER, $headers);
378
+
379
+ /**
380
+ * Make sure POSTFIELDS is set after $curlMethod is set:
381
+ * @link http://de2.php.net/manual/en/function.curl-setopt.php#81161
382
+ */
383
+ if ($method == Zend_Http_Client::POST) {
384
+ curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
385
+ } elseif ($curlMethod == CURLOPT_PUT) {
386
+ // this covers a PUT by file-handle:
387
+ // Make the setting of this options explicit (rather than setting it through the loop following a bit lower)
388
+ // to group common functionality together.
389
+ curl_setopt($this->_curl, CURLOPT_INFILE, $this->_config['curloptions'][CURLOPT_INFILE]);
390
+ curl_setopt($this->_curl, CURLOPT_INFILESIZE, $this->_config['curloptions'][CURLOPT_INFILESIZE]);
391
+ unset($this->_config['curloptions'][CURLOPT_INFILE]);
392
+ unset($this->_config['curloptions'][CURLOPT_INFILESIZE]);
393
+ } elseif ($method == Zend_Http_Client::PUT) {
394
+ // This is a PUT by a setRawData string, not by file-handle
395
+ curl_setopt($this->_curl, CURLOPT_POSTFIELDS, $body);
396
+ }
397
+
398
+ // set additional curl options
399
+ if (isset($this->_config['curloptions'])) {
400
+ foreach ((array)$this->_config['curloptions'] as $k => $v) {
401
+ if (!in_array($k, $this->_invalidOverwritableCurlOptions)) {
402
+ if (curl_setopt($this->_curl, $k, $v) == false) {
403
+ #require_once 'Zend/Http/Client/Exception.php';
404
+ throw new Zend_Http_Client_Exception(sprintf("Unknown or erroreous cURL option '%s' set", $k));
405
+ }
406
+ }
407
+ }
408
+ }
409
+
410
+ // send the request
411
+ $response = curl_exec($this->_curl);
412
+
413
+ // if we used streaming, headers are already there
414
+ if(!is_resource($this->out_stream)) {
415
+ $this->_response = $response;
416
+ }
417
+
418
+ $request = curl_getinfo($this->_curl, CURLINFO_HEADER_OUT);
419
+ $request .= $body;
420
+
421
+ if (empty($this->_response)) {
422
+ #require_once 'Zend/Http/Client/Exception.php';
423
+ throw new Zend_Http_Client_Exception("Error in cURL request: " . curl_error($this->_curl));
424
+ }
425
+
426
+ // cURL automatically decodes chunked-messages, this means we have to disallow the Zend_Http_Response to do it again
427
+ if (stripos($this->_response, "Transfer-Encoding: chunked\r\n")) {
428
+ $this->_response = str_ireplace("Transfer-Encoding: chunked\r\n", '', $this->_response);
429
+ }
430
+
431
+ // Eliminate multiple HTTP responses.
432
+ do {
433
+ $parts = preg_split('|(?:\r?\n){2}|m', $this->_response, 2);
434
+ $again = false;
435
+
436
+ if (isset($parts[1]) && preg_match("|^HTTP/1\.[01](.*?)\r\n|mi", $parts[1])) {
437
+ $this->_response = $parts[1];
438
+ $again = true;
439
+ }
440
+ } while ($again);
441
+
442
+ // cURL automatically handles Proxy rewrites, remove the "HTTP/1.0 200 Connection established" string:
443
+ if (stripos($this->_response, "HTTP/1.0 200 Connection established\r\n\r\n") !== false) {
444
+ $this->_response = str_ireplace("HTTP/1.0 200 Connection established\r\n\r\n", '', $this->_response);
445
+ }
446
+
447
+ return $request;
448
+ }
449
+
450
+ /**
451
+ * Return read response from server
452
+ *
453
+ * @return string
454
+ */
455
+ public function read()
456
+ {
457
+ return $this->_response;
458
+ }
459
+
460
+ /**
461
+ * Close the connection to the server
462
+ *
463
+ */
464
+ public function close()
465
+ {
466
+ if(is_resource($this->_curl)) {
467
+ curl_close($this->_curl);
468
+ }
469
+ $this->_curl = null;
470
+ $this->_connected_to = array(null, null);
471
+ }
472
+
473
+ /**
474
+ * Get cUrl Handle
475
+ *
476
+ * @return resource
477
+ */
478
+ public function getHandle()
479
+ {
480
+ return $this->_curl;
481
+ }
482
+
483
+ /**
484
+ * Set output stream for the response
485
+ *
486
+ * @param resource $stream
487
+ * @return Zend_Http_Client_Adapter_Socket
488
+ */
489
+ public function setOutputStream($stream)
490
+ {
491
+ $this->out_stream = $stream;
492
+ return $this;
493
+ }
494
+
495
+ /**
496
+ * Header reader function for CURL
497
+ *
498
+ * @param resource $curl
499
+ * @param string $header
500
+ * @return int
501
+ */
502
+ public function readHeader($curl, $header)
503
+ {
504
+ $this->_response .= $header;
505
+ return strlen($header);
506
+ }
507
+ }
app/code/community/Profileolabs/Shoppingflux/Model/Service/Http/Client/Adapter/Stream.php CHANGED
@@ -1,46 +1,46 @@
1
- <?php
2
-
3
- /**
4
- * Zend Framework
5
- *
6
- * LICENSE
7
- *
8
- * This source file is subject to the new BSD license that is bundled
9
- * with this package in the file LICENSE.txt.
10
- * It is also available through the world-wide-web at this URL:
11
- * http://framework.zend.com/license/new-bsd
12
- * If you did not receive a copy of the license and are unable to
13
- * obtain it through the world-wide-web, please send an email
14
- * to license@zend.com so we can send you a copy immediately.
15
- *
16
- * @category Zend
17
- * @package Zend_Http
18
- * @subpackage Client_Adapter
19
- * @version $Id: Stream.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
- * @license http://framework.zend.com/license/new-bsd New BSD License
22
- */
23
-
24
- /**
25
- * An interface description for Zend_Http_Client_Adapter_Stream classes.
26
- *
27
- * This interface decribes Zend_Http_Client_Adapter which supports streaming.
28
- *
29
- * @category Zend
30
- * @package Zend_Http
31
- * @subpackage Client_Adapter
32
- * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
- * @license http://framework.zend.com/license/new-bsd New BSD License
34
- */
35
- interface Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Stream
36
- {
37
- /**
38
- * Set output stream
39
- *
40
- * This function sets output stream where the result will be stored.
41
- *
42
- * @param resource $stream Stream to write the output to
43
- *
44
- */
45
- function setOutputStream($stream);
46
- }
1
+ <?php
2
+
3
+ /**
4
+ * Zend Framework
5
+ *
6
+ * LICENSE
7
+ *
8
+ * This source file is subject to the new BSD license that is bundled
9
+ * with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://framework.zend.com/license/new-bsd
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@zend.com so we can send you a copy immediately.
15
+ *
16
+ * @category Zend
17
+ * @package Zend_Http
18
+ * @subpackage Client_Adapter
19
+ * @version $Id: Stream.php 20785 2010-01-31 09:43:03Z mikaelkael $
20
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
21
+ * @license http://framework.zend.com/license/new-bsd New BSD License
22
+ */
23
+
24
+ /**
25
+ * An interface description for Zend_Http_Client_Adapter_Stream classes.
26
+ *
27
+ * This interface decribes Zend_Http_Client_Adapter which supports streaming.
28
+ *
29
+ * @category Zend
30
+ * @package Zend_Http
31
+ * @subpackage Client_Adapter
32
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
33
+ * @license http://framework.zend.com/license/new-bsd New BSD License
34
+ */
35
+ interface Profileolabs_Shoppingflux_Model_Service_Http_Client_Adapter_Stream
36
+ {
37
+ /**
38
+ * Set output stream
39
+ *
40
+ * This function sets output stream where the result will be stored.
41
+ *
42
+ * @param resource $stream Stream to write the output to
43
+ *
44
+ */
45
+ function setOutputStream($stream);
46
+ }
app/code/community/Profileolabs/Shoppingflux/Model/System/Config/Backend/Apikey.php CHANGED
@@ -1,39 +1,39 @@
1
- <?php
2
-
3
- /**
4
- * @deprecated
5
- * Shopping Flux Backend Model for Config Api key
6
- * @category ShoppingFlux
7
- * @package Profileolabs_Shoppingflux
8
- * @author kassim belghait
9
- */
10
- class Profileolabs_Shoppingflux_Model_System_Config_Backend_Apikey extends Mage_Core_Model_Config_Data {
11
-
12
- public function getConfig() {
13
- return Mage::getSingleton('profileolabs_shoppingflux/config');
14
- }
15
-
16
- protected function _beforeSave() {
17
- parent::_beforeSave();
18
-
19
- /*
20
- if ($this->isValueChanged()) {
21
- $storeId = 0;
22
- switch($this->getScope()) {
23
- case 'stores':
24
- $storeId = $this->getScopeId();
25
- break;
26
- }
27
- $apiKey = $this->getConfig()->getApiKey($storeId);
28
- $wsUri = $this->getConfig()->getWsUri();
29
-
30
- $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
31
-
32
- if ((boolean) $this->getFieldsetDataValue('enabled') && !$service->checkApiKey($this->getValue()))
33
- Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__('API key (Token) not valid'));
34
- }
35
-
36
- */
37
- }
38
-
39
  }
1
+ <?php
2
+
3
+ /**
4
+ * @deprecated
5
+ * Shopping Flux Backend Model for Config Api key
6
+ * @category ShoppingFlux
7
+ * @package Profileolabs_Shoppingflux
8
+ * @author kassim belghait
9
+ */
10
+ class Profileolabs_Shoppingflux_Model_System_Config_Backend_Apikey extends Mage_Core_Model_Config_Data {
11
+
12
+ public function getConfig() {
13
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
14
+ }
15
+
16
+ protected function _beforeSave() {
17
+ parent::_beforeSave();
18
+
19
+ /*
20
+ if ($this->isValueChanged()) {
21
+ $storeId = 0;
22
+ switch($this->getScope()) {
23
+ case 'stores':
24
+ $storeId = $this->getScopeId();
25
+ break;
26
+ }
27
+ $apiKey = $this->getConfig()->getApiKey($storeId);
28
+ $wsUri = $this->getConfig()->getWsUri();
29
+
30
+ $service = new Profileolabs_Shoppingflux_Model_Service($apiKey, $wsUri);
31
+
32
+ if ((boolean) $this->getFieldsetDataValue('enabled') && !$service->checkApiKey($this->getValue()))
33
+ Mage::throwException(Mage::helper('profileolabs_shoppingflux')->__('API key (Token) not valid'));
34
+ }
35
+
36
+ */
37
+ }
38
+
39
  }
app/code/community/Profileolabs/Shoppingflux/Model/System/Config/Backend/Category.php CHANGED
@@ -1,51 +1,51 @@
1
- <?php
2
-
3
- /**
4
- * @deprecated
5
- * Shopping Flux Backend Model for Config Api key
6
- * @category ShoppingFlux
7
- * @package Profileolabs_Shoppingflux
8
- * @author kassim belghait
9
- */
10
- class Profileolabs_Shoppingflux_Model_System_Config_Backend_Category extends Profileolabs_Shoppingflux_Model_System_Config_Backend_Refresh {
11
-
12
- public function getConfig() {
13
- return Mage::getSingleton('profileolabs_shoppingflux/config');
14
- }
15
-
16
- protected function _afterSave() {
17
- try {
18
- if ($this->isValueChanged()) {
19
-
20
- $categoryAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'shoppingflux_default_category');
21
-
22
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
23
- $write->beginTransaction();
24
- try {
25
- if($this->getValue()) {
26
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('eav/attribute') . " set source_model = 'profileolabs_shoppingflux/attribute_source_category' where attribute_id = '" . $categoryAttribute->getId() . "'";
27
- $write->query($query);
28
-
29
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('catalog/eav_attribute') . " set is_visible = '1' where attribute_id = '" . $categoryAttribute->getId() . "'";
30
- $write->query($query);
31
- } else {
32
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('eav/attribute') . " set source_model = '' where attribute_id = '" . $categoryAttribute->getId() . "'";
33
- $write->query($query);
34
-
35
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('catalog/eav_attribute') . " set is_visible = '0' where attribute_id = '" . $categoryAttribute->getId() . "'";
36
- $write->query($query);
37
- }
38
- $write->commit();
39
- } catch (Exception $e) {
40
- $write->rollback();
41
- }
42
-
43
- }
44
- } catch (Exception $e) {
45
-
46
- }
47
- parent::_afterSave();
48
- }
49
-
50
-
51
  }
1
+ <?php
2
+
3
+ /**
4
+ * @deprecated
5
+ * Shopping Flux Backend Model for Config Api key
6
+ * @category ShoppingFlux
7
+ * @package Profileolabs_Shoppingflux
8
+ * @author kassim belghait
9
+ */
10
+ class Profileolabs_Shoppingflux_Model_System_Config_Backend_Category extends Profileolabs_Shoppingflux_Model_System_Config_Backend_Refresh {
11
+
12
+ public function getConfig() {
13
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
14
+ }
15
+
16
+ protected function _afterSave() {
17
+ try {
18
+ if ($this->isValueChanged()) {
19
+
20
+ $categoryAttribute = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'shoppingflux_default_category');
21
+
22
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
23
+ $write->beginTransaction();
24
+ try {
25
+ if($this->getValue()) {
26
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('eav/attribute') . " set source_model = 'profileolabs_shoppingflux/attribute_source_category' where attribute_id = '" . $categoryAttribute->getId() . "'";
27
+ $write->query($query);
28
+
29
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('catalog/eav_attribute') . " set is_visible = '1' where attribute_id = '" . $categoryAttribute->getId() . "'";
30
+ $write->query($query);
31
+ } else {
32
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('eav/attribute') . " set source_model = '' where attribute_id = '" . $categoryAttribute->getId() . "'";
33
+ $write->query($query);
34
+
35
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('catalog/eav_attribute') . " set is_visible = '0' where attribute_id = '" . $categoryAttribute->getId() . "'";
36
+ $write->query($query);
37
+ }
38
+ $write->commit();
39
+ } catch (Exception $e) {
40
+ $write->rollback();
41
+ }
42
+
43
+ }
44
+ } catch (Exception $e) {
45
+
46
+ }
47
+ parent::_afterSave();
48
+ }
49
+
50
+
51
  }
app/code/community/Profileolabs/Shoppingflux/Model/System/Config/Backend/Refresh.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
-
3
- /**
4
- * @deprecated
5
- * Shopping Flux Backend Model for Config Api key
6
- * @category ShoppingFlux
7
- * @package Profileolabs_Shoppingflux
8
- * @author kassim belghait
9
- */
10
- class Profileolabs_Shoppingflux_Model_System_Config_Backend_Refresh extends Mage_Core_Model_Config_Data {
11
-
12
- public function getConfig() {
13
- return Mage::getSingleton('profileolabs_shoppingflux/config');
14
- }
15
-
16
- protected function _afterSave() {
17
- try {
18
- if ($this->isValueChanged()) {
19
-
20
- $storeIds = array();
21
-
22
- $storeId = Mage::app()->getStore($this->getStoreCode())->getId();
23
-
24
- try {
25
- $websiteId = Mage::app()->getWebsite($this->getWebsiteCode())->getId();
26
- } catch (Mage_Core_Exception $e) {
27
- $websiteId = 0;
28
- }
29
-
30
- if ($storeId != 0) {
31
- $storeIds[] = $storeId;
32
- } else if ($websiteId != 0) {
33
- $stores = Mage::app()->getWebsite($this->getWebsiteCode())->getStores();
34
- foreach ($stores as $strId => $str) {
35
- $storeIds[] = $strId;
36
- }
37
- } else {
38
- $stores = Mage::app()->getStores();
39
- foreach ($stores as $strId => $str) {
40
- $storeIds[] = $strId;
41
- }
42
- }
43
-
44
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
45
- foreach ($storeIds as $storeId) {
46
- $write->beginTransaction();
47
- try {
48
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 where store_id = '" . $storeId . "'";
49
- $write->query($query);
50
- $write->commit();
51
- } catch (Exception $e) {
52
- $write->rollback();
53
- }
54
- }
55
- }
56
- } catch (Exception $e) {
57
-
58
- }
59
- }
60
-
61
  }
1
+ <?php
2
+
3
+ /**
4
+ * @deprecated
5
+ * Shopping Flux Backend Model for Config Api key
6
+ * @category ShoppingFlux
7
+ * @package Profileolabs_Shoppingflux
8
+ * @author kassim belghait
9
+ */
10
+ class Profileolabs_Shoppingflux_Model_System_Config_Backend_Refresh extends Mage_Core_Model_Config_Data {
11
+
12
+ public function getConfig() {
13
+ return Mage::getSingleton('profileolabs_shoppingflux/config');
14
+ }
15
+
16
+ protected function _afterSave() {
17
+ try {
18
+ if ($this->isValueChanged()) {
19
+
20
+ $storeIds = array();
21
+
22
+ $storeId = Mage::app()->getStore($this->getStoreCode())->getId();
23
+
24
+ try {
25
+ $websiteId = Mage::app()->getWebsite($this->getWebsiteCode())->getId();
26
+ } catch (Mage_Core_Exception $e) {
27
+ $websiteId = 0;
28
+ }
29
+
30
+ if ($storeId != 0) {
31
+ $storeIds[] = $storeId;
32
+ } else if ($websiteId != 0) {
33
+ $stores = Mage::app()->getWebsite($this->getWebsiteCode())->getStores();
34
+ foreach ($stores as $strId => $str) {
35
+ $storeIds[] = $strId;
36
+ }
37
+ } else {
38
+ $stores = Mage::app()->getStores();
39
+ foreach ($stores as $strId => $str) {
40
+ $storeIds[] = $strId;
41
+ }
42
+ }
43
+
44
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
45
+ foreach ($storeIds as $storeId) {
46
+ $write->beginTransaction();
47
+ try {
48
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 where store_id = '" . $storeId . "'";
49
+ $write->query($query);
50
+ $write->commit();
51
+ } catch (Exception $e) {
52
+ $write->rollback();
53
+ }
54
+ }
55
+ }
56
+ } catch (Exception $e) {
57
+
58
+ }
59
+ }
60
+
61
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Export/CategoryController.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author vincent enjalbert
8
- */
9
- include_once "Mage/Adminhtml/controllers/Catalog/CategoryController.php";
10
-
11
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Export_CategoryController extends Mage_Adminhtml_Catalog_CategoryController {
12
-
13
- /**
14
- * Grid Action
15
- * Display list of products related to current category
16
- *
17
- * @return void
18
- */
19
- public function gridAction() {
20
- if (!$category = $this->_initCategory(true)) {
21
- return;
22
- }
23
- $this->getResponse()->setBody(
24
- $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_catalog_category_tab_default', 'shoppingflux.product.grid')
25
- ->toHtml()
26
- );
27
- }
28
-
29
- protected function _isAllowed()
30
- {
31
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/export');
32
- }
33
-
34
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author vincent enjalbert
8
+ */
9
+ include_once "Mage/Adminhtml/controllers/Catalog/CategoryController.php";
10
+
11
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Export_CategoryController extends Mage_Adminhtml_Catalog_CategoryController {
12
+
13
+ /**
14
+ * Grid Action
15
+ * Display list of products related to current category
16
+ *
17
+ * @return void
18
+ */
19
+ public function gridAction() {
20
+ if (!$category = $this->_initCategory(true)) {
21
+ return;
22
+ }
23
+ $this->getResponse()->setBody(
24
+ $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_catalog_category_tab_default', 'shoppingflux.product.grid')
25
+ ->toHtml()
26
+ );
27
+ }
28
+
29
+ protected function _isAllowed()
30
+ {
31
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/export');
32
+ }
33
+
34
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/ExportController.php CHANGED
@@ -1,135 +1,135 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux
7
- * @author kassim belghait
8
- * @deprecated deprecated since 0.1.1
9
- */
10
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_ExportController extends Mage_Adminhtml_Controller_Action {
11
-
12
- protected $_flowModel = null;
13
-
14
- /**
15
- * Get Singleton Flow
16
- * @return Profileolabs_Shoppingflux_Model_Export_Flow
17
- */
18
- protected function _getFlow() {
19
- $storeId = $this->getRequest()->getParam('store', 0);
20
- return Mage::getSingleton('profileolabs_shoppingflux/export_flow')->setStoreId($storeId);
21
- }
22
-
23
- public function indexAction() {
24
- $this->_redirect('*/*/edit');
25
- }
26
-
27
- public function editAction() {
28
- $this->loadLayout();
29
- $this->renderLayout();
30
- }
31
-
32
- public function updateAction() {
33
- $this->loadLayout();
34
- $this->renderLayout();
35
-
36
- return $this;
37
- }
38
-
39
- public function showAction() {
40
-
41
- $this->loadLayout();
42
- $this->renderLayout();
43
-
44
- return $this;
45
- }
46
-
47
- /**
48
- * Product grid for AJAX request
49
- */
50
- public function gridAction() {
51
- $this->loadLayout();
52
- $this->getResponse()->setBody(
53
- $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_product_grid')->toHtml()
54
- );
55
- }
56
-
57
- public function massPublishAction() {
58
- $productIds = (array) $this->getRequest()->getParam('product');
59
- $storeId = (int) $this->getRequest()->getParam('store', 0);
60
- $publish = (int) $this->getRequest()->getParam('publish');
61
- // die('P: '.$publish);
62
- //$entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getEntiyTypeId();
63
- $resource = Mage::getResourceModel('catalog/product');
64
- $entityTypeId = $resource->getEntityType()->getId();
65
-
66
- try {
67
- foreach ($productIds as $productId) {
68
- $product = new Varien_Object(array('entity_id' => $productId,
69
- 'id' => $productId,
70
- 'entity_type_id' => $entityTypeId,
71
- 'store_id' => $storeId,
72
- 'shoppingflux_product' => $publish));
73
- Mage::dispatchEvent('shoppingflux_mass_publish_save_item', array('product_id' => $productId, 'shoppingflux_product'=>$publish));
74
- $resource->saveAttribute($product, 'shoppingflux_product');
75
- }
76
- $this->_getSession()->addSuccess(
77
- $this->__('Total of %d record(s) were successfully updated', count($productIds))
78
- );
79
- } catch (Mage_Core_Model_Exception $e) {
80
- $this->_getSession()->addError($e->getMessage());
81
- } catch (Exception $e) {
82
- $this->_getSession()->addException($e, $e->getMessage() . $this->__('There was an error while updating product(s) publication'));
83
- }
84
-
85
- $this->_redirect('*/*/update', array('store' => $storeId));
86
- }
87
-
88
- public function runAction() {
89
- $this->loadLayout();
90
- $this->renderLayout();
91
-
92
- return $this;
93
- }
94
-
95
- public function flowRunAction() {
96
- if ($this->getRequest()->isPost()) {
97
-
98
- $offset = $this->getRequest()->getPost('offset', 1);
99
- $errors = array();
100
- $saved = 0;
101
- try {
102
-
103
- $this->_getFlow()->generateProductsNodes($offset);
104
- $saved = $this->_getFlow()->getLastCount();
105
- ;
106
- $errors = $this->_getFlow()->getErrors();
107
- } catch (Exception $e) {
108
- $errors[] = $e->getMessage();
109
- }
110
-
111
- $result = array(
112
- 'savedRows' => $saved,
113
- 'errors' => $errors,
114
- 'offset' => $offset,
115
- );
116
- $this->getResponse()->setBody(Zend_Json::encode($result));
117
- }
118
- }
119
-
120
- protected function _getSession() {
121
- return Mage::getSingleton('adminhtml/session');
122
- }
123
-
124
- public function flowFinishAction() {
125
- $result = array();
126
- $storeCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getCode();
127
- $result['filename'] = Mage::getBaseUrl('media') . "shoppingflux/" . $storeCode . "/flow.xml";
128
- $this->getResponse()->setBody(Zend_Json::encode($result));
129
- }
130
-
131
- protected function _isAllowed()
132
- {
133
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/export');
134
- }
135
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux
7
+ * @author kassim belghait
8
+ * @deprecated deprecated since 0.1.1
9
+ */
10
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_ExportController extends Mage_Adminhtml_Controller_Action {
11
+
12
+ protected $_flowModel = null;
13
+
14
+ /**
15
+ * Get Singleton Flow
16
+ * @return Profileolabs_Shoppingflux_Model_Export_Flow
17
+ */
18
+ protected function _getFlow() {
19
+ $storeId = $this->getRequest()->getParam('store', 0);
20
+ return Mage::getSingleton('profileolabs_shoppingflux/export_flow')->setStoreId($storeId);
21
+ }
22
+
23
+ public function indexAction() {
24
+ $this->_redirect('*/*/edit');
25
+ }
26
+
27
+ public function editAction() {
28
+ $this->loadLayout();
29
+ $this->renderLayout();
30
+ }
31
+
32
+ public function updateAction() {
33
+ $this->loadLayout();
34
+ $this->renderLayout();
35
+
36
+ return $this;
37
+ }
38
+
39
+ public function showAction() {
40
+
41
+ $this->loadLayout();
42
+ $this->renderLayout();
43
+
44
+ return $this;
45
+ }
46
+
47
+ /**
48
+ * Product grid for AJAX request
49
+ */
50
+ public function gridAction() {
51
+ $this->loadLayout();
52
+ $this->getResponse()->setBody(
53
+ $this->getLayout()->createBlock('profileolabs_shoppingflux/export_adminhtml_product_grid')->toHtml()
54
+ );
55
+ }
56
+
57
+ public function massPublishAction() {
58
+ $productIds = (array) $this->getRequest()->getParam('product');
59
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
60
+ $publish = (int) $this->getRequest()->getParam('publish');
61
+ // die('P: '.$publish);
62
+ //$entityTypeId = Mage::getSingleton('eav/config')->getEntityType('catalog_product')->getEntiyTypeId();
63
+ $resource = Mage::getResourceModel('catalog/product');
64
+ $entityTypeId = $resource->getEntityType()->getId();
65
+
66
+ try {
67
+ foreach ($productIds as $productId) {
68
+ $product = new Varien_Object(array('entity_id' => $productId,
69
+ 'id' => $productId,
70
+ 'entity_type_id' => $entityTypeId,
71
+ 'store_id' => $storeId,
72
+ 'shoppingflux_product' => $publish));
73
+ Mage::dispatchEvent('shoppingflux_mass_publish_save_item', array('product_id' => $productId, 'shoppingflux_product'=>$publish));
74
+ $resource->saveAttribute($product, 'shoppingflux_product');
75
+ }
76
+ $this->_getSession()->addSuccess(
77
+ $this->__('Total of %d record(s) were successfully updated', count($productIds))
78
+ );
79
+ } catch (Mage_Core_Model_Exception $e) {
80
+ $this->_getSession()->addError($e->getMessage());
81
+ } catch (Exception $e) {
82
+ $this->_getSession()->addException($e, $e->getMessage() . $this->__('There was an error while updating product(s) publication'));
83
+ }
84
+
85
+ $this->_redirect('*/*/update', array('store' => $storeId));
86
+ }
87
+
88
+ public function runAction() {
89
+ $this->loadLayout();
90
+ $this->renderLayout();
91
+
92
+ return $this;
93
+ }
94
+
95
+ public function flowRunAction() {
96
+ if ($this->getRequest()->isPost()) {
97
+
98
+ $offset = $this->getRequest()->getPost('offset', 1);
99
+ $errors = array();
100
+ $saved = 0;
101
+ try {
102
+
103
+ $this->_getFlow()->generateProductsNodes($offset);
104
+ $saved = $this->_getFlow()->getLastCount();
105
+ ;
106
+ $errors = $this->_getFlow()->getErrors();
107
+ } catch (Exception $e) {
108
+ $errors[] = $e->getMessage();
109
+ }
110
+
111
+ $result = array(
112
+ 'savedRows' => $saved,
113
+ 'errors' => $errors,
114
+ 'offset' => $offset,
115
+ );
116
+ $this->getResponse()->setBody(Zend_Json::encode($result));
117
+ }
118
+ }
119
+
120
+ protected function _getSession() {
121
+ return Mage::getSingleton('adminhtml/session');
122
+ }
123
+
124
+ public function flowFinishAction() {
125
+ $result = array();
126
+ $storeCode = Mage::app()->getStore($this->getRequest()->getParam('store'))->getCode();
127
+ $result['filename'] = Mage::getBaseUrl('media') . "shoppingflux/" . $storeCode . "/flow.xml";
128
+ $this->getResponse()->setBody(Zend_Json::encode($result));
129
+ }
130
+
131
+ protected function _isAllowed()
132
+ {
133
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/export');
134
+ }
135
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/GeneralController.php CHANGED
@@ -1,53 +1,53 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux
6
- * @author vincent enjalbert - web cooking
7
- */
8
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_GeneralController extends Mage_Adminhtml_Controller_Action
9
- {
10
- public function userdefinedAction() {
11
- $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
12
- $installer->updateAttribute('catalog_product', 'shoppingflux_default_category', 'is_user_defined', 1);
13
- $installer->updateAttribute('catalog_product', 'shoppingflux_product', 'is_user_defined', 1);
14
- }
15
-
16
-
17
- public function nuserdefinedAction() {
18
- $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
19
- $installer->updateAttribute('catalog_product', 'shoppingflux_default_category', 'is_user_defined', 0);
20
- $installer->updateAttribute('catalog_product', 'shoppingflux_product', 'is_user_defined', 0);
21
- }
22
-
23
- public function testAction() {
24
- //Profileolabs_Shoppingflux_Model_Export_Observer::fillMainCategory();
25
- //return;
26
-
27
-
28
- ini_set('display_errors',1);
29
- error_reporting(-1);
30
- //$write = Mage::getSingleton('core/resource')->getConnection('core_write');
31
- //$query = "delete from " . Mage::getConfig()->getTablePrefix() . 'core_resource' . " where code = 'profileolabs_shoppingflux_setup' ";
32
- //$write->query($query);
33
- /*$read = Mage::getSingleton('core/resource')->getConnection('core_read');
34
- $select = $read->select()
35
- ->distinct()
36
- ->from(Mage::getConfig()->getTablePrefix() . 'core_resource', array('code', 'version', 'data_version'))
37
- ->where('code = ?', 'profileolabs_shoppingflux_setup');
38
- $values = $read->fetchAll($select);
39
- foreach($values as $value) {
40
- var_dump($value);
41
- }*/
42
-
43
- die('OK');
44
- }
45
-
46
-
47
- protected function _isAllowed()
48
- {
49
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux');
50
- }
51
-
52
-
53
  }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux
6
+ * @author vincent enjalbert - web cooking
7
+ */
8
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_GeneralController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ public function userdefinedAction() {
11
+ $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
12
+ $installer->updateAttribute('catalog_product', 'shoppingflux_default_category', 'is_user_defined', 1);
13
+ $installer->updateAttribute('catalog_product', 'shoppingflux_product', 'is_user_defined', 1);
14
+ }
15
+
16
+
17
+ public function nuserdefinedAction() {
18
+ $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
19
+ $installer->updateAttribute('catalog_product', 'shoppingflux_default_category', 'is_user_defined', 0);
20
+ $installer->updateAttribute('catalog_product', 'shoppingflux_product', 'is_user_defined', 0);
21
+ }
22
+
23
+ public function testAction() {
24
+ //Profileolabs_Shoppingflux_Model_Export_Observer::fillMainCategory();
25
+ //return;
26
+
27
+
28
+ ini_set('display_errors',1);
29
+ error_reporting(-1);
30
+ //$write = Mage::getSingleton('core/resource')->getConnection('core_write');
31
+ //$query = "delete from " . Mage::getConfig()->getTablePrefix() . 'core_resource' . " where code = 'profileolabs_shoppingflux_setup' ";
32
+ //$write->query($query);
33
+ /*$read = Mage::getSingleton('core/resource')->getConnection('core_read');
34
+ $select = $read->select()
35
+ ->distinct()
36
+ ->from(Mage::getConfig()->getTablePrefix() . 'core_resource', array('code', 'version', 'data_version'))
37
+ ->where('code = ?', 'profileolabs_shoppingflux_setup');
38
+ $values = $read->fetchAll($select);
39
+ foreach($values as $value) {
40
+ var_dump($value);
41
+ }*/
42
+
43
+ die('OK');
44
+ }
45
+
46
+
47
+ protected function _isAllowed()
48
+ {
49
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux');
50
+ }
51
+
52
+
53
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Order/CronController.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux_ManageOrders
6
- * @author Vincent Enjalbert
7
- */
8
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Order_CronController extends Mage_Adminhtml_Controller_Action
9
- {
10
- protected function _initAction() {
11
- $this->loadLayout()
12
- ->_setActiveMenu('shoppingflux/manageorders/crons')
13
- ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('Crons'), Mage::helper('profileolabs_shoppingflux')->__('Crons'));
14
-
15
- return $this;
16
- }
17
-
18
-
19
- public function indexAction()
20
- {
21
- $this->_initAction()
22
- ->renderLayout();
23
-
24
- return $this;
25
- }
26
-
27
-
28
-
29
- public function gridAction()
30
- {
31
- $this->getResponse()->setBody(
32
- $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_cron_grid')->toHtml()
33
- );
34
-
35
- return $this;
36
- }
37
-
38
- protected function _isAllowed()
39
- {
40
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux');
41
- }
42
  }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux_ManageOrders
6
+ * @author Vincent Enjalbert
7
+ */
8
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Order_CronController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ protected function _initAction() {
11
+ $this->loadLayout()
12
+ ->_setActiveMenu('shoppingflux/manageorders/crons')
13
+ ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('Crons'), Mage::helper('profileolabs_shoppingflux')->__('Crons'));
14
+
15
+ return $this;
16
+ }
17
+
18
+
19
+ public function indexAction()
20
+ {
21
+ $this->_initAction()
22
+ ->renderLayout();
23
+
24
+ return $this;
25
+ }
26
+
27
+
28
+
29
+ public function gridAction()
30
+ {
31
+ $this->getResponse()->setBody(
32
+ $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_cron_grid')->toHtml()
33
+ );
34
+
35
+ return $this;
36
+ }
37
+
38
+ protected function _isAllowed()
39
+ {
40
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux');
41
+ }
42
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Order/ImportController.php CHANGED
@@ -1,64 +1,64 @@
1
- <?php
2
-
3
- /**
4
- * Shopping Flux
5
- * @category ShoppingFlux
6
- * @package Profileolabs_Shoppingflux_ManageOrders
7
- * @author kassim belghait
8
- */
9
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Order_ImportController extends Mage_Adminhtml_Controller_Action {
10
-
11
- protected function _initAction() {
12
- $this->loadLayout()
13
- ->_setActiveMenu('shoppingflux/manageorders/import')
14
- ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux order import'), Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux order import'));
15
-
16
- return $this;
17
- }
18
-
19
- public function indexAction() {
20
- $this->_initAction()
21
- ->renderLayout();
22
-
23
- return $this;
24
- }
25
-
26
- public function importOrdersAction() {
27
- try {
28
-
29
- error_reporting(E_ALL | E_STRICT);
30
- ini_set("display_errors", 1);
31
-
32
- /* @var $model Profileolabs_Shoppingflux_ManageOrders_Model_Order */
33
-
34
-
35
- $model = Mage::getModel('profileolabs_shoppingflux/manageorders_order')->manageOrders();
36
-
37
- $this->_getSession()->addSuccess(Mage::helper('profileolabs_shoppingflux')->__("%d orders have been imported", $model->getNbOrdersImported()));
38
-
39
- if ($model->getResultSendOrder() != "") {
40
- $this->_getSession()->addSuccess(Mage::helper('profileolabs_shoppingflux')->__("Orders sent result : %s", $model->getResultSendOrder()));
41
- }
42
- } catch (Exception $e) {
43
- $this->_getSession()->addError($e->getMessage());
44
- }
45
-
46
- $this->_redirect("*/*/index");
47
- }
48
-
49
-
50
- public function sendShipmentAction() {
51
- $orderId = $this->getRequest()->getParam('order_id');
52
- $order = Mage::getModel('sales/order')->load($orderId);
53
- if($order->getId() && $order->hasShipments()) {
54
- $shipment = $order->getShipmentsCollection()->getFirstItem();
55
- Mage::getModel('profileolabs_shoppingflux/manageorders_observer')->sendStatusShipped($shipment);
56
- }
57
- $this->_redirect('adminhtml/sales_order/view', array('order_id' => $orderId));
58
- }
59
-
60
- protected function _isAllowed()
61
- {
62
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/manageorders');
63
- }
64
  }
1
+ <?php
2
+
3
+ /**
4
+ * Shopping Flux
5
+ * @category ShoppingFlux
6
+ * @package Profileolabs_Shoppingflux_ManageOrders
7
+ * @author kassim belghait
8
+ */
9
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Order_ImportController extends Mage_Adminhtml_Controller_Action {
10
+
11
+ protected function _initAction() {
12
+ $this->loadLayout()
13
+ ->_setActiveMenu('shoppingflux/manageorders/import')
14
+ ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux order import'), Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux order import'));
15
+
16
+ return $this;
17
+ }
18
+
19
+ public function indexAction() {
20
+ $this->_initAction()
21
+ ->renderLayout();
22
+
23
+ return $this;
24
+ }
25
+
26
+ public function importOrdersAction() {
27
+ try {
28
+
29
+ error_reporting(E_ALL | E_STRICT);
30
+ ini_set("display_errors", 1);
31
+
32
+ /* @var $model Profileolabs_Shoppingflux_ManageOrders_Model_Order */
33
+
34
+
35
+ $model = Mage::getModel('profileolabs_shoppingflux/manageorders_order')->manageOrders();
36
+
37
+ $this->_getSession()->addSuccess(Mage::helper('profileolabs_shoppingflux')->__("%d orders have been imported", $model->getNbOrdersImported()));
38
+
39
+ if ($model->getResultSendOrder() != "") {
40
+ $this->_getSession()->addSuccess(Mage::helper('profileolabs_shoppingflux')->__("Orders sent result : %s", $model->getResultSendOrder()));
41
+ }
42
+ } catch (Exception $e) {
43
+ $this->_getSession()->addError($e->getMessage());
44
+ }
45
+
46
+ $this->_redirect("*/*/index");
47
+ }
48
+
49
+
50
+ public function sendShipmentAction() {
51
+ $orderId = $this->getRequest()->getParam('order_id');
52
+ $order = Mage::getModel('sales/order')->load($orderId);
53
+ if($order->getId() && $order->hasShipments()) {
54
+ $shipment = $order->getShipmentsCollection()->getFirstItem();
55
+ Mage::getModel('profileolabs_shoppingflux/manageorders_observer')->sendStatusShipped($shipment);
56
+ }
57
+ $this->_redirect('adminhtml/sales_order/view', array('order_id' => $orderId));
58
+ }
59
+
60
+ protected function _isAllowed()
61
+ {
62
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/manageorders');
63
+ }
64
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/Order/LogController.php CHANGED
@@ -1,52 +1,52 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux_ManageOrders
6
- * @author kassim belghait
7
- */
8
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Order_LogController extends Mage_Adminhtml_Controller_Action
9
- {
10
- protected function _initAction() {
11
- $this->loadLayout()
12
- ->_setActiveMenu('shoppingflux/manageorders/log')
13
- ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders log'), Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders log'));
14
-
15
- return $this;
16
- }
17
-
18
-
19
- public function indexAction()
20
- {
21
- $this->_initAction()
22
- ->renderLayout();
23
-
24
- return $this;
25
- }
26
-
27
- public function deleteAction()
28
- {
29
- $collection = Mage::getModel('profileolabs_shoppingflux/manageorders_log')->getCollection();
30
- foreach($collection as $log)
31
- $log->delete();
32
-
33
- $this->_getSession()->addSuccess(Mage::helper('profileolabs_shoppingflux')->__("Log is empty."));
34
-
35
- $this->_redirect('*/*/index');
36
-
37
- }
38
-
39
- public function gridAction()
40
- {
41
- $this->getResponse()->setBody(
42
- $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_log_grid')->toHtml()
43
- );
44
-
45
- return $this;
46
- }
47
- protected function _isAllowed()
48
- {
49
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/manageorders');
50
- }
51
-
52
  }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux_ManageOrders
6
+ * @author kassim belghait
7
+ */
8
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_Order_LogController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ protected function _initAction() {
11
+ $this->loadLayout()
12
+ ->_setActiveMenu('shoppingflux/manageorders/log')
13
+ ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders log'), Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders log'));
14
+
15
+ return $this;
16
+ }
17
+
18
+
19
+ public function indexAction()
20
+ {
21
+ $this->_initAction()
22
+ ->renderLayout();
23
+
24
+ return $this;
25
+ }
26
+
27
+ public function deleteAction()
28
+ {
29
+ $collection = Mage::getModel('profileolabs_shoppingflux/manageorders_log')->getCollection();
30
+ foreach($collection as $log)
31
+ $log->delete();
32
+
33
+ $this->_getSession()->addSuccess(Mage::helper('profileolabs_shoppingflux')->__("Log is empty."));
34
+
35
+ $this->_redirect('*/*/index');
36
+
37
+ }
38
+
39
+ public function gridAction()
40
+ {
41
+ $this->getResponse()->setBody(
42
+ $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_log_grid')->toHtml()
43
+ );
44
+
45
+ return $this;
46
+ }
47
+ protected function _isAllowed()
48
+ {
49
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/manageorders');
50
+ }
51
+
52
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Adminhtml/Shoppingfeed/OrderController.php CHANGED
@@ -1,61 +1,61 @@
1
- <?php
2
- /**
3
- * Shopping Flux
4
- * @category ShoppingFlux
5
- * @package Profileolabs_Shoppingflux_ManageOrders
6
- * @author kassim belghait
7
- */
8
- class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_OrderController extends Mage_Adminhtml_Controller_Action
9
- {
10
- protected function _initAction() {
11
- $this->loadLayout()
12
- ->_setActiveMenu('shoppingflux/manageorders/order')
13
- ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders'), Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders'));
14
-
15
- return $this;
16
- }
17
-
18
-
19
- public function indexAction()
20
- {
21
- $this->_initAction()
22
- ->renderLayout();
23
-
24
- return $this;
25
- }
26
-
27
- public function gridAction()
28
- {
29
- $this->getResponse()->setBody(
30
- $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_order_grid')->toHtml()
31
- );
32
-
33
- return $this;
34
- }
35
-
36
- /**
37
- * Export order grid to CSV format
38
- */
39
- public function exportCsvAction()
40
- {
41
- $fileName = 'orders_shoppingflux.csv';
42
- $grid = $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_order_grid');
43
- $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
44
- }
45
-
46
- /**
47
- * Export order grid to Excel XML format
48
- */
49
- public function exportExcelAction()
50
- {
51
- $fileName = 'orders_shoppingflux.xml';
52
- $grid = $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_order_grid');
53
- $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
54
- }
55
-
56
- protected function _isAllowed()
57
- {
58
- return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/manageorders');
59
- }
60
-
61
  }
1
+ <?php
2
+ /**
3
+ * Shopping Flux
4
+ * @category ShoppingFlux
5
+ * @package Profileolabs_Shoppingflux_ManageOrders
6
+ * @author kassim belghait
7
+ */
8
+ class Profileolabs_Shoppingflux_Adminhtml_Shoppingfeed_OrderController extends Mage_Adminhtml_Controller_Action
9
+ {
10
+ protected function _initAction() {
11
+ $this->loadLayout()
12
+ ->_setActiveMenu('shoppingflux/manageorders/order')
13
+ ->_addBreadcrumb(Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders'), Mage::helper('profileolabs_shoppingflux')->__('ShoppingFlux orders'));
14
+
15
+ return $this;
16
+ }
17
+
18
+
19
+ public function indexAction()
20
+ {
21
+ $this->_initAction()
22
+ ->renderLayout();
23
+
24
+ return $this;
25
+ }
26
+
27
+ public function gridAction()
28
+ {
29
+ $this->getResponse()->setBody(
30
+ $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_order_grid')->toHtml()
31
+ );
32
+
33
+ return $this;
34
+ }
35
+
36
+ /**
37
+ * Export order grid to CSV format
38
+ */
39
+ public function exportCsvAction()
40
+ {
41
+ $fileName = 'orders_shoppingflux.csv';
42
+ $grid = $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_order_grid');
43
+ $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
44
+ }
45
+
46
+ /**
47
+ * Export order grid to Excel XML format
48
+ */
49
+ public function exportExcelAction()
50
+ {
51
+ $fileName = 'orders_shoppingflux.xml';
52
+ $grid = $this->getLayout()->createBlock('profileolabs_shoppingflux/manageorders_adminhtml_order_grid');
53
+ $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
54
+ }
55
+
56
+ protected function _isAllowed()
57
+ {
58
+ return Mage::getSingleton('admin/session')->isAllowed('shoppingflux/manageorders');
59
+ }
60
+
61
  }
app/code/community/Profileolabs/Shoppingflux/controllers/Export/FluxController.php CHANGED
@@ -1,239 +1,239 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Export_FluxController extends Mage_Core_Controller_Front_Action {
4
-
5
- public function phpinfoAction() {
6
- //phpinfo();die();
7
- }
8
-
9
- public function testAction() {
10
- ini_set('display_errors', 1);
11
-
12
- die();
13
- //Mage::app()->cleanCache();
14
- $resource = Mage::getSingleton('core/resource');
15
- $readConnection = $resource->getConnection('core_read');
16
- $writeConnection = $resource->getConnection('core_write');
17
- $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
18
- /*$installer->run("
19
- ALTER TABLE `{$installer->getTable('shoppingflux_export_flux')}` ADD `product_id` int( 11 ) NOT NULL default 0 AFTER `id`;
20
- ");*/
21
- /* $installer->run("
22
- ALTER TABLE `{$installer->getTable('shoppingflux_export_flux')}` ADD INDEX ( `product_id` )
23
- ");*/
24
- //$results = $readConnection->fetchAll('SHOW COLUMNS FROM '.$installer->getTable('shoppingflux_export_flux'));
25
- // $results = $readConnection->fetchAll("SHOW INDEXES FROM shoppingflux_export_flux");
26
- $results = $readConnection->fetchAll("SELECT * FROM sales_flat_shipment_track where track_number ='CD108646420BE'");
27
- var_dump($results);
28
- //die();
29
-
30
- $track = Mage::getModel('sales/order_shipment_track')->load(8294);
31
- var_dump($track->getData(), $track->getStatus(), $track->getUrl());
32
- die();
33
-
34
-
35
- //Mage::getModel('profileolabs_shoppingflux/export_flux')->checkForDeletedProducts();
36
- //Mage::helper('profileolabs_shoppingflux')->newInstallation();
37
-
38
-
39
- $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
40
- $installer->addAttribute('catalog_product', 'shoppingflux_default_category', array(
41
- 'group' => 'General',
42
- 'type' => 'int',
43
- 'backend' => '',
44
- 'frontend_input' => '',
45
- 'frontend' => '',
46
- 'label' => 'Default Shoppingflux Category',
47
- 'input' => 'select',
48
- 'class' => '',
49
- // 'source' => 'profileolabs_shoppingflux/attribute_source_category', Optional. Needs to be added manually. To avoid having an error on uninstall if attribute is still there.
50
- 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
51
- 'visible' => false,// Optional. Needs to be added manually. To avoid having an error on uninstall if attribute is still there.
52
- 'used_in_product_listing' => true,
53
- 'frontend_class' => '',
54
- 'required' => false,
55
- 'user_defined' => true,
56
- 'default' => '',
57
- 'searchable' => false,
58
- 'filterable' => false,
59
- 'comparable' => false,
60
- 'visible_on_front' => false,
61
- 'unique' => false,
62
- 'position' => 60,
63
- ));
64
- //$sql = "delete from `".$installer->getTable('core/config_data')."` where `path` = 'shoppingflux_export/attributes_mapping/additional,'";
65
- //$sql = sprintf("UPDATE `%s` SET `path` = '%s' WHERE `path` = '%s'",$installer->getTable('core/config_data'), 'shoppingflux_export/attributes_mapping/additional', 'shoppingflux_export/attributes_additionnal/list');
66
- //$installer->run($sql);
67
- die('TESTS_END');
68
- }
69
-
70
- public function refreshAllAction() {
71
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
72
- $storeId = Mage::app()->getStore()->getId();
73
- $write->beginTransaction();
74
- try {
75
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 where store_id = '" . $storeId . "' and should_export = 1";
76
- $write->query($query);
77
- $write->commit();
78
- } catch (Exception $e) {
79
- $write->rollback();
80
- }
81
- die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
82
- }
83
-
84
- public function refreshAllAllStoresAction() {
85
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
86
- $storeId = Mage::app()->getStore()->getId();
87
- $write->beginTransaction();
88
- try {
89
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 where should_export = 1";
90
- $write->query($query);
91
- $write->commit();
92
- } catch (Exception $e) {
93
- $write->rollback();
94
- }
95
- die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
96
- }
97
-
98
- public function refreshEverythingAction() {
99
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
100
- $storeId = Mage::app()->getStore()->getId();
101
- $write->beginTransaction();
102
- try {
103
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1, should_export = 1 where store_id = '" . $storeId . "'";
104
- $write->query($query);
105
- $write->commit();
106
- } catch (Exception $e) {
107
- $write->rollback();
108
- }
109
- die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
110
- }
111
-
112
- public function refreshEverythingAllStoresAction() {
113
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
114
- $storeId = Mage::app()->getStore()->getId();
115
- $write->beginTransaction();
116
- try {
117
- $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1, should_export = 1";
118
- $write->query($query);
119
- $write->commit();
120
- } catch (Exception $e) {
121
- $write->rollback();
122
- }
123
- die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
124
- }
125
-
126
- public function statusAction() {
127
- /*if(!$this->getRequest()->getParam('bypasscheck', false)) {
128
- Mage::getModel('profileolabs_shoppingflux/export_flux')->checkForDeletedProducts();
129
- }*/
130
- ini_set('display_errors',1);
131
- error_reporting(-1);
132
-
133
- $storeId = Mage::app()->getStore()->getId();
134
- $productCollection = Mage::getModel('catalog/product')
135
- ->getCollection()
136
- ->addStoreFilter($storeId)
137
- ->setStoreId($storeId);
138
- $productCount = $productCollection->getSize();
139
-
140
-
141
- /* $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
142
- $collection->addFieldToFilter('store_id', $storeId);
143
- $feedCount = $collection->count();
144
- $feedExportCount = $feedUpdateNeededCount = 0;
145
- foreach($collection as $feedProduct) {
146
- if($feedProduct->getUpdateNeeded()) {
147
- $feedUpdateNeededCount++;
148
- }
149
- if($feedProduct->getShouldExport()) {
150
- $feedExportCount++;
151
- }
152
- }*/
153
- $_conn = Mage::getSingleton('core/resource')->getConnection('core_read');
154
- $results = $_conn->fetchAll('SELECT SUM(update_needed) as total_needed, SUM(should_export) as total_export, count(*) as total from ' . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . ' where store_id = ' . $storeId);
155
- list($feedUpdateNeededCount, $feedExportCount, $feedCount) = array_values($results[0]);
156
- $feedNotExportCount = $feedCount-$feedExportCount;
157
- if(!headers_sent()) {
158
- header('Content-type: text/xml; charset=UTF-8');
159
- }
160
- echo '<status version="'.Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version.'" m="'.ini_get('memory_limit').'">';
161
- echo "<feed_generation>";
162
- echo "<product_count>{$productCount}</product_count>";
163
- echo "<feed_count>{$feedCount}</feed_count>";
164
- echo "<feed_not_export_count>{$feedNotExportCount}</feed_not_export_count>";
165
- echo "<feed_export_count>{$feedExportCount}</feed_export_count>";
166
- echo "<feed_update_needed_count>{$feedUpdateNeededCount}</feed_update_needed_count>";
167
- echo "</feed_generation>";
168
- echo "</status>";
169
- exit();
170
- }
171
-
172
- public function indexAction() {
173
- Mage::register('export_feed_start_at', microtime(true));
174
- error_reporting(-1);
175
- ini_set('display_errors', 1);
176
- set_time_limit(0);
177
- ini_set("memory_limit", Mage::getSingleton('profileolabs_shoppingflux/config')->getMemoryLimit() . "M");
178
-
179
-
180
-
181
-
182
- $limit = $this->getRequest()->getParam('limit');
183
- $productSku = $this->getRequest()->getParam('product_sku');
184
- $forceMultiStores = $this->getRequest()->getParam('force_multi_stores', false);
185
- $forceStore = $this->getRequest()->getParam('force_store', false);
186
-
187
- if($forceStore) {
188
- $appEmulation = Mage::getSingleton('core/app_emulation');
189
- if ($appEmulation) { // not available in 1.4
190
- $appEmulation->startEnvironmentEmulation($forceStore);
191
- }
192
- }
193
-
194
- if(!headers_sent()) {
195
- header('Content-type: text/xml; charset=UTF-8');
196
- }
197
-
198
- $block = $this->getLayout()->createBlock('profileolabs_shoppingflux/export_flux', 'sf.export.flux');
199
- if ($limit) {
200
- $block->setLimit($limit);
201
- }
202
- if ($productSku) {
203
- $block->setProductSku($productSku);
204
- }
205
- if($forceMultiStores) {
206
- $block->setForceMultiStores(true);
207
- }
208
-
209
- $block->displayOutput();
210
-
211
- exit();
212
- }
213
-
214
- public function profileAction() {
215
- error_reporting(E_ALL | E_STRICT);
216
- ini_set('display_errors', 1);
217
- set_time_limit(0);
218
-
219
- $limit = $this->getRequest()->getParam('limit');
220
- $productSku = $this->getRequest()->getParam('product_sku');
221
-
222
- header('Content-type: text/html; charset=UTF-8');
223
-
224
- $block = $this->getLayout()->createBlock('profileolabs_shoppingflux/export_flux', 'sf.export.flux');
225
- if ($limit) {
226
- $block->setLimit($limit);
227
- }
228
- if ($productSku) {
229
- $block->setProductSku($productSku);
230
- }
231
- $block->toHtml();
232
- $block = $this->getLayout()->createBlock('core/profiler', 'profiler');
233
- $output = $block->toHtml();
234
-
235
- $this->getResponse()->setBody($output);
236
- return $this;
237
- }
238
-
239
- }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Export_FluxController extends Mage_Core_Controller_Front_Action {
4
+
5
+ public function phpinfoAction() {
6
+ //phpinfo();die();
7
+ }
8
+
9
+ public function testAction() {
10
+ ini_set('display_errors', 1);
11
+
12
+ die();
13
+ //Mage::app()->cleanCache();
14
+ $resource = Mage::getSingleton('core/resource');
15
+ $readConnection = $resource->getConnection('core_read');
16
+ $writeConnection = $resource->getConnection('core_write');
17
+ $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
18
+ /*$installer->run("
19
+ ALTER TABLE `{$installer->getTable('shoppingflux_export_flux')}` ADD `product_id` int( 11 ) NOT NULL default 0 AFTER `id`;
20
+ ");*/
21
+ /* $installer->run("
22
+ ALTER TABLE `{$installer->getTable('shoppingflux_export_flux')}` ADD INDEX ( `product_id` )
23
+ ");*/
24
+ //$results = $readConnection->fetchAll('SHOW COLUMNS FROM '.$installer->getTable('shoppingflux_export_flux'));
25
+ // $results = $readConnection->fetchAll("SHOW INDEXES FROM shoppingflux_export_flux");
26
+ $results = $readConnection->fetchAll("SELECT * FROM sales_flat_shipment_track where track_number ='CD108646420BE'");
27
+ var_dump($results);
28
+ //die();
29
+
30
+ $track = Mage::getModel('sales/order_shipment_track')->load(8294);
31
+ var_dump($track->getData(), $track->getStatus(), $track->getUrl());
32
+ die();
33
+
34
+
35
+ //Mage::getModel('profileolabs_shoppingflux/export_flux')->checkForDeletedProducts();
36
+ //Mage::helper('profileolabs_shoppingflux')->newInstallation();
37
+
38
+
39
+ $installer = Mage::getResourceModel('catalog/setup','profileolabs_shoppingflux_setup');
40
+ $installer->addAttribute('catalog_product', 'shoppingflux_default_category', array(
41
+ 'group' => 'General',
42
+ 'type' => 'int',
43
+ 'backend' => '',
44
+ 'frontend_input' => '',
45
+ 'frontend' => '',
46
+ 'label' => 'Default Shoppingflux Category',
47
+ 'input' => 'select',
48
+ 'class' => '',
49
+ // 'source' => 'profileolabs_shoppingflux/attribute_source_category', Optional. Needs to be added manually. To avoid having an error on uninstall if attribute is still there.
50
+ 'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
51
+ 'visible' => false,// Optional. Needs to be added manually. To avoid having an error on uninstall if attribute is still there.
52
+ 'used_in_product_listing' => true,
53
+ 'frontend_class' => '',
54
+ 'required' => false,
55
+ 'user_defined' => true,
56
+ 'default' => '',
57
+ 'searchable' => false,
58
+ 'filterable' => false,
59
+ 'comparable' => false,
60
+ 'visible_on_front' => false,
61
+ 'unique' => false,
62
+ 'position' => 60,
63
+ ));
64
+ //$sql = "delete from `".$installer->getTable('core/config_data')."` where `path` = 'shoppingflux_export/attributes_mapping/additional,'";
65
+ //$sql = sprintf("UPDATE `%s` SET `path` = '%s' WHERE `path` = '%s'",$installer->getTable('core/config_data'), 'shoppingflux_export/attributes_mapping/additional', 'shoppingflux_export/attributes_additionnal/list');
66
+ //$installer->run($sql);
67
+ die('TESTS_END');
68
+ }
69
+
70
+ public function refreshAllAction() {
71
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
72
+ $storeId = Mage::app()->getStore()->getId();
73
+ $write->beginTransaction();
74
+ try {
75
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 where store_id = '" . $storeId . "' and should_export = 1";
76
+ $write->query($query);
77
+ $write->commit();
78
+ } catch (Exception $e) {
79
+ $write->rollback();
80
+ }
81
+ die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
82
+ }
83
+
84
+ public function refreshAllAllStoresAction() {
85
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
86
+ $storeId = Mage::app()->getStore()->getId();
87
+ $write->beginTransaction();
88
+ try {
89
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1 where should_export = 1";
90
+ $write->query($query);
91
+ $write->commit();
92
+ } catch (Exception $e) {
93
+ $write->rollback();
94
+ }
95
+ die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
96
+ }
97
+
98
+ public function refreshEverythingAction() {
99
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
100
+ $storeId = Mage::app()->getStore()->getId();
101
+ $write->beginTransaction();
102
+ try {
103
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1, should_export = 1 where store_id = '" . $storeId . "'";
104
+ $write->query($query);
105
+ $write->commit();
106
+ } catch (Exception $e) {
107
+ $write->rollback();
108
+ }
109
+ die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
110
+ }
111
+
112
+ public function refreshEverythingAllStoresAction() {
113
+ $write = Mage::getSingleton('core/resource')->getConnection('core_write');
114
+ $storeId = Mage::app()->getStore()->getId();
115
+ $write->beginTransaction();
116
+ try {
117
+ $query = "update " . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . " set update_needed = 1, should_export = 1";
118
+ $write->query($query);
119
+ $write->commit();
120
+ } catch (Exception $e) {
121
+ $write->rollback();
122
+ }
123
+ die(Mage::helper('profileolabs_shoppingflux')->__('The cache of this feed has been purged'));
124
+ }
125
+
126
+ public function statusAction() {
127
+ /*if(!$this->getRequest()->getParam('bypasscheck', false)) {
128
+ Mage::getModel('profileolabs_shoppingflux/export_flux')->checkForDeletedProducts();
129
+ }*/
130
+ ini_set('display_errors',1);
131
+ error_reporting(-1);
132
+
133
+ $storeId = Mage::app()->getStore()->getId();
134
+ $productCollection = Mage::getModel('catalog/product')
135
+ ->getCollection()
136
+ ->addStoreFilter($storeId)
137
+ ->setStoreId($storeId);
138
+ $productCount = $productCollection->getSize();
139
+
140
+
141
+ /* $collection = Mage::getModel('profileolabs_shoppingflux/export_flux')->getCollection();
142
+ $collection->addFieldToFilter('store_id', $storeId);
143
+ $feedCount = $collection->count();
144
+ $feedExportCount = $feedUpdateNeededCount = 0;
145
+ foreach($collection as $feedProduct) {
146
+ if($feedProduct->getUpdateNeeded()) {
147
+ $feedUpdateNeededCount++;
148
+ }
149
+ if($feedProduct->getShouldExport()) {
150
+ $feedExportCount++;
151
+ }
152
+ }*/
153
+ $_conn = Mage::getSingleton('core/resource')->getConnection('core_read');
154
+ $results = $_conn->fetchAll('SELECT SUM(update_needed) as total_needed, SUM(should_export) as total_export, count(*) as total from ' . Mage::getSingleton('core/resource')->getTableName('profileolabs_shoppingflux/export_flux') . ' where store_id = ' . $storeId);
155
+ list($feedUpdateNeededCount, $feedExportCount, $feedCount) = array_values($results[0]);
156
+ $feedNotExportCount = $feedCount-$feedExportCount;
157
+ if(!headers_sent()) {
158
+ header('Content-type: text/xml; charset=UTF-8');
159
+ }
160
+ echo '<status version="'.Mage::getConfig()->getModuleConfig("Profileolabs_Shoppingflux")->version.'" m="'.ini_get('memory_limit').'">';
161
+ echo "<feed_generation>";
162
+ echo "<product_count>{$productCount}</product_count>";
163
+ echo "<feed_count>{$feedCount}</feed_count>";
164
+ echo "<feed_not_export_count>{$feedNotExportCount}</feed_not_export_count>";
165
+ echo "<feed_export_count>{$feedExportCount}</feed_export_count>";
166
+ echo "<feed_update_needed_count>{$feedUpdateNeededCount}</feed_update_needed_count>";
167
+ echo "</feed_generation>";
168
+ echo "</status>";
169
+ exit();
170
+ }
171
+
172
+ public function indexAction() {
173
+ Mage::register('export_feed_start_at', microtime(true));
174
+ error_reporting(-1);
175
+ ini_set('display_errors', 1);
176
+ set_time_limit(0);
177
+ ini_set("memory_limit", Mage::getSingleton('profileolabs_shoppingflux/config')->getMemoryLimit() . "M");
178
+
179
+
180
+
181
+
182
+ $limit = $this->getRequest()->getParam('limit');
183
+ $productSku = $this->getRequest()->getParam('product_sku');
184
+ $forceMultiStores = $this->getRequest()->getParam('force_multi_stores', false);
185
+ $forceStore = $this->getRequest()->getParam('force_store', false);
186
+
187
+ if($forceStore) {
188
+ $appEmulation = Mage::getSingleton('core/app_emulation');
189
+ if ($appEmulation) { // not available in 1.4
190
+ $appEmulation->startEnvironmentEmulation($forceStore);
191
+ }
192
+ }
193
+
194
+ if(!headers_sent()) {
195
+ header('Content-type: text/xml; charset=UTF-8');
196
+ }
197
+
198
+ $block = $this->getLayout()->createBlock('profileolabs_shoppingflux/export_flux', 'sf.export.flux');
199
+ if ($limit) {
200
+ $block->setLimit($limit);
201
+ }
202
+ if ($productSku) {
203
+ $block->setProductSku($productSku);
204
+ }
205
+ if($forceMultiStores) {
206
+ $block->setForceMultiStores(true);
207
+ }
208
+
209
+ $block->displayOutput();
210
+
211
+ exit();
212
+ }
213
+
214
+ public function profileAction() {
215
+ error_reporting(E_ALL | E_STRICT);
216
+ ini_set('display_errors', 1);
217
+ set_time_limit(0);
218
+
219
+ $limit = $this->getRequest()->getParam('limit');
220
+ $productSku = $this->getRequest()->getParam('product_sku');
221
+
222
+ header('Content-type: text/html; charset=UTF-8');
223
+
224
+ $block = $this->getLayout()->createBlock('profileolabs_shoppingflux/export_flux', 'sf.export.flux');
225
+ if ($limit) {
226
+ $block->setLimit($limit);
227
+ }
228
+ if ($productSku) {
229
+ $block->setProductSku($productSku);
230
+ }
231
+ $block->toHtml();
232
+ $block = $this->getLayout()->createBlock('core/profiler', 'profiler');
233
+ $output = $block->toHtml();
234
+
235
+ $this->getResponse()->setBody($output);
236
+ return $this;
237
+ }
238
+
239
+ }
app/code/community/Profileolabs/Shoppingflux/controllers/Manageorders/LaunchController.php CHANGED
@@ -1,34 +1,34 @@
1
- <?php
2
-
3
- class Profileolabs_Shoppingflux_Manageorders_LaunchController extends Mage_Core_Controller_Front_Action {
4
-
5
-
6
-
7
- public function getordersAction() {
8
- $forceStore = $this->getRequest()->getParam('force_store', false);
9
-
10
- if($forceStore) {
11
- $appEmulation = Mage::getSingleton('core/app_emulation');
12
- if ($appEmulation) { // not available in 1.4
13
- $appEmulation->startEnvironmentEmulation($forceStore);
14
- }
15
- }
16
- Mage::getModel('profileolabs_shoppingflux/manageorders_order')->manageOrders();
17
- }
18
-
19
- public function updateordersAction() {
20
- $forceStore = $this->getRequest()->getParam('force_store', false);
21
-
22
- if($forceStore) {
23
- $appEmulation = Mage::getSingleton('core/app_emulation');
24
- if ($appEmulation) { // not available in 1.4
25
- $appEmulation->startEnvironmentEmulation($forceStore);
26
- }
27
- }
28
- Mage::getModel('profileolabs_shoppingflux/manageorders_observer')->sendScheduledShipments();
29
- }
30
-
31
- public function getupdateorderscountAction() {
32
- die('Count : ' . Mage::getModel('profileolabs_shoppingflux/manageorders_export_shipments')->getCollection()->count());
33
- }
34
- }
1
+ <?php
2
+
3
+ class Profileolabs_Shoppingflux_Manageorders_LaunchController extends Mage_Core_Controller_Front_Action {
4
+
5
+
6
+
7
+ public function getordersAction() {
8
+ $forceStore = $this->getRequest()->getParam('force_store', false);
9
+
10
+ if($forceStore) {
11
+ $appEmulation = Mage::getSingleton('core/app_emulation');
12
+ if ($appEmulation) { // not available in 1.4
13
+ $appEmulation->startEnvironmentEmulation($forceStore);
14
+ }
15
+ }
16
+ Mage::getModel('profileolabs_shoppingflux/manageorders_order')->manageOrders();
17
+ }
18
+
19
+ public function updateordersAction() {
20
+ $forceStore = $this->getRequest()->getParam('force_store', false);
21
+
22
+ if($forceStore) {
23
+ $appEmulation = Mage::getSingleton('core/app_emulation');
24
+ if ($appEmulation) { // not available in 1.4
25
+ $appEmulation->startEnvironmentEmulation($forceStore);
26
+ }
27
+ }
28
+ Mage::getModel('profileolabs_shoppingflux/manageorders_observer')->sendScheduledShipments();
29
+ }
30
+
31
+ public function getupdateorderscountAction() {
32
+ die('Count : ' . Mage::getModel('profileolabs_shoppingflux/manageorders_export_shipments')->getCollection()->count());
33
+ }
34
+ }
app/code/community/Profileolabs/Shoppingflux/etc/adminhtml.xml CHANGED
@@ -1,94 +1,118 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <menu>
4
- <shoppingflux>
5
- <title>Shopping Flux</title>
6
- <sort_order>20</sort_order>
7
- <children>
8
- <manageorders translate="title" module="profileolabs_shoppingflux">
9
- <title>Orders</title>
10
- <sort_order>200</sort_order>
11
- <children>
12
- <order translate="title" module="profileolabs_shoppingflux">
13
- <title>ShoppingFlux orders</title>
14
- <action>adminhtml/shoppingfeed_order</action>
15
- <sort_order>10</sort_order>
16
- </order>
17
- <import translate="title" module="profileolabs_shoppingflux">
18
- <title>ShoppingFlux order import</title>
19
- <action>adminhtml/shoppingfeed_order_import</action>
20
- <sort_order>20</sort_order>
21
- </import>
22
- <log translate="title" module="profileolabs_shoppingflux">
23
- <title>ShoppingFlux order log</title>
24
- <action>adminhtml/shoppingfeed_order_log</action>
25
- <sort_order>30</sort_order>
26
- </log>
27
- </children>
28
- </manageorders>
29
- <export translate="title" module="profileolabs_shoppingflux">
30
- <title>Export</title>
31
- <sort_order>200</sort_order>
32
- <children>
33
- <show_flux translate="title" module="profileolabs_shoppingflux">
34
- <title>Feed List</title>
35
- <action>adminhtml/shoppingfeed_export/show</action>
36
- <sort_order>10</sort_order>
37
- </show_flux>
38
- <set_product translate="title" module="profileolabs_shoppingflux">
39
- <title>Product Selection</title>
40
- <action>adminhtml/shoppingfeed_export/update</action>
41
- <sort_order>20</sort_order>
42
- </set_product>
43
- </children>
44
- </export>
45
- <crons translate="title" module="profileolabs_shoppingflux">
46
- <title>Cron log</title>
47
- <sort_order>900</sort_order>
48
- <action>adminhtml/shoppingfeed_order_cron</action>
49
- </crons>
50
- <!--<test translate="title" module="profileolabs_shoppingflux">
51
- <title>test</title>
52
- <sort_order>900</sort_order>
53
- <action>adminhtml_shoppingfeed_general/test</action>
54
- </test>-->
55
- </children>
56
- </shoppingflux>
57
- </menu>
58
- <acl>
59
- <resources>
60
- <admin>
61
- <children>
62
- <system>
63
- <children>
64
- <config>
65
- <children>
66
- <shoppingflux translate="title" module="profileolabs_shoppingflux">
67
- <title>Shoppingflux general</title>
68
- </shoppingflux>
69
- <shoppingflux_mo translate="title" module="profileolabs_shoppingflux">
70
- <title>Shoppingflux manage orders</title>
71
- </shoppingflux_mo>
72
- <shoppingflux_export translate="title" module="profileolabs_shoppingflux">
73
- <title>Shoppingflux manage products</title>
74
- </shoppingflux_export>
75
- </children>
76
- </config>
77
- </children>
78
- </system>
79
- <shoppingflux>
80
- <title>Shopping Flux</title>
81
- <children>
82
- <manageorders translate="title" module="profileolabs_shoppingflux">
83
- <title>Orders</title>
84
- </manageorders>
85
- <export>
86
- <title>Export</title>
87
- </export>
88
- </children>
89
- </shoppingflux>
90
- </children>
91
- </admin>
92
- </resources>
93
- </acl>
94
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <menu>
4
+ <shoppingflux>
5
+ <title>Shopping Flux</title>
6
+ <sort_order>20</sort_order>
7
+ <children>
8
+ <manageorders translate="title" module="profileolabs_shoppingflux">
9
+ <title>Orders</title>
10
+ <sort_order>200</sort_order>
11
+ <children>
12
+ <order translate="title" module="profileolabs_shoppingflux">
13
+ <title>ShoppingFlux orders</title>
14
+ <action>adminhtml/shoppingfeed_order</action>
15
+ <sort_order>10</sort_order>
16
+ </order>
17
+ <import translate="title" module="profileolabs_shoppingflux">
18
+ <title>ShoppingFlux order import</title>
19
+ <action>adminhtml/shoppingfeed_order_import</action>
20
+ <sort_order>20</sort_order>
21
+ </import>
22
+ <log translate="title" module="profileolabs_shoppingflux">
23
+ <title>ShoppingFlux order log</title>
24
+ <action>adminhtml/shoppingfeed_order_log</action>
25
+ <sort_order>30</sort_order>
26
+ </log>
27
+ </children>
28
+ </manageorders>
29
+ <export translate="title" module="profileolabs_shoppingflux">
30
+ <title>Export</title>
31
+ <sort_order>200</sort_order>
32
+ <children>
33
+ <show_flux translate="title" module="profileolabs_shoppingflux">
34
+ <title>Feed List</title>
35
+ <action>adminhtml/shoppingfeed_export/show</action>
36
+ <sort_order>10</sort_order>
37
+ </show_flux>
38
+ <set_product translate="title" module="profileolabs_shoppingflux">
39
+ <title>Product Selection</title>
40
+ <action>adminhtml/shoppingfeed_export/update</action>
41
+ <sort_order>20</sort_order>
42
+ </set_product>
43
+ </children>
44
+ </export>
45
+ <crons translate="title" module="profileolabs_shoppingflux">
46
+ <title>Cron log</title>
47
+ <sort_order>900</sort_order>
48
+ <action>adminhtml/shoppingfeed_order_cron</action>
49
+ </crons>
50
+ <!--<test translate="title" module="profileolabs_shoppingflux">
51
+ <title>test</title>
52
+ <sort_order>900</sort_order>
53
+ <action>adminhtml_shoppingfeed_general/test</action>
54
+ </test>-->
55
+ </children>
56
+ </shoppingflux>
57
+ </menu>
58
+ <acl>
59
+ <resources>
60
+ <admin>
61
+ <children>
62
+ <system>
63
+ <children>
64
+ <config>
65
+ <children>
66
+ <shoppingflux translate="title" module="profileolabs_shoppingflux">
67
+ <title>Shoppingflux general</title>
68
+ </shoppingflux>
69
+ <shoppingflux_mo translate="title" module="profileolabs_shoppingflux">
70
+ <title>Shoppingflux manage orders</title>
71
+ </shoppingflux_mo>
72
+ <shoppingflux_export translate="title" module="profileolabs_shoppingflux">
73
+ <title>Shoppingflux manage products</title>
74
+ </shoppingflux_export>
75
+ </children>
76
+ </config>
77
+ </children>
78
+ </system>
79
+ <shoppingflux>
80
+ <title>Shopping Flux</title>
81
+ <children>
82
+ <manageorders translate="title" module="profileolabs_shoppingflux">
83
+ <title>Orders</title>
84
+ <children>
85
+ <order translate="title" module="profileolabs_shoppingflux">
86
+ <title>ShoppingFlux orders</title>
87
+ <sort_order>10</sort_order>
88
+ </order>
89
+ <import translate="title" module="profileolabs_shoppingflux">
90
+ <title>ShoppingFlux order import</title>
91
+ <sort_order>20</sort_order>
92
+ </import>
93
+ <log translate="title" module="profileolabs_shoppingflux">
94
+ <title>ShoppingFlux order log</title>
95
+ <sort_order>30</sort_order>
96
+ </log>
97
+ </children>
98
+ </manageorders>
99
+ <export>
100
+ <title>Export</title>
101
+ <children>
102
+ <show_flux translate="title" module="profileolabs_shoppingflux">
103
+ <title>Feed List</title>
104
+ <sort_order>10</sort_order>
105
+ </show_flux>
106
+ <set_product translate="title" module="profileolabs_shoppingflux">
107
+ <title>Product Selection</title>
108
+ <sort_order>20</sort_order>
109
+ </set_product>
110
+ </children>
111
+ </export>
112
+ </children>
113
+ </shoppingflux>
114
+ </children>
115
+ </admin>
116
+ </resources>
117
+ </acl>
118
+ </config>
app/code/community/Profileolabs/Shoppingflux/etc/config.xml CHANGED
@@ -1,521 +1,536 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <modules>
4
- <Profileolabs_Shoppingflux>
5
- <version>1.0.3</version>
6
- </Profileolabs_Shoppingflux>
7
- </modules>
8
- <admin>
9
- <routers>
10
- <adminhtml>
11
- <args>
12
- <modules>
13
- <shoppingflux after="Mage_Adminhtml">Profileolabs_Shoppingflux_Adminhtml</shoppingflux>
14
- </modules>
15
- </args>
16
- </adminhtml>
17
- </routers>
18
- </admin>
19
- <global>
20
- <fieldsets>
21
- <shoppingflux_convert_customer>
22
- <LastName>
23
- <to_customer>lastname</to_customer>
24
- <to_customer_address>lastname</to_customer_address>
25
- </LastName>
26
- <FirstName>
27
- <to_customer>firstname</to_customer>
28
- <to_customer_address>firstname</to_customer_address>
29
- </FirstName>
30
- <Email>
31
- <to_customer>email</to_customer>
32
- <to_customer_address>email</to_customer_address>
33
- </Email>
34
- <Phone>
35
- <to_customer_address>telephone</to_customer_address>
36
- </Phone>
37
- <Company>
38
- <to_customer_address>company</to_customer_address>
39
- </Company>
40
- <PostalCode>
41
- <to_customer_address>postcode</to_customer_address>
42
- </PostalCode>
43
- <Town>
44
- <to_customer_address>city</to_customer_address>
45
- </Town>
46
- <Country>
47
- <to_customer_address>country_id</to_customer_address>
48
- </Country>
49
- </shoppingflux_convert_customer>
50
- <sales_convert_order>
51
- <fees_shoppingflux>
52
- <to_invoice>*</to_invoice>
53
- <to_cm>*</to_cm>
54
- </fees_shoppingflux>
55
- </sales_convert_order>
56
- </fieldsets>
57
- <blocks>
58
- <profileolabs_shoppingflux>
59
- <class>Profileolabs_Shoppingflux_Block</class>
60
- </profileolabs_shoppingflux>
61
- </blocks>
62
- <helpers>
63
- <profileolabs_shoppingflux>
64
- <class>Profileolabs_Shoppingflux_Helper</class>
65
- </profileolabs_shoppingflux>
66
- </helpers>
67
- <models>
68
- <profileolabs_shoppingflux>
69
- <class>Profileolabs_Shoppingflux_Model</class>
70
- <resourceModel>profileolabs_shoppingflux_mysql4</resourceModel>
71
- </profileolabs_shoppingflux>
72
- <profileolabs_shoppingflux_mysql4>
73
- <class>Profileolabs_Shoppingflux_Model_Mysql4</class>
74
- <entities>
75
- <export_flux>
76
- <table>shoppingflux_export_flux</table>
77
- </export_flux>
78
- <manageorders_log>
79
- <table>shoppingflux_log</table>
80
- </manageorders_log>
81
- <export_updates>
82
- <table>shoppingflux_export_updates</table>
83
- </export_updates>
84
- <manageorders_shipping_method>
85
- <table>shoppingflux_shipping_methods</table>
86
- </manageorders_shipping_method>
87
- <manageorders_export_shipments>
88
- <table>shoppingflux_manageorders_export_shipments</table>
89
- </manageorders_export_shipments>
90
- </entities>
91
- </profileolabs_shoppingflux_mysql4>
92
- <catalog>
93
- <rewrite>
94
- <config>Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config</config>
95
- </rewrite>
96
- </catalog>
97
- <cataloginventory>
98
- <rewrite>
99
- <stock_item>Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item</stock_item>
100
- </rewrite>
101
- </cataloginventory>
102
- <sales>
103
- <rewrite>
104
- <service_quote>Profileolabs_Shoppingflux_Model_Sales_Service_Quote</service_quote>
105
- </rewrite>
106
- </sales>
107
- </models>
108
- <resources>
109
- <profileolabs_shoppingflux_setup>
110
- <setup>
111
- <module>Profileolabs_Shoppingflux</module>
112
- </setup>
113
- <connection>
114
- <use>core_setup</use>
115
- </connection>
116
- </profileolabs_shoppingflux_setup>
117
- <profileolabs_shoppingflux_write>
118
- <connection>
119
- <use>core_write</use>
120
- </connection>
121
- </profileolabs_shoppingflux_write>
122
- <profileolabs_shoppingflux_read>
123
- <connection>
124
- <use>core_read</use>
125
- </connection>
126
- </profileolabs_shoppingflux_read>
127
- </resources>
128
- <events>
129
- <cataloginventory_stock_item_save_after>
130
- <observers>
131
- <sf_update_stock>
132
- <type>singleton</type>
133
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
134
- <method>realtimeUpdateStock</method>
135
- </sf_update_stock>
136
- </observers>
137
- </cataloginventory_stock_item_save_after>
138
- <customer_group_load_after>
139
- <observers>
140
- <shoppingflux_quote_observer>
141
- <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
142
- <method>setCustomerTaxClassId</method>
143
- </shoppingflux_quote_observer>
144
- </observers>
145
- </customer_group_load_after>
146
- <sales_order_shipment_save_after>
147
- <observers>
148
- <shoppingflux_shipment_save_after>
149
- <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
150
- <method>scheduleShipmentUpdate</method>
151
- </shoppingflux_shipment_save_after>
152
- </observers>
153
- </sales_order_shipment_save_after>
154
- <order_cancel_after>
155
- <observers>
156
- <shoppingflux_order_cancel_after>
157
- <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
158
- <method>sendStatusCanceled</method>
159
- </shoppingflux_order_cancel_after>
160
- </observers>
161
- </order_cancel_after>
162
- <catalog_product_attribute_update_before>
163
- <observers>
164
- <shoppingflux_catalog_product_attribute_update_before>
165
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
166
- <method>catalogProductAttributeUpdateBefore</method>
167
- </shoppingflux_catalog_product_attribute_update_before>
168
- </observers>
169
- </catalog_product_attribute_update_before>
170
- <catalog_product_save_commit_after>
171
- <observers>
172
- <shoppingflux_catalog_product_save_commit_after>
173
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
174
- <method>catalogProductSaveCommitAfter</method>
175
- </shoppingflux_catalog_product_save_commit_after>
176
- </observers>
177
- </catalog_product_save_commit_after>
178
- <catalogrule_after_apply>
179
- <observers>
180
- <shoppingflux_catalogrule_after_apply>
181
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
182
- <method>catalogruleAfterApply</method>
183
- </shoppingflux_catalogrule_after_apply>
184
- </observers>
185
- </catalogrule_after_apply>
186
- <sales_order_place_after>
187
- <observers>
188
- <shoppingflux_sales_order_place_after>
189
- <type>singleton</type>
190
- <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
191
- <method>observeSalesOrderPlaceAfter</method>
192
- </shoppingflux_sales_order_place_after>
193
- </observers>
194
- </sales_order_place_after>
195
- </events>
196
- <template>
197
- <email>
198
- <shoppingflux_alert translate="label" module="profileolabs_shoppingflux">
199
- <label>Shoppingflux Alert</label>
200
- <file>shoppingflux/alert.html</file>
201
- <type>html</type>
202
- </shoppingflux_alert>
203
- </email>
204
- </template>
205
- <pdf>
206
- <totals>
207
- <fees_shoppingflux translate="title">
208
- <title>Commission Marketplace</title>
209
- <source_field>fees_shoppingflux</source_field>
210
- <font_size>7</font_size>
211
- <display_zero>0</display_zero>
212
- <sort_order>650</sort_order>
213
- </fees_shoppingflux>
214
- </totals>
215
- </pdf>
216
- </global>
217
- <frontend>
218
-
219
- <routers>
220
- <shoppingflux>
221
- <use>standard</use>
222
- <args>
223
- <module>Profileolabs_Shoppingflux</module>
224
- <frontName>shoppingflux</frontName>
225
- </args>
226
- </shoppingflux>
227
- </routers>
228
- <layout>
229
- <updates>
230
- <shoppingflux>
231
- <file>profileolabs_shoppingflux.xml</file>
232
- </shoppingflux>
233
- </updates>
234
- </layout>
235
- <product>
236
- <collection>
237
- <attributes>
238
- <shoppingflux_product />
239
- <shoppingflux_default_category />
240
- </attributes>
241
- </collection>
242
- </product>
243
- <translate>
244
- <modules>
245
- <Profileolabs_Shoppingflux>
246
- <files>
247
- <default>Profileolabs_Shoppingflux.csv</default>
248
- </files>
249
- </Profileolabs_Shoppingflux>
250
- </modules>
251
- </translate>
252
- </frontend>
253
- <adminhtml>
254
- <layout>
255
- <updates>
256
- <shoppingflux>
257
- <file>profileolabs_shoppingflux.xml</file>
258
- </shoppingflux>
259
- </updates>
260
- </layout>
261
- <translate>
262
- <modules>
263
- <Profileolabs_Shoppingflux>
264
- <files>
265
- <default>Profileolabs_Shoppingflux.csv</default>
266
- </files>
267
- </Profileolabs_Shoppingflux>
268
- </modules>
269
- </translate>
270
- <events>
271
- <catalog_product_delete_after_done>
272
- <observers>
273
- <sf_delete_event>
274
- <type>singleton</type>
275
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
276
- <method>realtimeUpdateDeletedProduct</method>
277
- </sf_delete_event>
278
- </observers>
279
- </catalog_product_delete_after_done>
280
- <shoppingflux_mass_publish_save_item>
281
- <observers>
282
- <sf_mass_insf_update>
283
- <type>singleton</type>
284
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
285
- <method>realtimeUpdateInSfMass</method>
286
- </sf_mass_insf_update>
287
- </observers>
288
- </shoppingflux_mass_publish_save_item>
289
- <catalog_product_save_after>
290
- <observers>
291
- <sf_price_update>
292
- <type>singleton</type>
293
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
294
- <method>realtimeUpdatePrice</method>
295
- </sf_price_update>
296
- <sf_insf_update>
297
- <type>singleton</type>
298
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
299
- <method>realtimeUpdateInSf</method>
300
- </sf_insf_update>
301
- <sf_disabled_update_save>
302
- <type>singleton</type>
303
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
304
- <method>realtimeUpdateDisabledProductSave</method>
305
- </sf_disabled_update_save>
306
- </observers>
307
- </catalog_product_save_after>
308
- <catalog_product_status_update>
309
- <observers>
310
- <sf_disabled_update>
311
- <type>singleton</type>
312
- <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
313
- <method>realtimeUpdateDisabledProduct</method>
314
- </sf_disabled_update>
315
- </observers>
316
- </catalog_product_status_update>
317
- <adminhtml_catalog_category_tabs>
318
- <observers>
319
- <sf_adminhtml_catalog_category_tabs>
320
- <type>singleton</type>
321
- <class>profileolabs_shoppingflux/export_observer</class>
322
- <method>addShoppingfluxProductsTab</method>
323
- </sf_adminhtml_catalog_category_tabs>
324
- </observers>
325
- </adminhtml_catalog_category_tabs>
326
- <catalog_category_prepare_save>
327
- <observers>
328
- <sf_catalog_category_prepare_save>
329
- <type>singleton</type>
330
- <class>profileolabs_shoppingflux/export_observer</class>
331
- <method>saveShoppingfluxCategoryProducts</method>
332
- </sf_catalog_category_prepare_save>
333
- </observers>
334
- </catalog_category_prepare_save>
335
- <adminhtml_block_html_before>
336
- <observers>
337
- <sf_adminhtml_block_html_before>
338
- <type>singleton</type>
339
- <class>profileolabs_shoppingflux/manageorders_observer</class>
340
- <method>observeAdminhtmlBlockHtmlBefore</method>
341
- </sf_adminhtml_block_html_before>
342
- </observers>
343
- </adminhtml_block_html_before>
344
- </events>
345
- </adminhtml>
346
- <crontab>
347
- <jobs>
348
- <!--<import_orders_shoppingflux>
349
- <schedule>
350
- <cron_expr>*/30 * * * *</cron_expr>
351
- </schedule>
352
- <run>
353
- <model>profileolabs_shoppingflux/manageorders_observer::manageOrders</model>
354
- </run>
355
- </import_orders_shoppingflux>-->
356
- <export_updates_shoppingflux>
357
- <schedule>
358
- <cron_expr>20 * * * *</cron_expr>
359
- </schedule>
360
- <run>
361
- <model>profileolabs_shoppingflux/export_observer::updateFlux</model>
362
- </run>
363
- </export_updates_shoppingflux>
364
- <remove_old_products>
365
- <schedule>
366
- <cron_expr>20 2 */10 * *</cron_expr>
367
- </schedule>
368
- <run>
369
- <model>profileolabs_shoppingflux/export_flux::checkForDeletedProducts</model>
370
- </run>
371
- </remove_old_products>
372
- <update_marketplaces>
373
- <schedule>
374
- <cron_expr>0 2 1 * *</cron_expr>
375
- </schedule>
376
- <run>
377
- <model>profileolabs_shoppingflux/manageorders_observer::updateMarketplaceList</model>
378
- </run>
379
- </update_marketplaces>
380
- <export_update_stock_shoppingflux>
381
- <schedule>
382
- <cron_expr>*/30 * * * *</cron_expr>
383
- </schedule>
384
- <run>
385
- <model>profileolabs_shoppingflux/export_observer::checkStock</model>
386
- </run>
387
- </export_update_stock_shoppingflux>
388
- <export_flux_in_file>
389
- <schedule>
390
- <cron_expr>0 5 * * *</cron_expr>
391
- </schedule>
392
- <run>
393
- <model>profileolabs_shoppingflux/export_observer::generateFluxInFile</model>
394
- </run>
395
- </export_flux_in_file>
396
- <!--<export_shipments_shoppingflux>
397
- <schedule>
398
- <cron_expr>*/10 * * * *</cron_expr>
399
- </schedule>
400
- <run>
401
- <model>profileolabs_shoppingflux/manageorders_observer::sendScheduledShipments</model>
402
- </run>
403
- </export_shipments_shoppingflux>-->
404
- <!--<export_updates_shoppingflux>
405
- <schedule>
406
- <cron_expr>*/5 * * * *</cron_expr>
407
- </schedule>
408
- <run>
409
- <model>profileolabs_shoppingflux/export_observer::manageUpdates</model>
410
- </run>
411
- </export_updates_shoppingflux>-->
412
- </jobs>
413
- </crontab>
414
- <default>
415
- <shoppingflux>
416
- <configuration>
417
- <is_sandbox>0</is_sandbox>
418
- <ws_uri_test>http://test.shopping-flux.com/ws/</ws_uri_test>
419
- <ws_uri_prod>http://ws.shopping-flux.com</ws_uri_prod>
420
- <!--<ws_uri_prod>https://clients.shopping-flux.com/webservice/</ws_uri_prod>-->
421
- <!--<ws_uri_prod>https://clients.shopping-flux.com/webservice/magento/</ws_uri_prod>-->
422
- <api_key></api_key>
423
- <!--<enable_buyline>0</enable_buyline>-->
424
- </configuration>
425
- </shoppingflux>
426
- <shoppingflux_mo>
427
- <manageorders>
428
- <enabled>0</enabled>
429
- <limit_orders>30</limit_orders>
430
- <new_order_status>pending</new_order_status>
431
- <create_invoice>1</create_invoice>
432
- <processing_order_status>processing</processing_order_status>
433
- <apply_tax>0</apply_tax>
434
- <use_product_id>0</use_product_id>
435
- <use_marketplace_date>1</use_marketplace_date>
436
- </manageorders>
437
- <shipment_update>
438
- <limit_hours>1</limit_hours>
439
- </shipment_update>
440
- <import_customer>
441
- <prefer_mobile_phone>1</prefer_mobile_phone>
442
- </import_customer>
443
- </shoppingflux_mo>
444
- <payment>
445
- <shoppingflux_purchaseorder>
446
- <active>0</active>
447
- <model>profileolabs_shoppingflux/manageorders_payment_method_purchaseorder</model>
448
- <order_status>new</order_status>
449
- <title>Shopping Flux Purchase Order</title>
450
- <allowspecific>0</allowspecific>
451
- </shoppingflux_purchaseorder>
452
- </payment>
453
- <carriers>
454
- <shoppingflux>
455
- <active>1</active>
456
- <sallowspecific>0</sallowspecific>
457
- <model>profileolabs_shoppingflux/manageorders_shipping_carrier_shoppingflux</model>
458
- <name>Frais de port de la place de marché</name>
459
- <title></title>
460
- </shoppingflux>
461
- </carriers>
462
- <shoppingflux_export>
463
- <general>
464
- <active>1</active>
465
- <filter_by_attribute>0</filter_by_attribute>
466
- <limit_product>100</limit_product>
467
- <default_shipping_delay>2</default_shipping_delay>
468
- <default_shipping_price></default_shipping_price>
469
- <default_shipping_method>flatrate_flatrate</default_shipping_method>
470
- <shipping_price_based_on>FR</shipping_price_based_on>
471
- <export_soldout>1</export_soldout>
472
- <export_not_salable>1</export_not_salable>
473
- <export_visibility>2,3,4</export_visibility>
474
- <enable_cron>0</enable_cron>
475
- <memory_limit>2048</memory_limit>
476
- <use_manage_stock>1</use_manage_stock>
477
- <all_store_products>0</all_store_products>
478
- <enable_events>0</enable_events>
479
- <manage_configurable>1</manage_configurable>
480
- <manage_catalog_rules>1</manage_catalog_rules>
481
- <manage_media_gallery>1</manage_media_gallery>
482
- </general>
483
- <category>
484
- <use_shoppingflux_category>0</use_shoppingflux_category>
485
- <use_only_shoppingflux_category>0</use_only_shoppingflux_category>
486
- <all_store_categories>0</all_store_categories>
487
- <max_category_level>5</max_category_level>
488
- </category>
489
- <attributes_mapping>
490
- <ean>ean</ean>
491
- <isbn>isbn</isbn>
492
- <ref_manufacturer>ref_manufacturer</ref_manufacturer>
493
- <ref_wholesaler>ref_wholesaler</ref_wholesaler>
494
- <shipping_delay>shipping_delay</shipping_delay>
495
- <shipping_send_delay>shipping_send_delay</shipping_send_delay>
496
- <brand>brand</brand>
497
- <brand_page_url>brand_page_url</brand_page_url>
498
- <ecotaxe>ecotaxe</ecotaxe>
499
- <short_name>short_name</short_name>
500
- <characteristics>characteristics</characteristics>
501
- <warranty>warranty</warranty>
502
- <kind>kind</kind>
503
- <matter>matter</matter>
504
- <size>size</size>
505
- <shoe_size>shoe_size</shoe_size>
506
- <dimension>dimension</dimension>
507
- <sku>sku</sku>
508
- <name>name</name>
509
- <description>description</description>
510
- <short_description>short_description</short_description>
511
- <meta_title>meta_title</meta_title>
512
- <meta_description>meta_description</meta_description>
513
- <meta_keyword>meta_keyword</meta_keyword>
514
- <weight>weight</weight>
515
- <color>color</color>
516
- <price>price</price>
517
- <special_price>special_price</special_price>
518
- </attributes_mapping>
519
- </shoppingflux_export>
520
- </default>
521
- </config>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Profileolabs_Shoppingflux>
5
+ <version>1.1.0</version>
6
+ </Profileolabs_Shoppingflux>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <adminhtml>
11
+ <args>
12
+ <modules>
13
+ <shoppingflux after="Mage_Adminhtml">Profileolabs_Shoppingflux_Adminhtml</shoppingflux>
14
+ </modules>
15
+ </args>
16
+ </adminhtml>
17
+ </routers>
18
+ </admin>
19
+ <global>
20
+ <fieldsets>
21
+ <shoppingflux_convert_customer>
22
+ <LastName>
23
+ <to_customer>lastname</to_customer>
24
+ <to_customer_address>lastname</to_customer_address>
25
+ </LastName>
26
+ <FirstName>
27
+ <to_customer>firstname</to_customer>
28
+ <to_customer_address>firstname</to_customer_address>
29
+ </FirstName>
30
+ <Email>
31
+ <to_customer>email</to_customer>
32
+ <to_customer_address>email</to_customer_address>
33
+ </Email>
34
+ <Phone>
35
+ <to_customer_address>telephone</to_customer_address>
36
+ </Phone>
37
+ <Company>
38
+ <to_customer_address>company</to_customer_address>
39
+ </Company>
40
+ <PostalCode>
41
+ <to_customer_address>postcode</to_customer_address>
42
+ </PostalCode>
43
+ <Town>
44
+ <to_customer_address>city</to_customer_address>
45
+ </Town>
46
+ <Country>
47
+ <to_customer_address>country_id</to_customer_address>
48
+ </Country>
49
+ </shoppingflux_convert_customer>
50
+ <sales_convert_order>
51
+ <fees_shoppingflux>
52
+ <to_invoice>*</to_invoice>
53
+ <to_cm>*</to_cm>
54
+ </fees_shoppingflux>
55
+ </sales_convert_order>
56
+ </fieldsets>
57
+ <blocks>
58
+ <profileolabs_shoppingflux>
59
+ <class>Profileolabs_Shoppingflux_Block</class>
60
+ </profileolabs_shoppingflux>
61
+ </blocks>
62
+ <helpers>
63
+ <profileolabs_shoppingflux>
64
+ <class>Profileolabs_Shoppingflux_Helper</class>
65
+ </profileolabs_shoppingflux>
66
+ </helpers>
67
+ <models>
68
+ <profileolabs_shoppingflux>
69
+ <class>Profileolabs_Shoppingflux_Model</class>
70
+ <resourceModel>profileolabs_shoppingflux_mysql4</resourceModel>
71
+ </profileolabs_shoppingflux>
72
+ <profileolabs_shoppingflux_mysql4>
73
+ <class>Profileolabs_Shoppingflux_Model_Mysql4</class>
74
+ <entities>
75
+ <export_flux>
76
+ <table>shoppingflux_export_flux</table>
77
+ </export_flux>
78
+ <manageorders_log>
79
+ <table>shoppingflux_log</table>
80
+ </manageorders_log>
81
+ <export_updates>
82
+ <table>shoppingflux_export_updates</table>
83
+ </export_updates>
84
+ <manageorders_shipping_method>
85
+ <table>shoppingflux_shipping_methods</table>
86
+ </manageorders_shipping_method>
87
+ <manageorders_export_shipments>
88
+ <table>shoppingflux_manageorders_export_shipments</table>
89
+ </manageorders_export_shipments>
90
+ <not_salable_product>
91
+ <table>shoppingflux_not_salable_product</table>
92
+ </not_salable_product>
93
+ <updated_not_salable_product>
94
+ <table>shoppingflux_updated_not_salable_product</table>
95
+ </updated_not_salable_product>
96
+ </entities>
97
+ </profileolabs_shoppingflux_mysql4>
98
+ <catalog>
99
+ <rewrite>
100
+ <config>Profileolabs_Shoppingflux_Model_Export_Rewrite_Catalog_Config</config>
101
+ </rewrite>
102
+ </catalog>
103
+ <cataloginventory>
104
+ <rewrite>
105
+ <stock_item>Profileolabs_Shoppingflux_Model_Export_Rewrite_CatalogInventory_Stock_Item</stock_item>
106
+ </rewrite>
107
+ </cataloginventory>
108
+ <sales>
109
+ <rewrite>
110
+ <service_quote>Profileolabs_Shoppingflux_Model_Sales_Service_Quote</service_quote>
111
+ </rewrite>
112
+ </sales>
113
+ </models>
114
+ <resources>
115
+ <profileolabs_shoppingflux_setup>
116
+ <setup>
117
+ <module>Profileolabs_Shoppingflux</module>
118
+ </setup>
119
+ <connection>
120
+ <use>core_setup</use>
121
+ </connection>
122
+ </profileolabs_shoppingflux_setup>
123
+ <profileolabs_shoppingflux_write>
124
+ <connection>
125
+ <use>core_write</use>
126
+ </connection>
127
+ </profileolabs_shoppingflux_write>
128
+ <profileolabs_shoppingflux_read>
129
+ <connection>
130
+ <use>core_read</use>
131
+ </connection>
132
+ </profileolabs_shoppingflux_read>
133
+ </resources>
134
+ <events>
135
+ <cataloginventory_stock_item_save_after>
136
+ <observers>
137
+ <sf_update_stock>
138
+ <type>singleton</type>
139
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
140
+ <method>realtimeUpdateStock</method>
141
+ </sf_update_stock>
142
+ </observers>
143
+ </cataloginventory_stock_item_save_after>
144
+ <customer_group_load_after>
145
+ <observers>
146
+ <shoppingflux_quote_observer>
147
+ <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
148
+ <method>setCustomerTaxClassId</method>
149
+ </shoppingflux_quote_observer>
150
+ </observers>
151
+ </customer_group_load_after>
152
+ <sales_order_shipment_save_after>
153
+ <observers>
154
+ <shoppingflux_shipment_save_after>
155
+ <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
156
+ <method>scheduleShipmentUpdate</method>
157
+ </shoppingflux_shipment_save_after>
158
+ </observers>
159
+ </sales_order_shipment_save_after>
160
+ <order_cancel_after>
161
+ <observers>
162
+ <shoppingflux_order_cancel_after>
163
+ <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
164
+ <method>sendStatusCanceled</method>
165
+ </shoppingflux_order_cancel_after>
166
+ </observers>
167
+ </order_cancel_after>
168
+ <catalog_product_attribute_update_before>
169
+ <observers>
170
+ <shoppingflux_catalog_product_attribute_update_before>
171
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
172
+ <method>catalogProductAttributeUpdateBefore</method>
173
+ </shoppingflux_catalog_product_attribute_update_before>
174
+ </observers>
175
+ </catalog_product_attribute_update_before>
176
+ <catalog_product_save_commit_after>
177
+ <observers>
178
+ <shoppingflux_catalog_product_save_commit_after>
179
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
180
+ <method>catalogProductSaveCommitAfter</method>
181
+ </shoppingflux_catalog_product_save_commit_after>
182
+ </observers>
183
+ </catalog_product_save_commit_after>
184
+ <catalogrule_after_apply>
185
+ <observers>
186
+ <shoppingflux_catalogrule_after_apply>
187
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
188
+ <method>catalogruleAfterApply</method>
189
+ </shoppingflux_catalogrule_after_apply>
190
+ </observers>
191
+ </catalogrule_after_apply>
192
+ <sales_order_place_after>
193
+ <observers>
194
+ <shoppingflux_sales_order_place_after>
195
+ <type>singleton</type>
196
+ <class>Profileolabs_Shoppingflux_Model_Manageorders_Observer</class>
197
+ <method>observeSalesOrderPlaceAfter</method>
198
+ </shoppingflux_sales_order_place_after>
199
+ </observers>
200
+ </sales_order_place_after>
201
+ </events>
202
+ <template>
203
+ <email>
204
+ <shoppingflux_alert translate="label" module="profileolabs_shoppingflux">
205
+ <label>Shoppingflux Alert</label>
206
+ <file>shoppingflux/alert.html</file>
207
+ <type>html</type>
208
+ </shoppingflux_alert>
209
+ </email>
210
+ </template>
211
+ <pdf>
212
+ <totals>
213
+ <fees_shoppingflux translate="title">
214
+ <title>Commission Marketplace</title>
215
+ <source_field>fees_shoppingflux</source_field>
216
+ <font_size>7</font_size>
217
+ <display_zero>0</display_zero>
218
+ <sort_order>650</sort_order>
219
+ </fees_shoppingflux>
220
+ </totals>
221
+ </pdf>
222
+ </global>
223
+ <frontend>
224
+
225
+ <routers>
226
+ <shoppingflux>
227
+ <use>standard</use>
228
+ <args>
229
+ <module>Profileolabs_Shoppingflux</module>
230
+ <frontName>shoppingflux</frontName>
231
+ </args>
232
+ </shoppingflux>
233
+ </routers>
234
+ <layout>
235
+ <updates>
236
+ <shoppingflux>
237
+ <file>profileolabs_shoppingflux.xml</file>
238
+ </shoppingflux>
239
+ </updates>
240
+ </layout>
241
+ <product>
242
+ <collection>
243
+ <attributes>
244
+ <shoppingflux_product />
245
+ <shoppingflux_default_category />
246
+ </attributes>
247
+ </collection>
248
+ </product>
249
+ <translate>
250
+ <modules>
251
+ <Profileolabs_Shoppingflux>
252
+ <files>
253
+ <default>Profileolabs_Shoppingflux.csv</default>
254
+ </files>
255
+ </Profileolabs_Shoppingflux>
256
+ </modules>
257
+ </translate>
258
+ </frontend>
259
+ <adminhtml>
260
+ <layout>
261
+ <updates>
262
+ <shoppingflux>
263
+ <file>profileolabs_shoppingflux.xml</file>
264
+ </shoppingflux>
265
+ </updates>
266
+ </layout>
267
+ <translate>
268
+ <modules>
269
+ <Profileolabs_Shoppingflux>
270
+ <files>
271
+ <default>Profileolabs_Shoppingflux.csv</default>
272
+ </files>
273
+ </Profileolabs_Shoppingflux>
274
+ </modules>
275
+ </translate>
276
+ <events>
277
+ <catalog_product_delete_after_done>
278
+ <observers>
279
+ <sf_delete_event>
280
+ <type>singleton</type>
281
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
282
+ <method>realtimeUpdateDeletedProduct</method>
283
+ </sf_delete_event>
284
+ </observers>
285
+ </catalog_product_delete_after_done>
286
+ <shoppingflux_mass_publish_save_item>
287
+ <observers>
288
+ <sf_mass_insf_update>
289
+ <type>singleton</type>
290
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
291
+ <method>realtimeUpdateInSfMass</method>
292
+ </sf_mass_insf_update>
293
+ </observers>
294
+ </shoppingflux_mass_publish_save_item>
295
+ <catalog_product_save_after>
296
+ <observers>
297
+ <sf_price_update>
298
+ <type>singleton</type>
299
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
300
+ <method>realtimeUpdatePrice</method>
301
+ </sf_price_update>
302
+ <sf_insf_update>
303
+ <type>singleton</type>
304
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
305
+ <method>realtimeUpdateInSf</method>
306
+ </sf_insf_update>
307
+ <sf_disabled_update_save>
308
+ <type>singleton</type>
309
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
310
+ <method>realtimeUpdateDisabledProductSave</method>
311
+ </sf_disabled_update_save>
312
+ </observers>
313
+ </catalog_product_save_after>
314
+ <catalog_product_status_update>
315
+ <observers>
316
+ <sf_disabled_update>
317
+ <type>singleton</type>
318
+ <class>Profileolabs_Shoppingflux_Model_Export_Observer</class>
319
+ <method>realtimeUpdateDisabledProduct</method>
320
+ </sf_disabled_update>
321
+ </observers>
322
+ </catalog_product_status_update>
323
+ <adminhtml_catalog_category_tabs>
324
+ <observers>
325
+ <sf_adminhtml_catalog_category_tabs>
326
+ <type>singleton</type>
327
+ <class>profileolabs_shoppingflux/export_observer</class>
328
+ <method>addShoppingfluxProductsTab</method>
329
+ </sf_adminhtml_catalog_category_tabs>
330
+ </observers>
331
+ </adminhtml_catalog_category_tabs>
332
+ <catalog_category_prepare_save>
333
+ <observers>
334
+ <sf_catalog_category_prepare_save>
335
+ <type>singleton</type>
336
+ <class>profileolabs_shoppingflux/export_observer</class>
337
+ <method>saveShoppingfluxCategoryProducts</method>
338
+ </sf_catalog_category_prepare_save>
339
+ </observers>
340
+ </catalog_category_prepare_save>
341
+ <adminhtml_block_html_before>
342
+ <observers>
343
+ <sf_adminhtml_block_html_before>
344
+ <type>singleton</type>
345
+ <class>profileolabs_shoppingflux/manageorders_observer</class>
346
+ <method>observeAdminhtmlBlockHtmlBefore</method>
347
+ </sf_adminhtml_block_html_before>
348
+ </observers>
349
+ </adminhtml_block_html_before>
350
+ </events>
351
+ </adminhtml>
352
+ <crontab>
353
+ <jobs>
354
+ <!--<import_orders_shoppingflux>
355
+ <schedule>
356
+ <cron_expr>*/30 * * * *</cron_expr>
357
+ </schedule>
358
+ <run>
359
+ <model>profileolabs_shoppingflux/manageorders_observer::manageOrders</model>
360
+ </run>
361
+ </import_orders_shoppingflux>-->
362
+ <export_updates_shoppingflux>
363
+ <schedule>
364
+ <cron_expr>20 * * * *</cron_expr>
365
+ </schedule>
366
+ <run>
367
+ <model>profileolabs_shoppingflux/export_observer::updateFlux</model>
368
+ </run>
369
+ </export_updates_shoppingflux>
370
+ <remove_old_products>
371
+ <schedule>
372
+ <cron_expr>20 2 */10 * *</cron_expr>
373
+ </schedule>
374
+ <run>
375
+ <model>profileolabs_shoppingflux/export_flux::checkForDeletedProducts</model>
376
+ </run>
377
+ </remove_old_products>
378
+ <update_marketplaces>
379
+ <schedule>
380
+ <cron_expr>0 2 1 * *</cron_expr>
381
+ </schedule>
382
+ <run>
383
+ <model>profileolabs_shoppingflux/manageorders_observer::updateMarketplaceList</model>
384
+ </run>
385
+ </update_marketplaces>
386
+ <export_update_stock_shoppingflux>
387
+ <schedule>
388
+ <cron_expr>*/30 * * * *</cron_expr>
389
+ </schedule>
390
+ <run>
391
+ <model>profileolabs_shoppingflux/export_observer::checkStock</model>
392
+ </run>
393
+ </export_update_stock_shoppingflux>
394
+ <export_flux_in_file>
395
+ <schedule>
396
+ <cron_expr>0 5 * * *</cron_expr>
397
+ </schedule>
398
+ <run>
399
+ <model>profileolabs_shoppingflux/export_observer::generateFluxInFile</model>
400
+ </run>
401
+ </export_flux_in_file>
402
+ <!--<export_shipments_shoppingflux>
403
+ <schedule>
404
+ <cron_expr>*/10 * * * *</cron_expr>
405
+ </schedule>
406
+ <run>
407
+ <model>profileolabs_shoppingflux/manageorders_observer::sendScheduledShipments</model>
408
+ </run>
409
+ </export_shipments_shoppingflux>-->
410
+ <!--<export_updates_shoppingflux>
411
+ <schedule>
412
+ <cron_expr>*/5 * * * *</cron_expr>
413
+ </schedule>
414
+ <run>
415
+ <model>profileolabs_shoppingflux/export_observer::manageUpdates</model>
416
+ </run>
417
+ </export_updates_shoppingflux>-->
418
+ <shoppingflux_refresh_not_salable_products>
419
+ <schedule>
420
+ <cron_expr>*/10 * * * *</cron_expr>
421
+ </schedule>
422
+ <run>
423
+ <model>profileolabs_shoppingflux/export_observer::refreshNotSalableProducts</model>
424
+ </run>
425
+ </shoppingflux_refresh_not_salable_products>
426
+ </jobs>
427
+ </crontab>
428
+ <default>
429
+ <shoppingflux>
430
+ <configuration>
431
+ <is_sandbox>0</is_sandbox>
432
+ <ws_uri_test>http://test.shopping-flux.com/ws/</ws_uri_test>
433
+ <ws_uri_prod>http://ws.shopping-flux.com</ws_uri_prod>
434
+ <!--<ws_uri_prod>https://clients.shopping-flux.com/webservice/</ws_uri_prod>-->
435
+ <!--<ws_uri_prod>https://clients.shopping-flux.com/webservice/magento/</ws_uri_prod>-->
436
+ <api_key></api_key>
437
+ <!--<enable_buyline>0</enable_buyline>-->
438
+ </configuration>
439
+ </shoppingflux>
440
+ <shoppingflux_mo>
441
+ <manageorders>
442
+ <enabled>1</enabled>
443
+ <limit_orders>30</limit_orders>
444
+ <new_order_status>pending</new_order_status>
445
+ <create_invoice>1</create_invoice>
446
+ <processing_order_status>processing</processing_order_status>
447
+ <apply_tax>0</apply_tax>
448
+ <use_product_id>0</use_product_id>
449
+ <use_marketplace_date>1</use_marketplace_date>
450
+ </manageorders>
451
+ <shipment_update>
452
+ <limit_hours>1</limit_hours>
453
+ </shipment_update>
454
+ <import_customer>
455
+ <prefer_mobile_phone>1</prefer_mobile_phone>
456
+ </import_customer>
457
+ </shoppingflux_mo>
458
+ <payment>
459
+ <shoppingflux_purchaseorder>
460
+ <active>0</active>
461
+ <model>profileolabs_shoppingflux/manageorders_payment_method_purchaseorder</model>
462
+ <order_status>new</order_status>
463
+ <title>Shopping Flux Purchase Order</title>
464
+ <allowspecific>0</allowspecific>
465
+ </shoppingflux_purchaseorder>
466
+ </payment>
467
+ <carriers>
468
+ <shoppingflux>
469
+ <active>1</active>
470
+ <sallowspecific>0</sallowspecific>
471
+ <model>profileolabs_shoppingflux/manageorders_shipping_carrier_shoppingflux</model>
472
+ <name>Frais de port de la place de marché</name>
473
+ <title></title>
474
+ </shoppingflux>
475
+ </carriers>
476
+ <shoppingflux_export>
477
+ <general>
478
+ <active>1</active>
479
+ <filter_by_attribute>0</filter_by_attribute>
480
+ <limit_product>100</limit_product>
481
+ <default_shipping_delay>2</default_shipping_delay>
482
+ <default_shipping_price></default_shipping_price>
483
+ <default_shipping_method>flatrate_flatrate</default_shipping_method>
484
+ <shipping_price_based_on>FR</shipping_price_based_on>
485
+ <export_soldout>1</export_soldout>
486
+ <export_not_salable>1</export_not_salable>
487
+ <export_visibility>2,3,4</export_visibility>
488
+ <export_all_images>1</export_all_images>
489
+ <enable_cron>0</enable_cron>
490
+ <memory_limit>2048</memory_limit>
491
+ <use_manage_stock>1</use_manage_stock>
492
+ <all_store_products>0</all_store_products>
493
+ <enable_events>0</enable_events>
494
+ <manage_configurable>1</manage_configurable>
495
+ <manage_catalog_rules>1</manage_catalog_rules>
496
+ <manage_media_gallery>1</manage_media_gallery>
497
+ </general>
498
+ <category>
499
+ <use_shoppingflux_category>0</use_shoppingflux_category>
500
+ <use_only_shoppingflux_category>0</use_only_shoppingflux_category>
501
+ <all_store_categories>0</all_store_categories>
502
+ <max_category_level>5</max_category_level>
503
+ </category>
504
+ <attributes_mapping>
505
+ <ean>ean</ean>
506
+ <isbn>isbn</isbn>
507
+ <ref_manufacturer>ref_manufacturer</ref_manufacturer>
508
+ <ref_wholesaler>ref_wholesaler</ref_wholesaler>
509
+ <shipping_delay>shipping_delay</shipping_delay>
510
+ <shipping_send_delay>shipping_send_delay</shipping_send_delay>
511
+ <brand>brand</brand>
512
+ <brand_page_url>brand_page_url</brand_page_url>
513
+ <ecotaxe>ecotaxe</ecotaxe>
514
+ <short_name>short_name</short_name>
515
+ <characteristics>characteristics</characteristics>
516
+ <warranty>warranty</warranty>
517
+ <kind>kind</kind>
518
+ <matter>matter</matter>
519
+ <size>size</size>
520
+ <shoe_size>shoe_size</shoe_size>
521
+ <dimension>dimension</dimension>
522
+ <sku>sku</sku>
523
+ <name>name</name>
524
+ <description>description</description>
525
+ <short_description>short_description</short_description>
526
+ <meta_title>meta_title</meta_title>
527
+ <meta_description>meta_description</meta_description>
528
+ <meta_keyword>meta_keyword</meta_keyword>
529
+ <weight>weight</weight>
530
+ <color>color</color>
531
+ <price>price</price>
532
+ <special_price>special_price</special_price>
533
+ </attributes_mapping>
534
+ </shoppingflux_export>
535
+ </default>
536
+ </config>
app/code/community/Profileolabs/Shoppingflux/etc/system.xml CHANGED
@@ -1,951 +1,1003 @@
1
- <?xml version="1.0"?>
2
- <config>
3
- <tabs>
4
- <shoppingflux translate="label" module="profileolabs_shoppingflux">
5
- <label>Shopping Flux</label>
6
- <sort_order>210</sort_order>
7
- </shoppingflux>
8
- </tabs>
9
- <sections>
10
- <shoppingflux translate="label" module="profileolabs_shoppingflux">
11
- <label>General</label>
12
- <tab>shoppingflux</tab>
13
- <frontend_type>text</frontend_type>
14
- <sort_order>10</sort_order>
15
- <show_in_default>1</show_in_default>
16
- <show_in_website>1</show_in_website>
17
- <show_in_store>1</show_in_store>
18
- <groups>
19
- <configuration translate="label" module="profileolabs_shoppingflux">
20
- <label>Configuration</label>
21
- <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
22
- <show_in_default>1</show_in_default>
23
- <show_in_website>1</show_in_website>
24
- <show_in_store>1</show_in_store>
25
- <sort_order>1</sort_order>
26
- <fields>
27
- <none>
28
- <label>--</label>
29
- <comment>Your ShoppingFlux's interface login</comment>
30
- <frontend_type>text</frontend_type>
31
- <sort_order>10</sort_order>
32
- <show_in_default>1</show_in_default>
33
- <show_in_website>0</show_in_website>
34
- <show_in_store>0</show_in_store>
35
- </none>
36
- <api_key>
37
- <label>API key</label>
38
- <frontend_type>text</frontend_type>
39
- <sort_order>20</sort_order>
40
- <show_in_default>0</show_in_default>
41
- <show_in_website>0</show_in_website>
42
- <show_in_store>1</show_in_store>
43
- </api_key>
44
- <id_tracking>
45
- <label>Tracking ID</label>
46
- <comment>Your ShoppingFlux Tracking ID</comment>
47
- <frontend_type>text</frontend_type>
48
- <sort_order>30</sort_order>
49
- <show_in_default>0</show_in_default>
50
- <show_in_website>0</show_in_website>
51
- <show_in_store>1</show_in_store>
52
- </id_tracking>
53
- <!--<enable_buyline>
54
- <label>Enable buyline ?</label>
55
- <frontend_type>select</frontend_type>
56
- <source_model>adminhtml/system_config_source_yesno</source_model>
57
- <sort_order>30</sort_order>
58
- <show_in_default>0</show_in_default>
59
- <show_in_website>0</show_in_website>
60
- <show_in_store>1</show_in_store>
61
- </enable_buyline>
62
- <alert_email>
63
- <label>Email address for alerts</label>
64
- <comment>In case of issue while transfering data, an email will be sent to this address.</comment>
65
- <frontend_type>text</frontend_type>
66
- <sort_order>100</sort_order>
67
- <show_in_default>0</show_in_default>
68
- <show_in_website>0</show_in_website>
69
- <show_in_store>1</show_in_store>
70
- </alert_email>-->
71
- </fields>
72
- </configuration>
73
- </groups>
74
- </shoppingflux>
75
- <shoppingflux_mo translate="label" module="profileolabs_shoppingflux">
76
- <label>Manage Orders</label>
77
- <tab>shoppingflux</tab>
78
- <frontend_type>text</frontend_type>
79
- <sort_order>100</sort_order>
80
- <show_in_default>0</show_in_default>
81
- <show_in_website>0</show_in_website>
82
- <show_in_store>1</show_in_store>
83
- <groups>
84
- <manageorders translate="label" module="profileolabs_shoppingflux">
85
- <label>Manage Orders</label>
86
- <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
87
- <show_in_default>0</show_in_default>
88
- <show_in_website>0</show_in_website>
89
- <show_in_store>1</show_in_store>
90
- <sort_order>1</sort_order>
91
- <fields>
92
- <enabled>
93
- <label>Enable order management</label>
94
- <frontend_type>select</frontend_type>
95
- <sort_order>10</sort_order>
96
- <show_in_default>0</show_in_default>
97
- <show_in_website>0</show_in_website>
98
- <show_in_store>1</show_in_store>
99
- <source_model>adminhtml/system_config_source_yesno</source_model>
100
- </enabled>
101
- <limit_orders>
102
- <label>Import by n orders</label>
103
- <sort_order>22</sort_order>
104
- <show_in_default>0</show_in_default>
105
- <show_in_website>0</show_in_website>
106
- <show_in_store>1</show_in_store>
107
- <comment>Limit number of orders imported. 10 by default</comment>
108
- </limit_orders>
109
- <new_order_status translate="label">
110
- <depends>
111
- <create_invoice>0</create_invoice>
112
- </depends>
113
- <label>New order status</label>
114
- <frontend_type>select</frontend_type>
115
- <source_model>adminhtml/system_config_source_order_status_new</source_model>
116
- <sort_order>80</sort_order>
117
- <show_in_default>0</show_in_default>
118
- <show_in_website>0</show_in_website>
119
- <show_in_store>1</show_in_store>
120
- </new_order_status>
121
- <create_invoice>
122
- <label>Create invoice ?</label>
123
- <comment>If yes, an invoice will be created on ShoppingFlux's order creation</comment>
124
- <frontend_type>select</frontend_type>
125
- <sort_order>25</sort_order>
126
- <show_in_default>0</show_in_default>
127
- <show_in_website>0</show_in_website>
128
- <show_in_store>1</show_in_store>
129
- <source_model>adminhtml/system_config_source_yesno</source_model>
130
- </create_invoice>
131
- <processing_order_status translate="label">
132
- <label>Invoiced order status</label>
133
- <depends>
134
- <create_invoice>1</create_invoice>
135
- </depends>
136
- <frontend_type>select</frontend_type>
137
- <source_model>adminhtml/system_config_source_order_status_processing</source_model>
138
- <sort_order>80</sort_order>
139
- <show_in_default>0</show_in_default>
140
- <show_in_website>0</show_in_website>
141
- <show_in_store>1</show_in_store>
142
- </processing_order_status>
143
- <use_product_id>
144
- <label>Use Product ID's instead of SKU ?</label>
145
- <comment>Should be no in most cases.</comment>
146
- <frontend_type>select</frontend_type>
147
- <sort_order>90</sort_order>
148
- <show_in_default>0</show_in_default>
149
- <show_in_website>0</show_in_website>
150
- <show_in_store>1</show_in_store>
151
- <source_model>adminhtml/system_config_source_yesno</source_model>
152
- </use_product_id>
153
- <use_marketplace_date>
154
- <label>Use Marketplace Order Date and Time ?</label>
155
- <comment>If no, the order date will be the import date.</comment>
156
- <frontend_type>select</frontend_type>
157
- <sort_order>100</sort_order>
158
- <show_in_default>0</show_in_default>
159
- <show_in_website>0</show_in_website>
160
- <show_in_store>1</show_in_store>
161
- <source_model>adminhtml/system_config_source_yesno</source_model>
162
- </use_marketplace_date>
163
- </fields>
164
- </manageorders>
165
- <import_customer translate="label" module="profileolabs_shoppingflux">
166
- <label>Customer Import</label>
167
- <frontend_model>profileolabs_shoppingflux/manageorders_adminhtml_system_config_form_fieldset_customer_group</frontend_model>
168
- <show_in_default>0</show_in_default>
169
- <show_in_website>0</show_in_website>
170
- <show_in_store>1</show_in_store>
171
- <sort_order>2</sort_order>
172
- <fields>
173
- <limit_address_length>
174
- <label>Limit addresses length</label>
175
- <comment>Leave empty to not limit length. Minimum value if filled : 20</comment>
176
- <frontend_type>text</frontend_type>
177
- <sort_order>5</sort_order>
178
- <show_in_default>0</show_in_default>
179
- <show_in_website>0</show_in_website>
180
- <show_in_store>1</show_in_store>
181
- </limit_address_length>
182
- <mobile_attribute>
183
- <label>Customer Mobile Attribute</label>
184
- <frontend_type>select</frontend_type>
185
- <sort_order>6</sort_order>
186
- <show_in_default>0</show_in_default>
187
- <show_in_website>0</show_in_website>
188
- <show_in_store>1</show_in_store>
189
- <source_model>profileolabs_shoppingflux/manageorders_source_attributes</source_model>
190
- </mobile_attribute>
191
- <prefer_mobile_phone>
192
- <depends>
193
- <mobile_attribute></mobile_attribute>
194
- </depends>
195
- <label>Import mobile phone instead of desk phone, if available</label>
196
- <frontend_type>select</frontend_type>
197
- <sort_order>7</sort_order>
198
- <show_in_default>0</show_in_default>
199
- <show_in_website>0</show_in_website>
200
- <show_in_store>1</show_in_store>
201
- <source_model>adminhtml/system_config_source_yesno</source_model>
202
- </prefer_mobile_phone>
203
- <default_group>
204
- <label>Default customer group</label>
205
- <frontend_type>select</frontend_type>
206
- <sort_order>10</sort_order>
207
- <show_in_default>0</show_in_default>
208
- <show_in_website>0</show_in_website>
209
- <show_in_store>1</show_in_store>
210
- <source_model>adminhtml/system_config_source_customer_group</source_model>
211
- </default_group>
212
- </fields>
213
- </import_customer>
214
- <shipping_method translate="label" module="profileolabs_shoppingflux">
215
- <label>Shipping Method</label>
216
- <frontend_model>profileolabs_shoppingflux/manageorders_adminhtml_system_config_form_fieldset_shipping_method</frontend_model>
217
- <show_in_default>0</show_in_default>
218
- <show_in_website>0</show_in_website>
219
- <show_in_store>1</show_in_store>
220
- <sort_order>3</sort_order>
221
- <fields>
222
- <default_method>
223
- <label>Default shipping method</label>
224
- <comment>Specific shipping method to use for imported ShoppingFlux's order</comment>
225
- <frontend_type>select</frontend_type>
226
- <sort_order>10</sort_order>
227
- <show_in_default>0</show_in_default>
228
- <show_in_website>0</show_in_website>
229
- <show_in_store>1</show_in_store>
230
- <source_model>adminhtml/system_config_source_shipping_allmethods</source_model>
231
- </default_method>
232
-
233
- </fields>
234
- </shipping_method>
235
- <advanced_shipping_method translate="label" module="profileolabs_shoppingflux">
236
- <label>Advanced Shipping Methods Mapping</label>
237
- <frontend_model>profileolabs_shoppingflux/manageorders_adminhtml_system_config_form_fieldset_shipping_method_extra</frontend_model>
238
- <show_in_default>0</show_in_default>
239
- <show_in_website>0</show_in_website>
240
- <show_in_store>1</show_in_store>
241
- <sort_order>4</sort_order>
242
- </advanced_shipping_method>
243
- <shipment_update translate="label" module="profileolabs_shoppingflux">
244
- <label>Shipment Update</label>
245
- <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
246
- <show_in_default>0</show_in_default>
247
- <show_in_website>0</show_in_website>
248
- <show_in_store>1</show_in_store>
249
- <sort_order>5</sort_order>
250
- <fields>
251
- <limit_hours>
252
- <label>Max time before sending shipment update to marketplace</label>
253
- <!-- Menu déroulant Immédiat et de 1 à 10 -->
254
- <comment>In hours. If the shipment has still not any tracking number filled after X hours, the shipment is sent to the marketplace without tracking number.</comment>
255
- <frontend_type>select</frontend_type>
256
- <source_model>profileolabs_shoppingflux/export_source_tracking_delay</source_model>
257
- <sort_order>10</sort_order>
258
- <show_in_default>0</show_in_default>
259
- <show_in_website>0</show_in_website>
260
- <show_in_store>1</show_in_store>
261
- </limit_hours>
262
- </fields>
263
- </shipment_update>
264
- </groups>
265
- </shoppingflux_mo>
266
- <shoppingflux_export translate="label" module="profileolabs_shoppingflux">
267
- <label>Manage Products</label>
268
- <tab>shoppingflux</tab>
269
- <frontend_type>text</frontend_type>
270
- <sort_order>90</sort_order>
271
- <show_in_default>0</show_in_default>
272
- <show_in_website>0</show_in_website>
273
- <show_in_store>1</show_in_store>
274
- <groups>
275
- <general translate="label">
276
- <label>General</label>
277
- <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
278
- <comment><![CDATA[<b style='color:red'>Feed URL :</b>&nbsp;&nbsp;<span style='font-size:14px;font-style:italic;'>http://domain.tld/shoppingflux/export_flux/</span><br /><br /><br />]]></comment>
279
- <show_in_default>0</show_in_default>
280
- <show_in_website>0</show_in_website>
281
- <show_in_store>1</show_in_store>
282
- <sort_order>1</sort_order>
283
- <fields>
284
- <active>
285
- <label>Enable product export ?</label>
286
- <comment></comment>
287
- <frontend_type>select</frontend_type>
288
- <sort_order>1</sort_order>
289
- <show_in_default>0</show_in_default>
290
- <show_in_website>0</show_in_website>
291
- <show_in_store>1</show_in_store>
292
- <source_model>adminhtml/system_config_source_yesno</source_model>
293
- </active>
294
- <filter_by_attribute>
295
- <label>Export selected products only ?</label>
296
- <comment><![CDATA[If yes, you'll have to select products in <strong>Shoppingflux > Product Selection</strong>]]></comment>
297
- <frontend_type>select</frontend_type>
298
- <sort_order>5</sort_order>
299
- <show_in_default>0</show_in_default>
300
- <show_in_website>0</show_in_website>
301
- <show_in_store>1</show_in_store>
302
- <source_model>adminhtml/system_config_source_yesno</source_model>
303
- </filter_by_attribute>
304
- <!-- <limit_product>
305
- <label>Export par n produits</label>
306
- <comment></comment>
307
- <sort_order>10</sort_order>
308
- <show_in_default>0</show_in_default>
309
- <show_in_website>0</show_in_website>
310
- <show_in_store>1</show_in_store>
311
- <comment>Limite le nombre de produit par lots</comment>
312
- </limit_product> -->
313
- <default_shipping_delay>
314
- <label>Shipping delay</label>
315
- <comment><![CDATA[Shipping delay, in <strong>days</strong>. This will be used if no shipping delay attribute is mapped.]]></comment>
316
- <frontend_type>text</frontend_type>
317
- <sort_order>20</sort_order>
318
- <show_in_default>0</show_in_default>
319
- <show_in_website>0</show_in_website>
320
- <show_in_store>1</show_in_store>
321
- </default_shipping_delay>
322
- <default_shipping_price>
323
- <label>Shipping fees</label>
324
- <comment>Default shipping fees amount</comment>
325
- <frontend_type>text</frontend_type>
326
- <sort_order>40</sort_order>
327
- <show_in_default>0</show_in_default>
328
- <show_in_website>0</show_in_website>
329
- <show_in_store>1</show_in_store>
330
- </default_shipping_price>
331
- <default_shipping_method>
332
- <label>Shipping Method</label>
333
- <comment>Default shipping method to calculate shipping fees</comment>
334
- <frontend_type>select</frontend_type>
335
- <source_model>adminhtml/system_config_source_shipping_allmethods</source_model>
336
- <sort_order>30</sort_order>
337
- <show_in_default>0</show_in_default>
338
- <show_in_website>0</show_in_website>
339
- <show_in_store>1</show_in_store>
340
- </default_shipping_method>
341
- <try_use_real_shipping_price>
342
- <label>Try to get real shipping fees for each product ?</label>
343
- <comment>Disable this option if you have memory issues.</comment>
344
- <frontend_type>select</frontend_type>
345
- <sort_order>40</sort_order>
346
- <show_in_default>0</show_in_default>
347
- <show_in_website>0</show_in_website>
348
- <show_in_store>1</show_in_store>
349
- <source_model>adminhtml/system_config_source_yesno</source_model>
350
- </try_use_real_shipping_price>
351
- <export_soldout>
352
- <label>Export out of stock products</label>
353
- <comment></comment>
354
- <frontend_type>select</frontend_type>
355
- <sort_order>50</sort_order>
356
- <show_in_default>0</show_in_default>
357
- <show_in_website>0</show_in_website>
358
- <show_in_store>1</show_in_store>
359
- <source_model>adminhtml/system_config_source_yesno</source_model>
360
- </export_soldout>
361
- <export_not_salable>
362
- <label>Export not salable products</label>
363
- <comment></comment>
364
- <frontend_type>select</frontend_type>
365
- <sort_order>55</sort_order>
366
- <show_in_default>0</show_in_default>
367
- <show_in_website>0</show_in_website>
368
- <show_in_store>1</show_in_store>
369
- <source_model>adminhtml/system_config_source_yesno</source_model>
370
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
371
- </export_not_salable>
372
- <show_advanced_configuration>
373
- <label>Show advanced configuration ?</label>
374
- <frontend_type>select</frontend_type>
375
- <source_model>adminhtml/system_config_source_yesno</source_model>
376
- <sort_order>57</sort_order>
377
- <show_in_default>0</show_in_default>
378
- <show_in_website>0</show_in_website>
379
- <show_in_store>1</show_in_store>
380
- </show_advanced_configuration>
381
- <shipping_price_based_on>
382
- <depends>
383
- <show_advanced_configuration>1</show_advanced_configuration>
384
- </depends>
385
- <label>Shipping Country</label>
386
- <comment>Default country used to calculate shipping fees</comment>
387
- <frontend_type>select</frontend_type>
388
- <source_model>adminhtml/system_config_source_country</source_model>
389
- <sort_order>60</sort_order>
390
- <show_in_default>0</show_in_default>
391
- <show_in_website>0</show_in_website>
392
- <show_in_store>1</show_in_store>
393
- </shipping_price_based_on>
394
- <export_visibility>
395
- <depends>
396
- <show_advanced_configuration>1</show_advanced_configuration>
397
- </depends>
398
- <label>Export product with visibility :</label>
399
- <comment></comment>
400
- <frontend_type>multiselect</frontend_type>
401
- <sort_order>70</sort_order>
402
- <show_in_default>0</show_in_default>
403
- <show_in_website>0</show_in_website>
404
- <show_in_store>1</show_in_store>
405
- <source_model>profileolabs_shoppingflux/export_source_visibility</source_model>
406
- </export_visibility>
407
- <memory_limit>
408
- <depends>
409
- <show_advanced_configuration>1</show_advanced_configuration>
410
- </depends>
411
- <label>Memory limit</label>
412
- <comment>in MB. Do not modify if you don't know what you are doing.</comment>
413
- <frontend_type>text</frontend_type>
414
- <sort_order>100</sort_order>
415
- <show_in_default>0</show_in_default>
416
- <show_in_website>0</show_in_website>
417
- <show_in_store>1</show_in_store>
418
- </memory_limit>
419
- <execution_time_limit>
420
- <depends>
421
- <show_advanced_configuration>1</show_advanced_configuration>
422
- </depends>
423
- <label>Execution time limit</label>
424
- <comment>in seconds. Do not modify if you don't know what you are doing.</comment>
425
- <frontend_type>text</frontend_type>
426
- <sort_order>110</sort_order>
427
- <show_in_default>0</show_in_default>
428
- <show_in_website>0</show_in_website>
429
- <show_in_store>1</show_in_store>
430
- </execution_time_limit>
431
- <enable_sync>
432
- <depends>
433
- <show_advanced_configuration>1</show_advanced_configuration>
434
- </depends>
435
- <label>Enable automatic updates ?</label>
436
- <comment>Update stocks and prices in real time. This could slow down price and stock modifications.</comment>
437
- <frontend_type>select</frontend_type>
438
- <sort_order>120</sort_order>
439
- <show_in_default>0</show_in_default>
440
- <show_in_website>0</show_in_website>
441
- <show_in_store>1</show_in_store>
442
- <source_model>adminhtml/system_config_source_yesno</source_model>
443
- </enable_sync>
444
- <enable_cron>
445
- <depends>
446
- <show_advanced_configuration>1</show_advanced_configuration>
447
- </depends>
448
- <label>Enable background generation ?</label>
449
- <comment>Update feed on background if needed.</comment>
450
- <frontend_type>select</frontend_type>
451
- <sort_order>125</sort_order>
452
- <show_in_default>0</show_in_default>
453
- <show_in_website>0</show_in_website>
454
- <show_in_store>1</show_in_store>
455
- <source_model>adminhtml/system_config_source_yesno</source_model>
456
- </enable_cron>
457
- <use_manage_stock>
458
- <depends>
459
- <show_advanced_configuration>1</show_advanced_configuration>
460
- </depends>
461
- <label>Manage 'Manage stock' attribute ?</label>
462
- <comment>If yes, products with 'Manage stock' = 'No' will have a stock qty to 100 in the feed.</comment>
463
- <frontend_type>select</frontend_type>
464
- <sort_order>130</sort_order>
465
- <show_in_default>0</show_in_default>
466
- <show_in_website>0</show_in_website>
467
- <show_in_store>1</show_in_store>
468
- <source_model>adminhtml/system_config_source_yesno</source_model>
469
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
470
- </use_manage_stock>
471
- <all_store_products>
472
- <depends>
473
- <show_advanced_configuration>1</show_advanced_configuration>
474
- </depends>
475
- <label>Export products from all stores ?</label>
476
- <comment>If any doubt exists, leave it to 'No'</comment>
477
- <frontend_type>select</frontend_type>
478
- <sort_order>135</sort_order>
479
- <show_in_default>0</show_in_default>
480
- <show_in_website>0</show_in_website>
481
- <show_in_store>1</show_in_store>
482
- <source_model>adminhtml/system_config_source_yesno</source_model>
483
- </all_store_products>
484
-
485
- <enable_events>
486
- <depends>
487
- <show_advanced_configuration>1</show_advanced_configuration>
488
- </depends>
489
- <label>Enable ShoppingFlux events ?</label>
490
- <comment>Usefull only in case of specific developments.</comment>
491
- <frontend_type>select</frontend_type>
492
- <sort_order>160</sort_order>
493
- <show_in_default>0</show_in_default>
494
- <show_in_website>0</show_in_website>
495
- <show_in_store>1</show_in_store>
496
- <source_model>adminhtml/system_config_source_yesno</source_model>
497
- </enable_events>
498
- <manage_configurable>
499
- <depends>
500
- <show_advanced_configuration>1</show_advanced_configuration>
501
- </depends>
502
- <label>Advanced management of configurable products ?</label>
503
- <comment>If no, only configurable products will be transfered (without their children). In most cases, should be set to 'Yes'.</comment>
504
- <frontend_type>select</frontend_type>
505
- <sort_order>170</sort_order>
506
- <show_in_default>0</show_in_default>
507
- <show_in_website>0</show_in_website>
508
- <show_in_store>1</show_in_store>
509
- <source_model>adminhtml/system_config_source_yesno</source_model>
510
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
511
- </manage_configurable>
512
- <manage_catalog_rules>
513
- <depends>
514
- <show_advanced_configuration>1</show_advanced_configuration>
515
- </depends>
516
- <label>Manage catalog price rules ?</label>
517
- <frontend_type>select</frontend_type>
518
- <sort_order>180</sort_order>
519
- <show_in_default>0</show_in_default>
520
- <show_in_website>0</show_in_website>
521
- <show_in_store>1</show_in_store>
522
- <source_model>adminhtml/system_config_source_yesno</source_model>
523
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
524
- </manage_catalog_rules>
525
- <manage_media_gallery>
526
- <depends>
527
- <show_advanced_configuration>1</show_advanced_configuration>
528
- </depends>
529
- <label>Manage product galleries ?</label>
530
- <comment>Does not concern main image. Faster if 'No'.</comment>
531
- <frontend_type>select</frontend_type>
532
- <sort_order>190</sort_order>
533
- <show_in_default>0</show_in_default>
534
- <show_in_website>0</show_in_website>
535
- <show_in_store>1</show_in_store>
536
- <source_model>adminhtml/system_config_source_yesno</source_model>
537
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
538
- </manage_media_gallery>
539
- <transform_qty_increments>
540
- <depends>
541
- <show_advanced_configuration>1</show_advanced_configuration>
542
- </depends>
543
- <label>Transform qty increments products ?</label>
544
- <frontend_type>select</frontend_type>
545
- <sort_order>200</sort_order>
546
- <show_in_default>0</show_in_default>
547
- <show_in_website>0</show_in_website>
548
- <show_in_store>1</show_in_store>
549
- <source_model>adminhtml/system_config_source_yesno</source_model>
550
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
551
- </transform_qty_increments>
552
- </fields>
553
- </general>
554
- <category>
555
- <label>Categories</label>
556
- <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
557
- <show_in_default>0</show_in_default>
558
- <show_in_website>0</show_in_website>
559
- <show_in_store>1</show_in_store>
560
- <sort_order>15</sort_order>
561
- <fields>
562
- <use_shoppingflux_category>
563
- <label>Use ShoppingFlux category attribute ?</label>
564
- <comment>Warning : Be sure that this field is set to no before uninstalling the extension.</comment>
565
- <frontend_type>select</frontend_type>
566
- <sort_order>10</sort_order>
567
- <show_in_default>0</show_in_default>
568
- <show_in_website>0</show_in_website>
569
- <show_in_store>1</show_in_store>
570
- <source_model>adminhtml/system_config_source_yesno</source_model>
571
- <backend_model>profileolabs_shoppingflux/system_config_backend_category</backend_model>
572
- </use_shoppingflux_category>
573
-
574
- <use_only_shoppingflux_category>
575
- <depends>
576
- <use_shoppingflux_category>1</use_shoppingflux_category>
577
- </depends>
578
- <label>Use only ShoppingFlux category ?</label>
579
- <comment>Faster if yes.</comment>
580
- <frontend_type>select</frontend_type>
581
- <sort_order>20</sort_order>
582
- <show_in_default>0</show_in_default>
583
- <show_in_website>0</show_in_website>
584
- <show_in_store>1</show_in_store>
585
- <source_model>adminhtml/system_config_source_yesno</source_model>
586
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
587
- </use_only_shoppingflux_category>
588
-
589
-
590
- <all_store_categories>
591
- <depends>
592
- <use_shoppingflux_category>1</use_shoppingflux_category>
593
- </depends>
594
- <label>Use categories from all stores ?</label>
595
- <comment>If any doubt exists, leave it to 'No'</comment>
596
- <frontend_type>select</frontend_type>
597
- <sort_order>30</sort_order>
598
- <show_in_default>0</show_in_default>
599
- <show_in_website>0</show_in_website>
600
- <show_in_store>1</show_in_store>
601
- <source_model>adminhtml/system_config_source_yesno</source_model>
602
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
603
- </all_store_categories>
604
-
605
- <max_category_level>
606
- <depends>
607
- <use_shoppingflux_category>1</use_shoppingflux_category>
608
- </depends>
609
- <label>Use only X first category levels</label>
610
- <frontend_type>select</frontend_type>
611
- <sort_order>40</sort_order>
612
- <show_in_default>0</show_in_default>
613
- <show_in_website>0</show_in_website>
614
- <show_in_store>1</show_in_store>
615
- <source_model>profileolabs_shoppingflux/export_source_category_level</source_model>
616
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
617
- </max_category_level>
618
-
619
- </fields>
620
- </category>
621
- <attributes_mapping translate="label">
622
- <label>Attribute mapping</label>
623
- <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
624
- <show_in_default>0</show_in_default>
625
- <show_in_website>0</show_in_website>
626
- <show_in_store>1</show_in_store>
627
- <sort_order>20</sort_order>
628
- <fields>
629
- <ean>
630
- <label>EAN</label>
631
- <comment></comment>
632
- <frontend_type>select</frontend_type>
633
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
634
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
635
- <sort_order>10</sort_order>
636
- <show_in_default>0</show_in_default>
637
- <show_in_website>0</show_in_website>
638
- <show_in_store>1</show_in_store>
639
- </ean>
640
- <isbn>
641
- <label>ISBN</label>
642
- <comment></comment>
643
- <frontend_type>select</frontend_type>
644
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
645
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
646
- <sort_order>20</sort_order>
647
- <show_in_default>0</show_in_default>
648
- <show_in_website>0</show_in_website>
649
- <show_in_store>1</show_in_store>
650
- </isbn>
651
- <ref_manufacturer>
652
- <label>Manufacturer's reference</label>
653
- <comment></comment>
654
- <frontend_type>select</frontend_type>
655
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
656
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
657
- <sort_order>30</sort_order>
658
- <show_in_default>0</show_in_default>
659
- <show_in_website>0</show_in_website>
660
- <show_in_store>1</show_in_store>
661
- </ref_manufacturer>
662
- <ref_wholesaler>
663
- <label>Supplier's reference</label>
664
- <comment></comment>
665
- <frontend_type>select</frontend_type>
666
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
667
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
668
- <sort_order>40</sort_order>
669
- <show_in_default>0</show_in_default>
670
- <show_in_website>0</show_in_website>
671
- <show_in_store>1</show_in_store>
672
- </ref_wholesaler>
673
- <shipping_delay>
674
- <label>Shipping delay</label>
675
- <comment></comment>
676
- <frontend_type>select</frontend_type>
677
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
678
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
679
- <sort_order>42</sort_order>
680
- <show_in_default>0</show_in_default>
681
- <show_in_website>0</show_in_website>
682
- <show_in_store>1</show_in_store>
683
- </shipping_delay>
684
- <shipping_send_delay>
685
- <label>Expedition delay</label>
686
- <comment></comment>
687
- <frontend_type>select</frontend_type>
688
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
689
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
690
- <sort_order>43</sort_order>
691
- <show_in_default>0</show_in_default>
692
- <show_in_website>0</show_in_website>
693
- <show_in_store>1</show_in_store>
694
- </shipping_send_delay>
695
- <brand>
696
- <label>Brand</label>
697
- <comment></comment>
698
- <frontend_type>select</frontend_type>
699
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
700
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
701
- <sort_order>50</sort_order>
702
- <show_in_default>0</show_in_default>
703
- <show_in_website>0</show_in_website>
704
- <show_in_store>1</show_in_store>
705
- </brand>
706
- <brand_page_url>
707
- <label>Brand page's URL</label>
708
- <comment></comment>
709
- <frontend_type>select</frontend_type>
710
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
711
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
712
- <sort_order>55</sort_order>
713
- <show_in_default>0</show_in_default>
714
- <show_in_website>0</show_in_website>
715
- <show_in_store>1</show_in_store>
716
- </brand_page_url>
717
- <ecotaxe>
718
- <label>Ecotax</label>
719
- <frontend_type>select</frontend_type>
720
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
721
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
722
- <sort_order>60</sort_order>
723
- <show_in_default>0</show_in_default>
724
- <show_in_website>0</show_in_website>
725
- <show_in_store>1</show_in_store>
726
- </ecotaxe>
727
- <short_name>
728
- <label>Product short name</label>
729
- <comment></comment>
730
- <frontend_type>select</frontend_type>
731
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
732
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
733
- <sort_order>70</sort_order>
734
- <show_in_default>0</show_in_default>
735
- <show_in_website>0</show_in_website>
736
- <show_in_store>1</show_in_store>
737
- </short_name>
738
- <characteristics>
739
- <label>Characteristics</label>
740
- <comment></comment>
741
- <frontend_type>select</frontend_type>
742
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
743
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
744
- <sort_order>80</sort_order>
745
- <show_in_default>0</show_in_default>
746
- <show_in_website>0</show_in_website>
747
- <show_in_store>1</show_in_store>
748
- </characteristics>
749
- <warranty>
750
- <label>Warranty</label>
751
- <comment></comment>
752
- <frontend_type>select</frontend_type>
753
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
754
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
755
- <sort_order>90</sort_order>
756
- <show_in_default>0</show_in_default>
757
- <show_in_website>0</show_in_website>
758
- <show_in_store>1</show_in_store>
759
- </warranty>
760
- <kind>
761
- <label>Gender</label>
762
- <comment></comment>
763
- <frontend_type>select</frontend_type>
764
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
765
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
766
- <sort_order>100</sort_order>
767
- <show_in_default>0</show_in_default>
768
- <show_in_website>0</show_in_website>
769
- <show_in_store>1</show_in_store>
770
- </kind>
771
- <matter>
772
- <label>Material</label>
773
- <comment></comment>
774
- <frontend_type>select</frontend_type>
775
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
776
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
777
- <sort_order>100</sort_order>
778
- <show_in_default>0</show_in_default>
779
- <show_in_website>0</show_in_website>
780
- <show_in_store>1</show_in_store>
781
- </matter>
782
- <size>
783
- <label>Size</label>
784
- <comment></comment>
785
- <frontend_type>select</frontend_type>
786
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
787
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
788
- <sort_order>110</sort_order>
789
- <show_in_default>0</show_in_default>
790
- <show_in_website>0</show_in_website>
791
- <show_in_store>1</show_in_store>
792
- </size>
793
- <shoe_size>
794
- <label>Shoe size</label>
795
- <comment></comment>
796
- <frontend_type>select</frontend_type>
797
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
798
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
799
- <sort_order>115</sort_order>
800
- <show_in_default>0</show_in_default>
801
- <show_in_website>0</show_in_website>
802
- <show_in_store>1</show_in_store>
803
- </shoe_size>
804
- <dimension>
805
- <label>Dimension</label>
806
- <comment></comment>
807
- <frontend_type>select</frontend_type>
808
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
809
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
810
- <sort_order>120</sort_order>
811
- <show_in_default>0</show_in_default>
812
- <show_in_website>0</show_in_website>
813
- <show_in_store>1</show_in_store>
814
- </dimension>
815
- <sku>
816
- <label>Product SKU</label>
817
- <comment>By default, you need to keep the 'sku' attribute. This value will be used as unique identifier for your products on ShoppingFeed and Marketplaces. Do not change unless shopping feed told you to.</comment>
818
- <frontend_type>select</frontend_type>
819
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
820
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
821
- <sort_order>0</sort_order>
822
- <show_in_default>0</show_in_default>
823
- <show_in_website>0</show_in_website>
824
- <show_in_store>1</show_in_store>
825
- </sku>
826
- <name>
827
- <label>Product name</label>
828
- <comment></comment>
829
- <frontend_type>select</frontend_type>
830
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
831
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
832
- <sort_order>10</sort_order>
833
- <show_in_default>0</show_in_default>
834
- <show_in_website>0</show_in_website>
835
- <show_in_store>1</show_in_store>
836
- </name>
837
- <description>
838
- <label>Product description</label>
839
- <comment></comment>
840
- <frontend_type>select</frontend_type>
841
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
842
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
843
- <sort_order>20</sort_order>
844
- <show_in_default>0</show_in_default>
845
- <show_in_website>0</show_in_website>
846
- <show_in_store>1</show_in_store>
847
- </description>
848
- <short_description>
849
- <label>Product short description</label>
850
- <comment></comment>
851
- <frontend_type>select</frontend_type>
852
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
853
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
854
- <sort_order>30</sort_order>
855
- <show_in_default>0</show_in_default>
856
- <show_in_website>0</show_in_website>
857
- <show_in_store>1</show_in_store>
858
- </short_description>
859
- <meta_title>
860
- <label>Meta title</label>
861
- <comment></comment>
862
- <frontend_type>select</frontend_type>
863
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
864
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
865
- <sort_order>30</sort_order>
866
- <show_in_default>0</show_in_default>
867
- <show_in_website>0</show_in_website>
868
- <show_in_store>1</show_in_store>
869
- </meta_title>
870
- <meta_description>
871
- <label>Meta description</label>
872
- <comment></comment>
873
- <frontend_type>select</frontend_type>
874
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
875
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
876
- <sort_order>30</sort_order>
877
- <show_in_default>0</show_in_default>
878
- <show_in_website>0</show_in_website>
879
- <show_in_store>1</show_in_store>
880
- </meta_description>
881
- <meta_keyword>
882
- <label>Meta Keywords</label>
883
- <comment></comment>
884
- <frontend_type>select</frontend_type>
885
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
886
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
887
- <sort_order>30</sort_order>
888
- <show_in_default>0</show_in_default>
889
- <show_in_website>0</show_in_website>
890
- <show_in_store>1</show_in_store>
891
- </meta_keyword>
892
- <weight>
893
- <label>Weight</label>
894
- <comment></comment>
895
- <frontend_type>select</frontend_type>
896
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
897
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
898
- <sort_order>40</sort_order>
899
- <show_in_default>0</show_in_default>
900
- <show_in_website>0</show_in_website>
901
- <show_in_store>1</show_in_store>
902
- </weight>
903
- <color>
904
- <label>Color</label>
905
- <comment></comment>
906
- <frontend_type>select</frontend_type>
907
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
908
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
909
- <sort_order>50</sort_order>
910
- <show_in_default>0</show_in_default>
911
- <show_in_website>0</show_in_website>
912
- <show_in_store>1</show_in_store>
913
- </color>
914
- <price>
915
- <label>Price</label>
916
- <comment></comment>
917
- <frontend_type>select</frontend_type>
918
- <source_model>profileolabs_shoppingflux/export_source_attributesprice</source_model>
919
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
920
- <sort_order>60</sort_order>
921
- <show_in_default>0</show_in_default>
922
- <show_in_website>0</show_in_website>
923
- <show_in_store>1</show_in_store>
924
- </price>
925
- <special_price>
926
- <label>Special Price</label>
927
- <comment></comment>
928
- <frontend_type>select</frontend_type>
929
- <source_model>profileolabs_shoppingflux/export_source_attributesprice</source_model>
930
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
931
- <sort_order>70</sort_order>
932
- <show_in_default>0</show_in_default>
933
- <show_in_website>0</show_in_website>
934
- <show_in_store>1</show_in_store>
935
- </special_price>
936
- <additional>
937
- <label>Other attributes to export</label>
938
- <frontend_type>wcmultiselect</frontend_type>
939
- <source_model>profileolabs_shoppingflux/export_source_attributes</source_model>
940
- <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
941
- <sort_order>125</sort_order>
942
- <show_in_default>0</show_in_default>
943
- <show_in_website>0</show_in_website>
944
- <show_in_store>1</show_in_store>
945
- </additional>
946
- </fields>
947
- </attributes_mapping>
948
- </groups>
949
- </shoppingflux_export>
950
- </sections>
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <shoppingflux translate="label" module="profileolabs_shoppingflux">
5
+ <label>Shopping Flux</label>
6
+ <sort_order>210</sort_order>
7
+ </shoppingflux>
8
+ </tabs>
9
+ <sections>
10
+ <shoppingflux translate="label" module="profileolabs_shoppingflux">
11
+ <label>General</label>
12
+ <tab>shoppingflux</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>10</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <configuration translate="label" module="profileolabs_shoppingflux">
20
+ <label>Configuration</label>
21
+ <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <sort_order>1</sort_order>
26
+ <fields>
27
+ <none>
28
+ <label>--</label>
29
+ <comment>Your ShoppingFlux's interface login</comment>
30
+ <frontend_type>text</frontend_type>
31
+ <sort_order>10</sort_order>
32
+ <show_in_default>1</show_in_default>
33
+ <show_in_website>0</show_in_website>
34
+ <show_in_store>0</show_in_store>
35
+ </none>
36
+ <api_key>
37
+ <label>API key</label>
38
+ <frontend_type>text</frontend_type>
39
+ <sort_order>20</sort_order>
40
+ <show_in_default>0</show_in_default>
41
+ <show_in_website>0</show_in_website>
42
+ <show_in_store>1</show_in_store>
43
+ </api_key>
44
+ <id_tracking>
45
+ <label>Tracking ID</label>
46
+ <comment>Your ShoppingFlux Tracking ID</comment>
47
+ <frontend_type>text</frontend_type>
48
+ <sort_order>30</sort_order>
49
+ <show_in_default>0</show_in_default>
50
+ <show_in_website>0</show_in_website>
51
+ <show_in_store>1</show_in_store>
52
+ </id_tracking>
53
+ <!--<enable_buyline>
54
+ <label>Enable buyline ?</label>
55
+ <frontend_type>select</frontend_type>
56
+ <source_model>adminhtml/system_config_source_yesno</source_model>
57
+ <sort_order>30</sort_order>
58
+ <show_in_default>0</show_in_default>
59
+ <show_in_website>0</show_in_website>
60
+ <show_in_store>1</show_in_store>
61
+ </enable_buyline>
62
+ <alert_email>
63
+ <label>Email address for alerts</label>
64
+ <comment>In case of issue while transfering data, an email will be sent to this address.</comment>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>100</sort_order>
67
+ <show_in_default>0</show_in_default>
68
+ <show_in_website>0</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ </alert_email>-->
71
+ </fields>
72
+ </configuration>
73
+ </groups>
74
+ </shoppingflux>
75
+ <shoppingflux_mo translate="label" module="profileolabs_shoppingflux">
76
+ <label>Manage Orders</label>
77
+ <tab>shoppingflux</tab>
78
+ <frontend_type>text</frontend_type>
79
+ <sort_order>100</sort_order>
80
+ <show_in_default>0</show_in_default>
81
+ <show_in_website>0</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ <groups>
84
+ <manageorders translate="label" module="profileolabs_shoppingflux">
85
+ <label>Manage Orders</label>
86
+ <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
87
+ <show_in_default>0</show_in_default>
88
+ <show_in_website>0</show_in_website>
89
+ <show_in_store>1</show_in_store>
90
+ <sort_order>1</sort_order>
91
+ <fields>
92
+ <enabled>
93
+ <label>Enable order management</label>
94
+ <frontend_type>select</frontend_type>
95
+ <sort_order>10</sort_order>
96
+ <show_in_default>0</show_in_default>
97
+ <show_in_website>0</show_in_website>
98
+ <show_in_store>1</show_in_store>
99
+ <source_model>adminhtml/system_config_source_yesno</source_model>
100
+ </enabled>
101
+ <limit_orders>
102
+ <label>Import by n orders</label>
103
+ <sort_order>22</sort_order>
104
+ <show_in_default>0</show_in_default>
105
+ <show_in_website>0</show_in_website>
106
+ <show_in_store>1</show_in_store>
107
+ <comment>Limit number of orders imported. 10 by default</comment>
108
+ </limit_orders>
109
+ <new_order_status translate="label">
110
+ <depends>
111
+ <create_invoice>0</create_invoice>
112
+ </depends>
113
+ <label>New order status</label>
114
+ <frontend_type>select</frontend_type>
115
+ <source_model>adminhtml/system_config_source_order_status_new</source_model>
116
+ <sort_order>80</sort_order>
117
+ <show_in_default>0</show_in_default>
118
+ <show_in_website>0</show_in_website>
119
+ <show_in_store>1</show_in_store>
120
+ </new_order_status>
121
+ <create_invoice>
122
+ <label>Create invoice ?</label>
123
+ <comment>If yes, an invoice will be created on ShoppingFlux's order creation</comment>
124
+ <frontend_type>select</frontend_type>
125
+ <sort_order>25</sort_order>
126
+ <show_in_default>0</show_in_default>
127
+ <show_in_website>0</show_in_website>
128
+ <show_in_store>1</show_in_store>
129
+ <source_model>adminhtml/system_config_source_yesno</source_model>
130
+ </create_invoice>
131
+ <processing_order_status translate="label">
132
+ <label>Invoiced order status</label>
133
+ <depends>
134
+ <create_invoice>1</create_invoice>
135
+ </depends>
136
+ <frontend_type>select</frontend_type>
137
+ <source_model>adminhtml/system_config_source_order_status_processing</source_model>
138
+ <sort_order>80</sort_order>
139
+ <show_in_default>0</show_in_default>
140
+ <show_in_website>0</show_in_website>
141
+ <show_in_store>1</show_in_store>
142
+ </processing_order_status>
143
+ <use_product_id>
144
+ <label>Use Product ID's instead of SKU ?</label>
145
+ <comment>Should be no in most cases.</comment>
146
+ <frontend_type>select</frontend_type>
147
+ <sort_order>90</sort_order>
148
+ <show_in_default>0</show_in_default>
149
+ <show_in_website>0</show_in_website>
150
+ <show_in_store>1</show_in_store>
151
+ <source_model>adminhtml/system_config_source_yesno</source_model>
152
+ </use_product_id>
153
+ <use_marketplace_date>
154
+ <label>Use Marketplace Order Date and Time ?</label>
155
+ <comment>If no, the order date will be the import date.</comment>
156
+ <frontend_type>select</frontend_type>
157
+ <sort_order>100</sort_order>
158
+ <show_in_default>0</show_in_default>
159
+ <show_in_website>0</show_in_website>
160
+ <show_in_store>1</show_in_store>
161
+ <source_model>adminhtml/system_config_source_yesno</source_model>
162
+ </use_marketplace_date>
163
+ </fields>
164
+ </manageorders>
165
+ <import_customer translate="label" module="profileolabs_shoppingflux">
166
+ <label>Customer Import</label>
167
+ <frontend_model>profileolabs_shoppingflux/manageorders_adminhtml_system_config_form_fieldset_customer_group</frontend_model>
168
+ <show_in_default>0</show_in_default>
169
+ <show_in_website>0</show_in_website>
170
+ <show_in_store>1</show_in_store>
171
+ <sort_order>2</sort_order>
172
+ <fields>
173
+ <limit_address_length>
174
+ <label>Limit addresses length</label>
175
+ <comment>Leave empty to not limit length. Minimum value if filled : 20</comment>
176
+ <frontend_type>text</frontend_type>
177
+ <sort_order>5</sort_order>
178
+ <show_in_default>0</show_in_default>
179
+ <show_in_website>0</show_in_website>
180
+ <show_in_store>1</show_in_store>
181
+ </limit_address_length>
182
+ <mobile_attribute>
183
+ <label>Customer Mobile Attribute</label>
184
+ <frontend_type>select</frontend_type>
185
+ <sort_order>6</sort_order>
186
+ <show_in_default>0</show_in_default>
187
+ <show_in_website>0</show_in_website>
188
+ <show_in_store>1</show_in_store>
189
+ <source_model>profileolabs_shoppingflux/manageorders_source_attributes</source_model>
190
+ </mobile_attribute>
191
+ <prefer_mobile_phone>
192
+ <depends>
193
+ <mobile_attribute></mobile_attribute>
194
+ </depends>
195
+ <label>Import mobile phone instead of desk phone, if available</label>
196
+ <frontend_type>select</frontend_type>
197
+ <sort_order>7</sort_order>
198
+ <show_in_default>0</show_in_default>
199
+ <show_in_website>0</show_in_website>
200
+ <show_in_store>1</show_in_store>
201
+ <source_model>adminhtml/system_config_source_yesno</source_model>
202
+ </prefer_mobile_phone>
203
+ <default_group>
204
+ <label>Default customer group</label>
205
+ <frontend_type>select</frontend_type>
206
+ <sort_order>10</sort_order>
207
+ <show_in_default>0</show_in_default>
208
+ <show_in_website>0</show_in_website>
209
+ <show_in_store>1</show_in_store>
210
+ <source_model>adminhtml/system_config_source_customer_group</source_model>
211
+ </default_group>
212
+ </fields>
213
+ </import_customer>
214
+ <shipping_method translate="label" module="profileolabs_shoppingflux">
215
+ <label>Shipping Method</label>
216
+ <frontend_model>profileolabs_shoppingflux/manageorders_adminhtml_system_config_form_fieldset_shipping_method</frontend_model>
217
+ <show_in_default>0</show_in_default>
218
+ <show_in_website>0</show_in_website>
219
+ <show_in_store>1</show_in_store>
220
+ <sort_order>3</sort_order>
221
+ <fields>
222
+ <default_method>
223
+ <label>Default shipping method</label>
224
+ <comment>Specific shipping method to use for imported ShoppingFlux's order</comment>
225
+ <frontend_type>select</frontend_type>
226
+ <sort_order>10</sort_order>
227
+ <show_in_default>0</show_in_default>
228
+ <show_in_website>0</show_in_website>
229
+ <show_in_store>1</show_in_store>
230
+ <source_model>adminhtml/system_config_source_shipping_allmethods</source_model>
231
+ </default_method>
232
+
233
+ </fields>
234
+ </shipping_method>
235
+ <advanced_shipping_method translate="label" module="profileolabs_shoppingflux">
236
+ <label>Advanced Shipping Methods Mapping</label>
237
+ <frontend_model>profileolabs_shoppingflux/manageorders_adminhtml_system_config_form_fieldset_shipping_method_extra</frontend_model>
238
+ <show_in_default>0</show_in_default>
239
+ <show_in_website>0</show_in_website>
240
+ <show_in_store>1</show_in_store>
241
+ <sort_order>4</sort_order>
242
+ </advanced_shipping_method>
243
+ <shipment_update translate="label" module="profileolabs_shoppingflux">
244
+ <label>Shipment Update</label>
245
+ <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
246
+ <show_in_default>0</show_in_default>
247
+ <show_in_website>0</show_in_website>
248
+ <show_in_store>1</show_in_store>
249
+ <sort_order>5</sort_order>
250
+ <fields>
251
+ <limit_hours>
252
+ <label>Max time before sending shipment update to marketplace</label>
253
+ <!-- Menu déroulant Immédiat et de 1 à 10 -->
254
+ <comment>In hours. If the shipment has still not any tracking number filled after X hours, the shipment is sent to the marketplace without tracking number.</comment>
255
+ <frontend_type>select</frontend_type>
256
+ <source_model>profileolabs_shoppingflux/export_source_tracking_delay</source_model>
257
+ <sort_order>10</sort_order>
258
+ <show_in_default>0</show_in_default>
259
+ <show_in_website>0</show_in_website>
260
+ <show_in_store>1</show_in_store>
261
+ </limit_hours>
262
+ </fields>
263
+ </shipment_update>
264
+ </groups>
265
+ </shoppingflux_mo>
266
+ <shoppingflux_export translate="label" module="profileolabs_shoppingflux">
267
+ <label>Manage Products</label>
268
+ <tab>shoppingflux</tab>
269
+ <frontend_type>text</frontend_type>
270
+ <sort_order>90</sort_order>
271
+ <show_in_default>0</show_in_default>
272
+ <show_in_website>0</show_in_website>
273
+ <show_in_store>1</show_in_store>
274
+ <groups>
275
+ <general translate="label">
276
+ <label>General</label>
277
+ <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
278
+ <comment><![CDATA[<b style='color:red'>Feed URL :</b>&nbsp;&nbsp;<span style='font-size:14px;font-style:italic;'>http://domain.tld/shoppingflux/export_flux/</span><br /><br /><br />]]></comment>
279
+ <show_in_default>0</show_in_default>
280
+ <show_in_website>0</show_in_website>
281
+ <show_in_store>1</show_in_store>
282
+ <sort_order>1</sort_order>
283
+ <fields>
284
+ <active>
285
+ <label>Enable product export ?</label>
286
+ <comment></comment>
287
+ <frontend_type>select</frontend_type>
288
+ <sort_order>1</sort_order>
289
+ <show_in_default>0</show_in_default>
290
+ <show_in_website>0</show_in_website>
291
+ <show_in_store>1</show_in_store>
292
+ <source_model>adminhtml/system_config_source_yesno</source_model>
293
+ </active>
294
+ <filter_by_attribute>
295
+ <label>Export selected products only ?</label>
296
+ <comment><![CDATA[If yes, you'll have to select products in <strong>Shoppingflux > Product Selection</strong>]]></comment>
297
+ <frontend_type>select</frontend_type>
298
+ <sort_order>5</sort_order>
299
+ <show_in_default>0</show_in_default>
300
+ <show_in_website>0</show_in_website>
301
+ <show_in_store>1</show_in_store>
302
+ <source_model>adminhtml/system_config_source_yesno</source_model>
303
+ </filter_by_attribute>
304
+ <!-- <limit_product>
305
+ <label>Export par n produits</label>
306
+ <comment></comment>
307
+ <sort_order>10</sort_order>
308
+ <show_in_default>0</show_in_default>
309
+ <show_in_website>0</show_in_website>
310
+ <show_in_store>1</show_in_store>
311
+ <comment>Limite le nombre de produit par lots</comment>
312
+ </limit_product> -->
313
+ <default_shipping_delay>
314
+ <label>Shipping delay</label>
315
+ <comment><![CDATA[Shipping delay, in <strong>days</strong>. This will be used if no shipping delay attribute is mapped.]]></comment>
316
+ <frontend_type>text</frontend_type>
317
+ <sort_order>20</sort_order>
318
+ <show_in_default>0</show_in_default>
319
+ <show_in_website>0</show_in_website>
320
+ <show_in_store>1</show_in_store>
321
+ </default_shipping_delay>
322
+ <default_shipping_price>
323
+ <label>Shipping fees</label>
324
+ <comment>Default shipping fees amount</comment>
325
+ <frontend_type>text</frontend_type>
326
+ <sort_order>40</sort_order>
327
+ <show_in_default>0</show_in_default>
328
+ <show_in_website>0</show_in_website>
329
+ <show_in_store>1</show_in_store>
330
+ </default_shipping_price>
331
+ <default_shipping_method>
332
+ <label>Shipping Method</label>
333
+ <comment>Default shipping method to calculate shipping fees</comment>
334
+ <frontend_type>select</frontend_type>
335
+ <source_model>adminhtml/system_config_source_shipping_allmethods</source_model>
336
+ <sort_order>30</sort_order>
337
+ <show_in_default>0</show_in_default>
338
+ <show_in_website>0</show_in_website>
339
+ <show_in_store>1</show_in_store>
340
+ </default_shipping_method>
341
+ <try_use_real_shipping_price>
342
+ <label>Try to get real shipping fees for each product ?</label>
343
+ <comment>Disable this option if you have memory issues.</comment>
344
+ <frontend_type>select</frontend_type>
345
+ <sort_order>40</sort_order>
346
+ <show_in_default>0</show_in_default>
347
+ <show_in_website>0</show_in_website>
348
+ <show_in_store>1</show_in_store>
349
+ <source_model>adminhtml/system_config_source_yesno</source_model>
350
+ </try_use_real_shipping_price>
351
+ <export_soldout>
352
+ <label>Export out of stock products</label>
353
+ <comment></comment>
354
+ <frontend_type>select</frontend_type>
355
+ <sort_order>50</sort_order>
356
+ <show_in_default>0</show_in_default>
357
+ <show_in_website>0</show_in_website>
358
+ <show_in_store>1</show_in_store>
359
+ <source_model>adminhtml/system_config_source_yesno</source_model>
360
+ </export_soldout>
361
+ <export_not_salable>
362
+ <label>Export not salable products</label>
363
+ <comment></comment>
364
+ <frontend_type>select</frontend_type>
365
+ <sort_order>51</sort_order>
366
+ <show_in_default>0</show_in_default>
367
+ <show_in_website>0</show_in_website>
368
+ <show_in_store>1</show_in_store>
369
+ <source_model>adminhtml/system_config_source_yesno</source_model>
370
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
371
+ </export_not_salable>
372
+ <enable_not_salable_retention>
373
+ <depends>
374
+ <export_soldout>0</export_soldout>
375
+ <export_not_salable>0</export_not_salable>
376
+ </depends>
377
+ <label>Enable temporary retention of out of stock/not salable products</label>
378
+ <comment>Experimental feature.</comment>
379
+ <frontend_type>select</frontend_type>
380
+ <sort_order>55</sort_order>
381
+ <show_in_default>0</show_in_default>
382
+ <show_in_website>0</show_in_website>
383
+ <show_in_store>1</show_in_store>
384
+ <source_model>adminhtml/system_config_source_yesno</source_model>
385
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
386
+ </enable_not_salable_retention>
387
+ <not_salable_retention_duration>
388
+ <depends>
389
+ <export_soldout>0</export_soldout>
390
+ <export_not_salable>0</export_not_salable>
391
+ <enable_not_salable_retention>1</enable_not_salable_retention>
392
+ </depends>
393
+ <label>Temporary retention duration</label>
394
+ <comment>In hours. Maximum duration: 168 hours (1 week).</comment>
395
+ <frontend_type>text</frontend_type>
396
+ <frontend_class>validate-greater-than-zero validate-number-range number-range-1-168</frontend_class>
397
+ <sort_order>56</sort_order>
398
+ <show_in_default>0</show_in_default>
399
+ <show_in_website>0</show_in_website>
400
+ <show_in_store>1</show_in_store>
401
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
402
+ </not_salable_retention_duration>
403
+ <export_all_images>
404
+ <label>Export all images</label>
405
+ <frontend_type>select</frontend_type>
406
+ <sort_order>57</sort_order>
407
+ <show_in_default>0</show_in_default>
408
+ <show_in_website>0</show_in_website>
409
+ <show_in_store>1</show_in_store>
410
+ <source_model>adminhtml/system_config_source_yesno</source_model>
411
+ </export_all_images>
412
+ <exported_image_count>
413
+ <depends>
414
+ <export_all_images>0</export_all_images>
415
+ </depends>
416
+ <label>Exported image count</label>
417
+ <frontend_type>text</frontend_type>
418
+ <frontend_class>validate-greater-than-zero</frontend_class>
419
+ <sort_order>58</sort_order>
420
+ <show_in_default>0</show_in_default>
421
+ <show_in_website>0</show_in_website>
422
+ <show_in_store>1</show_in_store>
423
+ </exported_image_count>
424
+ <show_advanced_configuration>
425
+ <label>Show advanced configuration ?</label>
426
+ <frontend_type>select</frontend_type>
427
+ <source_model>adminhtml/system_config_source_yesno</source_model>
428
+ <sort_order>59</sort_order>
429
+ <show_in_default>0</show_in_default>
430
+ <show_in_website>0</show_in_website>
431
+ <show_in_store>1</show_in_store>
432
+ </show_advanced_configuration>
433
+ <shipping_price_based_on>
434
+ <depends>
435
+ <show_advanced_configuration>1</show_advanced_configuration>
436
+ </depends>
437
+ <label>Shipping Country</label>
438
+ <comment>Default country used to calculate shipping fees</comment>
439
+ <frontend_type>select</frontend_type>
440
+ <source_model>adminhtml/system_config_source_country</source_model>
441
+ <sort_order>60</sort_order>
442
+ <show_in_default>0</show_in_default>
443
+ <show_in_website>0</show_in_website>
444
+ <show_in_store>1</show_in_store>
445
+ </shipping_price_based_on>
446
+ <export_visibility>
447
+ <depends>
448
+ <show_advanced_configuration>1</show_advanced_configuration>
449
+ </depends>
450
+ <label>Export product with visibility :</label>
451
+ <comment></comment>
452
+ <frontend_type>multiselect</frontend_type>
453
+ <sort_order>70</sort_order>
454
+ <show_in_default>0</show_in_default>
455
+ <show_in_website>0</show_in_website>
456
+ <show_in_store>1</show_in_store>
457
+ <source_model>profileolabs_shoppingflux/export_source_visibility</source_model>
458
+ </export_visibility>
459
+ <memory_limit>
460
+ <depends>
461
+ <show_advanced_configuration>1</show_advanced_configuration>
462
+ </depends>
463
+ <label>Memory limit</label>
464
+ <comment>in MB. Do not modify if you don't know what you are doing.</comment>
465
+ <frontend_type>text</frontend_type>
466
+ <sort_order>100</sort_order>
467
+ <show_in_default>0</show_in_default>
468
+ <show_in_website>0</show_in_website>
469
+ <show_in_store>1</show_in_store>
470
+ </memory_limit>
471
+ <execution_time_limit>
472
+ <depends>
473
+ <show_advanced_configuration>1</show_advanced_configuration>
474
+ </depends>
475
+ <label>Execution time limit</label>
476
+ <comment>in seconds. Do not modify if you don't know what you are doing.</comment>
477
+ <frontend_type>text</frontend_type>
478
+ <sort_order>110</sort_order>
479
+ <show_in_default>0</show_in_default>
480
+ <show_in_website>0</show_in_website>
481
+ <show_in_store>1</show_in_store>
482
+ </execution_time_limit>
483
+ <enable_sync>
484
+ <depends>
485
+ <show_advanced_configuration>1</show_advanced_configuration>
486
+ </depends>
487
+ <label>Enable automatic updates ?</label>
488
+ <comment>Update stocks and prices in real time. This could slow down price and stock modifications.</comment>
489
+ <frontend_type>select</frontend_type>
490
+ <sort_order>120</sort_order>
491
+ <show_in_default>0</show_in_default>
492
+ <show_in_website>0</show_in_website>
493
+ <show_in_store>1</show_in_store>
494
+ <source_model>adminhtml/system_config_source_yesno</source_model>
495
+ </enable_sync>
496
+ <enable_cron>
497
+ <depends>
498
+ <show_advanced_configuration>1</show_advanced_configuration>
499
+ </depends>
500
+ <label>Enable background generation ?</label>
501
+ <comment>Update feed on background if needed.</comment>
502
+ <frontend_type>select</frontend_type>
503
+ <sort_order>125</sort_order>
504
+ <show_in_default>0</show_in_default>
505
+ <show_in_website>0</show_in_website>
506
+ <show_in_store>1</show_in_store>
507
+ <source_model>adminhtml/system_config_source_yesno</source_model>
508
+ </enable_cron>
509
+ <use_manage_stock>
510
+ <depends>
511
+ <show_advanced_configuration>1</show_advanced_configuration>
512
+ </depends>
513
+ <label>Manage 'Manage stock' attribute ?</label>
514
+ <comment>If yes, products with 'Manage stock' = 'No' will have a stock qty to 100 in the feed.</comment>
515
+ <frontend_type>select</frontend_type>
516
+ <sort_order>130</sort_order>
517
+ <show_in_default>0</show_in_default>
518
+ <show_in_website>0</show_in_website>
519
+ <show_in_store>1</show_in_store>
520
+ <source_model>adminhtml/system_config_source_yesno</source_model>
521
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
522
+ </use_manage_stock>
523
+ <all_store_products>
524
+ <depends>
525
+ <show_advanced_configuration>1</show_advanced_configuration>
526
+ </depends>
527
+ <label>Export products from all stores ?</label>
528
+ <comment>If any doubt exists, leave it to 'No'</comment>
529
+ <frontend_type>select</frontend_type>
530
+ <sort_order>135</sort_order>
531
+ <show_in_default>0</show_in_default>
532
+ <show_in_website>0</show_in_website>
533
+ <show_in_store>1</show_in_store>
534
+ <source_model>adminhtml/system_config_source_yesno</source_model>
535
+ </all_store_products>
536
+
537
+ <enable_events>
538
+ <depends>
539
+ <show_advanced_configuration>1</show_advanced_configuration>
540
+ </depends>
541
+ <label>Enable ShoppingFlux events ?</label>
542
+ <comment>Usefull only in case of specific developments.</comment>
543
+ <frontend_type>select</frontend_type>
544
+ <sort_order>160</sort_order>
545
+ <show_in_default>0</show_in_default>
546
+ <show_in_website>0</show_in_website>
547
+ <show_in_store>1</show_in_store>
548
+ <source_model>adminhtml/system_config_source_yesno</source_model>
549
+ </enable_events>
550
+ <manage_configurable>
551
+ <depends>
552
+ <show_advanced_configuration>1</show_advanced_configuration>
553
+ </depends>
554
+ <label>Advanced management of configurable products ?</label>
555
+ <comment>If no, only configurable products will be transfered (without their children). In most cases, should be set to 'Yes'.</comment>
556
+ <frontend_type>select</frontend_type>
557
+ <sort_order>170</sort_order>
558
+ <show_in_default>0</show_in_default>
559
+ <show_in_website>0</show_in_website>
560
+ <show_in_store>1</show_in_store>
561
+ <source_model>adminhtml/system_config_source_yesno</source_model>
562
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
563
+ </manage_configurable>
564
+ <manage_catalog_rules>
565
+ <depends>
566
+ <show_advanced_configuration>1</show_advanced_configuration>
567
+ </depends>
568
+ <label>Manage catalog price rules ?</label>
569
+ <frontend_type>select</frontend_type>
570
+ <sort_order>180</sort_order>
571
+ <show_in_default>0</show_in_default>
572
+ <show_in_website>0</show_in_website>
573
+ <show_in_store>1</show_in_store>
574
+ <source_model>adminhtml/system_config_source_yesno</source_model>
575
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
576
+ </manage_catalog_rules>
577
+ <manage_media_gallery>
578
+ <depends>
579
+ <show_advanced_configuration>1</show_advanced_configuration>
580
+ </depends>
581
+ <label>Manage product galleries ?</label>
582
+ <comment>Does not concern main image. Faster if 'No'.</comment>
583
+ <frontend_type>select</frontend_type>
584
+ <sort_order>190</sort_order>
585
+ <show_in_default>0</show_in_default>
586
+ <show_in_website>0</show_in_website>
587
+ <show_in_store>1</show_in_store>
588
+ <source_model>adminhtml/system_config_source_yesno</source_model>
589
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
590
+ </manage_media_gallery>
591
+ <transform_qty_increments>
592
+ <depends>
593
+ <show_advanced_configuration>1</show_advanced_configuration>
594
+ </depends>
595
+ <label>Transform qty increments products ?</label>
596
+ <frontend_type>select</frontend_type>
597
+ <sort_order>200</sort_order>
598
+ <show_in_default>0</show_in_default>
599
+ <show_in_website>0</show_in_website>
600
+ <show_in_store>1</show_in_store>
601
+ <source_model>adminhtml/system_config_source_yesno</source_model>
602
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
603
+ </transform_qty_increments>
604
+ </fields>
605
+ </general>
606
+ <category>
607
+ <label>Categories</label>
608
+ <frontend_model>profileolabs_shoppingflux/adminhtml_system_config_form_fieldset_abstract</frontend_model>
609
+ <show_in_default>0</show_in_default>
610
+ <show_in_website>0</show_in_website>
611
+ <show_in_store>1</show_in_store>
612
+ <sort_order>15</sort_order>
613
+ <fields>
614
+ <use_shoppingflux_category>
615
+ <label>Use ShoppingFlux category attribute ?</label>
616
+ <comment>Warning : Be sure that this field is set to no before uninstalling the extension.</comment>
617
+ <frontend_type>select</frontend_type>
618
+ <sort_order>10</sort_order>
619
+ <show_in_default>0</show_in_default>
620
+ <show_in_website>0</show_in_website>
621
+ <show_in_store>1</show_in_store>
622
+ <source_model>adminhtml/system_config_source_yesno</source_model>
623
+ <backend_model>profileolabs_shoppingflux/system_config_backend_category</backend_model>
624
+ </use_shoppingflux_category>
625
+
626
+ <use_only_shoppingflux_category>
627
+ <depends>
628
+ <use_shoppingflux_category>1</use_shoppingflux_category>
629
+ </depends>
630
+ <label>Use only ShoppingFlux category ?</label>
631
+ <comment>Faster if yes.</comment>
632
+ <frontend_type>select</frontend_type>
633
+ <sort_order>20</sort_order>
634
+ <show_in_default>0</show_in_default>
635
+ <show_in_website>0</show_in_website>
636
+ <show_in_store>1</show_in_store>
637
+ <source_model>adminhtml/system_config_source_yesno</source_model>
638
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
639
+ </use_only_shoppingflux_category>
640
+
641
+
642
+ <all_store_categories>
643
+ <depends>
644
+ <use_shoppingflux_category>1</use_shoppingflux_category>
645
+ </depends>
646
+ <label>Use categories from all stores ?</label>
647
+ <comment>If any doubt exists, leave it to 'No'</comment>
648
+ <frontend_type>select</frontend_type>
649
+ <sort_order>30</sort_order>
650
+ <show_in_default>0</show_in_default>
651
+ <show_in_website>0</show_in_website>
652
+ <show_in_store>1</show_in_store>
653
+ <source_model>adminhtml/system_config_source_yesno</source_model>
654
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model>
655
+ </all_store_categories>
656
+
657
+ <max_category_level>
658
+ <depends>
659
+ <use_shoppingflux_category>1</use_shoppingflux_category>
660
+ </depends>
661
+ <label>Use only X first category levels</label>
662
+ <frontend_type>select</frontend_type>
663
+ <sort_order>40</sort_order>
664
+ <show_in_default>0</show_in_default>
665
+ <show_in_website>0</show_in_website>
666
+ <show_in_store>1</show_in_store>
667
+ <source_model>profileolabs_shoppingflux/export_source_category_level</source_model>
668
+ <backend_model>profileolabs_shoppingflux/system_config_backend_refresh</backend_model