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

[BUG] Credit memos and refund payment appears in different order #240

Merged
Show file tree
Hide file tree
Changes from 6 commits
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
7 changes: 7 additions & 0 deletions features/seeing_refund_payments_on_admin_order_view.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,10 @@ Feature: Seeing refund payments on admin order view
Scenario: Seeing refund payment on order view
When I view the summary of the order "#00000022"
Then I should see 1 refund payment with status "New"

clem21 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant blank line

@ui
Scenario: Having all credit memos listed on the order page in ascending order
clem21 marked this conversation as resolved.
Show resolved Hide resolved
Given the "#00000022" order's shipping cost already has a refund of "$2.50" with "Space money" payment
When I view the summary of the order "#00000022"
Then I should see the credit memo with "$10.00" total as 1st in the list
And I should see the credit memo with "$2.50" total as 2nd in the list
31 changes: 31 additions & 0 deletions src/Doctrine/ORM/CreditMemoRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\RefundPlugin\Doctrine\ORM;

use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\RefundPlugin\Repository\CreditMemoRepositoryInterface;

class CreditMemoRepository extends EntityRepository implements CreditMemoRepositoryInterface
{
public function findByOrderId(string $orderId): array
{
return $this->createQueryBuilder('o')
->andWhere('o.order = :orderId')
->addOrderBy('o.issuedAt', 'ASC')
->setParameter('orderId', $orderId)
->getQuery()
->getResult()
;
}
}
21 changes: 21 additions & 0 deletions src/Repository/CreditMemoRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Sylius\RefundPlugin\Repository;

use Sylius\Component\Resource\Repository\RepositoryInterface;

interface CreditMemoRepositoryInterface extends RepositoryInterface
{
public function findByOrderId(string $orderId): array;
}
2 changes: 1 addition & 1 deletion src/Resources/config/admin_routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ sylius_refund_order_credit_memos_list:
_sylius:
template: "@SyliusRefundPlugin/Order/Admin/CreditMemo/list.html.twig"
repository:
method: findByOrder
method: findByOrderId
arguments: $orderId

sylius_refund_credit_memo_details:
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ sylius_resource:
sylius_refund.credit_memo:
classes:
model: Sylius\RefundPlugin\Entity\CreditMemo
repository: Sylius\RefundPlugin\Doctrine\ORM\CreditMemoRepository
sylius_refund.line_item:
classes:
model: Sylius\RefundPlugin\Entity\LineItem
Expand Down
8 changes: 8 additions & 0 deletions tests/Behat/Context/Ui/CreditMemoContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,12 @@ public function pdfFileShouldBeSuccessfullyDownloaded(): void
{
Assert::true($this->pdfDownloadElement->isPdfFileDownloaded());
}

/**
* @Then /^I should see the credit memo with "([^"]+)" total as (\d+)(?:|st|nd|rd|th) in the list$/
*/
public function iShouldCreditMemoOrderByAscInTheList(string $creditMemoTotal, int $position): void
clem21 marked this conversation as resolved.
Show resolved Hide resolved
{
Assert::true($this->creditMemoDetailsPage->isCreditMemoInPosition($creditMemoTotal, $position));
}
}
11 changes: 11 additions & 0 deletions tests/Behat/Page/Admin/CreditMemoDetailsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,20 @@ public function getToAddress(): string
return $this->getDocument()->find('css', '#to-address')->getText();
}

public function isCreditMemoInPosition(string $creditMemo, int $position): bool
{
$result = $this->getElement('credit_memo_in_given_position', [
'%position%' => $position,
'%creditMemo%' => $creditMemo,
]);

return $result !== null;
clem21 marked this conversation as resolved.
Show resolved Hide resolved
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'credit_memo_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%creditMemo%")',
'table' => 'table',
'tax_item_amount' => 'tr.tax-item:contains("%label%") .tax-item-amount',
'total' => '#credit-memo-total',
Expand Down
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/CreditMemoDetailsPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ public function getComment(): string;
public function getFromAddress(): string;

public function getToAddress(): string;

public function isCreditMemoInPosition(string $creditMemo, int $position): bool;
}