Skip to content

Commit 697f7fe

Browse files
committed
updated store id
1 parent 323a2e8 commit 697f7fe

File tree

6 files changed

+66
-28
lines changed

6 files changed

+66
-28
lines changed

Controller/Reviews/Save.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ public function execute()
237237
$codes = $couponGenerator->generateCodes($coupon);
238238
$dataEmail['couponcode'] = $codes?$codes[0]:"";
239239
}
240-
$this->sender->sendCouponCodeEmail($dataEmail);
240+
$emailTemplate = $this->helper->getProductEmailTemplate($this->storeManager->getStore()->getId());
241+
$this->sender->sendCouponCodeEmail($dataEmail, $this->storeManager->getStore()->getId() , $emailTemplate);
241242

242243
/** Update review rating detailed summary */
243244
$this->summaryRate->execute($product->getSku(), $product->getId());

Cron/AutoSendReminders.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public function execute()
9898
'email' => $data->getEmail(),
9999
'product_id' => $data->getProductId(),
100100
'order_increment_id' => $order_increment_id,
101-
'order_id' => $orderId
101+
'order_id' => $orderId,
102+
'store_id' => $data->getStoreId()
102103
];
103104
}
104105
$currentDate = new \DateTime();

Helper/Data.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
4040
const XML_PATH_EMAIL_TEMPLATE = 'lof_product_reviews/email_settings/email_templates';
4141
const XML_PATH_REPLY_EMAIL_TEMPLATE = 'lof_product_reviews/email_settings/reply_email_templates';
4242
const XML_SEND_REMINDER_AUTO = 'lof_product_reviews/email_settings/send_emails_automatically';
43+
const XML_PATH_EMAIL_PRODUCT_TEMPLATE = 'lof_product_reviews/email_settings/review_product_templates';
4344

