<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface DeliveryUtilsInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context; | |||||
interface PointSaleUtilsInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface PriceUtilsInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context; | |||||
interface UserPointSaleInterface | |||||
{ | |||||
} |
use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | ||||
use Lc\ShopBundle\Context\MerchantInterface; | use Lc\ShopBundle\Context\MerchantInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | use Lc\ShopBundle\Context\MerchantUtilsInterface; | ||||
use Lc\ShopBundle\Context\OrderUtilsInterface; | |||||
use Lc\ShopBundle\Context\StatusInterface; | use Lc\ShopBundle\Context\StatusInterface; | ||||
use Lc\ShopBundle\Context\TreeInterface; | use Lc\ShopBundle\Context\TreeInterface; | ||||
use Lc\ShopBundle\Form\AbstractEditPositionType; | use Lc\ShopBundle\Form\AbstractEditPositionType; | ||||
protected $utils; | protected $utils; | ||||
protected $merchantUtils ; | protected $merchantUtils ; | ||||
protected $mailjetTransport ; | protected $mailjetTransport ; | ||||
protected $orderUtils ; | |||||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, | public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, | ||||
MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport) | |||||
MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport, OrderUtilsInterface $orderUtils) | |||||
{ | { | ||||
$this->security = $security; | $this->security = $security; | ||||
$this->userManager = $userManager; | $this->userManager = $userManager; | ||||
$this->utils = $utils; | $this->utils = $utils; | ||||
$this->merchantUtils = $merchantUtils ; | $this->merchantUtils = $merchantUtils ; | ||||
$this->mailjetTransport = $mailjetTransport ; | $this->mailjetTransport = $mailjetTransport ; | ||||
$this->orderUtils = $orderUtils ; | |||||
} | } | ||||
/** | /** |
namespace Lc\ShopBundle\Controller ; | namespace Lc\ShopBundle\Controller ; | ||||
use Lc\ShopBundle\Services\Cities; | |||||
use Lc\ShopBundle\Services\CityUtils; | |||||
use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
use Symfony\Component\HttpFoundation\JsonResponse; | use Symfony\Component\HttpFoundation\JsonResponse; | ||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
{ | { | ||||
protected $cities ; | protected $cities ; | ||||
public function __construct(Cities $cities) | |||||
public function __construct(CityUtils $cities) | |||||
{ | { | ||||
$this->cities = $cities ; | $this->cities = $cities ; | ||||
} | } |
foreach($data as $orderProduct) { | foreach($data as $orderProduct) { | ||||
if($orderProduct instanceof OrderProductInterface) { | if($orderProduct instanceof OrderProductInterface) { | ||||
$this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; | $this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; | ||||
if($orderProduct->getQuantityorder() > 0) { | |||||
if($orderProduct->getQuantityOrder() > 0) { | |||||
$this->orderProducts[] = $orderProduct ; | $this->orderProducts[] = $orderProduct ; | ||||
} | } | ||||
} | } |
return $entity; | return $entity; | ||||
} | } | ||||
private function setSortableProperty($entity, $entityRepo){ | |||||
private function setSortableProperty($entity, $entityRepo) | |||||
{ | |||||
if ($entity instanceof TreeInterface) { | if ($entity instanceof TreeInterface) { | ||||
if ($entity->getParent()) { | if ($entity->getParent()) { | ||||
$total = $entityRepo->count(array('status' => 1, 'parent' => $entity->getParent()->getId())); | $total = $entityRepo->count(array('status' => 1, 'parent' => $entity->getParent()->getId())); | ||||
$entity->setPosition($entity->getParent()->getId() . '_' . $total); | |||||
} else { | |||||
$entity->setPosition((float) $entity->getParent()->getId() . '.' . str_pad($total, 2, '0', STR_PAD_LEFT)); | |||||
} | |||||
else { | |||||
if ($entity instanceof FilterMerchantInterface) { | if ($entity instanceof FilterMerchantInterface) { | ||||
$total = $entityRepo->count(array('status' => 1, 'parent' => null, 'merchant' => $this->merchantUtils->getMerchantCurrent())); | $total = $entityRepo->count(array('status' => 1, 'parent' => null, 'merchant' => $this->merchantUtils->getMerchantCurrent())); | ||||
}else{ | }else{ | ||||
} | } | ||||
$entity->setPosition($total); | $entity->setPosition($total); | ||||
} | } | ||||
} else { | |||||
} | |||||
else { | |||||
if ($entity instanceof FilterMerchantInterface) { | if ($entity instanceof FilterMerchantInterface) { | ||||
$total = $entityRepo->count(array('status' => 1, 'merchant' => $this->merchantUtils->getMerchantCurrent())); | $total = $entityRepo->count(array('status' => 1, 'merchant' => $this->merchantUtils->getMerchantCurrent())); | ||||
}else{ | |||||
} | |||||
else { | |||||
$total = $entityRepo->count(array('status' => 1)); | $total = $entityRepo->count(array('status' => 1)); | ||||
} | } | ||||
$entity->setPosition($total); | $entity->setPosition($total); | ||||
return $entity; | return $entity; | ||||
} | } | ||||
private function setMerchantProperty($entity){ | |||||
private function setMerchantProperty($entity) | |||||
{ | |||||
$entity->setMerchant($this->merchantUtils->getMerchantCurrent()); | $entity->setMerchant($this->merchantUtils->getMerchantCurrent()); | ||||
} | } | ||||
private function setMultipleMerchantProperty($entity){ | |||||
private function setMultipleMerchantProperty($entity) | |||||
{ | |||||
if ($entity->getMerchants()->isEmpty()) { | if ($entity->getMerchants()->isEmpty()) { | ||||
$entity->addMerchant($this->merchantUtils->getMerchantCurrent()); | $entity->addMerchant($this->merchantUtils->getMerchantCurrent()); | ||||
} | } |
public function __toString() | public function __toString() | ||||
{ | { | ||||
return $this->getTitle() ; | |||||
return $this->getTitle().' - '.$this->getZip().' '.$this->getCity() ; | |||||
} | } | ||||
public function getUser(): ?User | public function getUser(): ?User |
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
*/ | */ | ||||
abstract class OrderShop implements FilterMerchantInterface | |||||
abstract class OrderShop extends AbstractEntity implements FilterMerchantInterface | |||||
{ | { | ||||
/** | /** | ||||
*/ | */ | ||||
protected $documentDeliveryNote; | protected $documentDeliveryNote; | ||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $infosDelivery; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->orderStatusHistories = new ArrayCollection(); | $this->orderStatusHistories = new ArrayCollection(); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getInfosDelivery(): ?string | |||||
{ | |||||
return $this->infosDelivery; | |||||
} | |||||
public function setInfosDelivery(?string $infosDelivery): self | |||||
{ | |||||
$this->infosDelivery = $infosDelivery; | |||||
return $this; | |||||
} | |||||
} | } |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\User; | |||||
use App\Entity\UserPointSale; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
*/ | */ | ||||
protected $address; | protected $address; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="pointSale", orphanRemoval=true) | |||||
*/ | |||||
protected $userPointSales; | |||||
public function labelAdminChoice(){ | |||||
return $this->getTitle(); | |||||
} | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->merchants = new ArrayCollection(); | $this->merchants = new ArrayCollection(); | ||||
$this->pointSaleDayInfos = new ArrayCollection(); | $this->pointSaleDayInfos = new ArrayCollection(); | ||||
$this->userPointSales = new ArrayCollection(); | |||||
} | } | ||||
public function __toString() | public function __toString() | ||||
return $this->getTitle() ; | return $this->getTitle() ; | ||||
} | } | ||||
public function labelAdminChoice() | |||||
{ | |||||
return $this->getTitle(); | |||||
} | |||||
/** | /** | ||||
* @return Collection|Merchant[] | * @return Collection|Merchant[] | ||||
*/ | */ | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|UserPointSale[] | |||||
*/ | |||||
public function getUserPointSales(): Collection | |||||
{ | |||||
return $this->userPointSales; | |||||
} | |||||
public function addUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if (!$this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales[] = $userPointSale; | |||||
$userPointSale->setPointSale($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if ($this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales->removeElement($userPointSale); | |||||
// set the owning side to null (unless already changed) | |||||
if ($userPointSale->getPointSale() === $this) { | |||||
$userPointSale->setPointSale(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
return $quantity.$unit->getWordingShort() ; | return $quantity.$unit->getWordingShort() ; | ||||
} | } | ||||
public function getQuantityTitle($productFamily) | |||||
{ | |||||
$title = $this->getQuantityLabelInherited() ; | |||||
if($productFamily->hasProductsWithVariousWeight()) { | |||||
$title .= ', '.$this->getTitleInherited() ; | |||||
} | |||||
return $title ; | |||||
} | |||||
public function getAvailableQuantityInherited() | public function getAvailableQuantityInherited() | ||||
{ | { | ||||
if($this->getProductFamily()->getBehaviorCountStock()) { | if($this->getProductFamily()->getBehaviorCountStock()) { |
namespace Lc\ShopBundle\Model; | namespace Lc\ShopBundle\Model; | ||||
use App\Entity\Newsletter; | use App\Entity\Newsletter; | ||||
use App\Entity\UserPointSale; | |||||
use Doctrine\Common\Collections\ArrayCollection; | use Doctrine\Common\Collections\ArrayCollection; | ||||
use Doctrine\Common\Collections\Collection; | use Doctrine\Common\Collections\Collection; | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
*/ | */ | ||||
protected $favoriteProductFamilies; | protected $favoriteProductFamilies; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\UserPointSaleInterface", mappedBy="user", orphanRemoval=true) | |||||
*/ | |||||
protected $userPointSales; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->groupUsers = new ArrayCollection(); | $this->groupUsers = new ArrayCollection(); | ||||
$this->newsletters = new ArrayCollection(); | $this->newsletters = new ArrayCollection(); | ||||
$this->favoriteProductFamilies = new ArrayCollection(); | $this->favoriteProductFamilies = new ArrayCollection(); | ||||
$this->userPointSales = new ArrayCollection(); | |||||
} | } | ||||
public function setEmail($email) | public function setEmail($email) | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|UserPointSale[] | |||||
*/ | |||||
public function getUserPointSales(): Collection | |||||
{ | |||||
return $this->userPointSales; | |||||
} | |||||
public function addUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if (!$this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales[] = $userPointSale; | |||||
$userPointSale->setUser($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeUserPointSale(UserPointSale $userPointSale): self | |||||
{ | |||||
if ($this->userPointSales->contains($userPointSale)) { | |||||
$this->userPointSales->removeElement($userPointSale); | |||||
// set the owning side to null (unless already changed) | |||||
if ($userPointSale->getUser() === $this) { | |||||
$userPointSale->setUser(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Model; | |||||
use Doctrine\ORM\Mapping as ORM; | |||||
/** | |||||
* @ORM\MappedSuperclass | |||||
*/ | |||||
abstract class UserPointSale | |||||
{ | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="userPointSales") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $user; | |||||
/** | |||||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\PointSaleInterface", inversedBy="userPointSales") | |||||
* @ORM\JoinColumn(nullable=false) | |||||
*/ | |||||
protected $pointSale; | |||||
/** | |||||
* @ORM\Column(type="text", nullable=true) | |||||
*/ | |||||
protected $comment; | |||||
public function getUser(): ?User | |||||
{ | |||||
return $this->user; | |||||
} | |||||
public function setUser(?User $user): self | |||||
{ | |||||
$this->user = $user; | |||||
return $this; | |||||
} | |||||
public function getPointSale(): ?PointSale | |||||
{ | |||||
return $this->pointSale; | |||||
} | |||||
public function setPointSale(?PointSale $pointSale): self | |||||
{ | |||||
$this->pointSale = $pointSale; | |||||
return $this; | |||||
} | |||||
public function getComment(): ?string | |||||
{ | |||||
return $this->comment; | |||||
} | |||||
public function setComment(?string $comment): self | |||||
{ | |||||
$this->comment = $comment; | |||||
return $this; | |||||
} | |||||
} |
return OrderShopInterface::class; | return OrderShopInterface::class; | ||||
} | } | ||||
public function findCurrent($params) | |||||
{ | |||||
$query = $this->createQueryBuilder('e') ; | |||||
if(isset($params['user'])) { | |||||
$query->andWhere('e.user = :user')->setParameter('user', $params['user']) ; | |||||
} | |||||
if(isset($params['visitor'])) { | |||||
$query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ; | |||||
} | |||||
$query->leftJoin('e.orderStatusHistories', 'orderStatusHistories') | |||||
->andWhere('SIZE(e.orderStatusHistories) = 0') ; | |||||
return $query->getQuery()->getOneOrNullResult() ; | |||||
} | |||||
public function findAllByDateStartEnd($dateStart, $dateEnd) | |||||
{ | |||||
$query = $this->findByMerchantQuery() | |||||
->andWhere('e.createdAt >= :dateStart') | |||||
->setParameter('dateStart', $dateStart) | |||||
->andWhere('e.createdAt <= :dateEnd') | |||||
->setParameter('dateEnd', $dateEnd) | |||||
; | |||||
$query->leftJoin('e.orderStatusHistories', 'orderStatusHistories') | |||||
->andWhere('SIZE(e.orderStatusHistories) > 0') ; | |||||
return $query->getQuery()->getResult() ; | |||||
} | |||||
} | } |
return PointSaleInterface::class; | return PointSaleInterface::class; | ||||
} | } | ||||
public function findAllPublics() | |||||
{ | |||||
return $this->createQueryBuilder('e') | |||||
->where(':currentMerchant MEMBER OF e.merchants') | |||||
->andWhere('e.isPublic = 1') | |||||
->andWhere('e.status = 1') | |||||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()) | |||||
->getQuery() | |||||
->getResult() ; | |||||
} | |||||
public function findAllByMerchant() | public function findAllByMerchant() | ||||
{ | { | ||||
return $this->createQueryBuilder('e') | return $this->createQueryBuilder('e') |
<?php | |||||
namespace Lc\ShopBundle\Repository; | |||||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | |||||
use Lc\ShopBundle\Context\PointSaleInterface; | |||||
/** | |||||
* @method UserPointSaleInterface|null find($id, $lockMode = null, $lockVersion = null) | |||||
* @method UserPointSaleInterface|null findOneBy(array $criteria, array $orderBy = null) | |||||
* @method UserPointSaleInterface[] findAll() | |||||
* @method UserPointSaleInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||||
*/ | |||||
class UserPointSaleRepository extends BaseRepository implements DefaultRepositoryInterface | |||||
{ | |||||
public function getInterfaceClass() | |||||
{ | |||||
return UserPointSaleInterface::class; | |||||
} | |||||
} |
{% endblock %} | {% endblock %} | ||||
{% block head_custom_stylesheets %} | {% block head_custom_stylesheets %} | ||||
<link rel="stylesheet" href="{{ asset('bundles/lcshop/css/backend/custom.css') }}"> | <link rel="stylesheet" href="{{ asset('bundles/lcshop/css/backend/custom.css') }}"> | ||||
{% for asset_css in easyadmin_config('design.assets.css') %} | |||||
<link rel="stylesheet" href="{{ asset(asset_css) }}"> | |||||
{% endfor %} | |||||
{% endblock head_custom_stylesheets %} | {% endblock head_custom_stylesheets %} | ||||
{# | {# | ||||
{% set favicon = easyadmin_config('design.assets.favicon') %} | {% set favicon = easyadmin_config('design.assets.favicon') %} | ||||
<link rel="icon" type="{{ favicon.mime_type }}" href="{{ asset(favicon.path) }}"/> | <link rel="icon" type="{{ favicon.mime_type }}" href="{{ asset(favicon.path) }}"/> | ||||
{% endblock %} | {% endblock %} | ||||
</head> | </head> | ||||
{% block body %} | {% block body %} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Lc\ShopBundle\Context\AddressInterface; | |||||
class AddressUtils | |||||
{ | |||||
public function getSummaryShort(AddressInterface $address) | |||||
{ | |||||
return $address->getAddress().' - '.$address->getZip().' '.$address->getCity() ; | |||||
} | |||||
public function getSummary(AddressInterface $address) | |||||
{ | |||||
$html = '' ; | |||||
if($address->getTitle()) { | |||||
$html .= $address->getTitle().'<br />' ; | |||||
} | |||||
if($address->getLastname() || $address->getFirstname()) { | |||||
$html .= $address->getLastname().' '.$address->getFirstname().'<br />' ; | |||||
} | |||||
if($address->getAddress()) { | |||||
$html .= $address->getAddress().'<br />' ; | |||||
} | |||||
if($address->getZip() || $address->getCity()) { | |||||
$html .= $address->getZip().' '.$address->getCity().'<br />' ; | |||||
} | |||||
if($address->getPhone()) { | |||||
$html .= 'Tél. '.$address->getPhone() ; | |||||
} | |||||
return $html ; | |||||
} | |||||
} |
namespace Lc\ShopBundle\Services ; | namespace Lc\ShopBundle\Services ; | ||||
class Cities | |||||
class CityUtils | |||||
{ | { | ||||
function callApi($method, $url, $data = false) | function callApi($method, $url, $data = false) | ||||
return $result; | return $result; | ||||
} | } | ||||
public function getZipByCity($city) | |||||
{ | |||||
$zip = null ; | |||||
$returnCitiesSearchZip = json_decode($this->callApi('get', 'communes', ['nom' => $city, 'fields' => 'nom,codesPostaux'])) ; | |||||
if($returnCitiesSearchZip) { | |||||
foreach($returnCitiesSearchZip as $citySearchZip) { | |||||
if(strtolower(trim($city)) == strtolower(trim($citySearchZip->nom))) { | |||||
$zip = $citySearchZip->codesPostaux[0] ; | |||||
} | |||||
} | |||||
} | |||||
return $zip ; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Services; | |||||
use CKSource\Bundle\CKFinderBundle\Authentication\Authentication as AuthenticationBase; | |||||
class CustomCKFinderAuth extends AuthenticationBase | |||||
{ | |||||
public function authenticate() | |||||
{ | |||||
return true; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
class DateUtils | |||||
{ | |||||
public function date($format, $timestamp) | |||||
{ | |||||
setlocale(LC_TIME, 'fr_FR.UTF8', 'fr.UTF8', 'fr_FR.UTF-8', 'fr.UTF-8'); | |||||
return strftime($format, $timestamp) ; | |||||
} | |||||
public function getNextDay($day) | |||||
{ | |||||
return new \DateTime('next '.$day) ; | |||||
} | |||||
public function getNextDayByNumber($number) | |||||
{ | |||||
return $this->getNextDay($this->getDayByNumber($number, 'en')) ; | |||||
} | |||||
public function getDayByNumber($number, $lang = 'fr') | |||||
{ | |||||
if($lang == 'fr') { | |||||
$daysArray = [ | |||||
1 => 'Lundi', | |||||
2 => 'Mardi', | |||||
3 => 'Mercredi', | |||||
4 => 'Jeudi', | |||||
5 => 'Vendredi', | |||||
6 => 'Samedi', | |||||
7 => 'Dimanche' | |||||
] ; | |||||
} | |||||
else { | |||||
$daysArray = [ | |||||
1 => 'Monday', | |||||
2 => 'Tuesday', | |||||
3 => 'Wednesday', | |||||
4 => 'Thursday', | |||||
5 => 'Friday', | |||||
6 => 'Saturday', | |||||
7 => 'Sunday', | |||||
] ; | |||||
} | |||||
if(isset($daysArray[$number])) { | |||||
return $daysArray[$number] ; | |||||
} | |||||
return '' ; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Symfony\Component\Security\Core\Security; | |||||
class DeliveryUtils | |||||
{ | |||||
protected $em ; | |||||
protected $security ; | |||||
public function __construct(EntityManagerInterface $em, Security $security) | |||||
{ | |||||
$this->em = $em ; | |||||
$this->security = $security ; | |||||
} | |||||
} |
protected $security; | protected $security; | ||||
protected $userUtils; | protected $userUtils; | ||||
protected $merchantUtils; | protected $merchantUtils; | ||||
private $orderShopRepo; | |||||
protected $orderShopRepo; | |||||
protected $priceUtils ; | protected $priceUtils ; | ||||
protected $productFamilyUtils ; | protected $productFamilyUtils ; | ||||
$this->security = $security; | $this->security = $security; | ||||
$this->userUtils = $userUtils; | $this->userUtils = $userUtils; | ||||
$this->merchantUtils = $merchantUtils; | $this->merchantUtils = $merchantUtils; | ||||
$this->orderShopRepo = $this->em->getRepository(OrderShop::class); | |||||
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName()); | |||||
$this->priceUtils = $priceUtils ; | $this->priceUtils = $priceUtils ; | ||||
$this->productFamilyUtils = $productFamilyUtils ; | $this->productFamilyUtils = $productFamilyUtils ; | ||||
} | } | ||||
$paramsSearchOrderShop['visitor'] = $visitor; | $paramsSearchOrderShop['visitor'] = $visitor; | ||||
} | } | ||||
$orderShop = $this->orderShopRepo->findOneBy($paramsSearchOrderShop); | |||||
$orderShop = $this->orderShopRepo->findCurrent($paramsSearchOrderShop); | |||||
if (!$orderShop) { | if (!$orderShop) { | ||||
$orderShop = $this->createOrderShop([ | $orderShop = $this->createOrderShop([ |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\PointSaleInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | |||||
use Lc\ShopBundle\Context\UserPointSaleInterface; | |||||
class PointSaleUtils | |||||
{ | |||||
protected $em ; | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | |||||
$this->em = $em ; | |||||
} | |||||
public function isUserLinkedToPointSale(UserInterface $user, PointSaleInterface $pointSale) | |||||
{ | |||||
foreach($user->getUserPointSales() as $userPointSale) { | |||||
if($userPointSale->getPointSale()->getId() == $pointSale->getId()) { | |||||
return true ; | |||||
} | |||||
} | |||||
return false ; | |||||
} | |||||
public function linkUserToPointSale(UserInterface $user, PointSaleInterface $pointSale) | |||||
{ | |||||
if(!$this->isUserLinkedToPointSale($user, $pointSale)) { | |||||
$userPointSaleClass = $this->em->getClassMetadata(UserPointSaleInterface::class)->getName(); | |||||
$userPointSale = new $userPointSaleClass ; | |||||
$userPointSale->setUser($user) ; | |||||
$userPointSale->setPointSale($pointSale) ; | |||||
$this->em->persist($userPointSale); | |||||
$this->em->flush() ; | |||||
} | |||||
} | |||||
} |
namespace Lc\ShopBundle\Services ; | namespace Lc\ShopBundle\Services ; | ||||
use Doctrine\Common\Collections\Collection; | |||||
use Lc\ShopBundle\Context\OrderProductInterface; | use Lc\ShopBundle\Context\OrderProductInterface; | ||||
use Lc\ShopBundle\Context\OrderShopInterface; | use Lc\ShopBundle\Context\OrderShopInterface; | ||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | use Lc\ShopBundle\Context\ProductFamilyInterface; | ||||
return $total ; | return $total ; | ||||
} | } | ||||
if($entity instanceof OrderShopInterface) { | if($entity instanceof OrderShopInterface) { | ||||
return $this->getTotalWithTaxByOrderProducts($entity->getOrderProducts()) ; | |||||
return $this->getTotalOrderProducts($entity->getOrderProducts(), true) ; | |||||
} | } | ||||
return null ; | return null ; | ||||
} | } | ||||
} | } | ||||
if($entity instanceof OrderShopInterface) { | if($entity instanceof OrderShopInterface) { | ||||
return $this->getTotalWithTaxAndReductionByOrderProducts($entity->getOrderProducts()) ; | |||||
return $this->getTotalOrderProductsWithTaxAndReduction($entity->getOrderProducts(), true, true) ; | |||||
} | } | ||||
} | } | ||||
public function getTotalWithTaxByOrderProducts($orderProducts) | |||||
public function getTotalOrderProducts($entity) | |||||
{ | { | ||||
$totalWithTax = 0; | |||||
foreach ($orderProducts as $orderProduct) { | |||||
$totalWithTax += $this->getTotalWithTax($orderProduct); | |||||
} | |||||
return $this->getSumOrderProductsDispatch($entity) ; | |||||
} | |||||
return $totalWithTax; | |||||
public function getTotalOrderProductsWithTax($entity) | |||||
{ | |||||
return $this->getSumOrderProductsDispatch($entity, true) ; | |||||
} | } | ||||
public function getTotalWithTaxAndReductionByOrderProducts($orderProducts) | |||||
public function getTotalOrderProductsWithTaxAndReduction($entity) | |||||
{ | { | ||||
$totalWithTax = 0; | |||||
return $this->getSumOrderProductsDispatch($entity, true, true) ; | |||||
} | |||||
foreach ($orderProducts as $orderProduct) { | |||||
$totalWithTax += $this->getTotalWithTaxAndReduction($orderProduct); | |||||
public function getSumOrderProductsDispatch($entity, $withTax = false, $withReduction = false) | |||||
{ | |||||
if($entity instanceof OrderShopInterface) { | |||||
return $this->getSumOrderProducts($entity->getOrderProducts(), $withTax, $withReduction) ; | |||||
} | |||||
if($entity instanceof Collection || is_array($entity)) { | |||||
return $this->getSumOrderProducts($entity, $withTax, $withReduction) ; | |||||
} | } | ||||
} | |||||
return $totalWithTax; | |||||
public function getSumOrderProducts($orderProducts, $withTax = false, $withReduction = false) | |||||
{ | |||||
$total = 0 ; | |||||
foreach($orderProducts as $orderProduct) { | |||||
if($withTax && $withReduction) { | |||||
$total += $this->getTotalWithTaxAndReduction($orderProduct) ; | |||||
} | |||||
elseif($withTax) { | |||||
$total += $this->getTotalWithTax($orderProduct) ; | |||||
} | |||||
else { | |||||
$total += $this->getTotal($orderProduct) ; | |||||
} | |||||
} | |||||
return $total ; | |||||
} | } | ||||
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null): ?float | public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null): ?float | ||||
$price, | $price, | ||||
$reductionCatalogValue | $reductionCatalogValue | ||||
), | ), | ||||
$this->getTaxRateInherited()->getValue() | |||||
$entity->getTaxRateInherited()->getValue() | |||||
); | ); | ||||
} | } | ||||
elseif($reductionCatalogBehaviorTaxRate == 'tax-included') { | elseif($reductionCatalogBehaviorTaxRate == 'tax-included') { |
$this->parameterBag = $parameterBag ; | $this->parameterBag = $parameterBag ; | ||||
} | } | ||||
// @todo : À supprimer et passer dans DateUtils (gérer du coup le cas du modèle DeliverySlot qui dépend de cette fonction) | |||||
public static function getDayByNumber($number, $lang = 'fr') | public static function getDayByNumber($number, $lang = 'fr') | ||||
{ | { | ||||
if($lang == 'fr') { | if($lang == 'fr') { | ||||
return '' ; | return '' ; | ||||
} | } | ||||
public function getElementByDevAlias($devAlias, $class = PageInterface::class) | public function getElementByDevAlias($devAlias, $class = PageInterface::class) | ||||
{ | { | ||||
$class = $this->em->getClassMetadata($class)->getName(); | $class = $this->em->getClassMetadata($class)->getName(); |
public function getProductCategories() | public function getProductCategories() | ||||
{ | { | ||||
$categories = $this->productCategoryRepository->findAllParents($this->merchantUtils->getMerchantCurrent()); | |||||
$categories = $this->productCategoryRepository->findAllParents(false); | |||||
return $categories; | return $categories; | ||||
} | } | ||||