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(); | |||||
} | |||||
} | } |
<?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); | |||||
} | |||||
} |
<!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; ?>"> |
$producer = $this->context->getProducerCurrent(); | $producer = $this->context->getProducerCurrent(); | ||||
$this->setTitle('Commander'); | $this->setTitle('Commander'); | ||||
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionOrder()); | |||||
?> | ?> | ||||
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"> |
$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()); | |||||
?> | ?> | ||||
$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()); | |||||
?> | ?> | ||||
$this->setTitle('Produits'); | $this->setTitle('Produits'); | ||||
$this->setPageTitle('Produits'); | $this->setPageTitle('Produits'); | ||||
$this->setMeta('description', $producerModule->getSeoGenerator()->generateMetaDescriptionProducts()); | |||||
?> | ?> | ||||