<?php | |||||
namespace Lc\CaracoleBundle\Builder\Credit; | |||||
use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder; | |||||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | |||||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; | |||||
use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | |||||
class CreditHistoryBuilder | |||||
{ | |||||
protected UserMerchantStore $userMerchantStore; | |||||
protected UserMerchantBuilder $userMerchantBuilder; | |||||
public function __construct( | |||||
UserMerchantStore $userMerchantStore, | |||||
UserMerchantBuilder $userMerchantBuilder | |||||
) { | |||||
$this->userMerchantStore = $userMerchantStore; | |||||
$this->userMerchantBuilder = $userMerchantBuilder; | |||||
} | |||||
// saveCreditHistory | |||||
public function save(CreditHistoryInterface $creditHistory) | |||||
{ | |||||
if ($creditHistory) { | |||||
$userMerchant = $creditHistory->getUserMerchant(); | |||||
$isCreditActive = $this->userMerchantStore->isCreditActive($userMerchant); | |||||
if ($isCreditActive) { | |||||
if ($creditHistory->getType() == CreditHistoryModel::TYPE_CREDIT) { | |||||
$userMerchantAmount = $userMerchant->getCredit() + $creditHistory->getAmountInherited(); | |||||
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | |||||
return true; | |||||
} elseif ($creditHistory->getType() == CreditHistoryModel::TYPE_DEBIT) { | |||||
if ($this->userMerchantStore->isCreditSufficientToPay($userMerchant, $creditHistory->getAmountInherited())) { | |||||
$userMerchantAmount = $userMerchant->getCredit() - $creditHistory->getAmountInherited(); | |||||
$this->userMerchantBuilder->updateCredit($userMerchant, $creditHistory, $userMerchantAmount); | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} |
use Lc\CaracoleBundle\Factory\File\DocumentFactory; | use Lc\CaracoleBundle\Factory\File\DocumentFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; | use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory; | use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderReductionCartFactory; | |||||
use Lc\CaracoleBundle\Factory\Order\OrderReductionCreditFactory; | |||||
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; | use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory; | ||||
use Lc\CaracoleBundle\Model\File\DocumentModel; | use Lc\CaracoleBundle\Model\File\DocumentModel; | ||||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | use Lc\CaracoleBundle\Model\Order\OrderStatusModel; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | use Lc\CaracoleBundle\Model\User\VisitorInterface; | ||||
use Lc\CaracoleBundle\Repository\Order\OrderProductStore; | use Lc\CaracoleBundle\Repository\Order\OrderProductStore; | ||||
return $document; | return $document; | ||||
} | } | ||||
public function addReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart) | |||||
{ | |||||
$orderReductionCartFactory = new OrderReductionCartFactory(); | |||||
$orderReductionCart = $orderReductionCartFactory->create($orderShop, $reductionCart); | |||||
$orderShop->addOrderReductionCart($orderReductionCart) ; | |||||
if($this->orderShopStore->isPositiveAmount($orderShop) | |||||
&& $this->isPositiveAmountRemainingToBePaid($orderShop)) { | |||||
$this->entityManager->persist($orderReductionCart); | |||||
$this->entityManager->flush(); | |||||
return $orderReductionCart ; | |||||
} | |||||
else { | |||||
$orderShop->removeOrderReductionCart($orderReductionCart) ; | |||||
return false; | |||||
} | |||||
} | |||||
// createOrderReductionCredit | |||||
public function addReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) | |||||
{ | |||||
$orderReductionCreditFactory = new OrderReductionCreditFactory(); | |||||
$orderReductionCredit = $orderReductionCreditFactory->create($orderShop, $reductionCredit); | |||||
$orderShop->addOrderReductionCredit($orderReductionCredit) ; | |||||
if($this->isOrderShopPositiveAmount($orderShop) | |||||
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) { | |||||
$this->entityManager->persist($orderReductionCredit); | |||||
$this->entityManager->flush(); | |||||
return $orderReductionCredit; | |||||
} | |||||
else { | |||||
$orderShop->removeOrderReductionCredit($orderReductionCredit) ; | |||||
return false; | |||||
} | |||||
} | |||||
public function deductAvailabilityProduct(OrderShopInterface $orderShop) | |||||
{ | |||||
// @TODO : à refactorer en plaçant dans src tout ce qui est spécifique à PDL | |||||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | |||||
//Si ce n'esrt pas une relivraison OU si c'est une relivraison + relivraison + ce n'est pas une erruer producteur | |||||
if (!$orderProduct->isRedelivery() || ($orderProduct->isRedelivery() && $orderProduct->isRedeliverySupplierOrder() && !$orderProduct->isRedeliverySupplierMistake())) { | |||||
switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) { | |||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE : | |||||
//Disponibilité par unité de référence | |||||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||||
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient())); | |||||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||||
$productFamily->setAvailableQuantity($newAvailability); | |||||
$productFamily->setUpdatedBy($orderShop->getUser()); | |||||
$this->entityManager->persist($productFamily); | |||||
break; | |||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY : | |||||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||||
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); | |||||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||||
$productFamily->setAvailableQuantity($newAvailability); | |||||
$productFamily->setUpdatedBy($orderShop->getUser()); | |||||
$this->entityManager->persist($productFamily); | |||||
break; | |||||
case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : | |||||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||||
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); | |||||
$product = $orderProduct->getProduct(); | |||||
$product->setAvailableQuantity($newAvailability); | |||||
$product->setUpdatedBy($orderShop->getUser()); | |||||
$this->entityManager->persist($product); | |||||
break; | |||||
} | |||||
$this->entityManager->flush(); | |||||
} | |||||
} | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Builder\User; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\CaracoleBundle\Factory\User\UserPointSaleFactory; | |||||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
class UserBuilder | |||||
{ | |||||
protected EntityManagerInterface $entityManager; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->entityManager = $entityManager; | |||||
} | |||||
public function linkToPointSale(UserInterface $user, PointSaleInterface $pointSale) | |||||
{ | |||||
if (!$user->isLinkedToPointSale($pointSale)) { | |||||
$userPointSaleFactory = new UserPointSaleFactory(); | |||||
$userPointSale = $userPointSaleFactory->create($user, $pointSale); | |||||
$this->entityManager->persist($userPointSale); | |||||
$this->entityManager->flush(); | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} | |||||
<?php | |||||
namespace Lc\CaracoleBundle\Builder\User; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory; | |||||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||||
use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
class UserMerchantBuilder | |||||
{ | |||||
protected EntityManagerInterface $entityManager; | |||||
protected UserMerchantStore $userMerchantStore; | |||||
public function __construct( | |||||
EntityManagerInterface $entityManager, | |||||
UserMerchantStore $userMerchantStore | |||||
) { | |||||
$this->entityManager = $entityManager; | |||||
$this->userMerchantStore = $userMerchantStore; | |||||
} | |||||
public function createIfNotExist(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||||
{ | |||||
$userMerchant = $this->userMerchantStore | |||||
->setMerchant($merchant) | |||||
->getOneByUser($user); | |||||
if (!$userMerchant) { | |||||
$userMerchantFactory = new UserMerchantFactory(); | |||||
$userMerchant = $userMerchantFactory | |||||
->setMerchant($merchant) | |||||
->create($user); | |||||
} | |||||
return $userMerchant; | |||||
} | |||||
public function init(UserInterface $user, MerchantInterface $merchant, bool $active = true, bool $creditActive = false, float $credit = null, bool $persist = true) | |||||
{ | |||||
$userMerchant = $this->createIfNotExist($user, $merchant); | |||||
$userMerchant->setActive($active); | |||||
$userMerchant->setCreditActive($creditActive) ; | |||||
$userMerchant->setCredit($credit) ; | |||||
if($persist) { | |||||
$this->entityManager->persist($userMerchant); | |||||
$this->entityManager->flush(); | |||||
} | |||||
return $userMerchant; | |||||
} | |||||
public function updateCreditActive( | |||||
UserInterface $user, | |||||
MerchantInterface $merchant, | |||||
$creditActive = true | |||||
): UserMerchantInterface { | |||||
$userMerchant = $this->createIfNotExist($user, $merchant); | |||||
$userMerchant->setCreditActive($creditActive); | |||||
$this->entityManager->persist($userMerchant); | |||||
$this->entityManager->flush(); | |||||
return $userMerchant; | |||||
} | |||||
public function activeCredit(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||||
{ | |||||
return $this->updateCreditActive($user, $merchant, true); | |||||
} | |||||
public function unactiveCredit(UserInterface $user, MerchantInterface $merchant): UserMerchantInterface | |||||
{ | |||||
return $this->updateCreditActive($user, $merchant, false); | |||||
} | |||||
public function updateCredit( | |||||
UserMerchantInterface $userMerchant, | |||||
CreditHistoryInterface $creditHistory, | |||||
float $amount | |||||
): UserMerchantInterface { | |||||
$userMerchant->setCredit($amount); | |||||
$this->entityManager->persist($creditHistory); | |||||
$this->entityManager->persist($userMerchant); | |||||
$this->entityManager->flush(); | |||||
return $userMerchant; | |||||
} | |||||
} | |||||
use App\Entity\Credit\CreditHistory; | use App\Entity\Credit\CreditHistory; | ||||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | ||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
class CreditHistoryFactory extends AbstractFactory | class CreditHistoryFactory extends AbstractFactory | ||||
{ | { | ||||
public function create(): CreditHistoryInterface | |||||
// createCreditHistory | |||||
public function create(string $type, UserMerchantInterface $userMerchant): CreditHistoryInterface | |||||
{ | { | ||||
$creditHistory = new CreditHistory(); | $creditHistory = new CreditHistory(); | ||||
$creditHistory->setType($type) ; | |||||
$creditHistory->setUserMerchant($userMerchant) ; | |||||
return $creditHistory; | return $creditHistory; | ||||
} | } | ||||
use App\Entity\Order\OrderReductionCart; | use App\Entity\Order\OrderReductionCart; | ||||
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; | use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
class OrderReductionCartFactory extends AbstractFactory | class OrderReductionCartFactory extends AbstractFactory | ||||
{ | { | ||||
public function create(): OrderReductionCartInterface | |||||
// createOrderReductionCart | |||||
public function create(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart, $code = null): OrderReductionCartInterface | |||||
{ | { | ||||
$orderReductionCart = new OrderReductionCart(); | $orderReductionCart = new OrderReductionCart(); | ||||
$orderReductionCart->setOrderShop($orderShop); | |||||
$orderReductionCart->setReductionCart($reductionCart); | |||||
$orderReductionCart->setTitle($reductionCart->getTitle()); | |||||
$orderReductionCart->setValue($reductionCart->getValue()); | |||||
$orderReductionCart->setUnit($reductionCart->getUnit()); | |||||
$orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate()); | |||||
$orderReductionCart->setFreeShipping($reductionCart->getFreeShipping()); | |||||
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); | |||||
$orderReductionCart->setType($reductionCart->getType()); | |||||
$orderReductionCart->setCodeUsed($code); | |||||
return $orderReductionCart; | return $orderReductionCart; | ||||
} | } | ||||
use App\Entity\Order\OrderReductionCredit; | use App\Entity\Order\OrderReductionCredit; | ||||
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; | use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | |||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
class OrderReductionCreditFactory extends AbstractFactory | class OrderReductionCreditFactory extends AbstractFactory | ||||
{ | { | ||||
public function create(): OrderReductionCreditInterface | |||||
public function create(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit): OrderReductionCreditInterface | |||||
{ | { | ||||
$orderReductionCredit = new OrderReductionCredit(); | $orderReductionCredit = new OrderReductionCredit(); | ||||
$orderReductionCredit->setOrderShop($orderShop); | |||||
$orderReductionCredit->setReductionCredit($reductionCredit); | |||||
$orderReductionCredit->setTitle($reductionCredit->getTitle()); | |||||
$orderReductionCredit->setValue($reductionCredit->getValue()); | |||||
$orderReductionCredit->setUnit($reductionCredit->getUnit()); | |||||
$orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate()); | |||||
$orderReductionCredit->setType($reductionCredit->getType()); | |||||
return $orderReductionCredit; | return $orderReductionCredit; | ||||
} | } | ||||
namespace Lc\CaracoleBundle\Factory\User; | namespace Lc\CaracoleBundle\Factory\User; | ||||
use App\Entity\User\UserMerchant; | use App\Entity\User\UserMerchant; | ||||
use Lc\CaracoleBundle\Factory\MerchantFactoryTrait; | |||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | ||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | ||||
use Lc\SovBundle\Factory\AbstractFactory; | use Lc\SovBundle\Factory\AbstractFactory; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
class UserMerchantFactory extends AbstractFactory | class UserMerchantFactory extends AbstractFactory | ||||
{ | { | ||||
use MerchantFactoryTrait; | |||||
public function create(MerchantInterface $merchant): UserMerchantInterface | |||||
// createUserMerchant | |||||
public function create(UserInterface $user): UserMerchantInterface | |||||
{ | { | ||||
$userMerchant = new UserMerchant(); | $userMerchant = new UserMerchant(); | ||||
$userMerchant->setMerchant($merchant); | |||||
$userMerchant->setMerchant($this->merchant); | |||||
$userMerchant->setUser($user); | |||||
return $userMerchant; | return $userMerchant; | ||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Factory\User; | |||||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||||
use Lc\CaracoleBundle\Model\User\UserPointSaleInterface; | |||||
use Lc\SovBundle\Factory\AbstractFactory; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
class UserPointSaleFactory extends AbstractFactory | |||||
{ | |||||
public function create(UserInterface $user, PointSaleInterface $pointSale): UserPointSaleInterface | |||||
{ | |||||
$userPointSale = parent::create(); | |||||
$userPointSale->setUser($user); | |||||
$userPointSale->setPointSale($pointSale); | |||||
return $userPointSale; | |||||
} | |||||
} |
return $title; | return $title; | ||||
} | } | ||||
// isOrderProductAvailable | |||||
public function isAvailable() | |||||
{ | |||||
return $this->getProduct()->isAvailable($this->getQuantityOrder()); | |||||
} | |||||
// isOrderProductAvailableAddCart | |||||
public function isAvailableAddCart(OrderShopInterface $orderShop = null) | |||||
{ | |||||
$product = $this->getProduct(); | |||||
return $this->isProductAvailable($product, $this->getQuantityOrder(), true, $orderShop); | |||||
} | |||||
public function getOrderShop(): ?OrderShopInterface | public function getOrderShop(): ?OrderShopInterface | ||||
{ | { | ||||
return $this->orderShop; | return $this->orderShop; |
return $this; | return $this; | ||||
} | } | ||||
// getSummaryOrderProductReductionCatalog | |||||
public function getSummary() | |||||
{ | |||||
$text = ''; | |||||
if ($this->getUnit() == 'amount') { | |||||
$text .= '- ' . $this->getValue() . ' €'; | |||||
} | |||||
if ($this->getUnit() == 'percent') { | |||||
$text .= '- ' . $this->getValue() . ' %'; | |||||
} | |||||
return $text; | |||||
} | |||||
// compareOrderProductReductionCatalog | |||||
public function compare($orderProductReductionCatalog) | public function compare($orderProductReductionCatalog) | ||||
{ | { | ||||
return $orderProductReductionCatalog | return $orderProductReductionCatalog |
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | ||||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | use Lc\CaracoleBundle\Model\File\DocumentInterface; | ||||
use Lc\CaracoleBundle\Model\File\DocumentModel; | use Lc\CaracoleBundle\Model\File\DocumentModel; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel; | |||||
use Lc\CaracoleBundle\Model\Product\ProductInterface; | |||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | use Lc\CaracoleBundle\Model\Section\SectionInterface; | ||||
use Lc\SovBundle\Model\Ticket\TicketInterface; | use Lc\SovBundle\Model\Ticket\TicketInterface; | ||||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | use Lc\CaracoleBundle\Model\User\VisitorInterface; | ||||
public function hasOrderProductAlreadyInCart($orderProductTest) | public function hasOrderProductAlreadyInCart($orderProductTest) | ||||
{ | { | ||||
foreach($this->getOrderProducts() as $orderProduct) { | |||||
if($orderProduct->getProduct() == $orderProductTest->getProduct()) { | |||||
return $orderProduct ; | |||||
foreach ($this->getOrderProducts() as $orderProduct) { | |||||
if ($orderProduct->getProduct() == $orderProductTest->getProduct()) { | |||||
return $orderProduct; | |||||
} | } | ||||
} | } | ||||
return false ; | |||||
return false; | |||||
} | } | ||||
public function getOrderProductsByProductFamily($productFamily) | public function getOrderProductsByProductFamily($productFamily) | ||||
{ | { | ||||
$arrayOrderProducts = [] ; | |||||
$arrayOrderProducts = []; | |||||
foreach($this->getOrderProducts() as $orderProduct) { | |||||
if($orderProduct->getProduct()->getProductFamily() == $productFamily) { | |||||
$arrayOrderProducts[] = $orderProduct ; | |||||
foreach ($this->getOrderProducts() as $orderProduct) { | |||||
if ($orderProduct->getProduct()->getProductFamily() == $productFamily) { | |||||
$arrayOrderProducts[] = $orderProduct; | |||||
} | } | ||||
} | } | ||||
return $arrayOrderProducts ; | |||||
return $arrayOrderProducts; | |||||
} | |||||
public function getQuantityOrderByProduct(ProductInterface $product, $byWeight = false) | |||||
{ | |||||
$quantity = 0; | |||||
$productFamily = $product->getProductFamily(); | |||||
$behaviorCountStock = $productFamily->getBehaviorCountStock(); | |||||
foreach ($this->getOrderProducts() as $orderProduct) { | |||||
if ($orderProduct->getProduct()->getId() == $product->getId() | |||||
|| (($behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) | |||||
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { | |||||
if ($byWeight) { | |||||
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct( | |||||
) / $orderProduct->getProduct()->getUnitInherited()->getCoefficient()); | |||||
} else { | |||||
$quantity += $orderProduct->getQuantityOrder(); | |||||
} | |||||
} | |||||
} | |||||
return $quantity; | |||||
} | } | ||||
public function getValidationDate(): ?\DateTimeInterface | public function getValidationDate(): ?\DateTimeInterface |
use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface; | use Lc\CaracoleBundle\Doctrine\Extension\PriceInterface; | ||||
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; | use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | use Gedmo\Mapping\Annotation as Gedmo; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\SovBundle\Doctrine\Extension\SortableInterface; | use Lc\SovBundle\Doctrine\Extension\SortableInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\SortableTrait; | use Lc\SovBundle\Doctrine\Extension\SortableTrait; | ||||
use Lc\SovBundle\Doctrine\Extension\StatusTrait; | use Lc\SovBundle\Doctrine\Extension\StatusTrait; | ||||
return $title; | return $title; | ||||
} | } | ||||
public function isProductSaleStatusOn() | |||||
{ | |||||
if ($this->getProductFamily()->getSaleStatus() != 1) { | |||||
return false; | |||||
} | |||||
$allCategoriesSalesOff = true; | |||||
$unavailableSpecificDay = false; | |||||
foreach ($this->getProductFamily()->getProductCategories() as $category) { | |||||
if ($category->getParent()) { | |||||
if ($category->getSaleStatus() && $category->getParent()->getSaleStatus()) { | |||||
$allCategoriesSalesOff = false; | |||||
} | |||||
} else { | |||||
if ($category->getSaleStatus()) { | |||||
$allCategoriesSalesOff = false; | |||||
} | |||||
} | |||||
// specific day | |||||
// @TODO : spécifique pdl ? | |||||
$displaySpecificDay = $category->getDisplaySpecificDay(); | |||||
if ($displaySpecificDay && $displaySpecificDay != date('N')) { | |||||
$unavailableSpecificDay = true; | |||||
} | |||||
} | |||||
if ($allCategoriesSalesOff) { | |||||
return false; | |||||
} | |||||
if ($unavailableSpecificDay) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
// isProductAvailable | |||||
public function isAvailable($quantityOrder = 0, $checkCart = false, $orderShop = null) | |||||
{ | |||||
if ($this->getStatus() != 1 || $this->getProductFamily()->getStatus() != 1 || !$this->isProductSaleStatusOn()) { | |||||
return false; | |||||
} | |||||
// @TODO : orderShop à définir où est appelé isProductAvailable | |||||
if ($checkCart && !$orderShop) { | |||||
throw new \Exception("Attention jeune padawan : définir le orderShop à l'endroit où est appelé isProductAvailable"); | |||||
} | |||||
$productFamily = $this->getProductFamily(); | |||||
$quantityAsked = $quantityOrder; | |||||
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||||
if (!$quantityOrder) { | |||||
$quantityAsked = $orderShop->getQuantityOrderByProduct($this, true); | |||||
} else { | |||||
$quantityAsked = ($this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient()) * $quantityOrder; | |||||
} | |||||
if ($checkCart) { | |||||
$quantityAsked += $orderShop->getQuantityOrderByProduct($this, true); | |||||
} | |||||
} | |||||
if (($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY | |||||
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) { | |||||
if (!$quantityOrder) { | |||||
$quantityAsked = $orderShop->getQuantityOrderByProduct($this); | |||||
} | |||||
if ($checkCart) { | |||||
$quantityAsked += $orderShop->getQuantityOrderByProduct($this); | |||||
} | |||||
} | |||||
if ($this->getAvailableQuantityInherited() >= $quantityAsked | |||||
|| $productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_UNLIMITED) { | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | |||||
// getProductQuantityMaxAddCart | |||||
public function getQuantityMaxAddCart(OrderShopInterface $orderShop) | |||||
{ | |||||
$productFamily = $this->getProductFamily(); | |||||
$byWeight = false; | |||||
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||||
$byWeight = true; | |||||
} | |||||
return $this->getAvailableQuantityInherited() - $orderShop->getQuantityOrderByProduct($this, $byWeight); | |||||
} | |||||
// getProductQuantity | |||||
public function getProductQuantity() | |||||
{ | |||||
$productFamily = $this->getProductFamily(); | |||||
if ($productFamily->getBehaviorCountStock() == ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||||
return $this->getQuantityInherited() / $this->getUnitInherited()->getCoefficient(); | |||||
} else { | |||||
return 1; | |||||
} | |||||
} | |||||
public function getBuyingPriceInherited() | public function getBuyingPriceInherited() | ||||
{ | { | ||||
if ($this->getBuyingPrice()) { | if ($this->getBuyingPrice()) { |
use Lc\SovBundle\Doctrine\Extension\StatusInterface; | use Lc\SovBundle\Doctrine\Extension\StatusInterface; | ||||
use Lc\SovBundle\Doctrine\Extension\StatusTrait; | use Lc\SovBundle\Doctrine\Extension\StatusTrait; | ||||
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass() | * @ORM\MappedSuperclass() | ||||
$this->uncombinables = new ArrayCollection(); | $this->uncombinables = new ArrayCollection(); | ||||
} | } | ||||
// isReductionCartMatchWithUser | |||||
public function matchWithUser(UserInterface $user) | |||||
{ | |||||
$conditionUser = false; | |||||
if ($user) { | |||||
if ($this->getUsers()->isEmpty() || $this->getUsers()->contains($user)) { | |||||
$conditionUser = true; | |||||
} | |||||
} | |||||
return $conditionUser; | |||||
} | |||||
// isReductionCartMatchWithGroupUser | |||||
public function matchWithGroupUser(UserInterface $user) | |||||
{ | |||||
$conditionGroupUser = false; | |||||
if ($user) { | |||||
if ($user->getGroupUsers() && count($user->getGroupUsers()) > 0) { | |||||
foreach ($user->getGroupUsers() as $groupUser) { | |||||
if ($this->getGroupUsers()->isEmpty() || $this->getGroupUsers()->contains($groupUser)) { | |||||
$conditionGroupUser = true; | |||||
} | |||||
} | |||||
} else { | |||||
if ($reductionCart->getGroupUsers()->isEmpty()) { | |||||
$conditionGroupUser = true; | |||||
} | |||||
} | |||||
} | |||||
return $conditionGroupUser; | |||||
} | |||||
public function getTitle(): ?string | public function getTitle(): ?string | ||||
{ | { |
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | use Gedmo\Mapping\Annotation as Gedmo; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | use Lc\CaracoleBundle\Model\Address\AddressInterface; | ||||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | ||||
protected $newsletters; | protected $newsletters; | ||||
/** | /** | ||||
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface") | * @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface") | ||||
*/ | */ | ||||
return (string)ucfirst(strtolower($this->getFirstname())) . ' ' . strtoupper($this->getLastname()); | return (string)ucfirst(strtolower($this->getFirstname())) . ' ' . strtoupper($this->getLastname()); | ||||
} | } | ||||
// isUserLinkedToPointSale | |||||
public function isLinkedToPointSale(PointSaleInterface $pointSale) | |||||
{ | |||||
foreach ($this->getUserPointSales() as $userPointSale) { | |||||
if ($userPointSale->getPointSale()->getId() == $pointSale->getId()) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
public function getPhone(): ?string | public function getPhone(): ?string | ||||
{ | { | ||||
return $this->phone; | return $this->phone; |
<?php | |||||
namespace Lc\CaracoleBundle\Notification; | |||||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; | |||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Twig\Environment; | |||||
class MailMailjetNotification | |||||
{ | |||||
const SUBJECT = 'subject'; | |||||
const SUBJECT_PREFIX = 'subject-prefix'; | |||||
const TO_EMAIL = 'to-email'; | |||||
const COPY_TO = 'copy-to'; | |||||
const COPY_HIDDEN_TO = 'copy-hidden-to'; | |||||
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'; | |||||
//const DISPOSITION_NOTIFICATION_TO = 'disposition-notification-to' ; | |||||
protected $transport; | |||||
protected $templating; | |||||
protected $parameterBag; | |||||
protected $merchantResolver; | |||||
public function __construct( | |||||
MailjetTransport $mailjetTransport, | |||||
Environment $templating, | |||||
ParameterBagInterface $parameterBag, | |||||
MerchantResolver $merchantResolver | |||||
) { | |||||
$this->transport = $mailjetTransport; | |||||
$this->templating = $templating; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->merchantResolver = $merchantResolver; | |||||
} | |||||
public function send($params = []) | |||||
{ | |||||
$merchantCurrent = $this->merchantResolver->getCurrent(); | |||||
$merchantConfigEmailFrom = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_FROM); | |||||
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL])) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom; | |||||
$merchantConfigEmailFromName = $merchantCurrent->getSettingValue(MerchantSettingDefinition::EMAIL_FROM_NAME); | |||||
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName; | |||||
$merchantConfigEmailSubjectPrefix = $merchantCurrent->getSettingValue(MerchantSettingDefinition::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]); | |||||
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); | |||||
} | |||||
$contentData = [] ; | |||||
if(isset($params[self::CONTENT_DATA])) { | |||||
$contentData = $params[self::CONTENT_DATA] ; | |||||
} | |||||
$message->addFrom($emailFrom, $emailFromName) | |||||
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData), 'text/html') | |||||
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData)); | |||||
if(isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) { | |||||
$message->addCc($params[self::COPY_TO]); | |||||
} | |||||
if(isset($params[self::COPY_HIDDEN_TO]) && strlen($params[self::COPY_HIDDEN_TO])) { | |||||
$message->addBcc($params[self::COPY_HIDDEN_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])) { | |||||
$message->attach(\Swift_Attachment::newInstance( | |||||
$params[self::ATTACHMENT_DATA], | |||||
$params[self::ATTACHMENT_FILENAME], | |||||
$params[self::ATTACHMENT_CONTENT_TYPE] | |||||
)); | |||||
} | |||||
/*if(isset($params[self::DISPOSITION_NOTIFICATION_TO]) && $params[self::DISPOSITION_NOTIFICATION_TO]) { | |||||
$emailFromDispositionNotificationTo = $emailFrom ; | |||||
if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { | |||||
$emailFromDispositionNotificationTo = $params[self::REPLY_TO] ; | |||||
} | |||||
$message->getHeaders()->addTextHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo) ; | |||||
$message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo); | |||||
}*/ | |||||
return $this->transport->send($message); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Notification; | |||||
use Lc\SovBundle\Component\StringComponent; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Symfony\Contracts\HttpClient\HttpClientInterface; | |||||
use Twig\Environment; | |||||
class SmsFactorNotification | |||||
{ | |||||
const TO_USER = 'to-user' ; | |||||
const CONTENT_MESSAGE = 'content-message' ; | |||||
const CONTENT_TEMPLATE = 'content-template' ; | |||||
const CONTENT_DATA = 'content-data' ; | |||||
protected HttpClientInterface $client; | |||||
protected ParameterBagInterface $parameterBag; | |||||
protected MailMailjetNotification $mailMailjetNotification ; | |||||
protected StringComponent $stringComponent ; | |||||
protected Environment $templating ; | |||||
public function __construct( | |||||
HttpClientInterface $client, | |||||
ParameterBagInterface $parameterBag, | |||||
MailMailjetNotification $mailMailjetNotification, | |||||
StringComponent $stringComponent, | |||||
Environment $templating | |||||
) { | |||||
$this->client = $client; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->mailMailjetNotification = $mailMailjetNotification ; | |||||
$this->stringComponent = $stringComponent ; | |||||
$this->templating = $templating ; | |||||
} | |||||
public function send($params = []) | |||||
{ | |||||
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ; | |||||
if($user) { | |||||
$phone = $this->stringComponent->formatPhoneNumber($user->getPhone()) ; | |||||
$message = '' ; | |||||
if(isset($params[self::CONTENT_MESSAGE])) { | |||||
$message = $params[self::CONTENT_MESSAGE] ; | |||||
} | |||||
elseif(isset($params[self::CONTENT_TEMPLATE])) { | |||||
$template = $params[self::CONTENT_TEMPLATE] ; | |||||
$paramsTemplate = [] ; | |||||
if(isset($params[self::CONTENT_DATA]) && is_array($params[self::CONTENT_DATA])) { | |||||
$paramsTemplate = $params[self::CONTENT_DATA] ; | |||||
} | |||||
$message = $this->templating->render($template, $paramsTemplate) ; | |||||
} | |||||
if($this->parameterBag->get('mailjet.dev.redirect.active') == 1) { | |||||
$this->mailMailjetNotification->send([ | |||||
MailMailjetNotification::SUBJECT => 'Notification par SMS à '.$phone, | |||||
MailMailjetNotification::TO_EMAIL => $user->getEmail(), | |||||
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/notification', | |||||
MailMailjetNotification::CONTENT_DATA => [ | |||||
'message' => $message | |||||
], | |||||
]); | |||||
return true ; | |||||
} | |||||
else { | |||||
$token = $this->parameterBag->get('smsfactor.token'); | |||||
$from = $this->parameterBag->get('smsfactor.from'); | |||||
if ($token && strlen($token) > 0) { | |||||
$response = $this->client->request( | |||||
'GET', | |||||
'https://api.smsfactor.com/send', | |||||
[ | |||||
'headers' => [ | |||||
'Authorization' => 'Bearer ' . $token, | |||||
'Content-Type' => 'application/json; charset=utf-8', | |||||
'Accept' => 'application/json' | |||||
], | |||||
'query' => [ | |||||
'sender' => $from, | |||||
'to' => $phone, | |||||
'text' => $message, | |||||
], | |||||
] | |||||
); | |||||
return $response ; | |||||
} | |||||
else { | |||||
throw new \ErrorException('Le token SMS SmsFactor n\'est pas défini.'); | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} |
} | } | ||||
return $unitsList; | return $unitsList; | ||||
} | } | ||||
} | } |
namespace Lc\CaracoleBundle\Repository\Order; | namespace Lc\CaracoleBundle\Repository\Order; | ||||
use Lc\CaracoleBundle\Model\Order\OrderProductInterface; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class OrderProductStore extends AbstractStore | class OrderProductStore extends AbstractStore |
return $orderProductsByProductFamily; | return $orderProductsByProductFamily; | ||||
} | } | ||||
// isOrderShopPositiveAmount | |||||
public function isPositiveAmount(OrderShopInterface $orderShop) | public function isPositiveAmount(OrderShopInterface $orderShop) | ||||
{ | { | ||||
return $this->priceResolver->getTotalWithTax($orderShop) >= 0; | return $this->priceResolver->getTotalWithTax($orderShop) >= 0; | ||||
return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop); | return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop); | ||||
} | } | ||||
public function isOrderShopPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool | |||||
// isOrderShopPositiveAmountRemainingToBePaid | |||||
public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool | |||||
{ | { | ||||
return $this->getTotalRemainingToBePaid($orderShop) > 0; | return $this->getTotalRemainingToBePaid($orderShop) > 0; | ||||
} | } |
namespace Lc\CaracoleBundle\Repository\Product; | namespace Lc\CaracoleBundle\Repository\Product; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||||
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class ProductFamilyStore extends AbstractStore | class ProductFamilyStore extends AbstractStore | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
public function isOneProductAvailableAddCart(array $products): bool | |||||
{ | |||||
foreach ($products as $product) { | |||||
if ($product->isAvailable(1, true)) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Product; | namespace Lc\CaracoleBundle\Repository\Product; | ||||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||||
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class ProductStore extends AbstractStore | class ProductStore extends AbstractStore | ||||
{ | { | ||||
protected ProductRepositoryQuery $query; | protected ProductRepositoryQuery $query; | ||||
protected PriceResolver $priceResolver; | |||||
public function __construct(ProductRepositoryQuery $query) | |||||
public function __construct(ProductRepositoryQuery $query, PriceResolver $priceResolver) | |||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
$this->priceResolver = $priceResolver; | |||||
} | |||||
public function getCheapestProduct($productFamily) | |||||
{ | |||||
$priceResolver = $this->priceResolver; | |||||
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceResolver) { | |||||
return $priceResolver->getPriceWithTaxAndReduction($a) > $priceResolver->getPriceWithTaxAndReduction($b); | |||||
}, true); | |||||
} | |||||
public function getCheapestProductByRefUnit(ProductFamilyInterface $productFamily) | |||||
{ | |||||
$priceResolver = $this->priceResolver; | |||||
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceResolver) { | |||||
return $priceResolver->getPriceByRefUnitWithTaxAndReduction($a) > $priceResolver->getPriceByRefUnitWithTaxAndReduction($b); | |||||
}, false); | |||||
} | |||||
public function getMostExpensiveProductByRefUnit(ProductFamilyInterface $productFamily) | |||||
{ | |||||
$priceResolver = $this->priceResolver; | |||||
return $this->getCheapestOrMostExpensiveProduct($productFamily, function ($a, $b) use ($priceResolver) { | |||||
return $priceResolver->getPriceByRefUnitWithTaxAndReduction($a) < $priceResolver->getPriceByRefUnitWithTaxAndReduction($b); | |||||
}, false); | |||||
} | |||||
private function getCheapestOrMostExpensiveProduct(ProductFamilyInterface $productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) | |||||
{ | |||||
if ($productFamily->getActiveProducts()) { | |||||
$products = $productFamily->getProductsOnline()->getValues(); | |||||
if (count($products) > 0) { | |||||
usort($products, $comparisonFunction); | |||||
return $products[0]; | |||||
} | |||||
} else { | |||||
return $productFamily->getOriginProduct(); | |||||
} | |||||
if ($returnSelfIfNotActiveProducts) { | |||||
return $productFamily; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | } | ||||
} | } |
{ | { | ||||
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
} | } | ||||
public function filterByCode(string $code) | |||||
{ | |||||
return $this | |||||
->andWhere('.codes LIKE :code') | |||||
->setParameter('code', '%'.$code.'%') ; | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Reduction; | namespace Lc\CaracoleBundle\Repository\Reduction; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface; | |||||
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class ReductionCartStore extends AbstractStore | class ReductionCartStore extends AbstractStore | ||||
{ | { | ||||
protected ReductionCartRepositoryQuery $query; | protected ReductionCartRepositoryQuery $query; | ||||
protected OrderShopStore $orderShopStore; | |||||
public function __construct(ReductionCartRepositoryQuery $query) | |||||
{ | |||||
public function __construct( | |||||
ReductionCartRepositoryQuery $query, | |||||
OrderShopStore $orderShopStore | |||||
) { | |||||
$this->query = $query; | $this->query = $query; | ||||
$this->orderShopStore = $orderShopStore; | |||||
} | } | ||||
// getReductionCartByCode | |||||
public function getByCode(string $code) | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query->filterByCode($code); | |||||
$reductionCarts = $query->find(); | |||||
$findReductionCart = null; | |||||
foreach ($reductionCarts as $reductionCart) { | |||||
if ($reductionCart && in_array($code, $reductionCart->getCodes())) { | |||||
$findReductionCart = $reductionCart; | |||||
} | |||||
} | |||||
return $findReductionCart; | |||||
} | |||||
// getReductionCartRemainingQuantity | |||||
public function getRemainingQuantity(ReductionCartInterface $reductionCart): float | |||||
{ | |||||
return $reductionCart->getAvailableQuantity() - $this->orderShopStore->countValidOrderWithReductionCart( | |||||
$reductionCart | |||||
); | |||||
} | |||||
// getReductionCartUsedQuantityPerUser | |||||
public function getUsedQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float | |||||
{ | |||||
return $this->orderShopStore->countValidOrderWithReductionCartPerUser($reductionCart, $user); | |||||
} | |||||
// getReductionCartUsedQuantity | |||||
public function getUsedQuantity(ReductionCartInterface $reductionCart): float | |||||
{ | |||||
return $this->orderShopStore->countValidOrderWithReductionCart($reductionCart); | |||||
} | |||||
// getReductionCartRemainingQuantityPerUser | |||||
public function getRemainingQuantityByUser(ReductionCartInterface $reductionCart, UserInterface $user): float | |||||
{ | |||||
if ($reductionCart->getAvailableQuantityPerUser()) { | |||||
return $reductionCart->getAvailableQuantityPerUser( | |||||
) - $this->orderShopRepo->countValidOrderWithReductionCartPerUser($reductionCart, $user); | |||||
} | |||||
return false; | |||||
} | |||||
// findAllAvailableForUser / getReductionCartsAvailableByUser | |||||
public function getAvailablesByUser(UserInterface $user) | |||||
{ | |||||
$reductionCarts = $this->query->find(); | |||||
$reductionCartsArray = []; | |||||
foreach ($reductionCarts as $reductionCart) { | |||||
if ($reductionCart->matchWithUser($user) | |||||
&& $reductionCart->matchWithGroupUser($user) | |||||
&& $this->getRemainingQuantityByUser($reductionCart, $user) | |||||
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) { | |||||
$reductionCartsArray[] = $reductionCart; | |||||
} | |||||
} | |||||
return $reductionCartsArray; | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Reduction; | namespace Lc\CaracoleBundle\Repository\Reduction; | ||||
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; | |||||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | use Lc\SovBundle\Repository\AbstractRepositoryQuery; | ||||
class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery | class ReductionCreditRepositoryQuery extends AbstractRepositoryQuery | ||||
{ | { | ||||
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
} | } | ||||
public function filterStatusOnline() | |||||
{ | |||||
return $this->andWhere('.status = 1'); | |||||
} | |||||
public function filterByUser(UserInterface $user) | |||||
{ | |||||
return $this | |||||
->andWhere(':user MEMBER OF .users') | |||||
->setParameter('user', $user); | |||||
} | |||||
public function filterByType(string $type = ReductionCreditModel::TYPE_CREDIT) | |||||
{ | |||||
return $this | |||||
->andWhere('.type = :type') | |||||
->setParameter('type', $type); | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\Reduction; | namespace Lc\CaracoleBundle\Repository\Reduction; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | |||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel; | |||||
use Lc\CaracoleBundle\Repository\Order\OrderShopStore; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class ReductionCreditStore extends AbstractStore | class ReductionCreditStore extends AbstractStore | ||||
{ | { | ||||
protected ReductionCreditRepositoryQuery $query; | protected ReductionCreditRepositoryQuery $query; | ||||
protected OrderShopStore $orderShopStore; | |||||
public function __construct(ReductionCreditRepositoryQuery $query) | |||||
{ | |||||
public function __construct( | |||||
ReductionCreditRepositoryQuery $query, | |||||
OrderShopStore $orderShopStore | |||||
) { | |||||
$this->query = $query; | $this->query = $query; | ||||
$this->orderShopStore = $orderShopStore; | |||||
} | |||||
// isReductionCreditAllowAddToOrder | |||||
public function isAllowAddToOrder(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) | |||||
{ | |||||
$user = $orderShop->getUser(); | |||||
// appartient à l'utilisateur | |||||
if (!$reductionCredit->getUsers()->contains($user)) { | |||||
// @TODO : gérer les addFlash dans le controleur | |||||
//$this->utils->addFlash('error', 'error.reductionCredit.userNotAllow'); | |||||
return false; | |||||
} | |||||
// n'a pas été utilisé | |||||
if ($reductionCredit->getType() == ReductionCredit::TYPE_CREDIT) { | |||||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user) > 0) { | |||||
//$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse'); | |||||
return false; | |||||
} | |||||
} else { | |||||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit) > 0) { | |||||
//$this->utils->addFlash('error', 'error.reductionCredit.alreadyUse'); | |||||
return false; | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
// findReductionCreditsByUser | |||||
public function getByTypeAndUser(string $type = ReductionCreditModel::TYPE_CREDIT, UserInterface $user) | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query | |||||
->filterStatusOnline() | |||||
->filterByType($type) | |||||
->filterByUser($user); | |||||
return $query->find(); | |||||
} | |||||
public function getReductionCreditsAvailableByUser(UserInterface $user) | |||||
{ | |||||
$reductionCredits = $this->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user); | |||||
$reductionCreditsArray = []; | |||||
foreach ($reductionCredits as $reductionCredit) { | |||||
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) { | |||||
$reductionCreditsArray[] = $reductionCredit; | |||||
} | |||||
} | |||||
return $reductionCreditsArray; | |||||
} | |||||
public function getReductionGiftsAvailableByUser($user) | |||||
{ | |||||
$reductionGifts = $this->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user); | |||||
$reductionGiftsArray = []; | |||||
foreach ($reductionGifts as $reductionGift) { | |||||
if (!$this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) { | |||||
$reductionGiftsArray[] = $reductionGift; | |||||
} | |||||
} | |||||
return $reductionGiftsArray; | |||||
} | |||||
public function isReductionGiftUsed(ReductionCreditInterface $reductionGift) | |||||
{ | |||||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionGift)) { | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | |||||
public function isReductionCreditUsed(ReductionCreditInterface $reductionCredit, UserInterface $user = null) | |||||
{ | |||||
if ($this->orderShopStore->countValidOrderWithReductionCredit($reductionCredit, $user)) { | |||||
return true; | |||||
} else { | |||||
return false; | |||||
} | |||||
} | |||||
public function isReductionCreditAddedToOrder( | |||||
OrderShopInterface $orderShop, | |||||
ReductionCreditInterface $reductionCredit | |||||
) { | |||||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||||
if ($orderReductionCredit->getReductionCredit() == $reductionCredit) { | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | } | ||||
} | } |
use Knp\Component\Pager\PaginatorInterface; | use Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait; | ||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | use Lc\SovBundle\Repository\AbstractRepositoryQuery; | ||||
class UserMerchantRepositoryQuery extends AbstractRepositoryQuery | class UserMerchantRepositoryQuery extends AbstractRepositoryQuery | ||||
{ | { | ||||
parent::__construct($repository, 'r', $paginator); | parent::__construct($repository, 'r', $paginator); | ||||
} | } | ||||
public function filterByUser(UserInterface $user) | |||||
{ | |||||
return $this | |||||
->andWhere('.user = :user') | |||||
->setParameter('user', $user); | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Repository\User; | namespace Lc\CaracoleBundle\Repository\User; | ||||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||||
use Lc\CaracoleBundle\Repository\MerchantStoreTrait; | |||||
use Lc\SovBundle\Model\User\UserInterface; | |||||
use Lc\SovBundle\Repository\AbstractStore; | use Lc\SovBundle\Repository\AbstractStore; | ||||
class UserMerchantStore extends AbstractStore | class UserMerchantStore extends AbstractStore | ||||
{ | { | ||||
use MerchantStoreTrait; | |||||
protected UserMerchantRepositoryQuery $query; | protected UserMerchantRepositoryQuery $query; | ||||
public function __construct(UserMerchantRepositoryQuery $query) | public function __construct(UserMerchantRepositoryQuery $query) | ||||
{ | { | ||||
$this->query = $query; | $this->query = $query; | ||||
} | } | ||||
// getUserMerchant | |||||
public function getOneByUser(UserInterface $user) | |||||
{ | |||||
$query = $this->query->create(); | |||||
$query | |||||
->filterByMerchant($this->merchant) | |||||
->filterByUser($user); | |||||
return $query->findOne(); | |||||
} | |||||
public function isCreditActive(UserMerchantInterface $userMerchant = null) | |||||
{ | |||||
if (!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) { | |||||
return false; | |||||
} | |||||
return true; | |||||
} | |||||
public function isCreditActiveByUser(UserInterface $user) | |||||
{ | |||||
$userMerchant = $this->getOneByUser($user); | |||||
return $this->isCreditActive($userMerchant); | |||||
} | |||||
public function isCreditSufficientToPay(UserMerchantInterface $userMerchant, float $amount) | |||||
{ | |||||
if ($this->isCreditActive($userMerchant) && $userMerchant->getCredit() >= $amount) { | |||||
return true; | |||||
} | |||||
return false; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\User; | |||||
use App\Entity\User\UserPointSale; | |||||
use Doctrine\Persistence\ManagerRegistry; | |||||
use Lc\SovBundle\Repository\AbstractRepository; | |||||
class UserPointSaleRepository extends AbstractRepository | |||||
{ | |||||
public function __construct(ManagerRegistry $registry) | |||||
{ | |||||
parent::__construct($registry, UserPointSale::class); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\User; | |||||
use Knp\Component\Pager\PaginatorInterface; | |||||
use Lc\SovBundle\Repository\AbstractRepositoryQuery; | |||||
class UserPointSaleRepositoryQuery extends AbstractRepositoryQuery | |||||
{ | |||||
public function __construct(UserPointSaleRepository $repository, PaginatorInterface $paginator) | |||||
{ | |||||
parent::__construct($repository, 'r', $paginator); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Repository\User; | |||||
use Lc\SovBundle\Repository\AbstractStore; | |||||
class UserPointSaleStore extends AbstractStore | |||||
{ | |||||
protected UserPointSaleRepositoryQuery $query; | |||||
public function __construct(UserPointSaleRepositoryQuery $query) | |||||
{ | |||||
$this->query = $query; | |||||
} | |||||
} |