PHP code example of setono / sylius-analytics-plugin

1. Go to this page and download the library: Download setono/sylius-analytics-plugin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

setono / sylius-analytics-plugin example snippets



$bundles = [
    Setono\SyliusAnalyticsPlugin\SetonoSyliusAnalyticsPlugin::class => ['all' => true],
    Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
];


use Setono\SyliusAnalyticsPlugin\Resolver\Brand\BrandResolverInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;

final class BrandResolver implements BrandResolverInterface
{
    public function resolveFromProduct(ProductInterface $product): ?string
    {
        return $product->getBrand(); // here we assume the getBrand() method will return a brand name or null (if not set)
    }

    public function resolveFromProductVariant(ProductVariantInterface $productVariant): ?string
    {
        return $this->resolveFromProduct($productVariant->getProduct());
    }
}


use Setono\SyliusAnalyticsPlugin\Resolver\Variant\VariantResolverInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;

final class ProductNameBasedVariantResolver implements VariantResolverInterface
{
    public function resolve(ProductVariantInterface $productVariant): ?string
    {
        return $productVariant->getProduct()->getName();
    }
}
bash
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate