1
votes

I've got this problem that I can't solve. Partly because I can't explain it with the right terms. I'm new to this so sorry for this clumsy question.

Below you can see an overview of my goal.

I'm using Magento CE 1.8.1.0

How do i override the Shopping Cart Price Rule.

enter image description here In core files app/code/core/Mage/SalesRule/Model/Validator.php in this file Default Code they written. Line 331 to 349 code is here.

$step = $rule->getDiscountStep();
if ($step) {
    $qty = floor($qty/$step)*$step;
}
$_rulePct = $rulePercent/100;
$discountAmount    = ($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct;
$baseDiscountAmount = ($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct;
//get discount for original price
$originalDiscountAmount    = ($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
$baseOriginalDiscountAmount = ($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
if (!$rule->getDiscountQty() || $rule->getDiscountQty()>$qty) {
    $discountPercent = min(100, $item->getDiscountPercent()+$rulePercent);
    $item->setDiscountPercent($discountPercent);
}

This code i want to Edit like this

$step = $rule->getDiscountStep();
if ($step) {
    $qty = floor($qty/$step)*$step;
}
$_rulePct = $rulePercent/100;
$discountAmount    = ($qty * $itemPrice - $item->getDiscountAmount()) * $_rulePct;
$baseDiscountAmount = ($qty * $baseItemPrice - $item->getBaseDiscountAmount()) * $_rulePct;
//get discount for original price
$originalDiscountAmount    = ($qty * $itemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
$maxlimitamount = 1000; // maximum amount entered in admin panel
if($originalDiscountAmount > $maxlimitamount)
{
    $originalDiscountAmount = 1000;
}
$baseOriginalDiscountAmount = ($qty * $baseItemOriginalPrice - $item->getDiscountAmount()) * $_rulePct;
if (!$rule->getDiscountQty() || $rule->getDiscountQty()>$qty) {
    $discountPercent = min(100, $item->getDiscountPercent()+$rulePercent);
    $item->setDiscountPercent($discountPercent);
}

My Custom Module config.xml

<global>
        <models>
            <salesrule_resource>
                <rewrite>     
                    <rule_collection>SCPR_Pricerule_Model_Resource_Rule_Collection</rule_collection>
                </rewrite>
            </salesrule_resource>
        </models> 
</global>

How do i achieve this ?

Any Ideas ?

1
Can't you do that by default using the Conditions tab?Samuel Coman
@SamuelComan Yes thats why i want to override only " Percent of product price discount " Please check my edited question.Naresh
It's not that easy. You have to think of 4 things - add the field into the form, save the data into the database, get the data from the database and use if where you need it (in this case, the validator). I'll edit my answer below.Samuel Coman

1 Answers

0
votes

I don't think you need to edit any code for that. Use some math tricks.

You want to give a 10% discount but no discount bigger than 1000$.

Create 2 rules:

  1. Give a 10% discount if cart total is smaller than 10,000$
  2. Give a 1000$ discount if cart total is bigger than 10,000$

EDIT - Since you want only one rule

  1. Move that limit field into the Magento Configuration section. See http://inchoo.net/ecommerce/magento/create-configuration-for-your-magento-extension/ for details. It's a lot easier if you separate it from the rules form.
  2. Extend the app/code/core/Mage/SalesRule/Model/Validator.php in your module using: app/code/local/Namespace/Module/etc/config.xml

    <global>
        <models>
            <salesrule>
                <rewrite>     
                    <validator>Namespace_Module_Model_Validator</rule_collection>
                </rewrite>
            </salesrule>
        </models> 
    

app/code/local/Namespace/Module/Model/Validator.php

<?php
Namespace_Module_Model_Validator extends Mage_Core_Model_Validator {
... //place your updated method here