Overwriting a Magento core class using custom module - class

I encouraged to post a question here for the first time, so here it goes!
I'm trying to overwrite Magento core class for the first time; Mage_CatalogInventory_Model_Stock_Item located # /app/code/core/Mage/CatalogInventory/Model/Stock/Item.php, but for some reason I'm not having any success as executing;
$object = Mage::getModel('cataloginventory/stock_item');
var_dump(get_class($object));
outputs
string 'Mage_CatalogInventory_Model_Stock_Item' (length=38)
I created a new directory under /app/code/local/Rage and copied the Item.php to /app/code/local/Rage/CatalogInventory/Model/Stock/Item.php renaming it to
class Rage_CatalogInventory_Model_Stock_Item extends Mage_CatalogInventory_Model_Stock_Item { ... }
I also made a couple of xml files. One to app/etc/modules/Rage_CatalogInventory.xml, which contains following;
<?xml version="1.0"?>
<config>
<modules>
<Rage_CatalogInventory>
<active>true</active>
<codepool>local</codepool>
</Rage_CatalogInventory>
</modules>
</config>
and another to app/code/local/Rage/CatalogInventory/etc/config.xml;
<?xml version="1.0" ?>
<config>
<modules>
<rage_cataloginventory>
<version>0.0.1</version>
</rage_cataloginventory>
</modules>
<global>
<models>
<cataloginventory>
<rewrite>
<stock_item>Rage_CatalogInventory_Model_Stock_Item</stock_item>
</rewrite>
</cataloginventory>
</models>
</global>
</config>
I just can't make it work even after a couple of hours trying... This is driving me crazy. Hope you can help me out!
Many many thanks in advance.
EDIT: Fixed config.xml as Amit pointed out. It turned out that Magento had compiler in use. I figured out that could've something to this. So disabled that and cleared the includes/src -folder contents, but still nothing is happening...

issue in config.xml and here rage_cataloginventory should be Rage_CatalogInventory and here total config.xml
<?xml version="1.0" ?>
<config>
<modules>
<Rage_CatalogInventory>
<version>0.0.1</version>
</Rage_CatalogInventory>
</modules>
<global>
<models>
<cataloginventory>
<rewrite>
<stock_item>Rage_CatalogInventory_Model_Stock_Item</stock_item>
</rewrite>
</cataloginventory>
</models>
</global>
</config>

Ok, this is just a guess and don´t be mad if i pointed something out that was clear to you;)
However: You did clear the config-cache, right?
(And keep the compiler disabled for development-environment, that saves you from some trouble if you forget that you have it active.)
The xml so far looks very correct to me, so that shouldn´t be the issue.
What to check:
Is the module loaded at all? (See under System->Config->Advanced)?
Is it working with any other model or just this one?
Any log output that gives a hint as to maybe the config.xml has an error (hidden chars etc.)?

Related

System.IO.InvalidDataException: An error occurred while applying transformation to 'web.config'

