-
Notifications
You must be signed in to change notification settings - Fork 42
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 #147 from magmodules/release/1.7.0
Release/1.7.0
- Loading branch information
Showing
17 changed files
with
458 additions
and
81 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
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
90 changes: 90 additions & 0 deletions
90
Block/Adminhtml/System/Config/Form/Field/Renderer/Carriers.php
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,90 @@ | ||
<?php | ||
/** | ||
* Copyright © Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magmodules\Channable\Block\Adminhtml\System\Config\Form\Field\Renderer; | ||
|
||
use Magento\Framework\View\Element\Html\Select; | ||
use Magento\Framework\View\Element\Context; | ||
use Magento\Shipping\Model\Config; | ||
|
||
class Carriers extends Select | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $carriers = [ | ||
['value' => 'all' , 'label' => 'All'] | ||
]; | ||
/** | ||
* @var Config | ||
*/ | ||
private $shippingConfig; | ||
|
||
/** | ||
* Countries constructor. | ||
* | ||
* @param Context $context | ||
* @param Config $shippingConfig | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Config $shippingConfig, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->shippingConfig = $shippingConfig; | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
public function _toHtml() | ||
{ | ||
if (!$this->getOptions()) { | ||
foreach ($this->getCarriersSource() as $carriers) { | ||
$this->addOption($carriers['value'], $carriers['label']); | ||
} | ||
} | ||
|
||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Get all countries | ||
* | ||
* @return array | ||
*/ | ||
private function getCarriersSource() | ||
{ | ||
if (!$this->carriers) { | ||
foreach ($this->shippingConfig->getAllCarriers() as $carrier) { | ||
$this->carriers[] = [ | ||
'value' => $carrier->getCarrierCode(), | ||
'label' => $carrier->getCarrierCode() | ||
]; | ||
} | ||
} | ||
|
||
return $this->carriers; | ||
} | ||
|
||
/** | ||
* Sets name for input element | ||
* | ||
* @param $value | ||
* | ||
* @return mixed | ||
*/ | ||
public function setInputName($value) | ||
{ | ||
return $this->setName($value); | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
/** | ||
* Copyright © Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magmodules\Channable\Block\Adminhtml\System\Config\Form\Field; | ||
|
||
use Magento\Framework\DataObject; | ||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; | ||
use Magento\Framework\View\Element\BlockInterface; | ||
|
||
/** | ||
* Represents a table for properties in the admin configuration | ||
*/ | ||
class ReturnLabel extends AbstractFieldArray | ||
{ | ||
|
||
/** | ||
* @var Renderer\Carriers | ||
*/ | ||
private $carriersRenderer; | ||
|
||
/** | ||
* Render block | ||
*/ | ||
public function _prepareToRender() | ||
{ | ||
$this->addColumn('carrier_code', [ | ||
'label' => __('Carrier Code'), | ||
'renderer' => $this->getCarrierRenderer() | ||
]); | ||
$this->addColumn('title_regexp', [ | ||
'label' => __('Title should contain'), | ||
]); | ||
$this->_addAfter = false; | ||
$this->_addButtonLabel = __('Add'); | ||
} | ||
|
||
/** | ||
* Returns render of stores | ||
* | ||
* @return BlockInterface | ||
*/ | ||
public function getCarrierRenderer() | ||
{ | ||
if (!$this->carriersRenderer) { | ||
try { | ||
$this->carriersRenderer = $this->getLayout()->createBlock( | ||
Renderer\Carriers::class, | ||
'', | ||
['data' => ['is_render_to_js_template' => true]] | ||
); | ||
} catch (\Exception $e) { | ||
$this->carriersRenderer = []; | ||
} | ||
} | ||
|
||
return $this->carriersRenderer; | ||
} | ||
|
||
/** | ||
* Prepare existing row data object | ||
* | ||
* @param DataObject $row | ||
*/ | ||
public function _prepareArrayRow(DataObject $row) | ||
{ | ||
$attribute = $row->getData('carrier_code'); | ||
$options = []; | ||
if ($attribute) { | ||
$options['option_' . $this->getCarrierRenderer()->calcOptionHash($attribute)] = 'selected="selected"'; | ||
} | ||
$row->setData('option_extra_attrs', $options); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
/** | ||
* Copyright © Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magmodules\Channable\Model\Config\Backend\Serialized; | ||
|
||
use Magento\Config\Model\Config\Backend\Serialized\ArraySerialized; | ||
|
||
class ReturnLabel extends ArraySerialized | ||
{ | ||
|
||
/** | ||
* @return ArraySerialized | ||
*/ | ||
public function beforeSave() | ||
{ | ||
$data = $this->getValue(); | ||
if (is_array($data)) { | ||
foreach ($data as $key => $row) { | ||
if (empty($row['carrier_code'])) { | ||
unset($data[$key]); | ||
continue; | ||
} | ||
} | ||
} | ||
$this->setValue($data); | ||
return parent::beforeSave(); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
/** | ||
* Copyright © Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magmodules\Channable\Model\Config\Source; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
|
||
/** | ||
* ReturnLabel source class | ||
*/ | ||
class ReturnLabel implements OptionSourceInterface | ||
{ | ||
|
||
public const OPTIONS = [ | ||
'no' => 'No', | ||
'regex' => 'Yes, use regex', | ||
]; | ||
|
||
/** | ||
* Options array | ||
* | ||
* @var array | ||
*/ | ||
public $options = null; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toOptionArray(): array | ||
{ | ||
if (!$this->options) { | ||
foreach (self::OPTIONS as $key => $option) { | ||
$this->options[] = ['value' => $key, 'label' => __($option)]; | ||
} | ||
} | ||
return $this->options; | ||
} | ||
} |
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.