<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface DeliveryUtilsInterface | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Context ; | |||||
interface PriceUtilsInterface | |||||
{ | |||||
} |
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 |
*/ | */ | ||||
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; | |||||
} | |||||
} | } |
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()) { |
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\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 ; | |||||
} | |||||
} |
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; | ||||
} | } | ||||