Magento 2 change pdf filename - pdf

I want to change the filenames of the PDF files in Magento 2.
The default names are not clear and I want invoices to be searchable when saved to a location on my pc.
Is it possible to change the filenames of the PDF-files in Magento 2 to a format like "invoice_1000000123.pdf"?

You should never edit core files. Seriously, don't.
Since /vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php is an abstract class you have to use a plugin or preference in your module in order to override it.
What you need to achieve that:
The usual minimum files:
/Vendor/Module/composer.json, /Vendor/Module/registration.php, /Vendor/Module/etc/module.xml
In /Vendor/Module/etc/module.xml you should sequence Magento_Sales
<?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_Module" setup_version="1.0.0">
<sequence>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
Then you can either use a plugin or a preference in /Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction" type="Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction"/>
</config>
Plugin would look something like this:
<type name="Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction">
<plugin name="Vendor_Module::aroundPrintInvoice" type="Vendor\Module\Block\Class" sortOrder="0"/>
</type>
Now add a PrintAction.php to the path specified in your preference / plugin (Example for preference)
<?php
namespace Vendor\Module\Controller\Adminhtml\Invoice\AbstractInvoice;
class PrintAction extends \Magento\Sales\Controller\Adminhtml\Invoice\AbstractInvoice\PrintAction
{
/* Write code here */
}

You need override the invoice admin controller.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="\Magento\Sales\Controller\Adminhtml\Order\Invoice"
type="Vendor\Module\Controller\Adminhtml\Order\Invoice" />
</config>
In your custom module admin controller, You need to change the name of Pdf file.
public function execute()
{
$invoiceId = $this->getRequest()->getParam('invoice_id');
return $this->_fileFactory->create(
'invoice_13012020' . $invoiceId . '.pdf', //<== Change the pdf name here.
$pdf->render(),
DirectoryList::VAR_DIR,
'application/pdf'
);
...
}
Reference Link

Yes it is possible to change invoice pdf filename.
Please go to following path:
/vendor/magento/module-sales/Controller/Adminhtml/Invoice/AbstractInvoice/PrintAction.php
You can change filename from above file.

Related

override core controller in custom module in Magento

HI i have to extend the core controller in my own module for this i am referencing the below link
http://inchoo.net/tools-frameworks/how-to-extend-magento-core-controller/
below is my module structure
/var/www/magento1.9/app/etc/modules
<?xml version="1.0"?>
<!--we need to enable this module as any other if-->
<!--you wish to do it as standalone module extension-->
<config>
<modules>
<Inchoo_Coreextended>
<active>true</active>
<codepool>local</codepool>
</Inchoo_Coreextended>
</modules>
</config>
/var/www/magento1.9/app/code/local/Inchoo/Coreextended/controllers/Frontend/Customer/AccountController.php
<?php
require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
//we need to add this one since Magento wont recognize it automatically
class Inchoo_Coreextended_Frontend_Customer_AccountController extends Mage_Customer_AccountController
{//here, you extended the core controller with our
public function indexAction()
{
parent::indexAction();
//you can always use default functionality
}
public function myactionAction()
{
//my code
//you can write your own methods / actions
}
public function mymethod()
{
//my code
//you can write your own methods
}
public function loginAction()
{
echo "hello";
//finally you can write your code that will rewrite the whole core method
//and you can call for your own methods, as you have full control over core controller
}
}
/var/www/magento1.9/app/code/local/Inchoo/Coreextended/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Inchoo_Coreextended>
<version>0.1.0</version>
</Inchoo_Coreextended>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<Inchoo_Coreextended before="Mage_Customer_AccountController">Inchoo_Coreextended_Frontend_Customer</Inchoo_Coreextended>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
but when i am accessing the http://localhost/magento1.9/index.php/customer/account/login/ it shows core login action and it is not switching from my module Can you please suggest where i am doing mistake .
I have fixed this by making changes in following file:
app/etc/modules/Inchoo_Coreextended.xml .
Before:
<config>
<modules>
<Inchoo_Coreextended>
<active>true</active>
<codepool>local</codepool>
</Inchoo_Coreextended>
</modules>
</config>
After:
<config>
<modules>
<Inchoo_Coreextended>
<active>true</active>
<codePool>local</codePool>
</Inchoo_Coreextended>
</modules>
</config>
codepool should be codePool

Custom module issue

