Skip to content

Commit 712a3ee

Browse files
authored
Do not startEnvironmentEmulation when target is current store (#1578)
1 parent e24dc16 commit 712a3ee

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
@@ -1383,24 +1383,30 @@ public function queueNewOrderEmail($forceMode = false)
13831383
$copyMethod = Mage::getStoreConfig(self::XML_PATH_EMAIL_COPY_METHOD, $storeId);
13841384

13851385
// Start store emulation process
1386-
/** @var Mage_Core_Model_App_Emulation $appEmulation */
1387-
$appEmulation = Mage::getSingleton('core/app_emulation');
1388-
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
1386+
if ($storeId != Mage::app()->getStore()->getId()) {
1387+
/** @var Mage_Core_Model_App_Emulation $appEmulation */
1388+
$appEmulation = Mage::getSingleton('core/app_emulation');
1389+
$initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($storeId);
1390+
}
13891391

13901392
try {
13911393
// Retrieve specified view block from appropriate design package (depends on emulated store)
13921394
$paymentBlock = Mage::helper('payment')->getInfoBlock($this->getPayment())
13931395
->setIsSecureMode(true);
13941396
$paymentBlock->getMethod()->setStore($storeId);
13951397
$paymentBlockHtml = $paymentBlock->toHtml();
1396-
} catch (Exception $exception) {
1398+
} catch (Exception $e) {
13971399
// Stop store emulation process
1398-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1399-
throw $exception;
1400+
if (isset($appEmulation, $initialEnvironmentInfo)) {
1401+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1402+
}
1403+
throw $e;
14001404
}
14011405

14021406
// Stop store emulation process
1403-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1407+
if (isset($appEmulation, $initialEnvironmentInfo)) {
1408+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
1409+
}
14041410

14051411
// Retrieve corresponding email template id and customer name
14061412
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
@@ -769,23 +769,29 @@ public function sendEmail($notifyCustomer = true, $comment = '')
769769
}
770770

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

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

787791
// Stop store emulation process
788-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
792+
if (isset($appEmulation, $initialEnvironmentInfo)) {
793+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
794+
}
789795

790796
// Retrieve corresponding email template id and customer name
791797
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
@@ -804,23 +804,29 @@ public function sendEmail($notifyCustomer = true, $comment = '')
804804
}
805805

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

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

822826
// Stop store emulation process
823-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
827+
if (isset($appEmulation, $initialEnvironmentInfo)) {
828+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
829+
}
824830

825831
// Retrieve corresponding email template id and customer name
826832
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
@@ -444,23 +444,29 @@ public function sendEmail($notifyCustomer = true, $comment = '')
444444
}
445445

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

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

462466
// Stop store emulation process
463-
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
467+
if (isset($appEmulation, $initialEnvironmentInfo)) {
468+
$appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo);
469+
}
464470

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

0 commit comments

Comments
 (0)