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 all 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
27 changes: 27 additions & 0 deletions features/seeing_credit_memos_on_admin_order_view.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@refunds
Feature: Seeing credit memos in admin order view
In order to see every credit memos related to one order
As an Administrator
I want to be able to see credit memos in admin order view

Background:
Given the store operates on a single green channel in "United States"
And the store has "Galaxy Post" shipping method with "$10.00" fee
And the store allows paying with "Space money"
And the store has a product "PHP T-Shirt" priced at "$10.00"
And the store has a product "Symfony Mug" priced at "$21.00"
And there is a customer "[email protected]" that placed an order "#00000022"
And the customer bought a "PHP T-Shirt" and a "Symfony Mug"
And the customer "Rick Sanchez" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address
And the customer chose "Galaxy Post" shipping method with "Space money" payment
And the order "#00000022" is already paid
And I am logged in as an administrator


clem21 marked this conversation as resolved.
Show resolved Hide resolved
@ui
Scenario: Having all credit memos listed on the order page in ascending order
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 the credit memo with "$4.50" total as 1st in the list
And I should see the credit memo with "$5.50" total as 2nd in the list
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ 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

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));
}
}
9 changes: 9 additions & 0 deletions tests/Behat/Page/Admin/CreditMemoDetailsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,18 @@ public function getToAddress(): string
return $this->getDocument()->find('css', '#to-address')->getText();
}

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

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;
}