瀏覽代碼

Frontend : finalisation ajout rapide au panier via modal

master
Guillaume 4 年之前
父節點
當前提交
91d6540f72
共有 3 個檔案被更改,包括 47 行新增10 行删除
  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 查看文件

@@ -17,6 +17,10 @@ class CartController extends BaseController
protected $orderUtils ;
protected $productFamilyRepository ;

protected $productFamily ;
protected $orderProducts = [] ;


public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
{
parent::__construct($em, $merchantUtils);
@@ -30,9 +34,9 @@ class CartController extends BaseController
$data = $request->request->all() ;
if(isset($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);

if ($form->isSubmitted() && $form->isValid()) {
@@ -41,13 +45,16 @@ class CartController extends BaseController
foreach($data as $orderProduct) {
if($orderProduct instanceof OrderProductInterface) {
$this->orderUtils->addOrderProduct($orderShop, $orderProduct) ;
if($orderProduct->getQuantity() > 0) {
$this->orderProducts[] = $orderProduct ;
}
}
}
}
}
}

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

public function addProduct()

+ 31
- 1
ShopBundle/Model/OrderProduct.php 查看文件

@@ -47,7 +47,7 @@ abstract class OrderProduct implements PriceInterface
{
$product = $this->getProduct() ;
$productFamily = $product->getProductFamily() ;
$titleProduct = $product->getTitle() ;
$titleProduct = $product->getTitleInherited() ;
$titleProductFamily = $productFamily->getTitle() ;

if(strlen($titleProduct) > 0 && strlen($titleProductFamily) > 0) {
@@ -64,6 +64,36 @@ abstract class OrderProduct implements PriceInterface
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
{
return $this->orderShop;

+ 5
- 5
ShopBundle/Resources/config/shop_routes.yaml 查看文件

@@ -8,21 +8,21 @@ lc_api:
controller: Lc\ShopBundle\Controller\ApiController::getEntity

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

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

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

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

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

Loading…
取消
儲存