Browse Source

[Site & boutique] Référencement : mise en place de meta descriptions

feature/rotating_product
Guillaume Bourgeois 6 months ago
parent
commit
b78172f4ff
8 changed files with 100 additions and 11 deletions
  1. +6
    -9
      domain/Producer/Producer/ProducerModule.php
  2. +79
    -0
      domain/Producer/Producer/ProducerSeoGenerator.php
  3. +7
    -1
      producer/views/layouts/main.php
  4. +1
    -0
      producer/views/order/order.php
  5. +4
    -0
      producer/views/site/contact.php
  6. +1
    -1
      producer/views/site/index.php
  7. +1
    -0
      producer/views/site/points-sale.php
  8. +1
    -0
      producer/views/site/products.php

+ 6
- 9
domain/Producer/Producer/ProducerModule.php View File



use domain\_\AbstractModule; use domain\_\AbstractModule;


/**
* @mixin ProducerDefinition
* @mixin ProducerSolver
* @mixin ProducerRepository
* @mixin ProducerBuilder
* @mixin ProducerManager
* @mixin ProducerPageSizer
* @mixin DolibarrProducerUtils
*/
class ProducerModule extends AbstractModule class ProducerModule extends AbstractModule
{ {
public function getServices(): array public function getServices(): array
ProducerManager::class, ProducerManager::class,
ProducerPageSizer::class, ProducerPageSizer::class,
DolibarrProducerUtils::class, DolibarrProducerUtils::class,
ProducerSeoGenerator::class,
]; ];
} }


{ {
return DolibarrProducerUtils::getInstance(); return DolibarrProducerUtils::getInstance();
} }

public function getSeoGenerator(): ProducerSeoGenerator
{
return ProducerSeoGenerator::getInstance();
}
} }

+ 79
- 0
domain/Producer/Producer/ProducerSeoGenerator.php View File

<?php

namespace domain\Producer\Producer;

use domain\_\AbstractGenerator;
use domain\PointSale\PointSale\PointSaleRepository;
use domain\Product\Product\ProductRepository;
use yii\helpers\Html;

class ProducerSeoGenerator extends AbstractGenerator
{
protected ProductRepository $productRepository;
protected PointSaleRepository $pointSaleRepository;

public function loadDependencies(): void
{
$this->productRepository = $this->loadService(ProductRepository::class);
$this->pointSaleRepository = $this->loadService(PointSaleRepository::class);
}

public function generateMetaDescriptionHome()
{
$producer = $this->getProducerContext();

if($producer->description) {
$metaDescription = substr(strip_tags($producer->description), 0, 200);
}
else {
$metaDescription = "Bienvenue sur la boutique du producteur ".Html::encode($producer->name);
}

return $metaDescription;
}

public function generateMetaDescriptionProducts()
{
$metaDescription = '';
$productsArray = $this->productRepository->findProducts();

foreach($productsArray as $product) {
$metaDescription .= Html::encode($product->name).', ';
}

if(strlen($metaDescription)) {
$metaDescription = substr($metaDescription, 0, strlen($metaDescription) - 2);
}

return $metaDescription;
}

public function generateMetaDescriptionPointsSale()
{
$metaDescription = '';
$pointsSaleArray = $this->pointSaleRepository->findPointSales();

foreach($pointsSaleArray as $pointSale) {
$metaDescription .= Html::encode($pointSale->name).', ';
}

if(strlen($metaDescription)) {
$metaDescription = substr($metaDescription, 0, strlen($metaDescription) - 2);
}

return $metaDescription;
}

public function generateMetaDescriptionOrder()
{
$producer = $this->getProducerContext();
return "Passez commande chez ".Html::encode($producer->name)." à la date et au lieu de votre choix.";
}

public function generateMetaDescriptionContact()
{
$producer = $this->getProducerContext();
return 'Contactez ce producteur en utilisant le formulaire de contact. '
.Html::encode($producer->name.', '.$producer->address.' '.$producer->postcode.' '.$producer->city);
}
}

+ 7
- 1
producer/views/layouts/main.php View File

<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr-FR"> <html lang="fr-FR">
<head> <head>
<title><?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?></title>
<title>
<?php if($this->getControllerAction() == 'site/index'): ?>
<?= Html::encode($producer->name); ?> | <?= $this->getPageTitle(); ?>
<?php else: ?>
<?= $this->getPageTitle(); ?> | <?= Html::encode($producer->name); ?>
<?php endif; ?>
</title>
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>"> <meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">

+ 1
- 0
producer/views/order/order.php View File

$producer = $this->context->getProducerCurrent(); $producer = $this->context->getProducerCurrent();


$this->setTitle('Commander'); $this->setTitle('Commander');
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionOrder());


?> ?>



+ 4
- 0
producer/views/site/contact.php View File

termes. termes.
*/ */


use domain\Producer\Producer\ProducerModule;
use yii\helpers\Html; use yii\helpers\Html;
use yii\bootstrap\ActiveForm; use yii\bootstrap\ActiveForm;
use yii\captcha\Captcha; use yii\captcha\Captcha;


$producerModule = ProducerModule::getInstance();

$this->setTitle('Contact'); $this->setTitle('Contact');
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionContact());


?> ?>
<div class="site-contact"> <div class="site-contact">

+ 1
- 1
producer/views/site/index.php View File

$producerModule = ProducerModule::getInstance(); $producerModule = ProducerModule::getInstance();
$distributionModule = DistributionModule::getInstance(); $distributionModule = DistributionModule::getInstance();
$pointSaleModule = PointSaleModule::getInstance(); $pointSaleModule = PointSaleModule::getInstance();

$producer = $this->context->getProducerCurrent(); $producer = $this->context->getProducerCurrent();


$this->setPageTitle(Html::encode($producer->type . ' à ' . $producer->city)); $this->setPageTitle(Html::encode($producer->type . ' à ' . $producer->city));
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionHome());


?> ?>



+ 1
- 0
producer/views/site/points-sale.php View File



$this->setTitle('Points de vente'); $this->setTitle('Points de vente');
$this->setPageTitle('Points de vente'); $this->setPageTitle('Points de vente');
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionPointsSale());


?> ?>



+ 1
- 0
producer/views/site/products.php View File



$this->setTitle('Produits'); $this->setTitle('Produits');
$this->setPageTitle('Produits'); $this->setPageTitle('Produits');
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionProducts());


?> ?>



Loading…
Cancel
Save