diff --git a/classes/Mail.php b/classes/Mail.php index bc09523d1..12d315516 100644 --- a/classes/Mail.php +++ b/classes/Mail.php @@ -245,7 +245,7 @@ class MailCore else $template_vars['{shop_logo}'] = ''; } - + ShopUrl::cacheMainDomainForShop((int)$id_shop); /* don't attach the logo as */ if (isset($logo)) $template_vars['{shop_logo}'] = $message->attach(new Swift_Message_EmbeddedFile(new Swift_File($logo), null, ImageManager::getMimeTypeByExtension($logo))); @@ -274,6 +274,9 @@ class MailCore /* Send mail */ $send = $swift->send($message, $to, new Swift_Address($from, $from_name)); $swift->disconnect(); + + ShopUrl::resetMainDomainCache(); + return $send; } catch (Swift_Exception $e) { diff --git a/classes/PaymentModule.php b/classes/PaymentModule.php index f23fd83b7..e19f2947b 100644 --- a/classes/PaymentModule.php +++ b/classes/PaymentModule.php @@ -135,6 +135,8 @@ abstract class PaymentModuleCore extends Module $this->context->customer = new Customer($this->context->cart->id_customer); $this->context->language = new Language($this->context->cart->id_lang); $this->context->shop = ($shop ? $shop : new Shop($this->context->cart->id_shop)); + ShopUrl::resetMainDomainCache(); + $id_currency = $currency_special ? (int)$currency_special : (int)$this->context->cart->id_currency; $this->context->currency = new Currency($id_currency, null, $this->context->shop->id); if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_delivery') diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index 5205dc72f..853d15450 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -85,6 +85,8 @@ class OrderHistoryCore extends ObjectModel else return; + ShopUrl::cacheMainDomainForShop($order->id_shop); + $new_os = new OrderState((int)$new_order_state, $order->id_lang); $old_os = $order->getCurrentOrderState(); $is_validated = $this->isValidated(); @@ -326,6 +328,8 @@ class OrderHistoryCore extends ObjectModel 'newOrderStatus' => $new_os, 'id_order' => (int)$order->id, )); + + ShopUrl::resetMainDomainCache(); } /** @@ -377,6 +381,8 @@ class OrderHistoryCore extends ObjectModel WHERE oh.`id_order_history` = '.(int)$this->id.' AND os.`send_email` = 1'); if (isset($result['template']) && Validate::isEmail($result['email'])) { + ShopUrl::cacheMainDomainForShop($order->id_shop); + $topic = $result['osname']; $data = array( '{lastname}' => $result['lastname'], @@ -400,6 +406,8 @@ class OrderHistoryCore extends ObjectModel if (Validate::isLoadedObject($order)) Mail::Send((int)$order->id_lang, $result['template'], $topic, $data, $result['email'], $result['firstname'].' '.$result['lastname'], null, null, null, null, _PS_MAIL_DIR_, false, (int)$order->id_shop); + + ShopUrl::resetMainDomainCache(); } return true; diff --git a/classes/shop/ShopUrl.php b/classes/shop/ShopUrl.php index 62d43aaa9..c30bb2676 100644 --- a/classes/shop/ShopUrl.php +++ b/classes/shop/ShopUrl.php @@ -143,25 +143,39 @@ class ShopUrlCore extends ObjectModel return Db::getInstance()->getValue($sql); } - public static function getMainShopDomain() + public static function getMainShopDomain($id_shop = null) { - if (!self::$main_domain) + if (!self::$main_domain || $id_shop !== null) self::$main_domain = Db::getInstance()->getValue('SELECT domain FROM '._DB_PREFIX_.'shop_url - WHERE main=1 AND id_shop = '.Context::getContext()->shop->id); + WHERE main=1 AND id_shop = '.($id_shop !== null ? (int)$id_shop : Context::getContext()->shop->id)); return self::$main_domain; } - public static function getMainShopDomainSSL() + public static function cacheMainDomainForShop($id_shop) { - if (!self::$main_domain_ssl) - { + if (!Validate::isUnsignedId($id_shop)) + return false; + + ShopUrl::getMainShopDomain($id_shop); + ShopUrl::getMainShopDomainSSL($id_shop); + } + + public static function resetMainDomainCache() + { + self::$main_domain = null; + self::$main_domain_ssl = null; + } + + + public static function getMainShopDomainSSL($id_shop = null) + { + if (!self::$main_domain_ssl || $id_shop !== null) $sql = 'SELECT domain_ssl FROM '._DB_PREFIX_.'shop_url WHERE main = 1 - AND id_shop='.Context::getContext()->shop->id; + AND id_shop = '.($id_shop !== null ? (int)$id_shop : Context::getContext()->shop->id); self::$main_domain_ssl = Db::getInstance()->getValue($sql); - } return self::$main_domain_ssl; } } diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index b678cc1d4..d97b0fded 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -373,6 +373,9 @@ class AdminCustomerThreadsControllerCore extends AdminController if (Tools::isSubmit('submitReply')) { $ct = new CustomerThread($id_customer_thread); + + ShopUrl::cacheMainDomainForShop((int)$ct->id_shop); + $cm = new CustomerMessage(); $cm->id_employee = (int)$this->context->employee->id; $cm->id_customer_thread = $ct->id; diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index 18f858e77..6da191cd1 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -268,6 +268,8 @@ class AdminOrdersControllerCore extends AdminController throw new PrestaShopException('Can\'t load Order object'); } + ShopUrl::cacheMainDomainForShop((int)$order->id_shop); + /* Update shipping number */ if (Tools::isSubmit('submitShippingNumber') && isset($order)) {