瀏覽代碼

Merge branch 'develop'

master
Fab 4 年之前
父節點
當前提交
8244cd2367
共有 10 個檔案被更改,包括 99 行新增164 行删除
  1. +1
    -0
      ShopBundle/Controller/Backend/OrderController.php
  2. +0
    -58
      ShopBundle/Form/Backend/Common/ProductType.php
  3. +0
    -52
      ShopBundle/Form/Backend/Common/UserType.php
  4. +5
    -0
      ShopBundle/Model/OrderStatus.php
  5. +2
    -0
      ShopBundle/Repository/NewsRepository.php
  6. +15
    -7
      ShopBundle/Repository/OrderShopRepository.php
  7. +9
    -2
      ShopBundle/Resources/translations/lcshop.fr.yaml
  8. +2
    -2
      ShopBundle/Resources/views/backend/order/macros.html.twig
  9. +51
    -43
      ShopBundle/Services/MailUtils.php
  10. +14
    -0
      ShopBundle/Services/Order/OrderUtilsCartTrait.php

+ 1
- 0
ShopBundle/Controller/Backend/OrderController.php 查看文件

@@ -511,6 +511,7 @@ class OrderController extends AdminController

if (!$user instanceof UserInterface) return $user;
else {
//TODO Utiliser getCartByUserOrCreateIt ds OrderUtils
$orderShopUser = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($orderShopUser) {
$this->utils->addFlash('info', 'error.order.otherOrderAlreadyExist');

+ 0
- 58
ShopBundle/Form/Backend/Common/ProductType.php 查看文件

@@ -1,58 +0,0 @@
<?php

namespace Lc\ShopBundle\Form\Backend\Common;

use Doctrine\ORM\EntityManagerInterface;

use Doctrine\ORM\EntityRepository;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class ProductType extends AbstractType
{
protected $em;
protected $merchantUtils;

public function __construct(EntityManagerInterface $entityManager, MerchantUtilsInterface $merchantUtils)
{
$this->em = $entityManager;
$this->merchantUtils = $merchantUtils;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$productClass = $this->em->getClassMetadata(ProductInterface::class);
$currentMerchant = $this->merchantUtils->getMerchantUser();

$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($productClass, $options, $currentMerchant) {
$builder = $event->getForm()->getParent();

$builder->add('product', EntityType::class, array_merge($options,[
'class' => $productClass->name,
'query_builder' => function (EntityRepository $er) use ($currentMerchant) {
return $er->createQueryBuilder('p')
->join('p.productFamily', 'pFamily')
->where('pFamily.merchant = :currentMerchant')
->andWhere('pFamily.status = 1')
->setParameter('currentMerchant', $currentMerchant);
},
'choice_label' => function ($product) {
return $product->getProductFamily()->getTitle() . ' - ' . $product->getTitle();
}
]));
});
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'translation_domain' => 'lcshop',
]);
}
}

+ 0
- 52
ShopBundle/Form/Backend/Common/UserType.php 查看文件

@@ -1,52 +0,0 @@
<?php

namespace Lc\ShopBundle\Form\Backend\Common;

use Doctrine\ORM\EntityManagerInterface;

use Doctrine\ORM\EntityRepository;
use Lc\ShopBundle\Context\ReductionCatalogInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Repository\GroupUserRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class UserType extends AbstractType
{
protected $em;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$userClass = $this->em->getClassMetadata(UserInterface::class);
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($userClass, $options) {
$builder = $event->getForm()->getParent();

$builder->add('user', EntityType::class, array_merge($options,[
'class' => $userClass->name,
'query_builder'=> function (EntityRepository $er) {
$query = $er->findByMerchantQuery();
return $query;
},
'expanded' => false,
'translation_domain'=>'lcshop',
]));
});
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'translation_domain' => 'lcshop',
]);
}
}

+ 5
- 0
ShopBundle/Model/OrderStatus.php 查看文件

@@ -37,6 +37,11 @@ abstract class OrderStatus
self::ALIAS_DONE
] ;

static $statusAliasWaitingDelivery = [
self::ALIAS_WAITING_DELIVERY,
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT,
];

