Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Order] persist internal cancellation reasons #1333

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/CoreShop/Bundle/FrontendBundle/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
namespace CoreShop\Bundle\FrontendBundle\Controller;

use CoreShop\Bundle\CoreBundle\Form\Type\Order\PaymentType;
use CoreShop\Bundle\WorkflowBundle\History\HistoryLogger;
use CoreShop\Component\Core\Model\OrderInterface;
use CoreShop\Component\Order\Model\CartInterface;
use CoreShop\Component\Order\OrderTransitions;
use CoreShop\Component\Order\Repository\OrderRepositoryInterface;
use CoreShop\Component\Payment\Model\PaymentInterface;
use CoreShop\Component\Resource\Repository\RepositoryInterface;
use Pimcore\Model\DataObject\Concrete;
use Symfony\Component\Form\ClickableInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -62,6 +64,14 @@ public function reviseAction(Request $request)

if ($cancelButton instanceof ClickableInterface && $form->isSubmitted() && $cancelButton->isClicked()) {
$this->get('coreshop.state_machine_applier')->apply($order, OrderTransitions::IDENTIFIER, OrderTransitions::TRANSITION_CANCEL);

if ($order instanceof Concrete) {
$this->get(HistoryLogger::class)->log(
$order,
'User Cart Revise Cancellation'
);
}

$cart = $this->get('coreshop.repository.cart')->findCartByOrder($order);

if ($cart instanceof CartInterface) {
Expand Down
10 changes: 10 additions & 0 deletions src/CoreShop/Bundle/OrderBundle/Controller/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
namespace CoreShop\Bundle\OrderBundle\Controller;

use Carbon\Carbon;
use CoreShop\Bundle\WorkflowBundle\History\HistoryLogger;
use CoreShop\Bundle\WorkflowBundle\Manager\StateMachineManager;
use CoreShop\Bundle\WorkflowBundle\StateManager\WorkflowStateInfoManagerInterface;
use CoreShop\Component\Order\Model\OrderInterface;
use CoreShop\Component\Order\Model\SaleInterface;
use CoreShop\Component\Order\OrderStates;
use CoreShop\Component\Order\OrderTransitions;
use CoreShop\Component\Order\Processable\ProcessableInterface;
use CoreShop\Component\Order\Repository\OrderInvoiceRepositoryInterface;
use CoreShop\Component\Order\Repository\OrderShipmentRepositoryInterface;
use CoreShop\Component\Pimcore\DataObject\NoteServiceInterface;
use Pimcore\Model\DataObject;
use Pimcore\Model\User;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand Down Expand Up @@ -140,6 +143,13 @@ public function updateOrderStateAction(Request $request)

$workflow->apply($order, $transition);

if ($order instanceof DataObject\Concrete && $transition === OrderTransitions::TRANSITION_CANCEL) {
$this->get(HistoryLogger::class)->log(
$order,
'Admin Order Cancellation'
);
}

return $this->viewHandler->handle(['success' => true]);
}

Expand Down
28 changes: 24 additions & 4 deletions src/CoreShop/Bundle/OrderBundle/Expiration/OrderExpiration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

namespace CoreShop\Bundle\OrderBundle\Expiration;

use CoreShop\Bundle\WorkflowBundle\Applier\StateMachineApplier;
use CoreShop\Bundle\WorkflowBundle\History\HistoryLoggerInterface;
use CoreShop\Component\Order\OrderTransitions;
use CoreShop\Component\Order\Repository\OrderRepositoryInterface;
use CoreShop\Bundle\WorkflowBundle\Applier\StateMachineApplier;
use Pimcore\Model\DataObject\Concrete;

final class OrderExpiration implements ProposalExpirationInterface
{
Expand All @@ -28,14 +30,24 @@ final class OrderExpiration implements ProposalExpirationInterface
*/
private $stateMachineApplier;

/**
* @var HistoryLoggerInterface
*/
private $historyLogger;

/**
* @param OrderRepositoryInterface $orderRepository
* @param StateMachineApplier $stateMachineApplier
* @param HistoryLoggerInterface $historyLogger
*/
public function __construct(OrderRepositoryInterface $orderRepository, StateMachineApplier $stateMachineApplier)
{
public function __construct(
OrderRepositoryInterface $orderRepository,
StateMachineApplier $stateMachineApplier,
HistoryLoggerInterface $historyLogger = null
) {
$this->orderRepository = $orderRepository;
$this->stateMachineApplier = $stateMachineApplier;
$this->historyLogger = $historyLogger;
}

/**
Expand All @@ -51,7 +63,15 @@ public function expire($days, $params = [])

if (is_array($orders)) {
foreach ($orders as $order) {
$this->stateMachineApplier->apply($order, OrderTransitions::IDENTIFIER, OrderTransitions::TRANSITION_CANCEL);
$this->stateMachineApplier->apply($order, OrderTransitions::IDENTIFIER,
OrderTransitions::TRANSITION_CANCEL);
dpfaffenbauer marked this conversation as resolved.
Show resolved Hide resolved

if (null !== $this->historyLogger && $order instanceof Concrete) {
$this->historyLogger->log(
$order,
'Automatic Expiration Order Cancellation'
);
}
}
}
}
Expand Down