Integrate warehouse address ACL for the Merchant Portal
Edit on GitHubIn the Merchant Portal, Propel queries are scoped by ACL entity rules, and an entity that is absent from the composed ACL entity metadata configuration is not readable for merchant users. Orm\Zed\StockAddress\Persistence\SpyStockAddress is such an entity unless you register it explicitly.
When the entity is missing from the configuration, merchant users cannot read warehouse addresses: StockTransfer.address stays empty even though the spy_stock_address record exists. Features that depend on the warehouse address can then fail further downstream, far from the actual cause.
StockAddressAclEntityConfigurationExpanderPlugin registers SpyStockAddress as a sub-entity of SpyStock. The address then inherits the ACL scope of its stock, so a merchant user who can read a warehouse can also read that warehouse’s address.
Prerequisites
Before you start, make sure that the following prerequisites are met:
- Your project uses the Merchant Portal with ACL entity restrictions enabled.
- Your project uses
spryker/stock-address1.5.0 or later.StockAddressAclEntityConfigurationExpanderPluginwas introduced in version 1.5.0.
Minimum required versions of the packages:
| Package | Minimum version |
|---|---|
| spryker/stock-address | 1.5.0 |
If your project uses an earlier version, upgrade the package to version 1.5.0 or later:
composer require spryker/stock-address:"^1.5.0" --update-with-dependencies
Register the ACL entity configuration plugin
Add StockAddressAclEntityConfigurationExpanderPlugin to the getAclEntityConfigurationExpanderPlugins() method:
src/Pyz/Zed/AclMerchantPortal/AclMerchantPortalDependencyProvider.php
<?php
namespace Pyz\Zed\AclMerchantPortal;
use Spryker\Zed\AclMerchantPortal\AclMerchantPortalDependencyProvider as SprykerAclMerchantPortalDependencyProvider;
use Spryker\Zed\StockAddress\Communication\Plugin\AclMerchantPortal\StockAddressAclEntityConfigurationExpanderPlugin;
class AclMerchantPortalDependencyProvider extends SprykerAclMerchantPortalDependencyProvider
{
/**
* @return list<\Spryker\Zed\AclMerchantPortalExtension\Dependency\Plugin\AclEntityConfigurationExpanderPluginInterface>
*/
protected function getAclEntityConfigurationExpanderPlugins(): array
{
return [
// ... other ACL entity configuration expander plugins
new StockAddressAclEntityConfigurationExpanderPlugin(),
];
}
}
The plugin registers the following entity:
| Entity | Relationship | Reason |
|---|---|---|
Orm\Zed\StockAddress\Persistence\SpyStockAddress |
Sub-entity of Orm\Zed\Stock\Persistence\SpyStock |
The address belongs to a single warehouse, so it inherits the ACL scope of that warehouse instead of defining its own permissions. |
Because you changed a dependency provider, clear the application cache by running:
vendor/bin/console cache:empty-all
Verify the integration
First, validate the ACL entity metadata configuration:
vendor/bin/console acl-entity:metadata:validate
When the warehouse address metadata is registered correctly, the output is ACL entity metadata configuration is valid.
To verify that merchant users can read warehouse addresses:
- Make sure that the warehouse assigned to one of the merchant’s product offers has an address. In the database, the
spy_stock_addresstable must contain a record whosefk_stockpoints to that warehouse. - Log in to the Merchant Portal as a user of that merchant.
- Open an order that contains a product offer from that warehouse and trigger an operation that reads the warehouse address, such as a refund.
- Make sure that the operation completes and that the order moves to the expected state.
- Make sure that no
NullValueExceptionfor a missing address is logged for the request.
Thank you!
For submitting the form