Version Notes
fixing admin JS issue
Download this release
Release Info
Developer | Kingshuk deb |
Extension | multidiscount |
Version | 0.1.9 |
Comparing to | |
See all releases |
Code changes from version 0.1.5 to 0.1.9
app/code/local/Multidiscount/Couponcode/Model/SalesRule/Validator.php
CHANGED
@@ -1,5 +1,90 @@
|
|
1 |
<?php
|
2 |
class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_Model_Validator{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
/**
|
4 |
* Quote item discount calculation process
|
5 |
*
|
@@ -149,15 +234,9 @@ class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_
|
|
149 |
}
|
150 |
}
|
151 |
$cartRules = $address->getCartFixedRules();
|
152 |
-
|
153 |
-
$
|
154 |
-
$
|
155 |
-
foreach($percentageData as $eachData){
|
156 |
-
if($eachData['from'] < $quoteAmount && $quoteAmount <= $eachData['to']){
|
157 |
-
$discountAmount = ($eachData['discount']*$quoteAmount)/100;
|
158 |
-
$discountAmount = $quote->getStore()->roundPrice($discountAmount);
|
159 |
-
}
|
160 |
-
}
|
161 |
|
162 |
$cartRules = $address->getCartFixedRules();
|
163 |
if (!isset($cartRules[$rule->getId()])) {
|
@@ -337,5 +416,33 @@ class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_
|
|
337 |
$this->_stopFurtherRules = false;
|
338 |
return $this;
|
339 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
}
|
341 |
|
1 |
<?php
|
2 |
class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_Model_Validator{
|
3 |
+
|
4 |
+
|
5 |
+
protected $_percentDiscountAmount;
|
6 |
+
/**
|
7 |
+
* Check if rule can be applied for specific address/quote/customer
|
8 |
+
*
|
9 |
+
* @param Mage_SalesRule_Model_Rule $rule
|
10 |
+
* @param Mage_Sales_Model_Quote_Address $address
|
11 |
+
* @return bool
|
12 |
+
*/
|
13 |
+
protected function _canProcessRule($rule, $address)
|
14 |
+
{
|
15 |
+
if ($rule->hasIsValidForAddress($address) && !$address->isObjectNew()) {
|
16 |
+
return $rule->getIsValidForAddress($address);
|
17 |
+
}
|
18 |
+
|
19 |
+
/**
|
20 |
+
* check per coupon usage limit
|
21 |
+
*/
|
22 |
+
if ($rule->getCouponType() != Mage_SalesRule_Model_Rule::COUPON_TYPE_NO_COUPON) {
|
23 |
+
$couponCode = $address->getQuote()->getCouponCode();
|
24 |
+
if (strlen($couponCode)) {
|
25 |
+
$coupon = Mage::getModel('salesrule/coupon');
|
26 |
+
$coupon->load($couponCode, 'code');
|
27 |
+
if ($coupon->getId()) {
|
28 |
+
// check entire usage limit
|
29 |
+
if ($coupon->getUsageLimit() && $coupon->getTimesUsed() >= $coupon->getUsageLimit()) {
|
30 |
+
$rule->setIsValidForAddress($address, false);
|
31 |
+
return false;
|
32 |
+
}
|
33 |
+
// check per customer usage limit
|
34 |
+
$customerId = $address->getQuote()->getCustomerId();
|
35 |
+
if ($customerId && $coupon->getUsagePerCustomer()) {
|
36 |
+
$couponUsage = new Varien_Object();
|
37 |
+
Mage::getResourceModel('salesrule/coupon_usage')->loadByCustomerCoupon(
|
38 |
+
$couponUsage, $customerId, $coupon->getId());
|
39 |
+
if ($couponUsage->getCouponId() &&
|
40 |
+
$couponUsage->getTimesUsed() >= $coupon->getUsagePerCustomer()
|
41 |
+
) {
|
42 |
+
$rule->setIsValidForAddress($address, false);
|
43 |
+
return false;
|
44 |
+
}
|
45 |
+
}
|
46 |
+
|
47 |
+
if($rule->getSimpleAction()=='cart_percent'){
|
48 |
+
$quoteAmount = $this->_getQuoteAmount();
|
49 |
+
$this->_getPercentAmount($quoteAmount,$rule);
|
50 |
+
if(!isset($this->_percentDiscountAmount)){
|
51 |
+
return false;
|
52 |
+
}
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* check per rule usage limit
|
60 |
+
*/
|
61 |
+
$ruleId = $rule->getId();
|
62 |
+
if ($ruleId && $rule->getUsesPerCustomer()) {
|
63 |
+
$customerId = $address->getQuote()->getCustomerId();
|
64 |
+
$ruleCustomer = Mage::getModel('salesrule/rule_customer');
|
65 |
+
$ruleCustomer->loadByCustomerRule($customerId, $ruleId);
|
66 |
+
if ($ruleCustomer->getId()) {
|
67 |
+
if ($ruleCustomer->getTimesUsed() >= $rule->getUsesPerCustomer()) {
|
68 |
+
$rule->setIsValidForAddress($address, false);
|
69 |
+
return false;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
}
|
73 |
+
$rule->afterLoad();
|
74 |
+
/**
|
75 |
+
* quote does not meet rule's conditions
|
76 |
+
*/
|
77 |
+
if (!$rule->validate($address)) {
|
78 |
+
$rule->setIsValidForAddress($address, false);
|
79 |
+
return false;
|
80 |
+
}
|
81 |
+
/**
|
82 |
+
* passed all validations, remember to be valid
|
83 |
+
*/
|
84 |
+
$rule->setIsValidForAddress($address, true);
|
85 |
+
return true;
|
86 |
+
}
|
87 |
+
|
88 |
/**
|
89 |
* Quote item discount calculation process
|
90 |
*
|
234 |
}
|
235 |
}
|
236 |
$cartRules = $address->getCartFixedRules();
|
237 |
+
|
238 |
+
$quoteAmount = $this->_getQuoteAmount();
|
239 |
+
$discountAmount = $this->_getPercentAmount($quoteAmount,$rule);
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
|
241 |
$cartRules = $address->getCartFixedRules();
|
242 |
if (!isset($cartRules[$rule->getId()])) {
|
416 |
$this->_stopFurtherRules = false;
|
417 |
return $this;
|
418 |
}
|
419 |
+
|
420 |
+
protected function _getPercentAmount($quoteAmount,$rule)
|
421 |
+
{
|
422 |
+
if(isset($this->_percentDiscountAmount)){
|
423 |
+
return $this->_percentDiscountAmount;
|
424 |
+
}else{
|
425 |
+
$percentageData = unserialize($rule->getCartpercentSerialized());
|
426 |
+
foreach($percentageData as $eachData){
|
427 |
+
if($eachData['from'] < $quoteAmount && $quoteAmount <= $eachData['to']){
|
428 |
+
$this->_percentDiscountAmount = ($eachData['discount']*$quoteAmount)/100;
|
429 |
+
$this->_percentDiscountAmount = Mage::app()->getStore()->roundPrice($this->_percentDiscountAmount);
|
430 |
+
}
|
431 |
+
}
|
432 |
+
}
|
433 |
+
}
|
434 |
+
|
435 |
+
protected function _getQuoteAmount(){
|
436 |
+
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
|
437 |
+
return $totals["subtotal"]->getValue();
|
438 |
+
}
|
439 |
+
|
440 |
+
protected function _getItemQty($item, $rule)
|
441 |
+
{
|
442 |
+
$qty = $item->getTotalQty();
|
443 |
+
if($rule->getSimpleAction()=='cart_percent'){
|
444 |
+
return $qty;
|
445 |
+
} else return $rule->getDiscountQty() ? min($qty, $rule->getDiscountQty()) : $qty;
|
446 |
+
}
|
447 |
}
|
448 |
|
app/design/adminhtml/default/default/template/promo/options.phtml
CHANGED
@@ -108,7 +108,11 @@ var nameArr = [];
|
|
108 |
}
|
109 |
}
|
110 |
);
|
111 |
-
|
|
|
|
|
|
|
|
|
112 |
|
113 |
var attributeOption = {
|
114 |
table : $('options-table'),
|
108 |
}
|
109 |
}
|
110 |
);
|
111 |
+
if (nameArr.length) {
|
112 |
+
maxNumber = Math.max.apply(Math, nameArr);
|
113 |
+
} else {
|
114 |
+
maxNumber = 0;
|
115 |
+
}
|
116 |
|
117 |
var attributeOption = {
|
118 |
table : $('options-table'),
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
-
<name>
|
4 |
-
<version>0.1.
|
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 
|
|
17 |
and so on.
|
18 |

|
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
|
21 |
<authors><author><name>Kingshuk deb</name><user>kingshukdeb</user><email>kingshukdeb88@gmail.com</email></author></authors>
|
22 |
-
<date>2016-
|
23 |
-
<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="
|
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</name>
|
4 |
+
<version>0.1.9</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.
|
18 |

|
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 admin JS issue</notes>
|
21 |
<authors><author><name>Kingshuk deb</name><user>kingshukdeb</user><email>kingshukdeb88@gmail.com</email></author></authors>
|
22 |
+
<date>2016-09-12</date>
|
23 |
+
<time>04:24:14</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="0c927d0bcf6887e0c95d2570ce3eac1f"/></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="2f85eb9fd93ae7f19b48e693b2f43040"/></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>
|