소스 검색

Backend status / reductionCart / reductionCredit

feature/export_comptable
Fab 4 년 전
부모
커밋
39cee85e11
11개의 변경된 파일186개의 추가작업 그리고 41개의 파일을 삭제
  1. +1
    -1
      ShopBundle/Form/Backend/Order/OrderReductionCreditType.php
  2. +1
    -1
      ShopBundle/Form/Backend/ReductionCart/UncombinableTypesType.php
  3. +16
    -0
      ShopBundle/Model/Address.php
  4. +36
    -0
      ShopBundle/Model/Merchant.php
  5. +5
    -5
      ShopBundle/Model/OrderShop.php
  6. +21
    -1
      ShopBundle/Model/Page.php
  7. +9
    -3
      ShopBundle/Repository/OrderShopRepository.php
  8. +2
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  9. +84
    -23
      ShopBundle/Services/OrderUtils.php
  10. +4
    -4
      ShopBundle/Services/PriceUtils.php
  11. +7
    -2
      ShopBundle/Services/UserUtils.php

+ 1
- 1
ShopBundle/Form/Backend/Order/OrderReductionCreditType.php 파일 보기

@@ -42,7 +42,7 @@ class OrderReductionCreditType extends AbstractType
$builder
->add('reductionCredit', EntityType::class, array(
'class' => $reductionCreditClass->getName(),
'choices' => $this->orderUtils->getReductionCreditByUser($entity->getUser()),
'choices' => $reductionCreditRepo->getReductionCreditByUser($entity->getUser()),
//'choices' => $this->orderUtils->getReductionCreditsAvailable($entity),

'required' => true,

+ 1
- 1
ShopBundle/Form/Backend/ReductionCart/UncombinableTypesType.php 파일 보기

@@ -29,7 +29,7 @@ class UncombinableTypesType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$reductionCartRepo = $this->em->getRepository(ReductionCartInterface::class);
$types = array();
foreach ($reductionCartRepo->getValuesOfFieldType() as $type){
$types['field.ReductionCart.typeOptions.'.$type['type']] = $type['type'];
}

+ 16
- 0
ShopBundle/Model/Address.php 파일 보기

@@ -95,6 +95,10 @@ abstract class Address extends AbstractEntity
*/
protected $merchant;

/**
* @ORM\Column(type="text", nullable=true)
*/
protected $deliveryInfos;

public function __toString()
{
@@ -347,4 +351,16 @@ abstract class Address extends AbstractEntity

return $this;
}

public function getDeliveryInfos(): ?string
{
return $this->deliveryInfos;
}

public function setDeliveryInfos(?string $deliveryInfos): self
{
$this->deliveryInfos = $deliveryInfos;

return $this;
}
}

+ 36
- 0
ShopBundle/Model/Merchant.php 파일 보기

@@ -56,6 +56,11 @@ abstract class Merchant extends AbstractDocumentEntity
*/
protected $news;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\PageInterface", mappedBy="merchant", orphanRemoval=true)
*/
protected $pages;

/**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\NewsletterInterface", mappedBy="merchant")
*/
@@ -279,6 +284,37 @@ abstract class Merchant extends AbstractDocumentEntity
return $this;
}

/**
* @return Collection|Page[]
*/
public function getPages(): Collection
{
return $this->pages;
}

public function addPage(Page $page): self
{
if (!$this->pages->contains($page)) {
$this->pages[] = $page;
$page->setMerchant($this);
}

return $this;
}

public function removePage(Page $page): self
{
if ($this->pages->contains($page)) {
$this->pages->removeElement($page);
// set the owning side to null (unless already changed)
if ($page->getMerchant() === $this) {
$page->setMerchant(null);
}
}

return $this;
}

/**
* @return Collection|Newsletter[]
*/

+ 5
- 5
ShopBundle/Model/OrderShop.php 파일 보기

@@ -83,7 +83,7 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $infosDelivery;
protected $deliveryInfos;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\OrderStatusInterface")
@@ -347,14 +347,14 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa
return $this;
}

public function getInfosDelivery(): ?string
public function getDeliveryInfos(): ?string
{
return $this->infosDelivery;
return $this->deliveryInfos;
}

public function setInfosDelivery(?string $infosDelivery): self
public function setDeliveryInfos(?string $deliveryInfos): self
{
$this->infosDelivery = $infosDelivery;
$this->deliveryInfos = $deliveryInfos;

return $this;
}

+ 21
- 1
ShopBundle/Model/Page.php 파일 보기

@@ -2,18 +2,26 @@

namespace Lc\ShopBundle\Model;

use App\Entity\Hub;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\FilterMerchantInterface;

