Browse Source

Frontend : finalisation ajout rapide au panier via modal

master
Guillaume 4 years ago
parent
commit
91d6540f72
3 changed files with 47 additions and 10 deletions
  1. +11
    -4
      ShopBundle/Controller/Frontend/CartController.php
  2. +31
    -1
      ShopBundle/Model/OrderProduct.php
  3. +5
    -5
      ShopBundle/Resources/config/shop_routes.yaml

+ 11
- 4
ShopBundle/Controller/Frontend/CartController.php View File

protected $orderUtils ; protected $orderUtils ;
protected $productFamilyRepository ; protected $productFamilyRepository ;


protected $productFamily ;
protected $orderProducts = [] ;


public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils) public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
{ {
parent::__construct($em, $merchantUtils); parent::__construct($em, $merchantUtils);
$data = $request->request->all() ; $data = $request->request->all() ;
if(isset($data['order_products']['id_product_family'])) { if(isset($data['order_products']['id_product_family'])) {
$idProductFamily = $data['order_products']['id_product_family'] ; $idProductFamily = $data['order_products']['id_product_family'] ;
$productFamily = $this->productFamilyRepository->find($idProductFamily) ;
if($productFamily) {
$form = $this->createForm(OrderProductsType::class, ['id_product_family' => $productFamily->getId()]);
$this->productFamily = $this->productFamilyRepository->find($idProductFamily) ;
if($this->productFamily) {
$form = $this->createForm(OrderProductsType::class, ['id_product_family' => $this->productFamily->getId()]);
$form->handleRequest($request); $form->handleRequest($request);


if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
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->getQuantity() > 0) {
$this->orderProducts[] = $orderProduct ;
}
} }
} }
} }
} }
} }


return new JsonResponse($data) ;
return new JsonResponse($return) ;
} }


public function addProduct() public function addProduct()

+ 31
- 1
ShopBundle/Model/OrderProduct.php View File

{ {
$product = $this->getProduct() ; $product = $this->getProduct() ;
$productFamily = $product->getProductFamily() ; $productFamily = $product->getProductFamily() ;
$titleProduct = $product->getTitle() ;
$titleProduct = $product->getTitleInherited() ;
$titleProductFamily = $productFamily->getTitle() ; $titleProductFamily = $productFamily->getTitle() ;


if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) { if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
return $title ; return $title ;
} }


public function getTitleSummaryAfterAddCart()
{
$title = '' ;

$product = $this->getProduct() ;
$productFamily = $product->getProductFamily() ;
$titleProduct = $product->getTitleInherited() ;
$titleProductFamily = $productFamily->getTitle() ;

// multiple
if($productFamily->getActiveProducts() && $productFamily->getBehaviorAddToCart() == 'multiple') {
$title .= $titleProduct ;
if($productFamily->hasProductsWithVariousWeight()) {
$title .= ' - '.$product->getQuantityLabelInherited() ;
}
}

// simple
if($productFamily->getBehaviorAddToCart() == 'simple') {
if($productFamily->getActiveProducts()) {
$title .= $titleProduct ;
if($productFamily->hasProductsWithVariousWeight()) {
$title .= ' - '.$product->getQuantityLabelInherited() ;
}
}
}

return $title ;
}

public function getOrderShop(): ?OrderShop public function getOrderShop(): ?OrderShop
{ {
return $this->orderShop; return $this->orderShop;

+ 5
- 5
ShopBundle/Resources/config/shop_routes.yaml View File

controller: Lc\ShopBundle\Controller\ApiController::getEntity controller: Lc\ShopBundle\Controller\ApiController::getEntity


lc_frontend_cart_add_product_family: lc_frontend_cart_add_product_family:
path: /cart/add-product-family
path: /lc/cart/add/product-family
controller: Lc\ShopBundle\Controller\Frontend\CartController::addProductFamily controller: Lc\ShopBundle\Controller\Frontend\CartController::addProductFamily


lc_frontend_cart_add_product: lc_frontend_cart_add_product:
path: /cart/add-product
path: /lc/cart/add/product
controller: Lc\ShopBundle\Controller\Frontend\CartController::addProduct controller: Lc\ShopBundle\Controller\Frontend\CartController::addProduct


lc_frontend_cart_edit_product: lc_frontend_cart_edit_product:
path: /cart/edit-product
path: /lc/cart/edit/product
controller: Lc\ShopBundle\Controller\Frontend\CartController::editProduct controller: Lc\ShopBundle\Controller\Frontend\CartController::editProduct


lc_frontend_cart_delete_product: lc_frontend_cart_delete_product:
path: /cart/delete-product
path: /lc/cart/delete/product
controller: Lc\ShopBundle\Controller\Frontend\CartController::deleteProduct controller: Lc\ShopBundle\Controller\Frontend\CartController::deleteProduct


lc_frontend_cart_summary: lc_frontend_cart_summary:
path: /cart/summary
path: /lc/cart/summary
controller: Lc\ShopBundle\Controller\Frontend\CartController::summary controller: Lc\ShopBundle\Controller\Frontend\CartController::summary

Loading…
Cancel
Save