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/ */
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();
}
}