Skip to content

Commit

Permalink
Feature: Allow POS access for guests mollie#823
Browse files Browse the repository at this point in the history
  • Loading branch information
michielgerritsen committed Dec 17, 2024
1 parent edfeaba commit 0bc9cf0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Model/Adminhtml/Source/CustomerGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function toOptionArray(): array
{
$groups = $this->groupManagement->getLoggedInGroups();

$notLoggedInGroup = $this->groupManagement->getNotLoggedInGroup();
array_unshift($groups, $notLoggedInGroup);

$output = [];
foreach ($groups as $group) {
$output[] = [
Expand Down
11 changes: 1 addition & 10 deletions Service/Mollie/PointOfSaleAvailability.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,9 @@ public function __construct(

public function isAvailable(CartInterface $cart): bool
{
$customerId = $this->customerSession->getCustomerId();
if ($customerId === null) {
return false;
}

$storeId = (int)$cart->getStoreId();
$allowedGroups = explode(',', $this->config->pointofsaleAllowedCustomerGroups($storeId));

return in_array(
(string)$this->customerSession->getCustomerGroupId(),
$allowedGroups
);
return $this->isAvailableForCustomerGroupId((int)$this->customerSession->getCustomerGroupId(), $storeId);
}

public function isAvailableForCustomerGroupId(int $customerGroupId, int $storeId): bool
Expand Down
43 changes: 43 additions & 0 deletions Test/Integration/Service/Mollie/PointOfSaleAvailabilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Mollie\Payment\Test\Integration\Service\Mollie;

use Magento\Quote\Model\Quote;
use Mollie\Payment\Service\Mollie\PointOfSaleAvailability;
use Mollie\Payment\Test\Integration\IntegrationTestCase;

class PointOfSaleAvailabilityTest extends IntegrationTestCase
{
/**
* @magentoDataFixture Magento/Sales/_files/quote.php
* @return void
*/
public function testDoesNotAllowAccessWhenSettingIsNotSet(): void
{
$cart = $this->objectManager->create(Quote::class);
$cart->load('test01', 'reserved_order_id');

/** @var \Mollie\Payment\Service\Mollie\PointOfSaleAvailability $instance */
$instance = $this->objectManager->get(PointOfSaleAvailability::class);

$this->assertFalse($instance->isAvailable($cart));
}

/**
* @magentoConfigFixture default_store payment/mollie_methods_pointofsale/allowed_customer_groups 0
* @magentoDataFixture Magento/Sales/_files/quote.php
* @return void
*/
public function testAllowsNotLoggedInAccesWhenConfiguredProperly(): void
{
$cart = $this->objectManager->create(Quote::class);
$cart->load('test01', 'reserved_order_id');

/** @var \Mollie\Payment\Service\Mollie\PointOfSaleAvailability $instance */
$instance = $this->objectManager->get(PointOfSaleAvailability::class);

$this->assertTrue($instance->isAvailable($cart));
}
}

0 comments on commit 0bc9cf0

Please sign in to comment.