0

I need to add new value in action dropdown So I have copied the related file in the local code pool.

app/code/local/Mage/Adminhtml/Block/Promo/Catalog/Edit/Tab/Actions.php

$fieldset->addField('sub_simple_action', 'select', array(
            'label'     => Mage::helper('catalogrule')->__('Apply'),
            'name'      => 'sub_simple_action',
            'options'   => array(
                'by_percent'    => Mage::helper('catalogrule')->__('By Percentage of the Original Price'),
                'by_fixed'      => Mage::helper('catalogrule')->__('By Fixed Amount'),
                'to_percent'    => Mage::helper('catalogrule')->__('To Percentage of the Original Price'),
                'to_fixed'      => Mage::helper('catalogrule')->__('To Fixed Amount'),
                'for_ship'  => Mage::helper('catalogrule')->__('For Shipping'),
            ),
        ));

$fieldset->addField('simple_action', 'select', array(
            'label'     => Mage::helper('catalogrule')->__('Apply'),
            'name'      => 'simple_action',
            'options'   => array(
                'by_percent'    => Mage::helper('catalogrule')->__('By Percentage of the Original Price'),
                'by_fixed'      => Mage::helper('catalogrule')->__('By Fixed Amount'),
                'to_percent'    => Mage::helper('catalogrule')->__('To Percentage of the Original Price'),
                'to_fixed'      => Mage::helper('catalogrule')->__('To Fixed Amount'),
                'for_ship'  => Mage::helper('catalogrule')->__('For Shipping'),
            ),
        ));

app/code/local/Mage/CatalogRule/Helper/Data.php

public function calcPriceRule($actionOperator, $ruleAmount, $price)
    {
        $priceRule = 0;
        switch ($actionOperator) {
            case 'to_fixed':
                $priceRule = min($ruleAmount, $price);
                break;
            case 'to_percent':
                $priceRule = $price * $ruleAmount / 100;
                break;
            case 'by_fixed':
                $priceRule = max(0, $price - $ruleAmount);
                break;
            case 'by_percent':
                $priceRule = $price * (1 - $ruleAmount / 100);
                break;
            case 'for_ship': //custom added
                $priceRule = $price * (1 - $ruleAmount / 100);
                break;
        }

        return $priceRule;

    }

app/code/local/Mage/CatalogRule/Model/Rule.php When I have checked in this file and print log it misbehaves.

     public function calcProductPriceRule(Mage_Catalog_Model_Product $product, $price)
        {
            $priceRules = null;
            $productId  = $product->getId();
            $storeId    = $product->getStoreId();
            $websiteId  = Mage::app()->getStore($storeId)->getWebsiteId();
            if ($product->hasCustomerGroupId()) {
                $customerGroupId = $product->getCustomerGroupId();
            } else {
                $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
            }
            $dateTs     = Mage::app()->getLocale()->date()->getTimestamp();
            $cacheKey   = date('Y-m-d', $dateTs) . "|$websiteId|$customerGroupId|$productId|$price";

            if (!array_key_exists($cacheKey, self::$_priceRulesData)) {
                $rulesData = $this->_getResource()->getRulesFromProduct($dateTs, $websiteId, $customerGroupId, $productId);
                if ($rulesData) {
                    foreach ($rulesData as $ruleData) {
                        if ($product->getParentId()) {
                            if (!empty($ruleData['sub_simple_action']) ) {
                                $priceRules = Mage::helper('catalogrule')->calcPriceRule(
                                    $ruleData['sub_simple_action'],
                                    $ruleData['sub_discount_amount'],
                                    $priceRules ? $priceRules : $price
                                );
                            } else {
                                $priceRules = ($priceRules ? $priceRules : $price);
                            }
                            if ($ruleData['action_stop']) {
                                break;
                            }
                        } else {
                            //this is true for my product, As I am checking with a simple products.
                            $priceRules = Mage::helper('catalogrule')->calcPriceRule(
                                $ruleData['action_operator'],
                                $ruleData['action_amount'],
                                $priceRules ? $priceRules : $price
                            );
                            //print log here
                            if ($ruleData['action_stop']) {
                                break;
                            }

                        }
                    }
                    return self::$_priceRulesData[$cacheKey] = $priceRules;
                } else {
                    self::$_priceRulesData[$cacheKey] = null;
                }
            } else {
                return self::$_priceRulesData[$cacheKey];
            }
            return null;
        } 

The problem is, My product has price 28500, and when I set 1 in the discount amount that is in %, It prints in a custom log file.

(
    [rule_product_id] => 691948
    [rule_id] => 18
    [from_time] => 1581292800
    [to_time] => 1581811199
    [customer_group_id] => 1
    [product_id] => 7257
    [action_operator] => for_ship
    [action_amount] => 1.0000
    [action_stop] => 0
    [sort_order] => 0
    [website_id] => 1
    [sub_simple_action] => 
    [sub_discount_amount] => 0.0000
)

priceRules: 23982.75 (one more rule is applied that is for 15% + this 1%, So total 16% discount)
Price: 28500.0000

But Nothing is in tables When I get Product's FinalPrice its return 0.00. Why It behaves like this.

0

I have resolved it by placing the file app/code/core/Mage/CatalogRule/Model/Action/Index/Refresh.php to app/code/local/Mage/CatalogRule/Model/Action/Index/Refresh.php

and do the needful changes to _calculatePrice function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.