Skip to content
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

Fix for admin shipment, creditmemo, invoice pdf emulation #4451

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ class Creditmemo extends AbstractPdf
*/
protected $_storeManager;

/**
* @var \Magento\Store\Model\App\Emulation
*/
protected $_appEmulation;

/**
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Stdlib\StringUtils $string
Expand All @@ -29,6 +34,7 @@ class Creditmemo extends AbstractPdf
* @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Store\Model\App\Emulation $appEmulation
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -47,10 +53,12 @@ public function __construct(
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Store\Model\App\Emulation $appEmulation,
array $data = []
) {
$this->_storeManager = $storeManager;
$this->_localeResolver = $localeResolver;
$this->_appEmulation = $appEmulation;
parent::__construct(
$paymentData,
$string,
Expand Down Expand Up @@ -146,6 +154,7 @@ public function getPdf($creditmemos = [])

foreach ($creditmemos as $creditmemo) {
if ($creditmemo->getStoreId()) {
$this->_appEmulation->startEnvironmentEmulation($creditmemo->getStoreId(), \Magento\Framework\App\Area::AREA_FRONTEND, true);
$this->_localeResolver->emulate($creditmemo->getStoreId());
$this->_storeManager->setCurrentStore($creditmemo->getStoreId());
}
Expand Down Expand Up @@ -183,6 +192,7 @@ public function getPdf($creditmemos = [])
}
$this->_afterGetPdf();
if ($creditmemo->getStoreId()) {
$this->_appEmulation->stopEnvironmentEmulation();
$this->_localeResolver->revert();
}
return $pdf;
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class Invoice extends AbstractPdf
*/
protected $_localeResolver;

/**
* @var \Magento\Store\Model\App\Emulation
*/
protected $_appEmulation;

/**
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Stdlib\StringUtils $string
Expand All @@ -36,6 +41,7 @@ class Invoice extends AbstractPdf
* @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Store\Model\App\Emulation $appEmulation
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -53,10 +59,12 @@ public function __construct(
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Store\Model\App\Emulation $appEmulation,
array $data = []
) {
$this->_storeManager = $storeManager;
$this->_localeResolver = $localeResolver;
$this->_appEmulation = $appEmulation;
parent::__construct(
$paymentData,
$string,
Expand Down Expand Up @@ -127,6 +135,7 @@ public function getPdf($invoices = [])

foreach ($invoices as $invoice) {
if ($invoice->getStoreId()) {
$this->_appEmulation->startEnvironmentEmulation($invoice->getStoreId(), \Magento\Framework\App\Area::AREA_FRONTEND, true);
$this->_localeResolver->emulate($invoice->getStoreId());
$this->_storeManager->setCurrentStore($invoice->getStoreId());
}
Expand Down Expand Up @@ -162,6 +171,7 @@ public function getPdf($invoices = [])
/* Add totals */
$this->insertTotals($page, $invoice);
if ($invoice->getStoreId()) {
$this->_appEmulation->stopEnvironmentEmulation();
$this->_localeResolver->revert();
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/code/Magento/Sales/Model/Order/Pdf/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class Shipment extends AbstractPdf
*/
protected $_localeResolver;

/**
* @var \Magento\Store\Model\App\Emulation
*/
protected $_appEmulation;

/**
* @param \Magento\Payment\Helper\Data $paymentData
* @param \Magento\Framework\Stdlib\StringUtils $string
Expand All @@ -34,6 +39,7 @@ class Shipment extends AbstractPdf
* @param \Magento\Sales\Model\Order\Address\Renderer $addressRenderer
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Locale\ResolverInterface $localeResolver
* @param \Magento\Store\Model\App\Emulation $appEmulation
* @param array $data
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
Expand All @@ -51,10 +57,12 @@ public function __construct(
\Magento\Sales\Model\Order\Address\Renderer $addressRenderer,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Locale\ResolverInterface $localeResolver,
\Magento\Store\Model\App\Emulation $appEmulation,
array $data = []
) {
$this->_storeManager = $storeManager;
$this->_localeResolver = $localeResolver;
$this->_appEmulation = $appEmulation;
parent::__construct(
$paymentData,
$string,
Expand Down Expand Up @@ -118,6 +126,7 @@ public function getPdf($shipments = [])
$this->_setFontBold($style, 10);
foreach ($shipments as $shipment) {
if ($shipment->getStoreId()) {
$this->_appEmulation->startEnvironmentEmulation($shipment->getStoreId(), \Magento\Framework\App\Area::AREA_FRONTEND, true);
$this->_localeResolver->emulate($shipment->getStoreId());
$this->_storeManager->setCurrentStore($shipment->getStoreId());
}
Expand Down Expand Up @@ -153,6 +162,7 @@ public function getPdf($shipments = [])
}
$this->_afterGetPdf();
if ($shipment->getStoreId()) {
$this->_appEmulation->stopEnvironmentEmulation();
$this->_localeResolver->revert();
}
return $pdf;
Expand Down