I tried creating one new module. For that i created indexController, config.xml, block, layout and other required files, even though i am unable to view the message that i wrote in my block file. Whenever the url is fired (http://mydomain.com/foobar/) the output "it is from foo bar" should be displayed, but at the moment it is not working.
My indexController.php code :
class Foo_Bar_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
Code related to block :
class Foo_Bar_Block_News extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function fetchRow()
{
echo "it is from foo bar";
}
}
code related to config.xml :
<?xml version="1.0"?>
<config>
<modules>
<Foo_Bar>
<version>1.0.0</version>
</Foo_Bar>
</modules>
<frontend>
<routers>
<foobar>
<use>standard</use>
<args>
<module>Foo_Bar</module>
<frontName>foobar</frontName>
</args>
</foobar>
</routers>
<layout>
<updates>
<bar>
<file>foobar.xml</file>
</bar>
</updates>
</layout>
<!--<events>
<catalog_product_load_after>
<observers>
<foo_bar>
<type>model</type>
<class>foo_bar/observer</class>
<method>catalogProductLoadAfter</method>
</foo_bar>
</observers>
</catalog_product_load_after>
</events>-->
</frontend>
<global>
<blocks>
<foobar>
<class>Foo_Bar_Block</class>
</foobar>
</blocks>
</global>
</config>
code related to layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<foobar_index_index>
<reference name="content">
<block type="foobar/news" name="news_test" template="bar/check.phtml"/>
</reference>
</foobar_index_index>
</layout>
Code related to template file
<?php
echo $this->fetchRow()
?>
Any help realted to this will be appreciated.
The solution to this issue in my case is to Disable the compilation from admin. Everything else is fine. The desired output is obtained after disabling the compilation from admin.
To disable compilation login to admin side of your magento project and then go to system>>Tools>>Compilation and then click on disable button to disable the compilation.

Primefaces fileupload filter when web.xml not used

I want to use the primefaces fileupload control in my jboss 7 web application. As I don't use any web.xml (not required with Java EE 6), how can I specify the filter required to make the fileupload work properly? Should I create a web.xml for that or can I use annotations instead?
Thank you in advance!
Technically, you should indeed be creating a web.xml file yourself. It's not that hard, just create a file in /WEB-INF/web.xml with the following kickoff template:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<!-- Your config here. -->
</web-app>
If you've really a hard head in and have some big aversion against "XML boilerplate", then you could always homebrew a filter class which extends the PrimeFaces file upload filter with the desired #WebFilter annotation.
package com.example;
import javax.servlet.annotation.WebFilter;
import org.primefaces.webapp.filter.FileUploadFilter;
#WebFilter("*.jsf") // Or #WebFilter(servletNames={"Faces Servlet"})
public class AnnotatedPrimeFacesFileUploadFilter extends FileUploadFilter {
// NOOP.
}

magento 1.7 add attributegroup

I need to add an attributegroup called Videos in the database using an install script.
these are my files:
app/code/local/Company/ProductVideo/etc/config.xml
<resources>
<attributegroup_setup>
<setup>
<module>Company_ProductVideo</module>
<class>Company_ProductVideo_Model_Entity_Setup</class>
</setup>
</attributegroup_setup>
</resources>
</global>
app/code/local/Company/ProductVideo/Model/Entity/Setup.php
<?php
class Company_ProductVideo_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup{
}
?>
app/code/local/Company/sql/attributegroup_setup/msql4-install-1.7.0.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttributeGroup('catalog_product', 'Default','Videos', 40);
$installer->endSetup();
?>
My module is also registered in app/code/etc/modules/Company_ProductVideo.xml
<config>
<modules>
<Company_ProductVideo>
<active>true</active>
<codePool>local</codePool>
</Company_ProductVideo>
</modules>
</config>
But this is not working, any help is welcome!!
I have already solved it, the problem was the name of the folder under the sql folder.
the convention is to name it like this: mysql4-install-'version'.

Why is my WCF Data Services method not appearing in the OData collections list?

When I view the root of my WCF Data Services service (http://localhost/MyService.svc/) in a browser I see this:
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<service xml:base="http://localhost/MyService.svc/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:app="http://www.w3.org/2007/app" xmlns="http://www.w3.org/2007/app">
<workspace>
<atom:title>Default</atom:title>
</workspace>
</service>
I would expect to see a list of collections.
When I go to the $metadata URL I see this:
<?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:DataServiceVersion="1.0">
<Schema Namespace="MyApp" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
<ComplexType Name="Package">
<Property Name="Id" Type="Edm.String" Nullable="true" />
</ComplexType>
</Schema>
<Schema Namespace="MyApp" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://schemas.microsoft.com/ado/2007/05/edm">
<EntityContainer Name="PackageService" m:IsDefaultEntityContainer="true">
<FunctionImport Name="GetQueryablePackages" ReturnType="Collection(MyApp.Package)" m:HttpMethod="GET" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
Why might my GetQueryablePackages collection not be appearing?
I'm using these access settings:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
Service operations (the function import in the EDM) is not exposed in the service document. Only entity sets are exposed there.
If you want your data to be exposed in the service document make an entity set out of it. Depending on the provider model this differs. Typically it means exposing a property of type IQueryable on your context class. Note that T has to be an entity type (must have a key).
Can you share the context definition where you have defined the IQueryable <> properties. There are 2 things that come to my mind: First the properties must be of type IQueryable<> or some type that derives from it. Second, the element type refered by the IQueryable<> must be an entity type i.e. they must have key properties declared in them.
Hope this helps.
Thanks
Pratik
Or you can create an extension method like this:
public static class TestEntitiesExtensions
{
public static IEnumerable<Package> GetQueryablePackages(this TestEntities context)
{
var uri = new Uri(context.BaseUri, "GetQueryablePackages");
return context.Execute<Package>(uri);
}
}