Skip to content

Make it possible to generate sales PDF's using the API #20043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2019

Conversation

AntonEvers
Copy link
Contributor

Description (*)

Currently if you try to generate an invoice PDF using a custom API endpoint, you will get the exception: Invalid template file: 'Magento_Payment::info/pdf/default.phtml' because you are not in the adminhtml scope or the frontend scope which is the only place where this template lives.

Because app/code/Magento/Payment/view/adminhtml/templates/info/pdf/default.phtml === app/code/Magento/Payment/view/frontend/templates/info/pdf/default.phtml it is safe to move that file to app/code/Magento/Payment/view/base/templates/info/pdf/default.phtml. I'll leave the adminhtml and frontend templates in place for backward compatibility.

Fixed Issues (if relevant)

  1. none

Manual testing scenarios (*)

  1. Create an API endpoint which generates an invoice PDF
  2. Calling that endpoint should not result in an error

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @AntonEvers. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.1 milestone Jan 3, 2019
@magento-engcom-team
Copy link
Contributor

Hi @aleron75, thank you for the review.
ENGCOM-3781 has been created to process this Pull Request

@aleron75
Copy link
Contributor

aleron75 commented Jan 3, 2019

Hello @AntonEvers thanks for your contribution.

Once merged, don't forget you can easily port this PR to other branches with the Porting Tool, read more here.

@AntonEvers AntonEvers removed Partner: Kega partners-contribution Pull Request is created by Magento Partner labels Jan 3, 2019
@AntonEvers
Copy link
Contributor Author

Thanks @aleron75! Great advice

@magento-engcom-team
Copy link
Contributor

Hi @aleron75, thank you for the review.
ENGCOM-3781 has been created to process this Pull Request

@okorshenko okorshenko removed this from the Release: 2.3.1 milestone Jan 28, 2019
@sdzhepa
Copy link
Contributor

sdzhepa commented Jan 31, 2019

Hi @AntonEvers

Could you help us with "Manual testing scenarios" for this issue?

Thank you for contribution and collaboration!

@AntonEvers
Copy link
Contributor Author

AntonEvers commented Feb 4, 2019

@sdzhepa this is my testing scenario:

  1. Check out 2.3-develop and install sample data
  2. Download n98-magerun2.phar
  3. Run
n98-magerun2.phar dev:console '$di->get(\Magento\Framework\App\State::class)->setAreaCode("webapi_rest"); $di->get(\Magento\Framework\App\Response\Http\FileFactory::class)->create("test-invoice-webapi_rest.pdf", $di->get(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf($di->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class))->render(), \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, "application/pdf");quit;'
n98-magerun2.phar dev:console '$di->get(\Magento\Framework\App\State::class)->setAreaCode("webapi_soap"); $di->get(\Magento\Framework\App\Response\Http\FileFactory::class)->create("test-invoice-webapi_soap.pdf", $di->get(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf($di->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class))->render(), \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, "application/pdf");quit;'
n98-magerun2.phar dev:console '$di->get(\Magento\Framework\App\State::class)->setAreaCode("adminhtml"); $di->get(\Magento\Framework\App\Response\Http\FileFactory::class)->create("test-invoice-adminhtml.pdf", $di->get(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf($di->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class))->render(), \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, "application/pdf");quit;'
n98-magerun2.phar dev:console '$di->get(\Magento\Framework\App\State::class)->setAreaCode("frontend"); $di->get(\Magento\Framework\App\Response\Http\FileFactory::class)->create("test-invoice-frontend.pdf", $di->get(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf($di->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class))->render(), \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, "application/pdf");quit;'
n98-magerun2.phar dev:console '$di->get(\Magento\Framework\App\State::class)->setAreaCode("crontab"); $di->get(\Magento\Framework\App\Response\Http\FileFactory::class)->create("test-invoice-crontab.pdf", $di->get(\Magento\Sales\Model\Order\Pdf\Invoice::class)->getPdf($di->get(\Magento\Sales\Model\ResourceModel\Order\Invoice\Collection::class))->render(), \Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR, "application/pdf");quit;'
  1. In the PDF's in the var dir, the Payment Method is rendered only in the adminhtml file.

Check out my changes and run rm -rf var/cache/* generated/*.
Then repeat the steps above to see rendered payment methods in the resulting PDF files.

@sidolov sidolov removed Partner: Kega partners-contribution Pull Request is created by Magento Partner labels Feb 4, 2019
@magento-engcom-team magento-engcom-team added Partner: Kega partners-contribution Pull Request is created by Magento Partner labels Feb 4, 2019
@sidolov sidolov removed the partners-contribution Pull Request is created by Magento Partner label Feb 4, 2019
@ghost
Copy link

ghost commented Feb 25, 2019

Hi @AntonEvers, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants