瀏覽代碼

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

feature/rotating_product
Guillaume Bourgeois 6 月之前
父節點
當前提交
b78172f4ff
共有 8 個檔案被更改,包括 100 行新增11 行删除
  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 查看文件

@@ -4,15 +4,6 @@ namespace domain\Producer\Producer;

use domain\_\AbstractModule;

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

@@ -67,4 +59,9 @@ class ProducerModule extends AbstractModule
{
return DolibarrProducerUtils::getInstance();
}

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

+ 79
- 0
domain/Producer/Producer/ProducerSeoGenerator.php 查看文件

@@ -0,0 +1,79 @@
<?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 查看文件

@@ -74,7 +74,13 @@ $mainColor = $producer->option_main_color ?: '#ee6f42' ;
<!DOCTYPE html>
<html lang="fr-FR">
<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 name="viewport" content="width=device-width, initial-scale=1">
<meta name="base-url" content="<?= \Yii::$app->urlManager->baseUrl; ?>">

+ 1
- 0
producer/views/order/order.php 查看文件

@@ -51,6 +51,7 @@ $producerModule = ProducerModule::getInstance();
$producer = $this->context->getProducerCurrent();

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

?>


+ 4
- 0
producer/views/site/contact.php 查看文件

@@ -36,11 +36,15 @@ pris connaissance de la licence CeCILL, et que vous en avez accepté les
termes.
*/

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

$producerModule = ProducerModule::getInstance();

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

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

+ 1
- 1
producer/views/site/index.php 查看文件

@@ -51,10 +51,10 @@ $productModule = ProductModule::getInstance();
$producerModule = ProducerModule::getInstance();
$distributionModule = DistributionModule::getInstance();
$pointSaleModule = PointSaleModule::getInstance();

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

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

?>


+ 1
- 0
producer/views/site/points-sale.php 查看文件

@@ -56,6 +56,7 @@ $producer = $this->context->getProducerCurrent();

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

?>


+ 1
- 0
producer/views/site/products.php 查看文件

@@ -56,6 +56,7 @@ $producer = $this->context->getProducerCurrent();

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

?>


Loading…
取消
儲存