Comments feature integration

Edit on GitHub
You are browsing a previous version of the document. The latest version is 202212.0.

Install Feature Core

Prerequisites

To start feature integration, overview and install the necessary features:

Name Version
Spryker Core 201907.0
Customer Account Management 201907.0

1) Install the required modules using Composer

Run the following command(s) to install the required modules:

composer require spryker-feature/comments: "^201907.0" --update-with-dependencies
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`Comment``vendor/spryker/comment`
`CommentDataImport``vendor/spryker/comment-data-import`

2) Set up Configuration

Add the following configuration to your project:

Configuration Specification Namespace
CommentConfig::getAvailableCommentTags() Used to allow saving comment tags to the database. Pyz\Shared\Comment
A regular expression (See below in config/Shared/config_default.php) Used to close access for not logged customers. None
src/Pyz/Zed/Comment/CommentConfig.php
<?php
 
namespace Pyz\Shared\Comment;
 
use Spryker\Shared\Comment\CommentConfig as SprykerCommentConfig;
 
class CommentConfig extends SprykerCommentConfig
{
	/**
	 * @return string[]
	 */
	public function getAvailableCommentTags(): array
	{
		return [
			'delivery',
			'important',
		];
	}
}

Verification
Make sure that when you add/remove comment tag (listed in config
to comment is allowed.)
config/Shared/config_default.php
<?php
 
$config[CustomerConstants::CUSTOMER_SECURED_PATTERN] = '(^(/en|/de)?/comment($|/))';


Verification
Make sure that `mysprykershop.com/comment` with a guest user redirects to login page.

3) Set up Database Schema and Transfer Objects

Run the following commands to apply database changes and generate entity and transfer changes:

console transfer:generate
console propel:install
console transfer:generate
Verification
Make sure that the following changes were applied by checking your database:
Database EntityTypeEvent
`spy_comment`tablecreated
`spy_comment_tag`tablecreated
`spy_comment_thread`tablecreated
`spy_comment_to_comment_tag`tablecreated
Verification
Make sure that the following changes in transfer objects:
TransferTypeEventPath
`SpyCommentEntityTransfer`classcreated`src/Generated/Shared/Transfer/SpyCommentEntityTransfer`
`SpyCommentTagEntityTransfer`classcreated`src/Generated/Shared/Transfer/SpyCommentTagEntityTransfer`
`SpyCommentThreadEntityTransfer`classcreated`src/Generated/Shared/Transfer/SpyCommentThreadEntityTransfer`
`SpyCommentToCommentTagEntityTransfer`classcreated`src/Generated/Shared/Transfer/SpyCommentToCommentTagEntityTransfer`
`Comment`classcreated`src/Generated/Shared/Transfer/Comment`
`CommentThread`classcreated`src/Generated/Shared/Transfer/CommentThread`
`CommentTag`classcreated`src/Generated/Shared/Transfer/CommentTag`
`CommentFilter`classcreated`src/Generated/Shared/Transfer/CommentFilter`
`CommentRequest`classcreated`src/Generated/Shared/Transfer/CommentRequest`
`CommentTagRequest`classcreated`src/Generated/Shared/Transfer/CommentTagRequest`
`CommentThreadResponse`classcreated`src/Generated/Shared/Transfer/CommentThreadResponse`

4) Add Translations

Append glossary according to your configuration:

src/data/import/glossary.csv
comment.validation.error.comment_not_found,Comment not found.,en_US
comment.validation.error.comment_not_found,Kommentar nicht gefunden.,de_DE
comment.validation.error.comment_thread_not_found,Comment Thread not found.,en_US
comment.validation.error.comment_thread_not_found,Kommentar Thread nicht gefunden.,de_DE
comment.validation.error.access_denied,Access denied.,en_US
comment.validation.error.access_denied,Zugriff verweigert.,en_US
comment.validation.error.comment_thread_already_exists,Comment Thread already exists.,de_DE
comment.validation.error.comment_thread_already_exists,Kommentar Thread existiert bereits.,de_DE
comment.validation.error.invalid_message_length,Invalid message length.,en_US
comment.validation.error.invalid_message_length,Ungültige Nachrichtenlänge.,de_DE
comment.validation.error.comment_tag_not_available,Comment tag not available.,en_US
comment.validation.error.comment_tag_not_available,Kommentar-Tag nicht verfügbar.,de_DE

Run the following console command to import data:

console data:import glossary
Verification
Make sure that in the database the configured data are added to the `spy_glossary` table.

5) Set up Behavior

Set up Comment Workflow

Enable the following behaviors by registering the plugins:

Plugin Specification Prerequisites Namespace
CommentDataImportPlugin Imports Comments data. None Spryker\Zed\CommentDataImport\Communication\Plugin
src/Pyz/Zed/DataImport/DataImportDependencyProvider.php
<?php
 
namespace Pyz\Zed\DataImport;
 
use Spryker\Zed\CommentDataImport\Communication\Plugin\CommentDataImportPlugin;
use Spryker\Zed\DataImport\DataImportDependencyProvider as SprykerDataImportDependencyProvider;
 
