I have a problem with the PDF invoice and i'm trying to override the AbstractPdf.php file, I have done the following:
1)Created the following directories and files:
a. 'app\code\Ochos\fixPDF\registration.php':
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Ochos_fixPDF',
__DIR__
);
b. 'app\code\Ochos\fixPDF\etc\di.xml':
<?xml version="1.0" ?>
<config>
<preference for="vendor\magento\module-sales\Model\Order\Pdf\AbstractPdf" type="Ochos\fixPDF\Model\Order\Pdf\AbstractPdf" />
</config>
c. 'app\code\Ochos\fixPDF\etc\module.xml':
<?xml version="1.0"?>
<config>
<module name="Ochos_fixPDF" setup_version="2.0.0"/>
</config>
d. 'app\code\Ochos\fixPDF\Model\Order\Pdf\Abstract.php': the file that I have made changes in.
2)enabled the extension in config.php
3) Executed the following:
php -f bin/magento module:enable --clear-static-content Ochos_fixPDF
php -f bin/magento setup:upgrade
it seems that the extension is enabled, but no changes are made in the invoice PDF.
What am I doing wrong?
Thanks!
The problem is the function you want override is a protected function. I have other post and explain how we can change the function.
You have to preference to invoice.php and create the function into this file.
See this post: https://magento.stackexchange.com/questions/153308/override-abstractpdf-class-in-magento2
Related
Magento 2.3.4 setup_module table does not show newly installed module as well as most of the default modules?
Module register in setup_module database use Two file
app/code/vendor/module_name/registration.php
<?php
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'vendor_modulename',
__DIR__
);
And second file ,
app/code/vendor/module_name/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="vendor_modulename" setup_version="1.1.0">
</module>
</config>
After created file and run this command,
php bin/magento s:up
php bin/magento c:f
Hope the help
Thanks.
I've the following file tree
mainfolder
|-assembly.xml
|
|-chapters
| |-introduction.xml
|
|-source
|-example01
|-main.cpp
assembly.xml is the assembly file of my docbook. It contains a reference to introduction.xml.
This is the assembly:
<?xml version="1.0" encoding="UTF-8"?>
<assembly version="5.1"
xmlns="http://docbook.org/ns/docbook">
<resources xml:base="chapters/">
<resource href="introduction.xml" xml:id="introduction" />
</resources>
<structure xml:id="main-book">
<info>
<description>Book chapters</description>
</info>
<output renderas="book"/>
<module resourceref="introduction"/>
</structure>
</assembly>
introduction.xml is docbook chapter. I want to insert in it an example including the main.cpp.
<?xml version="1.0" encoding="UTF-8"?>
<chapter version="5.1"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xila="http://www.w3.org/2001/XInclude/local-attributes"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:trans="http://docbook.org/ns/transclusion"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:m="http://www.w3.org/1998/Math/MathML"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:db="http://docbook.org/ns/docbook">
<info>
<title>Introduction</title>
</info>
<section>
<info>
<title>Chapter title</title>
</info>
<para>
You can see an example:
</para>
<example>
<title>main example</title>
<programlisting language="c++">
<xi:include href="./../source/example01/maiin.cpp" parse="text" />
</programlisting>
</example>
</section>
</chapter>
Anyway, when I build the book (I'm using personal edition of XMLMind), I don't see anything. In the PDF the example is printed, but instead of the source code inside the main.cpp I see
<xi:include></xi:include>
What I'm doing wrong? How can I include the source code from the file?
I've reproduced your situation in a different ways and got things working in a both cases.
You didn't mention the exact steps you make to build a book using XMLMind XML Editor (XXE for short), but the following steps certainly worked well.
None 1: I've used XXE Professional Edition, but as I know the difference between versions is only in putting random character within text if generating PDF from Personal Edition.
Note 2: XXE says that <description>Book chapters</description> element is not allowed within you context. Despite that fact, the assembly can be generated successfully.
1. Getting things working within XXE
Open an assembly file in XXE.
Select Convert > Convert document > Convert to PDF.
Select a path to save pdf file and press OK button.
2. Getting things working manually in command line
Use your exact files and DIR structure (I included my own .c file sample for my own test).
Use XXE assembly processor: http://www.xmlmind.com/xmleditor/assembly.shtml - it has the same codebase that XXE used for working with assemblies from XXE GUI.
Get docbook book file from assembly:assembly-1_0_2_01/bin/assembly -v assembly.xml docbook_book.xml In my test I've got the .c sample file included - that proves that assembly utility works well with XInclude.
Get .pdf manually: fop -c <config_file> -xsl <path_to_docbook_ns_stylesheets>/fo/docbook.xsl -xml docbook_book.xml -pdf docbook_book.pdf
I've got the final result with .c sample included in both cases.
I want to create the following xml during the installation created by wix 3.9.
<?xml version="1.0" encoding="utf-8"?>
<MappedUsers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UsersList>
<LyncUserID>
<CustomUserName>John.Smith</UcaUserName>
</LyncUcaUserID>
</UsersList>
</MappedUsers>
Tried creating the file using following code but got the error message during installtion that file doesn't exists.
<?define UserNameFile="[AppDataFolder]ThirdParty\LyncUcaUserMapping.XML" ?>
<util:XmlFile Id="UserMapping" Value="[USER_NAME]" ElementPath="/UsersList/LyncUserID/add[\[]#key='UcaUserName'[\]]" Action="setValue" File="$(var.UserNameFile)" Name="value" Sequence="7" />
Since I could not create the file during the installation I created the file manually and placed in my appdata folder. But then above code didn't work either as it says "failed to find the following node".
What am I missing?
Best method to do this is first you copy a sample xml file as below.
<?xml version="1.0" encoding="utf-8"?>
<MappedUsers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</MappedUsers>
Then edit it using a custom action.
Here is a link which shows how to edit xml files using c#
http://support.microsoft.com/kb/301233
Following link shows how to add custom actions to a wix project.
http://wixtoolset.org/documentation/manual/v3/wixdev/extensions/authoring_custom_actions.html
I have been trying to rewrite a class in Magento and I be doing all the correct procedures, however I am not getting.
I'm trying to rewrite app\code\core\Mage\Catalog\Model\Product\Attribute\Media\Api.php
Thanks in advance to anyone who can help me.
<config>
<modules>
<Namespace_Catalog>
<version>1.6.0.0.14</version>
</Namespace_Catalog>
</modules>
<global>
<models>
<catalog>
<rewrite>
<product_attribute_media_api>Namespace_Catalog_Model_Product_Attribute_Media_Api</product_attribute_media_api>
</rewrite>
</catalog>
</models>
</global>
</config>
Yeah I forgot to say that part
In the app/etc/modules/ I have with depends tag. I've tried with and without the tag depends and it never worked. I think I'm really doing everything right.
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Catalog />
</depends>
</Namespace_Catalog>
</modules>
</config>
In the app\code\local\Namespace\Catalog\Model\Product\Attribute\Media\Api.php I have
class Namespace_Catalog_Model_Product_Attribute_Media_Api extends Mage_Catalog_Model_Product_Attribute_Media_Api
I rewrote the function removes and let it equal to the original, but with Mage::log('rewrote', null, 'rewrote.log'), to know that he had successfully rewritten.
I cleared my cache.
I corrected codePool tag for case sensitive.
I checked /var/log/ and not found any error inside exception.log and system.log.
My Index.php is set as developer mode and ini_set('display_errors', 1); uncommented.
I followed a tutorial on Magento here
This describes the state of your Magento system. It lists all modules, models, classes, event listeners or almost anything else you could think of. For example, consider the config.xml file you created above. If you search the XML file in your browser for the text Namespace_Catalog_Model_Product_Attribute_Media_Api you'll find your class listed. Every module's config.xml file is parsed by Magento and included in the global config.
Here is my class to write. It seems okay. What can I be missing?
<catalog>
<class>Mage_Catalog_Model</class>
<resourceModel>catalog_resource</resourceModel>
<rewrite>
<product_attribute_media_api>Namespace_Catalog_Model_Product_Attribute_Media_Api</product_attribute_media_api>
</rewrite>
</catalog>
Your code seems to be right.
Have you created an XML-file in app/etc/modules/?
It should look like:
Namespace_Catalog.xml
< ?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<active>true</active>
<codepool>local</codepool>
</Namespace_Catalog>
</modules>
</config>
i think you missed something
<version>1.6.0.0.14</version>
should be same with
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Catalog>
<active>true</active>
<codepool>local</codepool>
<version>1.6.0.0.14</version>
</Namespace_Catalog>
</modules>
"Codepool" is case sensitiv.
Try:
<codePool>local</codePool>
instead of
<codepool>local</codepool>
I'm attempting to automate the building of our installers through MSBuild. The problem that I have come up against is getting the Version information of the C# project which is calling the custom MSBuild script, which would then pass the version number into Wix during the build process.
What I would like to do is to set the version into some properties like this:
<ProductVersion>$(MajorVersion).$(MinorVersion).$(PatchVersion).$(BuildVersion)</ProductVersion>
<InstallerName>"$(ProductName)-$(ProductVersion).msi"</InstallerName>
The version is updated as part of our continuous integration build and incorporating the version number into each installer that is built on our continuous integration server helps us in producing an application that is Continuously Deployable.
Any help would be greatly appreciated.
The way I have solved this problem is by creating a 'version.xml' file in my code repository. This file contains the following data
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionMajor>0</VersionMajor>
<VersionMinor>1</VersionMinor>
<VersionBuild>1</VersionBuild>
<VersionRevision>0</VersionRevision>
</PropertyGroup>
</Project>
In my case this file is checked in but it should not be too hard to generate this file with information from the build server or whatever is desired.
During the build a custom MsBuild taks (similar to the TemplateFile task) creates an assembly info file and a Wix include file from their respective template files. The 'version.xml' file is accessed by including it in the MsBuild script. For example like this:
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Include the version info file so that we can pull the version info from it -->
<Import
Project="$(DirWorkspace)\version.xml"
Condition="Exists('$(DirWorkspace)\version.xml')" />
<!-- Generate a file with the version information -->
<Target Name="GenerateAssemblyInfoVersionNumber">
<ItemGroup>
<VersionTokens Include="Major">
<ReplacementValue>$(VersionMajor)</ReplacementValue>
</VersionTokens>
<VersionTokens Include="Minor">
<ReplacementValue>$(VersionMinor)</ReplacementValue>
</VersionTokens>
<VersionTokens Include="Build">
<ReplacementValue>$(VersionBuild)</ReplacementValue>
</VersionTokens>
<VersionTokens Include="Revision">
<ReplacementValue>$(VersionRevision)</ReplacementValue>
</VersionTokens>
</ItemGroup>
<TemplateFile
Template="$(FileTemplateAssemblyVersion)"
OutputFileName="$(FileGeneratedAssemblyVersion)"
Tokens="#(VersionTokens)" />
</Target>
</Project>
The AssemblyInfo.VersionNumber.cs file which is included in the C# projects is generated from a template file that looks like:
//-----------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost
// if the code is regenerated.
// </auto-generated>
//-----------------------------------------------------------------------
using System.Reflection;
[assembly: AssemblyVersion("${Major}.${Minor}.${Build}.${Revision}")]
[assembly: AssemblyFileVersion("${Major}.${Minor}.${Build}.${Revision}")]
// The AssemblyInformationalVersion stores the version that will be displayed in
// Windows explorer.
[assembly: AssemblyInformationalVersion("${Major}.${Minor}.${Build}.${Revision}")]
During the replacement process the ${TEXT_HERE} sections are replaced with their respective values.
The Wix include template file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Include xmlns="http://schemas.microsoft.com/wix/2006/wi">
<!--
This is a generated file.
Do NOT make changes to this file.
They will be undone next time the file is generated.
-->
<!-- The current version -->
<?define CurrentVersion = "${Major}.${Minor}.${Build}"?>
<!-- The install version string -->
<?define ProductVersionFolder = "${Major}.${Minor}"?>
</Include>
After including this file it is possible to refer to the CurrentVersion and the ProductVersionFolder variables in the Wix installer where ever it is needed.
By using this method the version information is stored in a single location and can be accessed by all parts of the build.