/**
* @ORM\MappedSuperclass()
*/
abstract class Page extends AbstractDocumentEntity
abstract class Page extends AbstractDocumentEntity implements FilterMerchantInterface
{
/**
* @ORM\Column(type="text", nullable=true)
*/
protected $content;

/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface", inversedBy="pages")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;

public function __toString()
{
return $this->getTitle() ;
@@ -30,4 +38,16 @@ abstract class Page extends AbstractDocumentEntity

return $this;
}

public function getMerchant(): ?Hub
{
return $this->merchant;
}

public function setMerchant(?Hub $merchant): self
{
$this->merchant = $merchant;

return $this;
}
}

+ 9
- 3
ShopBundle/Repository/OrderShopRepository.php 파일 보기

@@ -20,7 +20,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt

public function findCartCurrent($params)
{
$query = $this->createQueryBuilder('e') ;
$query = $this->findByMerchantQuery() ;

if(isset($params['user'])) {
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
@@ -33,7 +33,13 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->leftJoin('e.orderStatusHistories', 'orderStatusHistories')
->andWhere('SIZE(e.orderStatusHistories) = 0') ;

return $query->getQuery()->getOneOrNullResult() ;
$results = $query->getQuery()->getResult() ;

if($results) {
return $results[0] ;
}
return null ;
}

public function findAllBy($params = [])
@@ -56,7 +62,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
}

$query->orderBy('e.createdAt', 'DESC') ;
$query->orderBy('e.id', 'DESC') ;

return $query->getQuery()->getResult() ;
}

+ 2
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml 파일 보기

@@ -122,7 +122,7 @@ field:
warningMessageType: Type de message d'avertissement
warningMessageTypeOptions:
warning: Attention (jaune)
info: Information (bleu)
info: Information (gris)
error: Erreur (rouge)
success: Succès (vert)
warningMessage: Contenu du message d'avertissement
@@ -136,6 +136,7 @@ field:
devAlias: Alias
merchantConfigs: Configuration
taxRate: Règle de taxe
deliveryTaxRate: Règle de taxe (livraison)
value: Valeur
behaviorAddToCart: Ajout au panier
taxIncluded: TVA incluse

+ 84
- 23
ShopBundle/Services/OrderUtils.php 파일 보기

@@ -7,6 +7,7 @@ use App\Entity\OrderShop;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\OrderReductionCartInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
use Lc\ShopBundle\Context\OrderStatusInterface;
@@ -14,6 +15,7 @@ use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Context\ReductionCreditInterface;
use Lc\ShopBundle\Context\UserInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Security;

class OrderUtils
@@ -38,6 +40,7 @@ class OrderUtils
$this->productFamilyUtils = $productFamilyUtils;
}


public function getCartCurrent()
{
$paramsSearchOrderShop = [];
@@ -45,22 +48,41 @@ class OrderUtils
$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = null;
$orderShopUser = null;
$orderShopVisitor = null;

if ($user) {
$paramsSearchOrderShop['user'] = $user;
$orderShopUser = $this->orderShopRepo->findCartCurrent([
'user' => $user
]);
}

if ($visitor) {
$paramsSearchOrderShop['visitor'] = $visitor;
$orderShopVisitor = $this->orderShopRepo->findCartCurrent([
'visitor' => $visitor
]);
}

$orderShop = $this->orderShopRepo->findCartCurrent($paramsSearchOrderShop);
if ($orderShopUser || $orderShopVisitor) {
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor && $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
}

if (!$orderShop) {
$orderShop = $this->createOrderShop([
'user' => $user,
'visitor' => $visitor,
'merchant' => $this->merchantUtils->getMerchantCurrent()
]);
if (!$user && !$visitor) {
$this->session->getFlashBag()->add('error', 'Vous devez accepter les cookies ou vous connecter pour créer un panier.');
} else {
if (!$orderShop) {
$orderShop = $this->createOrderShop([
'user' => $user,
'visitor' => $visitor,
'merchant' => $this->merchantUtils->getMerchantCurrent()
]);
}
}

return $orderShop;
@@ -109,7 +131,7 @@ class OrderUtils
return $orderShop;
}

public function addOrderProduct($orderShop, $orderProductAdd)
public function addOrderProduct($orderShop, $orderProductAdd, $persist = true)
{
if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false;
@@ -134,12 +156,18 @@ class OrderUtils

foreach ($orderShop->getOrderProducts() as $orderProduct) {
if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
&& $this->priceUtils->getPrice($orderProduct) == $this->priceUtils->getPrice($orderProductAdd)
&& (string)$this->priceUtils->getPrice($orderProduct) == (string)$this->priceUtils->getPrice($orderProductAdd)
&& $this->compareOrderProductReductionCatalog($orderProduct->getOrderProductReductionCatalog(), $orderProductAdd->getOrderProductReductionCatalog())) {

$updated = true;
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());
$this->em->persist($orderProduct);

if ($persist) {
$this->em->persist($orderProduct);
}

$updated = true;

break;
}
}

