-
Notifications
You must be signed in to change notification settings - Fork 15
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 #2 from aune-io/feature/configuration_matrix
Improve configuration and functionalities.
- Loading branch information
Showing
22 changed files
with
979 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Aune\AutoInvoice\Api\Data; | ||
|
||
interface InvoiceProcessItemInterface | ||
{ | ||
const KEY_ORDER = 'order'; | ||
const KEY_DESTINATION_STATUS = 'destination_status'; | ||
|
||
/** | ||
* Returns the order to invoice | ||
* | ||
* @returns \Magento\Sales\Api\Data\OrderInterface | ||
*/ | ||
public function getOrder(); | ||
|
||
/** | ||
* Sets the order to invoice | ||
* | ||
* @returns $this | ||
*/ | ||
public function setOrder(\Magento\Sales\Api\Data\OrderInterface $order); | ||
|
||
/** | ||
* Returns the destination status | ||
* | ||
* @returns string | ||
*/ | ||
public function getDestinationStatus(); | ||
|
||
/** | ||
* Sets the destination status | ||
* | ||
* @returns $this | ||
*/ | ||
public function setDestinationStatus(string $status); | ||
} |
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,67 @@ | ||
<?php | ||
|
||
namespace Aune\AutoInvoice\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Framework\View\Element\Context; | ||
use Magento\Framework\View\Element\Html\Select; | ||
use Magento\Payment\Model\Config as PaymentConfig; | ||
use Aune\AutoInvoice\Helper\Data as HelperData; | ||
|
||
class PaymentMethod extends Select | ||
{ | ||
/** | ||
* @var PaymentConfig | ||
*/ | ||
private $paymentConfig; | ||
|
||
/** | ||
* @param Context $context | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
PaymentConfig $paymentConfig, | ||
array $data = [] | ||
) { | ||
$this->paymentConfig = $paymentConfig; | ||
|
||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if (!$this->getOptions()) { | ||
$options = [ | ||
['value' => HelperData::RULE_PAYMENT_METHOD_ALL, 'label' => __('Any')] | ||
]; | ||
|
||
$paymentMethods = $this->paymentConfig->getActiveMethods(); | ||
foreach ($paymentMethods as $code => $model) { | ||
$options []= [ | ||
'value' => $code, | ||
'label' => $model->getTitle() ?: $code, | ||
]; | ||
} | ||
|
||
$this->setOptions($options); | ||
} | ||
|
||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Sets name for input element | ||
* | ||
* @param string $value | ||
* @return $this | ||
*/ | ||
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,130 @@ | ||
<?php | ||
|
||
namespace Aune\AutoInvoice\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray; | ||
use Magento\Framework\DataObject; | ||
|
||
class ProcessingRule extends AbstractFieldArray | ||
{ | ||
/** | ||
* @var Status | ||
*/ | ||
private $srcStatusRenderer = null; | ||
|
||
/** | ||
* @var Status | ||
*/ | ||
private $dstStatusRenderer = null; | ||
|
||
/** | ||
* @var PaymentMethod | ||
*/ | ||
private $paymentMethodRenderer = null; | ||
|
||
/** | ||
* Returns renderer for source status element | ||
*/ | ||
protected function getSrcStatusRenderer() | ||
{ | ||
if (!$this->srcStatusRenderer) { | ||
$this->srcStatusRenderer = $this->getLayout()->createBlock( | ||
Status::class, | ||
'', | ||
['data' => ['is_render_to_js_template' => true]] | ||
); | ||
} | ||
|
||
return $this->srcStatusRenderer; | ||
} | ||
|
||
/** | ||
* Returns renderer for destination status element | ||
*/ | ||
protected function getDstStatusRenderer() | ||
{ | ||
if (!$this->dstStatusRenderer) { | ||
$this->dstStatusRenderer = $this->getLayout()->createBlock( | ||
Status::class, | ||
'', | ||
['data' => ['is_render_to_js_template' => true]] | ||
); | ||
} | ||
|
||
return $this->dstStatusRenderer; | ||
} | ||
|
||
/** | ||
* Returns renderer for payment method | ||
*/ | ||
protected function getPaymentMethodRenderer() | ||
{ | ||
if (!$this->paymentMethodRenderer) { | ||
$this->paymentMethodRenderer = $this->getLayout()->createBlock( | ||
PaymentMethod::class, | ||
'', | ||
['data' => ['is_render_to_js_template' => true]] | ||
); | ||
} | ||
return $this->paymentMethodRenderer; | ||
} | ||
|
||
/** | ||
* Prepare to render | ||
* @return void | ||
*/ | ||
protected function _prepareToRender() | ||
{ | ||
$this->addColumn( | ||
'src_status', | ||
[ | ||
'label' => __('Source Status'), | ||
'renderer' => $this->getSrcStatusRenderer(), | ||
] | ||
); | ||
$this->addColumn( | ||
'payment_method', | ||
[ | ||
'label' => __('Payment Method'), | ||
'renderer' => $this->getPaymentMethodRenderer(), | ||
] | ||
); | ||
$this->addColumn( | ||
'dst_status', | ||
[ | ||
'label' => __('Destination Status'), | ||
'renderer' => $this->getDstStatusRenderer(), | ||
] | ||
); | ||
|
||
$this->_addAfter = false; | ||
$this->_addButtonLabel = __('Add Rule'); | ||
} | ||
|
||
/** | ||
* Prepare existing row data object | ||
* | ||
* @param DataObject $row | ||
* @return void | ||
*/ | ||
protected function _prepareArrayRow(DataObject $row) | ||
{ | ||
$srcStatus = $row->getSrcStatus(); | ||
$dstStatus = $row->getDstStatus(); | ||
$paymentMethod = $row->getPaymentMethod(); | ||
|
||
$options = []; | ||
if ($srcStatus) { | ||
$options['option_' . $this->getSrcStatusRenderer()->calcOptionHash($srcStatus)] | ||
= 'selected="selected"'; | ||
|
||
$options['option_' . $this->getDstStatusRenderer()->calcOptionHash($dstStatus)] | ||
= 'selected="selected"'; | ||
|
||
$options['option_' . $this->getPaymentMethodRenderer()->calcOptionHash($paymentMethod)] | ||
= '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,70 @@ | ||
<?php | ||
|
||
namespace Aune\AutoInvoice\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Framework\View\Element\Context; | ||
use Magento\Framework\View\Element\Html\Select; | ||
use Magento\Sales\Model\Order\Config; | ||
|
||
class Status extends Select | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $stateStatuses = [ | ||
\Magento\Sales\Model\Order::STATE_NEW, | ||
\Magento\Sales\Model\Order::STATE_PROCESSING, | ||
\Magento\Sales\Model\Order::STATE_COMPLETE, | ||
\Magento\Sales\Model\Order::STATE_CLOSED, | ||
\Magento\Sales\Model\Order::STATE_CANCELED, | ||
\Magento\Sales\Model\Order::STATE_HOLDED, | ||
]; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $orderConfig; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Config $orderConfig | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Config $orderConfig, | ||
array $data = [] | ||
) { | ||
$this->orderConfig = $orderConfig; | ||
|
||
parent::__construct($context, $data); | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
if (!$this->getOptions()) { | ||
$statuses = $this->stateStatuses | ||
? $this->orderConfig->getStateStatuses($this->stateStatuses) | ||
: $this->orderConfig->getStatuses(); | ||
|
||
$this->setOptions($statuses); | ||
} | ||
return parent::_toHtml(); | ||
} | ||
|
||
/** | ||
* Sets name for input element | ||
* | ||
* @param string $value | ||
* @return $this | ||
*/ | ||
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
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.