Product Sets feature integration
Edit on GitHubThis document describes how to install the Product Sets feature.
Prerequisites
To prepare your project to work with Product Sets:
- Require the Product Set modules in your
composer.json
:
composer require spryker/product-set spryker/product-set-collector spryker/product-set-gui
- If you want to enable the Product Sets search powered by Elasticsearch, install the
spryker/search-elasticsearch
module:
composer require spryker/search-elasticsearch
- Install the new database tables:
vendor/bin/console propel:diff
Propel should generate a migration file with the changes.
- Apply the database changes:
vendor/bin/console propel:migrate
- Generate ORM models:
vendor/bin/console propel:model:build
Make sure that:
-
New classes have been added to
\Orm\Zed\ProductSet\Persistence
. -
They extend the base classes from the Spryker core. For example:
-
\Orm\Zed\ProductSet\Persistence\SpyProductSet
extends\Spryker\Zed\ProductSet\Persistence\Propel\AbstractSpyProductSet
-
\Orm\Zed\ProductSet\Persistence\SpyProductSetData
extends\Spryker\Zed\ProductSet\Persistence\Propel\AbstractSpyProductSetData
-
\Orm\Zed\ProductSet\Persistence\SpyProductAbstractSet
extends\Spryker\Zed\ProductSet\Persistence\Propel\AbstractSpyProductAbstractSet
-
\Orm\Zed\ProductSet\Persistence\SpyProductSetQuery
extends\Spryker\Zed\ProductSet\Persistence\Propel\AbstractSpyProductSetQuery
-
\Orm\Zed\ProductSet\Persistence\SpyProductSetDataQuery
extends\Spryker\Zed\ProductSet\Persistence\Propel\AbstractSpyProductSetDataQuery
-
\Orm\Zed\ProductSet\Persistence\SpyProductAbstractSetQuery
extends\Spryker\Zed\ProductSet\Persistence\Propel\AbstractSpyProductAbstractSetQuery
-
- Get the new transfer objects:
vendor/bin/console transfer:generate
- Rebuild Zed navigation:
vendor/bin/console navigation:build-cache
- To activate the Product Set collectors, add
ProductSetCollectorStoragePlugin
to the storage collector plugin stack andProductSetCollectorSearchPlugin
to the search collector plugin stack:
<?php
namespace Pyz\Zed\Collector;
use Spryker\Shared\ProductSet\ProductSetConfig;
use Spryker\Zed\Kernel\Container;
use Spryker\Zed\ProductSetCollector\Communication\Plugin\ProductSetCollectorSearchPlugin;
use Spryker\Zed\ProductSetCollector\Communication\Plugin\ProductSetCollectorStoragePlugin;
// ...
class CollectorDependencyProvider extends SprykerCollectorDependencyProvider
{
/**
* @param \Spryker\Zed\Kernel\Container $container
*
* @return \Spryker\Zed\Kernel\Container
*/
public function provideBusinessLayerDependencies(Container $container)
{
// ...
$container->set(static::SEARCH_PLUGINS, function (Container $container) {
return [
// ...
ProductSetConfig::RESOURCE_TYPE_PRODUCT_SET => new ProductSetCollectorSearchPlugin(),
];
});
$container->set(static::STORAGE_PLUGINS, function (Container $container) {
return [
// ...
ProductSetConfig::RESOURCE_TYPE_PRODUCT_SET => new ProductSetCollectorStoragePlugin(),
];
});
// ...
}
}
Data setup
Implement an installer in your project to put products together in sets representing how you want them to be displayed in your shop frontend. Find implementation examples in the Demoshop.
Listing products sets on the Storefront
The KV storage and Elasticsearch should by now contain some product sets you can display on the Storefront. By default, the exported documents in Search do not support the configurable search features as products: full-text search, faceted navigation, sorting, and pagination. However, since their data structure is the same, it is possible to implement the same features with a custom implementation.
For a simple listing, the ProductSet
module provides a Client API to list product sets from Elasticsearch. By calling the ProductSetClient::getProductSetList()
method, a limited set of documents can be listed on the Storefront. The results are sorted in descending order based on the product sets’ weight attributes.
The executed search query works the same way as described in Search Query.
If you need to extend the query, for example, by filtering current store and locale, add the desired query expander plugins, like in the example below. To format a raw response from Elasticsearch, provide a result formatter plugin that is also provided by the ProductSet
module.
<?php
namespace Pyz\Client\ProductSet;
use Spryker\Client\ProductSet\Plugin\Elasticsearch\ResultFormatter\ProductSetListResultFormatterPlugin;
use Spryker\Client\ProductSet\ProductSetDependencyProvider as SprykerProductSetDependencyProvider;
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\LocalizedQueryExpanderPlugin;
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\StoreQueryExpanderPlugin;
class ProductSetDependencyProvider extends SprykerProductSetDependencyProvider
{
/**
* @return array
*/
protected function getProductSetListResultFormatterPlugins()
{
return [
new ProductSetListResultFormatterPlugin(),
];
}
/**
* @return array
*/
protected function getProductSetListQueryExpanderPlugins()
{
return [
new LocalizedQueryExpanderPlugin(),
new StoreQueryExpanderPlugin(),
];
}
}
You can reorder product sets in the Back Office. See Reorder product sets for more details.
Thank you!
For submitting the form