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() |
{ | { | ||||
$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; |
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 |