Skip to content

Commit

Permalink
Added some fixes for marketplace acceptance
Browse files Browse the repository at this point in the history
  • Loading branch information
PX-BE1 RL committed Sep 5, 2017
1 parent f975767 commit 0813d74
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 126 deletions.
74 changes: 38 additions & 36 deletions Block/Adminhtml/BankAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
class BankAccount extends \Magento\Config\Block\System\Config\Form\Field
{
protected $_addRowButtonHtml = array();
protected $_removeRowButtonHtml = array();
protected $addRowButtonHtml = [];
protected $removeRowButtonHtml = [];

/**
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
Expand All @@ -40,15 +40,17 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract

$html .= '<div id="bank_account_container">';
if ($this->_getValue('account_holder')) {
foreach ($this->_getValue('account_holder') as $i=>$f) {
foreach ($this->_getValue('account_holder') as $i => $f) {
if ($i) {
$html .= $this->_getRowTemplateHtml($i);
}
}
}
$html .= '</div><br />';
$html .= $this->_getAddRowButtonHtml('bank_account_container',
'bank_account_template', __('Add Bank Account'));
$html .= $this->_getAddRowButtonHtml(
'bank_account_container',
'bank_account_template', __('Add Bank Account')
);

return $html;
}
Expand All @@ -57,17 +59,17 @@ protected function _getElementHtml(\Magento\Framework\Data\Form\Element\Abstract
* @param int $i
* @return string
*/
protected function _getRowTemplateHtml($i=0)
protected function _getRowTemplateHtml($i = 0)
{
$html = '<fieldset>';
$html .= '<label>'.__('Account holder').'</label>';
$html .= '<input class="input-text" type="text" name="'.$this->getElement()->getName().'[account_holder][]" value="' . $this->_getValue('account_holder/'.$i) . '" '.$this->_getDisabled().' />';
$html .= '<label>'.__('Bank name').'</label>';
$html .= '<input class="input-text" type="text" name="'.$this->getElement()->getName().'[bank_name][]" value="' . $this->_getValue('bank_name/'.$i) . '" '.$this->_getDisabled().' />';
$html .= '<label>'.__('IBAN').'</label>';
$html .= '<input class="input-text" type="text" name="'.$this->getElement()->getName().'[iban][]" value="' . $this->_getValue('iban/'.$i) . '" '.$this->_getDisabled().' />';
$html .= '<label>'.__('BIC').'</label>';
$html .= '<input class="input-text" type="text" name="'.$this->getElement()->getName().'[bic][]" value="' . $this->_getValue('bic/'.$i) . '" '.$this->_getDisabled().' />';
$html .= '<label>' . __('Account holder') . '</label>';
$html .= '<input class="input-text" type="text" name="' . $this->getElement()->getName() . '[account_holder][]" value="' . $this->_getValue('account_holder/' . $i) . '" ' . $this->_getDisabled() . ' />';
$html .= '<label>' . __('Bank name') . '</label>';
$html .= '<input class="input-text" type="text" name="' . $this->getElement()->getName() . '[bank_name][]" value="' . $this->_getValue('bank_name/' . $i) . '" ' . $this->_getDisabled() . ' />';
$html .= '<label>' . __('IBAN') . '</label>';
$html .= '<input class="input-text" type="text" name="' . $this->getElement()->getName() . '[iban][]" value="' . $this->_getValue('iban/' . $i) . '" ' . $this->_getDisabled() . ' />';
$html .= '<label>' . __('BIC') . '</label>';
$html .= '<input class="input-text" type="text" name="' . $this->getElement()->getName() . '[bic][]" value="' . $this->_getValue('bic/' . $i) . '" ' . $this->_getDisabled() . ' />';
$html .= '<br />&nbsp;<br />';
$html .= $this->_getRemoveRowButtonHtml();
$html .= '</fieldset>';
Expand All @@ -89,7 +91,7 @@ protected function _getDisabled()
*/
protected function _getValue($key)
{
return $this->getElement()->getData('value/'.$key);
return $this->getElement()->getData('value/' . $key);
}

/**
Expand All @@ -99,7 +101,7 @@ protected function _getValue($key)
*/
protected function _getSelected($key, $value)
{
return $this->getElement()->getData('value/'.$key)==$value ? 'selected="selected"' : '';
return $this->getElement()->getData('value/' . $key) == $value ? 'selected="selected"' : '';
}

/**
Expand All @@ -108,36 +110,36 @@ protected function _getSelected($key, $value)
* @param string $title
* @return mixed
*/
protected function _getAddRowButtonHtml($container, $template, $title='Add')
protected function _getAddRowButtonHtml($container, $template, $title = 'Add')
{
if (!isset($this->_addRowButtonHtml[$container])) {
$this->_addRowButtonHtml[$container] = $this->getLayout()->createBlock('\Magento\Backend\Block\Widget\Button')
->setType('button')
->setClass('add')
->setLabel(__($title))
->setOnClick("Element.insert($('".$container."'), {bottom: $('".$template."').innerHTML})")
->setDisabled($this->_getDisabled())
->toHtml();
if (!isset($this->addRowButtonHtml[$container])) {
$this->addRowButtonHtml[$container] = $this->getLayout()->createBlock('\Magento\Backend\Block\Widget\Button')
->setType('button')
->setClass('add')
->setLabel(__($title))
->setOnClick("Element.insert($('" . $container . "'), {bottom: $('" . $template . "').innerHTML})")
->setDisabled($this->_getDisabled())
->toHtml();
}
return $this->_addRowButtonHtml[$container];
return $this->addRowButtonHtml[$container];
}

/**
* @param string $selector
* @param string $title
* @return array
*/
protected function _getRemoveRowButtonHtml($selector='fieldset', $title='Delete Account')
protected function _getRemoveRowButtonHtml($selector = 'fieldset', $title = 'Delete Account')
{
if (!$this->_removeRowButtonHtml) {
$this->_removeRowButtonHtml = $this->getLayout()->createBlock('\Magento\Backend\Block\Widget\Button')
->setType('button')
->setClass('delete v-middle')
->setLabel(__($title))
->setOnClick("Element.remove($(this).up('".$selector."'))")
->setDisabled($this->_getDisabled())
->toHtml();
if (!$this->removeRowButtonHtml) {
$this->removeRowButtonHtml = $this->getLayout()->createBlock('\Magento\Backend\Block\Widget\Button')
->setType('button')
->setClass('delete v-middle')
->setLabel(__($title))
->setOnClick("Element.remove($(this).up('" . $selector . "'))")
->setDisabled($this->_getDisabled())
->toHtml();
}
return $this->_removeRowButtonHtml;
return $this->removeRowButtonHtml;
}
}
1 change: 0 additions & 1 deletion Block/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Form extends \Magento\Payment\Block\Form
*/
protected $cmsPageFactory;


/**
* @var \Magento\Cms\Helper\Page
*/
Expand Down
9 changes: 6 additions & 3 deletions Block/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ public function toPdf()
/**
* @return mixed
*/
public function getAccounts() {
public function getAccounts()
{
return $this->getMethod()->getAccounts();
}

/**
* @return mixed
*/
public function getShowBankAccountsInPdf() {
public function getShowBankAccountsInPdf()
{
return $this->getMethod()->getConfigData('show_bank_accounts_in_pdf');
}

/**
* @return mixed
*/
public function getShowCustomTextInPdf() {
public function getShowCustomTextInPdf()
{
return $this->getMethod()->getConfigData('show_customtext_in_pdf');
}
}
11 changes: 5 additions & 6 deletions Model/BankPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class BankPayment extends \Magento\Payment\Model\Method\AbstractMethod
*/
protected $_code = self::PAYMENT_METHOD_PHOENIX_BANKPAYMENT_CODE;


/**
* @var \Phoenix\BankPayment\Model\Serialized $_serialized
*/
Expand Down Expand Up @@ -75,7 +74,6 @@ class BankPayment extends \Magento\Payment\Model\Method\AbstractMethod
*/
protected $_canCapturePartial = true;


/**
* @var \Magento\Framework\DataObjectFactory
*/
Expand All @@ -94,7 +92,8 @@ public function __construct(
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
) {
)
{
parent::__construct(
$context,
$registry,
Expand Down Expand Up @@ -149,16 +148,16 @@ public function getAccounts()
$storeId = $paymentInfo->getQuote()->getStoreId();
}

$accounts = $this->_serialized->unserialize($this->_scopeConfig->getValue('payment/phoenix_bankpayment/bank_accounts', \Magento\Store\Model\ScopeInterface::SCOPE_STORE,$storeId));
$accounts = $this->_serialized->unserialize($this->_scopeConfig->getValue('payment/phoenix_bankpayment/bank_accounts', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId));

$this->_accounts = array();
$this->_accounts = [];
$fields = is_array($accounts) ? array_keys($accounts) : null;
if (!empty($fields)) {
foreach ($accounts[$fields[0]] as $i => $k) {
if ($k) {
$account = $this->_dataObjectFactory->create();
foreach ($fields as $field) {
$account->setData($field,$accounts[$field][$i]);
$account->setData($field, $accounts[$field][$i]);
}
$this->_accounts[] = $account;
}
Expand Down
77 changes: 36 additions & 41 deletions Model/BankPaymentConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,36 @@

class BankPaymentConfigProvider implements ConfigProviderInterface
{
/**
* @var string
*/
protected $_methodCode = BankPayment::PAYMENT_METHOD_PHOENIX_BANKPAYMENT_CODE;

/**
* @var BankPayment
* @var BankPayment $method
*/
protected $_method;
private $method;

/**
* @var Serialized $_serialized
* @var Serialized $serialized
*/
protected $_serialized;
private $serialized;

/**
* @var Escaper
* @var Escaper $escaper
*/
protected $_escaper;
private $escaper;

/**
* @var \Magento\Cms\Model\PageFactory
*/
protected $_cmsPageFactory;

private $cmsPageFactory;

/**
* @var \Magento\Cms\Helper\Page
*/
protected $_cmsPageHelper;

private $cmsPageHelper;

/**
* @var array
*/
protected $_accounts;
private $accounts;

/**
* BankPaymentConfigProvider constructor.
Expand All @@ -74,26 +68,27 @@ public function __construct(
PaymentHelper $paymentHelper,
Serialized $serialized,
Escaper $escaper
) {
$this->_cmsPageFactory = $cmsPageFactory;
$this->_cmsPageHelper = $cmsPageHelper;
$this->_escaper = $escaper;
$this->_serialized = $serialized;
$this->_method = $paymentHelper->getMethodInstance($this->_methodCode);
)
{
$this->cmsPageFactory = $cmsPageFactory;
$this->cmsPageHelper = $cmsPageHelper;
$this->escaper = $escaper;
$this->serialized = $serialized;
$this->method = $paymentHelper->getMethodInstance(BankPayment::PAYMENT_METHOD_PHOENIX_BANKPAYMENT_CODE);
}

/**
* {@inheritdoc}
*/
public function getConfig()
{
return $this->_method->isAvailable() ? [
return $this->method->isAvailable() ? [
'payment' => [
$this->_methodCode => [
'formcmsurl' => $this->getFormCmsUrl(),
'customtext' => nl2br($this->_escaper->escapeHtml($this->_method->getCustomText())),
'instructions' => nl2br($this->_escaper->escapeHtml($this->getInstructions())),
'accounts' => $this->getAccounts()
BankPayment::PAYMENT_METHOD_PHOENIX_BANKPAYMENT_CODE => [
'formcmsurl' => $this->getFormCmsUrl(),
'customtext' => nl2br($this->escaper->escapeHtml($this->method->getCustomText())),
'instructions' => nl2br($this->escaper->escapeHtml($this->getInstructions())),
'accounts' => $this->getAccounts()
],
],
] : [];
Expand All @@ -105,10 +100,10 @@ public function getConfig()
public function getFormCmsUrl()
{
$pageUrl = null;
$pageCode = $this->_method->getConfigData('form_cms_page');
$pageCode = $this->method->getConfigData('form_cms_page');
if (!empty($pageCode)) {
if ($pageId = $this->_cmsPageFactory->create()->checkIdentifier($pageCode, $this->_method->getStore())) {
$pageUrl = $this->_cmsPageHelper->getPageUrl($pageId);
if ($pageId = $this->cmsPageFactory->create()->checkIdentifier($pageCode, $this->method->getStore())) {
$pageUrl = $this->cmsPageHelper->getPageUrl($pageId);
$pageUrl = __('More information on this payment method can be found <a target="_blank" href="%1">here</a>.', $pageUrl);
}
}
Expand All @@ -121,25 +116,25 @@ public function getFormCmsUrl()
public function getAccounts()
{

if (!$this->_accounts) {
if (!$this->accounts) {

$accounts = $this->_serialized->unserialize($this->_method->getConfigData('bank_accounts'));
$accounts = $this->serialized->unserialize($this->method->getConfigData('bank_accounts'));

$this->_accounts = array();
$this->accounts = [];
$fields = is_array($accounts) ? array_keys($accounts) : null;
if (!empty($fields)) {
foreach ($accounts[$fields[0]] as $i => $k) {
if ($k) {
$account = array();
$account = [];
foreach ($fields as $field) {
$account[$field] = $this->_escaper->escapeHtml($accounts[$field][$i]);
$account[$field] = $this->escaper->escapeHtml($accounts[$field][$i]);
}
$this->_accounts[] = $account;
$this->accounts[] = $account;
}
}
}
}
return $this->_accounts;
return $this->accounts;
}

/**
Expand All @@ -149,14 +144,14 @@ public function getInstructions()
{

if (count($this->getAccounts()) == 1) {
if ($this->_method->getPayWithinXDays() > 0) {
return __('Please transfer the money within %1 days to the following bank account', $this->_method->getPayWithinXDays());
if ($this->method->getPayWithinXDays() > 0) {
return __('Please transfer the money within %1 days to the following bank account', $this->method->getPayWithinXDays());
} else {
return __('Please transfer the money to the following bank account');
}
} else {
if ($this->_method->getPayWithinXDays() > 0) {
return __('Please transfer the money within %1 days to one of the following bank accounts', $this->_method->getPayWithinXDays());
if ($this->method->getPayWithinXDays() > 0) {
return __('Please transfer the money within %1 days to one of the following bank accounts', $this->method->getPayWithinXDays());
} else {
return __('Please transfer the money to one of the following bank accounts');
}
Expand Down
11 changes: 7 additions & 4 deletions Model/Config/Source/CmsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ public function toOptionArray()
{
if (!$this->options) {
parent::toOptionArray();
array_unshift($this->options, array(
'value' => '',
'label' => __('-- Please Select --'))
array_unshift(
$this->options,
[
'value' => '',
'label' => __('-- Please Select --')
]
);
}
return $this->options;
}
}
}
Loading

0 comments on commit 0813d74

Please sign in to comment.