MagnifyStudio_PriceAdjust - Version 0.1.0

Version Notes

Initial Release

Download this release

Release Info

Developer MagnifyStudio
Extension MagnifyStudio_PriceAdjust
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

Files changed (22) hide show
  1. app/code/community/MagnifyStudio/PriceAdjust/.DS_Store +0 -0
  2. app/code/community/MagnifyStudio/PriceAdjust/Helper/.DS_Store +0 -0
  3. app/code/community/MagnifyStudio/PriceAdjust/Helper/Data.php +374 -0
  4. app/code/community/MagnifyStudio/PriceAdjust/Model/.DS_Store +0 -0
  5. app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/.DS_Store +0 -0
  6. app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/Priceadjust.php +16 -0
  7. app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/Priceadjust/.DS_Store +0 -0
  8. app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/Priceadjust/Collection.php +16 -0
  9. app/code/community/MagnifyStudio/PriceAdjust/Model/Observer.php +25 -0
  10. app/code/community/MagnifyStudio/PriceAdjust/Model/Priceadjust.php +18 -0
  11. app/code/community/MagnifyStudio/PriceAdjust/controllers/.DS_Store +0 -0
  12. app/code/community/MagnifyStudio/PriceAdjust/controllers/AdjustController.php +23 -0
  13. app/code/community/MagnifyStudio/PriceAdjust/etc/.DS_Store +0 -0
  14. app/code/community/MagnifyStudio/PriceAdjust/etc/config.xml +86 -0
  15. app/code/community/MagnifyStudio/PriceAdjust/sql/.DS_Store +0 -0
  16. app/code/community/MagnifyStudio/PriceAdjust/sql/priceadjust_setup/.DS_Store +0 -0
  17. app/code/community/MagnifyStudio/PriceAdjust/sql/priceadjust_setup/mysql4-install-0.1.0.php +26 -0
  18. app/design/adminhtml/default/default/layout/magnifystudio_priceadjust.xml +8 -0
  19. app/design/adminhtml/default/default/template/magnifystudio/priceadjust/.DS_Store +0 -0
  20. app/design/adminhtml/default/default/template/magnifystudio/priceadjust/priceadjust.phtml +267 -0
  21. app/etc/modules/MagnifyStudio_PriceAdjust.xml +9 -0
  22. package.xml +18 -0
