7
7
namespace Magento \Wishlist \Controller \Index ;
8
8
9
9
use Magento \Framework \App \Action ;
10
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
10
11
use Magento \Framework \Exception \NotFoundException ;
12
+ use Magento \Framework \Session \Generic as WishlistSession ;
13
+ use Magento \Store \Model \StoreManagerInterface ;
11
14
use Magento \Wishlist \Controller \IndexInterface ;
12
15
use Magento \Framework \Controller \ResultFactory ;
13
16
use Magento \Framework \View \Result \Layout as ResultLayout ;
@@ -52,6 +55,21 @@ class Send extends Action\Action implements IndexInterface
52
55
*/
53
56
protected $ _formKeyValidator ;
54
57
58
+ /**
59
+ * @var WishlistSession
60
+ */
61
+ protected $ wishlistSession ;
62
+
63
+ /**
64
+ * @var ScopeConfigInterface
65
+ */
66
+ protected $ scopeConfig ;
67
+
68
+ /**
69
+ * @var StoreManagerInterface
70
+ */
71
+ protected $ storeManager ;
72
+
55
73
/**
56
74
* @param Action\Context $context
57
75
* @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
@@ -70,7 +88,10 @@ public function __construct(
70
88
\Magento \Wishlist \Model \Config $ wishlistConfig ,
71
89
\Magento \Framework \Mail \Template \TransportBuilder $ transportBuilder ,
72
90
\Magento \Framework \Translate \Inline \StateInterface $ inlineTranslation ,
73
- \Magento \Customer \Helper \View $ customerHelperView
91
+ \Magento \Customer \Helper \View $ customerHelperView ,
92
+ WishlistSession $ wishlistSession ,
93
+ ScopeConfigInterface $ scopeConfig ,
94
+ StoreManagerInterface $ storeManager
74
95
) {
75
96
$ this ->_formKeyValidator = $ formKeyValidator ;
76
97
$ this ->_customerSession = $ customerSession ;
@@ -79,6 +100,9 @@ public function __construct(
79
100
$ this ->_transportBuilder = $ transportBuilder ;
80
101
$ this ->inlineTranslation = $ inlineTranslation ;
81
102
$ this ->_customerHelperView = $ customerHelperView ;
103
+ $ this ->wishlistSession = $ wishlistSession ;
104
+ $ this ->scopeConfig = $ scopeConfig ;
105
+ $ this ->storeManager = $ storeManager ;
82
106
parent ::__construct ($ context );
83
107
}
84
108
@@ -108,7 +132,10 @@ public function execute()
108
132
$ sharingLimit = $ this ->_wishlistConfig ->getSharingEmailLimit ();
109
133
$ textLimit = $ this ->_wishlistConfig ->getSharingTextLimit ();
110
134
$ emailsLeft = $ sharingLimit - $ wishlist ->getShared ();
111
- $ emails = explode (', ' , $ this ->getRequest ()->getPost ('emails ' ));
135
+
136
+ $ emails = $ this ->getRequest ()->getPost ('emails ' );
137
+ $ emails = empty ($ emails ) ? $ emails : explode (', ' , $ emails );
138
+
112
139
$ error = false ;
113
140
$ message = (string )$ this ->getRequest ()->getPost ('message ' );
114
141
if (strlen ($ message ) > $ textLimit ) {
@@ -135,11 +162,7 @@ public function execute()
135
162
136
163
if ($ error ) {
137
164
$ this ->messageManager ->addError ($ error );
138
- $ this ->_objectManager ->get (
139
- 'Magento\Wishlist\Model\Session '
140
- )->setSharingForm (
141
- $ this ->getRequest ()->getPostValue ()
142
- );
165
+ $ this ->wishlistSession ->setSharingForm ($ this ->getRequest ()->getPostValue ());
143
166
$ resultRedirect ->setPath ('*/*/share ' );
144
167
return $ resultRedirect ;
145
168
}
@@ -159,32 +182,29 @@ public function execute()
159
182
$ sharingCode = $ wishlist ->getSharingCode ();
160
183
161
184
try {
162
- $ scopeConfig = $ this ->_objectManager ->get ('Magento\Framework\App\Config\ScopeConfigInterface ' );
163
- $ storeManager = $ this ->_objectManager ->get ('Magento\Store\Model\StoreManagerInterface ' );
164
185
foreach ($ emails as $ email ) {
165
186
$ transport = $ this ->_transportBuilder ->setTemplateIdentifier (
166
- $ scopeConfig ->getValue (
187
+ $ this -> scopeConfig ->getValue (
167
188
'wishlist/email/email_template ' ,
168
189
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
169
190
)
170
191
)->setTemplateOptions (
171
192
[
172
193
'area ' => \Magento \Framework \App \Area::AREA_FRONTEND ,
173
- 'store ' => $ storeManager ->getStore ()->getStoreId (),
194
+ 'store ' => $ this -> storeManager ->getStore ()->getStoreId (),
174
195
]
175
196
)->setTemplateVars (
176
197
[
177
198
'customer ' => $ customer ,
178
199
'customerName ' => $ customerName ,
179
200
'salable ' => $ wishlist ->isSalable () ? 'yes ' : '' ,
180
201
'items ' => $ this ->getWishlistItems ($ resultLayout ),
181
- 'addAllLink ' => $ this ->_url ->getUrl ('*/shared/allcart ' , ['code ' => $ sharingCode ]),
182
202
'viewOnSiteLink ' => $ this ->_url ->getUrl ('*/shared/index ' , ['code ' => $ sharingCode ]),
183
203
'message ' => $ message ,
184
- 'store ' => $ storeManager ->getStore (),
204
+ 'store ' => $ this -> storeManager ->getStore (),
185
205
]
186
206
)->setFrom (
187
- $ scopeConfig ->getValue (
207
+ $ this -> scopeConfig ->getValue (
188
208
'wishlist/email/email_identity ' ,
189
209
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
190
210
)
@@ -213,11 +233,7 @@ public function execute()
213
233
} catch (\Exception $ e ) {
214
234
$ this ->inlineTranslation ->resume ();
215
235
$ this ->messageManager ->addError ($ e ->getMessage ());
216
- $ this ->_objectManager ->get (
217
- 'Magento\Wishlist\Model\Session '
218
- )->setSharingForm (
219
- $ this ->getRequest ()->getPostValue ()
220
- );
236
+ $ this ->wishlistSession ->setSharingForm ($ this ->getRequest ()->getPostValue ());
221
237
$ resultRedirect ->setPath ('*/*/share ' );
222
238
return $ resultRedirect ;
223
239
}
0 commit comments