Skip to content

Commit d425ca8

Browse files
luigifabfballiano
authored andcommitted
Do not startEnvironmentEmulation when target is current store (#1578)
1 parent 7115c24 commit d425ca8

File tree

5 files changed

+50
-26
lines changed

5 files changed

+50
-26
lines changed

app/code/core/Mage/Core/Model/Template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected function _applyDesignConfig()
7171
$store = $designConfig->getStore();
7272
$storeId = is_object($store) ? $store->getId() : $store;
7373
$area = $designConfig->getArea();
74-
if (!is_null($storeId)) {
74+
if (!is_null($storeId) && ($storeId != Mage::app()->getStore()->getId())) {
7575
$appEmulation = Mage::getSingleton('core/app_emulation');
7676
$this->_initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId, $area);
7777
}

app/code/core/Mage/Sales/Model/Order.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,24 +1388,30 @@ public function queueNewOrderEmail($forceMode = false)
13881388
$copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
13891389

13901390
// Start store emulation process
1391-
/** @var Mage_Core_Model_App_Emulation $appEmulation */
1392-
$appEmulation = Mage::getSingleton('core/app_emulation');
1393-
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
1391+
if ($storeId != Mage::app()->getStore()->getId()) {
1392+
/** @var Mage_Core_Model_App_Emulation $appEmulation */
1393+
$appEmulation = Mage::getSingleton('core/app_emulation');
1394+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
1395+
}
13941396

13951397
try {
13961398
// Retrieve specified view block from appropriate design package (depends on emulated store)
13971399
$paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
13981400
->setIsSecureMode(true);
13991401
$paymentBlock->getMethod()->setStore($storeId);
14001402
$paymentBlockHtml = $paymentBlock->toHtml();
1401-
} catch (Exception $exception) {
1403+
} catch (Exception $e) {
14021404
// Stop store emulation process
1403-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1404-
throw $exception;
1405+
if (isset($appEmulation, $initialEnvironmentInfo)) {
1406+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1407+
}
1408+
throw $e;
14051409
}
14061410

14071411
// Stop store emulation process
1408-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1412+
if (isset($appEmulation, $initialEnvironmentInfo)) {
1413+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1414+
}
14091415

14101416
// Retrieve corresponding email template id and customer name
14111417
if ($this->getCustomerIsGuest()) {

app/code/core/Mage/Sales/Model/Order/Creditmemo.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -768,23 +768,29 @@ public function sendEmail($notifyCustomer = true, $comment = '')
768768
}
769769

770770
// Start store emulation process
771-
$appEmulation = Mage::getSingleton('core/app_emulation');
772-
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
771+
if ($storeId != Mage::app()->getStore()->getId()) {
772+
$appEmulation = Mage::getSingleton('core/app_emulation');
773+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
774+
}
773775

774776
try {
775777
// Retrieve specified view block from appropriate design package (depends on emulated store)
776778
$paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
777779
->setIsSecureMode(true);
778780
$paymentBlock->getMethod()->setStore($storeId);
779781
$paymentBlockHtml = $paymentBlock->toHtml();
780-
} catch (Exception $exception) {
782+
} catch (Exception $e) {
781783
// Stop store emulation process
782-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
783-
throw $exception;
784+
if (isset($appEmulation, $initialEnvironmentInfo)) {
785+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
786+
}
787+
throw $e;
784788
}
785789

786790
// Stop store emulation process
787-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
791+
if (isset($appEmulation, $initialEnvironmentInfo)) {
792+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
793+
}
788794

789795
// Retrieve corresponding email template id and customer name
790796
if ($order->getCustomerIsGuest()) {

app/code/core/Mage/Sales/Model/Order/Invoice.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -803,23 +803,29 @@ public function sendEmail($notifyCustomer = true, $comment = '')
803803
}
804804

805805
// Start store emulation process
806-
$appEmulation = Mage::getSingleton('core/app_emulation');
807-
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
806+
if ($storeId != Mage::app()->getStore()->getId()) {
807+
$appEmulation = Mage::getSingleton('core/app_emulation');
808+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
809+
}
808810

809811
try {
810812
// Retrieve specified view block from appropriate design package (depends on emulated store)
811813
$paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
812814
->setIsSecureMode(true);
813815
$paymentBlock->getMethod()->setStore($storeId);
814816
$paymentBlockHtml = $paymentBlock->toHtml();
815-
} catch (Exception $exception) {
817+
} catch (Exception $e) {
816818
// Stop store emulation process
817-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
818-
throw $exception;
819+
if (isset($appEmulation, $initialEnvironmentInfo)) {
820+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
821+
}
822+
throw $e;
819823
}
820824

821825
// Stop store emulation process
822-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
826+
if (isset($appEmulation, $initialEnvironmentInfo)) {
827+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
828+
}
823829

824830
// Retrieve corresponding email template id and customer name
825831
if ($order->getCustomerIsGuest()) {

app/code/core/Mage/Sales/Model/Order/Shipment.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,23 +443,29 @@ public function sendEmail($notifyCustomer = true, $comment = '')
443443
}
444444

445445
// Start store emulation process
446-
$appEmulation = Mage::getSingleton('core/app_emulation');
447-
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
446+
if ($storeId != Mage::app()->getStore()->getId()) {
447+
$appEmulation = Mage::getSingleton('core/app_emulation');
448+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
449+
}
448450

449451
try {
450452
// Retrieve specified view block from appropriate design package (depends on emulated store)
451453
$paymentBlock = Mage::helper('payment')->getInfoBlock($order->getPayment())
452454
->setIsSecureMode(true);
453455
$paymentBlock->getMethod()->setStore($storeId);
454456
$paymentBlockHtml = $paymentBlock->toHtml();
455-
} catch (Exception $exception) {
457+
} catch (Exception $e) {
456458
// Stop store emulation process
457-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
458-
throw $exception;
459+
if (isset($appEmulation, $initialEnvironmentInfo)) {
460+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
461+
}
462+
throw $e;
459463
}
460464

461465
// Stop store emulation process
462-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
466+
if (isset($appEmulation, $initialEnvironmentInfo)) {
467+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
468+
}
463469

464470
// Retrieve corresponding email template id and customer name
465471
if ($order->getCustomerIsGuest()) {

0 commit comments

Comments
 (0)