app/code/community/MagnifyStudio/PriceAdjust/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/Helper/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/Helper/Data.php ADDED
@@ -0,0 +1,374 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ class MagnifyStudio_PriceAdjust_Helper_Data extends Mage_Core_Helper_Abstract
11
+ {
12
+ /**
13
+ * Configuration
14
+ *
15
+ * @access protected
16
+ * @var array
17
+ */
18
+ protected $_config = array();
19
+
20
+ /**
21
+ * Rules
22
+ *
23
+ * @access protected
24
+ * @var array
25
+ */
26
+ protected $_rules = array();
27
+
28
+ /**
29
+ * Setup
30
+ *
31
+ * @access public
32
+ * @return void
33
+ */
34
+ public function setup()
35
+ {
36
+ static $_init = FALSE;
37
+
38
+ if ( ! $_init)
39
+ {
40
+ $_init = TRUE;
41
+
42
+ $post = $this->_getRequest()->getPost();
43
+
44
+ $stores = $this->get_stores();
45
+
46
+ current($stores);
47
+
48
+ $this->_config['store']['source'] = (isset($post['website']['source'])) ? $post['website']['source'] : key($stores);
49
+
50
+ $this->_config['store']['target'] = (isset($post['website']['target'])) ? $post['website']['target'] : key($stores);
51
+
52
+ if ( ! empty($post) && isset($post['rules']))
53
+ {
54
+ $this->set_rules($post['rules']);
55
+ }
56
+ else
57
+ {
58
+ $this->set_rules($this->pull_rules());
59
+ }
60
+ }
61
+
62
+ return $this;
63
+ }
64
+
65
+ /**
66
+ * Set rules
67
+ *
68
+ * @access public
69
+ * @param array
70
+ * @return self
71
+ */
72
+ public function set_rules(array $rules)
73
+ {
74
+ $this->_rules = $rules;
75
+
76
+ return $this;
77
+ }
78
+
79
+ /**
80
+ * Get Rules
81
+ *
82
+ * @access public
83
+ * @return array
84
+ */
85
+ public function get_rules()
86
+ {
87
+ return $this->_rules;
88
+ }
89
+
90
+ /**
91
+ * Get Configuration
92
+ *
93
+ * @access public
94
+ * @return array
95
+ */
96
+ public function get_config()
97
+ {
98
+ return $this->_config;
99
+ }
100
+
101
+ /**
102
+ * Pull rules from database
103
+ *
104
+ * @access public
105
+ * @return array
106
+ */
107
+ public function pull_rules()
108
+ {
109
+ $rules = array();
110
+
111
+ $collection = Mage::getModel('priceadjust/priceadjust')->getCollection();
112
+
113
+ foreach ($collection as $item)
114
+ {
115
+ $rule = array();
116
+
117
+ $rule['weight_begin'] = $item->getWeight_begin();
118
+ $rule['weight_end'] = $item->getWeight_end();
119
+ $rule['value'] = $item->getValue();
120
+ $rule['type'] = $item->getType();
121
+
122
+ $rules[] = $rule;
123
+ }
124
+
125
+ return $rules;
126
+ }
127
+
128
+ /**
129
+ * Save Rules
130
+ *
131
+ * @access public
132
+ * @return self
133
+ */
134
+ public function save_rules()
135
+ {
136
+ $priceadjust_model = Mage::getModel('priceadjust/priceadjust')->getCollection();
137
+ $priceadjust_model->walk('delete');
138
+
139
+ if ( ! empty($this->_rules))
140
+ {
141
+ foreach ($this->_rules as $rule)
142
+ {
143
+ $priceadjust_model = Mage::getModel('priceadjust/priceadjust');
144
+
145
+ $priceadjust_model->setWeight_begin($rule['weight_begin']);
146
+ $priceadjust_model->setWeight_end($rule['weight_end']);
147
+ $priceadjust_model->setValue($rule['value']);
148
+ $priceadjust_model->setType($rule['type']);
149
+
150
+ $priceadjust_model->save();
151
+ }
152
+ }
153
+
154
+ return $this;
155
+ }
156
+
157
+ /**
158
+ * Get stores
159
+ *
160
+ * @access public
161
+ * @return array
162
+ */
163
+ public function get_stores()
164
+ {
165
+ static $stores;
166
+
167
+ if ($stores === NULL)
168
+ {
169
+ $stores = array();
170
+
171
+ foreach (Mage::app()->getWebsites() as $index => $website)
172
+ {
173
+ foreach ($website->getStores() as $store)
174
+ {
175
+ $stores[$store->getId()] = $store->getName();
176
+ }
177
+ }
178
+ }
179
+
180
+ return $stores;
181
+ }
182
+
183
+ /**
184
+ * Retrive selected products ids from post or session
185
+ *
186
+ * @access public
187
+ * @return array|null
188
+ */
189
+ public function get_products()
190
+ {
191
+ $session = Mage::getSingleton('adminhtml/session');
192
+
193
+ $post = $this->_getRequest()->getPost();
194
+
195
+ if ( ! empty($post) && isset($post['product']))
196
+ {
197
+ $session->setProductIds($this->_getRequest()->getParam('product', NULL));
198
+ }
199
+
200
+ return $session->getProductIds();
201
+ }
202
+
203
+ /**
204
+ * Process Rules
205
+ *
206
+ * @access public
207
+ * @param float Product weight
208
+ * @param float Product price
209
+ * @return float|bool
210
+ */
211
+ public function rules($weight, $price)
212
+ {
213
+ $change = array
214
+ (
215
+ 'difference' => 0,
216
+ 'percent' => 0,
217
+ 'price' => 0
218
+ );
219
+
220
+ foreach ($this->_rules as $rule)
221
+ {
222
+ if ($weight >= $rule['weight_begin'] && $weight <= $rule['weight_end'])
223
+ {
224
+ $_price = FALSE;
225
+
226
+ switch ($rule['type'])
227
+ {
228
+ // Multiplication
229
+ case 0:
230
+ $_price = $price * $rule['value'];
231
+ break;
232
+
233
+ // Addition
234
+ case 1:
235
+ $_price = $price + $rule['value'];
236
+ break;
237
+
238
+ // Subtraction
239
+ case 2:
240
+ $_price = $price - $rule['value'];
241
+ break;
242
+
243
+ // Division
244
+ case 3:
245
+ $_price = $price / $rule['value'];
246
+ break;
247
+ }
248
+
249
+ if ($_price != FALSE)
250
+ {
251
+ $change['difference'] = $_price - $price;
252
+ $change['percent'] = ($price != 0) ? ($_price - $price) / $price * 100 : 0;
253
+ $change['price'] = $_price;
254
+ }
255
+
256
+ break;
257
+ }
258
+ }
259
+
260
+ return $change;
261
+ }
262
+
263
+ /**
264
+ * Process
265
+ *
266
+ * @access public
267
+ * @param int Store ID
268
+ * @param bool Whether or not to make the changes
269
+ * @return array
270
+ */
271
+ public function process($commit = FALSE)
272
+ {
273
+ $catalog = array();
274
+
275
+ $collection = Mage::getModel('catalog/product')
276
+ ->getCollection()
277
+ ->addStoreFilter($this->_config['store']['source'])
278
+ ->addAttributeToSelect('*');
279
+
280
+ $products = $this->get_products();
281
+
282
+ if ($products != NULL)
283
+ {
284
+ $collection->addIdFilter($products);
285
+ }
286
+
287
+ Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
288
+
289
+ $collection->load();
290
+
291
+ $count = 0;
292
+
293
+ foreach ($collection as $product)
294
+ {
295
+ $change = $this->rules($product->getWeight(), $product->getPrice());
296
+
297
+ $_product = array
298
+ (
299
+ 'id' => $product->getId(),
300
+ 'sku' => $product->getSku(),
301
+ 'name' => $product->getName(),
302
+ 'weight' => $product->getWeight(),
303
+ 'price' => $product->getPrice(),
304
+ 'change_difference' => $change['difference'],
305
+ 'change_percent' => $change['percent'],
306
+ 'change_price' => $change['price']
307
+ );
308
+
309
+ $catalog[] = $_product;
310
+
311
+ if ($commit)
312
+ {
313
+ $count++;
314
+
315
+ $this->_update_product($product->getId(), $change['price']);
316
+ }
317
+ }
318
+
319
+ /*
320
+ if ($commit)
321
+ {
322
+ Mage::getSingleton('adminhtml/session')->addSuccess($this->__('Total of %d record(s) were successfully updated', $count));
323
+ }
324
+ */
325
+
326
+ return $catalog;
327
+ }
328
+
329
+ /**
330
+ * Update product
331
+ *
332
+ * @access protected
333
+ * @param int Product ID
334
+ * @param float Product Price
335
+ * @return self
336
+ */
337
+ protected function _update_product($product_id, $price)
338
+ {
339
+ static $product_model;
340
+
341
+ if ($product_model === NULL)
342
+ {
343
+ $product_model = Mage::getModel('catalog/product');
344
+ }
345
+
346
+ $product_model->setData(array());
347
+
348
+ $product_model->setStoreId($this->_config['store']['target'])
349
+ ->load($product_id)
350
+ ->setIsMassupdate(TRUE)
351
+ ->setExcludeUrlRewrite(TRUE);
352
+
353
+ $product_model->addData(array
354
+ (
355
+ 'price' => $price
356
+ ));
357
+
358
+ $product_model->save();
359
+
360
+ return $this;
361
+ }
362
+
363
+ /**
364
+ * Format Price
365
+ *
366
+ * @access public
367
+ * @param float
368
+ * @return string
369
+ */
370
+ public function format_price($price)
371
+ {
372
+ return '$' . number_format($price, 2, '.', '');
373
+ }
374
+ }
app/code/community/MagnifyStudio/PriceAdjust/Model/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/Priceadjust.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ class MagnifyStudio_PriceAdjust_Model_Mysql4_Priceadjust extends Mage_Core_Model_Mysql4_Abstract
11
+ {
12
+ public function _construct()
13
+ {
14
+ $this->_init('priceadjust/priceadjust', 'priceadjust_id');
15
+ }
16
+ }
app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/Priceadjust/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/Model/Mysql4/Priceadjust/Collection.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ class MagnifyStudio_PriceAdjust_Model_Mysql4_Priceadjust_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
11
+ {
12
+ public function _construct()
13
+ {
14
+ $this->_init('priceadjust/priceadjust');
15
+ }
16
+ }
app/code/community/MagnifyStudio/PriceAdjust/Model/Observer.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ class MagnifyStudio_PriceAdjust_Model_Observer
11
+ {
12
+ public function addMassAction($observer)
13
+ {
14
+ $block = $observer->getEvent()->getBlock();
15
+
16
+ if (get_class($block) == 'Mage_Adminhtml_Block_Widget_Grid_Massaction'
17
+ && $block->getRequest()->getControllerName() == 'catalog_product')
18
+ {
19
+ $block->addItem('priceadjust', array(
20
+ 'label' => 'Price Adjust',
21
+ 'url' => Mage::app()->getStore()->getUrl('priceadjust/adjust/price'),
22
+ ));
23
+ }
24
+ }
25
+ }
app/code/community/MagnifyStudio/PriceAdjust/Model/Priceadjust.php ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ class MagnifyStudio_PriceAdjust_Model_Priceadjust extends Mage_Core_Model_Abstract
11
+ {
12
+ public function _construct()
13
+ {
14
+ parent::_construct();
15
+
16
+ $this->_init('priceadjust/priceadjust');
17
+ }
18
+ }
app/code/community/MagnifyStudio/PriceAdjust/controllers/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/controllers/AdjustController.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ class MagnifyStudio_PriceAdjust_AdjustController extends Mage_Adminhtml_Controller_Action
11
+ {
12
+ /**
13
+ * priceadjust/adjust/price
14
+ *
15
+ * @access public
16
+ * @return void
17
+ */
18
+ public function priceAction()
19
+ {
20
+ $this->loadLayout();
21
+ $this->renderLayout();
22
+ }
23
+ }
app/code/community/MagnifyStudio/PriceAdjust/etc/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/etc/config.xml ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <MagnifyStudio_PriceAdjust>
5
+ <version>0.1.0</version>
6
+ </MagnifyStudio_PriceAdjust>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <priceadjust>
11
+ <use>admin</use>
12
+ <args>
13
+ <module>MagnifyStudio_PriceAdjust</module>
14
+ <frontName>priceadjust</frontName>
15
+ </args>
16
+ </priceadjust>
17
+ <adminhtml>
18
+ <args>
19
+ <modules>
20
+ <MagnifyStudio_PriceAdjust before="Mage_Adminhtml">MagnifyStudio_PriceAdjust</MagnifyStudio_PriceAdjust>
21
+ </modules>
22
+ </args>
23
+ </adminhtml>
24
+ </routers>
25
+ </admin>
26
+ <global>
27
+ <models>
28
+ <priceadjust>
29
+ <class>MagnifyStudio_PriceAdjust_Model</class>
30
+ <resourceModel>priceadjust_mysql4</resourceModel>
31
+ </priceadjust>
32
+ <priceadjust_mysql4>
33
+ <class>MagnifyStudio_PriceAdjust_Model_Mysql4</class>
34
+ <entities>
35
+ <priceadjust>
36
+ <table>priceadjust</table>
37
+ </priceadjust>
38
+ </entities>
39
+ </priceadjust_mysql4>
40
+ </models>
41
+ <resources>
42
+ <priceadjust_setup>
43
+ <setup>
44
+ <module>MagnifyStudio_PriceAdjust</module>
45
+ </setup>
46
+ <connection>
47
+ <use>core_setup</use>
48
+ </connection>
49
+ </priceadjust_setup>
50
+ <priceadjust_write>
51
+ <connection>
52
+ <use>core_write</use>
53
+ </connection>
54
+ </priceadjust_write>
55
+ <priceadjust_read>
56
+ <connection>
57
+ <use>core_read</use>
58
+ </connection>
59
+ </priceadjust_read>
60
+ </resources>
61
+ <helpers>
62
+ <priceadjust>
63
+ <class>MagnifyStudio_PriceAdjust_Helper</class>
64
+ </priceadjust>
65
+ </helpers>
66
+ </global>
67
+ <adminhtml>
68
+ <events>
69
+ <core_block_abstract_prepare_layout_before>
70
+ <observers>
71
+ <priceadjust_core_block_abstract_prepare_layout_before>
72
+ <class>priceadjust/observer</class>
73
+ <method>addMassAction</method>
74
+ </priceadjust_core_block_abstract_prepare_layout_before>
75
+ </observers>
76
+ </core_block_abstract_prepare_layout_before>
77
+ </events>
78
+ <layout>
79
+ <updates>
80
+ <priceadjust>
81
+ <file>magnifystudio_priceadjust.xml</file>
82
+ </priceadjust>
83
+ </updates>
84
+ </layout>
85
+ </adminhtml>
86
+ </config>
app/code/community/MagnifyStudio/PriceAdjust/sql/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/sql/priceadjust_setup/.DS_Store ADDED
Binary file
app/code/community/MagnifyStudio/PriceAdjust/sql/priceadjust_setup/mysql4-install-0.1.0.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ $installer = $this;
11
+
12
+ $installer->startSetup();
13
+
14
+ $installer->run("
15
+ -- DROP TABLE IF EXISTS {$this->getTable('priceadjust')};
16
+ CREATE TABLE {$this->getTable('priceadjust')} (
17
+ `priceadjust_id` int(11) unsigned NOT NULL auto_increment,
18
+ `weight_begin` float NOT NULL default '0',
19
+ `weight_end` float NOT NULL default '0',
20
+ `type` smallint(2) NOT NULL default '0',
21
+ `value` float NOT NULL default '0',
22
+ PRIMARY KEY (`priceadjust_id`)
23
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
24
+ ");
25
+
26
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/magnifystudio_priceadjust.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout>
3
+ <priceadjust_adjust_price>
4
+ <reference name="content">
5
+ <block type="core/template" name="priceadjust" template="magnifystudio/priceadjust/priceadjust.phtml" />
6
+ </reference>
7
+ </priceadjust_adjust_price>
8
+ </layout>
app/design/adminhtml/default/default/template/magnifystudio/priceadjust/.DS_Store ADDED
Binary file
app/design/adminhtml/default/default/template/magnifystudio/priceadjust/priceadjust.phtml ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Ability to mass price adjust using rules.
4
+ *
5
+ * @package PriceAdjust
6
+ * @author Micheal Morgan <micheal@morgan.ly>
7
+ * @copyright (c) 2014 Micheal Morgan
8
+ * @license MIT
9
+ */
10
+ $helper = Mage::helper('priceadjust')->setup();
11
+
12
+ $stores = $helper->get_stores();
13
+ $config = $helper->get_config();
14
+ $products = $helper->get_products();
15
+
16
+ $post = $this->getRequest()->getPost();
17
+
18
+ $catalog = array();
19
+
20
+ if ( ! empty($post))
21
+ {
22
+ if (isset($post['submit']))
23
+ {
24
+ $commit = (isset($post['submit']['adjust'])) ? TRUE : FALSE;
25
+
26
+ $catalog = $helper->process($commit);
27
+ }
28
+
29
+ if (isset($post['save_rules']))
30
+ {
31
+ $helper->save_rules();
32
+ }
33
+ }
34
+
35
+ $rules = $helper->get_rules();
36
+ ?>
37
+
38
+ <script type="text/javascript">
39
+
40
+ var PriceAdjust = {};
41
+
42
+ PriceAdjust = {
43
+ index: 0,
44
+ add: function (value_1, value_2, value_3, value_4)
45
+ {
46
+ this.index++;
47
+ var data = {index:this.index};
48
+
49
+ Element.insert($('priceadjust_row_container'), {bottom: this.template.evaluate(data)});
50
+
51
+ $('rule_weight_begin' + this.index).disabled = false;
52
+ $('rule_weight_end' + this.index).disabled = false;
53
+ $('rule_type' + this.index).disabled = false;
54
+ $('rule_value' + this.index).disabled = false;
55
+
56
+ $('rule_weight_begin' + this.index).value = value_1;
57
+ $('rule_weight_end' + this.index).value = value_2;
58
+ $('rule_type' + this.index).options[value_3].selected = true;
59
+ $('rule_value' + this.index).value = value_4;
60
+ },
61
+ deleteRow: function (event)
62
+ {
63
+ var row = Event.findElement(event, 'tr');
64
+
65
+ if (row)
66
+ {
67
+ row.parentNode.removeChild(row)
68
+ }
69
+ }
70
+ }
71
+
72
+ </script>
73
+
74
+ <form id="edit_form" method="post" action="">
75
+
76
+ <input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey(); ?>" />
77
+
78
+ <div class="content-header">
79
+ <h3 class="icon-head head-products"><?php echo __('Mass Price Adjust'); ?></h3>
80
+ <div class="form-buttons">
81
+ <button class="scalable save" type="submit" name="submit[adjust]"><span><?php echo __('Mass Adjust'); ?></span></button>
82
+ <button class="scalable save" type="submit" name="submit[preview]"><span><?php echo __('Preview'); ?></span></button>
83
+ </div>
84
+ </div>
85
+
86
+ <p><?php echo __('Price is derived from the corresponding product within the "Source" site. The first rule the weight falls between, the price is multiplied against the "Multiple" and set as the price of the product at the "Target" site. If the product doesn\'t exist at either the target or source site, the adjustment is not applied. Also, if the weight is not found within the rules, the adjustment is not applied.'); ?></p><br />
87
+
88
+ <div class="box-left">
89
+
90
+ <div class="entry-edit">
91
+
92
+ <div class="entry-edit-head"><h4 class="icon-head"><?php echo __('Settings'); ?></h4></div>
93
+
94
+ <fieldset>
95
+ <table cellspacing="0" class="form-list">
96
+ <tr>
97
+ <td class="label">
98
+ <strong><?php echo __('Products'); ?></strong>
99
+ <a href="<?php echo $this->getUrl('enhancedgrid/catalog_product'); ?>" title="To select specific products, click here to use mass action [Adjust Price]">(?)</a>
100
+ </td>
101
+ <td><em><?php echo (($products == NULL) ? __('All') : count($products)) . ' ' . __('Products Selected'); ?></em></td>
102
+ </tr>
103
+ <tr>
104
+ <td class="label"><strong><?php echo __('Source Site'); ?></strong> <span class="required">*</span></td>
105
+ <td class="input-ele">
106
+
107
+ <select class="required-entry" name="website[source]" style="width: 100%;">
108
+
109
+ <?php foreach ($stores as $store_id => $store_name): ?>
110
+
111
+ <option value="<?php echo $store_id; ?>"<?php echo (($config['store']['source'] == $store_id) ? ' selected' : '') ?>><?php echo $store_name; ?></option>
112
+
113
+ <?php endforeach; ?>
114
+
115
+ </select>
116
+
117
+ </td>
118
+ </tr>
119
+ <tr>
120
+ <td class="label"><strong><?php echo __('Target Site'); ?></strong> <span class="required">*</span></td>
121
+ <td class="input-ele">
122
+
123
+ <select class="required-entry" name="website[target]" style="width: 100%;">
124
+
125
+ <?php foreach ($stores as $store_id => $store_name): ?>
126
+
127
+ <option value="<?php echo $store_id; ?>"<?php echo (($config['store']['target'] == $store_id) ? ' selected' : '') ?>><?php echo $store_name; ?></option>
128
+
129
+ <?php endforeach; ?>
130
+
131
+ </select>
132
+
133
+ </td>
134
+ </tr>
135
+ <tr>
136
+ <td class="label"><strong><?php echo __('Save Rules'); ?></strong></td>
137
+ <td class="input-ele">
138
+
139
+ <input type="checkbox" name="save_rules" value="1"<?php echo (isset($post['save_rules'])) ? ' checked' : '' ?> />
140
+
141
+ </td>
142
+ </tr>
143
+ </table>
144
+ </fieldset>
145
+
146
+ </div>
147
+
148
+ </div>
149
+
150
+ <div class="box-right">
151
+
152
+ <div class="entry-edit">
153
+
154
+ <div class="entry-edit-head"><h4 class="icon-head"><?php echo __('Markup Rules'); ?></h4></div>
155
+
156
+ <div class="grid">
157
+ <table cellspacing="0" class="data">
158
+ <thead>
159
+ <tr class="headings">
160
+ <th><?php echo __('Begin Weight'); ?> <span class="required">*</span></th>
161
+ <th><?php echo __('End Weight'); ?> <span class="required">*</span></th>
162
+ <th><?php echo __('Type'); ?> <span class="required">*</span></th>
163
+ <th><?php echo __('Value'); ?> <span class="required">*</span></th>
164
+ <th class="last"><?php echo __('Action'); ?></th>
165
+ </tr>
166
+ </thead>
167
+ <tbody id="priceadjust_row_container">
168
+ <tr id="priceadjust_row_template" class="template no-display">
169
+ <td><input class="input-text number-title required-entry" type="text" name="rules[__index__][weight_begin]" id="rule_weight_begin__index__" value="" disabled="disabled" /></td>
170
+ <td><input class="input-text number-title required-entry" type="text" name="rules[__index__][weight_end]" id="rule_weight_end__index__" value="" disabled="disabled" /></td>
171
+ <td>
172
+ <select class="required-entry" name="rules[__index__][type]" id="rule_type__index__" disabled="disabled">
173
+ <option value="0" selected>Multiply</option>
174
+ <option value="1">Addition</option>
175
+ <option value="2">Subtract</option>
176
+ <option value="3">Divide</option>
177
+ </select>
178
+ </td>
179
+ <td><input class="input-text number-title required-entry" type="text" name="rules[__index__][value]" id="rule_value__index__" value="" disabled="disabled" /></td>
180
+ <td class="last"><a href="#" onclick="PriceAdjust.deleteRow(event);return false"><?php echo $this->__('Delete'); ?></a></td>
181
+ </tr>
182
+ </tbody>
183
+ <tfoot>
184
+ <tr>
185
+ <td colspan="5" class="a-center last">
186
+ <button onclick="PriceAdjust.add(0,0,0,0)" class="scalable" type="button"><span><?php echo __('Add Rule'); ?></span></button>
187
+ </td>
188
+ </tr>
189
+ </tfoot>
190
+ </table>
191
+ </div>
192
+
193
+ </div>
194
+
195
+ </div>
196
+
197
+ <div class="clear"></div>
198
+
199
+ </form>
200
+
201
+ <?php if ( ! empty($catalog)): ?>
202
+
203
+ <div class="entry-edit">
204
+
205
+ <div class="entry-edit-head"><h4 class="icon-head"><?php echo __('Price Adjustments'); ?></h4></div>
206
+
207
+ <div class="grid">
208
+ <table cellspacing="0" class="data">
209
+ <thead>
210
+ <tr class="headings">
211
+ <th><?php echo __('Product ID'); ?></th>
212
+ <th><?php echo __('SKU'); ?></th>
213
+ <th><?php echo __('Name'); ?></th>
214
+ <th><?php echo __('Weight'); ?></th>
215
+ <th><?php echo __('Original Price'); ?></th>
216
+ <th><?php echo __('Percent Change'); ?></th>
217
+ <th><?php echo __('Difference'); ?></th>
218
+ <th><?php echo __('New Price'); ?></th>
219
+ </tr>
220
+ </thead>
221
+ <tbody>
222
+
223
+ <?php foreach ($catalog as $product): ?>
224
+
225
+ <tr>
226
+ <td><?php echo $product['id']; ?></td>
227
+ <td><?php echo $product['sku']; ?></td>
228
+ <td><?php echo $product['name']; ?></td>
229
+ <td><?php echo number_format($product['weight'], 3, '.', ''); ?></td>
230
+ <td><?php echo $helper->format_price($product['price']); ?></td>
231
+ <td><?php echo number_format($product['change_percent'], 2, '.', ''); ?>%</td>
232
+ <td><?php echo $helper->format_price($product['change_difference']); ?></td>
233
+ <td><?php echo $helper->format_price($product['change_price']); ?></td>
234
+ </tr>
235
+
236
+ <?php endforeach; ?>
237
+
238
+ </tbody>
239
+ </table>
240
+ </div>
241
+
242
+ </div>
243
+ </div>
244
+
245
+ <?php endif; ?>
246
+
247
+ <script type="text/javascript">
248
+
249
+ var editForm = new varienForm('edit_form');
250
+
251
+ PriceAdjust.template = new Template('<tr>' + $('priceadjust_row_template').innerHTML.replace(/__index__/g, '#{index}') + '<\/tr>');
252
+
253
+ <?php if ( ! empty($rules)): ?>
254
+
255
+ <?php foreach ($rules as $rule): ?>
256
+
257
+ PriceAdjust.add(<?php echo $rule['weight_begin']; ?>, <?php echo $rule['weight_end']; ?>, <?php echo $rule['type']; ?>, <?php echo $rule['value']; ?>);
258
+
259
+ <?php endforeach; ?>
260
+
261
+ <?php else: ?>
262
+
263
+ PriceAdjust.add(0,0,0,0);
264
+
265
+ <?php endif; ?>
266
+
267
+ </script>
app/etc/modules/MagnifyStudio_PriceAdjust.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <MagnifyStudio_PriceAdjust>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </MagnifyStudio_PriceAdjust>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>MagnifyStudio_PriceAdjust</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>MIT</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Mass adjust product prices based on rules. Advanced multi-store features.</summary>
10
+ <description>Ability to mass adjust product prices using rules. Can simply increase or decrease chosen product prices or set individual rules based on a products weight. The rules can be saved for easier rerunning of the adjustment. Advanced multi-store feature for choosing a source store for the prices and then targeting the corresponding products in a target store.</description>
11
+ <notes>Initial Release</notes>
12
+ <authors><author><name>Magnify Studio</name><user>magnifystudio</user><email>micheal.morgan@magnifystudio.com</email></author></authors>
13
+ <date>2014-03-15</date>
14
+ <time>07:22:26</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="MagnifyStudio_PriceAdjust.xml" hash="7cba81990b5cc766b358fe2879f05ec9"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="magnifystudio"><dir name="priceadjust"><file name="priceadjust.phtml" hash="8ff7822aa0fce421ab466b123ce61e81"/><file name=".DS_Store" hash="50c42cd2b89247cd779d00a70a5f341b"/></dir></dir></dir><dir name="layout"><file name="magnifystudio_priceadjust.xml" hash="868770d2f533b48b1913651fa1f21369"/></dir></dir></dir></dir></target><target name="magecommunity"><dir name="MagnifyStudio"><dir name="PriceAdjust"><dir><dir name="Helper"><file name="Data.php" hash="d8dbf499fe7b559da059cd141960b114"/><file name=".DS_Store" hash="3f3a2d9fa57478d21b0cbf6407cd3df0"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Priceadjust"><file name="Collection.php" hash="2f0de70df439f49a3c0dd42fc44aae44"/><file name=".DS_Store" hash="f3b2bab29f6b7eddfad0ccf944ef875f"/></dir><file name="Priceadjust.php" hash="3b2e3ec1c3d403b1961539b23d8bdc9d"/><file name=".DS_Store" hash="4029269024a69819d4a416f870145afc"/></dir><file name="Observer.php" hash="f0120223db35ea4f2e9548045f2c675c"/><file name="Priceadjust.php" hash="b9a9b9a5b16d40b575dfcb665a22cefb"/><file name=".DS_Store" hash="734c72fae8ab3470afbd540123e6fcef"/></dir><dir name="controllers"><file name="AdjustController.php" hash="9d45b3f98f51f99170669088fa9c2009"/><file name=".DS_Store" hash="f20aeed4dd746faabec770ccf9e87ef7"/></dir><dir name="etc"><file name="config.xml" hash="fc86ff3be920d3aad16447281bd76ba3"/><file name=".DS_Store" hash="c1946c774535b7e5cd8ff067c3957a7c"/></dir><dir name="sql"><dir name="priceadjust_setup"><file name="mysql4-install-0.1.0.php" hash="f40e45b21800e8beda6118cb3ecee4c8"/><file name=".DS_Store" hash="1cde15192a2cf058aa9adb4503f6a96a"/></dir><file name=".DS_Store" hash="25dbb7b2523dfea807261271a3e1db9e"/></dir></dir><file name=".DS_Store" hash="de7db78171bf9ec4055f8a59ad2d8066"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>