Browse Source

Pages commandes

feature/export_comptable
Fab 4 years ago
parent
commit
875b59c0ff
9 changed files with 273 additions and 84 deletions
  1. +3
    -3
      ShopBundle/Controller/CitiesController.php
  2. +1
    -0
      ShopBundle/Controller/Frontend/CartController.php
  3. +1
    -1
      ShopBundle/Model/AbstractEntity.php
  4. +2
    -1
      ShopBundle/Model/Product.php
  5. +6
    -1
      ShopBundle/Repository/ProductCategoryRepository.php
  6. +3
    -1
      ShopBundle/Repository/ReductionCartRepository.php
  7. +163
    -76
      ShopBundle/Services/Order/OrderUtils.php
  8. +1
    -0
      ShopBundle/Services/ProductFamilyUtils.php
  9. +93
    -1
      ShopBundle/Services/Utils.php

+ 3
- 3
ShopBundle/Controller/CitiesController.php View File

@@ -10,11 +10,11 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

class CitiesController extends AbstractController
{
protected $cities ;
protected $utils ;

public function __construct(Utils $cities)
public function __construct(Utils $utils)
{
$this->cities = $cities ;
$this->utils = $utils ;
}

public function index(Request $request) : JsonResponse

+ 1
- 0
ShopBundle/Controller/Frontend/CartController.php View File

@@ -13,6 +13,7 @@ use Lc\ShopBundle\Context\OrderUtilsInterface;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ReductionCartInterface;
use Lc\ShopBundle\Model\OrderReductionCart;
use Lc\ShopBundle\Model\ProductFamily;
use Lc\ShopBundle\Services\UserUtils;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

+ 1
- 1
ShopBundle/Model/AbstractEntity.php View File

@@ -40,7 +40,7 @@ abstract class AbstractEntity
protected $updatedBy;


public function addError($message, $domain = 'lcshop', $params){
public function addError($message, $domain = 'lcshop', $params = []){
$this->errors[] = array(
'message'=> $message,
'domain'=> $domain,

+ 2
- 1
ShopBundle/Model/Product.php View File

@@ -105,7 +105,8 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod
{
if ($this->getQuantity()) {
return $this->getQuantity();
} else {
}
else {
return $this->getProductFamily()->getQuantity();
}
}

+ 6
- 1
ShopBundle/Repository/ProductCategoryRepository.php View File

@@ -42,7 +42,7 @@ class ProductCategoryRepository extends BaseRepository implements DefaultReposit

}

public function findAllByParent($parentCategory, $withOffline = false)
public function findAllByParent($parentCategory, $withOffline = false, $withEmptyCategories = true)
{
$query = $this->createQueryBuilder('e');
$query->andWhere('e.parent = :idParentCategory');
@@ -50,6 +50,11 @@ class ProductCategoryRepository extends BaseRepository implements DefaultReposit
if ($withOffline) $query->andWhere('e.status >= 0');
else $query->andWhere('e.status = 1');

if(!$withEmptyCategories) {
$query->innerJoin('e.productFamilies','pf') ;
$query->andWhere('pf.status = 1') ;
}

$query->setParameter('idParentCategory', $parentCategory->getId());
return $query->getQuery()->getResult();
}

+ 3
- 1
ShopBundle/Repository/ReductionCartRepository.php View File

@@ -69,7 +69,9 @@ class ReductionCartRepository extends BaseRepository implements DefaultRepositor
$reductionCartsArray = [] ;
foreach($reductionCarts as $reductionCart) {
if($this->orderUtils->isReductionCartMatchWithUser($reductionCart, $user)
&& $this->orderUtils->isReductionCartMatchWithGroupUser($reductionCart, $user)) {
&& $this->orderUtils->isReductionCartMatchWithGroupUser($reductionCart, $user)
&& $this->orderUtils->countReductionCartAvailableForUser($reductionCart, $user)) {

$reductionCartsArray[] = $reductionCart ;
}
}

+ 163
- 76
ShopBundle/Services/Order/OrderUtils.php View File

@@ -65,7 +65,6 @@ class OrderUtils

public function getCartCurrent()
{

$paramsSearchOrderShop = [];

$user = $this->security->getUser();
@@ -91,7 +90,6 @@ class OrderUtils
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())) {

$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->session->getFlashBag()->add('success', "Votre panier visiteur vient d'être fusionné avec votre panier client.");
} else {
@@ -152,73 +150,86 @@ class OrderUtils
]);
}

