Question

Quick overview even though I think the below code will explain itself. I am wanting to extend the getName() public function and truncate it. However my code does nothing and does not even throw an error. Here is are my files.

Beckin/TextShortner/etc/config.xml

<config>    
<modules>
<Beckin_TextShortner><version>1.0.0</version></Beckin_TextShortner>
    </modules>

<global>           
            <models>
               <textshortner>
                     <class>Beckin_TextShortner_Model</class>
               </textshortner>
            </models>
    <helpers>
         <textshortner>
          <class>Beckin_TextShortner_Helper</class>
         </textshortner>
    </helpers>      
</global>


<textshortner>
  <settings>
    <enable>1</enable>
  </settings>
</textshortner>


 <frontend>
    <layout>
        <updates>
            <beckin>
                <file>beckin_textshortner.xml</file>
            </beckin>
        </updates>
    </layout>
    <routers>
        <textshortner>
            <use>standard</use>
            <args>
                <module>Beckin_TextShortner</module>
                <frontName>textshortner</frontName>
            </args>
        </textshortner>
    </routers>  
</frontend>

</config>

Beckin/TextShortner/Model/Catalog/Product.php

class Beckin_TextShortner_Model_Catalog_Product extends Mage_Catalog_Model_Catalog_Product
{   

public function getName()
{
$getmyName = $this->_getData('name');
return  $this->helper('core/string')->truncate($getmyName,10); 
}

}

Beckin/TextShortner/etc/system.xml

<config>
<tabs>
    <beckin translate="label">
        <label>Beckin Extensions</label>
        <sort_order>100</sort_order>
    </beckin>
</tabs>

<sections>  
            <textshortner translate="label">
        <label>Text Shortner</label>
        <tab>beckin</tab>
        <frontend_type>text</frontend_type>
        <sort_order>1010</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>


            <groups>            

                <settings translate="label">
                <label>Settings</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>

                    <fields>
                        <enable translate="label">
                        <label>Enable</label>
                        <comment>
                        <![CDATA[Enable or Disable this extension.]]>
                        </comment>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>1</show_in_store>                    
                        </enable>           
                    </fields>

                </settings>
            </groups>
        </textshortner>
</sections>     
</config>

Beckin/TextShortner/etc/adminhtml.xml

<config>  

    <acl>
        <resources>
        <all>
            <title>Allow Everything</title>
        </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <textshortner>
                                        <title>Beckin Text Shortner Extension</title>
                                    </textshortner>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>

</config>

and of-course I got my modules xml file set as well.

Can anyone help?

Was it helpful?

Solution

First things the model you extend Mage_Catalog_Model_Catalog_Product I think this is not the right name for the model ??

did you mean ? Mage_Catalog_Model_Product

Second with your code you extended the model but you didn't rewrite the model. So you have to change the model the in block files in the core pool which is not good.

So what u need to do here is to specify rewrite for the model in your config.xml

<models>
....
<catalog>
      <rewrite>
            <product>Beckin_TextShortner_Model_Catalog_Product</product>
      </rewrite>
</catalog>
....
</models>

Then you will be able to use the method without issues

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top