static $statusAliasAsCart = [
self::ALIAS_CART,
self::ALIAS_WAITING_PAYMENT_ONLINE,

+ 2
- 0
ShopBundle/Repository/NewsRepository.php 查看文件

@@ -24,6 +24,8 @@ class NewsRepository extends BaseRepository implements DefaultRepositoryInterfac
$result = $this->findByMerchantQuery()
->orderBy('e.date', 'DESC') ;

$result->andWhere('e.status = 1') ;

if($maxResults) {
$result->setMaxResults($maxResults) ;
}

+ 15
- 7
ShopBundle/Repository/OrderShopRepository.php 查看文件

@@ -65,20 +65,24 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt

public function filterOrderValid(?QueryBuilder $query): QueryBuilder
{
$query->leftJoin('e.orderStatus', 'os');
$query->andWhere('os.alias IN (:alias)');
$query->setParameter('alias', OrderStatus::$statusAliasAsValid);
return $this->_filterOrderStatus($query, OrderStatus::$statusAliasAsValid) ;
}

return $query;
public function filterOrderWaitingDelivery($query)
{
return $this->_filterOrderStatus($query, OrderStatus::$statusAliasWaitingDelivery) ;
}

public function filterOrderCart($query)
{
return $this->_filterOrderStatus($query, OrderStatus::$statusAliasAsCart) ;
}

private function _filterOrderStatus($query, $statusArray) {
$query->leftJoin('e.orderStatus', 'os');
$query->andWhere('os.alias IN (:alias)');
$query->setParameter('alias', OrderStatus::$statusAliasAsCart);

return $query;
$query->setParameter('alias',$statusArray);
return $query ;
}

public function findCartCurrent($params)
@@ -139,6 +143,10 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query = $this->filterOrderValid($query);
}

if (isset($params['isWaitingDelivery'])) {
$query = $this->filterOrderWaitingDelivery($query);
}