@@ -148,23 +176,39 @@ class OrderUtils

if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);

if ($persist) {
if (isset($orderProductReductionCatalog)) {
$this->em->persist($orderProductReductionCatalog);
}
$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);

}
}

$this->em->persist($orderProductAdd);
$this->em->persist($orderShop);
if ($persist) {
$this->em->flush();
}
}

$this->em->flush();
}

}

public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
{

return $orderProductReductionCatalog1 && $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& $orderProductReductionCatalog1->getValue() == $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate();

/*return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
|| ($orderProductReductionCatalog1
&& $orderProductReductionCatalog2
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;*/
}

public function countQuantities($orderShop)
@@ -201,16 +245,18 @@ class OrderUtils

public function getOrderDatas($order = null)
{

$data = [];
if (!$order) {
$order = $this->getCartCurrent();
}

$data = [];
$data['order'] = $order;
$data['count'] = $this->countQuantities($order);
$data['total_with_tax'] = $this->priceUtils->getTotalWithTaxAndReduction($order);
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order);

if ($order) {
$data['count'] = $this->countQuantities($order);
$data['total_with_tax'] = $this->priceUtils->getTotalWithTaxAndReduction($order);
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order);
}
return $data;
}

@@ -273,7 +319,6 @@ class OrderUtils
$this->em->persist($orderStatusHistory);
}


public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
{
$orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
@@ -303,4 +348,20 @@ class OrderUtils

}
}*/
public function mergeOrderShops($orderShop1, $orderShop2)
{
if ($orderShop1 && $orderShop2) {

foreach ($orderShop2->getOrderProducts() as $orderProduct) {
$this->addOrderProduct($orderShop1, $orderProduct);
$this->em->remove($orderProduct);
}

$this->em->remove($orderShop2);
$this->em->persist($orderShop1);
$this->em->flush();

return $orderShop1;
}
}
}

+ 4
- 4
ShopBundle/Services/PriceUtils.php 파일 보기

@@ -210,14 +210,14 @@ class PriceUtils

if(isset($reductionCatalogValue) && isset($reductionCatalogUnit) && isset($reductionCatalogBehaviorTaxRate)) {
if ($reductionCatalogUnit == 'percent') {
return $this->applyReductionPercent(
$priceWithTax = $this->applyReductionPercent(
$priceWithTax,
$reductionCatalogValue
);
}
elseif ($reductionCatalogUnit == 'amount') {
if($reductionCatalogBehaviorTaxRate == 'tax-excluded') {
return $this->applyTax(
$priceWithTax = $this->applyTax(
$this->applyReductionAmount(
$price,
$reductionCatalogValue
@@ -226,7 +226,7 @@ class PriceUtils
);
}
elseif($reductionCatalogBehaviorTaxRate == 'tax-included') {
return $this->applyReductionAmount(
$priceWithTax = $this->applyReductionAmount(
$priceWithTax,
$reductionCatalogValue
);
@@ -234,7 +234,7 @@ class PriceUtils
}
}

return $priceWithTax ;
return $this->round($priceWithTax) ;
}

public function applyTax($price, $taxRateValue)

+ 7
- 2
ShopBundle/Services/UserUtils.php 파일 보기

@@ -2,6 +2,7 @@

namespace Lc\ShopBundle\Services ;

use ConnectHolland\CookieConsentBundle\Cookie\CookieChecker;
use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Symfony\Component\HttpFoundation\Cookie ;
@@ -17,9 +18,10 @@ class UserUtils
protected $requestStack ;
protected $visitorRepository ;
protected $merchantUtils ;
protected $cookieChecker ;

public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils,
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils)
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils, CookieChecker $cookieChecker)
{
$this->em = $em ;
$this->parameterBag = $parameterBag ;
@@ -27,6 +29,7 @@ class UserUtils
$this->requestStack = $requestStack ;
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
$this->cookieChecker = $cookieChecker ;
}

public function getCookieNameVisitor()
@@ -46,7 +49,9 @@ class UserUtils

public function setCookieVisitor($response, $cookie)
{
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), 0, '/', $this->utils->getCookieDomain()));
if($this->cookieChecker->isCategoryAllowedByUser('site')) {
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), 0, '/', $this->utils->getCookieDomain()));
}
}

public function getVisitor($cookie)

Loading…
취소
저장