I'm creating a custom package off a project that needs to modify the web.config or app.config file of the destination application when installed. I have successfully created and published the package, religiously following the instructions provided by nuget, especially that of file and source code transformation.
However when I try installing the package in a project, I get the error:
System.IO.InvalidDataException: An error occurred while applying transformation to 'web.config' in project 'WebTestsNuget' No element in the source document matches '/configuration/system.runtime.caching/memoryCache'
I did some search and this ASP.NET blog post and this other post suggest I should remove the xmlns attribute in the configuration node of my .xdt files. When I did, published and tried installing again, I got the error.
System.IO.InvalidDataException: An error occurred while applying transformation to 'web.config' in project 'WebTestsNuget' 'xdt' is an undeclared prefix.
I found a similar issue reported on Github however the environment is MonoDevelop and it's way back in 2013. I'm using Visual Studio 2015 and .NET 4.6.1 for my work so it wasn't so helpful.
What else do I do to solve this problem?
(NB: I'm using Nuget 3.4.4.1321)
After much fruitless searches and trials, I finally experimented with the old (pre-NuGet 2.6) way of doing this: using .transform files, and it worked like charm!
Here's how to transform Web.Config using .transform files. It's much more straightforward that using XDT. Suppose you want to transform web.config (or app.config) file, you create a file named web.config.transform (or app.config.transform) and add the nodes you wish to be merged into the destination .config file.
For instance, if your .transform file contains the following:
<configuration>
<system.webServer>
<modules>
<add name="MyNuModule" type="Sample.MyNuModule" />
</modules>
<system.webServer>
</configuration>
and the destination config file contains the following:
<configuration>
.
.
<system.webServer>
<modules>
<add name="Module" type="Sample.Module" />
</modules>
<system.webServer>
.
.
</configuration>
the resultant after the merge will be
<configuration>
.
.
<system.webServer>
<modules>
<add name="MyNuModule" type="Sample.MyNuModule" />
<add name="Module" type="Sample.Module" />
</modules>
<system.webServer>
.
.
</configuration>
If the destination file does not have the <modules> node or even the <system.webServer> node, it will add it accordingly.

My custom extension is not visible on admin panel Magento 2.0

I installed my custom extension via composer.
I can confirm that app/code/vendor/package_name generated on the server by composer.
However,on admin panel under stores/configuration/advanced I can not see my extension.
What I've tried so far are as following ;
Flushing Magento 2.0 cache and disabling caching
Changing extension file permissions to 777
Deleting files under var/cache manually
Logging out and logging in again
None of them solved my problem.
How can I see my custom extension under admin stores / configuration / advanced on Magento 2.0 ?
I am not sure if it any helps but I posted my config.xml and module.xml
Thanks in advance,
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Fusion_CODFee" schema_version="0.0.1"></module>
</config>
<?xml version="1.0" ?>
<config>
<modules>
<Fusion_CODFee>
<version>0.1.0</version>
</Fusion_CODFee>
</modules>
</config>
According to me setup_version is missing from module.xml. It should be like this :
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Fusion_CODFee" schema_version="0.0.1" setup_version="0.0.1"></module>
</config>
you shoul try php bin/magento setup:upgrade command so that your magento upgrade itself with the new extension, also check for config.php in app/etc folder ,your module should be there if is active in case it is not then under array() tag add this "Fusion_CODFee=>1" and then run upgrade command in your rootdirectory, it might help you.
I've tried following code that's working for me please have look
Fusion\CODFee\etc\module.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Fusion_CODFee" setup_version="2.0.0">
</module>
</config>
Now next you have to register your module with registration.php
create registration.php under Fusion\CODFee\registration.php and put below code inside it.
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Fusion_CODFee',
__DIR__
);
Now clearing you cache and if still not working then fire below command from your root directory of magento installation
If your system is ubuntu then => sudo php bin\magento setup:upgrade or for window system remove sudo
then change permission and that's it
Let me know if still have any query

What are the steps needed in DITA-OT to pass ANT command line parameters to custom plugin's override XSLT-script