4445
/**
4546
* @var string
@@ -184,7 +185,7 @@ public function getImageHeight()
184185
}
185186

186187
/**
187-
* Retrieve Email Template
188+
* Retrieve Notify Email Template
188189
*
189190
* @param int $store
190191
* @return mixed
@@ -199,7 +200,22 @@ public function getEmailTemplate($store = null)
199200
}
200201

201202
/**
202-
* Retrieve Email Template
203+
* Retrieve Product Review Email Template
204+
*
205+
* @param int $store
206+
* @return mixed
207+
*/
208+
public function getProductEmailTemplate($store = null)
209+
{
210+
return $this->scopeConfig->getValue(
211+
self::XML_PATH_EMAIL_PRODUCT_TEMPLATE,
212+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
213+
$store
214+
);
215+
}
216+
217+
/**
218+
* Retrieve Reply Email Template
203219
*
204220
* @param int $store
205221
* @return mixed

Model/Reminders.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,22 @@ public function send($customerInfo = [])
124124
];
125125

126126
if ($customerInfo) {
127-
$tmp_customerInfo = [];
127+
$tmpCustomerInfo = [];
128128
foreach ($customerInfo as $key => $customer) {
129-
if (!isset($tmp_customerInfo[$customer['order_id']])) {
130-
$tmp_customerInfo[$customer['order_id']] = $customer;
131-
$tmp_customerInfo[$customer['order_id']]['products'] = [];
132-
$tmp_customerInfo[$customer['order_id']]['products'][] = $customer['product_id'];
129+
$customer['store_id'] = isset($customer['store_id']) ? (int)($customer['store_id']) : \Magento\Store\Model\Store::DEFAULT_STORE_ID;
130+
if (!isset($tmpCustomerInfo[$customer['order_id']])) {
131+
$tmpCustomerInfo[$customer['order_id']] = $customer;
132+
$tmpCustomerInfo[$customer['order_id']]['products'] = [];
133+
$tmpCustomerInfo[$customer['order_id']]['products'][] = $customer['product_id'];
133134
} else {
134-
$tmp_customerInfo[$customer['order_id']]['products'][] = $customer['product_id'];
135+
$tmpCustomerInfo[$customer['order_id']]['products'][] = $customer['product_id'];
135136
}
137+
136138
}
137-
$customerInfo = $tmp_customerInfo;
139+
$customerInfo = $tmpCustomerInfo;
138140
}
139141
foreach ($customerInfo as $data) {
142+
$storeId = isset($data['store_id']) ? (int)($data['store_id']) : \Magento\Store\Model\Store::DEFAULT_STORE_ID;
140143
$recipient = [
141144
'name' => $this->_escaper->escapeHtml($data['name']),
142145
'email' => $this->_escaper->escapeHtml($data['email']),
@@ -154,7 +157,7 @@ public function send($customerInfo = [])
154157
foreach ($product_ids as $product_id) {
155158
$product = $this->_product->load($product_id);
156159
$productName = $product->getName();
157-
$product->setStoreId($this->_storeManager->getStore()->getId());
160+
$product->setStoreId($storeId);
158161
$productUrl = $product->getProductUrl();
159162
$tmp = ['product_name' => $productName, 'product_url' => $productUrl];
160163
$products[] = $tmp;
@@ -171,16 +174,18 @@ public function send($customerInfo = [])
171174
'email' => $recipient['email'],
172175
'products' => $products_html,
173176
'order_increment_id' => $orderIncrementId,
174-
'order_id' => $orderId
177+
'order_id' => $orderId,
178+
'store_id' => $storeId
175179
]
176180
);
177-
181+
$emailTemplate = $this->_dataHelper->getEmailTemplate($storeId);
182+
$emailTemplate = $emailTemplate ? $emailTemplate : 'lof_product_reviews_email_settings_email_templates';
178183
$transportBuilder = $this->_transportBuilder->setTemplateIdentifier(
179-
'lof_product_reviews_email_settings_email_templates'
184+
$emailTemplate
180185
)->setTemplateOptions(
181186
[
182187
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
183-
'store' => $this->_storeManager->getStore()->getId(),
188+
'store' => $storeId,
184189
]
185190
)->setFrom(
186191
$sender

Model/Sender.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Magento\Customer\Model\Session;
2626
use Magento\Framework\App\Config\ScopeConfigInterface;
2727
use Magento\Store\Model\ScopeInterface;
28+
use Lof\ProductReviews\Helper\Data;
2829

2930
/**
3031
* Class Sender
@@ -102,13 +103,15 @@ public function __construct(
102103
}
103104

104105
/**
105-
* @param $data
106+
* @param mixed $data
107+
* @param int|null $storeId
106108
*/
107-
public function sendCouponCodeEmail($data)
109+
public function sendCouponCodeEmail($data, $storeId = null, $emailTemplate = "lof_product_reviews_email_settings_review_product_templates")
108110
{
109111
$sender ['email'] = $this->scopeConfig->getValue(
110112
self::SENDER_EMAIL,
111-
ScopeInterface::SCOPE_STORE
113+
ScopeInterface::SCOPE_STORE,
114+
$storeId
112115
);
113116
$sender['name'] = 'admin';
114117
try {
@@ -123,23 +126,23 @@ public function sendCouponCodeEmail($data)
123126
)->getData();
124127
$customerEmail = $customer[0]['email'];
125128
$transport = $this->_transportBuilder
126-
->setTemplateIdentifier('lof_product_reviews_email_settings_review_product_templates')
129+
->setTemplateIdentifier($emailTemplate)
127130
->setTemplateOptions(
128131
[
129132
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
130-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
133+
'store' => $storeId ? (int)$storeId : \Magento\Store\Model\Store::DEFAULT_STORE_ID,
131134
]
132135
)
133136
->setTemplateVars(['data' => $postObject])
134137
->setFrom($sender)->addTo($customerEmail)->getTransport();
135138

136139
} else {
137140
$transport = $this->_transportBuilder
138-
->setTemplateIdentifier('lof_product_reviews_email_settings_review_product_templates')
141+
->setTemplateIdentifier($emailTemplate)
139142
->setTemplateOptions(
140143
[
141144
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
142-
'store' => \Magento\Store\Model\Store::DEFAULT_STORE_ID,
145+
'store' => $storeId ? (int)$storeId : \Magento\Store\Model\Store::DEFAULT_STORE_ID,
143146
]
144147
)
145148
->setTemplateVars(['data' => $postObject])

Plugin/Adminhtml/Save.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ public function aroundExecute(\Magento\Review\Controller\Adminhtml\Product\Save
145145
{
146146
$reviewId = $object->getRequest()->getParam('id');
147147
$data = $object->getRequest()->getPostValue();
148+
$stores = isset($data['stores']) ? $data['stores'] : [];
149+
$storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
150+
if ($stores) {
151+
foreach ($stores as $_storeId) {
152+
if ($_storeId) {
153+
$storeId = $_storeId;
154+
break;
155+
}
156+
}
157+
}
148158
$current_admin_user = $this->getCurrentUser();
149159
$admin_user_id = 0;
150160
$email_address = "";
@@ -172,7 +182,7 @@ public function aroundExecute(\Magento\Review\Controller\Adminhtml\Product\Save
172182
$title = htmlspecialchars($data['reply_title']);
173183
$message = nl2br(htmlspecialchars($data['reply_comment']));
174184

175-
$this->sendReplyToCustomer($sender, $recipient, $title, $message);
185+
$this->sendReplyToCustomer($sender, $recipient, $title, $message, $storeId);
176186
}
177187
$email_address = isset($data['email_address']) ? $data['email_address'] : '';
178188
$avatar_url = isset($data['avatar_url']) ? $data['avatar_url'] : '';
@@ -240,7 +250,7 @@ public function aroundExecute(\Magento\Review\Controller\Adminhtml\Product\Save
240250
$modelGallery->setReviewId($reviewId)
241251
->setLabel('Gallery of Review ' . $reviewId)
242252
->setStatus(\Lof\ProductReviews\Model\Gallery::STATUS_DISABLED)
243-
->setValue(json_encode([]))
253+
->setValue(@json_encode([]))
244254
->save();
245255
}
246256

@@ -252,13 +262,15 @@ public function aroundExecute(\Magento\Review\Controller\Adminhtml\Product\Save
252262
* @param $recipient
253263
* @param $title
254264
* @param $message
265+
* @param int|null $storeId
255266
* @return $this
256267
* @throws \Magento\Framework\Exception\LocalizedException
257268
* @throws \Magento\Framework\Exception\MailException
258269
* @throws \Magento\Framework\Exception\NoSuchEntityException
259270
*/
260-
public function sendReplyToCustomer($sender, $recipient, $title, $message)
271+
public function sendReplyToCustomer($sender, $recipient, $title, $message, $storeId = null)
261272
{
273+
$storeId = $storeId ? (int)$storeId : \Magento\Store\Model\Store::DEFAULT_STORE_ID;
262274
$this->inlineTranslation->suspend();
263275

264276
$dataObj = $this->_dataObjectFactory->create()->setData(
@@ -273,11 +285,11 @@ public function sendReplyToCustomer($sender, $recipient, $title, $message)
273285
);
274286

275287
$this->_transportBuilder->setTemplateIdentifier(
276-
$this->_dataHelper->getReplyEmailTemplate()
288+
$this->_dataHelper->getReplyEmailTemplate($storeId)
277289
)->setTemplateOptions(
278290
[
279291
'area' => \Magento\Framework\App\Area::AREA_FRONTEND,
280-
'store' => $this->_storeManager->getStore()->getId(),
292+
'store' => $storeId,
281293
]
282294
)->setFrom(
283295
$sender

0 commit comments

Comments
 (0)