Browse Source

Merge branch 'develop'

master
Guillaume 4 years ago
parent
commit
6b70177c5c
5 changed files with 61 additions and 21 deletions
  1. +45
    -17
      ShopBundle/Controller/Backend/NewsController.php
  2. +11
    -0
      ShopBundle/Model/Product.php
  3. +1
    -1
      ShopBundle/Model/ProductFamily.php
  4. +2
    -2
      ShopBundle/Repository/OrderShopRepository.php
  5. +2
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml

+ 45
- 17
ShopBundle/Controller/Backend/NewsController.php View File

@@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use \Mailjet\Resources ;

class NewsController extends AdminController
{
@@ -60,34 +61,61 @@ class NewsController extends AdminController

public function sendAction()
{
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ;
$newsletter = $this->getNewsletter() ;

$news = $this->getNews() ;
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ;
$countUsers = count($users) ;
$messages = [];
$toArray = [];

foreach ($users as $user) {
$message = new \Swift_Message('[Place du Local] '.$news->getTitle());
$message->addTo($user->getEmail())
->addFrom($this->getParameter('app.noreply_email'), $this->getParameter('app.site_name'))
->setBody($this->renderView('mail/news-html.html.twig', [
'news' => $news,
'newsletter' => $newsletter,
'user' => $user
]), 'text/html');
array_push($messages, $message);
$toArray[] = [
'Email' => $user->getEmail(),
'Name' => $user->getFirstname().' '.$user->getLastname(),
] ;
}

if($countUsers > 0) {
$result = $this->mailjetTransport->bulkSend($messages);

$this->addFlash('success', 'Actualité envoyée à '.count($users).' utilisateurs.');

$news->setIsSent(true) ;
$this->em->persist($news);
$this->em->flush() ;
$mj = new \Mailjet\Client($this->mailjetTransport->getApiKey(), $this->mailjetTransport->getApiSecret(),true,['version' => 'v3.1']);

$paramsTemplate = [
'news' => $news,
'newsletter' => $newsletter,
'user' => $this->security->getUser()
] ;

$body = [
'Messages' => [
[
'From' => [
'Email' => $this->getParameter('app.noreply_email'),
'Name' => $this->getParameter('app.site_name')
],
'To' => $toArray,
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(),
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate),
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate),
'CustomCampaign' => $news->getTitle(),
'DeduplicateCampaign' => true
]
]
];


$response = $mj->post(Resources::$Email, ['body' => $body]);

if($response->success()) {
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.');

$news->setIsSent(true) ;
$this->em->persist($news);
$this->em->flush() ;
}
else {
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité.");
}
}
else {
$this->addFlash('error', 'Aucun utilisateur inscrit à la newsletter.');

+ 11
- 0
ShopBundle/Model/Product.php View File

@@ -54,6 +54,17 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
$this->status = 1;
}

public function __toString()
{
$title = $this->getProductFamily()->getTitle() ;

if($this->getTitle() && strlen($this->getTitle())) {
$title .= ' - '. $this->getTitle() ;
}

return $title ;
}

public function getBuyingPriceInherited()
{
if ($this->getBuyingPrice()) {

+ 1
- 1
ShopBundle/Model/ProductFamily.php View File

@@ -657,7 +657,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr

public function setPropertyVariety(?string $propertyVariety): self
{
$this->propertyQuantity = $propertyVariety;
$this->propertyVariety = $propertyVariety;

return $this;
}

+ 2
- 2
ShopBundle/Repository/OrderShopRepository.php View File

@@ -165,8 +165,8 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->andWhere('e.deliveryAddress = :address OR e.invoiceAddress = :address')->setParameter('address', $params['address']);
}

if(isset($params['weekDeliveryTruck'])) {
$query->andWhere('e.weekDeliveryTruck = :weekDeliveryTruck')->setParameter('weekDeliveryTruck', $params['weekDeliveryTruck']);
if(isset($params['weekDeliveryTrucks'])) {
$query->andWhere('e.weekDeliveryTruck IN (:weekDeliveryTrucks)')->setParameter('weekDeliveryTrucks', $params['weekDeliveryTrucks']);
}

if(isset($params['estimatedDeliveryDateTime'])) {

+ 2
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml View File

@@ -268,6 +268,7 @@ field:
metaDescription: Meta description
users: Utilisateurs
total: Total
products: Produits

PointSale:
code: Code
@@ -381,7 +382,7 @@ field:
quantityProduct: Quantité (en rapport à l'unité)
unit: Unité
OrderShop:
deliveryTruck: Véhicule de livraison
deliveryTrucks: Véhicules de livraison
createdAt: Date de création
updatedAt: Date de modification
save: Sauvegarder

Loading…
Cancel
Save