Skip to content

Commit

Permalink
Add default groups on carrier creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jolelievre committed Dec 19, 2024
1 parent d82b4d5 commit f5cd78d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace PrestaShop\PrestaShop\Core\Form\IdentifiableObject\DataProvider;

use PrestaShop\PrestaShop\Adapter\Form\ChoiceProvider\ZoneByIdChoiceProvider;
use PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider;
use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface;
use PrestaShop\PrestaShop\Core\ConfigurationInterface;
use PrestaShop\PrestaShop\Core\Context\ShopContext;
Expand All @@ -45,7 +46,8 @@ public function __construct(
private readonly ShopContext $shopContext,
private readonly CurrencyDataProviderInterface $currencyDataProvider,
private readonly ConfigurationInterface $configuration,
private readonly ZoneByIdChoiceProvider $zonesChoiceProvider
private readonly ZoneByIdChoiceProvider $zonesChoiceProvider,
private readonly GroupDataProvider $groupDataProvider,
) {
}

Expand Down Expand Up @@ -91,6 +93,7 @@ public function getDefaultData()
'general_settings' => [
'grade' => 0,
'associated_shops' => $this->shopContext->getAssociatedShopIds(),
'group_access' => $this->groupDataProvider->getAllGroupIds(),
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ services:
arguments: [ "@=service('prestashop.adapter.legacy.context')" ]

prestashop.adapter.data_provider.group:
class: PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider
alias: PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider
deprecated:
package: PrestaShop\PrestaShop
version: 9.0

prestashop.adapter.data_provider.manufacturer:
class: PrestaShop\PrestaShop\Adapter\Manufacturer\ManufacturerDataProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ services:

PrestaShop\PrestaShop\Adapter\Customer\Group\Repository\GroupRepository: ~

PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider: ~

prestashop.adapter.group.group_data_provider:
class: 'PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider'
alias: 'PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider'
deprecated:
package: PrestaShop\PrestaShop
version: 9.0

prestashop.adapter.feature.group_feature:
class: 'PrestaShop\PrestaShop\Adapter\Feature\GroupFeature'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

use PHPUnit\Framework\TestCase;
use PrestaShop\PrestaShop\Adapter\Form\ChoiceProvider\ZoneByIdChoiceProvider;
use PrestaShop\PrestaShop\Adapter\Group\GroupDataProvider;
use PrestaShop\PrestaShop\Core\CommandBus\CommandBusInterface;
use PrestaShop\PrestaShop\Core\ConfigurationInterface;
use PrestaShop\PrestaShop\Core\Context\ShopContext;
Expand Down Expand Up @@ -118,12 +119,15 @@ public function testGetData(): void
'Zone C' => 3,
]);

$groupDataProvider = $this->createMock(GroupDataProvider::class);

$formDataProvider = new CarrierFormDataProvider(
$queryBus,
$this->createMock(ShopContext::class),
$currencyDataProvider,
$configuration,
$zonesChoiceProvider
$zonesChoiceProvider,
$groupDataProvider
);
$formData = $formDataProvider->getData(42);
$this->assertEquals([
Expand Down Expand Up @@ -180,17 +184,24 @@ public function testGetDefaultData(): void
{
$shopContext = $this->createMock(ShopContext::class);
$shopContext->method('getAssociatedShopIds')->willReturn([2, 4]);
$groupDataProvider = $this->createMock(GroupDataProvider::class);
$groupDataProvider
->method('getAllGroupIds')
->willReturn([1, 2, 3]);

$formDataProvider = new CarrierFormDataProvider(
$this->createMock(CommandBusInterface::class),
$shopContext,
$this->createMock(CurrencyDataProviderInterface::class),
$this->createMock(ConfigurationInterface::class),
$this->createMock(ZoneByIdChoiceProvider::class)
$this->createMock(ZoneByIdChoiceProvider::class),
$groupDataProvider
);
$this->assertEquals([
'general_settings' => [
'grade' => 0,
'associated_shops' => [2, 4],
'group_access' => [1, 2, 3],
],
], $formDataProvider->getDefaultData());
}
Expand Down

0 comments on commit f5cd78d

Please sign in to comment.