multidiscount - Version 0.1.4

Version Notes

fixing multiple products issue

Download this release

Release Info

Developer Kingshuk deb
Extension multidiscount
Version 0.1.4
Comparing to
See all releases


Code changes from version 0.1.3 to 0.1.4

app/code/local/Multidiscount/Couponcode/Model/SalesRule/Validator.php CHANGED
@@ -136,6 +136,19 @@ class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_
136
  break;
137
 
138
  case Multidiscount_Couponcode_Model_Percentconst::CART_PERCENT_ACTION:
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  $percentageData = unserialize($rule->getCartpercentSerialized());
140
  $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
141
  $quoteAmount = $totals["subtotal"]->getValue();
@@ -145,6 +158,37 @@ class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_
145
  $discountAmount = $quote->getStore()->roundPrice($discountAmount);
146
  }
147
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  break;
149
 
150
  case Mage_SalesRule_Model_Rule::BUY_X_GET_Y_ACTION:
@@ -244,5 +288,54 @@ class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_
244
 
245
  return $this;
246
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
247
  }
248
 
136
  break;
137
 
138
  case Multidiscount_Couponcode_Model_Percentconst::CART_PERCENT_ACTION:
139
+ if (empty($this->_rulesItemTotals[$rule->getId()])) {
140
+ Mage::throwException(Mage::helper('salesrule')->__('Item totals are not set for rule.'));
141
+ }
142
+
143
+ if ($quote->getIsMultiShipping()) {
144
+ $usedForAddressId = $this->getCartFixedRuleUsedForAddress($rule->getId());
145
+ if ($usedForAddressId && $usedForAddressId != $address->getId()) {
146
+ break;
147
+ } else {
148
+ $this->setCartFixedRuleUsedForAddress($rule->getId(), $address->getId());
149
+ }
150
+ }
151
+ $cartRules = $address->getCartFixedRules();
152
  $percentageData = unserialize($rule->getCartpercentSerialized());
153
  $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
154
  $quoteAmount = $totals["subtotal"]->getValue();
158
  $discountAmount = $quote->getStore()->roundPrice($discountAmount);
159
  }
160
  }
161
+
162
+ $cartRules = $address->getCartFixedRules();
163
+ if (!isset($cartRules[$rule->getId()])) {
164
+ $cartRules[$rule->getId()] = $discountAmount;
165
+ }
166
+
167
+ if ($cartRules[$rule->getId()] > 0) {
168
+ if ($this->_rulesItemTotals[$rule->getId()]['items_count'] <= 1) {
169
+ $quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]);
170
+ $baseDiscountAmount = min($baseItemPrice * $qty, $cartRules[$rule->getId()]);
171
+ } else {
172
+ $discountRate = $baseItemPrice * $qty /
173
+ $this->_rulesItemTotals[$rule->getId()]['base_items_price'];
174
+ $maximumItemDiscount = $discountAmount * $discountRate;
175
+ $quoteAmount = $quote->getStore()->convertPrice($maximumItemDiscount);
176
+
177
+ $baseDiscountAmount = min($baseItemPrice * $qty, $maximumItemDiscount);
178
+ $this->_rulesItemTotals[$rule->getId()]['items_count']--;
179
+ }
180
+
181
+ $discountAmount = min($itemPrice * $qty, $quoteAmount);
182
+ $discountAmount = $quote->getStore()->roundPrice($discountAmount);
183
+ $baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
184
+
185
+ //get discount for original price
186
+ $originalDiscountAmount = min($itemOriginalPrice * $qty, $quoteAmount);
187
+ $baseOriginalDiscountAmount = $quote->getStore()->roundPrice($baseItemOriginalPrice);
188
+
189
+ $cartRules[$rule->getId()] -= $baseDiscountAmount;
190
+ }
191
+ $address->setCartFixedRules($cartRules);
192
  break;
193
 
194
  case Mage_SalesRule_Model_Rule::BUY_X_GET_Y_ACTION:
288
 
289
  return $this;
290
  }
