Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .github/workflows/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Flex Recipe

on:
push:
branches: [ master ]
branches: [ $default-branch ]
pull_request:

jobs:
Expand All @@ -14,8 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
sylius: ["~1.13.0", "1.14.0"]
php: [ '8.2', '8.3' ]
sylius: [ '~2.0.0', '~2.0.1' ]

steps:
- name: Setup PHP
Expand Down Expand Up @@ -61,13 +61,14 @@ jobs:
- name: Make sure to install the required version of Sylius
working-directory: ./sylius
run: |
composer require --no-install --no-scripts --no-progress sylius/sylius="${{ matrix.sylius }}"
composer require --no-install --no-scripts --no-progress --no-update sylius/sylius="${{ matrix.sylius }}"

- name: Setup some requirements
working-directory: ./sylius
run: |
composer config --no-plugins allow-plugins true
composer config --no-plugins extra.symfony.allow-contrib true
composer config --no-plugins extra.symfony.require "7.2.*"
composer config --no-plugins secure-http false
composer config --no-plugins --unset platform.php
composer config --no-plugins extra.symfony.docker false
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.2', '8.3']

steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Tests

on:
push:
branches: [ master ]
branches: [ $default-branch ]
pull_request:

jobs:
Expand All @@ -14,7 +14,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
php: [ '8.2', '8.3' ]
node: [ '20' ]

