Version Notes
Adding Validator model override
Download this release
Release Info
| Developer | Kingshuk deb |
| Extension | multidiscount |
| Version | 0.1.2 |
| Comparing to | |
| See all releases | |
Code changes from version 0.1.1 to 0.1.2
app/code/local/Multidiscount/Couponcode/Model/SalesRule/Validator.php
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
class Multidiscount_Couponcode_Model_SalesRule_Validator extends Mage_SalesRule_Model_Validator{
|
| 3 |
+
/**
|
| 4 |
+
* Quote item discount calculation process
|
| 5 |
+
*
|
| 6 |
+
* @param Mage_Sales_Model_Quote_Item_Abstract $item
|
| 7 |
+
* @return Mage_SalesRule_Model_Validator
|
| 8 |
+
*/
|
| 9 |
+
public function process(Mage_Sales_Model_Quote_Item_Abstract $item)
|
| 10 |
+
{
|
| 11 |
+
$item->setDiscountAmount(0);
|
| 12 |
+
$item->setBaseDiscountAmount(0);
|
| 13 |
+
$item->setDiscountPercent(0);
|
| 14 |
+
$quote = $item->getQuote();
|
| 15 |
+
$address = $this->_getAddress($item);
|
| 16 |
+
|
| 17 |
+
$itemPrice = $this->_getItemPrice($item);
|
| 18 |
+
$baseItemPrice = $this->_getItemBasePrice($item);
|
| 19 |
+
$itemOriginalPrice = $this->_getItemOriginalPrice($item);
|
| 20 |
+
$baseItemOriginalPrice = $this->_getItemBaseOriginalPrice($item);
|
| 21 |
+
|
| 22 |
+
if ($itemPrice < 0) {
|
| 23 |
+
return $this;
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
$appliedRuleIds = array();
|
| 27 |
+
$this->_stopFurtherRules = false;
|
| 28 |
+
foreach ($this->_getRules() as $rule) {
|
| 29 |
+
|
| 30 |
+
/* @var $rule Mage_SalesRule_Model_Rule */
|
| 31 |
+
if (!$this->_canProcessRule($rule, $address)) {
|
| 32 |
+
continue;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
if (!$rule->getActions()->validate($item)) {
|
| 36 |
+
continue;
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
$qty = $this->_getItemQty($item, $rule);
|
| 40 |
+
$rulePercent = min(100, $rule->getDiscountAmount());
|
| 41 |
+
|
| 42 |
+
$discountAmount = 0;
|
| 43 |
+
$baseDiscountAmount = 0;
|
| 44 |
+
//discount for original price
|
| 45 |
+
$originalDiscountAmount = 0;
|
| 46 |
+
$baseOriginalDiscountAmount = 0;
|
| 47 |
+
|
| 48 |
+
switch ($rule->getSimpleAction()) {
|
| 49 |
+
case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION:
|
| 50 |
+
$rulePercent = max(0, 100-$rule->getDiscountAmount());
|
| 51 |
+
//no break;
|
| 52 |
+
case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION:
|
| 53 |
+
$step = $rule->getDiscountStep();
|
| 54 |
+
if ($step) {
|
| 55 |
+
$qty = floor($qty/$step)*$step;
|
| 56 |
+
}
|
| 57 |
+
$_rulePct = $rulePercent/100;
|
| 58 |
+
$discountAmount = ($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct;
|
| 59 |
+
$baseDiscountAmount = ($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct;
|
| 60 |
+
//get discount for original price
|
| 61 |
+
$originalDiscountAmount = ($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
|
| 62 |
+
$baseOriginalDiscountAmount =
|
| 63 |
+
($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
|
| 64 |
+
|
| 65 |
+
if (!$rule->getDiscountQty() || $rule->getDiscountQty()>$qty) {
|
| 66 |
+
$discountPercent = min(100, $item->getDiscountPercent()+$rulePercent);
|
| 67 |
+
$item->setDiscountPercent($discountPercent);
|
| 68 |
+
}
|
| 69 |
+
break;
|
| 70 |
+
case Mage_SalesRule_Model_Rule::TO_FIXED_ACTION:
|
| 71 |
+
$quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
|
| 72 |
+
$discountAmount = $qty * ($itemPrice-$quoteAmount);
|
| 73 |
+
$baseDiscountAmount = $qty * ($baseItemPrice-$rule->getDiscountAmount());
|
| 74 |
+
//get discount for original price
|
| 75 |
+
$originalDiscountAmount = $qty * ($itemOriginalPrice-$quoteAmount);
|
| 76 |
+
$baseOriginalDiscountAmount = $qty * ($baseItemOriginalPrice-$rule->getDiscountAmount());
|
| 77 |
+
break;
|
| 78 |
+
|
| 79 |
+
case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION:
|
| 80 |
+
$step = $rule->getDiscountStep();
|
| 81 |
+
if ($step) {
|
| 82 |
+
$qty = floor($qty/$step)*$step;
|
| 83 |
+
}
|
| 84 |
+
$quoteAmount = $quote->getStore()->convertPrice($rule->getDiscountAmount());
|
| 85 |
+
$discountAmount = $qty * $quoteAmount;
|
| 86 |
+
$baseDiscountAmount = $qty * $rule->getDiscountAmount();
|
| 87 |
+
break;
|
| 88 |
+
|
| 89 |
+
case Mage_SalesRule_Model_Rule::CART_FIXED_ACTION:
|
| 90 |
+
if (empty($this->_rulesItemTotals[$rule->getId()])) {
|
| 91 |
+
Mage::throwException(Mage::helper('salesrule')->__('Item totals are not set for rule.'));
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
/**
|
| 95 |
+
* prevent applying whole cart discount for every shipping order, but only for first order
|
| 96 |
+
*/
|
| 97 |
+
if ($quote->getIsMultiShipping()) {
|
| 98 |
+
$usedForAddressId = $this->getCartFixedRuleUsedForAddress($rule->getId());
|
| 99 |
+
if ($usedForAddressId && $usedForAddressId != $address->getId()) {
|
| 100 |
+
break;
|
| 101 |
+
} else {
|
| 102 |
+
$this->setCartFixedRuleUsedForAddress($rule->getId(), $address->getId());
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
$cartRules = $address->getCartFixedRules();
|
| 106 |
+
if (!isset($cartRules[$rule->getId()])) {
|
| 107 |
+
$cartRules[$rule->getId()] = $rule->getDiscountAmount();
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
if ($cartRules[$rule->getId()] > 0) {
|
| 111 |
+
if ($this->_rulesItemTotals[$rule->getId()]['items_count'] <= 1) {
|
| 112 |
+
$quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]);
|
| 113 |
+
$baseDiscountAmount = min($baseItemPrice * $qty, $cartRules[$rule->getId()]);
|
| 114 |
+
} else {
|
| 115 |
+
$discountRate = $baseItemPrice * $qty /
|
| 116 |
+
$this->_rulesItemTotals[$rule->getId()]['base_items_price'];
|
| 117 |
+
$maximumItemDiscount = $rule->getDiscountAmount() * $discountRate;
|
| 118 |
+
$quoteAmount = $quote->getStore()->convertPrice($maximumItemDiscount);
|
| 119 |
+
|
| 120 |
+
$baseDiscountAmount = min($baseItemPrice * $qty, $maximumItemDiscount);
|
| 121 |
+
$this->_rulesItemTotals[$rule->getId()]['items_count']--;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
$discountAmount = min($itemPrice * $qty, $quoteAmount);
|
| 125 |
+
$discountAmount = $quote->getStore()->roundPrice($discountAmount);
|
| 126 |
+
$baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
|
| 127 |
+
|
| 128 |
+
//get discount for original price
|
| 129 |
+
$originalDiscountAmount = min($itemOriginalPrice * $qty, $quoteAmount);
|
| 130 |
+
$baseOriginalDiscountAmount = $quote->getStore()->roundPrice($baseItemOriginalPrice);
|
| 131 |
+
|
| 132 |
+
$cartRules[$rule->getId()] -= $baseDiscountAmount;
|
| 133 |
+
}
|
| 134 |
+
$address->setCartFixedRules($cartRules);
|
| 135 |
+
|
| 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();
|
| 142 |
+
foreach($percentageData as $eachData){
|
| 143 |
+
if($eachData['from'] < $quoteAmount && $quoteAmount <= $eachData['to']){
|
| 144 |
+
$discountAmount = ($eachData['discount']*$quoteAmount)/100;
|
| 145 |
+
$discountAmount = $quote->getStore()->roundPrice($discountAmount);
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
break;
|
| 149 |
+
|
| 150 |
+
case Mage_SalesRule_Model_Rule::BUY_X_GET_Y_ACTION:
|
| 151 |
+
$x = $rule->getDiscountStep();
|
| 152 |
+
$y = $rule->getDiscountAmount();
|
| 153 |
+
if (!$x || $y > $x) {
|
| 154 |
+
break;
|
| 155 |
+
}
|
| 156 |
+
$buyAndDiscountQty = $x + $y;
|
| 157 |
+
|
| 158 |
+
$fullRuleQtyPeriod = floor($qty / $buyAndDiscountQty);
|
| 159 |
+
$freeQty = $qty - $fullRuleQtyPeriod * $buyAndDiscountQty;
|
| 160 |
+
|
| 161 |
+
$discountQty = $fullRuleQtyPeriod * $y;
|
| 162 |
+
if ($freeQty > $x) {
|
| 163 |
+
$discountQty += $freeQty - $x;
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
$discountAmount = $discountQty * $itemPrice;
|
| 167 |
+
$baseDiscountAmount = $discountQty * $baseItemPrice;
|
| 168 |
+
//get discount for original price
|
| 169 |
+
$originalDiscountAmount = $discountQty * $itemOriginalPrice;
|
| 170 |
+
$baseOriginalDiscountAmount = $discountQty * $baseItemOriginalPrice;
|
| 171 |
+
break;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
$result = new Varien_Object(array(
|
| 175 |
+
'discount_amount' => $discountAmount,
|
| 176 |
+
'base_discount_amount' => $baseDiscountAmount,
|
| 177 |
+
));
|
| 178 |
+
Mage::dispatchEvent('salesrule_validator_process', array(
|
| 179 |
+
'rule' => $rule,
|
| 180 |
+
'item' => $item,
|
| 181 |
+
'address' => $address,
|
| 182 |
+
'quote' => $quote,
|
| 183 |
+
'qty' => $qty,
|
| 184 |
+
'result' => $result,
|
| 185 |
+
));
|
| 186 |
+
|
| 187 |
+
$discountAmount = $result->getDiscountAmount();
|
| 188 |
+
$baseDiscountAmount = $result->getBaseDiscountAmount();
|
| 189 |
+
|
| 190 |
+
$percentKey = $item->getDiscountPercent();
|
| 191 |
+
/**
|
| 192 |
+
* Process "delta" rounding
|
| 193 |
+
*/
|
| 194 |
+
if ($percentKey) {
|
| 195 |
+
$delta = isset($this->_roundingDeltas[$percentKey]) ? $this->_roundingDeltas[$percentKey] : 0;
|
| 196 |
+
$baseDelta = isset($this->_baseRoundingDeltas[$percentKey])
|
| 197 |
+
? $this->_baseRoundingDeltas[$percentKey]
|
| 198 |
+
: 0;
|
| 199 |
+
$discountAmount += $delta;
|
| 200 |
+
$baseDiscountAmount += $baseDelta;
|
| 201 |
+
|
| 202 |
+
$this->_roundingDeltas[$percentKey] = $discountAmount -
|
| 203 |
+
$quote->getStore()->roundPrice($discountAmount);
|
| 204 |
+
$this->_baseRoundingDeltas[$percentKey] = $baseDiscountAmount -
|
| 205 |
+
$quote->getStore()->roundPrice($baseDiscountAmount);
|
| 206 |
+
$discountAmount = $quote->getStore()->roundPrice($discountAmount);
|
| 207 |
+
$baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
|
| 208 |
+
} else {
|
| 209 |
+
$discountAmount = $quote->getStore()->roundPrice($discountAmount);
|
| 210 |
+
$baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
/**
|
| 214 |
+
* We can't use row total here because row total not include tax
|
| 215 |
+
* Discount can be applied on price included tax
|
| 216 |
+
*/
|
| 217 |
+
|
| 218 |
+
$itemDiscountAmount = $item->getDiscountAmount();
|
| 219 |
+
$itemBaseDiscountAmount = $item->getBaseDiscountAmount();
|
| 220 |
+
|
| 221 |
+
$discountAmount = min($itemDiscountAmount + $discountAmount, $itemPrice * $qty);
|
| 222 |
+
$baseDiscountAmount = min($itemBaseDiscountAmount + $baseDiscountAmount, $baseItemPrice * $qty);
|
| 223 |
+
|
| 224 |
+
$item->setDiscountAmount($discountAmount);
|
| 225 |
+
$item->setBaseDiscountAmount($baseDiscountAmount);
|
| 226 |
+
|
| 227 |
+
$item->setOriginalDiscountAmount($originalDiscountAmount);
|
| 228 |
+
$item->setBaseOriginalDiscountAmount($baseOriginalDiscountAmount);
|
| 229 |
+
|
| 230 |
+
$appliedRuleIds[$rule->getRuleId()] = $rule->getRuleId();
|
| 231 |
+
|
| 232 |
+
$this->_maintainAddressCouponCode($address, $rule);
|
| 233 |
+
$this->_addDiscountDescription($address, $rule);
|
| 234 |
+
|
| 235 |
+
if ($rule->getStopRulesProcessing()) {
|
| 236 |
+
$this->_stopFurtherRules = true;
|
| 237 |
+
break;
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
$item->setAppliedRuleIds(join(',',$appliedRuleIds));
|
| 242 |
+
$address->setAppliedRuleIds($this->mergeIds($address->getAppliedRuleIds(), $appliedRuleIds));
|
| 243 |
+
$quote->setAppliedRuleIds($this->mergeIds($quote->getAppliedRuleIds(), $appliedRuleIds));
|
| 244 |
+
|
| 245 |
+
return $this;
|
| 246 |
+
}
|
| 247 |
+
}
|
| 248 |
+
|
app/code/local/Multidiscount/Couponcode/etc/config.xml
CHANGED
|
@@ -14,7 +14,12 @@
|
|
| 14 |
<models>
|
| 15 |
<couponcode>
|
| 16 |
<class>Multidiscount_Couponcode_Model</class>
|
| 17 |
-
</couponcode>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
</models>
|
| 19 |
<helpers>
|
| 20 |
<couponcode>
|
| 14 |
<models>
|
| 15 |
<couponcode>
|
| 16 |
<class>Multidiscount_Couponcode_Model</class>
|
| 17 |
+
</couponcode>
|
| 18 |
+
<salesrule>
|
| 19 |
+
<rewrite>
|
| 20 |
+
<validator>Multidiscount_Couponcode_Model_SalesRule_Validator</validator>
|
| 21 |
+
</rewrite>
|
| 22 |
+
</salesrule>
|
| 23 |
</models>
|
| 24 |
<helpers>
|
| 25 |
<couponcode>
|
app/design/adminhtml/default/default/template/promo/options.phtml
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?php
|
| 2 |
+
/**
|
| 3 |
+
* Magento
|
| 4 |
+
*
|
| 5 |
+
* NOTICE OF LICENSE
|
| 6 |
+
*
|
| 7 |
+
* This source file is subject to the Academic Free License (AFL 3.0)
|
| 8 |
+
* that is bundled with this package in the file LICENSE_AFL.txt.
|
| 9 |
+
* It is also available through the world-wide-web at this URL:
|
| 10 |
+
* http://opensource.org/licenses/afl-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 design
|
| 22 |
+
* @package default_default
|
| 23 |
+
* @copyright Copyright (c) 2013 Magento Inc. (http://www.magentocommerce.com)
|
| 24 |
+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
| 25 |
+
*/
|
| 26 |
+
?>
|
| 27 |
+
<?php
|
| 28 |
+
/**
|
| 29 |
+
* Attribute options control
|
| 30 |
+
*
|
| 31 |
+
* @see Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
|
| 32 |
+
* @var $this Mage_Eav_Block_Adminhtml_Attribute_Edit_Options_Abstract
|
| 33 |
+
*/
|
| 34 |
+
?>
|
| 35 |
+
</tbody></table>
|
| 36 |
+
<div class="entity-edit" id="matage-options-panel">
|
| 37 |
+
<div class="hor-scroll">
|
| 38 |
+
<table class="dynamic-grid" cellspacing="0" cellpadding="0">
|
| 39 |
+
<tr id="options-table">
|
| 40 |
+
<?php //foreach ($this->getStores() as $_store): ?>
|
| 41 |
+
<th><?php echo 'From' ?></th>
|
| 42 |
+
<th><?php echo 'To' ?></th>
|
| 43 |
+
<th><?php echo 'Discount' ?></th>
|
| 44 |
+
<?php //endforeach; ?>
|
| 45 |
+
<th>
|
| 46 |
+
<?php if (!$this->getReadOnly()):?>
|
| 47 |
+
<?php echo $this->getAddNewButtonHtml() ?>
|
| 48 |
+
<?php endif;?>
|
| 49 |
+
</th>
|
| 50 |
+
</tr>
|
| 51 |
+
<?php foreach ($this->getOptionsData() as $_optionData=>$_option): //print_r($_option['from']); ?>
|
| 52 |
+
<tr class="option-row">
|
| 53 |
+
<td><input name="option[value][<?php echo $_optionData ?>][<?php echo 'from' ?>]"
|
| 54 |
+
value="<?php echo $_option['from'] ?>" class="input-text" type="text"/></td>
|
| 55 |
+
<td><input name="option[value][<?php echo $_optionData ?>][<?php echo 'to' ?>]"
|
| 56 |
+
value="<?php echo $_option['to'] ?>" class="input-text" type="text"/></td>
|
| 57 |
+
<td><input name="option[value][<?php echo $_optionData ?>][<?php echo 'discount' ?>]"
|
| 58 |
+
value="<?php echo $_option['discount'] ?>" class="input-text" type="text"/></td>
|
| 59 |
+
<td class="a-left">
|
| 60 |
+
<input type="hidden" class="delete-flag" name="option[delete][<?php echo $_optionData ?>]" value="" />
|
| 61 |
+
<?php if (!$this->getReadOnly()):?>
|
| 62 |
+
<?php echo $this->getDeleteButtonHtml() ?>
|
| 63 |
+
<?php endif;?>
|
| 64 |
+
</td>
|
| 65 |
+
</tr>
|
| 66 |
+
<?php endforeach; ?>
|
| 67 |
+
</table>
|
| 68 |
+
</div>
|
| 69 |
+
<input type="hidden" id="option-count-check" value="" />
|
| 70 |
+
</div>
|
| 71 |
+
<script type="text/javascript">
|
| 72 |
+
//<![CDATA[
|
| 73 |
+
var optionDefaultInputType = 'radio';
|
| 74 |
+
|
| 75 |
+
// IE removes quotes from element.innerHTML whenever it thinks they're not needed, which breaks html.
|
| 76 |
+
var templateText =
|
| 77 |
+
'<tr class="option-row">'+
|
| 78 |
+
<?php //foreach ($this->getStores() as $_store): ?>
|
| 79 |
+
'<td><input name="option[value][{{id}}][<?php echo "from" ?>]" value="{{store<?php echo "from" ?>}}" class="input-text" type="text"/><\/td>'+
|
| 80 |
+
|
| 81 |
+
'<td><input name="option[value][{{id}}][<?php echo "to" ?>]" value="{{store<?php echo "to" ?>}}" class="input-text" type="text"/><\/td>'+
|
| 82 |
+
|
| 83 |
+
'<td><input name="option[value][{{id}}][<?php echo "discount" ?>]" value="{{store<?php echo "discount" ?>}}" class="input-text" type="text"/><\/td>'+
|
| 84 |
+
<?php //endforeach; ?>
|
| 85 |
+
'<td class="a-left" id="delete_button_container_{{id}}">'+
|
| 86 |
+
'<input type="hidden" class="delete-flag" name="option[delete][{{id}}]" value="" />'+
|
| 87 |
+
<?php if (!$this->getReadOnly()):?>
|
| 88 |
+
'<?php echo $this->getDeleteButtonHtml() ?>'+
|
| 89 |
+
<?php endif;?>
|
| 90 |
+
'<\/td>'+
|
| 91 |
+
'<\/tr>';
|
| 92 |
+
|
| 93 |
+
var attributeOption = {
|
| 94 |
+
table : $('options-table'),
|
| 95 |
+
templateSyntax : /(^|.|\r|\n)({{(\w+)}})/,
|
| 96 |
+
templateText : templateText,
|
| 97 |
+
itemCount : <?php echo count($this->getOptionsData()); ?>,
|
| 98 |
+
totalItems : 0,
|
| 99 |
+
isReadOnly: <?php echo (int)$this->getReadOnly(); ?>,
|
| 100 |
+
add : function(data) {
|
| 101 |
+
this.template = new Template(this.templateText, this.templateSyntax);
|
| 102 |
+
var isNewOption = false;
|
| 103 |
+
if(!data.id){
|
| 104 |
+
data = {};
|
| 105 |
+
data.id = 'option_'+this.itemCount;
|
| 106 |
+
var x = document.getElementsByName("option[value]["+data.id+"][from]").length;
|
| 107 |
+
if(x){
|
| 108 |
+
this.itemCount++;
|
| 109 |
+
data.id = 'option_'+this.itemCount;
|
| 110 |
+
}
|
| 111 |
+
isNewOption = true;
|
| 112 |
+
}
|
| 113 |
+
if (!data.intype)
|
| 114 |
+
data.intype = optionDefaultInputType;
|
| 115 |
+
Element.insert(this.table, {after: this.template.evaluate(data)});
|
| 116 |
+
if (isNewOption && !this.isReadOnly) {
|
| 117 |
+
this.enableNewOptionDeleteButton(data.id);
|
| 118 |
+
}
|
| 119 |
+
this.bindRemoveButtons();
|
| 120 |
+
this.itemCount++;
|
| 121 |
+
this.totalItems++;
|
| 122 |
+
this.updateItemsCountField();
|
| 123 |
+
},
|
| 124 |
+
remove : function(event){
|
| 125 |
+
var element = $(Event.findElement(event, 'tr')); // !!! Button already
|
| 126 |
+
// have table parent in safari
|
| 127 |
+
// Safari workaround
|
| 128 |
+
element.ancestors().each(function(parentItem){
|
| 129 |
+
if (parentItem.hasClassName('option-row')) {
|
| 130 |
+
element = parentItem;
|
| 131 |
+
throw $break;
|
| 132 |
+
} else if (parentItem.hasClassName('box')) {
|
| 133 |
+
throw $break;
|
| 134 |
+
}
|
| 135 |
+
});
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
if(element){
|
| 139 |
+
var elementFlags = element.getElementsByClassName('delete-flag');
|
| 140 |
+
if(elementFlags[0]){
|
| 141 |
+
elementFlags[0].value=1;
|
| 142 |
+
}
|
| 143 |
+
|
| 144 |
+
element.addClassName('no-display');
|
| 145 |
+
element.addClassName('template');
|
| 146 |
+
element.remove();
|
| 147 |
+
this.totalItems--;
|
| 148 |
+
this.updateItemsCountField();
|
| 149 |
+
}
|
| 150 |
+
},
|
| 151 |
+
updateItemsCountField: function() {
|
| 152 |
+
if (this.totalItems > 0) {
|
| 153 |
+
$('option-count-check').value = '1';
|
| 154 |
+
} else {
|
| 155 |
+
$('option-count-check').value = '';
|
| 156 |
+
}
|
| 157 |
+
},
|
| 158 |
+
enableNewOptionDeleteButton: function(id) {
|
| 159 |
+
$$('#delete_button_container_' + id + ' button').each(function(button) {
|
| 160 |
+
button.enable();
|
| 161 |
+
button.removeClassName('disabled');
|
| 162 |
+
});
|
| 163 |
+
},
|
| 164 |
+
bindRemoveButtons : function(){
|
| 165 |
+
var buttons = $$('.delete-option');
|
| 166 |
+
for(var i=0;i<buttons.length;i++){
|
| 167 |
+
if(!$(buttons[i]).binded){
|
| 168 |
+
$(buttons[i]).binded = true;
|
| 169 |
+
Event.observe(buttons[i], 'click', this.remove.bind(this));
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
}
|
| 175 |
+
if($('row-template')){
|
| 176 |
+
$('row-template').remove();
|
| 177 |
+
}
|
| 178 |
+
attributeOption.bindRemoveButtons();
|
| 179 |
+
|
| 180 |
+
if($('add_new_option_button')){
|
| 181 |
+
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption));
|
| 182 |
+
}
|
| 183 |
+
Validation.addAllThese([
|
| 184 |
+
['required-option', '<?php echo $this->__('Failed') ?>', function(v) {
|
| 185 |
+
return !Validation.get('IsEmpty').test(v);
|
| 186 |
+
}]]);
|
| 187 |
+
Validation.addAllThese([
|
| 188 |
+
['required-options-count', '<?php echo $this->__('Options is required') ?>', function(v) {
|
| 189 |
+
return !Validation.get('IsEmpty').test(v);
|
| 190 |
+
}]]);
|
| 191 |
+
//]]>
|
| 192 |
+
</script>
|
package.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Multidiscount_Couponcode</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>
|
| 21 |
<authors><author><name>Kingshuk deb</name><user>kingshukdeb</user><email>kingshukdeb88@gmail.com</email></author></authors>
|
| 22 |
-
<date>2016-06-
|
| 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><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="
|
| 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.2</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>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-14</date>
|
| 23 |
+
<time>06:26:57</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="df9eba917c2aa3d7dd41513c39d55337"/></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>
|