This question follows this: Is it possible to pass custom ANT parameters into custom plugin with DITA-OT?
I have plugin folder called: com.mymods.pdf under DITA-OT/plugins folder. Under is explained the structure and files shortly (follows this example closely http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html). Plugin works but now I want to pass ANT command line parameters into mycustom.xsl:
com.mymods.pdf/
cfg/
common/
vars/
en.xml
fo/
attrs/
mycustom.xsl
xsl/
mycustom.xsl
catalog.xml
integrator.xml
plugin.xml
build_mymods_pdf_template.xml (dita2com.mymods.pdf.init target is here and it depends on dita2pdf2)
build.xml (<project><import file="build_mymods_pdf.xml"/></project>)
insertParameters.xml (see the linked question for contents)
So where I need to apply changes and/or add new files?
I use the plugin from other location with "mainANT.xml" which has target and transtype for using "dita2mymodsPDF".
plugin.xml code:
<?xml version='1.0' encoding='UTF-8'?>
<plugin id="com.mymods.pdf">
<require plugin="org.dita.pdf2" />
<feature extension="dita.conductor.transtype.check" value="com.mymods.pdf" />
<feature extension="dita.transtype.print" value="com.mymods.pdf" />
<feature extension="dita.conductor.target.relative" file="integrator.xml" />
<feature extension="dita.conductor.com.mymods.pdf.param" file="insertParameters.xml"/>
<extension-point id="dita.conductor.com.mymods.pdf.param" name="PDF XSLT parameters"/>
</plugin>
build_mymods_pdf_template.xml code:
<?xml version='1.0' encoding='UTF-8'?>
<project name="com.mymods.pdf" default="com.mymods.pdf">
<property name="transtype" value="com.mymods.pdf"/>
<target name="dita2com.mymods.pdf.init">
<property location="${dita.plugin.com.mymods.pdf.dir}/cfg" name="customization.dir" />
<property location="${dita.plugin.com.mymods.pdf.dir}/xsl/fo/topic2fo_shell_fop.xsl" name="args.xsl.pdf" />
<property name="args.chapter.layout" value="BASIC" />
<property name="args.bookmark.style" value="COLLAPSED" />
<!--property name="args.fo.include.rellinks" value="nofamily" /-->
</target>
<target depends="dita2com.mymods.pdf.init, dita2pdf2" name="dita2com.mymods.pdf" />
</project>
Also integrator.xml code:
<?xml version='1.0' encoding='UTF-8'?>
<project name="com.mymods.pdf">
<target name="dita2com.mymods.pdf.init">
<property location="${dita.plugin.com.mymods.pdf.dir}/cfg" name="customization.dir" />
<property location="${dita.plugin.com.mymods.pdf.dir}/xsl/fo/topic2fo_shell_fop.xsl" name="args.xsl.pdf" />
<property name="args.chapter.layout" value="BASIC" />
<property name="args.bookmark.style" value="COLLAPSED" />
<!--property name="args.fo.include.rellinks" value="nofamily" /-->
</target>
<target depends="dita2com.mymods.pdf.init, dita2pdf2" name="dita2com.mymods.pdf" />
</project>
Not totally sure whether integrator.xml or build_mymods_pdf_template.xml is like it actually should. But this fileset works and uses mycustom.xsl (other for attributes and other for XSLT overrides). Now the problem is that how to get my own custom ANT parameters so the plugin can see its value.
This is really easy for pdf2 plugin but still can't yet get it working inside my com.mymods.pdf . I think I don't need to post catalog.xml because it just tells where are "mycustom.xsl" files that are working properly.
Really easy way, not the cleanest way to do this is:
Note: This applies for DITA-OT 1.8.4 check suitability for other versions.
Create your custom PDF plugin as told in: http://dita-ot.github.io/1.8/readme/dita2pdf-customization.html
Create "insertParameters.xml" as in: http://dita-ot.github.io/1.8/dev_ref/plugin-xsltparams.html
In my case with following custom parameters:
<?xml version='1.0' encoding='UTF-8'?>
<dummy>
<!-- EXAMPLE: <param name="paramNameinXSLT" expression="${antProperty}" if="antProperty"/> -->
<param name="custom.data1" expression="${custom.data1}" if="custom.data1"/>
<param name="custom.data2" expression="${custom.data2}" if="custom.data2"/>
</dummy>
Now drop this "insertParameters.xml" into DITA-OT\plugins\org.dita.pdf2
Create processing to custom.xsl under xsl\custom.xsl.
Here is an example code snippet for custom.xsl
<?xml version='1.0' encoding='UTF-8'?>
<snippet>
<xsl:param name="custom.data1"/>
<xsl:param name="custom.data2"/>
<fo:block><xsl:value-of select="$custom.data1"/></fo:block>
<fo:block><xsl:value-of select="$custom.data2"/></fo:block>
</snippet>
Run integrator.xml to integrate changes into your DITA-OT.
Give in command line commands for running your PDF scenario like: "ant dita2mypdf -f -Dcustom.data1="myCustomParameter1value" -Dcustom.data2="myCustomParameter2value"
Run the process to create PDF and your parameters should be visible!
What this question was really intended to achieve to get a step by step instruction to set all these things to work 100% in the custom plugin that not a single thing needs to be added into DITA-OT default plugins (not even single file into pdf2 folder as in this solution). This could make updating DITA-OT remarkably easier for future.
The cleaner? alternative to this approach is
add a placeholder insertParameters.xml to the root of the DITA-OT 1.8.5. The file does not exist in the standard DITA-OT 1.8.5
<?xml version='1.0' encoding='UTF-8'?>
<dummy>
<param name="dummy" expression="{$dummy} if="dummy"/>
</dummy>
add the override insertParameters.xml to the root of your plugin
<?xml version='1.0' encoding='UTF-8'?>
<dummy>
<param name="my.runtime.parameter" expression="{$my.runtime.parameter} if="my.runtime.parameter"/>
</dummy>
Then run ant -f integrator.xml
Without knowing precisely which parameters you need to pass, it's difficult to answer this question. However, let's assume you're invoking this from the command line and you've defined a transtype of mymodspdf. The command would look like this:
ant -f build.xml -Dtranstype mymodspdf -Dmyparameter1 paramval1 -Dmyparameter2 paramval2
HTH,
Julio J. Vazquez
Write Spirit
http://www.writespiritservices.com

