ConsumerBell_Recall - Version 1.0.2

Version Notes

Version number: 1.0.2
Stability: Stable
Compatibility: Magento Community Edition 1.6.X, 1.7.X; Magento Enterprise Edition: 1.11.X, 1.12.X.
Initial release of ConsumerBell Inventory Recall Monitoring

Download this release

Release Info

Developer Magento Core Team
Extension ConsumerBell_Recall
Version 1.0.2
Comparing to
See all releases


Version 1.0.2

Files changed (48) hide show
  1. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Catalog.php +51 -0
  2. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Catalog/Form.php +139 -0
  3. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Map.php +80 -0
  4. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Map/Grid.php +164 -0
  5. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Product/Edit/Tab/Recall.php +113 -0
  6. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Product/Edit/Tab/Recall/Grid.php +120 -0
  7. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Status.php +49 -0
  8. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Status/Grid.php +184 -0
  9. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Toolbar.php +57 -0
  10. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Form/Element/Button.php +43 -0
  11. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Grid/Column/Renderer/Link.php +47 -0
  12. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Grid/Column/Renderer/Select.php +107 -0
  13. app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Grid/Column/Renderer/Text.php +44 -0
  14. app/code/community/ConsumerBell/Recall/Helper/Data.php +243 -0
  15. app/code/community/ConsumerBell/Recall/Model/Cron.php +146 -0
  16. app/code/community/ConsumerBell/Recall/Model/Info.php +84 -0
  17. app/code/community/ConsumerBell/Recall/Model/Map.php +89 -0
  18. app/code/community/ConsumerBell/Recall/Model/Observer.php +75 -0
  19. app/code/community/ConsumerBell/Recall/Model/Resource/Info.php +31 -0
  20. app/code/community/ConsumerBell/Recall/Model/Resource/Info/Collection.php +231 -0
  21. app/code/community/ConsumerBell/Recall/Model/Resource/Map.php +34 -0
  22. app/code/community/ConsumerBell/Recall/Model/Resource/Map/Collection.php +50 -0
  23. app/code/community/ConsumerBell/Recall/Model/Resource/Setup.php +24 -0
  24. app/code/community/ConsumerBell/Recall/Model/Resource/Status.php +113 -0
  25. app/code/community/ConsumerBell/Recall/Model/Resource/Status/Collection.php +37 -0
  26. app/code/community/ConsumerBell/Recall/Model/Service.php +445 -0
  27. app/code/community/ConsumerBell/Recall/Model/Service/Api.php +324 -0
  28. app/code/community/ConsumerBell/Recall/Model/Status.php +231 -0
  29. app/code/community/ConsumerBell/Recall/Model/System/Config/Backend/Cron.php +82 -0
  30. app/code/community/ConsumerBell/Recall/Model/System/Config/Source/Recall.php +47 -0
  31. app/code/community/ConsumerBell/Recall/controllers/Adminhtml/Consumerbell/Recall/CatalogController.php +137 -0
  32. app/code/community/ConsumerBell/Recall/controllers/Adminhtml/Consumerbell/Recall/MapController.php +100 -0
  33. app/code/community/ConsumerBell/Recall/controllers/Adminhtml/Consumerbell/Recall/StatusController.php +50 -0
  34. app/code/community/ConsumerBell/Recall/etc/adminhtml.xml +100 -0
  35. app/code/community/ConsumerBell/Recall/etc/config.xml +145 -0
  36. app/code/community/ConsumerBell/Recall/etc/system.xml +159 -0
  37. app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/install-1.0.0.php +50 -0
  38. app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/mysql4-install-1.0.2.php +62 -0
  39. app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/upgrade-1.0.0-1.0.1.php +64 -0
  40. app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/upgrade-1.0.1-1.0.2.php +69 -0
  41. app/design/adminhtml/default/default/layout/consumerbell/recall.xml +59 -0
  42. app/design/adminhtml/default/default/template/consumerbell/recall/cron/status_grid.phtml +43 -0
  43. app/design/adminhtml/default/default/template/consumerbell/recall/map/container.phtml +41 -0
  44. app/design/adminhtml/default/default/template/consumerbell/recall/toolbar.phtml +28 -0
  45. app/etc/modules/ConsumerBell_Recall.xml +30 -0
  46. app/locale/en_US/ConsumerBell_Recall.csv +73 -0
  47. app/locale/en_US/template/email/consumerbell/recall_cron.html +18 -0
  48. package.xml +23 -0
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Catalog.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Catalog Management Form Container Block
21
+ */
22
+ class ConsumerBell_Recall_Block_Adminhtml_Catalog extends Mage_Adminhtml_Block_Widget_Form_Container
23
+ {
24
+ /**
25
+ * Define Container options
26
+ */
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+
31
+ $this->_blockGroup = 'consumerbell_recall';
32
+ $this->_controller = 'adminhtml';
33
+ $this->_mode = 'catalog';
34
+ $this->_headerText = Mage::helper('consumerbell_recall')->__('Catalog Management');
35
+ }
36
+
37
+ /**
38
+ * Removes Header buttons
39
+ *
40
+ * @return ConsumerBell_Recall_Block_Adminhtml_Catalog
41
+ */
42
+ protected function _prepareLayout()
43
+ {
44
+ $this->_removeButton('back');
45
+ $this->_removeButton('reset');
46
+ $this->_removeButton('delete');
47
+ $this->_removeButton('save');
48
+
49
+ return parent::_prepareLayout();
50
+ }
51
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Catalog/Form.php ADDED
@@ -0,0 +1,139 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Catalog Management Form Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Catalog_Form extends Mage_Adminhtml_Block_Widget_Form
24
+ {
25
+ /**
26
+ * Prepare form elements
27
+ *
28
+ * @return ConsumerBell_Recall_Block_Adminhtml_Catalog_Form
29
+ */
30
+ protected function _prepareForm()
31
+ {
32
+ /* @var $helper ConsumerBell_Recall_Helper_Data */
33
+ $helper = Mage::helper('consumerbell_recall');
34
+
35
+ $form = new Varien_Data_Form();
36
+ $this->setForm($form);
37
+ $form->setData('use_container', false);
38
+
39
+ if (!$helper->isFieldMappingValid()) {
40
+ $form->addField('title', 'label', array(
41
+ 'value' => $this->__('Field mapping is not defined.'),
42
+ 'bold' => true,
43
+ ));
44
+
45
+ $form->addField('link', 'note', array(
46
+ 'text' => $this->__('<a href="%s">Field Mapping</a> is not defined',
47
+ $this->getUrl('*/consumerbell_recall_map')),
48
+ ));
49
+
50
+ return parent::_prepareForm();
51
+ }
52
+
53
+ $fieldset = $form->addFieldset('sync_fieldset', array(
54
+ 'legend' => $this->__('Sync Catalog')
55
+ ));
56
+
57
+ $this->_initFieldsetTypes($fieldset);
58
+
59
+ /* @var $service ConsumerBell_Recall_Model_Service */
60
+ $service = Mage::getSingleton('consumerbell_recall/service');
61
+ $timestamp = $helper->getLastSync();
62
+ if ($timestamp === null) {
63
+ $lastSync = $this->__('Never');
64
+ } else {
65
+ $datetime = Mage::app()->getLocale()->storeDate(null, $timestamp, true);
66
+ $lastSync = $this->formatDate($datetime, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, true);
67
+ }
68
+
69
+ $fieldset->addField('last_sync', 'label', array(
70
+ 'label' => $this->__('Last Catalog synchronization'),
71
+ 'value' => $lastSync,
72
+ ));
73
+
74
+ $fieldset->addField('to_sync', 'label', array(
75
+ 'label' => $this->__('Products to be synced'),
76
+ 'value' => $service->getProductCountToSync(),
77
+ ));
78
+
79
+ $action = sprintf("confirmSetLocation('%s','%s')",
80
+ $this->jsQuoteEscape($this->__('Are you sure that you want sync it?')),
81
+ $this->getUrl('*/*/sync'));
82
+ $fieldset->addField('sync', 'button', array(
83
+ 'label' => $this->__('Action'),
84
+ 'value' => $this->__('Sync'),
85
+ 'class' => 'button scalable',
86
+ 'onclick' => $action,
87
+ ));
88
+
89
+ $fieldset = $form->addFieldset('recall_fieldset', array(
90
+ 'legend' => $this->__('Check recalled products')
91
+ ));
92
+
93
+ $this->_initFieldsetTypes($fieldset);
94
+
95
+ $timestamp = $helper->getLastRecall();
96
+ if ($timestamp === null) {
97
+ $lastRecall = $this->__('Never');
98
+ } else {
99
+ $datetime = Mage::app()->getLocale()->storeDate(null, $timestamp, true);
100
+ $lastRecall = $this->formatDate($datetime, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, true);
101
+ }
102
+
103
+ $fieldset->addField('last_recall', 'label', array(
104
+ 'label' => $this->__('Last Check Recall status'),
105
+ 'value' => $lastRecall,
106
+ ));
107
+
108
+ $action = sprintf("confirmSetLocation('%s','%s')",
109
+ $this->jsQuoteEscape($this->__('Are you sure that you want check it?')),
110
+ $this->getUrl('*/*/check'));
111
+ $fieldset->addField('recall', 'button', array(
112
+ 'label' => $this->__('Action'),
113
+ 'value' => $this->__('Check'),
114
+ 'class' => 'button scalable',
115
+ 'onclick' => $action,
116
+ ));
117
+
118
+ $this->setForm($form);
119
+
120
+ return parent::_prepareForm();
121
+ }
122
+
123
+ /**
124
+ * Init Form Fieldset additional types
125
+ *
126
+ * @param Varien_Data_Form_Element_Fieldset $fieldset
127
+ */
128
+ protected function _initFieldsetTypes(Varien_Data_Form_Element_Fieldset $fieldset)
129
+ {
130
+ $types = array(
131
+ 'button' => 'consumerbell_recall/adminhtml_widget_form_element_button',
132
+ );
133
+ $config = Mage::getConfig();
134
+
135
+ foreach ($types as $code => $blockType) {
136
+ $fieldset->addType($code, $config->getBlockClassName($blockType));
137
+ }
138
+ }
139
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Map.php ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Field Mapping Container Block
21
+ */
22
+ class ConsumerBell_Recall_Block_Adminhtml_Map extends Mage_Adminhtml_Block_Widget_Grid_Container
23
+ {
24
+ /**
25
+ * Define Container options
26
+ */
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+
31
+ $this->_blockGroup = 'consumerbell_recall';
32
+ $this->_controller = 'adminhtml_map';
33
+ $this->_headerText = Mage::helper('consumerbell_recall')->__('Field Mapping');
34
+ }
35
+
36
+ /**
37
+ * Prepares Header buttons
38
+ *
39
+ * @return ConsumerBell_Recall_Block_Adminhtml_Map
40
+ */
41
+ protected function _prepareLayout()
42
+ {
43
+ parent::_prepareLayout();
44
+
45
+ $this->removeButton('add');
46
+ $this->addButton('sync', array(
47
+ 'label' => Mage::helper('consumerbell_recall')->__('Sync Attributes'),
48
+ 'onclick' => 'setLocation(\'' . $this->getUrl('*/*/sync') .'\')',
49
+ 'class' => 'go',
50
+ ));
51
+
52
+ $this->addButton('save', array(
53
+ 'label' => Mage::helper('consumerbell_recall')->__('Save'),
54
+ 'onclick' => 'gridForm.submit()',
55
+ 'class' => 'save',
56
+ ));
57
+
58
+ return $this;
59
+ }
60
+
61
+ /**
62
+ * Returns Form ID
63
+ *
64
+ * @return string
65
+ */
66
+ public function getFormId()
67
+ {
68
+ return 'consumerbell_recall_map';
69
+ }
70
+
71
+ /**
72
+ * Returns Form action URL
73
+ *
74
+ * @return string
75
+ */
76
+ public function getFormAction()
77
+ {
78
+ return $this->getUrl('*/*/save');
79
+ }
80
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Map/Grid.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall_Field Mapping Grid Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Map_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
+ {
25
+ /**
26
+ * List of Catalog Product Attributes
27
+ *
28
+ * @var Mage_Catalog_Model_Resource_Eav_Attribute[]
29
+ */
30
+ protected $_attributes;
31
+
32
+ /**
33
+ * Setups Grid settings
34
+ */
35
+ protected function _construct()
36
+ {
37
+ parent::_construct();
38
+
39
+ $this->setId('consumerbell_recall_grid');
40
+ $this->_filterVisibility = false;
41
+ $this->_pagerVisibility = false;
42
+ }
43
+
44
+ /**
45
+ * Defines and prepares Grid Collection
46
+ *
47
+ * @return ConsumerBell_Recall_Block_Adminhtml_Map_Grid
48
+ */
49
+ protected function _prepareCollection()
50
+ {
51
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Map_Collection */
52
+ $collection = Mage::getResourceModel('consumerbell_recall/map_collection');
53
+ $collection->setPositionOrder();
54
+ $this->setCollection($collection);
55
+
56
+ return parent::_prepareCollection();
57
+ }
58
+
59
+ /**
60
+ * Prepares Grid columns
61
+ *
62
+ * @return Mage_Adminhtml_Block_Widget_Grid
63
+ */
64
+ protected function _prepareColumns()
65
+ {
66
+ $this->addColumn('field', array(
67
+ 'header' => Mage::helper('index')->__('Field'),
68
+ 'width' => '180',
69
+ 'align' => 'left',
70
+ 'index' => 'field',
71
+ 'sortable' => false,
72
+ ));
73
+
74
+ $this->addColumn('name', array(
75
+ 'header' => Mage::helper('index')->__('Name'),
76
+ 'align' => 'left',
77
+ 'index' => 'name',
78
+ 'sortable' => false,
79
+ ));
80
+
81
+ $options = array(
82
+ '' => $this->__('-- Select --'),
83
+ '0' => $this->__('-- Empty value --'),
84
+ );
85
+ $options += $this->_getAttributeOptions();
86
+
87
+ $renderer = $this->getLayout()->createBlock('consumerbell_recall/adminhtml_widget_grid_column_renderer_select');
88
+ $this->addColumn('attribute_id', array(
89
+ 'header' => Mage::helper('index')->__('Product Attribute'),
90
+ 'sortable' => false,
91
+ 'renderer' => $renderer,
92
+ 'options' => $options,
93
+ 'getter' => array($this, 'getAttributeIdGetter'),
94
+ 'html_name_format' => 'attribute_id[%s]',
95
+ 'validate_class' => 'select required-entry validate-select'
96
+ ));
97
+
98
+ return parent::_prepareColumns();
99
+ }
100
+
101
+ /**
102
+ * Returns attribute id
103
+ *
104
+ * Try to match by attribute code if attribute value is empty
105
+ *
106
+ * @param ConsumerBell_Recall_Model_Map $row
107
+ * @return int
108
+ */
109
+ public function getAttributeIdGetter($row)
110
+ {
111
+ $value = $row->getData('attribute_id');
112
+ if (empty($value) && $value != '0') {
113
+ $this->_loadAttributes();
114
+ foreach ($this->_attributes as $attribute) {
115
+ if ($row->getField() == $attribute->getAttributeCode()) {
116
+ $value = $attribute->getId();
117
+ }
118
+ }
119
+ }
120
+
121
+ return $value;
122
+ }
123
+
124
+ /**
125
+ * Loads Catalog Product attributes
126
+ */
127
+ protected function _loadAttributes()
128
+ {
129
+ if ($this->_attributes !== null) {
130
+ return;
131
+ }
132
+
133
+ $this->_attributes = array();
134
+ /* @var $eavConfig Mage_Eav_Model_Config */
135
+ $eavConfig = Mage::getSingleton('eav/config');
136
+ $entityType = $eavConfig->getEntityType('catalog_product');
137
+ /** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
138
+ $collection = Mage::getResourceModel($entityType->getEntityAttributeCollection());
139
+ $collection->setEntityTypeFilter($entityType->getId());
140
+ $collection->addVisibleFilter();
141
+
142
+ /** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
143
+ foreach ($collection as $attribute) {
144
+ $this->_attributes[$attribute->getId()] = $attribute;
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Returns list of attributes
150
+ *
151
+ * @return array
152
+ */
153
+ protected function _getAttributeOptions()
154
+ {
155
+ $this->_loadAttributes();
156
+
157
+ $options = array();
158
+ foreach ($this->_attributes as $attribute) {
159
+ $options[$attribute->getId()] = $attribute->getFrontendLabel();
160
+ }
161
+
162
+ return $options;
163
+ }
164
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Product/Edit/Tab/Recall.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Catalog Product Edit Recall Tab Block
21
+ */
22
+ class ConsumerBell_Recall_Block_Adminhtml_Product_Edit_Tab_Recall
23
+ extends Mage_Adminhtml_Block_Abstract
24
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
25
+ {
26
+ /**
27
+ * Current product instance
28
+ *
29
+ * @var Mage_Catalog_Model_Product
30
+ */
31
+ protected $_product;
32
+
33
+ /**
34
+ * Returns current entity instance
35
+ *
36
+ * @return Mage_Catalog_Model_Product
37
+ */
38
+ protected function _getProduct()
39
+ {
40
+ if ($this->_product === null) {
41
+ $this->_product = Mage::registry('current_product');
42
+ }
43
+ return $this->_product;
44
+ }
45
+
46
+ /**
47
+ * Returns Tab label
48
+ *
49
+ * @return string
50
+ */
51
+ public function getTabLabel()
52
+ {
53
+ return Mage::helper('consumerbell_recall')->__('Recall Information');
54
+ }
55
+
56
+ /**
57
+ * Returns Tab title
58
+ *
59
+ * @return string
60
+ */
61
+ public function getTabTitle()
62
+ {
63
+ return Mage::helper('consumerbell_recall')->__('Recall Information');
64
+ }
65
+
66
+ /**
67
+ * Can show tab in tabs
68
+ *
69
+ * @return boolean
70
+ */
71
+ public function canShowTab()
72
+ {
73
+ /* @var $helper ConsumerBell_Recall_Helper_Data */
74
+ $helper = Mage::helper('consumerbell_recall');
75
+ if (!$helper->isEnabled()) {
76
+ return false;
77
+ }
78
+
79
+ return $this->_getProduct()->getId() ? true : false;
80
+ }
81
+
82
+ /**
83
+ * Tab is hidden
84
+ *
85
+ * @return boolean
86
+ */
87
+ public function isHidden()
88
+ {
89
+ return false;
90
+ }
91
+
92
+ /**
93
+ * Returns class name (load tab by AJAX)
94
+ *
95
+ * @return string
96
+ */
97
+ public function getTabClass()
98
+ {
99
+ return 'ajax';
100
+ }
101
+
102
+ /**
103
+ * Returns Tab load URL
104
+ *
105
+ * @return string
106
+ */
107
+ public function getTabUrl()
108
+ {
109
+ return $this->getUrl('adminhtml/consumerbell_recall_catalog/productRecallGrid', array(
110
+ 'product_id' => $this->_getProduct()->getId(),
111
+ ));
112
+ }
113
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Product/Edit/Tab/Recall/Grid.php ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Catalog Product Edit Recall Tab Block
21
+ */
22
+ class ConsumerBell_Recall_Block_Adminhtml_Product_Edit_Tab_Recall_Grid extends Mage_Adminhtml_Block_Widget_Grid
23
+ {
24
+ /**
25
+ * Current entity instance
26
+ *
27
+ * @var ConsumerBell_Recall_Model_Status
28
+ */
29
+ protected $_entity;
30
+
31
+ /**
32
+ * Returns current entity instance
33
+ *
34
+ * @return ConsumerBell_Recall_Model_Status
35
+ */
36
+ protected function _getEntity()
37
+ {
38
+ if ($this->_entity === null) {
39
+ $this->_entity = Mage::registry('current_recall');
40
+ }
41
+ return $this->_entity;
42
+ }
43
+
44
+ /**
45
+ * Initialize block
46
+ *
47
+ */
48
+ protected function _construct()
49
+ {
50
+ parent::_construct();
51
+
52
+ $this->setId('tab_recall_grid');
53
+ $this->setDefaultSort('updated_at');
54
+ $this->setDefaultDir('DESC');
55
+ $this->setUseAjax(true);
56
+ }
57
+
58
+ protected function _prepareLayout()
59
+ {
60
+ $this->_emptyText = Mage::helper('consumerbell_recall')->__('No recalls notifications for this item');
61
+
62
+ return parent::_prepareLayout();
63
+ }
64
+
65
+ /**
66
+ * Prepares collection for Grid
67
+ *
68
+ * @return $this
69
+ */
70
+ protected function _prepareCollection()
71
+ {
72
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Info_Collection */
73
+ $collection = Mage::getResourceModel('consumerbell_recall/info_collection');
74
+ $collection->addRecallFilter($this->_getEntity());
75
+
76
+ $this->setCollection($collection);
77
+
78
+ return parent::_prepareCollection();
79
+ }
80
+
81
+ /**
82
+ * Prepare Grid columns
83
+ *
84
+ * @return $this
85
+ */
86
+ protected function _prepareColumns()
87
+ {
88
+ $config = Mage::getConfig();
89
+ $renderer = $config->getBlockClassName('consumerbell_recall/adminhtml_widget_grid_column_renderer_link');
90
+
91
+ $this->addColumn('url', array(
92
+ 'index' => 'url',
93
+ 'renderer' => $renderer,
94
+ 'filter' => false,
95
+ 'sortable' => false,
96
+ // 'link_text' => Mage::helper('consumerbell_recall')->__('Read more'),
97
+ 'target' => '_blank',
98
+ 'header' => Mage::helper('consumerbell_recall')->__('Recall info'),
99
+ ));
100
+
101
+ $this->addColumn('updated_at', array(
102
+ 'index' => 'updated_at',
103
+ 'header' => Mage::helper('consumerbell_recall')->__('Updated At'),
104
+ 'type' => 'datetime',
105
+ ));
106
+
107
+ return parent::_prepareColumns();
108
+ }
109
+
110
+
111
+ /**
112
+ * Returns URL for AJAX Grid request
113
+ *
114
+ * @return string
115
+ */
116
+ public function getGridUrl()
117
+ {
118
+ return $this->getUrl('*/*/productRecallGrid/', array('_current' => true));
119
+ }
120
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Status.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recalled Products Grid Container Block
21
+ */
22
+ class ConsumerBell_Recall_Block_Adminhtml_Status extends Mage_Adminhtml_Block_Widget_Grid_Container
23
+ {
24
+ /**
25
+ * Define Container options
26
+ */
27
+ protected function _construct()
28
+ {
29
+ parent::_construct();
30
+
31
+ $this->_blockGroup = 'consumerbell_recall';
32
+ $this->_controller = 'adminhtml_status';
33
+ $this->_headerText = Mage::helper('consumerbell_recall')->__('Recalled Products');
34
+ }
35
+
36
+ /**
37
+ * Prepares Header buttons
38
+ *
39
+ * @return ConsumerBell_Recall_Block_Adminhtml_Map
40
+ */
41
+ protected function _prepareLayout()
42
+ {
43
+ parent::_prepareLayout();
44
+
45
+ $this->removeButton('add');
46
+
47
+ return $this;
48
+ }
49
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Status/Grid.php ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall_Field Mapping Grid Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Status_Grid extends Mage_Adminhtml_Block_Widget_Grid
24
+ {
25
+ /**
26
+ * Define Grid settings
27
+ */
28
+ protected function _construct()
29
+ {
30
+ parent::_construct();
31
+
32
+ $this->setDefaultSort('updated_at');
33
+ $this->setDefaultDir('desc');
34
+ }
35
+
36
+ /**
37
+ * Defines grid collection
38
+ *
39
+ * @return $this
40
+ */
41
+ protected function _prepareCollection()
42
+ {
43
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Info_Collection */
44
+ $collection = Mage::getResourceModel('consumerbell_recall/info_collection');
45
+ $collection->addProductData();
46
+
47
+ $this->setCollection($collection);
48
+
49
+ return parent::_prepareCollection();
50
+ }
51
+
52
+ /**
53
+ * Defines Grid columns
54
+ *
55
+ * @return $this
56
+ */
57
+ protected function _prepareColumns()
58
+ {
59
+ $this->addColumn('sku', array(
60
+ 'index' => 'sku',
61
+ 'header' => Mage::helper('consumerbell_recall')->__('SKU'),
62
+ ));
63
+
64
+ $config = Mage::getConfig();
65
+ $renderer = $config->getBlockClassName('consumerbell_recall/adminhtml_widget_grid_column_renderer_text');
66
+
67
+ $this->addColumn('product_id', array(
68
+ 'index' => 'product_name',
69
+ 'renderer' => $renderer,
70
+ 'getter' => array($this, 'getProductName'),
71
+ 'header' => Mage::helper('consumerbell_recall')->__('Product'),
72
+ ));
73
+
74
+ $this->addColumn('product_status', array(
75
+ 'index' => 'product_status',
76
+ 'type' => 'options',
77
+ 'getter' => array($this, 'getProductStatus'),
78
+ 'header' => Mage::helper('consumerbell_recall')->__('Product Status'),
79
+ 'options' => array(
80
+ '0' => Mage::helper('consumerbell_recall')->__('Disabled'),
81
+ '1' => Mage::helper('consumerbell_recall')->__('Enabled'),
82
+ ),
83
+ ));
84
+
85
+ $this->addColumn('product_stock', array(
86
+ 'index' => 'product_stock',
87
+ 'type' => 'options',
88
+ 'getter' => array($this, 'getProductStock'),
89
+ 'header' => Mage::helper('consumerbell_recall')->__('Stock'),
90
+ 'options' => array(
91
+ '0' => Mage::helper('consumerbell_recall')->__('Out of stock'),
92
+ '1' => Mage::helper('consumerbell_recall')->__('In stock'),
93
+ ),
94
+ ));
95
+
96
+ $renderer = $config->getBlockClassName('consumerbell_recall/adminhtml_widget_grid_column_renderer_link');
97
+
98
+ $this->addColumn('url', array(
99
+ 'index' => 'url',
100
+ 'renderer' => $renderer,
101
+ 'filter' => false,
102
+ 'sortable' => false,
103
+ 'link_text' => Mage::helper('consumerbell_recall')->__('Read more'),
104
+ 'target' => '_blank',
105
+ 'header' => Mage::helper('consumerbell_recall')->__('Recall info'),
106
+ ));
107
+
108
+ $this->addColumn('action', array(
109
+ 'index' => 'action',
110
+ 'header' => Mage::helper('consumerbell_recall')->__('Action applied'),
111
+ 'type' => 'options',
112
+ 'options' => array(
113
+ ConsumerBell_Recall_Model_Service::ACTION_NO_ACTION
114
+ => Mage::helper('consumerbell_recall')->__('Nothing'),
115
+ ConsumerBell_Recall_Model_Service::ACTION_OUT_OF_STOCK
116
+ => Mage::helper('consumerbell_recall')->__('Set out of stock'),
117
+ ConsumerBell_Recall_Model_Service::ACTION_DISABLE
118
+ => Mage::helper('consumerbell_recall')->__('Disable item'),
119
+ ),
120
+ ));
121
+
122
+ $this->addColumn('updated_at', array(
123
+ 'index' => 'updated_at',
124
+ 'header' => Mage::helper('consumerbell_recall')->__('Updated At'),
125
+ 'type' => 'datetime',
126
+ ));
127
+
128
+ return parent::_prepareColumns();
129
+ }
130
+
131
+ /**
132
+ * Returns Product name and Edit URL
133
+ *
134
+ * @param ConsumerBell_Recall_Model_Info $row
135
+ * @return string
136
+ */
137
+ public function getProductName($row)
138
+ {
139
+ $productId = $row->getRecall()->getProductId();
140
+
141
+ if (!$productId) {
142
+ return Mage::helper('consumerbell_recall')->__('None');
143
+ }
144
+
145
+ return sprintf('<a href="%s">%s</a>',
146
+ $this->getUrl('adminhtml/catalog_product/edit', array('id' => $productId)),
147
+ $this->escapeHtml($row->getRecall()->getProductName())
148
+ );
149
+ }
150
+
151
+ /**
152
+ * Returns Product status
153
+ *
154
+ * @param ConsumerBell_Recall_Model_Info $row
155
+ * @return string
156
+ */
157
+ public function getProductStatus($row)
158
+ {
159
+ $productId = $row->getRecall()->getProductId();
160
+
161
+ if (!$productId) {
162
+ return Mage::helper('consumerbell_recall')->__('Unknown');
163
+ }
164
+
165
+ return $row->getRecall()->getProductStatus();
166
+ }
167
+
168
+ /**
169
+ * Returns Product Stock status
170
+ *
171
+ * @param ConsumerBell_Recall_Model_Info $row
172
+ * @return string
173
+ */
174
+ public function getProductStock($row)
175
+ {
176
+ $productId = $row->getRecall()->getProductId();
177
+
178
+ if (!$productId) {
179
+ return Mage::helper('consumerbell_recall')->__('Unknown');
180
+ }
181
+
182
+ return $row->getRecall()->getProductStock();
183
+ }
184
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Toolbar.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ class ConsumerBell_Recall_Block_Adminhtml_Toolbar extends Mage_Adminhtml_Block_Template
20
+ {
21
+ /**
22
+ * Check is can show toolbar
23
+ *
24
+ * @return bool
25
+ */
26
+ public function canShow()
27
+ {
28
+ /* @var $helper ConsumerBell_Recall_Helper_Data */
29
+ $helper = Mage::helper('consumerbell_recall');
30
+
31
+ if (!$helper->isEnabled()) {
32
+ return false;
33
+ }
34
+ if ($helper->isCronEnabled() || !$helper->isFieldMappingValid()) {
35
+ return false;
36
+ }
37
+
38
+ /* @var $service ConsumerBell_Recall_Model_Service */
39
+ $service = Mage::getSingleton('consumerbell_recall/service');
40
+
41
+ if (!$service->getProductCountToSync()) {
42
+ return false;
43
+ }
44
+
45
+ return true;
46
+ }
47
+
48
+ /**
49
+ * Returns ConsumerBell Recall Manage page URL
50
+ *
51
+ * @return string
52
+ */
53
+ public function getManageUrl()
54
+ {
55
+ return $this->getUrl('adminhtml/consumerbell_recall_catalog');
56
+ }
57
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Form/Element/Button.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Form element BUTTON renderer Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Widget_Form_Element_Button extends Varien_Data_Form_Element_Abstract
24
+ {
25
+ /**
26
+ * Returns BUTTON element HTML content
27
+ *
28
+ * @return string
29
+ */
30
+ public function getElementHtml()
31
+ {
32
+ $attributes = array('name', 'type', 'class', 'title', 'onclick', 'style');
33
+ if ($this->getData('type')) {
34
+ $this->setData('type', 'button');
35
+ }
36
+
37
+ return sprintf('<button id="%s" %s><span><span>%s</span></span></button>%s',
38
+ $this->getHtmlId(),
39
+ $this->serialize($attributes),
40
+ $this->getEscapedValue(),
41
+ $this->getAfterElementHtml());
42
+ }
43
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Grid/Column/Renderer/Link.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Grid LINK column renderer Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Widget_Grid_Column_Renderer_Link
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ /**
27
+ * Returns row HTML value
28
+ *
29
+ * @param Varien_Object $row
30
+ * @return mixed|string
31
+ */
32
+ protected function _getValue(Varien_Object $row)
33
+ {
34
+ $label = $this->getColumn()->getLinkText();
35
+ $value = parent::_getValue($row);
36
+ if (empty($label)) {
37
+ $label = $value;
38
+ }
39
+ $props = '';
40
+ $target = $this->getColumn()->getTarget();
41
+ if ($target) {
42
+ $props .= sprintf(' target="%s"', $target);
43
+ }
44
+
45
+ return sprintf('<a href="%s"%s>%s</a>', $value, $props, $this->escapeHtml($label));
46
+ }
47
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Grid/Column/Renderer/Select.php ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Grid SELECT column renderer Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Widget_Grid_Column_Renderer_Select
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ /**
27
+ * Renders Grid column content
28
+ *
29
+ * @param Varien_Object $row
30
+ * @return string
31
+ */
32
+ public function render(Varien_Object $row)
33
+ {
34
+ $value = $this->_getValue($row);
35
+ $html = sprintf('<select id="%s" name="%s" class="%s">',
36
+ $this->getHtmlId($row), $this->getHtmlName($row), $this->getHtmlClass());
37
+ foreach ($this->getOptions() as $key => $label) {
38
+ $html .= sprintf('<option value="%s"%s>%s</option>',
39
+ $key, ($key == $value ? ' selected="selected"' : ''), $this->escapeHtml($label));
40
+ }
41
+ $html .= '</select>';
42
+
43
+ return $html;
44
+ }
45
+
46
+ /**
47
+ * Returns list of select options
48
+ *
49
+ * @return array
50
+ */
51
+ public function getOptions()
52
+ {
53
+ $options = $this->getColumn()->getOptions();
54
+ if (!is_array($options)) {
55
+ $options = array();
56
+ }
57
+
58
+ return $options;
59
+ }
60
+
61
+ /**
62
+ * Returns HTML attribute id for SELECT tag
63
+ *
64
+ * @param Varien_Object $row
65
+ * @return string
66
+ */
67
+ public function getHtmlId(Varien_Object $row)
68
+ {
69
+ $format = $this->getColumn()->getHtmlIdFormat();
70
+ if (!empty($format)) {
71
+ return sprintf($format, $row->getId());
72
+ }
73
+
74
+ return sprintf('%s_%s', $this->getColumn()->getId(), $row->getId());
75
+ }
76
+
77
+ /**
78
+ * Returns HTML attribute name for SELECT tag
79
+ *
80
+ * @param Varien_Object $row
81
+ * @return string
82
+ */
83
+ public function getHtmlName(Varien_Object $row)
84
+ {
85
+ $format = $this->getColumn()->getHtmlNameFormat();
86
+ if (!empty($format)) {
87
+ return sprintf($format, $row->getId());
88
+ }
89
+
90
+ $name = $this->getColumn()->getName();
91
+ if (!empty($name)) {
92
+ return $name;
93
+ }
94
+
95
+ return sprintf('%s[]', $this->getColumn()->getId());
96
+ }
97
+
98
+ /**
99
+ * Returns HTML attribute class for SELECT tag
100
+ *
101
+ * @return string
102
+ */
103
+ public function getHtmlClass()
104
+ {
105
+ return sprintf('select %s', $this->getColumn()->getValidateClass());
106
+ }
107
+ }
app/code/community/ConsumerBell/Recall/Block/Adminhtml/Widget/Grid/Column/Renderer/Text.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Grid TEXT column renderer Block
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Block_Adminhtml_Widget_Grid_Column_Renderer_Text
24
+ extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
25
+ {
26
+ /**
27
+ * Returns formatted value for row
28
+ *
29
+ * @param Varien_Object $row
30
+ * @return mixed|string
31
+ */
32
+ protected function _getValue(Varien_Object $row)
33
+ {
34
+ $value = parent::_getValue($row);
35
+ if ($this->getColumn()->getNl2br()) {
36
+ $value = nl2br($value);
37
+ }
38
+ if ($this->getColumn()->getEscape()) {
39
+ $value = $this->escapeHtml($value);
40
+ }
41
+
42
+ return $value;
43
+ }
44
+ }
app/code/community/ConsumerBell/Recall/Helper/Data.php ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Data Helper
21
+ */
22
+ class ConsumerBell_Recall_Helper_Data extends Mage_Core_Helper_Abstract
23
+ {
24
+ const XML_PATH_GENERAL_ACTIVE = 'consumerbell_recall/general/active';
25
+ const XML_PATH_GENERAL_API_URL = 'consumerbell_recall/general/api_url';
26
+ const XML_PATH_GENERAL_API_USERNAME = 'consumerbell_recall/general/api_username';
27
+ const XML_PATH_GENERAL_API_PASSWORD = 'consumerbell_recall/general/api_password';
28
+ const XML_PATH_GENERAL_RECALL_ACTION = 'consumerbell_recall/general/recall_action';
29
+
30
+ const XML_PATH_CRON_ACTIVE = 'consumerbell_recall/cron/active';
31
+ const XML_PATH_CRON_EMAIL_RECIPIENT = 'consumerbell_recall/cron/email_recipient';
32
+ const XML_PATH_CRON_EMAIL_IDENTITY = 'consumerbell_recall/cron/email_identity';
33
+ const XML_PATH_CRON_EMAIL_TEMPLATE = 'consumerbell_recall/cron/email_template';
34
+
35
+ const XML_PATH_SYNC_LAST_SYNC = 'consumerbell_recall/sync/last_sync';
36
+ const XML_PATH_SYNC_LAST_RECALL = 'consumerbell_recall/sync/last_recall';
37
+
38
+ /**
39
+ * List of Field Mapping
40
+ *
41
+ * @var array
42
+ */
43
+ protected $_fieldMapping;
44
+
45
+ /**
46
+ * Is field mapping valid flag
47
+ *
48
+ * @var bool
49
+ */
50
+ protected $_isFieldMappingValid;
51
+
52
+ /**
53
+ * Checks if Recall Monitoring is enabled
54
+ *
55
+ * @return bool
56
+ */
57
+ public function isEnabled()
58
+ {
59
+ return Mage::getStoreConfigFlag(self::XML_PATH_GENERAL_ACTIVE);
60
+ }
61
+
62
+ /**
63
+ * Checks if Recall Monitoring cron is enabled
64
+ *
65
+ * @return bool
66
+ */
67
+ public function isCronEnabled()
68
+ {
69
+ return Mage::getStoreConfigFlag(self::XML_PATH_CRON_ACTIVE);
70
+ }
71
+
72
+ /**
73
+ * Returns API URL without last slash
74
+ *
75
+ * @return string
76
+ */
77
+ public function getApiUrl()
78
+ {
79
+ return rtrim(Mage::getStoreConfig(self::XML_PATH_GENERAL_API_URL), '/');
80
+ }
81
+
82
+ /**
83
+ * Returns API Account Login
84
+ *
85
+ * @return string
86
+ */
87
+ public function getApiUsername()
88
+ {
89
+ return (string)Mage::getStoreConfig(self::XML_PATH_GENERAL_API_USERNAME);
90
+ }
91
+
92
+ /**
93
+ * Returns API Account Password
94
+ *
95
+ * @return string
96
+ */
97
+ public function getApiPassword()
98
+ {
99
+ /* @var $helper Mage_Core_Helper_Data */
100
+ $helper = Mage::helper('core');
101
+ $value = (string)Mage::getStoreConfig(self::XML_PATH_GENERAL_API_PASSWORD);
102
+
103
+ return $helper->decrypt($value);
104
+ }
105
+
106
+ /**
107
+ * Returns Cron Email Status Recipient email
108
+ *
109
+ * @return string
110
+ */
111
+ public function getCronEmailRecipient()
112
+ {
113
+ return Mage::getStoreConfig(self::XML_PATH_CRON_EMAIL_RECIPIENT);
114
+ }
115
+
116
+ /**
117
+ * Returns Cron Email Status Template
118
+ *
119
+ * @return string
120
+ */
121
+ public function getCronEmailTemplate()
122
+ {
123
+ return Mage::getStoreConfig(self::XML_PATH_CRON_EMAIL_TEMPLATE);
124
+ }
125
+
126
+ /**
127
+ * Returns Cron Email Status Sender
128
+ *
129
+ * @return string
130
+ */
131
+ public function getCronEmailIdentity()
132
+ {
133
+ return Mage::getStoreConfig(self::XML_PATH_CRON_EMAIL_IDENTITY);
134
+ }
135
+
136
+ /**
137
+ * Returns recall action
138
+ *
139
+ * @return string
140
+ */
141
+ public function getRecallAction()
142
+ {
143
+ return Mage::getStoreConfig(self::XML_PATH_GENERAL_RECALL_ACTION);
144
+ }
145
+
146
+ /**
147
+ * Check if field mapping are not empty and defined
148
+ *
149
+ * @return bool
150
+ */
151
+ public function isFieldMappingValid()
152
+ {
153
+ $this->getFieldMapping();
154
+
155
+ return $this->_isFieldMappingValid;
156
+ }
157
+
158
+ /**
159
+ * Returns list of field mapping
160
+ *
161
+ * @return array
162
+ */
163
+ public function getFieldMapping()
164
+ {
165
+ if ($this->_fieldMapping !== null) {
166
+ return $this->_fieldMapping;
167
+ }
168
+
169
+ $this->_isFieldMappingValid = true;
170
+
171
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Map_Collection */
172
+ $collection = Mage::getResourceModel('consumerbell_recall/map_collection');
173
+ $collection->setPositionOrder();
174
+ foreach ($collection->getItems() as $map) {
175
+ if ($map->getAttributeId() === null) {
176
+ $this->_isFieldMappingValid = false;
177
+ }
178
+ $this->_fieldMapping[$map->getField()] = $map->getAttributeId();
179
+ }
180
+
181
+ if (empty($this->_fieldMapping)) {
182
+ $this->_isFieldMappingValid = false;
183
+ }
184
+
185
+ return $this->_fieldMapping;
186
+ }
187
+
188
+ /**
189
+ * Returns last sync time
190
+ *
191
+ * @return int|null
192
+ */
193
+ public function getLastSync()
194
+ {
195
+ $value = (string)Mage::getStoreConfig(self::XML_PATH_SYNC_LAST_SYNC);
196
+ if (empty($value)) {
197
+ $value = null;
198
+ }
199
+
200
+ return $value;
201
+ }
202
+
203
+ /**
204
+ * Sets last sync time
205
+ *
206
+ * @return ConsumerBell_Recall_Helper_Data
207
+ */
208
+ public function setLastSync()
209
+ {
210
+ Mage::getConfig()->saveConfig(self::XML_PATH_SYNC_LAST_SYNC, time());
211
+ Mage::getConfig()->cleanCache();
212
+
213
+ return $this;
214
+ }
215
+
216
+ /**
217
+ * Returns last sync time
218
+ *
219
+ * @return int|null
220
+ */
221
+ public function getLastRecall()
222
+ {
223
+ $value = (string)Mage::getStoreConfig(self::XML_PATH_SYNC_LAST_RECALL);
224
+ if (empty($value)) {
225
+ $value = null;
226
+ }
227
+
228
+ return $value;
229
+ }
230
+
231
+ /**
232
+ * Sets last sync time
233
+ *
234
+ * @return ConsumerBell_Recall_Helper_Data
235
+ */
236
+ public function setLastRecall()
237
+ {
238
+ Mage::getConfig()->saveConfig(self::XML_PATH_SYNC_LAST_RECALL, time());
239
+ Mage::getConfig()->cleanCache();
240
+
241
+ return $this;
242
+ }
243
+ }
app/code/community/ConsumerBell/Recall/Model/Cron.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Cron Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_Cron
24
+ {
25
+ /**
26
+ * Data Helper instance
27
+ *
28
+ * @var ConsumerBell_Recall_Helper_Data
29
+ */
30
+ protected $_helper;
31
+
32
+ /**
33
+ * ConsumerBell Recall Service Model
34
+ *
35
+ * @var ConsumerBell_Recall_Model_Service
36
+ */
37
+ protected $_service;
38
+
39
+ /**
40
+ * Count of synced products
41
+ *
42
+ * @var int
43
+ */
44
+ protected $_synced = 0;
45
+
46
+ /**
47
+ * List of recalled items
48
+ *
49
+ * @var ConsumerBell_Recall_Model_Status[]
50
+ */
51
+ protected $_recalled = array();
52
+
53
+ /**
54
+ * Last error message
55
+ *
56
+ * @var string
57
+ */
58
+ protected $_error = null;
59
+
60
+ /**
61
+ * Initializes Model
62
+ *
63
+ */
64
+ public function __construct()
65
+ {
66
+ $this->_helper = Mage::helper('consumerbell_recall');
67
+ $this->_service = Mage::getSingleton('consumerbell_recall/service');
68
+ }
69
+
70
+ /**
71
+ * Sends Status email
72
+ *
73
+ */
74
+ protected function _sendEmail()
75
+ {
76
+ $recipient = $this->_helper->getCronEmailRecipient();
77
+ if (!$recipient) {
78
+ return;
79
+ }
80
+ $identity = $this->_helper->getCronEmailIdentity();
81
+ $template = $this->_helper->getCronEmailTemplate();
82
+
83
+ /* @var $translate Mage_Core_Model_Translate */
84
+ $translate = Mage::getSingleton('core/translate');
85
+ $translate->setTranslateInline(false);
86
+
87
+ /* @var $emailTemplate Mage_Core_Model_Email_Template */
88
+ $emailTemplate = Mage::getModel('core/email_template');
89
+ $emailTemplate->setDesignConfig(array('area' => 'backend'));
90
+
91
+ if ($this->_recalled) {
92
+ /* @var $appEmulation Mage_Core_Model_App_Emulation */
93
+ $appEmulation = Mage::getSingleton('core/app_emulation');
94
+ $envInfo = $appEmulation->startEnvironmentEmulation(Mage_Core_Model_App::ADMIN_STORE_ID,
95
+ Mage_Core_Model_App_Area::AREA_ADMINHTML);
96
+
97
+ $block = Mage::app()->getLayout()->createBlock('adminhtml/template', 'email', array(
98
+ 'template' => 'consumerbell/recall/cron/status_grid.phtml',
99
+ 'recalled' => $this->_recalled,
100
+ ));
101
+
102
+ $grid = $block->toHtml();
103
+ $appEmulation->stopEnvironmentEmulation($envInfo);
104
+ } else {
105
+ $grid = false;
106
+ }
107
+
108
+ $emailTemplate->sendTransactional($template, $identity, $recipient, null, array(
109
+ 'error' => $this->_error,
110
+ 'synced' => $this->_synced,
111
+ 'recalled_grid' => $grid,
112
+ ));
113
+ $translate->setTranslateInline(true);
114
+
115
+ }
116
+
117
+ /**
118
+ * Run cron process
119
+ *
120
+ */
121
+ public function run()
122
+ {
123
+ if (!$this->_helper->isEnabled() || !$this->_helper->isCronEnabled()) {
124
+ return;
125
+ }
126
+
127
+ if (!$this->_helper->isFieldMappingValid()) {
128
+ return;
129
+ }
130
+
131
+ try {
132
+ if ($this->_service->getProductCountToSync()) {
133
+ $this->_synced = $this->_service->sync();
134
+ }
135
+
136
+ $this->_recalled = $this->_service->check();
137
+ } catch (Mage_Core_Exception $e) {
138
+ $this->_error = $e->getMessage();
139
+ } catch (Exception $e) {
140
+ Mage::logException($e);
141
+ $this->_error = $e->getMessage();
142
+ }
143
+
144
+ $this->_sendEmail();
145
+ }
146
+ }
app/code/community/ConsumerBell/Recall/Model/Info.php ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Info Model
21
+ *
22
+ * @method ConsumerBell_Recall_Model_Resource_Info _getResource()
23
+ * @method ConsumerBell_Recall_Model_Resource_Info getResource()
24
+ * @method ConsumerBell_Recall_Model_Resource_Info_Collection getCollection()
25
+ * @method ConsumerBell_Recall_Model_Resource_Info_Collection getResourceCollection()
26
+ *
27
+ * @method ConsumerBell_Recall_Model_Info setInfoId(int $value)
28
+ * @method int getInfoId()
29
+ * @method ConsumerBell_Recall_Model_Info setRecallId(int $value)
30
+ * @method int getRecallId()
31
+ * @method ConsumerBell_Recall_Model_Info setUrl(string $value)
32
+ * @method string getUrl()
33
+ * @method ConsumerBell_Recall_Model_Info setUpdatedAt(string $value)
34
+ * @method string getUpdatedAt()
35
+ */
36
+ class ConsumerBell_Recall_Model_Info extends Mage_Core_Model_Abstract
37
+ {
38
+ /**
39
+ * Define Resource Model
40
+ */
41
+ public function _construct()
42
+ {
43
+ $this->_eventPrefix = 'consumerbell_recall_info';
44
+ $this->_init('consumerbell_recall/info');
45
+ }
46
+
47
+ /**
48
+ * Sets Recall instance
49
+ *
50
+ * @param ConsumerBell_Recall_Model_Status $recall
51
+ * @return $this
52
+ */
53
+ public function setRecall(ConsumerBell_Recall_Model_Status $recall)
54
+ {
55
+ if ($this->getRecallId() == $recall->getId()) {
56
+ $this->setData('recall', $recall);
57
+ }
58
+
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * Returns Recall instance or false
64
+ *
65
+ * @return bool|ConsumerBell_Recall_Model_Status
66
+ */
67
+ public function getRecall()
68
+ {
69
+ if (!$this->getRecallId()) {
70
+ return false;
71
+ }
72
+
73
+ $recall = $this->_getData('recall');
74
+ if ($recall === null) {
75
+ /* @var $recall ConsumerBell_Recall_Model_Status */
76
+ $recall = Mage::getModel('consumerbell_recall/status');
77
+ $recall->load($this->getRecallId());
78
+
79
+ $this->setRecall($recall);
80
+ }
81
+
82
+ return $recall;
83
+ }
84
+ }
app/code/community/ConsumerBell/Recall/Model/Map.php ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Field Mapping Model
21
+ *
22
+ * @method ConsumerBell_Recall_Model_Resource_Map _getResource()
23
+ * @method ConsumerBell_Recall_Model_Resource_Map getResource()
24
+ * @method ConsumerBell_Recall_Model_Resource_Map_Collection getCollection()
25
+ * @method ConsumerBell_Recall_Model_Resource_Map_Collection getResourceCollection()
26
+ *
27
+ * @method ConsumerBell_Recall_Model_Map setField(string $value)
28
+ * @method string getField()
29
+ * @method ConsumerBell_Recall_Model_Map setName(string $value)
30
+ * @method string getName()
31
+ * @method ConsumerBell_Recall_Model_Map setPosition(int $value)
32
+ * @method int getPosition()
33
+ * @method ConsumerBell_Recall_Model_Map setAttributeId(int $value)
34
+ * @method int getAttributeId()
35
+ */
36
+ class ConsumerBell_Recall_Model_Map extends Mage_Core_Model_Abstract
37
+ {
38
+ const PRODUCT_ID_ATTRIBUTE = 'id';
39
+
40
+ /**
41
+ * Define Resource Model
42
+ */
43
+ public function _construct()
44
+ {
45
+ $this->_eventPrefix = 'consumerbell_recall_map';
46
+ $this->_init('consumerbell_recall/map');
47
+ }
48
+
49
+ /**
50
+ * Syncs Field Mapping with API
51
+ */
52
+ public function sync()
53
+ {
54
+ /* @var $service ConsumerBell_Recall_Model_Service_Api */
55
+ $service = Mage::getSingleton('consumerbell_recall/service_api');
56
+ $fields = $service->getFields();
57
+
58
+ if ($fields === false) {
59
+ Mage::throwException($service->getLastError());
60
+ }
61
+
62
+ if (isset($fields[self::PRODUCT_ID_ATTRIBUTE])) {
63
+ unset($fields[self::PRODUCT_ID_ATTRIBUTE]);
64
+ }
65
+
66
+ $collection = $this->getCollection();
67
+ foreach ($collection->getItems() as $map) {
68
+ if (isset($fields[$map->getField()])) {
69
+ $data = $fields[$map->getField()];
70
+ $map->setPosition($data['position']);
71
+ $map->setName($data['name']);
72
+ $map->save();
73
+
74
+ unset($fields[$map->getField()]);
75
+ } else {
76
+ $map->delete();
77
+ }
78
+ }
79
+
80
+ foreach ($fields as $data) {
81
+ /* @var $map ConsumerBell_Recall_Model_Map */
82
+ $map = Mage::getModel('consumerbell_recall/map');
83
+ $map->setField($data['field']);
84
+ $map->setName($data['name']);
85
+ $map->setPosition($data['position']);
86
+ $map->save();
87
+ }
88
+ }
89
+ }
app/code/community/ConsumerBell/Recall/Model/Observer.php ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Observer Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_Observer
24
+ {
25
+ /**
26
+ * Uploads Catalog Products and Recall status
27
+ *
28
+ * Cron Job process
29
+ */
30
+ public function update()
31
+ {
32
+ /* @var $cron ConsumerBell_Recall_Model_Cron */
33
+ $cron = Mage::getModel('consumerbell_recall/cron');
34
+ $cron->run();
35
+ }
36
+
37
+ /**
38
+ * Shows admin notice message if product is recalled
39
+ *
40
+ * @param Varien_Event_Observer $observer
41
+ */
42
+ public function catalogProductEditAction(Varien_Event_Observer $observer)
43
+ {
44
+ /** @var $product Mage_Catalog_Model_Product */
45
+ $product = $observer->getEvent()->getProduct();
46
+
47
+ /* @var $helper ConsumerBell_Recall_Helper_Data */
48
+ $helper = Mage::helper('consumerbell_recall');
49
+ if (!$helper->isEnabled()) {
50
+ return;
51
+ }
52
+
53
+ /* @var $status ConsumerBell_Recall_Model_Status */
54
+ $status = Mage::getModel('consumerbell_recall/status');
55
+ $status->loadByProduct($product);
56
+
57
+ if (!$status->getId()) {
58
+ return;
59
+ }
60
+
61
+ $product->setData('consumerbell_recall_status', $status);
62
+
63
+ /* @var $helper Mage_Core_Helper_Data */
64
+ $helper = Mage::helper('core');
65
+ /* @var $session Mage_Adminhtml_Model_Session */
66
+ /*
67
+ $session = Mage::getSingleton('adminhtml/session');
68
+ $session->addNotice(Mage::helper('consumerbell_recall')->__('This product was updated as recalled on %1$s '
69
+ . '<a href="%2$s">click here</a> for more info',
70
+ $helper->formatDate($status->getUpdatedAt(), Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, false),
71
+ $helper->escapeUrl($status->getUrl())
72
+ ));
73
+ */
74
+ }
75
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Info.php ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Info Resource Model
21
+ */
22
+ class ConsumerBell_Recall_Model_Resource_Info extends Mage_Core_Model_Mysql4_Abstract
23
+ {
24
+ /**
25
+ * Define Resource Table
26
+ */
27
+ public function _construct()
28
+ {
29
+ $this->_init('consumerbell_recall/info', 'info_id');
30
+ }
31
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Info/Collection.php ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Info Resource Collection
21
+ *
22
+ * @property ConsumerBell_Recall_Model_Info[] $_items
23
+ * @method ConsumerBell_Recall_Model_Info[] getItems()
24
+ * @method ConsumerBell_Recall_Model_Info getNewEmptyItem()
25
+ * @method ConsumerBell_Recall_Model_Info getItemById()
26
+ * @method ConsumerBell_Recall_Model_Info getFirstItem()
27
+ * @method ConsumerBell_Recall_Model_Info getLastItem()
28
+ */
29
+ class ConsumerBell_Recall_Model_Resource_Info_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
30
+ {
31
+ /**
32
+ * Define Model for collection
33
+ */
34
+ public function _construct()
35
+ {
36
+ $this->_init('consumerbell_recall/info');
37
+ }
38
+
39
+ /**
40
+ * Adds filter by recall to collection
41
+ *
42
+ * @param int[]|int|ConsumerBell_Recall_Model_Status $recall
43
+ * @return $this
44
+ */
45
+ public function addRecallFilter($recall)
46
+ {
47
+ if ($recall instanceof ConsumerBell_Recall_Model_Status) {
48
+ $condition = (int)$recall->getRecallId();
49
+ } else if (is_array($recall)) {
50
+ $condition = array('in' => $recall);
51
+ } else {
52
+ $condition = (int)$recall;
53
+ }
54
+
55
+ $this->addFieldToFilter('main_table.recall_id', $condition);
56
+
57
+ return $this;
58
+ }
59
+
60
+ /**
61
+ * Sets order by Updated At to Collection
62
+ *
63
+ * @param string $direction
64
+ * @return $this
65
+ */
66
+ public function setUpdatedAtSort($direction = self::SORT_ORDER_DESC)
67
+ {
68
+ return $this->setOrder('main_table.updated_at', $direction);
69
+ }
70
+
71
+ /**
72
+ * Adds Consumer Bell Recall Status data to collection
73
+ *
74
+ * @return $this
75
+ */
76
+ public function addRecallData()
77
+ {
78
+ $flag = 'consumerbell_recall_status_joined';
79
+ if (!$this->getFlag($flag)) {
80
+ $this->setFlag($flag, true);
81
+
82
+ $this->getSelect()->joinLeft(
83
+ array('cbr_s' => $this->getTable('consumerbell_recall/status')),
84
+ 'main_table.recall_id = cbr_s.recall_id',
85
+ array(
86
+ 'product_id',
87
+ 'sku',
88
+ 'action',
89
+ )
90
+ );
91
+
92
+ $this->addFilterToMap('sku', 'cbr_s.sku');
93
+ $this->addFilterToMap('action', 'cbr_s.action');
94
+ }
95
+
96
+ return $this;
97
+ }
98
+
99
+ /**
100
+ * Adds product data to collection
101
+ *
102
+ * @return $this
103
+ */
104
+ public function addProductData()
105
+ {
106
+ $flag = 'catalog_product_joined';
107
+ if (!$this->getFlag($flag)) {
108
+ $this->addRecallData();
109
+
110
+ $this->getSelect()->joinLeft(
111
+ array('cp' => $this->getTable('catalog/product')),
112
+ 'cbr_s.product_id = cp.entity_id',
113
+ array()
114
+ );
115
+
116
+ $this->_addProductAttributeData('name', 'product_name');
117
+ $this->_addProductAttributeData('status', 'product_status');
118
+ $this->_addProductStock();
119
+
120
+ $this->addFilterToMap('updated_at', 'main_table.updated_at');
121
+
122
+ $this->setFlag($flag, true);
123
+ }
124
+
125
+ return $this;
126
+ }
127
+
128
+ /**
129
+ * Adds CatalogInventory stock item value to collection result
130
+ *
131
+ * @return $this
132
+ */
133
+ protected function _addProductStock()
134
+ {
135
+ $manage = Mage::getStoreConfig(Mage_CatalogInventory_Model_Stock_Item::XML_PATH_MANAGE_STOCK);
136
+ if ($manage) {
137
+ $expr = new Zend_Db_Expr('IF(ci_si.use_config_manage_stock = 0,'
138
+ . ' IF(ci_si.manage_stock = 1, ci_si.is_in_stock, 1), ci_si.is_in_stock)');
139
+ } else {
140
+ $expr = new Zend_Db_Expr('IF(ci_si.use_config_manage_stock = 0,'
141
+ . ' IF(ci_si.manage_stock = 1, ci_si.is_in_stock, 1), 1)');
142
+ }
143
+
144
+ $this->getSelect()->joinLeft(
145
+ array('ci_si' => $this->getTable('cataloginventory/stock_item')),
146
+ 'cbr_s.product_id = ci_si.product_id',
147
+ array(
148
+ 'product_stock' => $expr,
149
+ )
150
+ );
151
+ $this->getSelect()->where('ci_si.stock_id = ?', Mage_CatalogInventory_Model_Stock::DEFAULT_STOCK_ID);
152
+
153
+ $this->addFilterToMap('product_stock', $expr);
154
+
155
+ return $this;
156
+ }
157
+
158
+ /**
159
+ * Adds Catalog Product attribute value to result
160
+ *
161
+ * @param string $attributeCode
162
+ * @param string|null $attributeAlias
163
+ * @return $this
164
+ */
165
+ protected function _addProductAttributeData($attributeCode, $attributeAlias = null)
166
+ {
167
+ /* @var $eavConfig Mage_Eav_Model_Config */
168
+ $eavConfig = Mage::getSingleton('eav/config');
169
+ $attribute = $eavConfig->getAttribute('catalog_product', $attributeCode);
170
+
171
+ if (!$attribute->getId()) {
172
+ return $this;
173
+ }
174
+
175
+ if ($attributeAlias === null) {
176
+ $attributeAlias = $attributeCode;
177
+ }
178
+
179
+ $table = $attribute->getBackend()->getTable();
180
+ $alias = sprintf('cpa%d', $attribute->getId());
181
+
182
+ $this->getSelect()->joinLeft(
183
+ array($alias => $table),
184
+ sprintf('cbr_s.product_id = %1$s.entity_id AND %1$s.attribute_id = %2$d AND %1$s.store_id = 0',
185
+ $alias, $attribute->getId()),
186
+ array($attributeAlias => sprintf('%s.value', $alias))
187
+ );
188
+
189
+ $this->addFilterToMap($attributeAlias, sprintf('%s.value', $alias));
190
+
191
+ return $this;
192
+ }
193
+
194
+ /**
195
+ * Assigns Recall instance to collection items
196
+ *
197
+ * @return $this
198
+ */
199
+ protected function _afterLoad()
200
+ {
201
+ parent::_afterLoad();
202
+
203
+ if ($this->getFlag('consumerbell_recall_status_joined')) {
204
+ /* @var $status ConsumerBell_Recall_Model_Status */
205
+ $status = Mage::getModel('consumerbell_recall/status');
206
+ foreach ($this->_items as $item) {
207
+ $recall = clone $status;
208
+ $recall->setData(array(
209
+ 'recall_id' => $item->getData('recall_id'),
210
+ 'product_id' => $item->getData('product_id'),
211
+ 'sku' => $item->getData('sku'),
212
+ 'action' => $item->getData('action'),
213
+ ));
214
+
215
+ if ($this->getFlag('catalog_product_joined')) {
216
+ $recall->addData(array(
217
+ 'product_name' => $item->getData('product_name'),
218
+ 'product_status' => $item->getData('product_status'),
219
+ 'product_stock' => $item->getData('product_stock'),
220
+ ));
221
+ }
222
+
223
+ $recall->setOrigData();
224
+
225
+ $item->setRecall($recall);
226
+ }
227
+ }
228
+
229
+ return $this;
230
+ }
231
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Map.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Field Mapping Resource Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_Resource_Map extends Mage_Core_Model_Mysql4_Abstract
24
+ {
25
+ /**
26
+ * Define Resource Table
27
+ *
28
+ */
29
+ public function _construct()
30
+ {
31
+ $this->_isPkAutoIncrement = false;
32
+ $this->_init('consumerbell_recall/map', 'field');
33
+ }
34
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Map/Collection.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Field Mapping Resource Collection
21
+ *
22
+ * @property ConsumerBell_Recall_Model_Map[] $_items
23
+ * @method ConsumerBell_Recall_Model_Map[] getItems()
24
+ * @method ConsumerBell_Recall_Model_Map getItemById()
25
+ * @method ConsumerBell_Recall_Model_Map getFirstItem()
26
+ * @method ConsumerBell_Recall_Model_Map getLastItem()
27
+ */
28
+ class ConsumerBell_Recall_Model_Resource_Map_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
29
+ {
30
+ /**
31
+ * Define Model for collection
32
+ */
33
+ public function _construct()
34
+ {
35
+ $this->_init('consumerbell_recall/map');
36
+ }
37
+
38
+ /**
39
+ * Sets order by position to collection
40
+ *
41
+ * @param string $direction
42
+ * @return ConsumerBell_Recall_Model_Resource_Map_Collection
43
+ */
44
+ public function setPositionOrder($direction = self::SORT_ORDER_ASC)
45
+ {
46
+ $this->setOrder('position', $direction);
47
+
48
+ return $this;
49
+ }
50
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Setup.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Resource setup Model
21
+ */
22
+ class ConsumerBell_Recall_Model_Resource_Setup extends Mage_Catalog_Model_Resource_Eav_Mysql4_Setup
23
+ {
24
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Status.php ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Status Resource Model
21
+ */
22
+ class ConsumerBell_Recall_Model_Resource_Status extends Mage_Core_Model_Mysql4_Abstract
23
+ {
24
+ /**
25
+ * Define Resource Table
26
+ */
27
+ public function _construct()
28
+ {
29
+ $this->_init('consumerbell_recall/status', 'recall_id');
30
+ }
31
+
32
+ /**
33
+ * Returns Product Name
34
+ *
35
+ * @param ConsumerBell_Recall_Model_Status $object
36
+ * @return string
37
+ */
38
+ public function getProductName($object)
39
+ {
40
+ if (!$object->getProductId()) {
41
+ return '';
42
+ }
43
+
44
+ return $this->_getProductAttributeValue($object->getProductId(), 'name');
45
+ }
46
+
47
+ /**
48
+ * Returns Product Status
49
+ *
50
+ * @param ConsumerBell_Recall_Model_Status $object
51
+ * @return string
52
+ */
53
+ public function getProductStatus($object)
54
+ {
55
+ if (!$object->getProductId()) {
56
+ return '';
57
+ }
58
+
59
+ return $this->_getProductAttributeValue($object->getProductId(), 'status');
60
+ }
61
+
62
+ /**
63
+ * Returns Product Attribute value
64
+ *
65
+ * @param int $productId
66
+ * @param string $attributeCode
67
+ * @return string
68
+ */
69
+ protected function _getProductAttributeValue($productId, $attributeCode)
70
+ {
71
+ /* @var $eavConfig Mage_Eav_Model_Config */
72
+ $eavConfig = Mage::getSingleton('eav/config');
73
+ $attribute = $eavConfig->getAttribute('catalog_product', $attributeCode);
74
+ if (!$attribute->getId()) {
75
+ return '';
76
+ }
77
+
78
+ $adapter = $this->_getReadAdapter();
79
+ $table = $attribute->getBackend()->getTable();
80
+ $select = $adapter->select()
81
+ ->from($table, 'value')
82
+ ->where('attribute_id = :attribute_id')
83
+ ->where('entity_id = :entity_id')
84
+ ->where('store_id = 0')
85
+ ->where('entity_type_id = :entity_type_id');
86
+ $bind = array(
87
+ ':entity_type_id' => $attribute->getEntityTypeId(),
88
+ ':entity_id' => $productId,
89
+ ':attribute_id' => $attribute->getId(),
90
+ );
91
+
92
+ return $adapter->fetchOne($select, $bind);
93
+ }
94
+
95
+ /**
96
+ * Checks if product is exists
97
+ *
98
+ * @param int $productId
99
+ * @return bool
100
+ */
101
+ public function checkProductId($productId)
102
+ {
103
+ $adapter = $this->_getReadAdapter();
104
+ $select = $adapter->select()
105
+ ->from($this->getTable('catalog/product'), 'entity_id')
106
+ ->where('entity_id = :entity_id');
107
+ $bind = array(
108
+ ':entity_id' => $productId,
109
+ );
110
+
111
+ return $adapter->fetchOne($select, $bind) ? true : false;
112
+ }
113
+ }
app/code/community/ConsumerBell/Recall/Model/Resource/Status/Collection.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Status Resource Collection
21
+ *
22
+ * @property ConsumerBell_Recall_Model_Status[] $_items
23
+ * @method ConsumerBell_Recall_Model_Status[] getItems()
24
+ * @method ConsumerBell_Recall_Model_Status getItemById()
25
+ * @method ConsumerBell_Recall_Model_Status getFirstItem()
26
+ * @method ConsumerBell_Recall_Model_Status getLastItem()
27
+ */
28
+ class ConsumerBell_Recall_Model_Resource_Status_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
29
+ {
30
+ /**
31
+ * Define Model for collection
32
+ */
33
+ public function _construct()
34
+ {
35
+ $this->_init('consumerbell_recall/status');
36
+ }
37
+ }
app/code/community/ConsumerBell/Recall/Model/Service.php ADDED
@@ -0,0 +1,445 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Service Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_Service
24
+ {
25
+ const ACTION_NO_ACTION = '0';
26
+ const ACTION_OUT_OF_STOCK = '1';
27
+ const ACTION_DISABLE = '2';
28
+
29
+ const COLLECTION_LIMIT = 1000;
30
+
31
+ /**
32
+ * ConsumerBell Recall Data Helper
33
+ *
34
+ * @var ConsumerBell_Recall_Helper_Data
35
+ */
36
+ protected $_helper;
37
+
38
+ /**
39
+ * ConsumerBell Recall Service API instance
40
+ *
41
+ * @var ConsumerBell_Recall_Model_Service_Api
42
+ */
43
+ protected $_api;
44
+
45
+ /**
46
+ * Returns ConsumerBell Recall Data Helper
47
+ *
48
+ * @return ConsumerBell_Recall_Helper_Data
49
+ */
50
+ protected function _getHelper()
51
+ {
52
+ if ($this->_helper === null) {
53
+ $this->_helper = Mage::helper('consumerbell_recall');
54
+ }
55
+
56
+ return $this->_helper;
57
+ }
58
+
59
+ /**
60
+ * Returns ConsumerBell Recall Service API instance
61
+ *
62
+ * @return ConsumerBell_Recall_Model_Service_Api
63
+ */
64
+ protected function _getApi()
65
+ {
66
+ if ($this->_api === null) {
67
+ $this->_api = Mage::getSingleton('consumerbell_recall/service_api');
68
+ }
69
+
70
+ return $this->_api;
71
+ }
72
+
73
+ /**
74
+ * Adds ConsumerBell Recall Fields to collection
75
+ *
76
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
77
+ * @return ConsumerBell_Recall_Model_Service
78
+ */
79
+ protected function _addFieldsToCollection($collection)
80
+ {
81
+ /* @var $eavConfig Mage_Eav_Model_Config */
82
+ $eavConfig = Mage::getSingleton('eav/config');
83
+ $attributes = array();
84
+
85
+ foreach ($this->_getHelper()->getFieldMapping() as $attributeId) {
86
+ if ($attributeId == '0') {
87
+ continue;
88
+ }
89
+ $attribute = $eavConfig->getAttribute('catalog_product', $attributeId);
90
+ if ($attribute->getAttributeCode()) {
91
+ $attributes[] = $attribute->getAttributeCode();
92
+ }
93
+ }
94
+
95
+ if ($attributes) {
96
+ $collection->addAttributeToSelect($attributes);
97
+ }
98
+
99
+ return $this;
100
+ }
101
+
102
+ /**
103
+ * Adds Last Sync Filter to Product collection
104
+ *
105
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
106
+ * @return ConsumerBell_Recall_Model_Service
107
+ */
108
+ protected function _addLastSyncFilterToCollection($collection)
109
+ {
110
+ $lastTime = $this->_getHelper()->getLastSync();
111
+ $lastTime = $this->_formatDate($lastTime);
112
+
113
+ if ($lastTime !== null) {
114
+ $collection->addAttributeToFilter('updated_at', array(
115
+ 'from' => $lastTime,
116
+ ));
117
+ }
118
+
119
+ return $this;
120
+ }
121
+
122
+ /**
123
+ * Adds only allowed to upload products filter to collection
124
+ *
125
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
126
+ * @return ConsumerBell_Recall_Model_Service
127
+ */
128
+ protected function _addRecallFilterToCollection($collection)
129
+ {
130
+ $collection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED);
131
+
132
+ return $this;
133
+ }
134
+
135
+ /**
136
+ * Returns how many catalog product need to sync
137
+ *
138
+ * @return int
139
+ */
140
+ public function getProductCountToSync()
141
+ {
142
+ /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
143
+ $collection = Mage::getResourceModel('catalog/product_collection');
144
+ $this->_addRecallFilterToCollection($collection);
145
+ $this->_addLastSyncFilterToCollection($collection);
146
+
147
+ return $collection->getSize();
148
+ }
149
+
150
+ /**
151
+ * Returns Catalog Product Collection
152
+ *
153
+ * @return Mage_Catalog_Model_Resource_Product_Collection
154
+ */
155
+ public function getProductCollection()
156
+ {
157
+ /* @var $collection Mage_Catalog_Model_Resource_Product_Collection */
158
+ $collection = Mage::getResourceModel('catalog/product_collection');
159
+ $this->_addRecallFilterToCollection($collection);
160
+ $this->_addFieldsToCollection($collection);
161
+ $this->_addLastSyncFilterToCollection($collection);
162
+ $collection->setOrder('entity_id', 'ASC');
163
+ $collection->setPageSize(self::COLLECTION_LIMIT);
164
+
165
+ return $collection;
166
+ }
167
+
168
+ /**
169
+ * Check if can run sync process
170
+ *
171
+ * @return bool
172
+ */
173
+ public function canSync()
174
+ {
175
+ return $this->_getHelper()->isEnabled() && $this->_getHelper()->isFieldMappingValid();
176
+ }
177
+
178
+ /**
179
+ * Uploads catalog products to API
180
+ *
181
+ * @throws Mage_Core_Exception
182
+ * @return int Count of synced products
183
+ */
184
+ public function sync()
185
+ {
186
+ $source = $this->getProductCollection();
187
+ $count = null;
188
+ $page = 1;
189
+ $lPage = null;
190
+ $break = false;
191
+ $synced = 0;
192
+
193
+ while ($break !== true) {
194
+ $collection = clone $source;
195
+ $collection->setCurPage($page);
196
+ $collection->load();
197
+ if (is_null($count)) {
198
+ $count = $collection->getSize();
199
+ $lPage = $collection->getLastPageNumber();
200
+ }
201
+ if ($lPage == $page) {
202
+ $break = true;
203
+ }
204
+ $page ++;
205
+
206
+ $synced += $this->_upload($collection);
207
+ }
208
+
209
+ $this->_getHelper()->setLastSync();
210
+
211
+ return $synced;
212
+ }
213
+
214
+ /**
215
+ * Uploads Catalog Products to API
216
+ *
217
+ * @throws Mage_Core_Exception
218
+ * @param Mage_Catalog_Model_Resource_Product_Collection $collection
219
+ * @return int Count of uploaded products
220
+ */
221
+ protected function _upload($collection)
222
+ {
223
+ /* @var $eavConfig Mage_Eav_Model_Config */
224
+ $eavConfig = Mage::getSingleton('eav/config');
225
+ /** @var $attributes Mage_Catalog_Model_Resource_Eav_Attribute[] */
226
+ $attributes = array();
227
+
228
+ foreach ($this->_getHelper()->getFieldMapping() as $field => $attributeId) {
229
+ if ($attributeId == '0') {
230
+ $attribute = null;
231
+ } else {
232
+ $attribute = $eavConfig->getAttribute('catalog_product', $attributeId);
233
+ }
234
+
235
+ $attributes[$field] = $attribute;
236
+ }
237
+
238
+ $count = 0;
239
+ $delimiter = ',';
240
+ $enclosure = '"';
241
+ $stream = fopen('php://temp', 'r+');
242
+ $header = array_merge(array(ConsumerBell_Recall_Model_Map::PRODUCT_ID_ATTRIBUTE), array_keys($attributes));
243
+
244
+ fputcsv($stream, $header, $delimiter, $enclosure);
245
+ /** @var $product Mage_Catalog_Model_Product */
246
+ foreach ($collection as $product) {
247
+ $count ++;
248
+ $data = array(
249
+ $product->getId(),
250
+ );
251
+ foreach ($attributes as $attribute) {
252
+ if ($attribute === null) {
253
+ $value = '';
254
+ } else {
255
+ $value = $product->getData($attribute->getAttributeCode());
256
+ if ($attribute->usesSource()) {
257
+ $value = $attribute->getSource()->getOptionText($value);
258
+ }
259
+ }
260
+ $data[] = $value;
261
+ }
262
+ fputcsv($stream, $data, $delimiter, $enclosure);
263
+ }
264
+
265
+ $content = '';
266
+ rewind($stream);
267
+ while (feof($stream) === false) {
268
+ $content .= fgets($stream);
269
+ }
270
+ fclose($stream);
271
+
272
+ $result = $this->_getApi()->upload($content);
273
+ if ($result === false) {
274
+ Mage::throwException($this->_getApi()->getLastError());
275
+ }
276
+
277
+ return $count;
278
+ }
279
+
280
+ /**
281
+ * Returns new recalled products
282
+ *
283
+ * @return ConsumerBell_Recall_Model_Status[]
284
+ */
285
+ public function check()
286
+ {
287
+ $result = array();
288
+ $items = $this->_getApi()->getStatus();
289
+ /* @var $resource Mage_Catalog_Model_Resource_Product */
290
+ $resource = Mage::getResourceModel('catalog/product');
291
+
292
+ foreach ($items as $item) {
293
+ /* @var $status ConsumerBell_Recall_Model_Status */
294
+ $status = Mage::getModel('consumerbell_recall/status');
295
+ $productId = null;
296
+ if (!empty($item->id) && $status->checkProductId($item->id)) {
297
+ $status->loadByProduct($item->id);
298
+ $productId = $item->id;
299
+ }
300
+
301
+ if (!$status->getId()) {
302
+ $status->loadBySku($item->sku);
303
+ }
304
+
305
+ if ($productId === null) {
306
+ // try to find product by sku
307
+ $productId = $resource->getIdBySku($item->sku);
308
+ }
309
+ $status->setSku($item->sku);
310
+ $status->setProductId(empty($productId) ? null : $productId);
311
+ $this->_recallInfoUrl($status, $item);
312
+ $this->_recall($status);
313
+ $status->save();
314
+
315
+ $result[] = $status;
316
+ }
317
+
318
+ $this->_getHelper()->setLastRecall();
319
+
320
+ return $result;
321
+ }
322
+
323
+ /**
324
+ * Assigns Info URLs to status
325
+ *
326
+ * @param ConsumerBell_Recall_Model_Status $status
327
+ * @param stdClass $item
328
+ * @return $this
329
+ */
330
+ protected function _recallInfoUrl($status, $item)
331
+ {
332
+ if ($status->getId()) {
333
+ $collection = $status->getInfoCollection();
334
+ } else {
335
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Info_Collection */
336
+ $collection = Mage::getResourceModel('consumerbell_recall/info_collection');
337
+ $collection->addRecallFilter(0);
338
+ }
339
+
340
+ $save = false;
341
+ if (isset($item->recall_url)) {
342
+ $exists = false;
343
+ foreach ($collection->getItems() as $item) {
344
+ if ($item->getUrl() == $item->recall_url) {
345
+ $exists = true;
346
+ }
347
+ }
348
+
349
+ if (!$exists) {
350
+ $info = $collection->getNewEmptyItem();
351
+ $info->setUrl($item->recall_url);
352
+ $info->setUpdatedAt($this->_formatDate(true));
353
+ $collection->addItem($info);
354
+
355
+ $save = true;
356
+ }
357
+ } else if (isset($item->recall) && is_array($item->recall)) {
358
+ foreach ($item->recall as $data) {
359
+ $exists = false;
360
+ foreach ($collection->getItems() as $item) {
361
+ if ($item->getUrl() == $data->url) {
362
+ $exists = true;
363
+ }
364
+ }
365
+
366
+ if (!$exists) {
367
+ $info = $collection->getNewEmptyItem();
368
+ $info->setUrl($data->url);
369
+ $info->setUpdatedAt($this->_formatDate($data->flagged_ts));
370
+ $collection->addItem($info);
371
+
372
+ $save = true;
373
+ }
374
+ }
375
+ }
376
+
377
+ if ($save) {
378
+ $status->setSaveInfoCollection($save);
379
+ $status->setInfoCollection($collection);
380
+ }
381
+
382
+ return $this;
383
+ }
384
+
385
+ /**
386
+ * Returns formatted date
387
+ *
388
+ * @param int|bool $date
389
+ * @return string
390
+ */
391
+ protected function _formatDate($date)
392
+ {
393
+ if ($date === true) {
394
+ $date = time();
395
+ }
396
+
397
+ return date('Y-m-d H:i:s', $date);
398
+ }
399
+
400
+ /**
401
+ * Does action with Recalled product and Updates status action
402
+ *
403
+ * @param ConsumerBell_Recall_Model_Status $status
404
+ * @return $this
405
+ */
406
+ protected function _recall(ConsumerBell_Recall_Model_Status $status)
407
+ {
408
+ $action = $this->_getHelper()->getRecallAction();
409
+ if (!$status->getProductId()) {
410
+ $action = self::ACTION_NO_ACTION;
411
+ }
412
+
413
+ switch ($action) {
414
+ case self::ACTION_OUT_OF_STOCK:
415
+ /* @var $stock Mage_CatalogInventory_Model_Stock_Item */
416
+ $stock = Mage::getModel('cataloginventory/stock_item');
417
+ $stock->loadByProduct($status->getProductId());
418
+ if ($stock->getId()) {
419
+ $stock->setIsInStock(0);
420
+ $stock->save();
421
+ }
422
+
423
+ break;
424
+ case self::ACTION_DISABLE:
425
+ /* @var $product Mage_Catalog_Model_Product */
426
+ $product = Mage::getModel('catalog/product');
427
+ $product->load($status->getProductId());
428
+ if ($product->getId()) {
429
+ $product->setStatus(Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
430
+ $product->save();
431
+ $status->setProductName($product->getName());
432
+ }
433
+
434
+ break;
435
+ case self::ACTION_NO_ACTION:
436
+ default:
437
+ $action = self::ACTION_NO_ACTION;
438
+ break;
439
+ }
440
+
441
+ $status->setAction($action);
442
+
443
+ return $this;
444
+ }
445
+ }
app/code/community/ConsumerBell/Recall/Model/Service/Api.php ADDED
@@ -0,0 +1,324 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Service API Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_Service_Api
24
+ {
25
+ const URL_PATH_APP = '/app';
26
+ const URL_PATH_CONFIG = '/config';
27
+ const URL_PATH_INVENTORY = '/inventory';
28
+ const URL_PATH_STATUS = '/inventory_status';
29
+
30
+ /**
31
+ * Data Helper instance
32
+ *
33
+ * @var ConsumerBell_Recall_Helper_Data
34
+ */
35
+ protected $_helper;
36
+
37
+ /**
38
+ * Client ID
39
+ *
40
+ * @var string
41
+ */
42
+ protected $_clientId;
43
+
44
+ /**
45
+ * Client secret
46
+ *
47
+ * @var string
48
+ */
49
+ protected $_clientSecret;
50
+
51
+ /**
52
+ * Client Access Token
53
+ *
54
+ * @var string
55
+ */
56
+ protected $_accessToken;
57
+
58
+ /**
59
+ * Last API Error message
60
+ *
61
+ * @var string
62
+ */
63
+ protected $_lastError;
64
+
65
+ /**
66
+ * API URL
67
+ *
68
+ * @var string
69
+ */
70
+ protected $_apiUrl;
71
+
72
+ /**
73
+ * Returns Data helper instance
74
+ *
75
+ * @return ConsumerBell_Recall_Helper_Data
76
+ */
77
+ protected function _getHelper()
78
+ {
79
+ if ($this->_helper === null) {
80
+ $this->_helper = Mage::helper('consumerbell_recall');
81
+ }
82
+
83
+ return $this->_helper;
84
+ }
85
+
86
+ /**
87
+ * Returns Full URL to API by URL path
88
+ *
89
+ * @param string $path
90
+ * @param string $query
91
+ * @return string
92
+ */
93
+ protected function _getApiUrl($path, $query = '')
94
+ {
95
+ if ($this->_apiUrl === null) {
96
+ $this->_apiUrl = $this->_getHelper()->getApiUrl();
97
+ }
98
+
99
+ return sprintf('%s%s%s', $this->_apiUrl, $path, $query);
100
+ }
101
+
102
+ /**
103
+ * Connect to API and define token
104
+ *
105
+ * @return bool
106
+ */
107
+ protected function _connect()
108
+ {
109
+ if ($this->_accessToken !== null) {
110
+ return true;
111
+ }
112
+
113
+ $helper = $this->_getHelper();
114
+ $config = array(
115
+ 'adapter' => 'Zend_Http_Client_Adapter_Curl',
116
+ 'curloptions' => array(
117
+ CURLOPT_FOLLOWLOCATION => true,
118
+ CURLOPT_SSL_VERIFYPEER => false,
119
+ CURLOPT_HTTPAUTH => true,
120
+ CURLOPT_USERPWD => sprintf('%s:%s', $helper->getApiUsername(), $helper->getApiPassword()),
121
+ ),
122
+ );
123
+
124
+ try {
125
+ $appUrl = $this->_getApiUrl(self::URL_PATH_APP);
126
+ $client = new Zend_Http_Client($appUrl, $config);
127
+ $response = $client->request();
128
+
129
+ if ($response->getStatus() != 200) {
130
+ $message = Mage::helper('consumerbell_recall')->__('An error occurred while connecting to API');
131
+ if ($response->getStatus() == 401) {
132
+ $message = Mage::helper('consumerbell_recall')->__('Please check API credentials (Unauthorized)');
133
+ }
134
+ Mage::throwException($message);
135
+ }
136
+
137
+ $result = json_decode($response->getBody());
138
+ if (empty($result[0]) || !is_object($result[0])) {
139
+ $message = Mage::helper('consumerbell_recall')->__('An error occurred while parsing response');
140
+ Mage::throwException($message);
141
+ }
142
+
143
+ $this->_clientId = $result[0]->client_id;
144
+ $this->_clientSecret = $result[0]->client_secret;
145
+ $this->_accessToken = $result[0]->access_token;
146
+
147
+ } catch (Mage_Core_Exception $e) {
148
+ $this->_lastError = $e->getMessage();
149
+
150
+ return false;
151
+ } catch (Zend_Http_Client_Exception $e) {
152
+ $this->_lastError = $e->getMessage();
153
+
154
+ return false;
155
+ } catch (Exception $e) {
156
+ Mage::logException($e);
157
+ $this->_lastError = Mage::helper('consumerbell_recall')->__('An error occurred while connecting to API');
158
+
159
+ return false;
160
+ }
161
+
162
+ return true;
163
+ }
164
+
165
+ /**
166
+ * Returns list of config fields
167
+ *
168
+ * @return bool|array
169
+ */
170
+ public function getFields()
171
+ {
172
+ if (!$this->_connect()) {
173
+ return false;
174
+ }
175
+
176
+ try {
177
+ $url = $this->_getApiUrl(self::URL_PATH_CONFIG);
178
+ $client = $this->_getClient($url);
179
+ $response = $client->request(Zend_Http_Client::GET);
180
+
181
+ $result = json_decode($response->getBody());
182
+ } catch (Zend_Http_Client_Exception $e) {
183
+ $this->_lastError = $e->getMessage();
184
+
185
+ return false;
186
+ } catch (Exception $e) {
187
+ Mage::logException($e);
188
+ $this->_lastError = Mage::helper('consumerbell_recall')->__('An error occurred while connecting to API');
189
+
190
+ return false;
191
+ }
192
+
193
+ $fields = array();
194
+ $position = 0;
195
+ foreach ($result->fields as $key => $value) {
196
+ $fields[$key] = array(
197
+ 'field' => $key,
198
+ 'name' => $value,
199
+ 'position' => ++ $position,
200
+ );
201
+ }
202
+
203
+ return $fields;
204
+ }
205
+
206
+ /**
207
+ * Upload products
208
+ *
209
+ * @param string|resource $content
210
+ * @param int $attempt
211
+ * @return bool
212
+ */
213
+ public function upload($content, $attempt = 5)
214
+ {
215
+ if (!$this->_connect()) {
216
+ return false;
217
+ }
218
+
219
+ try {
220
+ $url = $this->_getApiUrl(self::URL_PATH_INVENTORY);
221
+ $client = $this->_getClient($url);
222
+ $client->setRawData($content);
223
+ $response = $client->request(Zend_Http_Client::POST);
224
+
225
+ $result = json_decode($response->getBody());
226
+
227
+ if (!$result instanceof stdClass || empty($result->status) || $result->status != 'success') {
228
+ $this->_lastError = Mage::helper('consumerbell_recall')->__('An error occurred while reading response');
229
+
230
+ if ($attempt > 0) {
231
+ return $this->upload($content, $attempt - 1);
232
+ }
233
+
234
+ return false;
235
+ }
236
+ } catch (Zend_Http_Client_Exception $e) {
237
+ $this->_lastError = $e->getMessage();
238
+
239
+ if ($attempt > 0) {
240
+ return $this->upload($content, $attempt - 1);
241
+ }
242
+
243
+ return false;
244
+ } catch (Exception $e) {
245
+ Mage::logException($e);
246
+ $this->_lastError = Mage::helper('consumerbell_recall')->__('An error occurred while connecting to API');
247
+
248
+ if ($attempt > 0) {
249
+ return $this->upload($content, $attempt - 1);
250
+ }
251
+
252
+ return false;
253
+ }
254
+
255
+ return true;
256
+ }
257
+
258
+ /**
259
+ * Returns list of recalled products
260
+ *
261
+ * @return bool|stdClass[]
262
+ */
263
+ public function getStatus()
264
+ {
265
+ if (!$this->_connect()) {
266
+ return false;
267
+ }
268
+
269
+ try {
270
+ $query = '';
271
+ $lastCheck = $this->_getHelper()->getLastRecall();
272
+ if ($lastCheck) {
273
+ $query = sprintf('?since_ts=%s', $lastCheck);
274
+ }
275
+
276
+ $url = $this->_getApiUrl(self::URL_PATH_STATUS, $query);
277
+ $client = $this->_getClient($url);
278
+ $response = $client->request(Zend_Http_Client::GET);
279
+
280
+ return json_decode($response->getBody());
281
+ } catch (Zend_Http_Client_Exception $e) {
282
+ $this->_lastError = $e->getMessage();
283
+
284
+ return false;
285
+ } catch (Exception $e) {
286
+ Mage::logException($e);
287
+ $this->_lastError = Mage::helper('consumerbell_recall')->__('An error occurred while connecting to API');
288
+
289
+ return false;
290
+ }
291
+ }
292
+
293
+ /**
294
+ * Initializes HTTP client
295
+ *
296
+ * @param string $url
297
+ * @return Zend_Http_Client
298
+ */
299
+ protected function _getClient($url)
300
+ {
301
+ $url = sprintf('%s?access_token=%s', $url, $this->_accessToken);
302
+ $config = array(
303
+ 'adapter' => 'Zend_Http_Client_Adapter_Curl',
304
+ 'curloptions' => array(
305
+ CURLOPT_FOLLOWLOCATION => true,
306
+ CURLOPT_SSL_VERIFYPEER => false,
307
+ ),
308
+ );
309
+
310
+ $client = new Zend_Http_Client($url, $config);
311
+
312
+ return $client;
313
+ }
314
+
315
+ /**
316
+ * Returns last error message
317
+ *
318
+ * @return string
319
+ */
320
+ public function getLastError()
321
+ {
322
+ return $this->_lastError;
323
+ }
324
+ }
app/code/community/ConsumerBell/Recall/Model/Status.php ADDED
@@ -0,0 +1,231 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Status Model
21
+ *
22
+ * @method ConsumerBell_Recall_Model_Resource_Status _getResource()
23
+ * @method ConsumerBell_Recall_Model_Resource_Status getResource()
24
+ * @method ConsumerBell_Recall_Model_Resource_Status_Collection getCollection()
25
+ * @method ConsumerBell_Recall_Model_Resource_Status_Collection getResourceCollection()
26
+ *
27
+ * @method ConsumerBell_Recall_Model_Status setRecallId(int $value)
28
+ * @method int getRecallId()
29
+ * @method ConsumerBell_Recall_Model_Status setProductId(int $value)
30
+ * @method int getProductId()
31
+ * @method ConsumerBell_Recall_Model_Status setSku(string $value)
32
+ * @method string getSku()
33
+ * @method ConsumerBell_Recall_Model_Status setAction(int $value)
34
+ * @method int getAction()
35
+ * @method ConsumerBell_Recall_Model_Status setProductName(string $value)
36
+ * @method ConsumerBell_Recall_Model_Status setProductStatus(string $value)
37
+ * @method ConsumerBell_Recall_Model_Status setProductStock(string $value)
38
+ * @method bool getSaveInfoCollection()
39
+ * @method ConsumerBell_Recall_Model_Status setSaveInfoCollection(bool $value)
40
+ */
41
+ class ConsumerBell_Recall_Model_Status extends Mage_Core_Model_Abstract
42
+ {
43
+ /**
44
+ * Define Resource Model
45
+ */
46
+ public function _construct()
47
+ {
48
+ $this->_eventPrefix = 'consumerbell_recall_status';
49
+ $this->_init('consumerbell_recall/status');
50
+ }
51
+
52
+ /**
53
+ * Setups default values before save
54
+ *
55
+ * @return $this
56
+ */
57
+ protected function _beforeSave()
58
+ {
59
+ parent::_beforeSave();
60
+
61
+ if (!$this->getProductId()) {
62
+ $this->setProductId(null);
63
+ }
64
+
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Save info collection after save recall
70
+ *
71
+ * @return $this
72
+ */
73
+ protected function _afterSave()
74
+ {
75
+ parent::_afterSave();
76
+
77
+ if ($this->getSaveInfoCollection()) {
78
+ foreach ($this->getInfoCollection()->getItems() as $info) {
79
+ $info->setRecallId($this->getId());
80
+ $info->save();
81
+ }
82
+ }
83
+
84
+ return $this;
85
+ }
86
+
87
+ /**
88
+ * Load Model by product
89
+ *
90
+ * @param Mage_Catalog_Model_Product|int $product
91
+ * @return $this
92
+ */
93
+ public function loadByProduct($product)
94
+ {
95
+ if ($product instanceof Mage_Catalog_Model_Product) {
96
+ $product = $product->getId();
97
+ }
98
+
99
+ return $this->load($product, 'product_id');
100
+ }
101
+
102
+ /**
103
+ * Loads Model by Product SKU
104
+ *
105
+ * @param string $sku
106
+ * @return Mage_Core_Model_Abstract
107
+ */
108
+ public function loadBySku($sku)
109
+ {
110
+ return $this->load($sku, 'sku');
111
+ }
112
+
113
+ /**
114
+ * Returns Product name if available
115
+ *
116
+ */
117
+ public function getProductName()
118
+ {
119
+ $value = $this->getData('product_name');
120
+ if ($value) {
121
+ return $value;
122
+ }
123
+
124
+ if (!$this->getProductId()) {
125
+ return '';
126
+ }
127
+
128
+ $value = $this->_getResource()->getProductName($this);
129
+ $this->setProductName($value);
130
+
131
+ return $value;
132
+ }
133
+
134
+ /**
135
+ * Returns Product status if available
136
+ *
137
+ */
138
+ public function getProductStatus()
139
+ {
140
+ $value = $this->getData('product_status');
141
+ if ($value != '') {
142
+ return $value;
143
+ }
144
+
145
+ if (!$this->getProductId()) {
146
+ return '';
147
+ }
148
+
149
+ $value = $this->_getResource()->getProductStatus($this);
150
+ $this->setProductStatus($value);
151
+
152
+ return $value;
153
+ }
154
+
155
+ /**
156
+ * Returns Is Product In Stock
157
+ *
158
+ * @return int
159
+ */
160
+ public function getProductStock()
161
+ {
162
+ $value = $this->_getData('product_stock');
163
+ if ($value != '') {
164
+ return $value;
165
+ }
166
+
167
+ if (!$this->getProductId()) {
168
+ return '';
169
+ }
170
+
171
+ /* @var $stock Mage_CatalogInventory_Model_Stock_Item */
172
+ $stock = Mage::getModel('cataloginventory/stock_item');
173
+ $stock->loadByProduct($this->getProductId());
174
+
175
+ $value = 0;
176
+ if ($stock->getId()) {
177
+ if ($stock->getManageStock()) {
178
+ $value = $stock->getIsInStock();
179
+ } else {
180
+ $value = 1;
181
+ }
182
+ }
183
+
184
+ $this->setData('product_stock', $value);
185
+
186
+ return $value;
187
+ }
188
+
189
+ /**
190
+ * Returns info collection
191
+ *
192
+ * @return ConsumerBell_Recall_Model_Resource_Info_Collection
193
+ */
194
+ public function getInfoCollection()
195
+ {
196
+ $collection = $this->_getData('info_collection');
197
+ if (!$collection) {
198
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Info_Collection */
199
+ $collection = Mage::getResourceModel('consumerbell_recall/info_collection');
200
+ $collection->addRecallFilter($this);
201
+
202
+ $this->setInfoCollection($collection);
203
+ }
204
+
205
+ return $collection;
206
+ }
207
+
208
+ /**
209
+ * Sets info collection
210
+ *
211
+ * @param ConsumerBell_Recall_Model_Resource_Info_Collection $collection
212
+ * @return $this
213
+ */
214
+ public function setInfoCollection($collection)
215
+ {
216
+ $this->setData('info_collection', $collection);
217
+
218
+ return $this;
219
+ }
220
+
221
+ /**
222
+ * Check if product is exists
223
+ *
224
+ * @param $productId
225
+ * @return bool
226
+ */
227
+ public function checkProductId($productId)
228
+ {
229
+ return $this->_getResource()->checkProductId($productId);
230
+ }
231
+ }
app/code/community/ConsumerBell/Recall/Model/System/Config/Backend/Cron.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Cron schedule Backend Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_System_Config_Backend_Cron extends Mage_Core_Model_Config_Data
24
+ {
25
+ const XML_NODE_SCHEDULE_EXPR = 'crontab/jobs/consumerbell_recall/schedule/cron_expr';
26
+ const XML_NODE_RUN_MODEL = 'crontab/jobs/consumerbell_recall/run/model';
27
+
28
+ /**
29
+ * Changes Cron settings after save Frequency value
30
+ *
31
+ * @throws Exception|Mage_Core_Exception
32
+ * @return ConsumerBell_Recall_Model_System_Config_Backend_Cron
33
+ */
34
+ protected function _afterSave()
35
+ {
36
+ parent::_afterSave();
37
+
38
+ $enabled = $this->getData('groups/cron/fields/active/value');
39
+ $time = $this->getData('groups/cron/fields/time/value');
40
+ $frequency = $this->getData('groups/cron/fields/frequency/value');
41
+ $cronExpr = '';
42
+
43
+ if ($enabled) {
44
+ $month = '*';
45
+ $week = '*';
46
+ switch ($frequency) {
47
+ case Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_WEEKLY:
48
+ $week = '1';
49
+ break;
50
+ case Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency::CRON_MONTHLY:
51
+ $month = '1';
52
+ break;
53
+ }
54
+
55
+ $cronExpr = sprintf('%d %d %s * %s', $time[1], $time[0], $month, $week);
56
+ }
57
+
58
+ try {
59
+ /* @var $config Mage_Core_Model_Config_Data */
60
+ $config = Mage::getModel('core/config_data');
61
+ $config->load(self::XML_NODE_SCHEDULE_EXPR, 'path');
62
+ $config->setPath(self::XML_NODE_SCHEDULE_EXPR)
63
+ ->setValue($cronExpr)
64
+ ->save();
65
+
66
+ /* @var $config Mage_Core_Model_Config_Data */
67
+ $config = Mage::getModel('core/config_data');
68
+ $config->load(self::XML_NODE_RUN_MODEL, 'path');
69
+ $config->setPath(self::XML_NODE_RUN_MODEL)
70
+ ->setValue((string)Mage::getConfig()->getNode(self::XML_NODE_RUN_MODEL))
71
+ ->save();
72
+
73
+ } catch (Mage_Core_Exception $e) {
74
+ throw $e;
75
+ } catch (Exception $e) {
76
+ Mage::logException($e);
77
+ Mage::throwException(Mage::helper('adminhtml')->__('Unable to save the cron expression.'));
78
+ }
79
+
80
+ return $this;
81
+ }
82
+ }
app/code/community/ConsumerBell/Recall/Model/System/Config/Source/Recall.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Action for recalled items System Source Model
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Model_System_Config_Source_Recall
24
+ {
25
+ /**
26
+ * Returns list of options
27
+ *
28
+ * @return array
29
+ */
30
+ public function toOptionArray()
31
+ {
32
+ return array(
33
+ array(
34
+ 'value' => ConsumerBell_Recall_Model_Service::ACTION_NO_ACTION,
35
+ 'label' => Mage::helper('consumerbell_recall')->__('Do nothing'),
36
+ ),
37
+ array(
38
+ 'value' => ConsumerBell_Recall_Model_Service::ACTION_OUT_OF_STOCK,
39
+ 'label' => Mage::helper('consumerbell_recall')->__('Set out of stock'),
40
+ ),
41
+ array(
42
+ 'value' => ConsumerBell_Recall_Model_Service::ACTION_DISABLE,
43
+ 'label' => Mage::helper('consumerbell_recall')->__('Disable item'),
44
+ ),
45
+ );
46
+ }
47
+ }
app/code/community/ConsumerBell/Recall/controllers/Adminhtml/Consumerbell/Recall/CatalogController.php ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Catalog Management Controller Action
21
+ *
22
+ */
23
+ class ConsumerBell_Recall_Adminhtml_Consumerbell_Recall_CatalogController extends Mage_Adminhtml_Controller_Action
24
+ {
25
+ /**
26
+ * Catalog Management Action
27
+ *
28
+ */
29
+ public function indexAction()
30
+ {
31
+ $this->_title(Mage::helper('catalog')->__('Catalog'));
32
+ $this->_title($this->__('ConsumerBell Recall Monitoring'));
33
+ $this->_title($this->__('Catalog Management'));
34
+
35
+ $this->loadLayout();
36
+ $this->_setActiveMenu('catalog/consumerbell_recall');
37
+ $this->renderLayout();
38
+ }
39
+
40
+ /**
41
+ * Uploads catalog products
42
+ *
43
+ */
44
+ public function syncAction()
45
+ {
46
+ try {
47
+ /* @var $service ConsumerBell_Recall_Model_Service */
48
+ $service = Mage::getSingleton('consumerbell_recall/service');
49
+
50
+ if (!$service->canSync()) {
51
+ Mage::throwException($this->__('Please configure everything first'));
52
+ }
53
+
54
+ if ($service->getProductCountToSync()) {
55
+ $service->sync();
56
+
57
+ $this->_getSession()->addSuccess($this->__('Products have been synced'));
58
+ } else {
59
+ $this->_getSession()->addNotice($this->__('All products already synced'));
60
+ }
61
+ } catch (Mage_Core_Exception $e) {
62
+ $this->_getSession()->addError($e->getMessage());
63
+ } catch (Exception $e) {
64
+ $this->_getSession()->addException($e, $this->__('An error occurred while syncing process'));
65
+ }
66
+
67
+ $this->_redirect('*/*/');
68
+ }
69
+
70
+ /**
71
+ * Check for recalled products
72
+ *
73
+ */
74
+ public function checkAction()
75
+ {
76
+ try {
77
+ /* @var $service ConsumerBell_Recall_Model_Service */
78
+ $service = Mage::getSingleton('consumerbell_recall/service');
79
+ /* @var $helper ConsumerBell_Recall_Helper_Data */
80
+ $helper = Mage::helper('consumerbell_recall');
81
+
82
+ if (!$helper->getLastSync()) {
83
+ Mage::throwException($this->__('Please synchronize catalog first'));
84
+ }
85
+
86
+ $products = $service->check();
87
+ if (count($products) > 0) {
88
+ $message = sprintf('%s. <a href="%s">%s</a>',
89
+ $this->__('%d product(s) have been recalled', count($products)),
90
+ $this->getUrl('adminhtml/consumerbell_recall_status'),
91
+ $this->__('View recalled products')
92
+ );
93
+ $this->_getSession()->addNotice($message);
94
+ } else {
95
+ $this->_getSession()->addSuccess($this->__('No new recalled items'));
96
+ }
97
+ } catch (Mage_Core_Exception $e) {
98
+ $this->_getSession()->addError($e->getMessage());
99
+ } catch (Exception $e) {
100
+ $this->_getSession()->addException($e, $this->__('An error occurred while syncing process'));
101
+ }
102
+
103
+ $this->_redirect('*/*/');
104
+ }
105
+
106
+ public function productRecallGridAction()
107
+ {
108
+ $productId = $this->getRequest()->getParam('product_id');
109
+ /* @var $status ConsumerBell_Recall_Model_Status */
110
+ $status = Mage::getModel('consumerbell_recall/status');
111
+ $status->loadByProduct($productId);
112
+
113
+ if (!$status->getId() && !$status->checkProductId($productId)) {
114
+ $this->norouteAction();
115
+
116
+ return;
117
+ }
118
+
119
+ Mage::register('current_recall', $status);
120
+
121
+ $this->loadLayout();
122
+ $this->renderLayout();
123
+ }
124
+
125
+ /**
126
+ * Checks if controller action is allow
127
+ *
128
+ * @return bool
129
+ */
130
+ protected function _isAllowed()
131
+ {
132
+ /* @var $session Mage_Admin_Model_Session */
133
+ $session = Mage::getSingleton('admin/session');
134
+
135
+ return $session->isAllowed('catalog/consumerbell_recall/catalog');
136
+ }
137
+ }
app/code/community/ConsumerBell/Recall/controllers/Adminhtml/Consumerbell/Recall/MapController.php ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Field Mapping Controller Action
21
+ */
22
+ class ConsumerBell_Recall_Adminhtml_Consumerbell_Recall_MapController extends Mage_Adminhtml_Controller_Action
23
+ {
24
+ /**
25
+ * Shows Field Mapping Grid
26
+ */
27
+ public function indexAction()
28
+ {
29
+ $this->_title(Mage::helper('catalog')->__('Catalog'));
30
+ $this->_title($this->__('ConsumerBell Recall Monitoring'));
31
+ $this->_title($this->__('Field Mapping'));
32
+
33
+ $this->loadLayout();
34
+ $this->_setActiveMenu('catalog/consumerbell_recall');
35
+ $this->renderLayout();
36
+ }
37
+
38
+ /**
39
+ * Saves Field Mapping
40
+ *
41
+ */
42
+ public function saveAction()
43
+ {
44
+ try {
45
+ $attributes = $this->getRequest()->getParam('attribute_id');
46
+ /* @var $collection ConsumerBell_Recall_Model_Resource_Map_Collection */
47
+ $collection = Mage::getResourceModel('consumerbell_recall/map_collection');
48
+ foreach ($collection->getItems() as $map) {
49
+ if (!isset($attributes[$map->getField()])) {
50
+ Mage::throwException($this->__('Undefined attribute for field "%s"', $map->getName()));
51
+ }
52
+ $map->setAttributeId($attributes[$map->getField()]);
53
+ }
54
+ $collection->save();
55
+
56
+ $this->_getSession()->addSuccess($this->__('Field mapping has been saved'));
57
+ } catch (Mage_Core_Exception $e) {
58
+ $this->_getSession()->addError($e->getMessage());
59
+ } catch (Exception $e) {
60
+ $this->_getSession()->addException($e, $this->__('An error occurred while saving process'));
61
+ }
62
+
63
+ $this->_redirect('*/*/');
64
+ }
65
+
66
+ /**
67
+ * Syncs field mapping
68
+ *
69
+ */
70
+ public function syncAction()
71
+ {
72
+ try {
73
+ /* @var $map ConsumerBell_Recall_Model_Map */
74
+ $map = Mage::getModel('consumerbell_recall/map');
75
+ $map->sync();
76
+
77
+ $this->_getSession()->addSuccess($this->__('List of fields have been synced'));
78
+ $this->_getSession()->addNotice($this->__('Please don\'t forget to verify product mapping and save'));
79
+ } catch (Mage_Core_Exception $e) {
80
+ $this->_getSession()->addError($e->getMessage());
81
+ } catch (Exception $e) {
82
+ $this->_getSession()->addException($e, $this->__('An error occurred while syncing process'));
83
+ }
84
+
85
+ $this->_redirect('*/*/');
86
+ }
87
+
88
+ /**
89
+ * Checks if controller action is allow
90
+ *
91
+ * @return bool
92
+ */
93
+ protected function _isAllowed()
94
+ {
95
+ /* @var $session Mage_Admin_Model_Session */
96
+ $session = Mage::getSingleton('admin/session');
97
+
98
+ return $session->isAllowed('catalog/consumerbell_recall/map');
99
+ }
100
+ }
app/code/community/ConsumerBell/Recall/controllers/Adminhtml/Consumerbell/Recall/StatusController.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * ConsumerBell Recall Field Mapping Controller Action
21
+ */
22
+ class ConsumerBell_Recall_Adminhtml_Consumerbell_Recall_StatusController extends Mage_Adminhtml_Controller_Action
23
+ {
24
+ /**
25
+ * Shows Recalled Products Grid
26
+ */
27
+ public function indexAction()
28
+ {
29
+ $this->_title(Mage::helper('catalog')->__('Catalog'));
30
+ $this->_title($this->__('ConsumerBell Recall Monitoring'));
31
+ $this->_title($this->__('Recalled Products'));
32
+
33
+ $this->loadLayout();
34
+ $this->_setActiveMenu('catalog/consumerbell_recall');
35
+ $this->renderLayout();
36
+ }
37
+
38
+ /**
39
+ * Checks if controller action is allow
40
+ *
41
+ * @return bool
42
+ */
43
+ protected function _isAllowed()
44
+ {
45
+ /* @var $session Mage_Admin_Model_Session */
46
+ $session = Mage::getSingleton('admin/session');
47
+
48
+ return $session->isAllowed('catalog/consumerbell_recall/status');
49
+ }
50
+ }
app/code/community/ConsumerBell/Recall/etc/adminhtml.xml ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * MageCore
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
10
+ * If you did not receive a copy of the license and are unable to
11
+ * obtain it through the world-wide-web, please send an email
12
+ * to license@magecore.com so we can send you a copy immediately
13
+ *
14
+ * @category ConsumerBell
15
+ * @package ConsumerBell_Recall
16
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <menu>
22
+ <catalog>
23
+ <children>
24
+ <consumerbell_recall translate="title" module="consumerbell_recall">
25
+ <title>ConsumerBell Recall Monitoring</title>
26
+ <sort_order>100</sort_order>
27
+ <children>
28
+ <map translate="title">
29
+ <title>Field Mapping</title>
30
+ <sort_order>30</sort_order>
31
+ <action>adminhtml/consumerbell_recall_map</action>
32
+ <depends>
33
+ <config>consumerbell_recall/general/active</config>
34
+ </depends>
35
+ </map>
36
+ <catalog translate="title">
37
+ <title>Catalog Management</title>
38
+ <sort_order>20</sort_order>
39
+ <action>adminhtml/consumerbell_recall_catalog</action>
40
+ <depends>
41
+ <config>consumerbell_recall/general/active</config>
42
+ </depends>
43
+ </catalog>
44
+ <status translate="title">
45
+ <title>Recalled Products</title>
46
+ <sort_order>10</sort_order>
47
+ <action>adminhtml/consumerbell_recall_status</action>
48
+ <depends>
49
+ <config>consumerbell_recall/general/active</config>
50
+ </depends>
51
+ </status>
52
+ </children>
53
+ <depends>
54
+ <config>consumerbell_recall/general/active</config>
55
+ </depends>
56
+ </consumerbell_recall>
57
+ </children>
58
+ </catalog>
59
+ </menu>
60
+ <acl>
61
+ <resources>
62
+ <admin>
63
+ <children>
64
+ <catalog>
65
+ <children>
66
+ <consumerbell_recall translate="title" module="consumerbell_recall">
67
+ <title>ConsumerBell Recall Monitoring</title>
68
+ <children>
69
+ <map translate="title">
70
+ <title>Field Mapping</title>
71
+ <sort_order>30</sort_order>
72
+ </map>
73
+ <catalog translate="title">
74
+ <title>Catalog Management</title>
75
+ <sort_order>20</sort_order>
76
+ </catalog>
77
+ <status translate="title">
78
+ <title>Recalled Products</title>
79
+ <sort_order>10</sort_order>
80
+ </status>
81
+ </children>
82
+ </consumerbell_recall>
83
+ </children>
84
+ </catalog>
85
+ <system>
86
+ <children>
87
+ <config>
88
+ <children>
89
+ <consumerbell_recall translate="title" module="consumerbell_recall">
90
+ <title>ConsumerBell Recall Monitoring</title>
91
+ </consumerbell_recall>
92
+ </children>
93
+ </config>
94
+ </children>
95
+ </system>
96
+ </children>
97
+ </admin>
98
+ </resources>
99
+ </acl>
100
+ </config>
app/code/community/ConsumerBell/Recall/etc/config.xml ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * MageCore
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
10
+ * If you did not receive a copy of the license and are unable to
11
+ * obtain it through the world-wide-web, please send an email
12
+ * to license@magecore.com so we can send you a copy immediately
13
+ *
14
+ * @category ConsumerBell
15
+ * @package ConsumerBell_Recall
16
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <ConsumerBell_Recall>
23
+ <version>1.0.2</version>
24
+ </ConsumerBell_Recall>
25
+ </modules>
26
+
27
+ <global>
28
+ <models>
29
+ <consumerbell_recall>
30
+ <class>ConsumerBell_Recall_Model</class>
31
+ <resourceModel>consumerbell_recall_resource</resourceModel>
32
+ </consumerbell_recall>
33
+ <consumerbell_recall_resource>
34
+ <class>ConsumerBell_Recall_Model_Resource</class>
35
+ <entities>
36
+ <map>
37
+ <table>consumerbell_recall_map</table>
38
+ </map>
39
+ <status>
40
+ <table>consumerbell_recall_status</table>
41
+ </status>
42
+ <info>
43
+ <table>consumerbell_recall_info</table>
44
+ </info>
45
+ </entities>
46
+ </consumerbell_recall_resource>
47
+ </models>
48
+ <helpers>
49
+ <consumerbell_recall>
50
+ <class>ConsumerBell_Recall_Helper</class>
51
+ </consumerbell_recall>
52
+ </helpers>
53
+ <blocks>
54
+ <consumerbell_recall>
55
+ <class>ConsumerBell_Recall_Block</class>
56
+ </consumerbell_recall>
57
+ </blocks>
58
+ <resources>
59
+ <consumerbell_recall_setup>
60
+ <setup>
61
+ <module>ConsumerBell_Recall</module>
62
+ <class>ConsumerBell_Recall_Model_Resource_Setup</class>
63
+ </setup>
64
+ </consumerbell_recall_setup>
65
+ </resources>
66
+ <template>
67
+ <email>
68
+ <consumerbell_recall_cron_email_template translate="label" module="consumerbell_recall">
69
+ <label>ConsumerBell Recall Monitoring Status</label>
70
+ <file>consumerbell/recall_cron.html</file>
71
+ <type>html</type>
72
+ </consumerbell_recall_cron_email_template>
73
+ </email>
74
+ </template>
75
+ </global>
76
+
77
+ <admin>
78
+ <routers>
79
+ <adminhtml>
80
+ <args>
81
+ <modules>
82
+ <ConsumerBell_Recall before="Mage_Adminhtml">ConsumerBell_Recall_Adminhtml</ConsumerBell_Recall>
83
+ </modules>
84
+ </args>
85
+ </adminhtml>
86
+ </routers>
87
+ </admin>
88
+
89
+ <adminhtml>
90
+ <layout>
91
+ <updates>
92
+ <consumerbell_recall>
93
+ <file>consumerbell/recall.xml</file>
94
+ </consumerbell_recall>
95
+ </updates>
96
+ </layout>
97
+ <translate>
98
+ <modules>
99
+ <ConsumerBell_Recall>
100
+ <files>
101
+ <default>ConsumerBell_Recall.csv</default>
102
+ </files>
103
+ </ConsumerBell_Recall>
104
+ </modules>
105
+ </translate>
106
+ <events>
107
+ <!--<catalog_product_edit_action>-->
108
+ <!--<observers>-->
109
+ <!--<consumerbell_recall>-->
110
+ <!--<class>consumerbell_recall/observer</class>-->
111
+ <!--<method>catalogProductEditAction</method>-->
112
+ <!--</consumerbell_recall>-->
113
+ <!--</observers>-->
114
+ <!--</catalog_product_edit_action>-->
115
+ </events>
116
+ </adminhtml>
117
+
118
+ <crontab>
119
+ <jobs>
120
+ <consumerbell_recall>
121
+ <run>
122
+ <model>consumerbell_recall/observer::update</model>
123
+ </run>
124
+ </consumerbell_recall>
125
+ </jobs>
126
+ </crontab>
127
+
128
+ <default>
129
+ <consumerbell_recall>
130
+ <general>
131
+ <active>0</active>
132
+ <api_url>https://www.consumerbell.com/api</api_url>
133
+ <recall_action>0</recall_action>
134
+ </general>
135
+ <cron>
136
+ <active>0</active>
137
+ <frequency>D</frequency>
138
+ <time>02,00,00</time>
139
+ <email_recipient />
140
+ <email_identity>support</email_identity>
141
+ <email_template>consumerbell_recall_cron_email_template</email_template>
142
+ </cron>
143
+ </consumerbell_recall>
144
+ </default>
145
+ </config>
app/code/community/ConsumerBell/Recall/etc/system.xml ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * MageCore
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
10
+ * If you did not receive a copy of the license and are unable to
11
+ * obtain it through the world-wide-web, please send an email
12
+ * to license@magecore.com so we can send you a copy immediately
13
+ *
14
+ * @category ConsumerBell
15
+ * @package ConsumerBell_Recall
16
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <tabs>
22
+ <consumerbell translate="label" module="consumerbell_recall">
23
+ <label>ConsumerBell</label>
24
+ <sort_order>250</sort_order>
25
+ </consumerbell>
26
+ </tabs>
27
+ <sections>
28
+ <consumerbell_recall translate="label" module="consumerbell_recall">
29
+ <label>Recall Monitoring</label>
30
+ <class>separator-top</class>
31
+ <tab>consumerbell</tab>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>100</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ <groups>
38
+ <general translate="label">
39
+ <label>General</label>
40
+ <frontend_type>text</frontend_type>
41
+ <sort_order>100</sort_order>
42
+ <show_in_default>1</show_in_default>
43
+ <show_in_website>0</show_in_website>
44
+ <show_in_store>0</show_in_store>
45
+ <fields>
46
+ <active translate="label">
47
+ <label>Enabled</label>
48
+ <frontend_type>select</frontend_type>
49
+ <source_model>adminhtml/system_config_source_yesno</source_model>
50
+ <sort_order>10</sort_order>
51
+ <show_in_default>1</show_in_default>
52
+ <show_in_website>0</show_in_website>
53
+ <show_in_store>0</show_in_store>
54
+ </active>
55
+ <api_url translate="label">
56
+ <label>API URL</label>
57
+ <frontend_type>text</frontend_type>
58
+ <validate>validate-url</validate>
59
+ <sort_order>20</sort_order>
60
+ <show_in_default>1</show_in_default>
61
+ <show_in_website>0</show_in_website>
62
+ <show_in_store>0</show_in_store>
63
+ </api_url>
64
+ <api_username translate="label">
65
+ <label>Account Login</label>
66
+ <frontend_type>text</frontend_type>
67
+ <sort_order>30</sort_order>
68
+ <show_in_default>1</show_in_default>
69
+ <show_in_website>0</show_in_website>
70
+ <show_in_store>0</show_in_store>
71
+ </api_username>
72
+ <api_password translate="label">
73
+ <label>Account Password</label>
74
+ <frontend_type>obscure</frontend_type>
75
+ <backend_model>adminhtml/system_config_backend_encrypted</backend_model>
76
+ <sort_order>40</sort_order>
77
+ <show_in_default>1</show_in_default>
78
+ <show_in_website>0</show_in_website>
79
+ <show_in_store>0</show_in_store>
80
+ </api_password>
81
+ <recall_action translate="label">
82
+ <label>Action for recalled items</label>
83
+ <frontend_type>select</frontend_type>
84
+ <source_model>consumerbell_recall/system_config_source_recall</source_model>
85
+ <sort_order>50</sort_order>
86
+ <show_in_default>1</show_in_default>
87
+ <show_in_website>0</show_in_website>
88
+ <show_in_store>0</show_in_store>
89
+ </recall_action>
90
+ </fields>
91
+ </general>
92
+ <cron>
93
+ <label>Cron Settings</label>
94
+ <frontend_type>text</frontend_type>
95
+ <sort_order>200</sort_order>
96
+ <show_in_default>1</show_in_default>
97
+ <show_in_website>0</show_in_website>
98
+ <show_in_store>0</show_in_store>
99
+ <fields>
100
+ <active translate="label">
101
+ <label>Enabled</label>
102
+ <frontend_type>select</frontend_type>
103
+ <source_model>adminhtml/system_config_source_yesno</source_model>
104
+ <sort_order>10</sort_order>
105
+ <show_in_default>1</show_in_default>
106
+ <show_in_website>0</show_in_website>
107
+ <show_in_store>0</show_in_store>
108
+ </active>
109
+ <frequency translate="label">
110
+ <label>Frequency</label>
111
+ <frontend_type>select</frontend_type>
112
+ <source_model>adminhtml/system_config_source_cron_frequency</source_model>
113
+ <backend_model>consumerbell_recall/system_config_backend_cron</backend_model>
114
+ <sort_order>20</sort_order>
115
+ <show_in_default>1</show_in_default>
116
+ <show_in_website>0</show_in_website>
117
+ <show_in_store>0</show_in_store>
118
+ </frequency>
119
+ <time translate="label">
120
+ <label>Start Time</label>
121
+ <frontend_type>time</frontend_type>
122
+ <sort_order>30</sort_order>
123
+ <show_in_default>1</show_in_default>
124
+ <show_in_website>0</show_in_website>
125
+ <show_in_store>0</show_in_store>
126
+ </time>
127
+ <email_recipient translate="label">
128
+ <label>Status Email Recipient</label>
129
+ <frontend_type>text</frontend_type>
130
+ <validate>validate-email</validate>
131
+ <sort_order>50</sort_order>
132
+ <show_in_default>1</show_in_default>
133
+ <show_in_website>0</show_in_website>
134
+ <show_in_store>0</show_in_store>
135
+ </email_recipient>
136
+ <email_identity translate="label">
137
+ <label>Status Email Sender</label>
138
+ <frontend_type>select</frontend_type>
139
+ <source_model>adminhtml/system_config_source_email_identity</source_model>
140
+ <sort_order>60</sort_order>
141
+ <show_in_default>1</show_in_default>
142
+ <show_in_website>0</show_in_website>
143
+ <show_in_store>0</show_in_store>
144
+ </email_identity>
145
+ <email_template translate="label">
146
+ <label>Status Email Template</label>
147
+ <frontend_type>select</frontend_type>
148
+ <source_model>adminhtml/system_config_source_email_template</source_model>
149
+ <sort_order>70</sort_order>
150
+ <show_in_default>1</show_in_default>
151
+ <show_in_website>0</show_in_website>
152
+ <show_in_store>0</show_in_store>
153
+ </email_template>
154
+ </fields>
155
+ </cron>
156
+ </groups>
157
+ </consumerbell_recall>
158
+ </sections>
159
+ </config>
app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/install-1.0.0.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * @var $this ConsumerBell_Recall_Model_Resource_Setup
21
+ */
22
+
23
+ $this->startSetup();
24
+
25
+ /**
26
+ * Create table 'consumerbell_recall/map'
27
+ */
28
+ $table = $this->getConnection()
29
+ ->newTable($this->getTable('consumerbell_recall/map'))
30
+ ->addColumn('field', Varien_Db_Ddl_Table::TYPE_TEXT, '64', array(
31
+ 'primary' => true,
32
+ ), 'Field code')
33
+ ->addColumn('name', Varien_Db_Ddl_Table::TYPE_TEXT, '128', array(
34
+ ), 'Name')
35
+ ->addColumn('position', Varien_Db_Ddl_Table::TYPE_SMALLINT, 'null', array(
36
+ 'nullable' => false,
37
+ 'unsigned' => true,
38
+ ), 'Position')
39
+ ->addColumn('attribute_id', Varien_Db_Ddl_Table::TYPE_SMALLINT, 'null', array(
40
+ 'nullable' => true,
41
+ 'unsigned' => true,
42
+ ), 'Attribute Id')
43
+ ->addIndex($this->getIdxName('consumerbell_recall/map', array('position')),
44
+ array('position'))
45
+ ->addIndex($this->getIdxName('consumerbell_recall/map', array('attribute_id')),
46
+ array('attribute_id'))
47
+ ->setComment('Consumerbell Recall Field Mapping');
48
+ $this->getConnection()->createTable($table);
49
+
50
+ $this->endSetup();
app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/mysql4-install-1.0.2.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * @var $this ConsumerBell_Recall_Model_Resource_Setup
21
+ */
22
+
23
+ $this->startSetup();
24
+
25
+ $this->run("
26
+ CREATE TABLE `{$this->getTable('consumerbell_recall/map')}` (
27
+ `field` varchar(64) NOT NULL,
28
+ `name` varchar(128) NOT NULL,
29
+ `position` tinyint(3) unsigned NOT NULL,
30
+ `attribute_id` smallint(5) unsigned DEFAULT NULL,
31
+ PRIMARY KEY (`field`),
32
+ KEY `IDX_CONSUMERBELL_RECALL_MAP_POSITION` (`position`),
33
+ KEY `IDX_CONSUMERBELL_RECALL_MAP_ATTRIBUTE_ID` (`attribute_id`)
34
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
35
+
36
+ CREATE TABLE `{$this->getTable('consumerbell_recall/status')}` (
37
+ `recall_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Recall Id',
38
+ `product_id` int(10) unsigned DEFAULT NULL COMMENT 'Product Id',
39
+ `sku` varchar(64) DEFAULT NULL COMMENT 'Product Sku',
40
+ `action` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Did action',
41
+ PRIMARY KEY (`recall_id`),
42
+ KEY `IDX_CONSUMERBELL_RECALL_STATUS_SKU` (`sku`),
43
+ KEY `IDX_CONSUMERBELL_RECALL_STATUS_PRODUCT_ID` (`product_id`),
44
+ CONSTRAINT `FK_CONSUMERBELL_RECALL_STS_PRD_ID_CAT_PRD_ENTT_ENTT_ID` FOREIGN KEY (`product_id`)
45
+ REFERENCES `{$this->getTable('catalog/product')}` (`entity_id`)
46
+ ON DELETE SET NULL ON UPDATE NO ACTION
47
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Consumerbell Recall Status';
48
+
49
+ CREATE TABLE `{$this->getTable('consumerbell_recall/info')}` (
50
+ `info_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Info Id',
51
+ `recall_id` int(10) unsigned NOT NULL COMMENT 'Recall Id',
52
+ `url` varchar(128) DEFAULT NULL COMMENT 'URL',
53
+ `updated_at` datetime DEFAULT NULL COMMENT 'Updated At',
54
+ PRIMARY KEY (`info_id`),
55
+ KEY `IDX_CONSUMERBELL_RECALL_INFO_RECALL_ID` (`recall_id`),
56
+ CONSTRAINT `FK_B7C58DFF68FB627A88F66E607769B208` FOREIGN KEY (`recall_id`)
57
+ REFERENCES `{$this->getTable('consumerbell_recall/status')}` (`recall_id`)
58
+ ON DELETE CASCADE ON UPDATE NO ACTION
59
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Consumerbell Recall Info';
60
+ ");
61
+
62
+ $this->endSetup();
app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/upgrade-1.0.0-1.0.1.php ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * @var $this ConsumerBell_Recall_Model_Resource_Setup
21
+ */
22
+
23
+ $this->startSetup();
24
+
25
+ /**
26
+ * Create table 'consumerbell_recall/status'
27
+ */
28
+ $table = $this->getConnection()
29
+ ->newTable($this->getTable('consumerbell_recall/status'))
30
+ ->addColumn('recall_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 'null', array(
31
+ 'nullable' => false,
32
+ 'identity' => true,
33
+ 'unsigned' => true,
34
+ 'primary' => true,
35
+ ), 'Recall Id')
36
+ ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 'null', array(
37
+ 'nullable' => true,
38
+ 'unsigned' => true,
39
+ ), 'Product Id')
40
+ ->addColumn('sku', Varien_Db_Ddl_Table::TYPE_TEXT, '64', array(
41
+ 'nullable' => true,
42
+ ), 'Product Sku')
43
+ ->addColumn('url', Varien_Db_Ddl_Table::TYPE_TEXT, '255', array(
44
+ 'nullable' => true,
45
+ ), 'Recall info URL')
46
+ ->addColumn('action', Varien_Db_Ddl_Table::TYPE_SMALLINT, 'null', array(
47
+ 'nullable' => false,
48
+ 'unsigned' => true,
49
+ 'default' => '0',
50
+ ), 'Action applied')
51
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
52
+ ), 'Updated At')
53
+ ->addIndex($this->getIdxName('consumerbell_recall/status', array('sku')),
54
+ array('sku'))
55
+ ->addIndex($this->getIdxName('consumerbell_recall/status', array('product_id')),
56
+ array('product_id'))
57
+ ->addForeignKey(
58
+ $this->getFkName('consumerbell_recall/status', 'product_id', 'catalog/product', 'entity_id'),
59
+ 'product_id', $this->getTable('catalog/product'), 'entity_id',
60
+ Varien_Db_Ddl_Table::ACTION_SET_NULL, Varien_Db_Ddl_Table::ACTION_NO_ACTION)
61
+ ->setComment('Consumerbell Recall Status');
62
+ $this->getConnection()->createTable($table);
63
+
64
+ $this->endSetup();
app/code/community/ConsumerBell/Recall/sql/consumerbell_recall_setup/upgrade-1.0.1-1.0.2.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category ConsumerBell
14
+ * @package ConsumerBell_Recall
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * @var $this ConsumerBell_Recall_Model_Resource_Setup
21
+ */
22
+
23
+ $this->startSetup();
24
+
25
+ $adapter = $this->getConnection();
26
+
27
+ /**
28
+ * Create table 'consumerbell_recall/info'
29
+ */
30
+ $table = $adapter
31
+ ->newTable($this->getTable('consumerbell_recall/info'))
32
+ ->addColumn('info_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 'null', array(
33
+ 'nullable' => false,
34
+ 'identity' => true,
35
+ 'unsigned' => true,
36
+ 'primary' => true,
37
+ ), 'Info Id')
38
+ ->addColumn('recall_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 'null', array(
39
+ 'nullable' => false,
40
+ 'unsigned' => true,
41
+ ), 'Recall Id')
42
+ ->addColumn('url', Varien_Db_Ddl_Table::TYPE_TEXT, '128', array(
43
+ ), 'URL')
44
+ ->addColumn('updated_at', Varien_Db_Ddl_Table::TYPE_DATETIME, NULL, array(
45
+ ), 'Updated At')
46
+ ->addIndex($this->getIdxName('consumerbell_recall/info', array('recall_id')),
47
+ array('recall_id'))
48
+ ->addForeignKey(
49
+ $this->getFkName('consumerbell_recall/info', 'recall_id', 'consumerbell_recall/status', 'recall_id'),
50
+ 'recall_id', $this->getTable('consumerbell_recall/status'), 'recall_id',
51
+ Varien_Db_Ddl_Table::ACTION_CASCADE, Varien_Db_Ddl_Table::ACTION_NO_ACTION)
52
+ ->setComment('Consumerbell Recall Info');
53
+ $adapter->createTable($table);
54
+
55
+ $select = $adapter->select()
56
+ ->from($this->getTable('consumerbell_recall/status'), array(
57
+ 'info_id' => new Zend_Db_Expr('NULL'),
58
+ 'recall_id' => 'recall_id',
59
+ 'url' => 'url',
60
+ 'updated_at' => 'updated_at'
61
+ ));
62
+
63
+ $query = $adapter->insertFromSelect($select, $this->getTable('consumerbell_recall/info'));
64
+ $adapter->query($query);
65
+
66
+ $adapter->dropColumn($this->getTable('consumerbell_recall/status'), 'url');
67
+ $adapter->dropColumn($this->getTable('consumerbell_recall/status'), 'updated_at');
68
+
69
+ $this->endSetup();
app/design/adminhtml/default/default/layout/consumerbell/recall.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * MageCore
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
10
+ * If you did not receive a copy of the license and are unable to
11
+ * obtain it through the world-wide-web, please send an email
12
+ * to license@magecore.com so we can send you a copy immediately
13
+ *
14
+ * @category default
15
+ * @package default_default
16
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <layout>
21
+ <default>
22
+ <reference name="notifications">
23
+ <block type="consumerbell_recall/adminhtml_toolbar" name="consumerbell_recall_toolbar"
24
+ template="consumerbell/recall/toolbar.phtml"/>
25
+ </reference>
26
+ </default>
27
+
28
+ <adminhtml_consumerbell_recall_map_index>
29
+ <reference name="content">
30
+ <block type="consumerbell_recall/adminhtml_map" name="consumerbell_recall_map"
31
+ template="consumerbell/recall/map/container.phtml"/>
32
+ </reference>
33
+ </adminhtml_consumerbell_recall_map_index>
34
+ <adminhtml_consumerbell_recall_catalog_index>
35
+ <reference name="content">
36
+ <block type="consumerbell_recall/adminhtml_catalog" name="consumerbell_recall_catalog"/>
37
+ </reference>
38
+ </adminhtml_consumerbell_recall_catalog_index>
39
+
40
+ <adminhtml_consumerbell_recall_status_index>
41
+ <reference name="content">
42
+ <block type="consumerbell_recall/adminhtml_status" name="consumerbell_recall_status"/>
43
+ </reference>
44
+ </adminhtml_consumerbell_recall_status_index>
45
+ <adminhtml_catalog_product_edit>
46
+ <reference name="product_tabs">
47
+ <block type="consumerbell_recall/adminhtml_product_edit_tab_recall" name="consumerbell_recall"/>
48
+ <action method="addTab">
49
+ <name>tab_consumerbell_recall</name>
50
+ <block>consumerbell_recall</block>
51
+ </action>
52
+ </reference>e
53
+ </adminhtml_catalog_product_edit>
54
+ <adminhtml_consumerbell_recall_catalog_productrecallgrid>
55
+ <block type="adminhtml/text_list" name="root">
56
+ <block type="consumerbell_recall/adminhtml_product_edit_tab_recall_grid" name="consumerbell_recall_grid"/>
57
+ </block>
58
+ </adminhtml_consumerbell_recall_catalog_productrecallgrid>
59
+ </layout>
app/design/adminhtml/default/default/template/consumerbell/recall/cron/status_grid.phtml ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category default
14
+ * @package default_default
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @var $this Mage_Adminhtml_Block_Template
20
+ * @var $recalled ConsumerBell_Recall_Model_Status[]
21
+ */
22
+ $recalled = $this->getRecalled();
23
+ ?>
24
+ <table cellspacing="0" cellpadding="0" border="0">
25
+ <thead>
26
+ <tr>
27
+ <td><?php echo $this->__('SKU') ?></td>
28
+ <td><?php echo $this->__('Product Name') ?></td>
29
+ <td><?php echo $this->__('Recall info') ?></td>
30
+ <td><?php echo $this->__('Updated At') ?></td>
31
+ </tr>
32
+ </thead>
33
+ <?php foreach ($recalled as $status): ?>
34
+ <?php foreach ($status->getInfoCollection()->getItems() as $info): ?>
35
+ <tr>
36
+ <td><?php echo $this->escapeHtml($status->getSku()); ?></td>
37
+ <td><?php echo $this->escapeHtml($status->getProductName()); ?></td>
38
+ <td><a href="<?php echo $this->escapeUrl($info->getUrl()) ?>"><?php echo $this->__('Read more'); ?></a></td>
39
+ <td><?php echo $this->formatDate($info->getUpdatedAt()) ?></td>
40
+ </tr>
41
+ <?php endforeach; ?>
42
+ <?php endforeach; ?>
43
+ </table>
app/design/adminhtml/default/default/template/consumerbell/recall/map/container.phtml ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category default
14
+ * @package default_default
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @var $this ConsumerBell_Recall_Block_Adminhtml_Map
20
+ */
21
+ ?>
22
+ <div class="content-header">
23
+ <table cellspacing="0">
24
+ <tr>
25
+ <td style="<?php echo $this->getHeaderWidth() ?>"><?php echo $this->getHeaderHtml() ?></td>
26
+ <td class="form-buttons"><?php echo $this->getButtonsHtml() ?></td>
27
+ </tr>
28
+ </table>
29
+ </div>
30
+ <form id="<?php echo $this->getFormId() ?>" method="post" action="<?php echo $this->getFormAction() ?>">
31
+ <input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
32
+ <div>
33
+ <?php echo $this->getGridHtml() ?>
34
+ </div>
35
+ </form>
36
+
37
+ <script type="text/javascript">
38
+ //<!CDATA[[
39
+ var gridForm = new varienForm('<?php echo $this->getFormId() ?>');
40
+ //]]>
41
+ </script>
app/design/adminhtml/default/default/template/consumerbell/recall/toolbar.phtml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * MageCore
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
9
+ * If you did not receive a copy of the license and are unable to
10
+ * obtain it through the world-wide-web, please send an email
11
+ * to license@magecore.com so we can send you a copy immediately
12
+ *
13
+ * @category default
14
+ * @package default_default
15
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @var $this ConsumerBell_Recall_Block_Adminhtml_Toolbar
20
+ */
21
+ ?>
22
+ <?php if ($this->canShow()): ?>
23
+ <div class="notification-global">
24
+ <div><?php echo $this->__('Some modifications were made to your catalog and you should sync your product with Consumer Bell') ?>
25
+ (<a href="<?php echo $this->getManageUrl() ?>"><?php echo $this->__('click here to sync'); ?></a>)
26
+ </div>
27
+ </div>
28
+ <?php endif; ?>
app/etc/modules/ConsumerBell_Recall.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * MageCore
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is published at http://opensource.org/licenses/osl-3.0.php.
10
+ * If you did not receive a copy of the license and are unable to
11
+ * obtain it through the world-wide-web, please send an email
12
+ * to license@magecore.com so we can send you a copy immediately
13
+ *
14
+ * @category ConsumerBell
15
+ * @package ConsumerBell_Recall
16
+ * @copyright Copyright (c) 2013 MageCore Inc. (http://www.magecore.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <ConsumerBell_Recall>
23
+ <codePool>community</codePool>
24
+ <active>true</active>
25
+ <depends>
26
+ <Mage_Catalog />
27
+ </depends>
28
+ </ConsumerBell_Recall>
29
+ </modules>
30
+ </config>
app/locale/en_US/ConsumerBell_Recall.csv ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "%d product(s) have been recalled","%d product(s) have been recalled"
2
+ "-- Empty value --","-- Empty value --"
3
+ "-- Select --","-- Select --"
4
+ "API URL","API URL"
5
+ "Account Login","Account Login"
6
+ "Account Password","Account Password"
7
+ "Action","Action"
8
+ "Action applied","Action applied"
9
+ "Action for recalled items","Action for recalled items"
10
+ "All products already synced","All products already synced"
11
+ "An error occurred while connecting to API","An error occurred while connecting to API"
12
+ "An error occurred while parsing response","An error occurred while parsing response"
13
+ "An error occurred while reading response","An error occurred while reading response"
14
+ "An error occurred while saving process","An error occurred while saving process"
15
+ "An error occurred while syncing process","An error occurred while syncing process"
16
+ "Are you sure that you want check it?","Are you sure that you want check it?"
17
+ "Are you sure that you want sync it?","Are you sure that you want sync it?"
18
+ "Catalog Management","Catalog Management"
19
+ "Check","Check"
20
+ "Check recalled products","Check recalled products"
21
+ "ConsumerBell","ConsumerBell"
22
+ "ConsumerBell Recall Monitoring","ConsumerBell Recall Monitoring"
23
+ "ConsumerBell Recall Monitoring Status","ConsumerBell Recall Monitoring Status"
24
+ "Disable item","Disable item"
25
+ "Disabled","Disabled"
26
+ "Do nothing","Do nothing"
27
+ "Enabled","Enabled"
28
+ "Field Mapping","Field Mapping"
29
+ "Field mapping has been saved","Field mapping has been saved"
30
+ "Field mapping is not defined.","Field mapping is not defined."
31
+ "Frequency","Frequency"
32
+ "General","General"
33
+ "In stock","In stock"
34
+ "Last Catalog synchronization","Last Catalog synchronization"
35
+ "Last Check Recall status","Last Check Recall status"
36
+ "List of fields have been synced","List of fields have been synced"
37
+ "Never","Never"
38
+ "No new recalled items","No new recalled items"
39
+ "No recalls notifications for this item","No recalls notifications for this item"
40
+ "None","None"
41
+ "Nothing","Nothing"
42
+ "Out of stock","Out of stock"
43
+ "Please check API credentials (Unauthorized)","Please check API credentials (Unauthorized)"
44
+ "Please configure everything first","Please configure everything first"
45
+ "Please don\'t forget to verify product mapping and save","Please don\'t forget to verify product mapping and save"
46
+ "Please synchronize catalog first","Please synchronize catalog first"
47
+ "Product","Product"
48
+ "Product Name","Product Name"
49
+ "Product Status","Product Status"
50
+ "Products have been synced","Products have been synced"
51
+ "Products to be synced","Products to be synced"
52
+ "Read more","Read more"
53
+ "Recall Information","Recall Information"
54
+ "Recall Monitoring","Recall Monitoring"
55
+ "Recall info","Recall info"
56
+ "Recalled Products","Recalled Products"
57
+ "SKU","SKU"
58
+ "Save","Save"
59
+ "Set out of stock","Set out of stock"
60
+ "Some modifications were made to your catalog and you should sync your product with Consumer Bell","Some modifications were made to your catalog and you should sync your product with Consumer Bell"
61
+ "Start Time","Start Time"
62
+ "Status Email Recipient","Status Email Recipient"
63
+ "Status Email Sender","Status Email Sender"
64
+ "Status Email Template","Status Email Template"
65
+ "Stock","Stock"
66
+ "Sync","Sync"
67
+ "Sync Attributes","Sync Attributes"
68
+ "Sync Catalog","Sync Catalog"
69
+ "Undefined attribute for field ""%s""","Undefined attribute for field ""%s"""
70
+ "Unknown","Unknown"
71
+ "Updated At","Updated At"
72
+ "View recalled products","View recalled products"
73
+ "click here to sync","click here to sync"
app/locale/en_US/template/email/consumerbell/recall_cron.html ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!--@subject ConsumerBell Recall Monitoring Cron Job Status! @-->
2
+ <!--@vars
3
+ {"var error":"Error message",
4
+ "var synced":"Number of synced products",
5
+ "var recalled_grid":"Grid of recalled products"}
6
+ @-->
7
+ <body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;">
8
+ {{depend error}}
9
+ <p><strong>Error:</strong> {{htmlescape var error}}</p>
10
+ {{/depend}}
11
+ {{depend synced}}
12
+ <p><strong>Sync catalog:</strong> {{var synced}} product(s) have been synced</p>
13
+ {{/depend}}
14
+ {{depend recalled_grid}}
15
+ <p><strong>Following products were recalled</strong></p>
16
+ {{var recalled_grid}}
17
+ {{/depend}}
18
+ </body>
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>ConsumerBell_Recall</name>
4
+ <version>1.0.2</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>ConsumerBell Inventory Recall Monitoring</summary>
10
+ <description>ConsumerBell's Inventory Recall Monitoring protects your store from selling products that have been recalled. This extension continuously compares your inventory against our list of recalls and automatically flags those products in your inventory so that they cannot be sold the consumer. &#xD;
11
+ &#xD;
12
+ Your inventory is compared against recalls from the CPSC, FDA, USDA, EPA and other major recall sources.</description>
13
+ <notes>Version number: 1.0.2&#xD;
14
+ Stability: Stable&#xD;
15
+ Compatibility: Magento Community Edition 1.6.X, 1.7.X; Magento Enterprise Edition: 1.11.X, 1.12.X.&#xD;
16
+ Initial release of ConsumerBell Inventory Recall Monitoring</notes>
17
+ <authors><author><name>MageCore</name><user>auto-converted</user><email>info@magecore.com</email></author></authors>
18
+ <date>2013-03-11</date>
19
+ <time>15:27:05</time>
20
+ <contents><target name="magecommunity"><dir name="ConsumerBell"><dir name="Recall"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><file name="Form.php" hash="45a5333981f60e3ccc853b1517ebb1eb"/></dir><dir name="Map"><file name="Grid.php" hash="33181fccc98eace794037dc27467dd90"/></dir><dir name="Product"><dir name="Edit"><dir name="Tab"><dir name="Recall"><file name="Grid.php" hash="27cf35bc499353c0d6dd78ff045e9bd1"/></dir><file name="Recall.php" hash="7955217d587962e025e759d24904ab2a"/></dir></dir></dir><dir name="Status"><file name="Grid.php" hash="71c5d1475d85b88f8d846e1b752a0576"/></dir><dir name="Widget"><dir name="Form"><dir name="Element"><file name="Button.php" hash="9500dba09446a30aae562a8411e67e6c"/></dir></dir><dir name="Grid"><dir name="Column"><dir name="Renderer"><file name="Link.php" hash="5e399034fdbd174508c7457d8b3d5818"/><file name="Select.php" hash="d9a080bde02462b4d9b89bee0d84f16e"/><file name="Text.php" hash="1f341d001cb712566480aa9fce58d706"/></dir></dir></dir></dir><file name="Catalog.php" hash="f02f4a38b2b3ea9841fed92f662c1298"/><file name="Map.php" hash="f4dc72e4ff36ac3a53e0568e20abce88"/><file name="Status.php" hash="4c86f90d27d05ca45e81888f548b9737"/><file name="Toolbar.php" hash="3f675f283ae39db320c20b78fd9bf4e5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="ac0a21893287f2822050d091f7df1d4c"/></dir><dir name="Model"><dir name="Resource"><dir name="Info"><file name="Collection.php" hash="a1cdea97426677d4c3d7ccaefeb1e9f7"/></dir><dir name="Map"><file name="Collection.php" hash="0f9b7b45658e35790b005d7041e17856"/></dir><dir name="Status"><file name="Collection.php" hash="f35108a681607e0f21fa5480e01cb62d"/></dir><file name="Info.php" hash="c0d3fcc5bdc91f212a8d167d297399a7"/><file name="Map.php" hash="9655573843732cc3bc48eee72167b19b"/><file name="Setup.php" hash="42ea87b0d0f0de1493da5fdf075c94fa"/><file name="Status.php" hash="6ef92c574e28229c7415b394f69d0d0e"/></dir><dir name="Service"><file name="Api.php" hash="6f719ea8eebb643e3626e2a7849cd4de"/></dir><dir name="System"><dir name="Config"><dir name="Backend"><file name="Cron.php" hash="991bcd11dbaf5458bc97124310ac8676"/></dir><dir name="Source"><file name="Recall.php" hash="be97224d9d397b661f83c07400246630"/></dir></dir></dir><file name="Cron.php" hash="679b49821c3c77fb1fb3d1708f851bab"/><file name="Info.php" hash="945c07f47488d7880344ed3b2c5dc866"/><file name="Map.php" hash="4f3790758fac4b8ebaa0b3ece6fdb67b"/><file name="Observer.php" hash="f325209e7e467e1187ee6703ae731aa2"/><file name="Service.php" hash="38ff4df466125d8463a253a460075910"/><file name="Status.php" hash="75474fb48b47f5ac2d87fd701020bd1b"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Consumerbell"><dir name="Recall"><file name="CatalogController.php" hash="3e55fe71b57ff82eb4a2678c847b8af1"/><file name="MapController.php" hash="8b340ed9b9ec06705cc404c534cf6432"/><file name="StatusController.php" hash="e40d5c1df26c1dddf49ac3706c16cf3f"/></dir></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="784d018a25cf68277fb78bcb4573657f"/><file name="config.xml" hash="9033273e4cf468301320499b56847a00"/><file name="system.xml" hash="7e0da1712fc3b547057e5d18d1f31463"/></dir><dir name="sql"><dir name="consumerbell_recall_setup"><file name="install-1.0.0.php" hash="65440b8436dd26c3f30830f6d488cb2b"/><file name="mysql4-install-1.0.2.php" hash="48c31250f39c5194bc02b9d76ef903e3"/><file name="upgrade-1.0.0-1.0.1.php" hash="ab40fc1c2ef3b9a22faa39fa35c46116"/><file name="upgrade-1.0.1-1.0.2.php" hash="92ec786c8f6a6ae8750a1847a6b2c581"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="ConsumerBell_Recall.xml" hash="b5f0a1f2e5bd7fc68570af447f501715"/></dir></target><target name="magelocale"><dir name="en_US"><dir name="template"><dir name="email"><dir name="consumerbell"><file name="recall_cron.html" hash="5421291814378102f261fd8fbb3ffa74"/></dir></dir></dir><file name="ConsumerBell_Recall.csv" hash="61a2f7705756f138f79da84798e7a71a"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="consumerbell"><dir name="recall"><dir name="cron"><file name="status_grid.phtml" hash="fb822a20b14e5b3daf1bd6a7d256fcb9"/></dir><dir name="map"><file name="container.phtml" hash="bb265c4edaa70e552f17d7fe27a1d4a6"/></dir><file name="toolbar.phtml" hash="2c6f3490300521a74c7ea695d1816393"/></dir></dir></dir><dir name="layout"><dir name="consumerbell"><file name="recall.xml" hash="7b7137a24ee98d61e5351b359b2b4d00"/></dir></dir></dir></dir></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies/>
23
+ </package>