Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
Shopware_Components_StringCompiler example
$userId
=
$params
[
'userId'
]
;
$status
=
$params
[
'status'
]
;
if
(
!
$toMail
|| !
$fromName
|| !
$fromMail
|| !
$subject
|| !
$content
|| !
$userId
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false, 'message' => 'All required fields needs to be filled.'
]
)
;
return
;
}
$content
=
preg_replace
(
'`<br(?: /)?>([\\n\\r])`', '$1',
$params
[
'content'
]
)
;
$compiler
=
new
Shopware_Components_StringCompiler
(
$this
->
View
(
)
->
Engine
(
)
)
;
$defaultContext
=
[
'sConfig' =>
Shopware
(
)
->
Config
(
)
,
]
;
$compiler
->
setContext
(
$defaultContext
)
;
// Send eMail to customer
$mail
->
IsHTML
(
false
)
;
$mail
->From =
$compiler
->
compileString
(
$fromMail
)
;
$mail
->FromName =
$compiler
->
compileString
(
$fromName
)
;
$mail
->Subject =
$compiler
->
compileString
(
$subject
)
;
$mail
->Body =
$compiler
->
compileString
(
$content
)
;
use
Shopware_Components_TemplateMail;
class
TemplateMail
{
/** * @return Shopware_Components_TemplateMail */
public
function
factory
(
Container
$container
)
{
$container
->
load
(
'mailtransport'
)
;
$stringCompiler
=
new
Shopware_Components_StringCompiler
(
$container
->
get
(
Enlight_Template_Manager::
class
)
)
;
$mailer
=
new
Shopware_Components_TemplateMail
(
)
;
if
(
$container
->
initialized
(
'shop'
)
)
{
$shop
=
$container
->
get
(
'shop'
)
;
if
(
!
$shop
instanceof Shop
)
{
throw
new
RuntimeException
(
'Shop object not found in DI container'
)
;
}
$mailer
->
setShop
(
$shop
)
;
}
$mailer
->
setModelManager
(
$container
->
get
(
ModelManager::
class
)
)
;
$mail
=
$this
->
getRepository
(
)
->
find
(
$id
)
;
if
(
!
$mail
instanceof Mail
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false, 'message' => 'Mail not found'
]
)
;
return
;
}
if
(
!
(
$value
=
$this
->
Request
(
)
->
getParam
(
'value'
)
)
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false, 'message' => 'Value not found'
]
)
;
}
$compiler
=
new
Shopware_Components_StringCompiler
(
$this
->
View
(
)
->
Engine
(
)
)
;
$shop
=
$this
->
get
(
'models'
)
->
getRepository
(
Shop::
class
)
->
getActiveDefault
(
)
;
$this
->
get
(
ShopRegistrationServiceInterface::
class
)
->
registerShop
(
$shop
)
;
$compiler
->
setContext
(
array_merge
(
$this
->
getDefaultMailContext
(
$shop
)
,
$mail
->
getContext
(
)
)
)
;
try
{
$template
=
$compiler
->
compileString
(
$value
)
;
}
catch
(
Enlight_Exception
$e
)
{
$this
->
View
(
)
->
assign
(
[
'success' => false, 'message' =>
$e
->
getMessage
(
)
]
)
;