Skip to content

Commit

Permalink
bug #240 [BUG] Credit memos and refund payment appears in different o…
Browse files Browse the repository at this point in the history
…rder (clem21)

This PR was merged into the 1.0-dev branch.

Discussion
----------

Fixes #231 

Commits
-------

1f96d2e Create CreditMemo repository to find order by Id and order them correctly
5160572 Add behat scenario
87eb341 Add return type to CreditMemoRepositoryInterface
cf32dc9 Fix typo
8666f26 Fix typo
c3a01cd applied Grzegorz's comments
e8f4d0f Create new behat feature file
  • Loading branch information
GSadee authored Jan 12, 2021
2 parents 4d79cbd + e8f4d0f commit 9ba209d
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 1 deletion.
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


@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"

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

0 comments on commit 9ba209d

Please sign in to comment.