@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Context ; | |||
interface DeliveryUtilsInterface | |||
{ | |||
} |
@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Context ; | |||
interface PriceUtilsInterface | |||
{ | |||
} |
@@ -2,7 +2,7 @@ | |||
namespace Lc\ShopBundle\Controller ; | |||
use Lc\ShopBundle\Services\Cities; | |||
use Lc\ShopBundle\Services\CityUtils; | |||
use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\HttpFoundation\JsonResponse; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
@@ -11,7 +11,7 @@ class CitiesController extends AbstractController | |||
{ | |||
protected $cities ; | |||
public function __construct(Cities $cities) | |||
public function __construct(CityUtils $cities) | |||
{ | |||
$this->cities = $cities ; | |||
} |
@@ -47,7 +47,7 @@ class CartController extends BaseController | |||
foreach($data as $orderProduct) { | |||
if($orderProduct instanceof OrderProductInterface) { | |||
$this->orderUtils->addOrderProduct($orderShop, $orderProduct) ; | |||
if($orderProduct->getQuantityorder() > 0) { | |||
if($orderProduct->getQuantityOrder() > 0) { | |||
$this->orderProducts[] = $orderProduct ; | |||
} | |||
} |
@@ -67,12 +67,14 @@ class EditEventSubscriber implements EventSubscriberInterface | |||
return $entity; | |||
} | |||
private function setSortableProperty($entity, $entityRepo){ | |||
private function setSortableProperty($entity, $entityRepo) | |||
{ | |||
if ($entity instanceof TreeInterface) { | |||
if ($entity->getParent()) { | |||
$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) { | |||
$total = $entityRepo->count(array('status' => 1, 'parent' => null, 'merchant' => $this->merchantUtils->getMerchantCurrent())); | |||
}else{ | |||
@@ -80,10 +82,12 @@ class EditEventSubscriber implements EventSubscriberInterface | |||
} | |||
$entity->setPosition($total); | |||
} | |||
} else { | |||
} | |||
else { | |||
if ($entity instanceof FilterMerchantInterface) { | |||
$total = $entityRepo->count(array('status' => 1, 'merchant' => $this->merchantUtils->getMerchantCurrent())); | |||
}else{ | |||
} | |||
else { | |||
$total = $entityRepo->count(array('status' => 1)); | |||
} | |||
$entity->setPosition($total); | |||
@@ -91,11 +95,13 @@ class EditEventSubscriber implements EventSubscriberInterface | |||
return $entity; | |||
} | |||
private function setMerchantProperty($entity){ | |||
private function setMerchantProperty($entity) | |||
{ | |||
$entity->setMerchant($this->merchantUtils->getMerchantCurrent()); | |||
} | |||
private function setMultipleMerchantProperty($entity){ | |||
private function setMultipleMerchantProperty($entity) | |||
{ | |||
if ($entity->getMerchants()->isEmpty()) { | |||
$entity->addMerchant($this->merchantUtils->getMerchantCurrent()); | |||
} |
@@ -98,7 +98,7 @@ abstract class Address extends AbstractEntity | |||
public function __toString() | |||
{ | |||
return $this->getTitle() ; | |||
return $this->getTitle().' - '.$this->getZip().' '.$this->getCity() ; | |||
} | |||
public function getUser(): ?User |
@@ -85,6 +85,11 @@ abstract class OrderShop implements FilterMerchantInterface | |||
*/ | |||
protected $documentDeliveryNote; | |||
/** | |||
* @ORM\Column(type="text", nullable=true) | |||
*/ | |||
protected $infosDelivery; | |||
public function __construct() | |||
{ | |||
$this->orderStatusHistories = new ArrayCollection(); | |||
@@ -304,4 +309,16 @@ abstract class OrderShop implements FilterMerchantInterface | |||
return $this; | |||
} | |||
public function getInfosDelivery(): ?string | |||
{ | |||
return $this->infosDelivery; | |||
} | |||
public function setInfosDelivery(?string $infosDelivery): self | |||
{ | |||
$this->infosDelivery = $infosDelivery; | |||
return $this; | |||
} | |||
} |
@@ -108,6 +108,15 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod | |||
return $quantity.$unit->getWordingShort() ; | |||
} | |||
public function getQuantityTitle($productFamily) | |||
{ | |||
$title = $this->getQuantityLabelInherited() ; | |||
if($productFamily->hasProductsWithVariousWeight()) { | |||
$title .= ', '.$this->getTitleInherited() ; | |||
} | |||
return $title ; | |||
} | |||
public function getAvailableQuantityInherited() | |||
{ | |||
if($this->getProductFamily()->getBehaviorCountStock()) { |
@@ -19,17 +19,6 @@ class PointSaleRepository extends BaseRepository implements DefaultRepositoryInt | |||
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() | |||
{ | |||
return $this->createQueryBuilder('e') |
@@ -0,0 +1,41 @@ | |||
<?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 ; | |||
} | |||
} |
@@ -2,7 +2,7 @@ | |||
namespace Lc\ShopBundle\Services ; | |||
class Cities | |||
class CityUtils | |||
{ | |||
function callApi($method, $url, $data = false) | |||
@@ -39,4 +39,20 @@ class Cities | |||
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 ; | |||
} | |||
} |
@@ -1,13 +0,0 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services; | |||
use CKSource\Bundle\CKFinderBundle\Authentication\Authentication as AuthenticationBase; | |||
class CustomCKFinderAuth extends AuthenticationBase | |||
{ | |||
public function authenticate() | |||
{ | |||
return true; | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
<?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 '' ; | |||
} | |||
} |
@@ -0,0 +1,18 @@ | |||
<?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 ; | |||
} | |||
} |
@@ -2,6 +2,7 @@ | |||
namespace Lc\ShopBundle\Services ; | |||
use Doctrine\Common\Collections\Collection; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
@@ -115,7 +116,7 @@ class PriceUtils | |||
return $total ; | |||
} | |||
if($entity instanceof OrderShopInterface) { | |||
return $this->getTotalWithTaxByOrderProducts($entity->getOrderProducts()) ; | |||
return $this->getTotalOrderProducts($entity->getOrderProducts(), true) ; | |||
} | |||
return null ; | |||
} | |||
@@ -131,30 +132,50 @@ class PriceUtils | |||
} | |||
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 | |||
@@ -199,7 +220,7 @@ class PriceUtils | |||
$price, | |||
$reductionCatalogValue | |||
), | |||
$this->getTaxRateInherited()->getValue() | |||
$entity->getTaxRateInherited()->getValue() | |||
); | |||
} | |||
elseif($reductionCatalogBehaviorTaxRate == 'tax-included') { |
@@ -22,6 +22,7 @@ class Utils | |||
$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') | |||
{ | |||
if($lang == 'fr') { | |||
@@ -54,7 +55,6 @@ class Utils | |||
return '' ; | |||
} | |||
public function getElementByDevAlias($devAlias, $class = PageInterface::class) | |||
{ | |||
$class = $this->em->getClassMetadata($class)->getName(); |
@@ -96,7 +96,7 @@ class FrontendTwigExtension extends AbstractExtension | |||
public function getProductCategories() | |||
{ | |||
$categories = $this->productCategoryRepository->findAllParents($this->merchantUtils->getMerchantCurrent()); | |||
$categories = $this->productCategoryRepository->findAllParents(false); | |||
return $categories; | |||
} | |||