class DataImportDependencyProvider extends SprykerDataImportDependencyProvider
{
	/**
	 * @return array
	 */
	protected function getDataImporterPlugins(): array
	{
		return [
			new CommentDataImportPlugin(),
		];
	}

Verification
Make sure that `spy_comment`, `spy_comment_thread`, and `spy_comment_to_comment_tag` are not empty.

Install feature frontend

Prerequisites

Please overview and install the necessary features before beginning the integration step.

Name Version
Spryker Core 201907.0
Customer Account Management 201907.0

1) Install the required modules using Composer

Run the following command(s) to install the required modules:

composer require spryker-feature/comments: "^201907.0" --update-with-dependencies
Verification
Make sure that the following modules were installed:
ModuleExpected Directory
`CommentWidget``vendor/spryker-shop/comment-widget`
`CommentWidgetExtension``vendor/spryker-shop/comment-widget-extension`

2) Add Translations

Append glossary according to your configuration:

src/data/import/glossary.csv
comment_widget.comments_to_cart,Comments to Cart,en_US
comment_widget.comments_to_cart,Kommentare zum Warenkorb,de_DE
comment_widget.form.add_comment,Add,en_US
comment_widget.form.add_comment,Hinzufügen,de_DE
comment_widget.form.update_comment,Update,en_US
comment_widget.form.update_comment,Aktualisieren,de_DE
comment_widget.form.remove_comment,Remove,en_US
comment_widget.form.remove_comment,Entfernen,de_DE
comment_widget.form.you,You,en_US
comment_widget.form.you,Sie,de_DE
comment_widget.form.attach,Attach,en_US
comment_widget.form.attach,Anhängen,de_DE
comment_widget.form.unattach,Unattach,en_US
comment_widget.form.unattach, Anhang entfernen,de_DE
comment_widget.form.all,All,en_US
comment_widget.form.all,Alles,de_DE
comment_widget.form.attached,Attached,en_US
comment_widget.form.attached,Angehängt,de_DE
comment_widget.form.button_default,Button,en_US
comment_widget.form.button_default,Schaltfläche,de_DE
comment_widget.form.edited,edited,en_US
comment_widget.form.edited,bearbeitet,de_DE
comment_widget.form.tags,Tags,en_US
comment_widget.form.tags,Tags,de_DE
comment_widget.form.placeholder.add_comment,Add a comment,en_US
comment_widget.form.placeholder.add_comment,Kommentar hinzufügen,de_DE
comment_widget.tags.all,All,en_US
comment_widget.tags.all,Alles,de_DE
comment_widget.tags.delivery,Delivery,en_US
comment_widget.tags.delivery,Lieferung,de_DE
comment_widget.tags.important,Important,en_US
comment_widget.tags.important,Wichtig,de_DE

Run the following console command to import data:

console data:import glossary
Verification
Make sure that in the database the configured data are added to the `spy_glossary` table.

3) Enable Controllers

Controller Provider List

Register controller provider(s) in the Yves application

Provider Namespace
CommentWidgetControllerProvider SprykerShop\Yves\CommentWidget\Plugin\Provider
src/Pyz/Yves/ShopApplication/YvesBootstrap.php
<?php
 
namespace Pyz\Yves\ShopApplication;
 
use SprykerShop\Yves\CommentWidget\Plugin\Provider\CommentWidgetControllerProvider;
use SprykerShop\Yves\ShopApplication\YvesBootstrap as SprykerYvesBootstrap;
 
class YvesBootstrap extends SprykerYvesBootstrap
{
	/**
	 * @param bool|null $isSsl
	 *
	 * @return \SprykerShop\Yves\ShopApplication\Plugin\Provider\AbstractYvesControllerProvider[]
	 */
	protected function getControllerProviderStack($isSsl)
	{
		return [
			new CommentWidgetControllerProvider($isSsl),
		];
	}
}

Verification
Verify the `CommentWidgetControllerProvider`, log in as a customer and open the link: `mysprykershop.com/comment/0adafdf4-cb26-477d-850d-b26412fbd382/tag/add?returnUrl=/cart`
Make sure that the error flash message was shown.

4) Set up Widgets

Register the following plugins to enable widgets:

Plugin Description Prerequisites Namespace
CommentThreadWidget Displays comments. None SprykerShop\Yves\CommentWidget\Widget
src/Pyz/Yves/ShopApplication/ShopApplicationDependencyProvider.php
<?php
 
namespace Pyz\Yves\ShopApplication;
 
use SprykerShop\Yves\CommentWidget\Widget\CommentThreadWidget;
use SprykerShop\Yves\ShopApplication\ShopApplicationDependencyProvider as SprykerShopApplicationDependencyProvider;
 
class ShopApplicationDependencyProvider extends SprykerShopApplicationDependencyProvider
{
	/**
	 * @return string[]
	 */
	protected function getGlobalWidgets(): array
	{
		return [
			CommentThreadWidget::class,
		];
	}
}

Run the following command to enable Javascript and CSS changes:

console frontend:yves:build
Verification
Make sure that the following widget was registered:
ModuleTest
`CommentThreadWidget`You can check availability in twig `{% widget 'CommentThreadWidget' args [...] only %}{% endwidget %}`