init
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user