if (isset($params['orderStatus'])) {
$query->leftJoin('e.orderStatus', 'os');
$query->andWhere('os.alias LIKE :alias');

+ 9
- 2
ShopBundle/Resources/translations/lcshop.fr.yaml 查看文件

@@ -52,6 +52,7 @@ group:
conditions: Conditions d'applications
actions: Actions
OrderShop:
redelivery: Relivraison
resume: Résumé de commande
addProduct: Ajout de produit à la commande
orderPayment: Ajouter un règlement
@@ -375,6 +376,10 @@ field:
typeOptions:
individual: Particulier
legal-person: Professionnel
OrderProductRedelivery:
quantityOrder: Quantité commandé
quantityProduct: Quantité (en rapport à l'unité)
unit: Unité
OrderShop:
save: Sauvegarder
reference: Référence
@@ -390,8 +395,10 @@ field:
quantityOrder: Quantité commandé
quantityProduct: Quantité (en rapport à l'unité)
unit: Unité
redeliverySupplier: Erreur producteur
redeliverySupplierOrder: A recommander au producteur
redeliverySupplierShort: Erreur producteur
redeliverySupplier: Erreur producteur (Aura un prix à 0€ dans le prohain bon de commande producteur - vous devez cocher à recommander)
redeliverySupplierOrderShort: À recommander au producteur
redeliverySupplierOrder: À recommander au producteur (Sera affiché dans le prohain bon de commande producteur)
deliveryType: Type de livraison
deliveryTypeOptions:
point-sale: En ambassade

+ 2
- 2
ShopBundle/Resources/views/backend/order/macros.html.twig 查看文件

@@ -301,11 +301,11 @@
{% block label %}{{ "field.default.deliveryAvailabilty"|trans({}, 'lcshop') }}{% endblock %}
{% block value %}
<div v-if="order.deliveryType == 'home'">
<div v-html="order.deliveryAvailabilityZone">
<div v-html="order.deliveryAvailabilityZone != null ? order.deliveryAvailabilityZone : order.deliveryDate">
</div>
</div>
<div v-else-if="order.deliveryType == 'point-sale'">
<div v-html="order.deliveryAvailabilityPointSale">
<div v-html="order.deliveryAvailabilityPointSale != null ? order.deliveryAvailabilityPointSale : order.deliveryDate">
</div>
</div>
<div v-else>

+ 51
- 43
ShopBundle/Services/MailUtils.php 查看文件

@@ -1,6 +1,6 @@
<?php

namespace Lc\ShopBundle\Services ;
namespace Lc\ShopBundle\Services;

use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Model\Merchant;
@@ -10,61 +10,69 @@ use Twig\Environment;

class MailUtils
{
const SUBJECT = 'subject' ;
const SUBJECT_PREFIX = 'subject-prefix' ;
const TO_EMAIL = 'to-email' ;
const TO_NAME = 'to-name' ;
const FROM_EMAIL = 'from-email' ;
const FROM_NAME = 'from-name' ;
const REPLY_TO = 'reply-to' ;
const CONTENT_TEMPLATE = 'content-template' ;
const CONTENT_DATA = 'content-data' ;
const ATTACHMENT_DATA = 'attachment-data' ;
const ATTACHMENT_FILENAME = 'attachment-filename' ;
const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type' ;
protected $transport ;
protected $templating ;
protected $parameterBag ;
protected $merchantUtils ;
public function __construct(MailjetTransport $mailjetTransport, Environment $templating,ParameterBagInterface $parameterBag, MerchantUtilsInterface $merchantUtils)
const SUBJECT = 'subject';
const SUBJECT_PREFIX = 'subject-prefix';
const TO_EMAIL = 'to-email';
const TO_NAME = 'to-name';
const FROM_EMAIL = 'from-email';
const FROM_NAME = 'from-name';
const REPLY_TO = 'reply-to';
const CONTENT_TEMPLATE = 'content-template';
const CONTENT_DATA = 'content-data';
const ATTACHMENT_DATA = 'attachment-data';
const ATTACHMENT_FILENAME = 'attachment-filename';
const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type';
protected $transport;
protected $templating;
protected $parameterBag;
protected $merchantUtils;
public function __construct(MailjetTransport $mailjetTransport, Environment $templating, ParameterBagInterface $parameterBag, MerchantUtilsInterface $merchantUtils)
{
$this->transport = $mailjetTransport ;
$this->templating = $templating ;
$this->parameterBag = $parameterBag ;
$this->merchantUtils = $merchantUtils ;
$this->transport = $mailjetTransport;
$this->templating = $templating;
$this->parameterBag = $parameterBag;
$this->merchantUtils = $merchantUtils;
}

public function send($params = [])
{
$merchantCurrent = $this->merchantUtils->getMerchantCurrent() ;
$merchantCurrent = $this->merchantUtils->getMerchantCurrent();

$merchantConfigEmailFrom = $merchantCurrent->getMerchantConfig('email-from') ;
$emailFrom = isset($params[self::FROM_EMAIL]) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom ;
$merchantConfigEmailFrom = $merchantCurrent->getMerchantConfig('email-from');
$emailFrom = isset($params[self::FROM_EMAIL]) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;

$merchantConfigEmailFromName = $merchantCurrent->getMerchantConfig('email-from-name') ;
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName ;
$merchantConfigEmailFromName = $merchantCurrent->getMerchantConfig('email-from-name');
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName;

$merchantConfigEmailSubjectPrefix = $merchantCurrent->getMerchantConfig('email-subject-prefix') ;
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix ;
if($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
$emailSubjectPrefix .= ' ' ;
$merchantConfigEmailSubjectPrefix = $merchantCurrent->getMerchantConfig('email-subject-prefix');
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix;
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
$emailSubjectPrefix .= ' ';
}

$message = new \Swift_Message($emailSubjectPrefix.$params[self::SUBJECT]);
$message->addTo(
$message = new \Swift_Message($emailSubjectPrefix . $params[self::SUBJECT]);


if ($this->parameterBag->get('mailjet.dev.redirect.active')==1) {
$message->addTo($this->parameterBag->get('mailjet.dev.redirect.email'),
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null);
} else {
$message->addTo(
$params[self::TO_EMAIL],
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null)
->addFrom($emailFrom, $emailFromName)
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE].'-html.html.twig', $params[self::CONTENT_DATA]), 'text/html')
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE].'-text.html.twig', $params[self::CONTENT_DATA]));
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null);
}

$message->addFrom($emailFrom, $emailFromName)
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $params[self::CONTENT_DATA]), 'text/html')
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $params[self::CONTENT_DATA]));

if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) {
$message->addReplyTo($params[self::REPLY_TO]) ;
if (isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) {
$message->addReplyTo($params[self::REPLY_TO]);
}

if(isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) {
if (isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) {
$message->attach(\Swift_Attachment::newInstance(
$params[self::ATTACHMENT_DATA],
$params[self::ATTACHMENT_FILENAME],
@@ -72,6 +80,6 @@ class MailUtils
));
}

$this->transport->send($message) ;
$this->transport->send($message);
}
}

+ 14
- 0
ShopBundle/Services/Order/OrderUtilsCartTrait.php 查看文件

@@ -3,10 +3,24 @@
namespace Lc\ShopBundle\Services\Order;


use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Model\OrderStatus;

trait OrderUtilsCartTrait
{
public function getCartByUserOrCreateIt($user){
$newOrderShop= $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($newOrderShop === null) {
$newOrderShop = $this->createOrderShop(array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
));
}

return $newOrderShop;
}


public function getCartCurrent()
{
$paramsSearchOrderShop = [];

Loading…
取消
儲存