-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from agorbulin/1.0.0-dev
1.0.0 dev
- Loading branch information
Showing
14 changed files
with
321 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
## Release 1.0.0 (2019-01-20) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Goral\ContactUs\Helper; | ||
|
||
use Magento\Store\Model\ScopeInterface; | ||
|
||
/** | ||
* Class Helper Data | ||
* | ||
* @package Goral\ContactUs\Helper | ||
*/ | ||
class Data extends \Magento\Framework\App\Helper\AbstractHelper | ||
{ | ||
const XML_PATH_ENABLED = 'contactus/general/enabled'; | ||
const XML_PATH_TEMPLATE = 'contactus/general/template'; | ||
|
||
/** | ||
* @param string $scope | ||
* @param null $scopeCode | ||
* | ||
* @return mixed | ||
*/ | ||
public function isEnabled($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null) | ||
{ | ||
return $this->scopeConfig->getValue(self::XML_PATH_ENABLED, $scope, $scopeCode); | ||
} | ||
|
||
/** | ||
* @param string $scope | ||
* @param null $scopeCode | ||
* | ||
* @return mixed | ||
*/ | ||
public function getTemplate($scope = ScopeInterface::SCOPE_STORE, $scopeCode = null) | ||
{ | ||
return $this->scopeConfig->getValue(self::XML_PATH_TEMPLATE, $scope, $scopeCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Goral\ContactUs\Model; | ||
|
||
use Magento\Framework\Validator\AbstractValidator; | ||
use Goral\ContactUs\Api\Data\ContactInterface; | ||
|
||
/** | ||
* Contact Validator | ||
*/ | ||
class ContactValidator extends AbstractValidator | ||
{ | ||
|
||
/** | ||
* Validate contact data | ||
* | ||
* @param ContactInterface $contact | ||
* | ||
* @return bool | ||
* @throws \Zend_Validate_Exception | ||
*/ | ||
public function isValid($contact) | ||
{ | ||
$errors = []; | ||
|
||
if (!\Zend_Validate::is($contact->getName(), 'NotEmpty')) { | ||
$errors['name'] = __('Name can\'t be empty.'); | ||
} | ||
|
||
if (!\Zend_Validate::is($contact->getEmail(), 'NotEmpty')) { | ||
$errors['email'] = __('Email can\'t be empty.'); | ||
} | ||
|
||
if (!\Zend_Validate::is($contact->getComment(), 'NotEmpty')) { | ||
$errors['comment'] = __('Comment can\'t be empty.'); | ||
} | ||
|
||
if (!\Zend_Validate::is($contact->getAnswer(), 'NotEmpty')) { | ||
$errors['answer'] = __('Answer can\'t be empty.'); | ||
} | ||
|
||
$this->_addMessages($errors); | ||
|
||
return empty($errors); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
namespace Goral\ContactUs\Model; | ||
|
||
use Goral\ContactUs\Api\Data\ContactInterface; | ||
use Magento\Framework\Mail\Template\TransportBuilder; | ||
use Magento\Framework\Translate\Inline\StateInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Framework\App\Area; | ||
use Goral\ContactUs\Helper\Data; | ||
use Magento\Contact\Model\ConfigInterface; | ||
use Magento\Framework\DataObject; | ||
|
||
/** | ||
* Class Mail | ||
* | ||
* @package Goral\ContactUs\Model | ||
*/ | ||
class Mail | ||
{ | ||
/** | ||
* @var ConfigInterface | ||
*/ | ||
private $contactsConfig; | ||
|
||
/** | ||
* @var TransportBuilder | ||
*/ | ||
private $transportBuilder; | ||
|
||
/** | ||
* @var StateInterface | ||
*/ | ||
private $inlineTranslation; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
private $helper; | ||
|
||
/** | ||
* Mail constructor. | ||
* | ||
* @param ConfigInterface $contactsConfig | ||
* @param TransportBuilder $transportBuilder | ||
* @param StateInterface $inlineTranslation | ||
* @param StoreManagerInterface $storeManager | ||
* @param Data $helper | ||
*/ | ||
public function __construct( | ||
ConfigInterface $contactsConfig, | ||
TransportBuilder $transportBuilder, | ||
StateInterface $inlineTranslation, | ||
StoreManagerInterface $storeManager, | ||
Data $helper | ||
) { | ||
$this->contactsConfig = $contactsConfig; | ||
$this->transportBuilder = $transportBuilder; | ||
$this->inlineTranslation = $inlineTranslation; | ||
$this->storeManager = $storeManager; | ||
$this->helper = $helper; | ||
} | ||
|
||
/** | ||
* Send email to contact | ||
* | ||
* @param ContactInterface $contact | ||
* | ||
* @throws \Magento\Framework\Exception\MailException | ||
*/ | ||
public function send($contact) | ||
{ | ||
$this->inlineTranslation->suspend(); | ||
try { | ||
$transport = $this->transportBuilder | ||
->setTemplateIdentifier($this->helper->getTemplate()) | ||
->setTemplateOptions( | ||
[ | ||
'area' => Area::AREA_FRONTEND, | ||
'store' => $contact->getStoreId() | ||
] | ||
) | ||
->setTemplateVars(['data' => new DataObject($contact->getData())]) | ||
->setFrom($this->contactsConfig->emailSender()) | ||
->addTo($contact->getEmail()) | ||
->setReplyTo($this->contactsConfig->emailRecipient(), $this->contactsConfig->emailSender()) | ||
->getTransport(); | ||
|
||
$transport->sendMessage(); | ||
} finally { | ||
$this->inlineTranslation->resume(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.