if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false;

$orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop());
$orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct()));
$orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited());
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited());
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited());

$productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug());
$reductionCatalog = $productFamily->getReductionCatalog();
if ($reductionCatalog) {
$orderProductReductionCatalog = new OrderProductReductionCatalog();
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle());
$orderProductReductionCatalog->setValue($reductionCatalog->getValue());
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit());
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate());

$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);
}
if($this->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
if ($orderProductAdd->getQuantityOrder() > 0) {
$updated = false;

$orderProductAdd->setTitle($orderProductAdd->getTitleOrderShop());
$orderProductAdd->setPrice($this->priceUtils->getPrice($orderProductAdd->getProduct()));
$orderProductAdd->setUnit($orderProductAdd->getProduct()->getUnitInherited());
$orderProductAdd->setTaxRate($orderProductAdd->getProduct()->getTaxRateInherited());
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited());

$productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug());
$reductionCatalog = $productFamily->getReductionCatalog();
if ($reductionCatalog) {
$orderProductReductionCatalog = new OrderProductReductionCatalog();
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle());
$orderProductReductionCatalog->setValue($reductionCatalog->getValue());
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit());
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate());

$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);
}

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

$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());
$orderProduct->setQuantityOrder($orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder());

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

$updated = true;
$return = true;
$updated = true;
$return = true;

break;
break;
}
}
}

if (!$updated) {
$orderShop->addOrderProduct($orderProductAdd);
if (!$updated) {
$orderShop->addOrderProduct($orderProductAdd);

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

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

}

$return = true;
}

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

$return = true;
}
}
else {
$availableQuantity = $orderProductAdd->getProduct()->getAvailableQuantityInherited() ;
$textError = "Le produit <strong>".$orderProductAdd->getTitleOrderShop()."</strong> n'est pas disponible" ;
if($availableQuantity !== false && $availableQuantity > 0) {
$unit = '' ;
if($orderProductAdd->getProduct()->getProductFamily()->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$unit = $orderProductAdd->getProduct()->getUnitInherited()->getUnit() ;
}
$textError .= ' dans cette quantité ' ;
$textError .= '<br />'.$availableQuantity.$unit.' disponible(s) dont '.$this->getQuantityOrderByProduct($orderShop, $orderProductAdd->getProduct()).$unit.' déjà dans votre panier.' ;
}
$this->session->getFlashBag()->add('error', $textError) ;
}

return $return;
return $return ;
}


public function countQuantities($orderShop)
{
return $this->countQuantitiesByOrderProducts($orderShop->getOrderProducts());
@@ -445,34 +456,6 @@ class OrderUtils
}
}

public function isProductAvailable(Product $product, $quanityOrder)
{
$quanityAsked = $quanityOrder;

switch ($product->getProductFamily()->getBehaviorCountStock()) {
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
if ($product->getAvailableQuantityInherited() >= $quanityAsked) {
return true;
} else {
return false;
}
break;
case ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
$quanityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quanityOrder;
if ($product->getAvailableQuantityInherited() >= $quanityAsked) {
return true;
} else {
return false;
}
break;
case ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED :
return true;

}

}

public function isCartAllowToBeOrder($order){
return true;
}
@@ -501,4 +484,108 @@ class OrderUtils

return false ;
}

public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null)
{
if(!$orderShop) {
$orderShop = $this->getCartCurrent() ;
}
$productFamily = $product->getProductFamily() ;
$quantityAsked = $quantityOrder;

if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
if(!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true) ;
}
else {
$quantityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quantityOrder;
}

if($checkCart) {
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product, true) ;
}
}

if(($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) {

if(!$quantityOrder) {
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product) ;
}

if($checkCart) {
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product) ;
}
}

if ($product->getAvailableQuantityInherited() >= $quantityAsked
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) {
return true;
}
else {
return false;
}
}

public function isOneProductAvailableAddCart($products): bool
{
$orderShop = $this->getCartCurrent() ;

foreach($products as $product) {
if($this->isProductAvailable($product, 1, true)) {
return true ;
}
}

return false ;
}