291
+
292
+ /**
293
+ * Calculate quote totals for each rule and save results
294
+ *
295
+ * @param mixed $items
296
+ * @param Mage_Sales_Model_Quote_Address $address
297
+ * @return Mage_SalesRule_Model_Validator
298
+ */
299
+ public function initTotals($items, Mage_Sales_Model_Quote_Address $address)
300
+ {
301
+ $address->setCartFixedRules(array());
302
+
303
+ if (!$items) {
304
+ return $this;
305
+ }
306
+
307
+ foreach ($this->_getRules() as $rule) {
308
+ if (Mage_SalesRule_Model_Rule::CART_FIXED_ACTION == $rule->getSimpleAction()
309
+ && $this->_canProcessRule($rule, $address) || Multidiscount_Couponcode_Model_Percentconst::CART_PERCENT_ACTION == $rule->getSimpleAction()
310
+ && $this->_canProcessRule($rule, $address)) {
311
+
312
+ $ruleTotalItemsPrice = 0;
313
+ $ruleTotalBaseItemsPrice = 0;
314
+ $validItemsCount = 0;
315
+
316
+ foreach ($items as $item) {
317
+ //Skipping child items to avoid double calculations
318
+ if ($item->getParentItemId()) {
319
+ continue;
320
+ }
321
+ if (!$rule->getActions()->validate($item)) {
322
+ continue;
323
+ }
324
+ $qty = $this->_getItemQty($item, $rule);
325
+ $ruleTotalItemsPrice += $this->_getItemPrice($item) * $qty;
326
+ $ruleTotalBaseItemsPrice += $this->_getItemBasePrice($item) * $qty;
327
+ $validItemsCount++;
328
+ }
329
+
330
+ $this->_rulesItemTotals[$rule->getId()] = array(
331
+ 'items_price' => $ruleTotalItemsPrice,
332
+ 'base_items_price' => $ruleTotalBaseItemsPrice,
333
+ 'items_count' => $validItemsCount,
334
+ );
335
+ }
336
+ }
337
+ $this->_stopFurtherRules = false;
338
+ return $this;
339
+ }
340
  }
341
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Multidiscount_Couponcode</name>
4
- <version>0.1.3</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
@@ -17,11 +17,11 @@ Like if you want to provide discount for &#xD;
17
  and so on.&#xD;
18
  &#xD;
19
  You just need to create a single coupon code and need to add from what amount to what amount how much discount you want to provide.</description>
20
- <notes>Adding Validator model override</notes>
21
  <authors><author><name>Kingshuk deb</name><user>kingshukdeb</user><email>kingshukdeb88@gmail.com</email></author></authors>
22
- <date>2016-06-18</date>
23
- <time>06:45:33</time>
24
- <contents><target name="magelocal"><dir name="Multidiscount"><dir name="Couponcode"><dir name="Block"><dir name="Adminhtml"><dir name="Promo"><dir name="Quote"><dir name="Edit"><file name="Options.php" hash="b251dd1751fb49adaa0143fe63b357e4"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="16e670874b16e6ea0f0a318fbae54c05"/></dir><dir name="Model"><file name="Observer.php" hash="cc58c72bed15cd57dedf24e0e64cf22d"/><file name="Percentconst.php" hash="c566016651e421e291039314231e1eb1"/><dir name="SalesRule"><file name="Validator.php" hash="96deaaaff346601ab0c1406331312228"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Promo"><file name="QuoteController.php" hash="630cf0a5e3daa42a1f1b32edb6378197"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="1932d41ed30fcaf19010e0b350d1691e"/></dir><dir name="sql"><dir name="couponcode_setup"><file name="mysql4-install-0.1.0.php" hash="dcaebeba905eb8719f5e218fd91e8794"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Multidiscount_Couponcode.xml" hash="c30e1bd8c3f55c2710f2aa2f360c98f0"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="promo"><file name="options.phtml" hash="e4c1e842aebb019393c87e77ffe6e800"/></dir></dir></dir></dir></dir></target></contents>
25
  <compatible/>
26
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
27
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Multidiscount_Couponcode</name>
4
+ <version>0.1.4</version>
5
  <stability>stable</stability>
6
  <license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
  <channel>community</channel>
17
  and so on.&#xD;
18
  &#xD;
19
  You just need to create a single coupon code and need to add from what amount to what amount how much discount you want to provide.</description>
20
+ <notes>fixing multiple products issue</notes>
21
  <authors><author><name>Kingshuk deb</name><user>kingshukdeb</user><email>kingshukdeb88@gmail.com</email></author></authors>
22
+ <date>2016-06-22</date>
23
+ <time>11:53:51</time>
24
+ <contents><target name="magelocal"><dir name="Multidiscount"><dir name="Couponcode"><dir name="Block"><dir name="Adminhtml"><dir name="Promo"><dir name="Quote"><dir name="Edit"><file name="Options.php" hash="b251dd1751fb49adaa0143fe63b357e4"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="16e670874b16e6ea0f0a318fbae54c05"/></dir><dir name="Model"><file name="Observer.php" hash="cc58c72bed15cd57dedf24e0e64cf22d"/><file name="Percentconst.php" hash="c566016651e421e291039314231e1eb1"/><dir name="SalesRule"><file name="Validator.php" hash="f0891f61c7ff06696ed713569a7a75f1"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Promo"><file name="QuoteController.php" hash="630cf0a5e3daa42a1f1b32edb6378197"/></dir></dir></dir><dir name="etc"><file name="config.xml" hash="1932d41ed30fcaf19010e0b350d1691e"/></dir><dir name="sql"><dir name="couponcode_setup"><file name="mysql4-install-0.1.0.php" hash="dcaebeba905eb8719f5e218fd91e8794"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Multidiscount_Couponcode.xml" hash="c30e1bd8c3f55c2710f2aa2f360c98f0"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="promo"><file name="options.phtml" hash="e4c1e842aebb019393c87e77ffe6e800"/></dir></dir></dir></dir></dir></target></contents>
25
  <compatible/>
26
  <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
27
  </package>