Skip to content

Commit

Permalink
Bugfix: Handle shipping costs for virtual products mollie#68
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Oct 2, 2023
1 parent e4d579e commit c2bc5e7
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Service/Mollie/GetShippingCostForOrderItem.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Subscriptions\Service\Mollie;

Expand Down Expand Up @@ -53,7 +59,12 @@ public function __construct(

public function execute(OrderInterface $order, OrderItemInterface $orderItem): float
{
if ($order->getIsVirtual()) {
return 0.0;
}

$this->order = $order;

$result = $this->getCarrierResult($orderItem);

if ($price = $this->getRateByCarrier($result)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/*
* Copyright Magmodules.eu. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Mollie\Subscriptions\Test\Integration\Service\Mollie;

use Mollie\Payment\Test\Integration\IntegrationTestCase;
use Mollie\Subscriptions\Service\Mollie\GetShippingCostForOrderItem;

class GetShippingCostForOrderItemTest extends IntegrationTestCase
{
/**
* @magentoDataFixture Magento/Sales/_files/order.php
* @return void
*/
public function testDoesNotAddShippingCostsForVirtualOrders(): void
{
$order = $this->loadOrder('100000001');
$order->setIsVirtual(1);

$items = $order->getItems();
/** @var GetShippingCostForOrderItem $instance */
$instance = $this->objectManager->create(GetShippingCostForOrderItem::class);

$result = $instance->execute($order, array_shift($items));

$this->assertSame(0.0, $result);
}
}

0 comments on commit c2bc5e7

Please sign in to comment.