cancel
Showing results for 
Search instead for 
Did you mean: 

"local" Folder

"local" Folder

Hello!

 

i just want to implement a price rounding for all prices. For that i was editing the roundPrice() Function in app/code/core/Mage/Core/Model/Store.php

 

On the detailsite the prices arent rounded ... Now i started a topic here and i should create a file in app/code/local/Mage/Core/Model/Store.php .... But i dont have a local folder. How can i implement my own Module or file now and maybe someone can explain me in an easy way how to round even the special prices on the articledetails.

 

Thanks, Christian

 

3 REPLIES 3

Re: "local" Folder

Hello @christian _stegemann

 

You can follow below instructions and if you donot have local folder just create a local folder in app/code folder.

 

Just observe catalog_product_load_after event, and overwrite special_price with a rounded value.

Create a bootstrap file for your module:

app/etc/modules/Danslo_RoundSpecialPrice.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Danslo_RoundSpecialPrice>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Catalog />
            </depends>
        </Danslo_RoundSpecialPrice>
    </modules>
</config>

Specify that we want to observe the product load event:

app/code/local/Danslo/RoundSpecialPrice/etc/config.xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <global>
        <models>
            <roundspecialprice>
                <class>Danslo_RoundSpecialPrice_Model</class>
            </roundspecialprice>
        </models>
        <events>
            <catalog_product_load_after>
                <observers>
                    <round_special_price>
                        <class>roundspecialprice/observer</class>
                        <type>singleton</type>
                        <method>roundSpecialPrice</method>
                    </round_special_price>
                </observers>
            </catalog_product_load_after>
            <catalog_product_collection_load_after>
                <observers>
                    <round_special_price>
                        <class>roundspecialprice/observer</class>
                        <type>singleton</type>
                        <method>roundSpecialPriceInCollection</method>
                    </round_special_price>
                </observers>
            </catalog_product_collection_load_after>
        </events>
    </global>
</config>

Then just write your observer implementation:

app/code/local/Danslo/RoundSpecialPrice/Model/Observer.php:

class Danslo_RoundSpecialPrice_Model_Observer
{

    public function roundSpecialPrice($observer)
    {        $product = $observer->getProduct();
        if ($product->getSpecialPrice()) {            $product->setSpecialPrice(round($product->getSpecialPrice()));
        }
    }

    public function roundSpecialPriceInCollection($observer)
    {
        foreach ($observer->getCollection() as $product) {
            if ($product->getSpecialPrice()) {                $product->setSpecialPrice(round($product->getSpecialPrice()));
            }
        }
    }

}

 

Manish Mittal
https://www.manishmittal.com/

Re: "local" Folder

Thank you for your answer. I did all the things you mentioned...

 

1) I created the bootstrap file into the folder "app/etc/modules/Danslo_RoundSpecialPrice.xml", with the same code as your file:Screenshot_8.jpg

2) I created the new config file with the same code as your file in "app/code/local/Danslo/RoundSpecialPrice/etc/config.xml"

3) At Last i created the new Observer.php..... "app/code/local/Danslo/RoundSpecialPrice/Model/Observer.php"

It doesnt work. Maybe you forgot the implemtentation of the special rounding in your observer.php ? I really dont know Smiley Sad

 

Re: "local" Folder

Thats how my new roundPrice function look like to round the prices ... it work but not in details of an article ....

 

Screenshot_9.jpg

 

And i wonder if the file at Core "app/code/core/Mage/Core/Model" wont get overwritten with the next update