Skip to content

Commit

Permalink
Improve zero waste fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsegura committed Feb 7, 2025
1 parent 88b1a35 commit 4a6bd24
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
32 changes: 6 additions & 26 deletions src/Entity/Sylius/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -1738,20 +1738,10 @@ public function getLoopeatDeliver()

public function getLoopeatAccessToken()
{
if (null === $this->loopeatCredentials) {

return null;
}

$accessToken = $this->loopeatCredentials->getLoopeatAccessToken();

// Guest checkout
if (null !== $accessToken) {

return $accessToken;
}
$ownToken = $this->loopeatCredentials?->getLoopeatAccessToken();
$customerToken = $this->customer?->getLoopeatAccessToken();

return $this->customer->getLoopeatAccessToken();
return $customerToken ?? $ownToken;
}

public function setLoopeatAccessToken($accessToken)
Expand All @@ -1771,20 +1761,10 @@ public function setLoopeatAccessToken($accessToken)

public function getLoopeatRefreshToken()
{
if (null === $this->loopeatCredentials) {

return null;
}

$refreshToken = $this->loopeatCredentials->getLoopeatRefreshToken();

// Guest checkout
if (null !== $refreshToken) {

return $refreshToken;
}
$ownToken = $this->loopeatCredentials?->getLoopeatRefreshToken();
$customerToken = $this->customer?->getLoopeatRefreshToken();

return $this->customer->getLoopeatRefreshToken();
return $customerToken ?? $ownToken;
}

public function setLoopeatRefreshToken($refreshToken)
Expand Down
26 changes: 26 additions & 0 deletions tests/AppBundle/Entity/Sylius/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use AppBundle\Entity\LocalBusiness;
use AppBundle\Entity\ReusablePackaging;
use AppBundle\Entity\ReusablePackagings;
use AppBundle\Entity\Sylius\Customer;
use AppBundle\Entity\Sylius\Order;
use AppBundle\Sylius\Order\OrderItemInterface;
use AppBundle\Sylius\Order\OrderInterface;
Expand Down Expand Up @@ -176,4 +177,29 @@ public function testGetFormatsToDeliverForLoopeatGroupsContainers()

$this->assertEquals($expectedFormats, $order->getFormatsToDeliverForLoopeat());
}

public function testLoopeatCredentialsAreResolvedFromCustomer()
{
$order = new Order();
$customer = new Customer();

$order->setCustomer($customer);

$customer->setLoopeatAccessToken('123456');
$customer->setLoopeatRefreshToken('654321');

$this->assertEquals('123456', $order->getLoopeatAccessToken());
$this->assertEquals('654321', $order->getLoopeatRefreshToken());
}

public function testLoopeatCredentialsAreResolvedFromOrder()
{
$order = new Order();

$order->setLoopeatAccessToken('123456');
$order->setLoopeatRefreshToken('654321');

$this->assertEquals('123456', $order->getLoopeatAccessToken());
$this->assertEquals('654321', $order->getLoopeatRefreshToken());
}
}

0 comments on commit 4a6bd24

Please sign in to comment.