Skip to content

Commit

Permalink
Merge pull request #147 from magmodules/release/1.7.0
Browse files Browse the repository at this point in the history
Release/1.7.0
  • Loading branch information
Marvin-Magmodules authored Mar 8, 2022
2 parents b8da999 + 7e522db commit 1659d12
Show file tree
Hide file tree
Showing 17 changed files with 458 additions and 81 deletions.
19 changes: 19 additions & 0 deletions Api/Config/System/OrderInterface.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface OrderInterface
const XML_PATH_SHIPPING_METHOD = 'magmodules_channable_marketplace/order/shipping_method';
const XML_PATH_SHIPPING_CUSTOM = 'magmodules_channable_marketplace/order/shipping_method_custom';
const XML_PATH_SHIPPING_METHOD_FALLBACK = 'magmodules_channable_marketplace/order/shipping_method_fallback';
const XML_PATH_RETURN_LABEL = 'magmodules_channable_marketplace/order/return_label';
const XML_PATH_RETURN_LABEL_REGEXP = 'magmodules_channable_marketplace/order/return_label_regexp';
const XML_PATH_IMPORT_CUSTOMER = 'magmodules_channable_marketplace/order/import_customer';
const XML_PATH_CUSTOMER_GROUP_ID = 'magmodules_channable_marketplace/order/customers_group';
const XML_PATH_SEPERATE_HOUSENUMBER = 'magmodules_channable_marketplace/order/seperate_housenumber';
Expand Down Expand Up @@ -289,6 +291,23 @@ public function getStatusUrl(int $storeId): string;
*/
public function getCarrierTitle(int $storeId = null): string;

/**
* Returns labels option
* Options: \Magmodules\Channable\Model\Config\Source\ReturnLabel
*
* @param null|int $storeId
* @return null|string
*/
public function useReturnLabel(int $storeId = null): ?string;

/**
* Retruns array of carrier_code and regex to determine is label is return label
*
* @param null|int $storeId
* @return array
*/
public function getReturnLabelRegexp(int $storeId = null): array;

/**
* @param null|int $storeId
* @return string
Expand Down
54 changes: 14 additions & 40 deletions Block/Adminhtml/Order/Totals.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,37 @@
namespace Magmodules\Channable\Block\Adminhtml\Order;

use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Template\Context;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Sales\Block\Adminhtml\Order\Totals as MagentoTotals;
use Magento\Sales\Helper\Admin;

/**
* Class to add Marketplace Transaction Fee
*/
class Totals extends MagentoTotals
{
/**
* @var CartRepositoryInterface
*/
private $quote;

/**
* @param Context $context
* @param Registry $registry
* @param Admin $adminHelper
* @param CartRepositoryInterface $cartRepositoryInterface
* @param array $data
*/
public function __construct(
Context $context,
Registry $registry,
Admin $adminHelper,
CartRepositoryInterface $cartRepositoryInterface,
array $data = []
) {
$this->quote = $cartRepositoryInterface;
parent::__construct($context, $registry, $adminHelper, $data);
}

/**
* Initialize all order totals relates with tax
* Add Marketplace Transaction Fee to totals
*
* @return Totals
* @throws NoSuchEntityException
*/
public function initTotals()
{
$quoteId = $this->getOrder()->getQuoteId();
$quote = $this->quote->get($quoteId);
$parent = $this->getParentBlock();
$this->_order = $parent->getOrder();
if ($quote->getTransactionFee() > 0) {
$fee = new \Magento\Framework\DataObject(
[
'code' => 'transaction_fee',
'strong' => false,
'value' => $quote->getTransactionFee(),
'label' => __('Marketplace Transaction Fee'),
]
);
$order = $parent->getOrder();

$parent->addTotal($fee, 'transaction_fee');
if ($order->getTransactionFee() != 0) {
$parent->addTotal(
new \Magento\Framework\DataObject(
[
'code' => 'transaction_fee',
'strong' => false,
'value' => $order->getTransactionFee(),
'label' => __('Marketplace Transaction Fee'),
]
),
'transaction_fee'
);
}

return $this;
Expand Down
90 changes: 90 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/Renderer/Carriers.php
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);
}
}
77 changes: 77 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/ReturnLabel.php
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);
}
}
32 changes: 32 additions & 0 deletions Model/Config/Backend/Serialized/ReturnLabel.php
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();
}
}
42 changes: 42 additions & 0 deletions Model/Config/Source/ReturnLabel.php
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;
}
}
16 changes: 16 additions & 0 deletions Model/Config/System/OrderRepository.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,20 @@ public function getDefaultManageStock($storeId = null): bool
{
return $this->isSetFlag(CatalogInventoryConfiguration::XML_PATH_MANAGE_STOCK, $storeId);
}

/**
* @inheritDoc
*/
public function useReturnLabel(int $storeId = null): ?string
{
return $this->getStoreValue(self::XML_PATH_RETURN_LABEL, $storeId);
}

/**
* @inheritDoc
*/
public function getReturnLabelRegexp(int $storeId = null): array
{
return $this->getStoreValueArray(self::XML_PATH_RETURN_LABEL_REGEXP, $storeId);
}
}
Loading

0 comments on commit 1659d12

Please sign in to comment.