Magento Forum

Where to create my code
 
jaccoermers
Jr. Member
 
Total Posts:  30
Joined:  2013-01-23
 

Hi everyone,

Because bundled products displayed a +0.00 value I went searching for the code. I made a small change to the code to make it work the way I wanted it too.

\app\code\core\Mage\Bundle\Block\Catalog\Product\View\Type\Bundle\Option.php

public function getSelectionQtyTitlePrice($_selection$includeContainer true)
    
{
        $price 
$this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
        
$this->setFormatProduct($_selection);
        
$priceTitle $_selection->getSelectionQty()*' x ' $this->escapeHtml($_selection->getName());
        if (
$price == 0){
        } 
else {
        $priceTitle 
.= ' &nbsp; ' . ($includeContainer '<span class="price-notice">' '')
            . 
'+' $this->formatPriceString($price$includeContainer)
            . (
$includeContainer '</span>' '');
        
}
        
return  $priceTitle;
    
}

Unfortunately I am not a fan of core hacking. So while learning Magento I am now wondering, where should I place my code to make it work even after a magento update.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Hneotics
Jr. Member
 
Total Posts:  2
Joined:  2013-02-11
 

I’d like to say that I was impressed by the work of neosofttech.com and their programmers.
They are highly reliable, professional - they provide excellent and fast support. I like them and can highly recommend to others.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaccoermers
Jr. Member
 
Total Posts:  30
Joined:  2013-01-23
 
Hneotics - 07 March 2013 03:57 AM

I’d like to say that I was impressed by the work of neosofttech.com and their programmers.
They are highly reliable, professional - they provide excellent and fast support. I like them and can highly recommend to others.

and how does this help me? Just advertising them??

 
Magento Community Magento Community
Magento Community
Magento Community
 
p2409
Jr. Member
 
Total Posts:  16
Joined:  2008-08-16
 
jaccoermers - 07 March 2013 04:10 AM

Hneotics - 07 March 2013 03:57 AM
I’d like to say that I was impressed by the work of neosofttech.com and their programmers.
They are highly reliable, professional - they provide excellent and fast support. I like them and can highly recommend to others.

and how does this help me? Just advertising them??

Another Indian outfit self-promoting on this forum. These forum spammers are pretty common, and they usually sound pretty low-quality given they claim expertise in every language and system ever invented!

 
Magento Community Magento Community
Magento Community
Magento Community
 
devromans
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2012-04-05
 

Hello, you need to create your own module in app/code/local.

Create dir’s:
app/code/local/MyModule/Bundle
app/code/local/MyModule/Bundle/etc
app/code/local/MyModule/Bundle/Block

In app/code/local/MyModule/Bundle/etc create config.xml file:

<config>
    <
modules>
        <
MyModule_Bundle>
            <
version>0.1.0</version>
        </
MyModule_Bundle>
    </
modules>
    <global>
        <
blocks>
            <
bundle>
                <
rewrite>
                    <
catalog_product_view_type_bundle_option>MyModule_Bundle_Block_Catalog_Product_View_Type_Bundle_Option</catalog_product_view_type_bundle_option>
                </
rewrite>
            </
bundle>
        </
blocks>
    </global>
</
config>

Then create Option.php file in app/code/local/MyModule/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php:

<?php
class MyModule_Bundle_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option
{
    
public function getSelectionQtyTitlePrice($_selection$includeContainer true)
    
{
        $price 
$this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
        
$this->setFormatProduct($_selection);
        
$priceTitle $_selection->getSelectionQty()*' x ' $this->escapeHtml($_selection->getName());
        if (
$price == 0){
        } 
else {
        $priceTitle 
.= ' &nbsp; ' . ($includeContainer '<span class="price-notice">' '')
            . 
'+' $this->formatPriceString($price$includeContainer)
            . (
$includeContainer '</span>' '');
        
}
        
return  $priceTitle;
    

}

Then enable your module. Create file MyModule_Bundle.xml in app/etc/modules:

<?xml version "1.0"?>
<config>
    <
modules>
        <
MyModule_Bundle>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends>
                <
Mage_Bundle />
            </
depends>
        </
MyModule_Bundle>
    </
modules>
</
config>

Thats all smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaccoermers
Jr. Member
 
Total Posts:  30
Joined:  2013-01-23
 

Thank you for this detailed description,

also found out that a direct override in the local folder works:

/app/code/local/mage/..... etc

This means that my personal re-writes can go there. If I develop a module I will create the extensive code wink

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaccoermers
Jr. Member
 
Total Posts:  30
Joined:  2013-01-23
 
devromans - 07 March 2013 09:50 AM

Hello, you need to create your own module in app\\code\\local.

Create dir\’s:
app\\code\\local\\MyModule
app\\code\\local\\MyModule\\etc
app\\code\\local\\MyModule\\Block

In app\\code\\local\\MyModule\\etc create config.xml file:

<config>
    <
modules>
        <
MyModule_Bundle>
            <
version>0.1.0</version>
        </
MyModule_Bundle>
    </
modules>
    <global>
        <
blocks>
            <
bundle>
                <
rewrite>
                    <
catalog_product_view_type_bundle_option>MyModule_Bundle_Block_Catalog_Product_View_Type_Bundle_Option</catalog_product_view_type_bundle_option>
                </
rewrite>
            </
bundle>
        </
blocks>
    </global>
</
config>

Then create Option.php file in app\\code\\local\\MyModule\\Blockk\\Catalog\\Product\\View\\Type\\Bundle\\Option.php:
<?php
class MyModule_Bundle_Block_Catalog_Product_View_Type_Bundle_Option extends Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option
{
    
public function getSelectionQtyTitlePrice($_selection$includeContainer true)
    
{
        $price 
$this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
        
$this->setFormatProduct($_selection);
        
$priceTitle $_selection->getSelectionQty()*' x ' $this->escapeHtml($_selection->getName());
        if (
$price == 0){
        } 
else {
        $priceTitle 
.= ' &nbsp; ' . ($includeContainer '<span class="price-notice">' '')
            . 
'+' $this->formatPriceString($price$includeContainer)
            . (
$includeContainer '</span>' '');
        
}
        
return  $priceTitle;
    

}

Then enable your module. Create file MyModule_Bundle.xml in app/etc/modules:
<?xml version "1.0"?>
<config>
    <
modules>
        <
MyModule_Bundle>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends>
                <
Mage_Bundle />
            </
depends>
        </
MyModule_Bundle>
    </
modules>
</
config>

Thats all smile

Still trying to go this way. By now I have changed several things in code core (via local/mage system) but going to venture into making them into modules, later maybe share them via connect so others can benefit from it. I am slightly surpriced by the directory layout you are using.

My directory now:
app/local/Jacco/ (this is where all my custom modules will go)
app/local/Jacco/HideEmptyPrices (this specific module)

Now, based on your above example:
app/local/Jacco/HideEmptyPrices/Block/Catalog/Product/View/Type/Bundle/Option.php
should this not be:
app/local/Jacco/HideEmptyPrices/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php ??

My config.xml will be:

<config>
    <
modules>
        <
Jacco_HideEmptyPrice>
            <
version>0.1.0</version>
        </
Jacco_HideEmptyPrice>
    </
modules>
    <global>
        <
blocks>
            <
bundle>
                <
rewrite>
                    <
catalog_product_view_type_bundle_option>Jacco_HideEmptyPrice_Block_Catalog_Product_View_Type_Bundle_Option</catalog_product_view_type_bundle_option>
                </
rewrite>
            </
bundle>
        </
blocks>
    </global>
</
config>
or again, should it be:
<config>
    <
modules>
        <
Jacco_HideEmptyPrice>
            <
version>0.1.0</version>
        </
Jacco_Jacco_HideEmptyPrice>
    </
modules>
    <global>
        <
blocks>
            <
bundle>
                <
rewrite>
                    <
catalog_product_view_type_bundle_option>Jacco_HideEmptyPrice_Bundle_Block_Catalog_Product_View_Type_Bundle_Option</catalog_product_view_type_bundle_option>
                </
rewrite>
            </
bundle>
        </
blocks>
    </global>
</
config>
Then offcourse I want to create a adminhtml to set this extension On/Off. Again, any help is appreciated…
 
Magento Community Magento Community
Magento Community
Magento Community
 
jaccoermers
Jr. Member
 
Total Posts:  30
Joined:  2013-01-23
 

Decided to create it according Magento guidelines but it doesn’t seem to work :(

/app/etc/modules/Jacco_HideEmptyPrice.xml
/app/local/Jacco/HideEmptyPrice/
/app/local/Jacco/HideEmptyPrice/etc/
/app/local/Jacco/HideEmptyPrice/etc/config.xml
/app/local/Jacco/HideEmptyPrice/Helper/
/app/local/Jacco/HideEmptyPrice/Model/
/app/local/Jacco/HideEmptyPrice/Model/option.php

Jacco_HideEmptyPrice.xml

<?xml version \"1.0\"?>
<config>
    <
modules>
        <
Jacco_HideEmptyPrice>
            <
active>true</active>
            <
codePool>local</codePool>
            <
depends>
                <
Mage_Bundle />
            </
depends>
        </
Jacco_HideEmptyPrice>
    </
modules>
</
config>

config.xml

<config>
    <
modules>
        <
Jacco_HideEmptyPrice>
            <
version>0.1.0</version>
        </
Jacco_HideEmptyPrice>
    </
modules>
    <global>
        <
blocks>
            <
bundle>
                <
rewrite>
                    <
catalog_product_view_type_bundle_option>Jacco_HideEmptyPrice_Model_Option</catalog_product_view_type_bundle_option>
                </
rewrite>
            </
bundle>
        </
blocks>
    </global>
</
config>

option.php

<?php
class Jacco_HideEmptyPrice_Model_Option extends Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option
{
    
public function getSelectionQtyTitlePrice($_selection$includeContainer true)
    
{
        $price 
$this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection);
        
$this->setFormatProduct($_selection);
        
$priceTitle $_selection->getSelectionQty()*\' x \' $this->escapeHtml($_selection->getName());
        if (
$price == 0){
        } 
else {
        $priceTitle 
.= \' Â  \' . ($includeContainer \'<span class=\"price-notice\">\' \'\')
            . 
\'+\' $this->formatPriceString($price$includeContainer)
            . (
$includeContainer \'</span>\' \'\');
        
}
        
return  $priceTitle;
    

}
 
Magento Community Magento Community
Magento Community
Magento Community
 
devromans
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2012-04-05
 

Sorry for typo in path’s. I updated my post, but it seems that this solution dont work on Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option class.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jaccoermers
Jr. Member
 
Total Posts:  30
Joined:  2013-01-23
 

It seems that this guy did have a solution for a simple block…

but can’t seem to get it to work on mine.

http://www.magentocommerce.com/boards/viewthread/43682/

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top