public function isOrderProductAvailable(OrderProductInterface $orderProduct)
{
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()) ;
}

public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null)
{
$product = $orderProduct->getProduct() ;
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop);
}

public function getQuantityOrderByProduct($orderShop, $product, $byWeight = false)
{
$quantity = 0 ;
$productFamily = $product->getProductFamily() ;
$behaviorCountStock = $productFamily->getBehaviorCountStock() ;

if($orderShop) {
foreach($orderShop->getOrderProducts() as $orderProduct) {
if($orderProduct->getProduct()->getId() == $product->getId()
|| ( ($behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE)
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) {

if($byWeight) {
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $product->getUnitInherited()->getCoefficient()) ;
}
else {
$quantity += $orderProduct->getQuantityOrder() ;
}
}
}
}

return $quantity ;
}

public function getProductQuantityMaxAddCart($product)
{
$orderShop = $this->getCartCurrent() ;
$productFamily = $product->getProductFamily() ;

$byWeight = false ;
if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
$byWeight = true ;
}

return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight) ;
}
}

+ 1
- 0
ShopBundle/Services/ProductFamilyUtils.php View File

@@ -3,6 +3,7 @@
namespace Lc\ShopBundle\Services ;

use Lc\ShopBundle\Context\PriceUtilsInterface;
use Lc\ShopBundle\Model\ProductFamily;

class ProductFamilyUtils
{

+ 93
- 1
ShopBundle/Services/Utils.php View File

@@ -44,7 +44,8 @@ class Utils
return ($this->isServerLocalhost()) ? null : $this->parameterBag->get('app.cookie_domain_distant') ;
}

function limitText($text, $limit) {
public function limitText($text, $limit) {
$text = strip_tags($text) ;
if (str_word_count($text, 0) > $limit) {
$words = str_word_count($text, 2);
$pos = array_keys($words);
@@ -53,6 +54,97 @@ class Utils
return $text;
}

function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) {
if ($considerHtml) {
// if the plain text is shorter than the maximum length, return the whole text
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
$total_length = strlen($ending);
$open_tags = array();
$truncate = '';
foreach ($lines as $line_matchings) {
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($line_matchings[1])) {
// if it's an "empty element" with or without xhtml-conform closing slash
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
// do nothing
// if tag is a closing tag
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
// delete tag from $open_tags list
$pos = array_search($tag_matchings[1], $open_tags);
if ($pos !== false) {
unset($open_tags[$pos]);
}
// if tag is an opening tag
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
// add tag to the beginning of $open_tags list
array_unshift($open_tags, strtolower($tag_matchings[1]));
}
// add html-tag to $truncate'd text
$truncate .= $line_matchings[1];
}
// calculate the length of the plain text part of the line; handle entities as one character
$content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
if ($total_length+$content_length> $length) {
// the number of characters which are left
$left = $length - $total_length;
$entities_length = 0;
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
foreach ($entities[0] as $entity) {
if ($entity[1]+1-$entities_length <= $left) {
$left--;
$entities_length += strlen($entity[0]);
} else {
// no more characters left
break;
}
}
}
$truncate .= substr($line_matchings[2], 0, $left+$entities_length);
// maximum lenght is reached, so get off the loop
break;
} else {
$truncate .= $line_matchings[2];
$total_length += $content_length;
}
// if the maximum length is reached, get off the loop
if($total_length>= $length) {
break;
}
}
} else {
if (strlen($text) <= $length) {
return $text;
} else {
$truncate = substr($text, 0, $length - strlen($ending));
}
}
// if the words shouldn't be cut in the middle...
if (!$exact) {
// ...search the last occurance of a space...
$spacepos = strrpos($truncate, ' ');
if (isset($spacepos)) {
// ...and cut the text in this position
$truncate = substr($truncate, 0, $spacepos);
}
}
// add the defined ending to the text
$truncate .= $ending;
if($considerHtml) {
// close all unclosed html-tags
foreach ($open_tags as $tag) {
$truncate .= '</' . $tag . '>';
}
}
return $truncate;
}


public function isBot()
{
if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) {

Loading…
Cancel
Save