mediego-recommendations - Version 1.0.0

Version Notes

Version initiale

Download this release

Release Info

Developer Orinoko
Extension mediego-recommendations
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (33) hide show
  1. app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Edit.php +49 -0
  2. app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Edit/Form.php +76 -0
  3. app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Grid.php +172 -0
  4. app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Grid/Container.php +55 -0
  5. app/code/community/Mediego/Recommendations/Block/Js.php +57 -0
  6. app/code/community/Mediego/Recommendations/Block/Widget.php +153 -0
  7. app/code/community/Mediego/Recommendations/Helper/Chooser.php +114 -0
  8. app/code/community/Mediego/Recommendations/Helper/Data.php +66 -0
  9. app/code/community/Mediego/Recommendations/Model/Collection/Memory.php +470 -0
  10. app/code/community/Mediego/Recommendations/Model/Default/Recommendations.php +37 -0
  11. app/code/community/Mediego/Recommendations/Model/Resource/Default/Recommendations.php +32 -0
  12. app/code/community/Mediego/Recommendations/Model/Resource/Default/Recommendations/Collection.php +32 -0
  13. app/code/community/Mediego/Recommendations/controllers/Adminhtml/IndexController.php +154 -0
  14. app/code/community/Mediego/Recommendations/etc/adminhtml.xml +62 -0
  15. app/code/community/Mediego/Recommendations/etc/compilation.xml +44 -0
  16. app/code/community/Mediego/Recommendations/etc/config.xml +117 -0
  17. app/code/community/Mediego/Recommendations/etc/system.xml +62 -0
  18. app/code/community/Mediego/Recommendations/etc/widget.xml +92 -0
  19. app/code/community/Mediego/Recommendations/sql/mediego_recommendations_setup/install-0.1.0.php +56 -0
  20. app/design/adminhtml/default/default/layout/mediegorecommendations.xml +32 -0
  21. app/design/frontend/base/default/layout/mediegorecommendations.xml +29 -0
  22. app/design/frontend/base/default/template/mediegorecommendations/js.phtml +19 -0
  23. app/design/frontend/base/default/template/mediegorecommendations/opengraph.phtml +51 -0
  24. app/design/frontend/base/default/template/mediegorecommendations/recommendations.phtml +74 -0
  25. app/design/frontend/rwd/default/template/mediegorecommendations/recommendations.phtml +74 -0
  26. app/etc/modules/Mediego_Recommendations.xml +31 -0
  27. app/locale/fr_FR/Mediego_Recommendations.csv +41 -0
  28. package.xml +30 -0
  29. skin/adminhtml/default/default/images/mediego.png +0 -0
  30. skin/adminhtml/default/default/images/widget/mediego_recommendations__widget.gif +0 -0
  31. skin/adminhtml/default/default/mediego_recommendations.css +2 -0
  32. skin/frontend/base/default/css/mediego.css +36 -0
  33. skin/frontend/rwd/default/css/mediego.css +57 -0
