@@ -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(); | |||
} | |||
} |
@@ -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); | |||
} | |||
} |
@@ -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; ?>"> |
@@ -51,6 +51,7 @@ $producerModule = ProducerModule::getInstance(); | |||
$producer = $this->context->getProducerCurrent(); | |||
$this->setTitle('Commander'); | |||
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionOrder()); | |||
?> | |||
@@ -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"> |
@@ -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()); | |||
?> | |||
@@ -56,6 +56,7 @@ $producer = $this->context->getProducerCurrent(); | |||
$this->setTitle('Points de vente'); | |||
$this->setPageTitle('Points de vente'); | |||
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionPointsSale()); | |||
?> | |||
@@ -56,6 +56,7 @@ $producer = $this->context->getProducerCurrent(); | |||
$this->setTitle('Produits'); | |||
$this->setPageTitle('Produits'); | |||
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionProducts()); | |||
?> | |||