composer require commerce-weavers/sylius-also-bought-plugin
// config/bundles.php
CommerceWeavers\SyliusAlsoBoughtPlugin\CommerceWeaversSyliusAlsoBoughtPlugin::class => ['all' => true],
# config/packages/cw_sylius_also_bought_plugin.yaml
imports:
- { resource: "@CommerceWeaversSyliusAlsoBoughtPlugin/config/app/config.yaml" }
commerce_weavers_sylius_also_bought:
number_of_products_to_associate: 10 # default value
batch_size_limit: 1000 # default value
// src/Entity/Product/Product.php
<?php
declare(strict_types=1);
namespace App\Entity\Product;
use CommerceWeavers\SyliusAlsoBoughtPlugin\Entity\BoughtTogetherProductsAwareInterface;
use CommerceWeavers\SyliusAlsoBoughtPlugin\Entity\BoughtTogetherProductsAwareTrait;
use Doctrine\ORM\Mapping as ORM;
use Sylius\Component\Core\Model\Product as BaseProduct;
#[ORM\Entity]
#[ORM\Table(name: 'sylius_product')]
class Product extends BaseProduct implements BoughtTogetherProductsAwareInterface
{
use BoughtTogetherProductsAwareTrait;
}
bin/console doctrine:migrations:migrate -n
bin/console sylius:also-bought:setup
bin/console sylius:also-bought:synchronize
Run this command periodically to keep the bought together products up to date. Use cron or any other scheduler to automate this process.
bin/console cache:clear
bin/console cache:warmup