env:
SYMFONY_ARGS: --no-tls
Expand All @@ -25,7 +26,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
node-version: ${{ matrix.node }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

declare(strict_types=1);

use PhpCsFixer\UnsupportedPhpVersionAllowedConfigInterface;

$header = <<<'HEADER'
This file is part of Monsieur Biz' Contact Request plugin for Sylius.

Expand Down Expand Up @@ -267,4 +269,8 @@
->setFinder($finder)
;

if ($config instanceof UnsupportedPhpVersionAllowedConfigInterface) {
$config->setUnsupportedPhpVersionAllowed(true);
}

return $config;
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DEFAULT_GOAL := help
SHELL=/bin/bash
APP_DIR=tests/Application
SYLIUS_VERSION=1.14.0
SYLIUS_VERSION=2.1.0
SYMFONY=cd ${APP_DIR} && symfony
COMPOSER=symfony composer
CONSOLE=${SYMFONY} console
Expand Down Expand Up @@ -70,10 +70,11 @@ setup_application:
rm -f ${APP_DIR}/yarn.lock
(cd ${APP_DIR} && ${COMPOSER} config repositories.plugin '{"type": "path", "url": "../../"}')
(cd ${APP_DIR} && ${COMPOSER} config extra.symfony.allow-contrib true)
(cd ${APP_DIR} && ${COMPOSER} config extra.symfony.require "7.2.*")
(cd ${APP_DIR} && ${COMPOSER} config minimum-stability dev)
(cd ${APP_DIR} && ${COMPOSER} config --no-plugins allow-plugins true)
(cd ${APP_DIR} && ${COMPOSER} config --no-plugins --json extra.symfony.endpoint '["https://api.github.com/repos/monsieurbiz/symfony-recipes/contents/index.json?ref=flex/master","flex://defaults"]')
(cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint
(cd ${APP_DIR} && ${COMPOSER} require --no-install --no-scripts --no-progress --no-update sylius/sylius="~${SYLIUS_VERSION}") # Make sure to install the required version of sylius because the sylius-standard has a soft constraint
$(MAKE) ${APP_DIR}/.php-version
$(MAKE) ${APP_DIR}/php.ini
(cd ${APP_DIR} && ${COMPOSER} install --no-interaction)
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ This plugin allows you to customize the contact page on the front-end of your Sy

## Compatibility

| Sylius Version | PHP Version |
|----------------|-----------------|
| 1.13 | 8.1 - 8.2 - 8.3 |
| 1.14 | 8.1 - 8.2 - 8.3 |
| Sylius Version | PHP Version |
|----------------|-------------|
| 2.0, 2.1 | 8.2 - 8.3 |


ℹ️ For Sylius 1.x, see our [1.x branch](https://github.com/monsieurbiz/SyliusContactRequestPlugin/tree/1.x) and all 1.x releases.

## Installation

Expand Down Expand Up @@ -79,14 +81,22 @@ sylius_shop_contact_request:
_locale: ^[A-Za-z]{2,4}(_([A-Za-z]{4}|[0-9]{3}))?(_([A-Za-z]{2}|[0-9]{3}))?$
methods: [GET, POST]
defaults:
_controller: sylius.controller.shop.contact::requestAction
_controller: sylius_shop.controller.contact::requestAction
_sylius:
redirect: sylius_shop_homepage
template: '@MonsieurBizSyliusContactRequestPlugin/Shop/ContactRequest/request.html.twig'
template: '@MonsieurBizSyliusContactRequestPlugin/shop/contact/contact_request.html.twig'
```

This is the same as Sylius route configuration instead of the template key which is overridden to use the plugin template.

Copy the override template in your template directory to display name, company and phone number in the contact email:

```bash
cp -Rv vendor/monsieurbiz/sylius-contact-request-plugin/src/Resources/templates/* templates/
```

Then you can customize the template as you want.

## Contributing

You can find a way to run the plugin without effort in the file [DEVELOPMENT.md](./DEVELOPMENT.md).
Expand Down
6 changes: 6 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# UPGRADE FROM `1.2` TO `2.0`

- Service controller has changed from `sylius.controller.shop.contact` to `sylius_shop.controller.contact`, particularly in the `sylius_shop_contact_request` route in `config/routes/sylius_shop_contact_request_override.yaml`.
- Template path has changed from `@MonsieurBizSyliusContactRequestPlugin/Shop/ContactRequest/request.html.twig` to `@MonsieurBizSyliusContactRequestPlugin/shop/contact/contact_request.html.twig`, particularly in the `sylius_shop_contact_request` route in `config/routes/sylius_shop_contact_request_override.yaml`.
- Replace translation prefix from `monsieurbiz.contact_request.` to `monsieurbiz_contact_request.` for the context "messages".
- Replace translation prefix from `monsieurbiz.contact_request.` to `monsieurbiz_contact_request.contact.` for the context "validators".
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"description": "Add a contact request plugin to your Sylius.",
"license": "MIT",
"require": {
"php": "^8.1",
"sylius/sylius": ">=1.13 <2.0",
"monsieurbiz/sylius-settings-plugin": "^1.2.0",
"monsieurbiz/sylius-rich-editor-plugin": "^2.8.0"
"php": "^8.2",
"sylius/sylius": "~2.0",
"monsieurbiz/sylius-settings-plugin": "^2.0.1",
"monsieurbiz/sylius-rich-editor-plugin": "^3.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.16",
Expand All @@ -30,15 +30,15 @@
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"phpcs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --using-cache=no",
"phpcs": "php-cs-fixer fix --using-cache=no",
"phpstan": "phpstan analyse -c phpstan.neon src/",
"phpmd": "phpmd --exclude Migrations/* src/ ansi phpmd.xml",
"phpunit": "phpunit",
"phpspec": "phpspec run"
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
"dev-master": "2.0-dev"
},
"symfony": {
"docker": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of Monsieur Biz' Contact Request plugin for Sylius.
*
* (c) Monsieur Biz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Context\Channel\RequestBased;

use Sylius\Component\Channel\Context\RequestBased\RequestResolverInterface;
use Sylius\Component\Channel\Model\ChannelInterface;
use Sylius\Component\Channel\Repository\ChannelRepositoryInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
use Symfony\Component\HttpFoundation\Request;

#[AutoconfigureTag('sylius.context.channel.request_based.resolver')]
final class HostnameAndPortBasedRequestResolver implements RequestResolverInterface
{
public function __construct(private ChannelRepositoryInterface $channelRepository)
{
}

public function findChannel(Request $request): ?ChannelInterface
{
return $this->channelRepository->findOneEnabledByHostname($request->getHost() . ':' . $request->getPort());
}
}
Binary file modified docs/images/admin-list.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/demo-shop.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/settings.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 2 additions & 16 deletions src/EmailManager/DecorateContactEmailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,19 @@
use MonsieurBiz\SyliusContactRequestPlugin\Factory\ContactRequestFactoryInterface;
use MonsieurBiz\SyliusSettingsPlugin\Provider\SettingsProviderInterface;
use Sylius\Bundle\CoreBundle\Mailer\ContactEmailManagerInterface;
use Sylius\Bundle\ShopBundle\EmailManager\ContactEmailManagerInterface as OldContactEmailManagerInterface;
use Sylius\Component\Core\Model\ChannelInterface;

final class DecorateContactEmailManager implements ContactEmailManagerInterface
{
public function __construct(
private OldContactEmailManagerInterface|ContactEmailManagerInterface $decoratedContactEmailManager,
private ContactEmailManagerInterface $decoratedContactEmailManager,
private ContactRequestFactoryInterface $contactRequestFactory,
private EntityManagerInterface $contactRequestManager,
private SettingsProviderInterface $settingProvider,
) {
if ($this->decoratedContactEmailManager instanceof OldContactEmailManagerInterface) {
trigger_deprecation(
'sylius/shop-bundle',
'1.13',
'The "%s" interface is deprecated, use "%s" instead.',
OldContactEmailManagerInterface::class,
ContactEmailManagerInterface::class,
);
}
}

public function sendContactRequest(array $data, array $recipients, ChannelInterface $channel = null, string $localeCode = null): void
public function sendContactRequest(array $data, array $recipients, ChannelInterface $channel, string $localeCode): void
{
$settingRecipients = $this->getContactRequestEmailRecipients();
if (!empty($settingRecipients)) {
Expand All @@ -48,10 +38,6 @@ public function sendContactRequest(array $data, array $recipients, ChannelInterf

$this->decoratedContactEmailManager->sendContactRequest($data, $recipients, $channel, $localeCode);

if (null === $channel) {
return;
}

$contactRequest = $this->contactRequestFactory->createNewFromChannelAndData($channel, $data);
$this->contactRequestManager->persist($contactRequest);
$this->contactRequestManager->flush();
Expand Down
18 changes: 9 additions & 9 deletions src/Form/Extension/ContactTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,34 @@ public function buildForm(FormBuilderInterface $builder, array $options): void

$builder
->add('name', TextType::class, [
'label' => 'monsieurbiz.contact_request.form.name',
'label' => 'monsieurbiz_contact_request.form.name',
'required' => $isNameRequired,
'constraints' => $this->getConstraints($isNameRequired, 'monsieurbiz.contact_request.name.not_blank'),
'constraints' => $this->getConstraints($isNameRequired, 'monsieurbiz_contact_request.contact.name.not_blank'),
])
->add('company', TextType::class, [
'label' => 'monsieurbiz.contact_request.form.company',
'label' => 'monsieurbiz_contact_request.form.company',
'required' => $isCompanyRequired,
'constraints' => $this->getConstraints($isCompanyRequired, 'monsieurbiz.contact_request.company.not_blank'),
'constraints' => $this->getConstraints($isCompanyRequired, 'monsieurbiz_contact_request.contact.company.not_blank'),
])
->add('phoneNumber', TelType::class, [
'label' => 'monsieurbiz.contact_request.form.phone_number',
'invalid_message' => 'monsieurbiz.contact_request.phone_number.invalid',
'label' => 'monsieurbiz_contact_request.form.phone_number',
'invalid_message' => 'monsieurbiz_contact_request.contact.phone_number.invalid',
'required' => $isPhoneNumberRequired,
'constraints' => $this->getConstraints($isPhoneNumberRequired, 'monsieurbiz.contact_request.phone_number.not_blank'),
'constraints' => $this->getConstraints($isPhoneNumberRequired, 'monsieurbiz_contact_request.contact.phone_number.not_blank'),
])
;

$isConfirmationFieldDisplayed = (bool) $this->settingProvider->getSettingValue('monsieurbiz_contact_request.contact', 'field_confirmation_displayed');
if ($isConfirmationFieldDisplayed) {
$confirmationFieldLabel = (string) $this->settingProvider->getSettingValue('monsieurbiz_contact_request.contact', 'field_confirmation_label');
$confirmationFieldLabel = empty($confirmationFieldLabel) ? 'monsieurbiz.contact_request.form.confirmation_default_label' : $confirmationFieldLabel;
$confirmationFieldLabel = empty($confirmationFieldLabel) ? 'monsieurbiz_contact_request.form.confirmation_default_label' : $confirmationFieldLabel;
$builder->add('confirmation', CheckboxType::class, [
'label' => $confirmationFieldLabel,
'label_html' => true,
'required' => true,
'constraints' => [
new Assert\NotBlank([
'message' => 'monsieurbiz.contact_request.confirmation_error',
'message' => 'monsieurbiz_contact_request.contact.confirmation_error',
]),
],
]);
Expand Down
Loading
Loading