troubleshooting a hello world module

I followed a tutorial from Alan Storm on creating a basic Hello World module for Magento. After some initial problems I got it working. Today I have gone to try and expand on that and the module no longer works(I get a 404 page not found message), I have not changed any code within that module or deleted any files.
The only thing that I can think I did since first creating the module and now is go into Magento's admin screen and make some adjustments - which i've tried changing back, but I still get the 404. I also have few other basic modules that I have been working on, but they also seem to no longer work.
I have checked System > Configuration > Advanced and the modules are all still enabled
Can anyone see something in my code that would stop this module from not being found when I vist http://magentotest.local/helloworld
app/etc/modules/As_Helloworld.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<As_Helloworld>
<active>true</active>
<codePool>local</codePool>
</As_Helloworld>
</modules>
</config>
app/code/local/As/Helloworld/controllers/IndexController.php
class As_Helloworld_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction() {
echo 'Hello Index!';
}
}
app/code/local/As/Helloworld/etc/config.xml
<config>
<modules>
<As_Helloworld>
<version>0.1.0</version>
</As_Helloworld>
</modules>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>As_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
</frontend>
</config>
1-Would changing options in the admin area be able to stop a module working?
2-If so where do I start looking to fix the problem
3-What can I do to prevent it from happening again?

Magento does not recognize new module

i tried like all tutorials out there and i still cannot get a custom created module to work in Magento.
This is the path where i created the XML file on the server to tell Magento what the module is:
app/etc/modules/Multiplies_HelloWorld.xml
<?xml version="1.0"?>
<config>
<modules>
<Multiplies_HelloWorld>
<active>true</active>
<codePool>local</codePool>
</Multiplies_HelloWorld>
</modules>
</config>
This is the module path:
app/code/local/Multiplies/HelloWorld/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Multiplies_HelloWorld>
<version>0.0.1</version>
</Multiplies_HelloWorld>
</modules>
</config>
when i go to System/Configuration/Advanced i see a whole bunch of other modules except mine.
I tried to flush the cash, disable it, clear it manualy, restart browser, relog but still no module in my list.
The version im using is magento 1.7.0.2 (free)
Im using FileZilla to upload files.
Any suggestions would be really appreciated.
This may be a bit late, but I was just having this same problem.
After 20 minutes of chin scratching I tried resetting all caches (System > Cache Management) and then it popped up!
I'm disabling the "configuration" cache while heavily developing a module. I think that'll help reduce friction.
Make sure your etc/module.xml looks like this:
<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="OrgName_ModuleName" setup_version="1.0.0">
</module>
</config>
Make sure your composer.json has this:
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"OrgName\\ModuleName\\": ""
}
}
Make sure your registration.php looks like this:
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'OrgName_ModuleName',
isset($file) && realpath($file) == __FILE__ ? dirname($file) : __DIR__
);
If your module is contained in a symlinked directory that is outside of magento root directory (happens when you use local "path": as a module's repository description in composer), you have to allow magento for symlinks with: bin/magento config:set dev/template/allow_symlink 1 . See https://magento.stackexchange.com/a/315525/88882 for more info.