app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Edit.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
27
+ {
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+
32
+ $this->_objectId = 'id';
33
+ $this->_blockGroup = 'mediego_recommendations';
34
+ $this->_controller = 'adminhtml_default_recommendations';
35
+
36
+ $this->_updateButton('save', 'label', $this->__('Save'));
37
+ $this->_updateButton('delete', 'label', $this->__('Delete'));
38
+ }
39
+
40
+ public function getHeaderText()
41
+ {
42
+ return $this->__('Recommendation Details');
43
+ }
44
+
45
+ public function getHeaderCssClass()
46
+ {
47
+ return 'icon-head head-mediego';
48
+ }
49
+ }
app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Edit/Form.php ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Edit_Form extends Mage_Adminhtml_Block_Widget_Form
27
+ {
28
+ protected function _prepareForm()
29
+ {
30
+ // creates the form
31
+ $form = new Varien_Data_Form(array(
32
+ 'id' => 'edit_form',
33
+ 'action' => $this->getUrl('*/*/save', array('id' => $this->getRequest()->getParam('id'))),
34
+ 'method' => 'post',
35
+ 'enctype' => 'multipart/form-data'
36
+ ));
37
+
38
+ $form->setUseContainer(true);
39
+ $this->setForm($form);
40
+
41
+ // gets the model from the registry and prefix the product_id with product/ for the chooser to work
42
+ $model = Mage::registry('mediego_recommendations_data');
43
+ $productId = $model->getData('product_id');
44
+
45
+ if ($productId) {
46
+ $model->setProductId('product/'.$productId);
47
+ }
48
+
49
+ // add the field set
50
+ $fieldset = $form->addFieldset('mediego_recommendations_form', array(
51
+ 'legend' => $this->__('Details')
52
+ ));
53
+
54
+ // adds the product chooser field
55
+ $productConfig = array(
56
+ 'input_name' => 'product_id',
57
+ 'input_label' => $this->__('Product'),
58
+ 'button_text' => $this->__('Select Product...'),
59
+ 'required' => true
60
+ );
61
+
62
+ $chooserHelper = Mage::helper('mediego_recommendations/chooser');
63
+ $chooserHelper->createProductChooser($model, $fieldset, $productConfig);
64
+
65
+ // adds the position field
66
+ $fieldset->addField('position', 'text', array(
67
+ 'name' => 'position',
68
+ 'label' => $this->__('Position')
69
+ ));
70
+
71
+ // updates the form values from the model
72
+ $form->setValues($model->getData());
73
+
74
+ return parent::_prepareForm();
75
+ }
76
+ }
app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Grid.php ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Grid extends Mage_Adminhtml_Block_Widget_Grid
27
+ {
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+
32
+ $this->setId('mediegoRecommendationsGrid');
33
+ $this->setDefaultSort('position');
34
+ $this->setDefaultDir('ASC');
35
+ $this->setSaveParametersInSession(true);
36
+ }
37
+
38
+ protected function _prepareCollection()
39
+ {
40
+ // gets all the recommendations (we do not even apply paging at this stage since there will never be many rows)
41
+ $recommendations = Mage::getModel('mediego_recommendations/default_recommendations')
42
+ ->getCollection()
43
+ ->addFieldToSelect(array('id','position','product_id'));
44
+
45
+ $productIds = $recommendations->getColumnValues('product_id');
46
+
47
+ // gets the products
48
+ $products = Mage::getModel('catalog/product')
49
+ ->getCollection()
50
+ ->addAttributeToSelect(array('entity_id','name','sku','visibility','status'))
51
+ ->addFieldToFilter('entity_id', array('in' => $productIds));
52
+
53
+ if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
54
+ $products->joinField('qty',
55
+ 'cataloginventory/stock_item',
56
+ 'qty',
57
+ 'product_id=entity_id',
58
+ '{{table}}.stock_id=1',
59
+ 'left');
60
+ }
61
+
62
+ // groups the products by their id
63
+ $productById = array();
64
+
65
+ foreach ($products as $p) {
66
+ $productById[$p->getEntityId()] = $p;
67
+ }
68
+
69
+ // builds the rows
70
+ $items = array();
71
+
72
+ foreach ($recommendations as $recommendation) {
73
+ $item = new Varien_Object();
74
+ $item->setId($recommendation->getId());
75
+ $item->setPosition($recommendation->getPosition());
76
+
77
+ if (isset($productById[$recommendation->getProductId()])) {
78
+ $product = $productById[$recommendation->getProductId()];
79
+ $item->setName($product->getName());
80
+ $item->setSku($product->getSku());
81
+ $item->setQty($product->getQty());
82
+ $item->setVisibility($product->getVisibility());
83
+ $item->setStatus($product->getStatus());
84
+ }
85
+
86
+ $items[] = $item;
87
+ }
88
+
89
+ $collection = new Mediego_Recommendations_Model_Collection_Memory($items, function($i) { return $i->getData(); });
90
+ $this->setCollection($collection);
91
+
92
+ return parent::_prepareCollection();
93
+ }
94
+
95
+ protected function _prepareColumns()
96
+ {
97
+ $this->addColumn('id', array(
98
+ 'header' => 'ID',
99
+ 'align' => 'right',
100
+ 'width' => '50px',
101
+ 'index' => 'id'
102
+ ));
103
+
104
+ $this->addColumn('position', array(
105
+ 'header' => $this->__('Position'),
106
+ 'align' => 'left',
107
+ 'type' => 'number',
108
+ 'index' => 'position',
109
+ 'width' => '70px'
110
+ ));
111
+
112
+ $this->addColumn('name', array(
113
+ 'header' => $this->__('Product'),
114
+ 'align' => 'left',
115
+ 'index' => 'name'
116
+ ));
117
+
118
+ $this->addColumn('sku', array(
119
+ 'header' => $this->__('SKU'),
120
+ 'width' => '80',
121
+ 'index' => 'sku',
122
+ ));
123
+
124
+ if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
125
+ $this->addColumn('qty', array(
126
+ 'header'=> Mage::helper('catalog')->__('Qty'),
127
+ 'width' => '100px',
128
+ 'type' => 'number',
129
+ 'index' => 'qty',
130
+ ));
131
+ }
132
+
133
+ $this->addColumn('visibility', array(
134
+ 'header'=> Mage::helper('catalog')->__('Visibility'),
135
+ 'width' => '180px',
136
+ 'index' => 'visibility',
137
+ 'type' => 'options',
138
+ 'options' => Mage::getModel('catalog/product_visibility')->getOptionArray(),
139
+ ));
140
+
141
+ $this->addColumn('status', array(
142
+ 'header'=> Mage::helper('catalog')->__('Status'),
143
+ 'width' => '70px',
144
+ 'index' => 'status',
145
+ 'type' => 'options',
146
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
147
+ ));
148
+
149
+ return parent::_prepareColumns();
150
+ }
151
+
152
+ protected function _prepareMassaction()
153
+ {
154
+ $this->setMassactionIdField('id');
155
+ $this->getMassactionBlock()->setFormFieldName('ids');
156
+
157
+ $this->getMassactionBlock()->addItem('delete', array(
158
+ 'label'=> $this->__('Delete'),
159
+ 'url' => $this->getUrl('*/*/massDelete', array('' => '')), // public function massDeleteAction() in Mage_Adminhtml_Tax_RateController
160
+ 'confirm' => $this->__('Are you sure?')
161
+ ));
162
+
163
+ return $this;
164
+ }
165
+
166
+ public function getRowUrl($row)
167
+ {
168
+ return $this->getUrl('*/*/edit', array(
169
+ 'id' => $row->getId()
170
+ ));
171
+ }
172
+ }
app/code/community/Mediego/Recommendations/Block/Adminhtml/Default/Recommendations/Grid/Container.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Grid_Container extends Mage_Adminhtml_Block_Widget_Grid_Container
27
+ {
28
+ public function __construct()
29
+ {
30
+ $this->_controller = 'adminhtml_default_recommendations';
31
+ $this->_blockGroup = 'mediego_recommendations';
32
+ $this->_addButtonLabel = $this->__('Add Recommendation');
33
+
34
+ parent::__construct();
35
+
36
+ $recommendations = Mage::getModel('mediego_recommendations/default_recommendations')->getCollection();
37
+
38
+ $hint = $this->__("The default recommendations acts as a fallback when Mediego can not recommend products. For the widgets to be displayed:") . "<br>∙&nbsp;"
39
+ . $this->__("you need enough default recommendations to fill them") . "<br>∙&nbsp;"
40
+ . $this->__("the products must be visible and enabled") . "<br>"
41
+ . $this->__("Warning: Duplicate products will not be displayed");
42
+
43
+ Mage::getSingleton('adminhtml/session')->addNotice($hint);
44
+ }
45
+
46
+ public function getHeaderText()
47
+ {
48
+ return $this->__('Default Recommendations');
49
+ }
50
+
51
+ public function getHeaderCssClass()
52
+ {
53
+ return 'icon-head head-mediego';
54
+ }
55
+ }
app/code/community/Mediego/Recommendations/Block/Js.php ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Block_Js extends Mage_Core_Block_Template
27
+ {
28
+ public function _construct()
29
+ {
30
+ $this->setTemplate('mediegorecommendations/js.phtml');
31
+
32
+ parent::_construct();
33
+
34
+ $this->addData(array('cache_lifetime' => false));
35
+ $this->addCacheTag(array(
36
+ Mage_Core_Model_Store::CACHE_TAG,
37
+ Mage_Cms_Model_Block::CACHE_TAG,
38
+ ));
39
+ }
40
+
41
+ public function getCacheKeyInfo()
42
+ {
43
+ return array(
44
+ 'MEDIEGO_JS',
45
+ Mage::app()->getStore()->getCode()
46
+ );
47
+ }
48
+
49
+ protected function _toHtml()
50
+ {
51
+ if (!Mage::helper('mediego_recommendations')->isOutputEnabled()) {
52
+ return '';
53
+ }
54
+
55
+ return parent::_toHtml();
56
+ }
57
+ }
app/code/community/Mediego/Recommendations/Block/Widget.php ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Block_Widget extends Mage_Core_Block_Template implements Mage_Widget_Block_Interface
27
+ {
28
+ public function _construct()
29
+ {
30
+ $this->setTemplate('mediegorecommendations/recommendations.phtml');
31
+
32
+ parent::_construct();
33
+
34
+ $this->addData(array('cache_lifetime' => false));
35
+ $this->addCacheTag(array(
36
+ Mage_Core_Model_Store::CACHE_TAG,
37
+ Mage_Cms_Model_Block::CACHE_TAG,
38
+ Mage_Catalog_Model_Product::CACHE_TAG,
39
+ Mediego_Recommendations_Model_Default_Recommendations::CACHE_TAG
40
+ ));
41
+ }
42
+
43
+ public function getLayoutOrientation()
44
+ {
45
+ $layout = $this->getData('layout'); // (getLayout is reserved)
46
+
47
+ if (preg_match('/^[0-9]+x$/', $layout)) {
48
+ return "horizontal";
49
+ } else if (preg_match('/^x[0-9]+$/', $layout)) {
50
+ return "vertical";
51
+ } else {
52
+ return null;
53
+ }
54
+ }
55
+
56
+ public function getDisplayPrice()
57
+ {
58
+ return $this->getData('display_price');
59
+ }
60
+
61
+ public function getGridSize()
62
+ {
63
+ $layoutProductCount = $this->getLayoutProductCount();
64
+
65
+ if ($layoutProductCount > 4) {
66
+ return $layoutProductCount/2;
67
+ } else {
68
+ return $layoutProductCount;
69
+ }
70
+ }
71
+
72
+ public function getLayoutProductCount()
73
+ {
74
+ $layout = $this->getData('layout'); // (getLayout is reserved)
75
+ $matches = array();
76
+
77
+ if (preg_match('/^([0-9]+)x$/', $layout, $matches)) {
78
+ return (int) $matches[1];
79
+ } else if (preg_match('/^x([0-9]+)$/', $layout, $matches)) {
80
+ return (int) $matches[1];
81
+ } else {
82
+ return 0;
83
+ }
84
+ }
85
+
86
+ public function getProducts()
87
+ {
88
+ // gets default recommendations product ids (in the display order). Note we load all of them and use paging
89
+ // later with the producs collection only to have a better chance of having enough products
90
+ $productIds = Mage::getModel('mediego_recommendations/default_recommendations')
91
+ ->getCollection()
92
+ ->addFieldToSelect(array('id','position','product_id'))
93
+ ->setOrder('position','asc')
94
+ ->setOrder('id')
95
+ ->getColumnValues('product_id');
96
+
97
+ // gets the products
98
+ $products = Mage::getModel('catalog/product')
99
+ ->getCollection()
100
+ ->addFieldToFilter('entity_id', array('in' => $productIds))
101
+ ->addMinimalPrice()
102
+ ->addFinalPrice()
103
+ ->addTaxPercents()
104
+ ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
105
+ ->addUrlRewrite();
106
+
107
+ Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
108
+ Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
109
+
110
+ $products->setPageSize($this->getLayoutProductCount());
111
+
112
+ // groups the products by their id
113
+ $productById = array();
114
+
115
+ foreach ($products as $p) {
116
+ $productById[$p->getEntityId()] = $p;
117
+ }
118
+
119
+ // builds the items
120
+ $items = new Varien_Data_Collection();
121
+
122
+ foreach ($productIds as $productId) {
123
+ if (isset($productById[$productId])) {
124
+ $items->addItem($productById[$productId]);
125
+ }
126
+ }
127
+
128
+ return $items;
129
+ }
130
+
131
+ public function getCacheKeyInfo()
132
+ {
133
+ return array(
134
+ 'MEDIEGO_RECOMMENDATIONS_WIDGET',
135
+ Mage::app()->getStore()->getCode(),
136
+ $this->getTemplateFile(),
137
+ 'template' => $this->getTemplate(),
138
+ $this->getModuleKey() ?: '',
139
+ $this->getData('layout'),
140
+ $this->getData('display_price'),
141
+ $this->getData('custom_title')
142
+ );
143
+ }
144
+
145
+ protected function _toHtml()
146
+ {
147
+ if (!Mage::helper('mediego_recommendations')->isOutputEnabled()) {
148
+ return '';
149
+ }
150
+
151
+ return parent::_toHtml();
152
+ }
153
+ }
app/code/community/Mediego/Recommendations/Helper/Chooser.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * Credits goes to Tsvetan Stoychev <tsvetan.stoychev@jarlssen.de> @ http://www.jarlssen.de
23
+ *
24
+ * @category Mediego
25
+ * @package Mediego_Recommendations
26
+ * @author Orinoko <contact@orinoko.fr>
27
+ */
28
+ class Mediego_Recommendations_Helper_Chooser extends Mage_Core_Helper_Abstract
29
+ {
30
+ public function createProductChooser($dataModel, $fieldset, $config)
31
+ {
32
+ $blockAlias = 'adminhtml/catalog_product_widget_chooser';
33
+
34
+ $this->_prepareChooser($dataModel, $fieldset, $config, $blockAlias);
35
+
36
+ return $this;
37
+ }
38
+
39
+ protected function _prepareChooser($dataModel, $fieldset, $config, $blockAlias)
40
+ {
41
+ $this->_populateMissingConfigValues($config, $blockAlias);
42
+
43
+ $chooserConfigData = $this->_prepareChooserConfig($config, $blockAlias);
44
+ $chooserBlock = Mage::app()->getLayout()->createBlock($blockAlias, '', $chooserConfigData);
45
+
46
+ $element = $this->_createFormElement($dataModel, $fieldset, $config);
47
+ $chooserBlock->setConfig($chooserConfigData)
48
+ ->setFieldsetId($fieldset->getId())
49
+ ->prepareElementHtml($element);
50
+
51
+ $this->_fixChooserAjaxUrl($element);
52
+
53
+ return $this;
54
+ }
55
+
56
+ protected function _populateMissingConfigValues(&$config, $blockAlias)
57
+ {
58
+ $currentWidgetKey = str_replace('adminhtml/', '',$blockAlias);
59
+ $chooserDefaults = Mage::getStoreConfig($this->__('Select Product...'));
60
+
61
+ if (!isset($chooserDefaults[$currentWidgetKey])) {
62
+ $currentWidgetKey = 'default';
63
+ }
64
+
65
+ foreach ($chooserDefaults[$currentWidgetKey] as $configKey => $value) {
66
+ if (!isset($config[$configKey])) {
67
+ $config[$configKey] = $value;
68
+ }
69
+ }
70
+
71
+ return $this;
72
+ }
73
+
74
+ protected function _createFormElement($dataModel, $fieldset, $config)
75
+ {
76
+ $isRequired = (isset($config['required']) && true === $config['required']) ? true : false;
77
+
78
+ $inputConfig = array(
79
+ 'name' => $config['input_name'],
80
+ 'label' => $config['input_label'],
81
+ 'required' => $isRequired
82
+ );
83
+
84
+ if (!isset($config['input_id'])) {
85
+ $config['input_id'] = $config['input_name'];
86
+ }
87
+
88
+ $element = $fieldset->addField($config['input_id'], 'label', $inputConfig);
89
+ $element->setValue($dataModel->getData($element->getId()));
90
+ $dataModel->setData($element->getId(),'');
91
+
92
+ return $element;
93
+ }
94
+
95
+ protected function _prepareChooserConfig($config, $blockAlias)
96
+ {
97
+ return array(
98
+ 'button' => array('open' => $config['button_text'],
99
+ 'type' => $blockAlias)
100
+ );
101
+ }
102
+
103
+ protected function _fixChooserAjaxUrl($element)
104
+ {
105
+ $adminPath = (string) Mage::getConfig()->getNode(Mage_Adminhtml_Helper_Data::XML_PATH_ADMINHTML_ROUTER_FRONTNAME);
106
+ $currentRouterName = Mage::app()->getRequest()->getModuleName();
107
+
108
+ if ($adminPath != $currentRouterName) {
109
+ $afterElementHtml = $element->getAfterElementHtml();
110
+ $afterElementHtml = str_replace('/' . $currentRouterName . '/','/' . $adminPath . '/', $afterElementHtml);
111
+ $element->setAfterElementHtml($afterElementHtml);
112
+ }
113
+ }
114
+ }
app/code/community/Mediego/Recommendations/Helper/Data.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Helper_Data extends Mage_Core_Helper_Data
27
+ {
28
+ private $_enabled = null;
29
+ private $_opengraphEnabled = null;
30
+ private $_outputEnabled = null;
31
+
32
+ public function isEnabled()
33
+ {
34
+ if (is_null($this->_enabled)) {
35
+ $this->_enabled = Mage::getStoreConfigFlag('mediego_recommendations/general/enabled');
36
+ }
37
+
38
+ return $this->_enabled;
39
+ }
40
+
41
+ public function isOpengraphEnabled()
42
+ {
43
+ if (!$this->isEnabled()) {
44
+ return false;
45
+ }
46
+
47
+ if (is_null($this->_opengraphEnabled)) {
48
+ $this->_opengraphEnabled = Mage::getStoreConfigFlag('mediego_recommendations/general/open_graph');
49
+ }
50
+
51
+ return $this->_opengraphEnabled;
52
+ }
53
+
54
+ public function isOutputEnabled()
55
+ {
56
+ if (!$this->isEnabled()) {
57
+ return false;
58
+ }
59
+
60
+ if (is_null($this->_outputEnabled)) {
61
+ $this->_outputEnabled = Mage::helper('core')->isModuleOutputEnabled('Mediego_Recommendations');
62
+ }
63
+
64
+ return $this->_outputEnabled;
65
+ }
66
+ }
app/code/community/Mediego/Recommendations/Model/Collection/Memory.php ADDED
@@ -0,0 +1,470 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Model_Collection_Memory extends Varien_Data_Collection
27
+ {
28
+ private $_rawItems = array();
29
+ private $_rowMapper = null;
30
+ private $_filterIncrement = 0;
31
+ private $_filterBrackets = array();
32
+ private $_filterEvalRendered = '';
33
+
34
+ public function __construct($rawItems, $rowMapper = null)
35
+ {
36
+ parent::__construct();
37
+
38
+ $this->_rawItems = $rawItems;
39
+ $this->_rowMapper = $rowMapper;
40
+ }
41
+
42
+ /**
43
+ * Launch data collecting
44
+ *
45
+ * @param bool $printQuery
46
+ * @param bool $logQuery
47
+ * @return Mediego_Recommendations_Model_Collection_Memory
48
+ */
49
+ public function loadData($printQuery = false, $logQuery = false)
50
+ {
51
+ if ($this->isLoaded()) {
52
+ return $this;
53
+ }
54
+
55
+ $this->_generateAndFilterAndSort('_rawItems');
56
+
57
+ // calculate totals
58
+ $this->_totalRecords = count($this->_rawItems);
59
+ $this->_setIsLoaded();
60
+
61
+ // paginate and add items
62
+ $from = ($this->getCurPage() - 1) * $this->getPageSize();
63
+ $to = $from + $this->getPageSize() - 1;
64
+ $isPaginated = $this->getPageSize() > 0;
65
+
66
+ $cnt = 0;
67
+ foreach ($this->_rawItems as $row) {
68
+ $cnt++;
69
+ if ($isPaginated && ($cnt < $from + 1 || $cnt > $to + 1)) {
70
+ continue;
71
+ }
72
+ $item = new $this->_itemObjectClass();
73
+ $this->addItem($item->addData($row));
74
+ if (!$item->hasId()) {
75
+ $item->setId($cnt);
76
+ }
77
+ }
78
+
79
+ return $this;
80
+ }
81
+
82
+ /**
83
+ * With specified collected items:
84
+ * - generate data
85
+ * - apply filters
86
+ * - sort
87
+ */
88
+ private function _generateAndFilterAndSort($attributeName)
89
+ {
90
+ // generate custom data (as rows with columns) basing on the filenames
91
+ foreach ($this->$attributeName as $key => $rawItem) {
92
+ $this->{$attributeName}[$key] = $this->_generateRow($rawItem);
93
+ }
94
+
95
+ // apply filters on generated data
96
+ if (!empty($this->_filters)) {
97
+ foreach ($this->$attributeName as $key => $row) {
98
+ if (!$this->_filterRow($row)) {
99
+ unset($this->{$attributeName}[$key]);
100
+ }
101
+ }
102
+ }
103
+
104
+ // sort (keys are lost!)
105
+ if (!empty($this->_orders)) {
106
+ usort($this->$attributeName, array($this, '_usort'));
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Callback for sorting items
112
+ * Currently supports only sorting by one column
113
+ *
114
+ * @param array $a
115
+ * @param array $b
116
+ * @return int
117
+ */
118
+ protected function _usort($a, $b)
119
+ {
120
+ foreach ($this->_orders as $key => $direction) {
121
+ $result = $a[$key] > $b[$key] ? 1 : ($a[$key] < $b[$key] ? -1 : 0);
122
+ return (self::SORT_ORDER_ASC === strtoupper($direction) ? $result : -$result);
123
+ break;
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Set select order
129
+ * Currently supports only sorting by one column
130
+ *
131
+ * @param string $field
132
+ * @param string $direction
133
+ * @return Varien_Data_Collection
134
+ */
135
+ public function setOrder($field, $direction = self::SORT_ORDER_DESC)
136
+ {
137
+ $this->_orders = array($field => $direction);
138
+ return $this;
139
+ }
140
+
141
+ /**
142
+ * Generate item row based on the value
143
+ *
144
+ * @param mixed $rawItem
145
+ * @return array
146
+ */
147
+ protected function _generateRow($rawItem)
148
+ {
149
+ if (!$this->_rowMapper) {
150
+ throw new Exception('Please specify a row mapper or override _generateRow');
151
+ }
152
+
153
+ return call_user_func($this->_rowMapper, $rawItem);
154
+ }
155
+
156
+ /**
157
+ * Set a custom filter with callback
158
+ * The callback must take 3 params:
159
+ * string $field - field key,
160
+ * mixed $filterValue - value to filter by,
161
+ * array $row - a generated row (before generaring varien objects)
162
+ *
163
+ * @param string $field
164
+ * @param mixed $value
165
+ * @param string $type 'and'|'or'
166
+ * @param callback $callback
167
+ * @param bool $isInverted
168
+ * @return Mediego_Recommendations_Model_Collection_Memory
169
+ */
170
+ public function addCallbackFilter($field, $value, $type, $callback, $isInverted = false)
171
+ {
172
+ $this->_filters[$this->_filterIncrement] = array(
173
+ 'field' => $field,
174
+ 'value' => $value,
175
+ 'is_and' => 'and' === $type,
176
+ 'callback' => $callback,
177
+ 'is_inverted' => $isInverted
178
+ );
179
+ $this->_filterIncrement++;
180
+ return $this;
181
+ }
182
+
183
+ /**
184
+ * The filters renderer and caller
185
+ * Aplies to each row, renders once.
186
+ *
187
+ * @param array $row
188
+ * @return bool
189
+ */
190
+ protected function _filterRow($row)
191
+ {
192
+ // render filters once
193
+ if (!$this->_isFiltersRendered) {
194
+ $eval = '';
195
+ for ($i = 0; $i < $this->_filterIncrement; $i++) {
196
+ if (isset($this->_filterBrackets[$i])) {
197
+ $eval .= $this->_renderConditionBeforeFilterElement($i, $this->_filterBrackets[$i]['is_and'])
198
+ . $this->_filterBrackets[$i]['value'];
199
+ }
200
+ else {
201
+ $f = '$this->_filters[' . $i . ']';
202
+ $eval .= $this->_renderConditionBeforeFilterElement($i, $this->_filters[$i]['is_and'])
203
+ . ($this->_filters[$i]['is_inverted'] ? '!' : '')
204
+ . '$this->_invokeFilter(' . "{$f}['callback'], array({$f}['field'], {$f}['value'], " . '$row))';
205
+ }
206
+ }
207
+ $this->_filterEvalRendered = $eval;
208
+ $this->_isFiltersRendered = true;
209
+ }
210
+ $result = false;
211
+ if ($this->_filterEvalRendered) {
212
+ eval('$result = ' . $this->_filterEvalRendered . ';');
213
+ }
214
+ return $result;
215
+ }
216
+
217
+ /**
218
+ * Invokes specified callback
219
+ * Skips, if there is no filtered key in the row
220
+ *
221
+ * @param callback $callback
222
+ * @param array $callbackParams
223
+ * @return bool
224
+ */
225
+ protected function _invokeFilter($callback, $callbackParams)
226
+ {
227
+ list($field, $value, $row) = $callbackParams;
228
+ if (!array_key_exists($field, $row)) {
229
+ return false;
230
+ }
231
+ return call_user_func_array($callback, $callbackParams);
232
+ }
233
+
234
+ /**
235
+ * Fancy field filter
236
+ *
237
+ * @param string $field
238
+ * @param mixed $cond
239
+ * @param string $type 'and' | 'or'
240
+ * @see Varien_Data_Collection_Db::addFieldToFilter()
241
+ * @return Mediego_Recommendations_Model_Collection_Memory
242
+ */
243
+ public function addFieldToFilter($field, $cond, $type = 'and')
244
+ {
245
+ $inverted = true;
246
+
247
+ // simply check whether equals
248
+ if (!is_array($cond)) {
249
+ return $this->addCallbackFilter($field, $cond, $type, array($this, 'filterCallbackEq'));
250
+ }
251
+
252
+ // versatile filters
253
+ if (isset($cond['from']) || isset($cond['to'])) {
254
+ $this->_addFilterBracket('(', 'and' === $type);
255
+ if (isset($cond['from'])) {
256
+ $this->addCallbackFilter($field, $cond['from'], 'and', array($this, 'filterCallbackIsLessThan'), $inverted);
257
+ }
258
+ if (isset($cond['to'])) {
259
+ $this->addCallbackFilter($field, $cond['to'], 'and', array($this, 'filterCallbackIsMoreThan'), $inverted);
260
+ }
261
+ return $this->_addFilterBracket(')');
262
+ }
263
+ if (isset($cond['eq'])) {
264
+ return $this->addCallbackFilter($field, $cond['eq'], $type, array($this, 'filterCallbackEq'));
265
+ }
266
+ if (isset($cond['neq'])) {
267
+ return $this->addCallbackFilter($field, $cond['neq'], $type, array($this, 'filterCallbackEq'), $inverted);
268
+ }
269
+ if (isset($cond['like'])) {
270
+ return $this->addCallbackFilter($field, $cond['like'], $type, array($this, 'filterCallbackLike'));
271
+ }
272
+ if (isset($cond['nlike'])) {
273
+ return $this->addCallbackFilter($field, $cond['nlike'], $type, array($this, 'filterCallbackLike'), $inverted);
274
+ }
275
+ if (isset($cond['in'])) {
276
+ return $this->addCallbackFilter($field, $cond['in'], $type, array($this, 'filterCallbackInArray'));
277
+ }
278
+ if (isset($cond['nin'])) {
279
+ return $this->addCallbackFilter($field, $cond['nin'], $type, array($this, 'filterCallbackInArray'), $inverted);
280
+ }
281
+ if (isset($cond['notnull'])) {
282
+ return $this->addCallbackFilter($field, $cond['notnull'], $type, array($this, 'filterCallbackIsNull'), $inverted);
283
+ }
284
+ if (isset($cond['null'])) {
285
+ return $this->addCallbackFilter($field, $cond['null'], $type, array($this, 'filterCallbackIsNull'));
286
+ }
287
+ if (isset($cond['moreq'])) {
288
+ return $this->addCallbackFilter($field, $cond['moreq'], $type, array($this, 'filterCallbackIsLessThan'), $inverted);
289
+ }
290
+ if (isset($cond['gt'])) {
291
+ return $this->addCallbackFilter($field, $cond['gt'], $type, array($this, 'filterCallbackIsMoreThan'));
292
+ }
293
+ if (isset($cond['lt'])) {
294
+ return $this->addCallbackFilter($field, $cond['lt'], $type, array($this, 'filterCallbackIsLessThan'));
295
+ }
296
+ if (isset($cond['gteq'])) {
297
+ return $this->addCallbackFilter($field, $cond['gteq'], $type, array($this, 'filterCallbackIsLessThan'), $inverted);
298
+ }
299
+ if (isset($cond['lteq'])) {
300
+ return $this->addCallbackFilter($field, $cond['lteq'], $type, array($this, 'filterCallbackIsMoreThan'), $inverted);
301
+ }
302
+ if (isset($cond['finset'])) {
303
+ $filterValue = ($cond['finset'] ? explode(',', $cond['finset']) : array());
304
+ return $this->addCallbackFilter($field, $filterValue, $type, array($this, 'filterCallbackInArray'));
305
+ }
306
+
307
+ // add OR recursively
308
+ foreach ($cond as $orCond) {
309
+ $this->_addFilterBracket('(', 'and' === $type);
310
+ $this->addFieldToFilter($field, $orCond, 'or');
311
+ $this->_addFilterBracket(')');
312
+ }
313
+ return $this;
314
+ }
315
+
316
+ /**
317
+ * Prepare a bracket into filters
318
+ *
319
+ * @param string $bracket
320
+ * @param bool $isAnd
321
+ * @return Mediego_Recommendations_Model_Collection_Memory
322
+ */
323
+ protected function _addFilterBracket($bracket = '(', $isAnd = true)
324
+ {
325
+ $this->_filterBrackets[$this->_filterIncrement] = array(
326
+ 'value' => $bracket === ')' ? ')' : '(',
327
+ 'is_and' => $isAnd,
328
+ );
329
+ $this->_filterIncrement++;
330
+ return $this;
331
+ }
332
+
333
+ /**
334
+ * Render condition sign before element, if required
335
+ *
336
+ * @param int $increment
337
+ * @param bool $isAnd
338
+ * @return string
339
+ */
340
+ protected function _renderConditionBeforeFilterElement($increment, $isAnd)
341
+ {
342
+ if (isset($this->_filterBrackets[$increment]) && ')' === $this->_filterBrackets[$increment]['value']) {
343
+ return '';
344
+ }
345
+ $prevIncrement = $increment - 1;
346
+ $prevBracket = false;
347
+ if (isset($this->_filterBrackets[$prevIncrement])) {
348
+ $prevBracket = $this->_filterBrackets[$prevIncrement]['value'];
349
+ }
350
+ if ($prevIncrement < 0 || $prevBracket === '(') {
351
+ return '';
352
+ }
353
+ return ($isAnd ? ' && ' : ' || ');
354
+ }
355
+
356
+ /**
357
+ * Does nothing. Intentionally disabled parent method
358
+ *
359
+ * @return Mediego_Recommendations_Model_Collection_Memory
360
+ */
361
+ public function addFilter($field, $value, $type = 'and')
362
+ {
363
+ return $this;
364
+ }
365
+
366
+ /**
367
+ * Get all ids of collected items
368
+ *
369
+ * @return array
370
+ */
371
+ public function getAllIds()
372
+ {
373
+ return array_keys($this->_items);
374
+ }
375
+
376
+ /**
377
+ * Callback method for 'like' fancy filter
378
+ *
379
+ * @param string $field
380
+ * @param mixed $filterValue
381
+ * @param array $row
382
+ * @return bool
383
+ * @see addFieldToFilter()
384
+ * @see addCallbackFilter()
385
+ */
386
+ public function filterCallbackLike($field, $filterValue, $row)
387
+ {
388
+ // [ORK] Remove the quoting of the filter value, if any
389
+ $filterValue = trim($filterValue, "'");
390
+
391
+ $filterValueRegex = str_replace('%', '(.*?)', preg_quote($filterValue, '/'));
392
+
393
+ return (bool)preg_match("/^{$filterValueRegex}$/i", $row[$field]);
394
+ }
395
+
396
+ /**
397
+ * Callback method for 'eq' fancy filter
398
+ *
399
+ * @param string $field
400
+ * @param mixed $filterValue
401
+ * @param array $row
402
+ * @return bool
403
+ * @see addFieldToFilter()
404
+ * @see addCallbackFilter()
405
+ */
406
+ public function filterCallbackEq($field, $filterValue, $row)
407
+ {
408
+ return $filterValue == $row[$field];
409
+ }
410
+
411
+ /**
412
+ * Callback method for 'in' fancy filter
413
+ *
414
+ * @param string $field
415
+ * @param mixed $filterValue
416
+ * @param array $row
417
+ * @return bool
418
+ * @see addFieldToFilter()
419
+ * @see addCallbackFilter()
420
+ */
421
+ public function filterCallbackInArray($field, $filterValue, $row)
422
+ {
423
+ return in_array($row[$field], $filterValue);
424
+ }
425
+
426
+ /**
427
+ * Callback method for 'isnull' fancy filter
428
+ *
429
+ * @param string $field
430
+ * @param mixed $filterValue
431
+ * @param array $row
432
+ * @return bool
433
+ * @see addFieldToFilter()
434
+ * @see addCallbackFilter()
435
+ */
436
+ public function filterCallbackIsNull($field, $filterValue, $row)
437
+ {
438
+ return null === $row[$field];
439
+ }
440
+
441
+ /**
442
+ * Callback method for 'moreq' fancy filter
443
+ *
444
+ * @param string $field
445
+ * @param mixed $filterValue
446
+ * @param array $row
447
+ * @return bool
448
+ * @see addFieldToFilter()
449
+ * @see addCallbackFilter()
450
+ */
451
+ public function filterCallbackIsMoreThan($field, $filterValue, $row)
452
+ {
453
+ return $row[$field] > $filterValue;
454
+ }
455
+
456
+ /**
457
+ * Callback method for 'lteq' fancy filter
458
+ *
459
+ * @param string $field
460
+ * @param mixed $filterValue
461
+ * @param array $row
462
+ * @return bool
463
+ * @see addFieldToFilter()
464
+ * @see addCallbackFilter()
465
+ */
466
+ public function filterCallbackIsLessThan($field, $filterValue, $row)
467
+ {
468
+ return $row[$field] < $filterValue;
469
+ }
470
+ }
app/code/community/Mediego/Recommendations/Model/Default/Recommendations.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Model_Default_Recommendations extends Mage_Core_Model_Abstract
27
+ {
28
+ const CACHE_TAG = 'mediego_recommendations';
29
+
30
+ protected $_eventObject = 'default_recommendations';
31
+ protected $_eventPrefix = 'mediego_recommendations_default_recommendations';
32
+
33
+ public function _construct()
34
+ {
35
+ $this->_init("mediego_recommendations/default_recommendations");
36
+ }
37
+ }
app/code/community/Mediego/Recommendations/Model/Resource/Default/Recommendations.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Model_Resource_Default_Recommendations extends Mage_Core_Model_Resource_Db_Abstract
27
+ {
28
+ public function _construct()
29
+ {
30
+ $this->_init("mediego_recommendations/default_recommendations", "id");
31
+ }
32
+ }
app/code/community/Mediego/Recommendations/Model/Resource/Default/Recommendations/Collection.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Model_Resource_Default_Recommendations_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
27
+ {
28
+ public function _construct()
29
+ {
30
+ $this->_init("mediego_recommendations/default_recommendations");
31
+ }
32
+ }
app/code/community/Mediego/Recommendations/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /**
20
+ * Mediego recommendations
21
+ *
22
+ * @category Mediego
23
+ * @package Mediego_Recommendations
24
+ * @author Orinoko <contact@orinoko.fr>
25
+ */
26
+ class Mediego_Recommendations_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
27
+ {
28
+ protected function _isAllowed()
29
+ {
30
+ return Mage::getSingleton('admin/session')->isAllowed('catalog/mediego_recommendations');
31
+ }
32
+
33
+ public function indexAction()
34
+ {
35
+ $this->loadLayout();
36
+ $this->_setActiveMenu('catalog/mediego_recommendations');
37
+ $this->renderLayout();
38
+ }
39
+
40
+ public function editAction()
41
+ {
42
+ $recommendationId = $this->getRequest()->getParam('id');
43
+ $recommendation = Mage::getModel('mediego_recommendations/default_recommendations');
44
+
45
+ $recommendation->load($recommendationId);
46
+
47
+ Mage::register('mediego_recommendations_data', $recommendation);
48
+
49
+ $this->loadLayout();
50
+ $this->_setActiveMenu('catalog/mediego_recommendations');
51
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
52
+ $this->_addContent($this->getLayout()->createBlock('mediego_recommendations/adminhtml_default_recommendations_edit'));
53
+
54
+ $this->renderLayout();
55
+ }
56
+
57
+ public function newAction()
58
+ {
59
+ $recommendation = Mage::getModel('mediego_recommendations/default_recommendations');
60
+
61
+ Mage::register('mediego_recommendations_data', $recommendation);
62
+
63
+ $this->loadLayout();
64
+ $this->_setActiveMenu('catalog/mediego_recommendations');
65
+ $this->getLayout()->getBlock('head')->setCanLoadExtJs(true);
66
+ $this->_addContent($this->getLayout()->createBlock('mediego_recommendations/adminhtml_default_recommendations_edit'));
67
+
68
+ $this->renderLayout();
69
+ }
70
+
71
+ public function saveAction()
72
+ {
73
+ if ($this->getRequest()->getPost()) {
74
+ try {
75
+ $postData = $this->getRequest()->getPost();
76
+ $productId = (int) explode('/',$postData['product_id'])[1];
77
+ $position = $postData['position'];
78
+
79
+ $recommendation = Mage::getModel('mediego_recommendations/default_recommendations');
80
+ $recommendation->setId($this->getRequest()->getParam('id'))
81
+ ->setProductId($productId)
82
+ ->setPosition($position)
83
+ ->save();
84
+
85
+ Mage::app()->cleanCache(array(Mediego_Recommendations_Model_Default_Recommendations::CACHE_TAG));
86
+
87
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Successfully saved'));
88
+ Mage::getSingleton('adminhtml/session')->setDefaultRecommendationData(false);
89
+
90
+ $this->_redirect('*/*/');
91
+ return;
92
+ } catch (Exception $e){
93
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
94
+ Mage::getSingleton('adminhtml/session')->setDefaultRecommendationData($this->getRequest()->getPost());
95
+
96
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
97
+ return;
98
+ }
99
+ }
100
+
101
+ $this->_redirect('*/*/');
102
+ }
103
+
104
+ public function deleteAction()
105
+ {
106
+ if ($this->getRequest()->getParam('id') > 0) {
107
+ try
108
+ {
109
+ $recommendation = Mage::getModel('mediego_recommendations/default_recommendations');
110
+ $recommendation->setId($this->getRequest()->getParam('id'))
111
+ ->delete();
112
+
113
+ Mage::app()->cleanCache(array(Mediego_Recommendations_Model_Default_Recommendations::CACHE_TAG));
114
+
115
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Successfully deleted'));
116
+
117
+ $this->_redirect('*/*/');
118
+ } catch (Exception $e) {
119
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
120
+
121
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
122
+ }
123
+ }
124
+
125
+ $this->_redirect('*/*/');
126
+ }
127
+
128
+ public function massDeleteAction()
129
+ {
130
+ $ids = $this->getRequest()->getParam('ids');
131
+
132
+ if (!is_array($ids)) {
133
+ Mage::getSingleton('adminhtml/session')->addError($this->__('Please select recommendations'));
134
+ } else {
135
+ try {
136
+ $recommendations = Mage::getModel('mediego_recommendations/default_recommendations')
137
+ ->getCollection()
138
+ ->addFieldToFilter('id', array('in' => array($ids)));
139
+
140
+ foreach ($recommendations as $recommendation) {
141
+ $recommendation->delete();
142
+ }
143
+
144
+ Mage::app()->cleanCache(array(Mediego_Recommendations_Model_Default_Recommendations::CACHE_TAG));
145
+
146
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('%d recommendation(s) were deleted', count($ids)));
147
+ } catch (Exception $e) {
148
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
149
+ }
150
+ }
151
+
152
+ $this->_redirect('*/*/index');
153
+ }
154
+ }
app/code/community/Mediego/Recommendations/etc/adminhtml.xml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.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
+ <mediego_recommendations>
25
+ <title>Mediego</title>
26
+ <sort_order>200</sort_order>
27
+ <action>mediego_recommendations/adminhtml_index</action>
28
+ </mediego_recommendations>
29
+ </children>
30
+ </catalog>
31
+ </menu>
32
+
33
+ <acl>
34
+ <resources>
35
+ <all>
36
+ <title>Allow Everything</title>
37
+ </all>
38
+ <admin>
39
+ <children>
40
+ <catalog>
41
+ <children>
42
+ <mediego_recommendations>
43
+ <title>Mediego</title>
44
+ </mediego_recommendations>
45
+ </children>
46
+ </catalog>
47
+ <system>
48
+ <children>
49
+ <config>
50
+ <children>
51
+ <mediego_recommendations>
52
+ <title>Mediego</title>
53
+ </mediego_recommendations>
54
+ </children>
55
+ </config>
56
+ </children>
57
+ </system>
58
+ </children>
59
+ </admin>
60
+ </resources>
61
+ </acl>
62
+ </config>
app/code/community/Mediego/Recommendations/etc/compilation.xml ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <!--
22
+ Regenerate using:
23
+
24
+ find -name '*.php' | grep -v 'sql/' | sed 's,^./,Mediego_Recommendations_,g; s,/,_,g; s,.php,,g; s,^,<,g; s,$,/>,g;' | grep -v _controllers_ | sort
25
+ -->
26
+ <includes>
27
+ <mediego_recommendations>
28
+ <Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Edit/>
29
+ <Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Edit_Form/>
30
+ <Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Edit_Tab_Form/>
31
+ <Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Edit_Tabs/>
32
+ <Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Grid/>
33
+ <Mediego_Recommendations_Block_Adminhtml_Default_Recommendations_Grid_Container/>
34
+ <Mediego_Recommendations_Block_Js/>
35
+ <Mediego_Recommendations_Block_Widget/>
36
+ <Mediego_Recommendations_Helper_Chooser/>
37
+ <Mediego_Recommendations_Helper_Data/>
38
+ <Mediego_Recommendations_Model_Collection_Memory/>
39
+ <Mediego_Recommendations_Model_Default_Recommendations/>
40
+ <Mediego_Recommendations_Model_Resource_Default_Recommendations/>
41
+ <Mediego_Recommendations_Model_Resource_Default_Recommendations_Collection/>
42
+ </mediego_recommendations>
43
+ </includes>
44
+ </config>
app/code/community/Mediego/Recommendations/etc/config.xml ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <Mediego_Recommendations>
23
+ <version>1.0.0</version>
24
+ </Mediego_Recommendations>
25
+ </modules>
26
+ <global>
27
+ <models>
28
+ <mediego_recommendations>
29
+ <class>Mediego_Recommendations_Model</class>
30
+ <resourceModel>mediego_recommendations_resource</resourceModel>
31
+ </mediego_recommendations>
32
+ <mediego_recommendations_resource>
33
+ <class>Mediego_Recommendations_Model_Resource</class>
34
+ <entities>
35
+ <default_recommendations>
36
+ <table>mediego_recommendations_default_recommendations</table>
37
+ </default_recommendations>
38
+ </entities>
39
+ </mediego_recommendations_resource>
40
+ </models>
41
+ <resources>
42
+ <mediego_recommendations_setup>
43
+ <connection>
44
+ <use>core_setup</use>
45
+ </connection>
46
+ <setup>
47
+ <module>Mediego_Recommendations</module>
48
+ </setup>
49
+ </mediego_recommendations_setup>
50
+ </resources>
51
+ <blocks>
52
+ <mediego_recommendations>
53
+ <class>Mediego_Recommendations_Block</class>
54
+ </mediego_recommendations>
55
+ </blocks>
56
+ <helpers>
57
+ <mediego_recommendations>
58
+ <class>Mediego_Recommendations_Helper</class>
59
+ </mediego_recommendations>
60
+ </helpers>
61
+ </global>
62
+ <frontend>
63
+ <layout>
64
+ <updates>
65
+ <mediego_recommendations>
66
+ <file>mediegorecommendations.xml</file>
67
+ </mediego_recommendations>
68
+ </updates>
69
+ </layout>
70
+ <translate>
71
+ <modules>
72
+ <mediego_recommendations>
73
+ <files>
74
+ <default>Mediego_Recommendations.csv</default>
75
+ </files>
76
+ </mediego_recommendations>
77
+ </modules>
78
+ </translate>
79
+ </frontend>
80
+ <admin>
81
+ <routers>
82
+ <mediego_recommendations>
83
+ <use>admin</use>
84
+ <args>
85
+ <module>Mediego_Recommendations</module>
86
+ <frontName>mediego_recommendations</frontName>
87
+ </args>
88
+ </mediego_recommendations>
89
+ </routers>
90
+ </admin>
91
+ <adminhtml>
92
+ <translate>
93
+ <modules>
94
+ <mediego_recommendations>
95
+ <files>
96
+ <default>Mediego_Recommendations.csv</default>
97
+ </files>
98
+ </mediego_recommendations>
99
+ </modules>
100
+ </translate>
101
+ <layout>
102
+ <updates>
103
+ <mediego_recommendations>
104
+ <file>mediegorecommendations.xml</file>
105
+ </mediego_recommendations>
106
+ </updates>
107
+ </layout>
108
+ </adminhtml>
109
+ <default>
110
+ <mediego_recommendations>
111
+ <general>
112
+ <enabled>1</enabled>
113
+ <open_graph>1</open_graph>
114
+ </general>
115
+ </mediego_recommendations>
116
+ </default>
117
+ </config>
app/code/community/Mediego/Recommendations/etc/system.xml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <sections>
22
+ <mediego_recommendations>
23
+ <label>Mediego</label>
24
+ <tab>catalog</tab>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>200</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>1</show_in_website>
29
+ <show_in_store>1</show_in_store>
30
+ <groups>
31
+ <general translate="label" module="mediego_recommendations">
32
+ <label>General</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>10</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <fields>
39
+ <enabled translate="label" module="mediego_recommendations">
40
+ <label>Enabled</label>
41
+ <frontend_type>select</frontend_type>
42
+ <source_model>adminhtml/system_config_source_yesno</source_model>
43
+ <sort_order>10</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>1</show_in_website>
46
+ <show_in_store>1</show_in_store>
47
+ </enabled>
48
+ <open_graph translate="label" module="mediego_recommendations">
49
+ <label>Open Graph tagging</label>
50
+ <frontend_type>select</frontend_type>
51
+ <source_model>adminhtml/system_config_source_yesno</source_model>
52
+ <sort_order>20</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>1</show_in_website>
55
+ <show_in_store>1</show_in_store>
56
+ </open_graph>
57
+ </fields>
58
+ </general>
59
+ </groups>
60
+ </mediego_recommendations>
61
+ </sections>
62
+ </config>
app/code/community/Mediego/Recommendations/etc/widget.xml ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <widgets>
21
+ <mediego_recommendations_widget type="mediego_recommendations/widget" translate="name description" module="mediego_recommendations">
22
+ <name>Mediego Recommendations</name>
23
+ <description>Displays Mediego recommendations</description>
24
+ <parameters>
25
+ <layout translate="label description" module="mediego_recommendations">
26
+ <label>Layout</label>
27
+ <description>You must have enough default recommendations in the Catalog &gt; Mediego menu, otherwise no recommendation will be suggested at all.</description>
28
+ <visible>1</visible>
29
+ <required>1</required>
30
+ <type>select</type>
31
+ <value>3x</value>
32
+ <values>
33
+ <h1 translate="label">
34
+ <value>1x</value>
35
+ <label>Horizontal - 1 recommendation</label>
36
+ </h1>
37
+ <h3 translate="label">
38
+ <value>3x</value>
39
+ <label>Horizontal - 3 recommendations</label>
40
+ </h3>
41
+ <h4 translate="label">
42
+ <value>4x</value>
43
+ <label>Horizontal - 4 recommendations</label>
44
+ </h4>
45
+ <h6 translate="label">
46
+ <value>6x</value>
47
+ <label>Horizontal - 6 recommendations</label>
48
+ </h6>
49
+ <h8 translate="label">
50
+ <value>8x</value>
51
+ <label>Horizontal - 8 recommendations</label>
52
+ </h8>
53
+ <v1 translate="label">
54
+ <value>x1</value>
55
+ <label>Vertical - 1 recommendation</label>
56
+ </v1>
57
+ <v3 translate="label">
58
+ <value>x3</value>
59
+ <label>Vertical - 3 recommendations</label>
60
+ </v3>
61
+ </values>
62
+ </layout>
63
+ <custom_title translate="label" module="mediego_recommendations">
64
+ <label>Custom Title</label>
65
+ <visible>1</visible>
66
+ <type>text</type>
67
+ </custom_title>
68
+ <display_price translate="label" module="mediego_recommendations">
69
+ <label>Display price</label>
70
+ <visible>1</visible>
71
+ <type>select</type>
72
+ <value>false</value>
73
+ <values>
74
+ <no translate="label">
75
+ <value>false</value>
76
+ <label>No</label>
77
+ </no>
78
+ <yes translate="label">
79
+ <value>true</value>
80
+ <label>Yes</label>
81
+ </yes>
82
+ </values>
83
+ </display_price>
84
+ <module_key translate="label description" module="mediego_recommendations">
85
+ <label>Module Key (advanced)</label>
86
+ <description>The identifier used to differenciate multiple widgets in the same page.</description>
87
+ <visible>1</visible>
88
+ <type>text</type>
89
+ </module_key>
90
+ </parameters>
91
+ </mediego_recommendations_widget>
92
+ </widgets>
app/code/community/Mediego/Recommendations/sql/mediego_recommendations_setup/install-0.1.0.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+
19
+ /* @var @installer Mage_Core_Model_Resource_Setup */
20
+ $installer = $this;
21
+ $installer->startSetup();
22
+
23
+ $table = $installer->getConnection()
24
+ ->newTable($installer->getTable('mediego_recommendations/default_recommendations'))
25
+ ->addColumn('id', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
26
+ array(
27
+ 'nullable' => false,
28
+ 'identity' => true,
29
+ 'unsigned' => true,
30
+ 'primary' => true,
31
+ ),
32
+ 'Primary key, auto increment')
33
+ ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(), 'Product Id')
34
+ ->addColumn('position', Varien_Db_Ddl_Table::TYPE_INTEGER, null,
35
+ array(
36
+ 'unsigned' => true,
37
+ 'nullable' => false,
38
+ 'default' => 0,
39
+ ),
40
+ 'Position')
41
+ ->addForeignKey(
42
+ $installer->getFkName(
43
+ 'mediego_recommendations/default_recommendations',
44
+ 'product_id',
45
+ 'catalog/product',
46
+ 'entity_id'
47
+ ),
48
+ 'product_id',
49
+ $installer->getTable('catalog/product'),
50
+ 'entity_id',
51
+ Varien_Db_Ddl_Table::ACTION_CASCADE,
52
+ Varien_Db_Ddl_Table::ACTION_CASCADE)
53
+ ->setComment('Default recommendations for module Mediego_Recommendations');
54
+ $installer->getConnection()->createTable($table);
55
+
56
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/mediegorecommendations.xml ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <layout version="0.1.0">
21
+ <default>
22
+ <update handle="editor"/>
23
+ <reference name="head">
24
+ <action method="addCss"><name>mediego_recommendations.css</name></action>
25
+ </reference>
26
+ </default>
27
+ <mediego_recommendations_adminhtml_index_index>
28
+ <reference name="content">
29
+ <block type="mediego_recommendations/adminhtml_default_recommendations_grid_container" name="mediego_recommendations" />
30
+ </reference>
31
+ </mediego_recommendations_adminhtml_index_index>
32
+ </layout>
app/design/frontend/base/default/layout/mediegorecommendations.xml ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+
21
+ <layout version="0.1.0">
22
+ <default>
23
+ <reference name="head">
24
+ <action method="addCss"><stylesheet>css/mediego.css</stylesheet></action>
25
+ <block type="core/template" name="mediego.js" template="mediegorecommendations/js.phtml"/>
26
+ <block type="core/template" name="head.opengraph" template="mediegorecommendations/opengraph.phtml"/>
27
+ </reference>
28
+ </default>
29
+ </layout>
app/design/frontend/base/default/template/mediegorecommendations/js.phtml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ ?>
19
+ <script type="text/javascript" src="//mediego.com/agent.js"></script>
app/design/frontend/base/default/template/mediegorecommendations/opengraph.phtml ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ ?>
19
+ <?php
20
+ $_enabled = Mage::helper('mediego_recommendations')->isOpengraphEnabled();
21
+
22
+ if ($_enabled && $this->getRequest()->getModuleName() == 'catalog'
23
+ && $this->getRequest()->getControllerName() == 'product'):
24
+ $_product = Mage::registry('current_product');
25
+
26
+ // add minimal price support for tier priced products
27
+ if($_product->getFinalPrice() == 0) {
28
+ $_product = Mage::getModel("catalog/product")->getCollection()
29
+ ->addAttributeToSelect(Mage::getSingleton("catalog/config")->getProductAttributes())
30
+ ->addAttributeToFilter("entity_id", $_product->getId())
31
+ ->setPage(1, 1)
32
+ ->addMinimalPrice()
33
+ ->addFinalPrice()
34
+ ->load()
35
+ ->getFirstItem();
36
+ }
37
+
38
+ $_storeCcySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>
39
+
40
+ <?php if ($_product): ?>
41
+ <meta property="og:type" content="product"/>
42
+ <meta property="og:url" content="<?php echo $_product->getProductUrl(); ?>"/>
43
+ <meta property="og:title" content="<?php echo htmlspecialchars($_product->getName()) ?>" />
44
+ <meta property="product:name" content="<?php echo htmlspecialchars($_product->getName()) ?>" />
45
+ <meta property="product:original_price:amount" content="<?php echo number_format($_product->getPrice(), 2, ".", " ") ?>" />
46
+ <meta property="product:original_price:currency" content="<?php echo $_storeCcySymbol ?>" />
47
+ <meta property="product:price:amount" content="<?php echo number_format($_product->getFinalPrice() == 0 ? $_product->getMinimalPrice() : $_product->getFinalPrice(), 2, ".", " ") ?>" />
48
+ <meta property="product:price:currency" content="<?php echo $_storeCcySymbol ?>" />
49
+ <meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210); ?>" />
50
+ <?php endif; ?>
51
+ <?php endif; ?>
app/design/frontend/base/default/template/mediegorecommendations/recommendations.phtml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ ?>
19
+ <?php
20
+ $_layoutOrientation = $this->getLayoutOrientation();
21
+ $_layoutProductCount = $this->getLayoutProductCount();
22
+ $_displayPrice = $this->getDisplayPrice();
23
+ $_gridSize = $this->getGridSize();
24
+ $_storeCcySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
25
+ $_productBlock = $this->getLayout()->createBlock('catalog/product_price');
26
+ $_safeTitle = $this->hasCustomTitle() ? $this->escapeHtml($this->getCustomTitle()) : $this->__('Recommended Products');
27
+ $_moduleKey = $this->getModuleKey();
28
+ $_products = $this->getProducts();
29
+ ?>
30
+ <?php if ($_products->getSize() && $_products->getSize() >= $_layoutProductCount): ?>
31
+ <?php
32
+ $_i = 'A';
33
+ ?>
34
+ <div class="widget widget-mediego <?php echo $_layoutOrientation ?>">
35
+ <?php if ($_layoutOrientation == 'horizontal'): ?>
36
+ <div class="widget-title"><h2><?php echo $_safeTitle ?></h2></div>
37
+ <div class="widget-products">
38
+ <ul class="products-grid products-grid--max-<?php echo $_gridSize ?>-col-widget">
39
+ <?php else: ?>
40
+ <div class="block block-products">
41
+ <div class="block-title">
42
+ <strong><span><?php echo $_safeTitle ?></span></strong>
43
+ </div>
44
+ <div class="block-content">
45
+ <?php endif; ?>
46
+
47
+ <?php foreach ($_products as $_product): ?>
48
+ <li class="item">
49
+ <a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image mediego mediego.item<?php echo $_i ?>.link<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>">
50
+ <img class="mediego mediego.item<?php echo $_i ?>.image<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135); ?>" width="135" height="135" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
51
+ </a>
52
+ <div class="product-info">
53
+ <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="mediego mediego.item<?php echo $_i ?>.link<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>">
54
+ <h2 class="mediego mediego.item<?php echo $_i ?>.title<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?> product-name"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></h2>
55
+ <div class="price-box">
56
+ <span class="regular-price">
57
+ <span class="price"><span class="mediego mediego.item<?php echo $_i ?>.metadata['product:price:amount']<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>"><?php echo number_format($_product->getFinalPrice() == 0 ? $_product->getMinimalPrice() : $_product->getFinalPrice(), 2, ",", " ") ?></span> <span class="mediego mediego.item<?php echo $_i ?>.metadata['product:price:currency']<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>"><?php echo $_storeCcySymbol ?></span></span>
58
+ </span>
59
+ </div>
60
+ </a>
61
+ </div>
62
+ </li>
63
+ <?php
64
+ $_i++;
65
+ ?>
66
+ <?php endforeach; ?>
67
+ <?php if ($_layoutOrientation == 'horizontal'): ?>
68
+ </ul>
69
+ <?php else: ?>
70
+ </div>
71
+ <?php endif; ?>
72
+ </div>
73
+ </div>
74
+ <?php endif; ?>
app/design/frontend/rwd/default/template/mediegorecommendations/recommendations.phtml ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Mediego
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ *
12
+ * @category Mediego
13
+ * @package Mediego_Recommendations
14
+ * @author Orinoko <contact@orinoko.fr>
15
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ ?>
19
+ <?php
20
+ $_layoutOrientation = $this->getLayoutOrientation();
21
+ $_layoutProductCount = $this->getLayoutProductCount();
22
+ $_displayPrice = $this->getDisplayPrice();
23
+ $_gridSize = $this->getGridSize();
24
+ $_storeCcySymbol = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
25
+ $_productBlock = $this->getLayout()->createBlock('catalog/product_price');
26
+ $_safeTitle = $this->hasCustomTitle() ? $this->escapeHtml($this->getCustomTitle()) : $this->__('Recommended Products');
27
+ $_moduleKey = $this->getModuleKey();
28
+ $_products = $this->getProducts();
29
+ ?>
30
+ <?php if ($_products->getSize() && $_products->getSize() >= $_layoutProductCount): ?>
31
+ <?php
32
+ $_i = 'A';
33
+ ?>
34
+ <div class="widget widget-mediego <?php echo $_layoutOrientation ?>">
35
+ <?php if ($_layoutOrientation == 'horizontal'): ?>
36
+ <div class="widget-title"><h2><?php echo $_safeTitle ?></h2></div>
37
+ <div class="widget-products">
38
+ <ul class="products-grid products-grid--max-<?php echo $_gridSize ?>-col-widget">
39
+ <?php else: ?>
40
+ <div class="block block-products">
41
+ <div class="block-title">
42
+ <strong><span><?php echo $_safeTitle ?></span></strong>
43
+ </div>
44
+ <div class="block-content">
45
+ <?php endif; ?>
46
+
47
+ <?php foreach ($_products as $_product): ?>
48
+ <li class="item">
49
+ <a href="<?php echo $_product->getProductUrl(); ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image mediego mediego.item<?php echo $_i ?>.link<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>">
50
+ <img class="mediego mediego.item<?php echo $_i ?>.image<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210); ?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
51
+ </a>
52
+ <div class="product-info">
53
+ <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="mediego mediego.item<?php echo $_i ?>.link<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>">
54
+ <h2 class="mediego mediego.item<?php echo $_i ?>.title<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?> product-name"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></h2>
55
+ <div class="price-box">
56
+ <span class="regular-price">
57
+ <span class="price"><span class="mediego mediego.item<?php echo $_i ?>.metadata['product:price:amount']<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>"><?php echo number_format($_product->getFinalPrice() == 0 ? $_product->getMinimalPrice() : $_product->getFinalPrice(), 2, ",", " ") ?></span> <span class="mediego mediego.item<?php echo $_i ?>.metadata['product:price:currency']<?php if($_moduleKey): ?> mediego.id.<?php echo $_moduleKey; endif; ?>"><?php echo $_storeCcySymbol ?></span></span>
58
+ </span>
59
+ </div>
60
+ </a>
61
+ </div>
62
+ </li>
63
+ <?php
64
+ $_i++;
65
+ ?>
66
+ <?php endforeach; ?>
67
+ <?php if ($_layoutOrientation == 'horizontal'): ?>
68
+ </ul>
69
+ <?php else: ?>
70
+ </div>
71
+ <?php endif; ?>
72
+ </div>
73
+ </div>
74
+ <?php endif; ?>
app/etc/modules/Mediego_Recommendations.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="utf-8" standalone="no"?>
2
+ <!--
3
+ /**
4
+ * Mediego
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Open Software License (OSL 3.0)
9
+ * that is bundled with this package in the file LICENSE.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/osl-3.0.php
12
+ *
13
+ * @category Mediego
14
+ * @package Mediego_Recommendations
15
+ * @author Orinoko <contact@orinoko.fr>
16
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
17
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
18
+ */
19
+ -->
20
+ <config>
21
+ <modules>
22
+ <Mediego_Recommendations>
23
+ <active>true</active>
24
+ <codePool>community</codePool>
25
+ <depends>
26
+ <Mage_Adminhtml/>
27
+ <Mage_Catalog/>
28
+ </depends>
29
+ </Mediego_Recommendations>
30
+ </modules>
31
+ </config>
app/locale/fr_FR/Mediego_Recommendations.csv ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ "Enabled","Activé"
2
+ "Product","Produit"
3
+ "Details","Details"
4
+ "Select Product...","Choisir un produit..."
5
+ "Position","Position"
6
+ "Recommendation","Recommandation"
7
+ "General","Général"
8
+ "Default Recommendations","Recommandations par défaut"
9
+ "Add Recommendation","Ajouter une recommandation"
10
+ "The default recommendations acts as a fallback when Mediego can not recommend products. For the widgets to be displayed:","Les recommandations par défaut sont utilisées si Mediego ne peut recommander de produit. Pour que les widgets s'affichent :"
11
+ "you need enough default recommendations to fill them","vous devez avoir suffisamment de recommendations par défaut pour les remplir"
12
+ "the products must be visible and enabled","les produits doivent être visibles et activés"
13
+ "Save","Sauvegarder"
14
+ "Delete","Supprimer"
15
+ "Recommendation Details","Détails de la recommandation"
16
+ "Position","Position"
17
+ "Are you sure?","Êtes-vous certain ?"
18
+ "Successfully saved","Sauvegardé avec succès"
19
+ "Successfully deleted","Supprimé avec succès"
20
+ "Please select recommendations","Veuillez sélectionner au moins une recommandation"
21
+ "%d recommendation(s) were deleted","%d recommandation(s) supprimée(s)"
22
+ "Horizontal","Horizontal"
23
+ "Vertical (up to 3 recommendations)","Vertical (max. 3 recommandations)"
24
+ "Recommended Products","Produits recommandés"
25
+ "Open Graph tagging","Marquage Open Graph"
26
+ "Mediego Recommendations","Recommandations Mediego"
27
+ "Displays Mediego recommendations","Affiche les recommandations Mediego"
28
+ "Layout","Agencement"
29
+ "Custom Title","Titre personnalisé"
30
+ "Module Key (advanced)","Clé du module (avancé)"
31
+ "You must have enough default recommendations in the Catalog > Mediego menu, otherwise no recommendation will be suggested at all.","Vous devez avoir suffisamment de recommandations par défaut dans le menu Catalogue > Mediego, sinon aucune suggestion ne sera proposée."
32
+ "The identifier used to differenciate multiple widgets in the same page.","L'identifiant utilisé pour différencier plusieurs widgets dans une même page."
33
+ "Horizontal - 1 recommendation","Horizontal - 1 recommandation"
34
+ "Horizontal - 3 recommendations","Horizontal - 3 recommandations"
35
+ "Horizontal - 4 recommendations","Horizontal - 4 recommandations"
36
+ "Horizontal - 6 recommendations","Horizontal - 6 recommandations"
37
+ "Horizontal - 8 recommendations","Horizontal - 8 recommandations"
38
+ "Vertical - 1 recommendation","Vertical - 1 recommandation"
39
+ "Vertical - 3 recommendations","Vertical - 3 recommandations"
40
+ "Warning: Duplicate products will not be displayed","Attention : Les produits en double ne seront pas affichés"
41
+ "Display price","Afficher le prix"
package.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>mediego-recommendations</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Gr&#xE2;ce &#xE0; son algorithme de similarit&#xE9; entre utilisateurs, Mediego assure la pertinence de vos recommandations.</summary>
10
+ <description>Gr&#xE2;ce &#xE0; son algorithme de similarit&#xE9; entre utilisateurs, Mediego assure la pertinence de vos recommandations en temps r&#xE9;el et fluidifie la navigation des visiteurs sur votre site.&#xD;
11
+ &#xD;
12
+ Offrez une exp&#xE9;rience unique &#xE0; vos internautes.&#xD;
13
+ &#xD;
14
+ Issue de 4 ann&#xE9;es de recherche et d&#xE9;veloppement au sein du laboratoire Inria (Rennes), Mediego identifie les similarit&#xE9;s entre internautes pour offrir des contenus pertinents et personnalis&#xE9;s d&#xE8;s la premi&#xE8;re visite.&#xD;
15
+ En moyenne les contenus personnalis&#xE9;s sont 150% fois plus cliqu&#xE9;s que les recommandations bas&#xE9;es sur la popularit&#xE9;.&#xD;
16
+ &#xD;
17
+ Configurez votre moteur de recommandation en quelques clics.&#xD;
18
+ &#xD;
19
+ Installez l'extension Mediego depuis Magento Connect.&#xD;
20
+ Gr&#xE2;ce au syst&#xE8;me de widget int&#xE9;gr&#xE9; &#xE0; Magento, vous pourrez ais&#xE9;ment choisir l'emplacement de votre module de recommandations personnalis&#xE9;es.&#xD;
21
+ Une configuration suppl&#xE9;mentaire ainsi que la cr&#xE9;ation d'un compte sur le site http://www.mediego.com sera n&#xE9;cessaire au bon fonctionnement du module.&#xD;
22
+ Pour plus d'informations sur l'installation et la configuration de l'extension Mediego, veuillez consulter la documentation, ou contacter le support.</description>
23
+ <notes>Version initiale</notes>
24
+ <authors><author><name>Orinoko</name><user>orinoko</user><email>mediego-support@orinoko.fr</email></author></authors>
25
+ <date>2015-09-09</date>
26
+ <time>14:54:46</time>
27
+ <contents><target name="magecommunity"><dir name="Mediego"><dir name="Recommendations"><dir name="Block"><dir name="Adminhtml"><dir name="Default"><dir name="Recommendations"><dir name="Edit"><file name="Form.php" hash="0aa1e945924691a374add3c1d69450d1"/></dir><file name="Edit.php" hash="56b05309fc9cd441bfa2b7735271bee9"/><dir name="Grid"><file name="Container.php" hash="ad371bfaeca9ad2e8633b18c530df100"/></dir><file name="Grid.php" hash="eec0447cbd397a1d207250bdd4d3bd1d"/></dir></dir></dir><file name="Js.php" hash="2367fd6fd4817207bda2186593b32974"/><file name="Widget.php" hash="b1572ab1449a4ba3a19b954d646fb990"/></dir><dir name="Helper"><file name="Chooser.php" hash="07971c470ee62085c2cdc59c65c3c266"/><file name="Data.php" hash="190d4ad025e34fec68c76d5326c220da"/></dir><dir name="Model"><dir name="Collection"><file name="Memory.php" hash="f590c03359f1f0e0867cdbb623e08861"/></dir><dir name="Default"><file name="Recommendations.php" hash="6671393288e6124a374c306080c465d2"/></dir><dir name="Resource"><dir name="Default"><dir name="Recommendations"><file name="Collection.php" hash="a999a2302cdfee2fa324a9a04fe1d911"/></dir><file name="Recommendations.php" hash="eb34654d19b5974c045f681a9ec45f49"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="a749d0ae84f6c0bb5280a6d3157eb8b1"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="69905157d496c82b4d975c88dfe553a4"/><file name="compilation.xml" hash="65799ccd970704535384a031b4c404e3"/><file name="config.xml" hash="ba5f4a253a821e336f00cba83b663dc5"/><file name="system.xml" hash="61ac46a7c68c07054f6c48caba4e7f3c"/><file name="widget.xml" hash="7d965ab65487f1c403e4c8c1f33fc7a8"/></dir><dir name="sql"><dir name="mediego_recommendations_setup"><file name="install-0.1.0.php" hash="f27b91ac14fc1f7e89b76f99920731d8"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="mediegorecommendations.xml" hash="ead8503e2c23e766d7fde355a8212172"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="mediegorecommendations.xml" hash="3487d583bb88928fa9116cc37538bb8b"/></dir><dir name="template"><dir name="mediegorecommendations"><file name="js.phtml" hash="8c9c2b0c9c999c50be6a5d9faed3ba71"/><file name="opengraph.phtml" hash="ecd8f30db9f745461fc4f8cf9f438e45"/><file name="recommendations.phtml" hash="054c22d0e78b7f5c2f038697e2446ebc"/></dir></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="template"><dir name="mediegorecommendations"><file name="recommendations.phtml" hash="656c60b4b07f02722ad28b955c161e98"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mediego_Recommendations.xml" hash="9cf968757c07148be11920162ef52941"/></dir></target><target name="magelocale"><dir name="fr_FR"><file name="Mediego_Recommendations.csv" hash="bbdc69e39725e6f3676c5858aca6e12b"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="images"><file name="mediego.png" hash="4045dfc753ebe6d3d2f2fa7fc52879b0"/><dir name="widget"><file name="mediego_recommendations__widget.gif" hash="aaf11e748d1be1ba4772e3d6eafbc595"/></dir></dir><file name="mediego_recommendations.css" hash="72890e33da89f826b13a68fb163b22a4"/></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="css"><file name="mediego.css" hash="9a3f509c75c573ef92912e362957df69"/></dir></dir></dir><dir name="rwd"><dir name="default"><dir name="css"><file name="mediego.css" hash="c6da043c418b4024805bd50f5f46005d"/></dir></dir></dir></dir></target></contents>
28
+ <compatible/>
29
+ <dependencies><required><php><min>5.4.0</min><max>5.6.13</max></php></required></dependencies>
30
+ </package>
skin/adminhtml/default/default/images/mediego.png ADDED
Binary file
skin/adminhtml/default/default/images/widget/mediego_recommendations__widget.gif ADDED
Binary file
skin/adminhtml/default/default/mediego_recommendations.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .head-mediego { background-image: url(images/mediego.png); }
2
+ #widget_options #widget_options_mediego_recommendations_widget .form-list td.value p.note { width: 500px; }
skin/frontend/base/default/css/mediego.css ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Mediego
3
+ *
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL 3.0)
7
+ * that is bundled with this package in the file LICENSE.txt.
8
+ * It is also available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category Mediego
12
+ * @package Mediego_Recommendations
13
+ * @author Orinoko <contact@orinoko.fr>
14
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ .widget-mediego {
18
+ display: block;
19
+ width: 100%;
20
+ margin-top: 20px;
21
+ text-align: center;
22
+ }
23
+
24
+ .col-main .widget-mediego { margin:7px 0; }
25
+ .widget-mediego .products-grid .product-image,
26
+ .widget-mediego .products-list .product-image { width:135px; height:135px; }
27
+ .widget-mediego .products-list .product-shop { margin-left:100px; }
28
+ .widget-mediego .products-grid .item { padding-bottom:12px; }
29
+ .widget-mediego .product-info > a { text-decoration: none; }
30
+ .widget-mediego .product-info > a > h2 { text-decoration: underline; }
31
+ .widget-mediego .product-info > a > h2:hover { text-decoration: none; }
32
+ .sidebar .widget-mediego .block { font-size:11px; line-height:1.25; }
33
+ .sidebar .widget-mediego .block-title strong { color:#dc5033; }
34
+
35
+
36
+ .widget-mediego .item { list-style-type: none; }
skin/frontend/rwd/default/css/mediego.css ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Mediego
3
+ *
4
+ * NOTICE OF LICENSE
5
+ *
6
+ * This source file is subject to the Open Software License (OSL 3.0)
7
+ * that is bundled with this package in the file LICENSE.txt.
8
+ * It is also available through the world-wide-web at this URL:
9
+ * http://opensource.org/licenses/osl-3.0.php
10
+ *
11
+ * @category Mediego
12
+ * @package Mediego_Recommendations
13
+ * @author Orinoko <contact@orinoko.fr>
14
+ * @copyright Copyright (c) 2014-2015 Mediego (http://mediego.com)
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ .widget-mediego {
18
+ display: block;
19
+ width: 100%;
20
+ margin-top: 20px;
21
+ text-align: center;
22
+ }
23
+
24
+ .widget-mediego .product-image {
25
+ margin: 15px auto 5px auto;
26
+ max-width: 210px;
27
+ max-height: 210px;
28
+ }
29
+
30
+ .widget-mediego .item { list-style-type: none; }
31
+ .widget-mediego .item .product-info { padding-bottom:0px; }
32
+ .widget-mediego .item .product-info > a { text-decoration : none; }
33
+
34
+ .widget-mediego.horizontal .products-grid.products-grid--max-1-col-widget .item {
35
+ float:none;
36
+ margin: 0 auto;
37
+ }
38
+
39
+ .widget-mediego.vertical { margin-top:0px; }
40
+ .widget-mediego.vertical .block-title { text-align: start; }
41
+ .widget-mediego.vertical .product-image { margin: 15px auto 5px auto; }
42
+
43
+ /** Fix for 4 column grid */
44
+ .widget-mediego .products-grid--max-4-col-widget > li {
45
+ width: 23.33333%;
46
+ margin-right: 2.22222%;
47
+ }
48
+ .widget-mediego .products-grid--max-4-col-widget > li:nth-child(odd) { clear: none; }
49
+ .widget-mediego .products-grid--max-4-col-widget > li:nth-child(3n+1) { clear: none; }
50
+ .widget-mediego .products-grid--max-4-col-widget > li:nth-child(even),
51
+ .widget-mediego .products-grid--max-4-col-widget > li:nth-child(3n) {
52
+ margin-right: 2.22222%;
53
+ }
54
+ .widget-mediego .products-grid--max-4-col-widget > li:nth-child(4n+1) { clear: left; }
55
+ .widget-mediego .products-grid--max-4-col-widget > li:nth-child(4n) {
56
+ margin-right: 0;
57
+ }