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 5 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
8 changes: 8 additions & 0 deletions features/viewing_details_of_credit_memo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ Feature: Viewing details of a credit memo
And it should contain 1 "Galaxy Post" shipment with "4.50" gross value in "USD" currency
And it should be issued in "United States" channel
And its total should be "4.50" in "USD" currency

@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 "$4.50" with "Space money" payment
And the 1st "PHP T-Shirt" product from order "#00000022" has a refund of "$5.50" with "Space money" payment
When I view the summary of the order "#00000022"
Then I should see "4.50" credit memo as 1st in the list
And I should see "5.50" credit memo as 2nd in the list
clem21 marked this conversation as resolved.
Show resolved Hide resolved
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('c')
->andWhere('c.order = :orderId')
->addOrderBy('c.issuedAt', 'ASC')
->setParameter('orderId', $orderId)
clem21 marked this conversation as resolved.
Show resolved Hide resolved
->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 "([^"]+)" credit memo as (\d+)(?:|st|nd|rd|th) in the list$/
*/
public function iShouldCreditMemoOrderByAscInTheList(string $creditMemo, int $position): void
clem21 marked this conversation as resolved.
Show resolved Hide resolved
{
Assert::true($this->creditMemoDetailsPage->isCreditMemoInPosition($creditMemo, $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,13 +126,24 @@ 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(), [
'table' => 'table',
'tax_item_amount' => 'tr.tax-item:contains("%label%") .tax-item-amount',
'total' => '#credit-memo-total',
'total_currency_code' => '#credit-memo-total-currency-code',
'credit_memo_in_given_position' => 'table tbody tr:nth-child(%position%) td:contains("%creditMemo%")',
clem21 marked this conversation as resolved.
Show resolved Hide resolved
]);
}
}
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;
}