jmage-special-cart-rule - Version 1.0.0

Version Notes

First Release.

Download this release

Release Info

Developer Jickson Johnson Koottala
Extension jmage-special-cart-rule
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Jmage/SalesRule/Block/Promo/Quote/Edit/Tab/Actions.php ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Adminhtml
23
+ * @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ /**
28
+ * description
29
+ *
30
+ * @category Mage
31
+ * @category Mage
32
+ * @package Mage_Adminhtml
33
+ * @author Magento Core Team <core@magentocommerce.com>
34
+ */
35
+ class Jmage_SalesRule_Block_Promo_Quote_Edit_Tab_Actions
36
+ extends Mage_Adminhtml_Block_Promo_Quote_Edit_Tab_Actions
37
+
38
+ {
39
+
40
+ protected function _prepareForm()
41
+ {
42
+ $model = Mage::registry('current_promo_quote_rule');
43
+
44
+ //$form = new Varien_Data_Form(array('id' => 'edit_form1', 'action' => $this->getData('action'), 'method' => 'post'));
45
+ $form = new Varien_Data_Form();
46
+
47
+ $form->setHtmlIdPrefix('rule_');
48
+
49
+ $fieldset = $form->addFieldset('action_fieldset', array('legend'=>Mage::helper('salesrule')->__('Update prices using the following information')));
50
+ //updated the new action
51
+ $fieldset->addField('simple_action', 'select', array(
52
+ 'label' => Mage::helper('salesrule')->__('Apply'),
53
+ 'name' => 'simple_action',
54
+ 'options' => array(
55
+ Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION => Mage::helper('salesrule')->__('Percent of product price discount'),
56
+ Mage_SalesRule_Model_Rule::BY_FIXED_ACTION => Mage::helper('salesrule')->__('Fixed amount discount'),
57
+ Mage_SalesRule_Model_Rule::CART_FIXED_ACTION => Mage::helper('salesrule')->__('Fixed amount discount for whole cart'),
58
+ Mage_SalesRule_Model_Rule::BUY_X_GET_Y_ACTION => Mage::helper('salesrule')->__('Buy X get Y free (discount amount is Y)'),
59
+ Jmage_SalesRule_Model_Rule::HIGHEST_PRICE_ITEM_DISCOUNT_ACTION => Mage::helper('salesrule')->__(' X% Discount on highest priced item in cart'),
60
+ Jmage_SalesRule_Model_Rule::LOWEST_PRICE_ITEM_DISCOUNT_ACTION => Mage::helper('salesrule')->__(' X% Discount on lowest priced item in cart'),
61
+
62
+ ),
63
+ ));
64
+ $fieldset->addField('discount_amount', 'text', array(
65
+ 'name' => 'discount_amount',
66
+ 'required' => true,
67
+ 'class' => 'validate-not-negative-number',
68
+ 'label' => Mage::helper('salesrule')->__('Discount Amount'),
69
+ ));
70
+ $model->setDiscountAmount($model->getDiscountAmount()*1);
71
+
72
+ $fieldset->addField('discount_qty', 'text', array(
73
+ 'name' => 'discount_qty',
74
+ 'label' => Mage::helper('salesrule')->__('Maximum Qty Discount is Applied To'),
75
+ ));
76
+ $model->setDiscountQty($model->getDiscountQty()*1);
77
+
78
+ $fieldset->addField('discount_step', 'text', array(
79
+ 'name' => 'discount_step',
80
+ 'label' => Mage::helper('salesrule')->__('Discount Qty Step (Buy X)'),
81
+ ));
82
+
83
+ $fieldset->addField('apply_to_shipping', 'select', array(
84
+ 'label' => Mage::helper('salesrule')->__('Apply to Shipping Amount'),
85
+ 'title' => Mage::helper('salesrule')->__('Apply to Shipping Amount'),
86
+ 'name' => 'apply_to_shipping',
87
+ 'values' => Mage::getSingleton('adminhtml/system_config_source_yesno')->toOptionArray(),
88
+ ));
89
+
90
+ $fieldset->addField('simple_free_shipping', 'select', array(
91
+ 'label' => Mage::helper('salesrule')->__('Free Shipping'),
92
+ 'title' => Mage::helper('salesrule')->__('Free Shipping'),
93
+ 'name' => 'simple_free_shipping',
94
+ 'options' => array(
95
+ 0 => Mage::helper('salesrule')->__('No'),
96
+ Mage_SalesRule_Model_Rule::FREE_SHIPPING_ITEM => Mage::helper('salesrule')->__('For matching items only'),
97
+ Mage_SalesRule_Model_Rule::FREE_SHIPPING_ADDRESS => Mage::helper('salesrule')->__('For shipment with matching items'),
98
+ ),
99
+ ));
100
+
101
+ $fieldset->addField('stop_rules_processing', 'select', array(
102
+ 'label' => Mage::helper('salesrule')->__('Stop Further Rules Processing'),
103
+ 'title' => Mage::helper('salesrule')->__('Stop Further Rules Processing'),
104
+ 'name' => 'stop_rules_processing',
105
+ 'options' => array(
106
+ '1' => Mage::helper('salesrule')->__('Yes'),
107
+ '0' => Mage::helper('salesrule')->__('No'),
108
+ ),
109
+ ));
110
+
111
+ $renderer = Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
112
+ ->setTemplate('promo/fieldset.phtml')
113
+ ->setNewChildUrl($this->getUrl('*/promo_quote/newActionHtml/form/rule_actions_fieldset'));
114
+
115
+ $fieldset = $form->addFieldset('actions_fieldset', array(
116
+ 'legend'=>Mage::helper('salesrule')->__('Apply the rule only to cart items matching the following conditions (leave blank for all items)')
117
+ ))->setRenderer($renderer);
118
+
119
+ $fieldset->addField('actions', 'text', array(
120
+ 'name' => 'actions',
121
+ 'label' => Mage::helper('salesrule')->__('Apply To'),
122
+ 'title' => Mage::helper('salesrule')->__('Apply To'),
123
+ 'required' => true,
124
+ ))->setRule($model)->setRenderer(Mage::getBlockSingleton('rule/actions'));
125
+
126
+ Mage::dispatchEvent('adminhtml_block_salesrule_actions_prepareform', array('form' => $form));
127
+
128
+ $form->setValues($model->getData());
129
+
130
+ if ($model->isReadonly()) {
131
+ foreach ($fieldset->getElements() as $element) {
132
+ $element->setReadonly(true, true);
133
+ }
134
+ }
135
+ //$form->setUseContainer(true);
136
+
137
+ $this->setForm($form);
138
+
139
+ return $this;
140
+ }
141
+
142
+ }
app/code/local/Jmage/SalesRule/Model/Rule.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+ class Jmage_SalesRule_Model_Rule extends Mage_SalesRule_Model_Rule
3
+ {
4
+ const HIGHEST_PRICE_ITEM_DISCOUNT_ACTION = 'highest_price_item_discount';
5
+ const LOWEST_PRICE_ITEM_DISCOUNT_ACTION = 'lowest_price_item_discount';
6
+ }
7
+ ?>
app/code/local/Jmage/SalesRule/Model/Validator.php ADDED
@@ -0,0 +1,375 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_SalesRule
23
+ * @copyright Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+
28
+ /**
29
+ * SalesRule Validator Model
30
+ *
31
+ * Allows dispatching before and after events for each controller action
32
+ *
33
+ * @category Mage
34
+ * @package Mage_SalesRule
35
+ * @author Magento Core Team <core@magentocommerce.com>
36
+ */
37
+ class Jmage_SalesRule_Model_Validator extends Mage_SalesRule_Model_Validator
38
+ {
39
+ //created new member variable
40
+ protected $_stopFurtherRules = array();
41
+ public $discount_qty = 0;
42
+ public $notsame = 0;
43
+
44
+
45
+ /**
46
+ * Quote item discount calculation process
47
+ *
48
+ * @param Mage_Sales_Model_Quote_Item_Abstract $item
49
+ * @return Mage_SalesRule_Model_Validator
50
+ */
51
+ public function process(Mage_Sales_Model_Quote_Item_Abstract $item)
52
+ {
53
+ $item->setDiscountAmount(0);
54
+ $item->setBaseDiscountAmount(0);
55
+ $item->setDiscountPercent(0);
56
+ $quote = $item->getQuote();
57
+ $address = $this->_getAddress($item);
58
+
59
+ $itemPrice = $this->_getItemPrice($item);
60
+ $baseItemPrice = $this->_getItemBasePrice($item);
61
+ $itemOriginalPrice = $this->_getItemOriginalPrice($item);
62
+ $baseItemOriginalPrice = $this->_getItemBaseOriginalPrice($item);
63
+
64
+ if ($itemPrice < 0) {
65
+ return $this;
66
+ }
67
+
68
+ $appliedRuleIds = array();
69
+ $this->_stopFurtherRules = false;
70
+ foreach ($this->_getRules() as $rule) {
71
+
72
+ /* @var $rule Mage_SalesRule_Model_Rule */
73
+ if (!$this->_canProcessRule($rule, $address)) {
74
+ continue;
75
+ }
76
+
77
+ if (!$rule->getActions()->validate($item)) {
78
+ continue;
79
+ }
80
+
81
+ $qty = $this->_getItemQty($item, $rule);
82
+ $rulePercent = min(100, $rule->getDiscountAmount());
83
+
84
+ $discountAmount = 0;
85
+ $baseDiscountAmount = 0;
86
+ //discount for original price
87
+ $originalDiscountAmount = 0;
88
+ $baseOriginalDiscountAmount = 0;
89
+
90
+ switch ($rule->getSimpleAction()) {
91
+ case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION:
92
+ $rulePercent = max(0, 100-$rule->getDiscountAmount());
93
+ //no break;
94
+ case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION:
95
+ $step = $rule->getDiscountStep();
96
+ if ($step) {
97
+ $qty = floor($qty/$step)*$step;
98
+ }
99
+ $_rulePct = $rulePercent/100;
100
+ $discountAmount = ($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct;
101
+ $baseDiscountAmount = ($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct;
102
+ //get discount for original price
103
+ $originalDiscountAmount = ($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
104
+ $baseOriginalDiscountAmount =
105
+ ($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
106
+
107
+ if (!$rule->getDiscountQty() || $rule->getDiscountQty()>$qty) {
108
+ $discountPercent = min(100, $item->getDiscountPercent()+$rulePercent);
109
+ $item->setDiscountPercent($discountPercent);
110
+ }
111
+ break;
112
+ case Mage_SalesRule_Model_Rule::TO_FIXED_ACTION:
113
+ $quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
114
+ $discountAmount = $qty * ($itemPrice-$quoteAmount);
115
+ $baseDiscountAmount = $qty * ($baseItemPrice-$rule->getDiscountAmount());
116
+ //get discount for original price
117
+ $originalDiscountAmount = $qty * ($itemOriginalPrice-$quoteAmount);
118
+ $baseOriginalDiscountAmount = $qty * ($baseItemOriginalPrice-$rule->getDiscountAmount());
119
+ break;
120
+
121
+ case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION:
122
+ $step = $rule->getDiscountStep();
123
+ if ($step) {
124
+ $qty = floor($qty/$step)*$step;
125
+ }
126
+ $quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
127
+ $discountAmount = $qty * $quoteAmount;
128
+ $baseDiscountAmount = $qty * $rule->getDiscountAmount();
129
+ break;
130
+
131
+ case Mage_SalesRule_Model_Rule::CART_FIXED_ACTION:
132
+ if (empty($this->_rulesItemTotals[$rule->getId()])) {
133
+ Mage::throwException(Mage::helper('salesrule')->__('Item totals are not set for rule.'));
134
+ }
135
+
136
+ /**
137
+ * prevent applying whole cart discount for every shipping order, but only for first order
138
+ */
139
+ if ($quote->getIsMultiShipping()) {
140
+ $usedForAddressId = $this->getCartFixedRuleUsedForAddress($rule->getId());
141
+ if ($usedForAddressId && $usedForAddressId != $address->getId()) {
142
+ break;
143
+ } else {
144
+ $this->setCartFixedRuleUsedForAddress($rule->getId(), $address->getId());
145
+ }
146
+ }
147
+ $cartRules = $address->getCartFixedRules();
148
+ if (!isset($cartRules[$rule->getId()])) {
149
+ $cartRules[$rule->getId()] = $rule->getDiscountAmount();
150
+ }
151
+
152
+ if ($cartRules[$rule->getId()] > 0) {
153
+ if ($this->_rulesItemTotals[$rule->getId()]['items_count'] <= 1) {
154
+ $quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]);
155
+ $baseDiscountAmount = min($baseItemPrice * $qty, $cartRules[$rule->getId()]);
156
+ } else {
157
+ $discountRate = $baseItemPrice * $qty /
158
+ $this->_rulesItemTotals[$rule->getId()]['base_items_price'];
159
+ $maximumItemDiscount = $rule->getDiscountAmount() * $discountRate;
160
+ $quoteAmount = $quote->getStore()->convertPrice($maximumItemDiscount);
161
+
162
+ $baseDiscountAmount = min($baseItemPrice * $qty, $maximumItemDiscount);
163
+ $this->_rulesItemTotals[$rule->getId()]['items_count']--;
164
+ }
165
+
166
+ $discountAmount = min($itemPrice * $qty, $quoteAmount);
167
+ $discountAmount = $quote->getStore()->roundPrice($discountAmount);
168
+ $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
169
+
170
+ //get discount for original price
171
+ $originalDiscountAmount = min($itemOriginalPrice * $qty, $quoteAmount);
172
+ $baseOriginalDiscountAmount = $quote->getStore()->roundPrice($baseItemOriginalPrice);
173
+
174
+ $cartRules[$rule->getId()] -= $baseDiscountAmount;
175
+ }
176
+ $address->setCartFixedRules($cartRules);
177
+
178
+ break;
179
+
180
+ case Mage_SalesRule_Model_Rule::BUY_X_GET_Y_ACTION:
181
+
182
+ $x = $rule->getDiscountStep();
183
+ $y = $rule->getDiscountAmount();
184
+ if (!$x || $y > $x) {
185
+ break;
186
+ }
187
+ $buyAndDiscountQty = $x + $y;
188
+
189
+ $fullRuleQtyPeriod = floor($qty / $buyAndDiscountQty);
190
+ $freeQty = $qty - $fullRuleQtyPeriod * $buyAndDiscountQty;
191
+
192
+ $discountQty = $fullRuleQtyPeriod * $y;
193
+ if ($freeQty > $x) {
194
+ $discountQty += $freeQty - $x;
195
+ }
196
+
197
+ $discountAmount = $discountQty * $itemPrice;
198
+ $baseDiscountAmount = $discountQty * $baseItemPrice;
199
+ //get discount for original price
200
+ $originalDiscountAmount = $discountQty * $itemOriginalPrice;
201
+ $baseOriginalDiscountAmount = $discountQty * $baseItemOriginalPrice;
202
+ break;
203
+
204
+ //new case condition for new rule HIGHEST_PRICE_ITEM_DISCOUNT_ACTION
205
+ case Jmage_SalesRule_Model_Rule::HIGHEST_PRICE_ITEM_DISCOUNT_ACTION:
206
+
207
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
208
+ $cartItems = $quote->getAllVisibleItems();
209
+ $num_items = count($cartItems);
210
+ if($num_items >= 1 )
211
+ {
212
+ $highest_product_price=$cartItems[0]->getPrice();
213
+ $highest_product_qty=$cartItems[0]->getQty();
214
+ foreach($cartItems as $item)
215
+ {
216
+ if($item->getPrice() > $highest_product_price || $item->getPrice() == $highest_product_price )
217
+ {
218
+ $highest_product_price = $item->getPrice();
219
+ $highest_product_qty = $item->getQty();
220
+ $item_sku = $item->getSku();
221
+ }
222
+ }
223
+ }
224
+ $item_sku = $item_sku;
225
+ $highest_product_price_item = $highest_product_price;
226
+ $highest_item_qty = $highest_product_qty;
227
+ $quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
228
+ $_rulePct = $quoteAmount/100;
229
+ $discountAmount = ($highest_item_qty*$highest_product_price_item) * $_rulePct;
230
+ $baseDiscountAmount= ($highest_item_qty*$highest_product_price_item) * $_rulePct;
231
+ $originalDiscountAmount = ($highest_item_qty*$highest_product_price_item) * $_rulePct;
232
+ $baseOriginalDiscountAmount= ($highest_item_qty*$highest_product_price_item) * $_rulePct;
233
+ break;
234
+
235
+ //new case condition for new rule LOWEST_PRICE_ITEM_DISCOUNT_ACTION
236
+ case Jmage_SalesRule_Model_Rule::LOWEST_PRICE_ITEM_DISCOUNT_ACTION:
237
+
238
+ $quote = Mage::getSingleton('checkout/session')->getQuote();
239
+ $cartItems = $quote->getAllVisibleItems();
240
+ $num_items = count($cartItems);
241
+ if($num_items >= 1 )
242
+ {
243
+ $lowest_product_price=$cartItems[0]->getPrice();
244
+ $lowest_product_qty =$cartItems[0]->getQty();
245
+ foreach($cartItems as $item)
246
+ {
247
+ if($item->getPrice() < $lowest_product_price || $item->getPrice() == $lowest_product_price )
248
+ {
249
+ $lowest_product_price = $item->getPrice();
250
+ $lowest_product_qty = $item->getQty();
251
+ $item_sku = $item->getSku();
252
+ }
253
+ }
254
+ }
255
+ $item_sku = $item_sku;
256
+ $lowest_product_price_item = $lowest_product_price;
257
+ $lowest_item_qty = $lowest_product_qty;
258
+ $quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
259
+ $_rulePct = $quoteAmount/100;
260
+ $discountAmount = ($lowest_item_qty*$lowest_product_price_item) * $_rulePct;
261
+ $baseDiscountAmount= ($lowest_item_qty*$lowest_product_price_item) * $_rulePct;
262
+ $originalDiscountAmount = ($lowest_item_qty*$lowest_product_price_item) * $_rulePct;
263
+ $baseOriginalDiscountAmount= ($lowest_item_qty*$lowest_product_price_item) * $_rulePct;
264
+ break;
265
+ }
266
+
267
+ $result = new Varien_Object(array(
268
+ 'discount_amount' => $discountAmount,
269
+ 'base_discount_amount' => $baseDiscountAmount,
270
+ ));
271
+ Mage::dispatchEvent('salesrule_validator_process', array(
272
+ 'rule' => $rule,
273
+ 'item' => $item,
274
+ 'address' => $address,
275
+ 'quote' => $quote,
276
+ 'qty' => $qty,
277
+ 'result' => $result,
278
+ ));
279
+
280
+ $discountAmount = $result->getDiscountAmount();
281
+ $baseDiscountAmount = $result->getBaseDiscountAmount();
282
+
283
+ $percentKey = $item->getDiscountPercent();
284
+ /**
285
+ * Process "delta" rounding
286
+ */
287
+ if ($percentKey) {
288
+ $delta = isset($this->_roundingDeltas[$percentKey]) ? $this->_roundingDeltas[$percentKey] : 0;
289
+ $baseDelta = isset($this->_baseRoundingDeltas[$percentKey])
290
+ ? $this->_baseRoundingDeltas[$percentKey]
291
+ : 0;
292
+ $discountAmount += $delta;
293
+ $baseDiscountAmount += $baseDelta;
294
+
295
+ $this->_roundingDeltas[$percentKey] = $discountAmount -
296
+ $quote->getStore()->roundPrice($discountAmount);
297
+ $this->_baseRoundingDeltas[$percentKey] = $baseDiscountAmount -
298
+ $quote->getStore()->roundPrice($baseDiscountAmount);
299
+ $discountAmount = $quote->getStore()->roundPrice($discountAmount);
300
+ $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
301
+ } else {
302
+ $discountAmount = $quote->getStore()->roundPrice($discountAmount);
303
+ $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
304
+ }
305
+
306
+ /**
307
+ * We can't use row total here because row total not include tax
308
+ * Discount can be applied on price included tax
309
+ */
310
+
311
+ /*$itemDiscountAmount = $item->getDiscountAmount();
312
+ $itemBaseDiscountAmount = $item->getBaseDiscountAmount();
313
+
314
+ echo 'item discount amount'.$itemDiscountAmount.'<br>';
315
+ echo 'item base discount amount'.$itemDiscountAmount.'<br>';
316
+
317
+ $discountAmount = min($itemDiscountAmount + $discountAmount, $itemPrice * $qty);
318
+ $baseDiscountAmount = min($itemBaseDiscountAmount + $baseDiscountAmount, $baseItemPrice * $qty);
319
+
320
+ echo 'item discount amount'.$discountAmount.'<br>';
321
+ echo 'item base discount amount'.$baseDiscountAmount.'<br>';*/
322
+
323
+
324
+ $item->setDiscountAmount($discountAmount);
325
+ $item->setBaseDiscountAmount($baseDiscountAmount);
326
+
327
+ $item->setOriginalDiscountAmount($originalDiscountAmount);
328
+ $item->setBaseOriginalDiscountAmount($baseOriginalDiscountAmount);
329
+
330
+ $appliedRuleIds[$rule->getRuleId()] = $rule->getRuleId();
331
+
332
+ $this->_maintainAddressCouponCode($address, $rule);
333
+ $this->_addDiscountDescription($address, $rule, $item_sku, $quoteAmount);
334
+
335
+ if ($rule->getStopRulesProcessing()) {
336
+ $this->_stopFurtherRules = true;
337
+ break;
338
+ }
339
+ }
340
+ $item->setAppliedRuleIds(join(',',$appliedRuleIds));
341
+ $address->setAppliedRuleIds($this->mergeIds($address->getAppliedRuleIds(), $appliedRuleIds));
342
+ $quote->setAppliedRuleIds($this->mergeIds($quote->getAppliedRuleIds(), $appliedRuleIds));
343
+
344
+ return $this;
345
+ }
346
+
347
+ protected function _addDiscountDescription($address, $rule, $item_sku, $quoteAmount)
348
+ {
349
+ $description = $address->getDiscountDescriptionArray();
350
+ $ruleLabel = $rule->getStoreLabel($address->getQuote()->getStore());
351
+ $label = '';
352
+ if ($ruleLabel) {
353
+ $label = $ruleLabel;
354
+ } else if (strlen($address->getCouponCode())) {
355
+ $label = $address->getCouponCode();
356
+ }
357
+ if($rule->getSimpleAction() == Jmage_SalesRule_Model_Rule::HIGHEST_PRICE_ITEM_DISCOUNT_ACTION)
358
+ {
359
+ $label .= ",".$quoteAmount." % dsicount on High Price sku (".$item_sku.")";
360
+ }
361
+ elseif($rule->getSimpleAction() == Jmage_SalesRule_Model_Rule::LOWEST_PRICE_ITEM_DISCOUNT_ACTION)
362
+ {
363
+ $label .= ",".$quoteAmount." % dsicount on Low Price sku (".$item_sku.")";
364
+ }
365
+
366
+ if (strlen($label)) {
367
+ $description[$rule->getId()] = $label;
368
+ }
369
+
370
+ $address->setDiscountDescriptionArray($description);
371
+ return $this;
372
+ }
373
+
374
+
375
+ }
app/code/local/Jmage/SalesRule/etc/config.xml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Jmage_SalesRule>
5
+ <version>1.0.0</version>
6
+ </Jmage_SalesRule>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <adminhtml>
11
+ <rewrite>
12
+ <promo_quote_edit_tab_actions>Jmage_SalesRule_Block_Promo_Quote_Edit_Tab_Actions</promo_quote_edit_tab_actions>
13
+ </rewrite>
14
+ </adminhtml>
15
+ </blocks>
16
+ <models>
17
+ <salesrule>
18
+ <rewrite>
19
+ <rule>Jmage_SalesRule_Model_Rule</rule>
20
+ <validator>Jmage_SalesRule_Model_Validator</validator>
21
+ </rewrite>
22
+ </salesrule>
23
+ </models>
24
+ </global>
25
+ </config>
app/etc/modules/Jmage_SalesRule.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Jmage_SalesRule>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ <depends>
8
+ <Mage_Sales/>
9
+ </depends>
10
+ <!-- if there any other module overriding the same class (Mage_SalesRule_Model_Validator), then mention the module name in the the depends tag -->
11
+ </Jmage_SalesRule>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>jmage-special-cart-rule</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This module will allow you to set discount on high and low price item in cart.</summary>
10
+ <description>Jmage SalesRule extension is a extended version of Magento Shopping Cart Module. Using this module we can able to set discount price on High and Low priced item in shopping cart. &#xD;
11
+ This works same like the default shopping cart rule. There will be two extra option in the shopping cart rule action settings. We only need to choose the appropriate one and set the discount amount. This module will support coupon code and other conditions and combinations within the shopping cart rule settings.</description>
12
+ <notes>First Release.</notes>
13
+ <authors><author><name>Jickson Johnson Koottala</name><user>jicksonkoottala</user><email>jicksonkoottala@gmail.com</email></author></authors>
14
+ <date>2015-11-08</date>
15
+ <time>18:19:58</time>
16
+ <contents><target name="magelocal"><dir name="Jmage"><dir name="SalesRule"><dir name="Block"><dir name="Promo"><dir name="Quote"><dir name="Edit"><dir name="Tab"><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/><file name="Actions.php" hash="26eb34fbc36072a0c263cf763114d1bc"/></dir></dir></dir></dir></dir><dir name="Model"><file name="Rule.php" hash="a8461dae74bb184e49915e79d364e966"/><file name="Validator.php" hash="383993d1cffda2a0e378b30a532f54a9"/><file name="Rule.php" hash="a8461dae74bb184e49915e79d364e966"/><file name="Validator.php" hash="383993d1cffda2a0e378b30a532f54a9"/><file name="Rule.php" hash="a8461dae74bb184e49915e79d364e966"/><file name="Validator.php" hash="383993d1cffda2a0e378b30a532f54a9"/><file name="Rule.php" hash="a8461dae74bb184e49915e79d364e966"/><file name="Validator.php" hash="383993d1cffda2a0e378b30a532f54a9"/></dir><dir name="etc"><file name="config.xml" hash="66338ee5dd686819c94f6052f9534d0f"/><file name="config.xml" hash="66338ee5dd686819c94f6052f9534d0f"/><file name="config.xml" hash="66338ee5dd686819c94f6052f9534d0f"/><file name="config.xml" hash="66338ee5dd686819c94f6052f9534d0f"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Jmage_SalesRule.xml" hash="21b5b44edc20e617cbac94ea76a08cb2"/></dir></target></contents>
17
+ <compatible/>
18
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Module</name><channel>community</channel><min>1.8</min><max>1.9</max></package></required></dependencies>
19
+ </package>