Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/tell a friend #2568

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24645,31 +24645,6 @@ parameters:
count: 1
path: engine/Shopware/Controllers/Frontend/Sitemap.php

-
message: "#^Access to an undefined property Enlight_Controller_Request_RequestHttp\\:\\:\\$sArticle\\.$#"
count: 1
path: engine/Shopware/Controllers/Frontend/Tellafriend.php

-
message: "#^Method Shopware_Controllers_Frontend_Tellafriend\\:\\:indexAction\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Controllers/Frontend/Tellafriend.php

-
message: "#^Method Shopware_Controllers_Frontend_Tellafriend\\:\\:init\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Controllers/Frontend/Tellafriend.php

-
message: "#^Method Shopware_Controllers_Frontend_Tellafriend\\:\\:successAction\\(\\) has no return type specified\\.$#"
count: 1
path: engine/Shopware/Controllers/Frontend/Tellafriend.php

-
message: "#^Property Shopware_Controllers_Frontend_Tellafriend\\:\\:\\$sSYSTEM has no type specified\\.$#"
count: 1
path: engine/Shopware/Controllers/Frontend/Tellafriend.php

-
message: "#^Property Shopware_Controllers_Frontend_Tracking\\:\\:\\$testRepository has no type specified\\.$#"
count: 1
Expand Down
4 changes: 4 additions & 0 deletions engine/Shopware/Components/TemplateMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public function getStringCompiler()
}

/**
* @deprecated The $overrideConfig parameter will be removed with Shopware 5.8, directly apply the changes to the returned mail component
*
* @param string|Mail $mailModel
* @param array $context
* @param Shop $shop
Expand Down Expand Up @@ -256,6 +258,8 @@ public function createMail($mailModel, $context = [], $shop = null, $overrideCon
/**
* Loads values from MailModel into Mail
*
* @deprecated The $overrideConfig parameter will be removed with Shopware 5.8, directly apply the changes to the returned mail component
*
* @param array $overrideConfig
*
* @throws Enlight_Exception
Expand Down
105 changes: 50 additions & 55 deletions engine/Shopware/Controllers/Frontend/Tellafriend.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,16 @@

class Shopware_Controllers_Frontend_Tellafriend extends Enlight_Controller_Action
{
/**
* @deprecated Will be removed in Shopware 5.8 without replacement
*
* @var \sSystem
*/
public $sSYSTEM;

/**
* @return void
*/
public function init()
{
$this->sSYSTEM = Shopware()->System();
Expand All @@ -43,95 +51,82 @@ public function preDispatch()
}
}

/**
* @return void
*/
public function successAction()
{
$this->View()->loadTemplate('frontend/tellafriend/index.tpl');
$this->View()->assign('sSuccess', true);
}

/**
* @return void
*/
public function indexAction()
{
if (empty($this->Request()->sDetails)) {
$id = $this->Request()->sArticle;
} else {
$id = $this->Request()->sDetails;
}
$productId = (int) ($this->Request()->get('sDetails') ?? $this->Request()->get('sArticle'));
if ($productId === 0) {
$this->forward('index', 'index');

if (empty($id)) {
return $this->forward('index', 'index');
return;
}

// Get Product-Information
$product = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, (int) $id);
if (empty($product['articleName'])) {
return $this->forward('index', 'index');
$product = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, $productId);
if (!isset($product['articleName']) || !isset($product['linkDetails'])
|| !\is_string($product['articleName']) || !\is_string($product['linkDetails'])
|| $product['articleName'] === '' || $product['linkDetails'] === '') {
$this->forward('index', 'index');

return;
}

if ($this->Request()->getPost('sMailTo')) {
$variables['sError'] = false;
if (!$this->Request()->getPost('sName')) {
$variables['sError'] = true;
}
if (!$this->Request()->getPost('sMail')) {
$variables['sError'] = true;
}
if (!$this->Request()->getPost('sRecipient')) {
$variables['sError'] = true;
}
$fromName = $this->Request()->getPost('sName');
$fromMail = $this->Request()->getPost('sMail');
$recipient = $this->Request()->getPost('sRecipient');
$comment = $this->Request()->getPost('sComment', '');

if (preg_match('/;/', $this->Request()->getPost('sRecipient')) || \strlen($this->Request()->getPost('sRecipient')) >= 50) {
$variables['sError'] = true;
}
$emailValidator = $this->container->get(EmailValidator::class);

$validator = $this->container->get(EmailValidator::class);
if (!$validator->isValid($this->Request()->getPost('sRecipient'))) {
$variables['sError'] = true;
}
$validInputParameters = \is_string($fromName) && \is_string($fromMail)
&& \is_string($recipient) && \is_string($comment)
&& !preg_match('/;/', $recipient) && \strlen($recipient) < 50
&& $emailValidator->isValid($fromMail) && $emailValidator->isValid($recipient)
;

if (!empty(Shopware()->Config()->get('CaptchaColor'))) {
if ($validInputParameters && !empty(Shopware()->Config()->get('CaptchaColor'))) {
/** @var \Shopware\Components\Captcha\CaptchaValidator $captchaValidator */
$captchaValidator = $this->container->get('shopware.captcha.validator');

if (!$captchaValidator->validate($this->Request())) {
$variables['sError'] = true;
}
$validInputParameters = $captchaValidator->validate($this->Request());
}

if ($variables['sError'] == false) {
// Prepare eMail
$product['linkDetails'] = $this->Front()->ensureRouter()->assemble(['sViewport' => 'detail', 'sArticle' => $product['articleID']]);

$context = [
'sName' => $this->sSYSTEM->_POST['sName'],
'sArticle' => html_entity_decode($product['articleName']),
if ($validInputParameters) {
$mail = Shopware()->TemplateMail()->createMail('sTELLAFRIEND', [
'sName' => strip_tags($fromName),
'sArticle' => strip_tags($product['articleName']),
'sLink' => $product['linkDetails'],
];

if ($this->sSYSTEM->_POST['sComment']) {
$context['sComment'] = strip_tags(html_entity_decode($this->sSYSTEM->_POST['sComment']));
} else {
$context['sComment'] = '';
}

$mail = Shopware()->TemplateMail()->createMail('sTELLAFRIEND', $context, null, [
'fromMail' => $this->sSYSTEM->_POST['sMail'],
'fromName' => $this->sSYSTEM->_POST['sName'],
'sComment' => strip_tags($comment),
]);

$mail->addTo($this->sSYSTEM->_POST['sRecipient']);
$mail->setFrom($fromMail, $fromName);
$mail->addTo($recipient);

$mail->send();

$this->View()->assign('sSuccess', true);
$url = $this->Front()->ensureRouter()->assemble(['controller' => 'tellafriend', 'action' => 'success']);
$this->redirect($url);
} else {
$this->View()->assign('sError', true);
$this->View()->assign('sName', $this->Request()->getPost('sName'));
$this->View()->assign('sMail', $this->Request()->getPost('sMail'));
$this->View()->assign('sRecipient', $this->Request()->getPost('sRecipient'));
$this->View()->assign('sComment', $this->Request()->getPost('sComment'));
$this->View()->assign('sName', (string) $fromName);
$this->View()->assign('sMail', (string) $fromMail);
$this->View()->assign('sRecipient', (string) $recipient);
$this->View()->assign('sComment', (string) $comment);
}
}

$this->View()->assign('rand', Random::getAlphanumericString(32));
$this->View()->assign('sArticle', $product);
}
Expand Down