Download the PHP package tmonier/sylius-channel-access-plugin without Composer

On this page you can find all versions of the php package tmonier/sylius-channel-access-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sylius-channel-access-plugin

Sylius Channel Access Plugin

Build

Choose, channel by channel, whether visitors who are not signed in see the catalogue, the prices and the buy button: open, prices hidden, or closed behind a login.

A B2B shop often needs a login wall (nothing for anonymous visitors) or a catalogue without prices until the customer signs in. Hiding a price in a template is not enough: the same price is in the shop API, and the add-to-cart works whatever the page shows. This plugin enforces the mode on the server.

Features

Mode Anonymous visitor Signed-in customer
open (default) Everything, as Sylius Everything
prices_hidden Catalogue pages; no price, no promotion, no buy button (replaced by a "Log in to see your prices" link), no mini cart; cart, checkout and order routes redirect to the login; the shop API returns no price and refuses carts Everything
closed Only the home page, the login, the registration, the password reset and the routes you exempt; everything else redirects to the login (401 JSON on /api/v2/shop/*); no price, no product and no taxon menu even on the home page and the login Everything

Also: a field on the channel form of the admin (invalid value refused, previous mode kept); responses of a restricted channel are private, no-store (no shared cache mixes visitors); a last-line guard on the order modifier refuses any add to cart of an anonymous visitor of a channel that hides prices (shop pages, live components, shop API, re-order); an unknown stored value reads as closed; translations in English, French, German, Spanish, Italian, Dutch and Polish; MySQL, MariaDB and PostgreSQL (Schema API migration).

Requirements

Version
PHP 8.3+
Sylius 2.3 (the plugin relies on the condition option of the twig hooks, absent from Sylius 2.2)
Symfony 6.4, 7.4, 8.0

Installation

  1. Require the package:

  2. Register the bundle in config/bundles.php:

  3. Add the trait to the channel entity of your application (the plugin changes no Sylius entity on its own):

    and declare it (config/packages/_sylius.yaml):

    A channel class without the trait is treated as closed (and an error is logged): the plugin refuses rather than silently opening everything.

  4. Import the hooks (prices, buy button and the admin field) in config/packages/_sylius.yaml:

  5. Run the migration (one column sylius_channel.access_mode, default open; existing channels stay open):

  6. Choose the mode in the admin: Channels > edit > Access mode.

Configuration

Optional (config/packages/tmonier_sylius_channel_access.yaml):

An anonymous visitor of a closed channel reaches only:

Patterns use * for any characters, / included (/feeds/* matches /feeds/a/b.xml, not /feedsx). A pattern that would match every request (*, /*...) is refused when the container is built. A path containing .., // or a NUL byte is never matched by a path pattern (the request is refused as any non-listed path). Everything not listed is refused, including unknown paths (no 404 page that would show the menu of the catalogue).

Restricting more routes (restricted_routes, restricted_paths)

On a prices hidden channel an anonymous visitor is refused the cart, the checkout, the orders and the shop API orders. Other plugins add routes that show prices or build a priced document; list them with the same patterns as the exemptions (route names with *, paths with *, %parameter% placeholders resolved by the container). They are merged with the built-in ones and refused like the cart: redirection to the login for pages, 401 JSON under the shop API. Examples: the quote request form (tmonier_quote_request_shop_new, tmonier_quote_request_shop_basket_add), the quick order (tmonier_quick_order_shop_add), the AI assistants consent (tmonier_b2b_mcp_shop_*), the volume prices API (.../product-variants/*/tier-prices). On a closed channel everything not exempt is already refused, so these options only matter for prices hidden channels. A value that is empty or not a string is a configuration error naming the option. A route or path that is both in exempt_* and in restricted_* (the built-in ones included) fails the container compilation with a message naming it; the comparison is made on the resolved values and covers an entry that includes another one (for instance exempt_paths: /api/v2/shop/* against the built-in restricted .../orders), in either direction, naming both entries. A restriction wins over an exemption (deny over allow) for the overlaps this comparison cannot see (two wildcard patterns that cross): the safe side of a mistake is a refused route, not an open one.

Prefer route names to paths: a path pattern has to guess every spelling of the URL (format suffix such as .json / .jsonld, trailing slash, locale prefix), a route name is what the router matched. The built-in API restriction covers orders, orders/* and orders.*; for your own API path add the variants (.../tier-prices*). A path that cannot be trusted (.., //, a backslash, a NUL byte) is treated as restricted by the restriction matcher (fail closed) and never matches an exemption.

The redirect always goes to login_route; no query parameter or header of the request chooses the target (no open redirect). The locale of the login URL is the request one when the channel offers it, else the default locale of the channel.

Contract for other plugins

Frozen for 0.x (Tmonier\SyliusChannelAccessPlugin\Access):

The service is tmonier_channel_access.resolver (alias on the interface). Twig: tmonier_channel_access_mode(), tmonier_channel_can_see_prices(), tmonier_channel_can_see_catalog(). Security attributes for is_granted() and hook conditions: TMONIER_CHANNEL_ACCESS_SEE_PRICES, TMONIER_CHANNEL_ACCESS_SEE_CATALOG. A plugin that shows prices elsewhere (a quick order form, a price list) asks the resolver, or puts the same condition on its hookable.

Extension points (used by tmonier/sylius-registration-approval-plugin): decorate the service tmonier_channel_access.resolver to change who counts as signed in (every protection follows), and call VisitorAccessListener::refusalFor(Request): ?Response (service tmonier_channel_access.listener.visitor_access) to know whether an anonymous visitor would be refused for a request, and with which response.

How it works and limits

Testing

See CLAUDE.md for the commands. The functional tests drive the real shop and API and check the rendered behaviour (redirects, absence of prices in pages and JSON, refused add to cart, exempt routes, forged inputs).

License

MIT, see LICENSE.


All versions of sylius-channel-access-plugin with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
sylius/sylius Version ^2.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tmonier/sylius-channel-access-plugin contains the following files

Loading the files please wait ...