1
0
Fork 0
mirror of synced 2025-04-04 05:33:31 +03:00

fix not selected list

This commit is contained in:
gorokh 2020-04-06 22:47:16 +03:00
parent 172c330e08
commit 2a69456087
6 changed files with 119 additions and 24 deletions

View file

@ -9,6 +9,11 @@ class PaymentCms extends \Magento\Framework\View\Element\Html\Select
*/
private $paymentConfig;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* PaymentCms constructor.
*
@ -19,11 +24,13 @@ class PaymentCms extends \Magento\Framework\View\Element\Html\Select
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Payment\Model\Config $paymentConfig,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->paymentConfig = $paymentConfig;
$this->logger = $logger;
}
/**
@ -43,11 +50,19 @@ class PaymentCms extends \Magento\Framework\View\Element\Html\Select
public function _toHtml()
{
if (!$this->getOptions()) {
$paymentMethods = array();
$paymentMethods = $this->paymentConfig->getActiveMethods();
try {
$paymentMethods = $this->paymentConfig->getActiveMethods();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
foreach ($paymentMethods as $code => $payment) {
$this->addOption($payment->getCode(), $payment->getTitle());
$this->addOption( 'null', "not selected");
if ($paymentMethods) {
foreach ($paymentMethods as $code => $payment) {
$this->addOption($payment->getCode(), $payment->getTitle());
}
}
}

View file

@ -8,6 +8,12 @@ class PaymentCrm extends \Magento\Framework\View\Element\Html\Select
* @var \Retailcrm\Retailcrm\Helper\Proxy
*/
private $client;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* Activation constructor.
*
@ -17,11 +23,13 @@ class PaymentCrm extends \Magento\Framework\View\Element\Html\Select
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Retailcrm\Retailcrm\Helper\Proxy $client,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->client = $client;
$this->logger = $logger;
}
/**
@ -41,17 +49,25 @@ class PaymentCrm extends \Magento\Framework\View\Element\Html\Select
public function _toHtml()
{
if (!$this->getOptions()) {
$paymentsTypes = array();
$response = $this->client->paymentTypesList();
try {
$response = $this->client->paymentTypesList();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
if ($response->isSuccessful()) {
if (isset($response) && $response->isSuccessful()) {
$paymentsTypes = $response['paymentTypes'];
}
$this->addOption( 'null', " ");
foreach ($paymentsTypes as $paymentsType) {
$this->addOption($paymentsType['code'], $paymentsType['name']);
$this->addOption( 'null', "not selected");
if ($paymentsTypes) {
foreach ($paymentsTypes as $paymentsType) {
$this->addOption($paymentsType['code'], $paymentsType['name']);
}
}
}
return parent::_toHtml();

View file

@ -9,6 +9,11 @@ class ShippingCms extends \Magento\Framework\View\Element\Html\Select
*/
private $shippingConfig;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* ShippingColumn constructor.
*
@ -19,11 +24,13 @@ class ShippingCms extends \Magento\Framework\View\Element\Html\Select
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Shipping\Model\Config $shippingConfig,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->shippingConfig = $shippingConfig;
$this->logger = $logger;
}
/**
@ -43,11 +50,21 @@ class ShippingCms extends \Magento\Framework\View\Element\Html\Select
public function _toHtml()
{
if (!$this->getOptions()) {
$deliveryMethods = $this->shippingConfig->getActiveCarriers();
$deliveryMethods = array();
foreach ($deliveryMethods as $code => $delivery) {
$this->addOption($delivery->getCarrierCode(), $delivery->getConfigData('title'));
try {
$deliveryMethods = $this->shippingConfig->getActiveCarriers();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
$this->addOption( 'null', "not selected");
if ($deliveryMethods) {
foreach ($deliveryMethods as $code => $delivery) {
$this->addOption($delivery->getCarrierCode(), $delivery->getConfigData('title'));
}
}
}
return parent::_toHtml();

View file

@ -8,6 +8,12 @@ class ShippingCrm extends \Magento\Framework\View\Element\Html\Select
* @var \Retailcrm\Retailcrm\Helper\Proxy
*/
private $client;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* Activation constructor.
*
@ -17,11 +23,13 @@ class ShippingCrm extends \Magento\Framework\View\Element\Html\Select
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Retailcrm\Retailcrm\Helper\Proxy $client,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->client = $client;
$this->logger = $logger;
}
/**
@ -41,16 +49,23 @@ class ShippingCrm extends \Magento\Framework\View\Element\Html\Select
public function _toHtml()
{
if (!$this->getOptions()) {
$deliveryTypes = array();
$response = $this->client->deliveryTypesList();
try {
$response = $this->client->deliveryTypesList();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
if ($response->isSuccessful()) {
if (isset($response) && $response->isSuccessful()) {
$deliveryTypes = $response['deliveryTypes'];
}
$this->addOption( 'null', " ");
foreach ($deliveryTypes as $deliveryType) {
$this->addOption($deliveryType['code'], $deliveryType['name']);
$this->addOption( 'null', "not selected");
if ($deliveryTypes) {
foreach ($deliveryTypes as $deliveryType) {
$this->addOption($deliveryType['code'], $deliveryType['name']);
}
}
}

View file

@ -9,6 +9,11 @@ class StatusCms extends \Magento\Framework\View\Element\Html\Select
*/
private $statusCollection;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* StatusCms constructor.
*
@ -19,11 +24,13 @@ class StatusCms extends \Magento\Framework\View\Element\Html\Select
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Sales\Model\ResourceModel\Order\Status\Collection $statusCollection,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->statusCollection = $statusCollection;
$this->logger = $logger;
}
/**
@ -43,10 +50,19 @@ class StatusCms extends \Magento\Framework\View\Element\Html\Select
public function _toHtml()
{
if (!$this->getOptions()) {
$statuses = $this->statusCollection->toOptionArray();
$statuses = array();
foreach ($statuses as $code => $status) {
$this->addOption( $status['value'], $status['label']);
try {
$statuses = $this->statusCollection->toOptionArray();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
$this->addOption( 'null', "not selected");
if ($statuses) {
foreach ($statuses as $code => $status) {
$this->addOption( $status['value'], $status['label']);
}
}
}

View file

@ -8,6 +8,12 @@ class StatusCrm extends \Magento\Framework\View\Element\Html\Select
* @var \Retailcrm\Retailcrm\Helper\Proxy
*/
private $client;
/**
* @var \Retailcrm\Retailcrm\Model\Logger\Logger
*/
private $logger;
/**
* Activation constructor.
*
@ -17,11 +23,13 @@ class StatusCrm extends \Magento\Framework\View\Element\Html\Select
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Retailcrm\Retailcrm\Helper\Proxy $client,
\Retailcrm\Retailcrm\Model\Logger\Logger $logger,
array $data = []
) {
parent::__construct($context, $data);
$this->client = $client;
$this->logger = $logger;
}
/**
@ -41,17 +49,25 @@ class StatusCrm extends \Magento\Framework\View\Element\Html\Select
public function _toHtml()
{
if (!$this->getOptions()) {
$statuses = array();
$response = $this->client->statusesList();
try {
$response = $this->client->statusesList();
} catch (\Exception $exception) {
$this->logger->writeRow($exception->getMessage());
}
if ($response->isSuccessful()) {
if (isset($response) && $response->isSuccessful()) {
$statuses = $response['statuses'];
}
$this->addOption( 'null', " ");
foreach ($statuses as $status) {
$this->addOption($status['code'], $status['name']);
$this->addOption( 'null', "not selected");
if ($statuses) {
foreach ($statuses as $status) {
$this->addOption($status['code'], $status['name']);
}
}
}
return parent::_toHtml();