diff --git a/features/viewing_details_of_credit_memo.feature b/features/viewing_details_of_credit_memo.feature index 88d61772..119b76bc 100644 --- a/features/viewing_details_of_credit_memo.feature +++ b/features/viewing_details_of_credit_memo.feature @@ -9,8 +9,10 @@ Feature: Viewing details of a credit memo And channel "United States" billing data is "Haas & Milan", "Pacific Coast Hwy", "90003" "Los Angeles", "United States" with "1100110011" tax ID And default tax zone is "US" And the store has "US VAT" tax rate of 10% for "Clothes" within the "US" zone + And the store has "US VAT-SHIPPING" tax rate of 15% for "Shipping" within the "US" zone And the store has included in price "VAT" tax rate of 20% for "Mugs" within the "US" zone And the store has "Galaxy Post" shipping method with "$10.00" fee + And shipping method "Galaxy Post" belongs to "Shipping" tax category And the store allows paying with "Space money" And the store has a product "PHP T-Shirt" priced at "$10.00" And it belongs to "Clothes" tax category @@ -55,3 +57,13 @@ 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 @application + Scenario: Viewing details of a credit memo issued for a shipping cost refund + Given the "#00000022" order's shipping cost already has a refund of "$11.50" with "Space money" payment + When I browse the details of the only credit memo generated for order "#00000022" + Then it should have sequential number generated from current date + And it should contain 1 "Galaxy Post" shipment with "10.00" net value, "1.50" tax amount and "11.50" gross value in "USD" currency + And it should be issued in "United States" channel + And it should contain a tax item "15%" with amount "1.50" in "USD" currency + And its total should be "11.50" in "USD" currency diff --git a/src/Converter/ShipmentLineItemsConverter.php b/src/Converter/ShipmentLineItemsConverter.php index b61f92b1..f4cce3b1 100644 --- a/src/Converter/ShipmentLineItemsConverter.php +++ b/src/Converter/ShipmentLineItemsConverter.php @@ -5,6 +5,8 @@ namespace Sylius\RefundPlugin\Converter; use Sylius\Component\Core\Model\AdjustmentInterface; +use Sylius\Component\Core\Model\ShipmentInterface; +use Sylius\Component\Core\Repository\ShipmentRepositoryInterface; use Sylius\Component\Resource\Repository\RepositoryInterface; use Sylius\RefundPlugin\Entity\LineItem; use Sylius\RefundPlugin\Entity\LineItemInterface; @@ -16,9 +18,15 @@ final class ShipmentLineItemsConverter implements LineItemsConverterInterface /** @var RepositoryInterface */ private $adjustmentRepository; - public function __construct(RepositoryInterface $adjustmentRepository) - { + /** @var ShipmentRepositoryInterface */ + private $shipmentRepository; + + public function __construct( + RepositoryInterface $adjustmentRepository, + ShipmentRepositoryInterface $shipmentRepository + ) { $this->adjustmentRepository = $adjustmentRepository; + $this->shipmentRepository = $shipmentRepository; } public function convert(array $units): array @@ -43,6 +51,13 @@ private function convertUnitRefundToLineItem(UnitRefundInterface $unitRefund): L Assert::notNull($shippingAdjustment); Assert::lessThanEq($unitRefund->total(), $shippingAdjustment->getAmount()); + /** @var ShipmentInterface $shipment */ + $shipment = $this->shipmentRepository->find(['id' => $unitRefund->id()]); + Assert::notNull($shipment); + /** @var AdjustmentInterface $adjustment */ + $adjustment = $shipment->getUnits()->first()->getAdjustments()->first(); + $adjustment->getAmount(); + return new LineItem( $shippingAdjustment->getLabel(), 1, @@ -50,7 +65,7 @@ private function convertUnitRefundToLineItem(UnitRefundInterface $unitRefund): L $unitRefund->total(), $unitRefund->total(), $unitRefund->total(), - 0 + $adjustment->getAmount() ); } } diff --git a/src/Resources/config/services/converter.xml b/src/Resources/config/services/converter.xml index 37d17c90..e1740965 100644 --- a/src/Resources/config/services/converter.xml +++ b/src/Resources/config/services/converter.xml @@ -11,6 +11,7 @@ +