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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order\Email;
|
||||
|
||||
class Items extends \Magento\Sales\Block\Order\Email\Items
|
||||
{
|
||||
public function getPrice(\Magento\Sales\Model\Order\Item $item): string
|
||||
{
|
||||
// $discountPercent = $item->getData('customer_discount_percent')*1.0;
|
||||
$price = $item->getPrice();
|
||||
// $price = $discountPercent? $price*((100-$discountPercent)/100):$price;
|
||||
return number_format($price, 2);
|
||||
}
|
||||
|
||||
public function getRowTotal(\Magento\Sales\Model\Order\Item $item): string
|
||||
{
|
||||
$discountPercent = $item->getData('customer_discount_percent')*1.0;
|
||||
$rowTotal = $item->getRowTotal();
|
||||
$rowTotal = $discountPercent? $rowTotal*((100-$discountPercent)/100):$rowTotal;
|
||||
|
||||
return number_format($rowTotal, 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order\Email\Salesperson;
|
||||
|
||||
class Items extends \Magento\Sales\Block\Order\Email\Items
|
||||
{
|
||||
public function getPrice(\Magento\Sales\Model\Order\Item $item): string
|
||||
{
|
||||
// $discountPercent = $item->getData('customer_discount_percent')*1.0;
|
||||
$price = $item->getPrice();
|
||||
// $price = $discountPercent? $price*((100-$discountPercent)/100):$price;
|
||||
return number_format($price, 2);
|
||||
}
|
||||
|
||||
public function getRowTotal(\Magento\Sales\Model\Order\Item $item): string
|
||||
{
|
||||
$discountPercent = $item->getData('customer_discount_percent')*1.0;
|
||||
$rowTotal = $item->getRowTotal();
|
||||
$rowTotal = $discountPercent? $rowTotal*((100-$discountPercent)/100):$rowTotal;
|
||||
return number_format($rowTotal, 2);
|
||||
}
|
||||
|
||||
public function getSalespersonGrandTotal(\Magento\Sales\Model\Order $order): string
|
||||
{
|
||||
return '¥'.number_format($order->getGrandTotal(), 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order;
|
||||
|
||||
use Magento\Framework\App\ObjectManager;
|
||||
use Magento\Sales\Model\ResourceModel\Order\CollectionFactoryInterface;
|
||||
|
||||
class History extends \Magento\Sales\Block\Order\History
|
||||
{
|
||||
protected CollectionFactoryInterface $orderCollectionFactory;
|
||||
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
\Magento\Sales\Model\ResourceModel\Order\CollectionFactory $orderCollectionFactory,
|
||||
\Magento\Customer\Model\Session $customerSession,
|
||||
\Magento\Sales\Model\Order\Config $orderConfig,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $orderCollectionFactory, $customerSession, $orderConfig, $data);
|
||||
$this->orderCollectionFactory = $orderCollectionFactory;
|
||||
}
|
||||
|
||||
public function getOrders()
|
||||
{
|
||||
if (!($customerId = $this->_customerSession->getCustomerId())) {
|
||||
return false;
|
||||
}
|
||||
if (!$this->orders) {
|
||||
$this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
|
||||
'*'
|
||||
)->addFieldToFilter(
|
||||
'status',
|
||||
['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
|
||||
)->setOrder(
|
||||
'created_at',
|
||||
'desc'
|
||||
);
|
||||
}
|
||||
$q = trim((string)$this->_request->getParam('q', ''));
|
||||
if (!empty($q)) {
|
||||
$this->orders->addFieldToFilter('increment_id', ['like' => '%' . $q . '%']);
|
||||
}
|
||||
return $this->orders;
|
||||
}
|
||||
|
||||
protected function getOrderCollectionFactory()
|
||||
{
|
||||
if ($this->orderCollectionFactory === null) {
|
||||
$this->orderCollectionFactory = ObjectManager::getInstance()->get(CollectionFactoryInterface::class);
|
||||
}
|
||||
return $this->orderCollectionFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order;
|
||||
|
||||
use Magento\Framework\Api\SearchCriteriaBuilder;
|
||||
use Magento\Framework\Registry;
|
||||
use Magento\Framework\View\Element\Template\Context as TemplateContext;
|
||||
use Magento\Payment\Helper\Data as PaymentHelper;
|
||||
use Magento\Sales\Model\Order\Address\Renderer as AddressRenderer;
|
||||
use Magento\Sales\Api\OrderStatusHistoryRepositoryInterface;
|
||||
use Magento\Sales\Model\ResourceModel\Order\Status\History\CollectionFactory;
|
||||
use Stemcell\Sales\Model\OrderStatus;
|
||||
|
||||
class Info extends \Magento\Sales\Block\Order\Info
|
||||
{
|
||||
public function __construct(
|
||||
TemplateContext $context,
|
||||
Registry $registry,
|
||||
PaymentHelper $paymentHelper,
|
||||
AddressRenderer $addressRenderer,
|
||||
protected CollectionFactory $statusHistoryCollectionFactory,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $registry, $paymentHelper, $addressRenderer, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRejectComment()
|
||||
{
|
||||
$collection = $this->getOrder()->getStatusHistoryCollection()
|
||||
->addFieldToFilter('status', OrderStatus::rejected->name);
|
||||
if ($collection->getSize()) {
|
||||
return $collection->getFirstItem()->getComment();
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order\Item\Renderer;
|
||||
|
||||
use Magento\Catalog\Model\Product\OptionFactory;
|
||||
use Magento\Framework\Exception\LocalizedException;
|
||||
use Magento\Framework\Stdlib\StringUtils;
|
||||
use Magento\Framework\View\Element\Template\Context;
|
||||
use Magento\Sales\Model\Order\Item;
|
||||
use Stemcell\Customer\Api\SalespersonRepositoryInterface;
|
||||
use Stemcell\Customer\Model\LabRepository;
|
||||
|
||||
class DefaultRenderer extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer
|
||||
{
|
||||
public function __construct(
|
||||
Context $context,
|
||||
StringUtils $string,
|
||||
OptionFactory $productOptionFactory,
|
||||
private SalespersonRepositoryInterface $salespersonRepository,
|
||||
private LabRepository $labRepository,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $string, $productOptionFactory, $data);
|
||||
}
|
||||
|
||||
public function getSalespersonName(Item $orderItem)
|
||||
{
|
||||
if ($orderItem->getSalespersonId()) {
|
||||
$salesperson = $this->salespersonRepository->get($orderItem->getSalespersonId());
|
||||
return $salesperson->getName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getLabBookingAccount(Item $orderItem)
|
||||
{
|
||||
if ($orderItem->getLabId()) {
|
||||
try {
|
||||
$lab = $this->labRepository->get($orderItem->getLabId());
|
||||
return $lab->getBookingAccount();
|
||||
} catch (LocalizedException $e) {
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Item $orderItem
|
||||
* @return string|null
|
||||
*/
|
||||
public function getCustomDiscountPercent(Item $orderItem)
|
||||
{
|
||||
if ($orderItem->getData('customer_discount_percent')) {
|
||||
return number_format(
|
||||
$orderItem->getData('customer_discount_percent')*1.0,
|
||||
2, '.', ''
|
||||
).'%';
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order;
|
||||
|
||||
use Magento\Framework\DataObject;
|
||||
|
||||
class Totals extends \Magento\Sales\Block\Order\Totals
|
||||
{
|
||||
protected function addShippingTotal($source)
|
||||
{
|
||||
if (!$source->getIsVirtual()
|
||||
&& ($source->getShippingAmount() !== null
|
||||
|| $source->getShippingDescription())
|
||||
) {
|
||||
$shippingLabel = __('Shipping & Handling');
|
||||
|
||||
if (!isset($this->_totals['discount'])) {
|
||||
if ($source->getCouponCode()) {
|
||||
$shippingLabel .= " ({$source->getCouponCode()})";
|
||||
} elseif ($source->getDiscountDescription()) {
|
||||
$shippingLabel .= " ({$source->getDiscountDescription()})";
|
||||
}
|
||||
}
|
||||
$this->_totals['shipping'] = new DataObject(
|
||||
[
|
||||
'code' => 'shipping',
|
||||
'field' => 'shipping_amount',
|
||||
'value' => $source->getShippingAmount(),
|
||||
'label' => $shippingLabel,
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
protected function _initTotals()
|
||||
{
|
||||
$source = $this->getSource();
|
||||
|
||||
$this->_totals = [];
|
||||
$this->_totals['subtotal'] = new \Magento\Framework\DataObject(
|
||||
['code' => 'subtotal', 'value' => $source->getSubtotal(), 'label' => __('Subtotal')]
|
||||
);
|
||||
|
||||
/**
|
||||
* Add discount
|
||||
*/
|
||||
if ((double)$this->getSource()->getDiscountAmount() != 0) {
|
||||
if ($this->getSource()->getDiscountDescription()) {
|
||||
$discountLabel = __('Discount (%1)', $source->getDiscountDescription());
|
||||
} else {
|
||||
$discountLabel = __('Discount');
|
||||
}
|
||||
$this->_totals['discount'] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'discount',
|
||||
'field' => 'discount_amount',
|
||||
'value' => $source->getDiscountAmount(),
|
||||
'label' => $discountLabel,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
$this->addShippingTotal($source);
|
||||
$this->_totals['customer_discount'] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'customer_discount',
|
||||
'field' => 'customer_discount',
|
||||
'value' => $source->getData('customer_discount'),
|
||||
'label' => '优惠金额',
|
||||
]
|
||||
);
|
||||
$this->_totals['grand_total'] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'grand_total',
|
||||
'field' => 'grand_total',
|
||||
'strong' => true,
|
||||
'value' => $source->getGrandTotal(),
|
||||
'label' => __('Grand Total'),
|
||||
]
|
||||
);
|
||||
|
||||
/**
|
||||
* Base grandtotal
|
||||
*/
|
||||
if ($this->getOrder()->isCurrencyDifferent()) {
|
||||
$this->_totals['base_grandtotal'] = new \Magento\Framework\DataObject(
|
||||
[
|
||||
'code' => 'base_grandtotal',
|
||||
'value' => $this->getOrder()->formatBasePrice($source->getBaseGrandTotal()),
|
||||
'label' => __('Grand Total to be Charged'),
|
||||
'is_formated' => true,
|
||||
]
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Order;
|
||||
|
||||
use Stemcell\Sales\Model\OrderStatus;
|
||||
|
||||
class View extends \Magento\Sales\Block\Order\View
|
||||
{
|
||||
/**
|
||||
* @return \Magento\Sales\Model\ResourceModel\Order\Status\History\Collection
|
||||
*/
|
||||
public function getRejectComment()
|
||||
{
|
||||
return $this->getOrder()->getStatusHistoryCollection()
|
||||
->addFieldToFilter('status', OrderStatus::rejected->name);
|
||||
|
||||
}
|
||||
|
||||
public function isOrderRejected() {
|
||||
return $this->getOrder()->getStatus() == OrderStatus::rejected->name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Stemcell\Sales\Block\Tracking;
|
||||
|
||||
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
|
||||
use Magento\Shipping\Model\Order\Track;
|
||||
use Magento\Shipping\Model\ResourceModel\Order\Track\CollectionFactory;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Stemcell\Sales\Helper\Data;
|
||||
|
||||
class Popup extends \Magento\Shipping\Block\Tracking\Popup
|
||||
{
|
||||
protected Data $helper;
|
||||
protected CollectionFactory $trackCollectionFactory;
|
||||
public function __construct(
|
||||
\Magento\Framework\View\Element\Template\Context $context,
|
||||
\Magento\Framework\Registry $registry,
|
||||
DateTimeFormatterInterface $dateTimeFormatter,
|
||||
CollectionFactory $trackCollectionFactory,
|
||||
Data $helper,
|
||||
LoggerInterface $logger,
|
||||
array $data = []
|
||||
) {
|
||||
parent::__construct($context, $registry, $dateTimeFormatter, $data);
|
||||
$this->trackCollectionFactory = $trackCollectionFactory;
|
||||
$this->helper = $helper;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getExpressInfo(): array
|
||||
{
|
||||
$info = $this->_registry->registry('current_shipping_info');
|
||||
if ($info->getOrderId()) {
|
||||
/* @var $track Track */
|
||||
$track = $this->trackCollectionFactory->create()
|
||||
->setOrderFilter($info->getOrderId())
|
||||
->setItemObjectClass(Track::class)
|
||||
->getFirstItem();
|
||||
$expressInfo = json_decode($track->getDescription(), true);
|
||||
//是否已签收
|
||||
$isReceived = !empty($expressInfo) && isset($expressInfo['deliverystatus']) && $expressInfo['deliverystatus']==3;
|
||||
if ($track->getTrackNumber() && !$isReceived) {
|
||||
try {
|
||||
$result = $this->helper->getExpressInfo($track->getTrackNumber());
|
||||
if (isset($result['expName'])) {
|
||||
$track->setDescription(json_encode($result))->save();
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
$this->logger->critical('request express info fail, message:'.$exception->getMessage(), $exception->getTrace());
|
||||
}
|
||||
}
|
||||
if ($track->getDescription()) {
|
||||
if (isset($expressInfo['list']) && is_array($expressInfo['list'])) {
|
||||
return $expressInfo['list'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user