Anais_Accessories - Version 1.0.0

Version Notes

Accessories extension

Download this release

Release Info

Developer Anais Software
Extension Anais_Accessories
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/Anais/Accessories/Block/Adminhtml/Catalog/Product/Edit/Tab/Accessories.php ADDED
@@ -0,0 +1,246 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ /**
23
+ * block for adminhtml accessories
24
+ */
25
+ class Anais_Accessories_Block_Adminhtml_Catalog_Product_Edit_Tab_Accessories extends Mage_Adminhtml_Block_Widget_Grid
26
+ {
27
+
28
+ /**
29
+ * constructor
30
+ * Set grid params
31
+ * @access public
32
+ * @return void
33
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
34
+ */
35
+ public function __construct(){
36
+ parent::__construct();
37
+ $this->setId('accessories_product_grid');
38
+ $this->setDefaultSort('entity_id');
39
+ $this->setUseAjax(true);
40
+ if ($this->_getProduct()->getId()) {
41
+ $this->setDefaultFilter(array('in_products'=>1));
42
+ }
43
+ }
44
+
45
+ /**
46
+ * Retirve currently edited product model
47
+ * @access protected
48
+ * @return Mage_Catalog_Model_Product
49
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
50
+ */
51
+ protected function _getProduct(){
52
+ return Mage::registry('current_product');
53
+ }
54
+
55
+ /**
56
+ * Add filter
57
+ * @access protected
58
+ * @param object $column
59
+ * @return Anais_Accessories_Block_Adminhtml_Catalog_Product_Edit_Tab_Accessories
60
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
61
+ */
62
+ protected function _addColumnFilterToCollection($column){
63
+ if ($column->getId() == 'in_products') {
64
+ $productIds = $this->_getSelectedProducts();
65
+ if (empty($productIds)) {
66
+ $productIds = 0;
67
+ }
68
+ if ($column->getFilter()->getValue()) {
69
+ $this->getCollection()->addFieldToFilter('entity_id', array('in'=>$productIds));
70
+ } else {
71
+ if($productIds) {
72
+ $this->getCollection()->addFieldToFilter('entity_id', array('nin'=>$productIds));
73
+ }
74
+ }
75
+ } else {
76
+ parent::_addColumnFilterToCollection($column);
77
+ }
78
+ return $this;
79
+ }
80
+
81
+ /**
82
+ * Checks when this block is readonly
83
+ * @access public
84
+ * @return boolean
85
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
86
+ */
87
+ public function isReadonly(){
88
+ return $this->_getProduct()->getAccessoriesReadonly();
89
+ }
90
+
91
+ /**
92
+ * Prepare collection
93
+ * @access protected
94
+ * @return Mage_Adminhtml_Block_Widget_Grid
95
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
96
+ */
97
+ protected function _prepareCollection(){
98
+ $collection = Mage::getModel('catalog/product_link')->useAccessoriesLinks()
99
+ ->getProductCollection()
100
+ ->setProduct($this->_getProduct())
101
+ ->addAttributeToSelect('*');
102
+ if ($this->isReadonly()) {
103
+ $productIds = $this->_getSelectedProducts();
104
+ if (empty($productIds)) {
105
+ $productIds = array(0);
106
+ }
107
+ $collection->addFieldToFilter('entity_id', array('in'=>$productIds));
108
+ }
109
+
110
+ $this->setCollection($collection);
111
+ return parent::_prepareCollection();
112
+ }
113
+
114
+ /**
115
+ * Add columns to grid
116
+ * @access protected
117
+ * @return Mage_Adminhtml_Block_Widget_Grid
118
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
119
+ */
120
+ protected function _prepareColumns(){
121
+ if (!$this->_getProduct()->getAccessoriesReadonly()) {
122
+ $this->addColumn('in_products', array(
123
+ 'header_css_class' => 'a-center',
124
+ 'type' => 'checkbox',
125
+ 'name' => 'in_products',
126
+ 'values' => $this->_getSelectedProducts(),
127
+ 'align' => 'center',
128
+ 'index' => 'entity_id'
129
+ ));
130
+ }
131
+
132
+ $this->addColumn('entity_id', array(
133
+ 'header' => Mage::helper('catalog')->__('ID'),
134
+ 'sortable' => true,
135
+ 'width' => 60,
136
+ 'index' => 'entity_id'
137
+ ));
138
+ $this->addColumn('name', array(
139
+ 'header' => Mage::helper('catalog')->__('Name'),
140
+ 'index' => 'name'
141
+ ));
142
+
143
+ $this->addColumn('type', array(
144
+ 'header' => Mage::helper('catalog')->__('Type'),
145
+ 'width' => 100,
146
+ 'index' => 'type_id',
147
+ 'type' => 'options',
148
+ 'options' => Mage::getSingleton('catalog/product_type')->getOptionArray(),
149
+ ));
150
+
151
+ $sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
152
+ ->setEntityTypeFilter(Mage::getModel('catalog/product')->getResource()->getTypeId())
153
+ ->load()
154
+ ->toOptionHash();
155
+
156
+ $this->addColumn('set_name', array(
157
+ 'header' => Mage::helper('catalog')->__('Attrib. Set Name'),
158
+ 'width' => 130,
159
+ 'index' => 'attribute_set_id',
160
+ 'type' => 'options',
161
+ 'options' => $sets,
162
+ ));
163
+
164
+ $this->addColumn('status', array(
165
+ 'header' => Mage::helper('catalog')->__('Status'),
166
+ 'width' => 90,
167
+ 'index' => 'status',
168
+ 'type' => 'options',
169
+ 'options' => Mage::getSingleton('catalog/product_status')->getOptionArray(),
170
+ ));
171
+
172
+ $this->addColumn('visibility', array(
173
+ 'header' => Mage::helper('catalog')->__('Visibility'),
174
+ 'width' => 90,
175
+ 'index' => 'visibility',
176
+ 'type' => 'options',
177
+ 'options' => Mage::getSingleton('catalog/product_visibility')->getOptionArray(),
178
+ ));
179
+
180
+ $this->addColumn('sku', array(
181
+ 'header' => Mage::helper('catalog')->__('SKU'),
182
+ 'width' => 80,
183
+ 'index' => 'sku'
184
+ ));
185
+
186
+ $this->addColumn('price', array(
187
+ 'header' => Mage::helper('catalog')->__('Price'),
188
+ 'type' => 'currency',
189
+ 'currency_code' => (string) Mage::getStoreConfig(Mage_Directory_Model_Currency::XML_PATH_CURRENCY_BASE),
190
+ 'index' => 'price'
191
+ ));
192
+
193
+ $this->addColumn('position', array(
194
+ 'header' => Mage::helper('catalog')->__('Position'),
195
+ 'name' => 'position',
196
+ 'type' => 'number',
197
+ 'width' => 60,
198
+ 'validate_class' => 'validate-number',
199
+ 'index' => 'position',
200
+ 'editable' => !$this->_getProduct()->getUpsellReadonly(),
201
+ 'edit_only' => !$this->_getProduct()->getId()
202
+ ));
203
+
204
+ return parent::_prepareColumns();
205
+ }
206
+
207
+ /**
208
+ * Rerieve grid URL
209
+ * @access public
210
+ * @return string
211
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
212
+ */
213
+ public function getGridUrl(){
214
+ return $this->_getData('grid_url') ? $this->_getData('grid_url') : $this->getUrl('*/*/accessoriesGrid', array('_current'=>true));
215
+ }
216
+
217
+ /**
218
+ * Retrieve selected accessories products
219
+ * @access protected
220
+ * @return array
221
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
222
+ */
223
+ protected function _getSelectedProducts(){
224
+ $products = $this->getProductsAccessories();
225
+ if (!is_array($products)) {
226
+ $products = array_keys($this->getSelectedAccessoriesProducts());
227
+ }
228
+ return $products;
229
+ }
230
+
231
+ /**
232
+ * Retrieve accessories products
233
+ * @access public
234
+ * @return array
235
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
236
+ */
237
+ public function getSelectedAccessoriesProducts()
238
+ {
239
+ $products = array();
240
+ foreach (Mage::registry('current_product')->getAccessoriesProducts() as $product) {
241
+ $products[$product->getId()] = array('position' => $product->getPosition());
242
+ }
243
+ return $products;
244
+ }
245
+
246
+ }
app/code/community/Anais/Accessories/Block/Adminhtml/Catalog/Product/Edit/Tabs.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ /**
23
+ * override of the admin tabs block to include accessories
24
+ */
25
+ class Anais_Accessories_Block_Adminhtml_Catalog_Product_Edit_Tabs extends Mage_Adminhtml_Block_Catalog_Product_Edit_Tabs{
26
+ /**
27
+ * override the _prepareLayout() method to include teh accessories tab
28
+ * @access protected
29
+ * @return Anais_Accessories_Block_Adminhtml_Catalog_Product_Edit_Tabs
30
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
31
+ */
32
+ protected function _prepareLayout(){
33
+ parent::_prepareLayout();
34
+ $product = $this->getProduct();
35
+ if (!($setId = $product->getAttributeSetId())) {
36
+ $setId = $this->getRequest()->getParam('set', null);
37
+ }
38
+ if ($setId) {
39
+ $this->addTab('accessories', array(
40
+ 'label' => Mage::helper('accessories')->__('Accessories'),
41
+ 'url' => $this->getUrl('*/*/accessories', array('_current' => true)),
42
+ 'class' => 'ajax',
43
+ ));
44
+ }
45
+ return $this;
46
+ }
47
+ }
app/code/community/Anais/Accessories/Block/Product/List/Accessories.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ class Anais_Accessories_Block_Product_List_Accessories extends Mage_Catalog_Block_Product_List_Upsell{
23
+ /**
24
+ * Prepare accessories items data
25
+ * @access protected
26
+ * @return Anais_Catalog_Block_Product_List_Accessories
27
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
28
+ */
29
+ protected function _prepareData()
30
+ {
31
+ $product = Mage::registry('product');
32
+
33
+ $this->_itemCollection = $product->getAccessoriesProductCollection()
34
+ ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
35
+ ->addAttributeToSort('position', 'asc')
36
+ ->addStoreFilter();
37
+
38
+ Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($this->_itemCollection);
39
+ if ($this->getItemLimit('accessories') > 0) {
40
+ $this->_itemCollection->setPageSize($this->getItemLimit('accessories'));
41
+ }
42
+ $this->_itemCollection->load();
43
+
44
+ foreach ($this->_itemCollection as $product) {
45
+ $product->setDoNotUseCategoryId(true);
46
+ }
47
+ return $this;
48
+ }
49
+
50
+ }
app/code/community/Anais/Accessories/Helper/Data.php ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ class Anais_Accessories_Helper_Data extends Mage_Core_Helper_Data{
23
+
24
+ }
app/code/community/Anais/Accessories/Model/Observer.php ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ class Anais_Accessories_Model_Observer{
23
+ /**
24
+ * set accessories for save
25
+ * @access public
26
+ * @param Varien_Object $observer
27
+ * @return Anais_Accessories_Model_Observer
28
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
29
+ */
30
+ public function beforeProductSave($observer){
31
+
32
+ $product = $observer->getEvent()->getProduct();
33
+ $links = $observer->getEvent()->getRequest()->getPost('links');
34
+ if (isset($links['accessories']) && !$product->getAccessoriesReadonly()) {
35
+ $product->setAccessoriesLinkData(Mage::helper('adminhtml/js')->decodeGridSerializedInput($links['accessories']));
36
+ }
37
+ return $this;
38
+ }
39
+ }
app/code/community/Anais/Accessories/Model/Product.php ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ /**
23
+ * override of the product model to support accessories
24
+ */
25
+
26
+ class Anais_Accessories_Model_Product extends Mage_Catalog_Model_Product{
27
+ /**
28
+ * Retrieve array of accessories
29
+ * @access public
30
+ * @return array
31
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
32
+ */
33
+ public function getAccessoriesProducts(){
34
+ if (!$this->hasAccessoriesProducts()) {
35
+ $products = array();
36
+ foreach ($this->getAccessoriesProductCollection() as $product) {
37
+ $products[] = $product;
38
+ }
39
+ $this->setAccessoriesProducts($products);
40
+ }
41
+ return $this->getData('accessories_products');
42
+ }
43
+
44
+ /**
45
+ * Retrieve accessories identifiers
46
+ * @access public
47
+ * @return array
48
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
49
+ */
50
+ public function getAccessoriesProductIds(){
51
+ if (!$this->hasAccessoriesProductIds()) {
52
+ $ids = array();
53
+ foreach ($this->getAccessoriesProducts() as $product) {
54
+ $ids[] = $product->getId();
55
+ }
56
+ $this->setAccessoriesProductIds($ids);
57
+ }
58
+ return $this->getData('accessories_product_ids');
59
+ }
60
+
61
+ /**
62
+ * Retrieve collection accessories product
63
+ * @access public
64
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection
65
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
66
+ */
67
+ public function getAccessoriesProductCollection(){
68
+ $collection = $this->getLinkInstance()->useAccessoriesLinks()
69
+ ->getProductCollection()
70
+ ->setIsStrongMode();
71
+ $collection->setProduct($this);
72
+ return $collection;
73
+ }
74
+
75
+ /**
76
+ * Retrieve collection accessories link
77
+ * @access public
78
+ * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Link_Collection
79
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
80
+ */
81
+ public function getAccessoriesLinkCollection(){
82
+ $collection = $this->getLinkInstance()->useAccessoriesLinks()
83
+ ->getLinkCollection();
84
+ $collection->setProduct($this);
85
+ $collection->addLinkTypeIdFilter();
86
+ $collection->addProductIdFilter();
87
+ $collection->joinAttributes();
88
+ return $collection;
89
+ }
90
+ }
app/code/community/Anais/Accessories/Model/Product/Link.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ /**
23
+ * override of the Mage_Catalog_Model_Product_Link in orer to support the new association
24
+ */
25
+ class Anais_Accessories_Model_Product_Link extends Mage_Catalog_Model_Product_Link{
26
+ const LINK_TYPE_ACCESSORIES = 6;
27
+ /**
28
+ * tell the model to use accessories
29
+ * @access public
30
+ * @return Anais_Catalog_Model_Product_Link
31
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
32
+ */
33
+ public function useAccessoriesLinks(){
34
+ $this->setLinkTypeId(self::LINK_TYPE_ACCESSORIES);
35
+ return $this;
36
+ }
37
+
38
+ /**
39
+ * Save data for product relations
40
+ * @param Mage_Catalog_Model_Product $product
41
+ * @return Mage_Catalog_Model_Product_Link
42
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
43
+ */
44
+ public function saveProductRelations($product)
45
+ {
46
+ parent::saveProductRelations($product);
47
+ $data = $product->getAccessoriesLinkData();
48
+ if (!is_null($data)) {
49
+ $this->_getResource()->saveProductLinks($product, $data, self::LINK_TYPE_ACCESSORIES);
50
+ }
51
+ return $this;
52
+ }
53
+
54
+ }
app/code/community/Anais/Accessories/controllers/Adminhtml/Catalog/ProductController.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ /**
23
+ * override of the admin product controller to include accessories
24
+ */
25
+
26
+ require_once('Mage/Adminhtml/controllers/Catalog/ProductController.php');
27
+ class Anais_Accessories_Adminhtml_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController{
28
+ /**
29
+ * Get accessories products grid and serializer block
30
+ * @access public
31
+ * @return void
32
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
33
+ */
34
+ public function accessoriesAction(){
35
+ $this->_initProduct();
36
+ $this->loadLayout();
37
+ $this->getLayout()->getBlock('catalog.product.edit.tab.accessories')
38
+ ->setProductsAccessories($this->getRequest()->getPost('products_accessories', null));
39
+ $this->renderLayout();
40
+ }
41
+ /**
42
+ * Get upsell products grid
43
+ * @access public
44
+ * @return void
45
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
46
+ */
47
+ public function accessoriesGridAction()
48
+ {
49
+ $this->_initProduct();
50
+ $this->loadLayout();
51
+ $this->getLayout()->getBlock('catalog.product.edit.tab.accessories')
52
+ ->setProductsAccessories($this->getRequest()->getPost('products_accessories', null));
53
+ $this->renderLayout();
54
+ }
55
+ }
app/code/community/Anais/Accessories/etc/config.xml ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Anais_Accessories extension
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 Anais
14
+ * @package Anais_Accessories
15
+ * @copyright Copyright (c) 2011 Anais Software Services
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @category Anais
20
+ * @package Anais_Accessories
21
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
22
+ */
23
+ -->
24
+ <config>
25
+ <modules>
26
+ <Anais_Accessories>
27
+ <version>0.1.0</version>
28
+ </Anais_Accessories>
29
+ </modules>
30
+ <global>
31
+ <models>
32
+ <accessories>
33
+ <class>Anais_Accessories_Model</class>
34
+ </accessories>
35
+ <catalog>
36
+ <rewrite>
37
+ <product>Anais_Accessories_Model_Product</product>
38
+ <product_link>Anais_Accessories_Model_Product_Link</product_link>
39
+ </rewrite>
40
+ </catalog>
41
+ </models>
42
+ <blocks>
43
+ <accessories>
44
+ <class>Anais_Accessories_Block</class>
45
+ </accessories>
46
+ <adminhtml>
47
+ <rewrite>
48
+ <catalog_product_edit_tabs>Anais_Accessories_Block_Adminhtml_Catalog_Product_Edit_Tabs</catalog_product_edit_tabs>
49
+ <catalog_product_edit_tab_accessories>Anais_Accessories_Block_Adminhtml_Catalog_Product_Edit_Tab_Accessories</catalog_product_edit_tab_accessories>
50
+ </rewrite>
51
+ </adminhtml>
52
+ </blocks>
53
+ <helpers>
54
+ <accessories>
55
+ <class>Anais_Accessories_Helper</class>
56
+ </accessories>
57
+ </helpers>
58
+ <resources>
59
+ <anais_accessories_setup>
60
+ <setup>
61
+ <module>Anais_Accessories</module>
62
+ <class>Mage_Eav_Model_Entity_Setup</class>
63
+ </setup>
64
+ </anais_accessories_setup>
65
+ </resources>
66
+ </global>
67
+ <frontend>
68
+ <layout>
69
+ <updates>
70
+ <anais_accessories>
71
+ <file>anais_accessories.xml</file>
72
+ </anais_accessories>
73
+ </updates>
74
+ </layout>
75
+ <translate>
76
+ <modules>
77
+ <Anais_Accessories>
78
+ <files>
79
+ <default>Anais_Accessories.csv</default>
80
+ </files>
81
+ </Anais_Accessories>
82
+ </modules>
83
+ </translate>
84
+ </frontend>
85
+ <admin>
86
+ <routers>
87
+ <adminhtml>
88
+ <args>
89
+ <modules>
90
+ <Anais_Accessories before="Mage_Adminhtml">Anais_Accessories_Adminhtml</Anais_Accessories>
91
+ </modules>
92
+ </args>
93
+ </adminhtml>
94
+ </routers>
95
+ </admin>
96
+ <adminhtml>
97
+ <layout>
98
+ <updates>
99
+ <anais_accessories>
100
+ <file>anais_accessories.xml</file>
101
+ </anais_accessories>
102
+ </updates>
103
+ </layout>
104
+ <events>
105
+ <catalog_product_prepare_save>
106
+ <observers>
107
+ <accessories_adminhtml_before_product_save>
108
+ <class>accessories/observer</class>
109
+ <method>beforeProductSave</method>
110
+ </accessories_adminhtml_before_product_save>
111
+ </observers>
112
+ </catalog_product_prepare_save>
113
+ </events>
114
+ <translate>
115
+ <modules>
116
+ <Anais_Accessories>
117
+ <files>
118
+ <default>Anais_Accessories.csv</default>
119
+ </files>
120
+ </Anais_Accessories>
121
+ </modules>
122
+ </translate>
123
+ </adminhtml>
124
+ </config>
app/code/community/Anais/Accessories/sql/anais_accessories_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ $installer = $this;
23
+ $installer->startSetup();
24
+ $linkTypeId = Anais_Accessories_Model_Product_Link::LINK_TYPE_ACCESSORIES;
25
+ $installer->run("INSERT INTO {$installer->getTable('catalog/product_link_type')} SET link_type_id = '{$linkTypeId}', code = 'accessories'");
26
+ $installer->run("INSERT INTO {$installer->getTable('catalog/product_link_attribute')} SET link_type_id = '{$linkTypeId}', `product_link_attribute_code` = 'position', `data_type` = 'int'");
27
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/anais_accessories.xml ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!--
3
+ /**
4
+ * Anais_Accessories extension
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 Anais
14
+ * @package Anais_Accessories
15
+ * @copyright Copyright (c) 2011 Anais Software Services
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @category Anais
20
+ * @package Anais_Accessories
21
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
22
+ */
23
+ -->
24
+ <layout>
25
+ <adminhtml_catalog_product_accessories>
26
+ <block type="core/text_list" name="root">
27
+ <block type="adminhtml/catalog_product_edit_tab_accessories" name="catalog.product.edit.tab.accessories"/>
28
+ <block type="adminhtml/widget_grid_serializer" name="accessories_grid_serializer">
29
+ <reference name="accessories_grid_serializer">
30
+ <action method="initSerializerBlock">
31
+ <grid_block_name>catalog.product.edit.tab.accessories</grid_block_name>
32
+ <data_callback>getSelectedAccessoriesProducts</data_callback>
33
+ <hidden_input_name>links[accessories]</hidden_input_name>
34
+ <reload_param_name>products_accessories</reload_param_name>
35
+ </action>
36
+ <action method="addColumnInputName">
37
+ <input_name>position</input_name>
38
+ </action>
39
+ </reference>
40
+ </block>
41
+ </block>
42
+ </adminhtml_catalog_product_accessories>
43
+ <adminhtml_catalog_product_accessoriesgrid>
44
+ <block type="core/text_list" name="root">
45
+ <block type="adminhtml/catalog_product_edit_tab_accessories" name="catalog.product.edit.tab.accessories"/>
46
+ </block>
47
+ </adminhtml_catalog_product_accessoriesgrid>
48
+ </layout>
app/design/frontend/base/default/layout/anais_accessories.xml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Anais_Accessories extension
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 Anais
14
+ * @package Anais_Accessories
15
+ * @copyright Copyright (c) 2011 Anais Software Services
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @category Anais
20
+ * @package Anais_Accessories
21
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
22
+ */
23
+ -->
24
+ <layout>
25
+ <catalog_product_view>
26
+ <reference name="product.info">
27
+ <block type="accessories/product_list_accessories" name="product.info.accessories" as="accessories_products" template="anais_accessories/anais_accessories.phtml">
28
+ <!-- <action method="setColumnCount"><columns>4</columns></action> --><!-- Uncomment to change the columns count for accessories -->
29
+ <!-- <action method="setItemLimit"><type>accessories</type><limit>4</limit></action> --><!-- Uncomment to change the number of items listed -->
30
+ <action method="addToParentGroup"><group>detailed_info</group></action>
31
+ <action method="setTitle" translate="value"><value>Accessories</value></action>
32
+ </block>
33
+ </reference>
34
+ </catalog_product_view>
35
+ </layout>
app/design/frontend/base/default/template/anais_accessories/anais_accessories.phtml ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Anais_Accessories extension
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 Anais
13
+ * @package Anais_Accessories
14
+ * @copyright Copyright (c) 2011 Anais Software Services
15
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
16
+ */
17
+ /**
18
+ * @category Anais
19
+ * @package Anais_Accessories
20
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
21
+ */
22
+ ?>
23
+ <?php if(count($this->getItemCollection()->getItems())): ?>
24
+ <div class="box-collateral box-accessories box-up-sell">
25
+ <table class="products-grid" id="accessories-product-table">
26
+ <?php $this->resetItemsIterator() ?>
27
+ <?php for($_i=0;$_i<$this->getRowCount();$_i++): ?>
28
+ <tr>
29
+ <?php for($_j=0;$_j<$this->getColumnCount();$_j++): ?>
30
+ <?php if($_link=$this->getIterableItem()): ?>
31
+ <td>
32
+ <a href="<?php echo $_link->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_link->getName()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_link, 'small_image')->resize(125) ?>" width="125" height="125" alt="<?php echo $this->htmlEscape($_link->getName()) ?>" /></a>
33
+ <h3 class="product-name"><a href="<?php echo $_link->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_link->getName()) ?>"><?php echo $this->htmlEscape($_link->getName()) ?></a></h3>
34
+ <?php echo $this->getPriceHtml($_link, true, '-accessories') ?>
35
+ <?php echo $this->getReviewsSummaryHtml($_link) ?>
36
+ </td>
37
+ <?php else: ?>
38
+ <td class="empty">&nbsp;</td>
39
+ <?php endif; ?>
40
+ <?php endfor; ?>
41
+ </tr>
42
+ <?php endfor; ?>
43
+ </table>
44
+ <script type="text/javascript">decorateTable('accessories-product-table')</script>
45
+ </div>
46
+ <?php endif ?>
app/design/frontend/default/modern/layout/anais_accessories.xml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Anais_Accessories extension
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 Anais
14
+ * @package Anais_Accessories
15
+ * @copyright Copyright (c) 2011 Anais Software Services
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @category Anais
20
+ * @package Anais_Accessories
21
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
22
+ */
23
+ -->
24
+ <layout>
25
+ <catalog_product_view>
26
+ <reference name="product.info.tabs">
27
+ <action method="addTab" translate="title" module="accessories"><alias>accessories</alias><title>Accessories</title><block>accessories/product_list_accessories</block><template>anais_accessories/anais_accessories.phtml</template></action>
28
+ </reference>
29
+ </catalog_product_view>
30
+ </layout>
app/etc/modules/Anais_Accessories.xml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Anais_Accessories extension
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 Anais
14
+ * @package Anais_Accessories
15
+ * @copyright Copyright (c) 2011 Anais Software Services
16
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
+ */
18
+ /**
19
+ * @category Anais
20
+ * @package Anais_Accessories
21
+ * @author Marius Strajeru <marius.strajeru@anais-it.com>
22
+ */
23
+ -->
24
+ <config>
25
+ <modules>
26
+ <Anais_Accessories>
27
+ <active>true</active>
28
+ <codePool>community</codePool>
29
+ <depends>
30
+ <Mage_Catalog />
31
+ </depends>
32
+ </Anais_Accessories>
33
+ </modules>
34
+ </config>
app/locale/en_US/Anais_Accessories.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Accessories","Accessories"
app/locale/ro_RO/Anais_Accessories.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Accessories","Accesorii"
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Anais_Accessories</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL 3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension adds a new type of product association: Accessories</summary>
10
+ <description>This extension adds a new type of product association.&#xD;
11
+ You can assign products as accessories to an other product without any obligation to buy.</description>
12
+ <notes>Accessories extension</notes>
13
+ <authors><author><name>Anais Software</name><user>AnaisSoftware</user><email>magento@anais-it.com</email></author></authors>
14
+ <date>2011-09-05</date>
15
+ <time>08:32:54</time>
16
+ <contents><target name="magecommunity"><dir name="Anais"><dir name="Accessories"><dir name="Block"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><file name="Accessories.php" hash="e9005d55e7cb1c871a6c8c962be68cd2"/></dir><file name="Tabs.php" hash="562add1a3b186caf6fa6bc3ec8d898b3"/></dir></dir></dir></dir><dir name="Product"><dir name="List"><file name="Accessories.php" hash="501a28d860585628e40a1b6b1a39e193"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="a34b74d6231d53f84024e69a8123a96a"/></dir><dir name="Model"><file name="Observer.php" hash="2bae09435d2096b902744cbd33602197"/><dir name="Product"><file name="Link.php" hash="f8e6104e7e45187f48ed335aafea4dba"/></dir><file name="Product.php" hash="30701579236ba17101513be17129746e"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Catalog"><file name="ProductController.php" hash="3cb04c705048778be3b4dbfa62fcc2a4"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="3fee93deb0d9a04aa6839bd6150f3f01"/></dir><dir name="sql"><dir name="anais_accessories_setup"><file name="mysql4-install-0.1.0.php" hash="d5116e9e4b1012fe3e3803035533ebd2"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="anais_accessories.xml" hash="c27b42262b7dc4bde6e857a36cee8473"/></dir><dir name="template"><dir name="anais_accessories"><file name="anais_accessories.phtml" hash="b07f89ab7addd5fb5383cc5419586edb"/></dir></dir></dir></dir><dir name="default"><dir name="modern"><dir name="layout"><file name="anais_accessories.xml" hash="941bd3e0a64d34761d77ad27c993a62e"/></dir></dir></dir></dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="anais_accessories.xml" hash="ff1eaf0538d9b4ebec382b7d58147212"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Anais_Accessories.xml" hash="79cb1be2dc16be38a06c96469adafc0f"/></dir></target><target name="magelocale"><dir name="en_US"><file name="Anais_Accessories.csv" hash="9a589761d54f1fc3f8200d7f01347271"/></dir><dir name="ro_RO"><file name="Anais_Accessories.csv" hash="da171efdb8cf602bb5e90c1be48a4e9e"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.2.13</min><max>6.0.0</max></php></required></dependencies>
19
+ </package>