init
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Adminhtml\Order;
|
||||
|
||||
use Magento\Backend\Block\Template\Context;
|
||||
use Magento\Directory\Helper\Data as DirectoryHelper;
|
||||
use Magento\Framework\Json\Helper\Data as JsonHelper;
|
||||
|
||||
class Reject extends \Magento\Backend\Block\Template
|
||||
{
|
||||
|
||||
public function __construct(
|
||||
Context $context,
|
||||
protected \Magento\Framework\Registry $_coreRegistry,
|
||||
array $data = [],
|
||||
?JsonHelper $jsonHelper = null,
|
||||
?DirectoryHelper $directoryHelper = null
|
||||
)
|
||||
{
|
||||
parent::__construct($context, $data, $jsonHelper, $directoryHelper);
|
||||
$this->_authorization = $context->getAuthorization();
|
||||
}
|
||||
|
||||
public function getRejectUrl()
|
||||
{
|
||||
return $this->getUrl('sales/*/reject');
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return $this->_coreRegistry->registry('current_order');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $resourceId
|
||||
* @return bool
|
||||
*/
|
||||
public function canReject(string $resourceId = 'Magento_Sales::cancel') {
|
||||
return $this->_authorization->isAllowed($resourceId) && $this->getOrder()->canCancel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Adminhtml\Order;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
class Totals extends \Magento\Sales\Block\Adminhtml\Order\Totals
|
||||
{
|
||||
protected function _initTotals()
|
||||
{
|
||||
\Magento\Sales\Block\Adminhtml\Totals::_initTotals();
|
||||
$this->_totals['paid'] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'paid',
|
||||
'strong' => true,
|
||||
'value' => $this->getSource()->getTotalPaid(),
|
||||
'base_value' => $this->getSource()->getBaseTotalPaid(),
|
||||
'label' => __('Total Paid'),
|
||||
'area' => 'footer',
|
||||
]
|
||||
);
|
||||
$this->_totals['refunded'] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'refunded',
|
||||
'strong' => true,
|
||||
'value' => $this->getSource()->getTotalRefunded(),
|
||||
'base_value' => $this->getSource()->getBaseTotalRefunded(),
|
||||
'label' => __('Total Refunded'),
|
||||
'area' => 'footer',
|
||||
]
|
||||
);
|
||||
$this->_totals['customer_discount_amount'] = new DataObject(
|
||||
[
|
||||
'code' => 'customer_discount_amount',
|
||||
'strong' => true,
|
||||
'value' => '¥'.number_format($this->getSource()->getData('customer_discount'), 2, '.', ''),
|
||||
'label' => __('优惠金额'),
|
||||
'area' => 'footer',
|
||||
]
|
||||
);
|
||||
$code = 'due';
|
||||
$label = 'Total Due';
|
||||
$value = $this->getSource()->getTotalDue();
|
||||
$baseValue = $this->getSource()->getBaseTotalDue();
|
||||
if ($this->getSource()->getTotalCanceled() > 0 && $this->getSource()->getBaseTotalCanceled() > 0) {
|
||||
$code = 'canceled';
|
||||
$label = 'Total Canceled';
|
||||
$value = $this->getSource()->getTotalCanceled();
|
||||
$baseValue = $this->getSource()->getBaseTotalCanceled();
|
||||
}
|
||||
$this->_totals[$code] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'due',
|
||||
'strong' => true,
|
||||
'value' => $value,
|
||||
'base_value' => $baseValue,
|
||||
'label' => __($label),
|
||||
'area' => 'footer',
|
||||
]
|
||||
);
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Adminhtml\Order;
|
||||
|
||||
use Magento\Backend\Block\Widget\Context;
|
||||
use Magento\Backend\Block\Widget\Form\Container;
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Framework\View\Helper\SecureHtmlRenderer;
|
||||
use Magento\Sales\Model\ConfigInterface;
|
||||
use Magento\Sales\Model\Order;
|
||||
|
||||
class View extends \Magento\Sales\Block\Adminhtml\Order\View
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getReviewUrl()
|
||||
{
|
||||
return $this->getUrl('stemcell_sales/*/review');
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @SuppressWarnings(PHPMD.NPathComplexity)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
*/
|
||||
protected function _construct()
|
||||
{
|
||||
$this->_objectId = 'order_id';
|
||||
$this->_controller = 'adminhtml_order';
|
||||
$this->_mode = 'view';
|
||||
|
||||
Container::_construct();
|
||||
|
||||
$this->removeButton('delete');
|
||||
$this->removeButton('reset');
|
||||
$this->removeButton('save');
|
||||
$this->setId('sales_order_view');
|
||||
$order = $this->getOrder();
|
||||
|
||||
if (!$order) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->_isAllowedAction('Magento_Sales::cancel')
|
||||
&& $order->canCancel()
|
||||
&& $order->getState() != Order::STATE_PROCESSING
|
||||
) {
|
||||
$this->addButton(
|
||||
'order_cancel',
|
||||
[
|
||||
'label' => __('Cancel'),
|
||||
'class' => 'cancel',
|
||||
'id' => 'order-view-cancel-button',
|
||||
'data_attribute' => [
|
||||
'url' => $this->getCancelUrl()
|
||||
]
|
||||
]
|
||||
);
|
||||
$this->addButton(
|
||||
'order_reject',
|
||||
[
|
||||
'label' => __('驳回'),
|
||||
'class' => 'order_reject',
|
||||
'onclick' => 'orderReject()'
|
||||
]
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// if ($this->_isAllowedAction('Magento_Sales::email') && !$order->isCanceled()) {
|
||||
// $message = __('Are you sure you want to send an order email to customer?');
|
||||
// $this->addButton(
|
||||
// 'send_notification',
|
||||
// [
|
||||
// 'label' => __('Send Email'),
|
||||
// 'class' => 'send-email',
|
||||
// 'onclick' => "confirmSetLocation('{$message}', '{$this->getEmailUrl()}')"
|
||||
// ]
|
||||
// );
|
||||
// }
|
||||
|
||||
if ($this->_isAllowedAction(
|
||||
'Magento_Sales::ship'
|
||||
) && $order->canShip() && !$order->getForcedShipmentWithInvoice()
|
||||
) {
|
||||
|
||||
$this->addButton(
|
||||
'order_ship',
|
||||
[
|
||||
'label' => __('Ship'),
|
||||
'onclick' => 'setLocation(\'' . $this->getShipUrl() . '\')',
|
||||
'class' => 'ship'
|
||||
]
|
||||
);
|
||||
if ($order->getState() != Order::STATE_PROCESSING) {
|
||||
$this->addButton(
|
||||
'order_review',
|
||||
[
|
||||
'label' => __('审核'),
|
||||
'class' => 'order_review',
|
||||
'onclick' => 'setLocation(\'' . $this->getReviewUrl() . '\')',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_isAllowedAction(
|
||||
'Magento_Sales::reorder'
|
||||
) && $this->_reorderHelper->isAllowed(
|
||||
$order->getStore()
|
||||
) && $order->canReorderIgnoreSalable()
|
||||
) {
|
||||
$this->addButton(
|
||||
'order_reorder',
|
||||
[
|
||||
'label' => __('Reorder'),
|
||||
'onclick' => 'setLocation(\'' . $this->getReorderUrl() . '\')',
|
||||
'class' => 'reorder'
|
||||
]
|
||||
);
|
||||
}
|
||||
$this->removeButton('order_edit');
|
||||
$this->removeButton('order_invoice');
|
||||
$this->removeButton('order_hold');
|
||||
$this->removeButton('send_notification');
|
||||
if ($order->getState() == Order::STATE_PROCESSING) {
|
||||
$this->removeButton('order_cancel');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Adminhtml\Order\View\Items\Renderer;
|
||||
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
|
||||
class DefaultRenderer extends \Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer
|
||||
{
|
||||
/**
|
||||
* Retrieve rendered column html content
|
||||
*
|
||||
* @param \Magento\Framework\DataObject|Item $item
|
||||
* @param string $column
|
||||
* @param string $field
|
||||
* @return string
|
||||
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
|
||||
* @since 100.1.0
|
||||
*/
|
||||
public function getColumnHtml(\Magento\Framework\DataObject $item, $column, $field = null)
|
||||
{
|
||||
$html = '';
|
||||
switch ($column) {
|
||||
case 'product':
|
||||
if ($this->canDisplayContainer()) {
|
||||
$html .= '<div id="' . $this->getHtmlId() . '">';
|
||||
}
|
||||
$html .= $this->getColumnHtml($item, 'name');
|
||||
if ($this->canDisplayContainer()) {
|
||||
$html .= '</div>';
|
||||
}
|
||||
break;
|
||||
case 'status':
|
||||
$html = $item->getStatus();
|
||||
break;
|
||||
case 'sku':
|
||||
$html = $item->getSku();
|
||||
break;
|
||||
case 'cd-code':
|
||||
$html = $item->getData('cd');
|
||||
break;
|
||||
case 'quote-code':
|
||||
$html = $item->getData('quote');
|
||||
break;
|
||||
case 'price-original':
|
||||
$html = $this->displayPriceAttribute('original_price');
|
||||
break;
|
||||
case 'tax-amount':
|
||||
$html = $this->displayPriceAttribute('tax_amount');
|
||||
break;
|
||||
case 'tax-percent':
|
||||
$html = $this->displayTaxPercent($item);
|
||||
break;
|
||||
case 'discont':
|
||||
$html = number_format($item->getData('customer_discount_percent'), 2, '.', '').'%';
|
||||
break;
|
||||
default:
|
||||
$html = \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer::getColumnHtml($item, $column, $field);
|
||||
}
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user