<?php
namespace App\Manager;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Cart;
use App\Service\Mailer;
use App\Manager\CustomerManager;
use App\Manager\CartManager;
use App\Entity\Product;
class PriceManager {
private $em;
private $customerMgr;
private $cartMgr;
private $customer;
private $currentDiscountType = false;
private $currentMarketingRule = false;
// private $rules = [];
public function __construct(EntityManagerInterface $em, CartManager $cartMgr)
{
$this->cartMgr = $cartMgr;
$this->em = $em;
$this->customer = false;
// $this->rules = $this->em->getRepository('App:MarketingRule')->getActiveRules();
}
public function getPrice(Product $product, $qty = 1, $useCart = true, $debug = false) {
$this->customer = $this->cartMgr->getCustomer();
$discountType = "";
$discountAmount = 0;
$discountPercent = "";
$cart = $this->cartMgr->getCart();
$normalPrice = $product->getPrice(false, $cart->getPriceGroup());
$price = $product->getPrice(false, $cart->getPriceGroup());
$ecoTax = $product->getEcotax();
$this->currentMarketingRule = null;
if($this->customer === false){
return $product->getPrice(true, $cart->getPriceGroup());
}
if($this->cartMgr->isExpert()){
return $product->getPrice(true, $cart->getPriceGroup());
}
// if($useCart){
// }else{
// $cart = false;
// }
// remise standard
$tmp = $this->round($normalPrice) - $this->round($this->getStandardDiscount($product, $qty));
if ($tmp < $price) {
$price = $tmp;
$discountType = "standard";
} else {
$this->hasSpecialPrice = false;
}
// $tmp = $this->round($price) - $this->round($this->getSpecialDiscounts($product, $qty));
// if ($tmp < $price) {
// $price = $tmp;
// $discountType = "specialDiscounts";
// }
// $tmp = $this->round($normalPrice) - $this->round($this->getSpecialDiscounts($product, $qty));
// if ($tmp < $price) {
// $price = $tmp;
// $discountType = "SpecialDiscounts";
// }
if ($this->isLockedPrice($product)) {
return $this->round($price);
}
//remise de bienvenue
$tmp = $this->round($normalPrice) - $this->round($this->getWelcomeDiscount($product));
if ($tmp < $price) {
$price = $tmp;
$discountType = "bienvenue";
}
// remise soleil
$tmp = $this->round($normalPrice) - $this->round($this->getSoleilDiscount($product, $useCart));
if ($tmp < $price) {
$price = $tmp;
$discountType = "soleil";
}
//remises dynamiques
$discounts = $this->getDiscountsByProduct($product);
foreach($discounts as $discount){
if($discount->isTypeOffered() && ($discount->getQtyRequested() < $discount->getProductsDiscountedQty($cart))) {
$discountType = $discount->getType();
$this->currentMarketingRule = $discount;
$price = $product->getPrice(true);
}else{
$additonalDiscount = 0;
if($discount->getSkipSoleilDiscount() === false) {
$additonalDiscount = $this->getSoleilDiscount($product);
}
$tmp = $this->round($normalPrice) - $this->round($discount->getProductDiscountByCart($product, $cart, $additonalDiscount));
if ($tmp < $price) {
$price = $tmp;
$discountType = $discount->getType();
$this->currentMarketingRule = $discount;
}
}
}
$this->currentDiscountType = $discountType;
return $this->round($price)+$this->round($ecoTax);
}
public function getStandardDiscount(Product $product) {
$price = $product->getPrice();
$specialPrice = $this->em->getRepository('App:SpecialPrice')->getDiscount($product);
if (!empty($specialPrice)) {
return $price - $specialPrice->getPrice();
}
return 0;
}
public function getSoleilDiscount(Product $product, $useCart = true) {
if ($this->isLockedPrice($product) || !$this->hasSoleilDiscount())
return 0;
$cart = $this->cartMgr->getCart();
$price = $product->getPrice();
$cartTotal = $this->getCartTotal();
$nonSoleilTotal = $cart->getNonSoleilTotal();
$soleilTotal = $cart->getSoleilTotal();
if(!$useCart){ // on ajoute la prix du produit pour obtenir la remise après ajout au panier
$cartTotal += $price;
$nonSoleilTotal += $price;
$soleilTotal += $price;
}
$discount = 0;
if (($product->getSoleil() == 0) && ($nonSoleilTotal > 100)) {
$discount = $product->getPrice(false) * 0.1;
} else if (($product->getSoleil() == 1) && ($soleilTotal > 100)) {
$coef = 0.25;
$discount = $product->getPrice(false) * $coef;
if ($this->hasTVADiscount()) {
$discount += ($product->getPrice(false) - $discount) * 0.2;
}
} else if ($product->getSoleil() == 1) {
if ($this->hasTVADiscount()) {
$discount += ($product->getPrice(false) - $discount) * 0.2;
}
}
return $discount;
}
public function getWelcomeDiscount(Product $product) {
// if ($this->isLockedPrice($product))
// return 0;
// if (!$this->hasCartTotal())
// return 0;
if(!$product->isProduct())
return 0;
$manufacturer = $product->getManufacturer();
if($manufacturer && !$manufacturer->hasWelcomeDiscount()) {
return 0;
}
if (!$product->hasWelcomeDiscount()) {
return 0;
}
if ($this->hasWelcomeDiscount()) {
return $product->getPrice(false) * 0.1;
}
return 0;
}
public function getFidelityDiscount(Product $product) {
if ($this->isLockedPrice($product))
return 0;
$customer = $this->cartMgr->getCustomer();
if($customer) {
if ($customer->hasPlatiniumDiscount()) {
return $product->getPrice() * 0.05;
} else if ($customer->hasEliteDiscount()) {
return $product->getPrice() * 0.1;
}
}
return 0;
}
public function getPalierDiscount(Product $product) {
if ($this->isLockedPrice($product))
return 0;
if ($this->customer && !$this->customer->hasSoleil())
return 0;
if (($product->getSoleil() == 1)) {
if ($this->getCartTotal() >= 2500) {
return $product->getPrice() * 0.30;
} else if ($this->getCartTotal() >= 2000) {
return $product->getPrice() * 0.20;
} else if ($this->getCartTotal() >= 1500) {
return $product->getPrice() * 0.15;
} else if ($this->getCartTotal() >= 1000) {
return $product->getPrice() * 0.10;
} else if ($this->getCartTotal() >= 400) {
return $product->getPrice() * 0.05;
}
// } else {
} else if (($product->getSoleil() == 0)) {
if ($this->getCartTotal() >= 2500) {
return $product->getPrice() * 0.1;
} else if ($this->getCartTotal() >= 2000) {
return $product->getPrice() * 0.05;
}
}
return 0;
}
public function getSpecialDiscounts(Product $product, $qty = 1) {
$from = mktime(0, 0, 0, 11, 1, 2025);
$limit = mktime(23, 59, 59, 12, 15, 2025);
$now = time();
if (($now < $from) || ($now > $limit)) {
return 0;
}
// $refs = ['3006063','3006064','3006067','3006071','3006075','3006345','3006352','3006354','3006411','3006412','3006415','3006419','3006420','3006423','3006427','3006428','3006431','3006435','3006436','3006439','3006443','3006444','3006447','3006451','3006452','3006455','3006731','3006732','3006733','3006734','3006735','3006736','3006737','3006738','3006739','3006740','3006741','3006742','3006743','3006744','3006745','3006746','3006747','3006748','3006749','3006750','3006751','3006752','3006753','3006754','3006360','3006363','3006688','3006689','3006692','3006755','3006756','3006758'];
// if(in_array($product->getModelSAP(), $refs)){
// if($qty>=3){
// return $product->getPrice() * (1-($qty-floor($qty/3))/$qty);
// }
// }
// return 0;
$refs = ['3006063','3006064','3006067','3006071','3006075','3006345','3006352','3006354','3006411','3006412','3006415','3006419','3006420','3006423','3006427','3006428','3006431','3006435','3006436','3006439','3006443','3006444','3006447','3006451','3006452','3006455','3006731','3006732','3006733','3006734','3006735','3006736','3006737','3006738','3006739','3006740','3006741','3006742','3006743','3006744','3006745','3006746','3006747','3006748','3006749','3006750','3006751','3006752','3006753','3006754','3006360','3006363','3006688','3006689','3006692','3006755','3006756','3006758'];
if(in_array($product->getModelSAP(), $refs)){
if($qty>=20){
return $product->getPrice() * 0.3 + $this->getSoleilDiscount($product);
}else if($qty>=15){
return $product->getPrice() * 0.25 + $this->getSoleilDiscount($product);
}else if($qty>=10){
return $product->getPrice() * 0.20 + $this->getSoleilDiscount($product);
}else if($qty>=5){
return $product->getPrice() * 0.15 + $this->getSoleilDiscount($product);
}
}
return 0;
$refs = ['200013', '200014', '200015', '200016', '200017', '200018', '200019', '200020', '200021', '200029', '200033', '200034', '200035', '200040', '200068', '200069', '200070', '200071', '200072', '200073', '200074', '200075', '200076', '200077'];
if(in_array($product->getModel(), $refs)){
return $product->getPrice() * 0.15;
}
$refs = ['22661', '22672', '22668', '22670', '22662', '22663', '22664', '22665', '22666'];
if(in_array($product->getId(), $refs)){
if($qty>=11){
return $product->getPrice() * (1-($qty-1)/$qty);
}
}
$refs = ['22035', '22036', '22037', '22038', '22039', '22635', '22636'];
if(in_array($product->getId(), $refs)){
if($qty>=16){
return $product->getPrice() * (1-($qty-2)/$qty);
}
}
return 0;
}
public function getSpecialDiscountsCart(Product $product, $qty) {
// echo('getSpecialDiscountsCart '. $product->getModel().' '.$qty);
$from = mktime(0, 0, 0, 4, 5, 2023);
$limit = mktime(23, 59, 59, 12, 31, 2023);
$now = time();
if (($now < $from) || ($now > $limit)) {
return 0;
}
$refs = ['13521', '13700.6', '13702.6', '15407R', '15408R', '15409R', '17086', '17091', '17092', '17093', '17094', '17095', '17097', '17126R', '17127R', '17145', '17156V', '17173', '17174', '17175', '17180J', '17181J', '17190B', '17191B', '17195V', '17196V', '18104G', '18105G', '18136', '18413V', '18417B', '18419A', '18420A', '18423A', '18424A', '18426A', '18427A', '18427V', '18428A', '18448.R', '18452.R', '18456.N', '18456.R', '64130', '64131', '75505.1', '75505.4', '75506.1', '75511.8', '75511.9', '75512.1', '75512.9', '75527.1', '75527.5', '75533', '75534', '75535', '75536', '75537', '75539', '75540', '75541', '75542', '75543', '75544', '75549.2', '75550.1', '75550.5', '75550.7', '75551.1', '75551.5', '75552.1', '75554.5', '75555.5', '75562.3', '75562.4', '75597', '75601.3', '75602.3', '75605.3', '75622.6', '75628.2', '75628.3', '75661.2', '75665.1', '75669.1', '75678.2', '75680.2', '75681.1', '75681.2', '75682.1', '75682.2', '75683.1', '75683.2', '75684.1', '75684.2', '75685.1', '75685.2', '75686.1', '75686.2', '75687.1', '75687.2', '75688.1', '75688.2', '75717.1', '75817.2', '75845.1', '75894.1', '75894.2', '75899.1', '75900.1', '75900.2', '75900.3', '75900.4', '75901.1', '75901.2', '75901.3', '75901.4', '75902.2', '75902.4', '75903.2', '75905.1', '75905.2', '75905.3', '75905.4', '75910.1', '75910.2', '75910.3', '75910.4', '75911.3', '75911.4', '75912.1', '75912.2', '75912.3', '75912.4', '75913.1', '75913.2', '75913.3', '75913.4', '75914.1', '75914.3', '75914.4', '75915.2', '75915.3', '75915.4', '75920.1', '75920.3', '75921.1', '75921.3', '75922.1', '75922.3', '75930.1', '75930.2', '75930.3', '75930.4', '75931.2', '75931.3', '75931.4', '75932.1', '75932.2', '75932.3', '75932.4', '75933.1', '75933.2', '75933.3', '75933.4', '75934.1', '75934.2', '75934.3', '75935.1', '75935.2', '75935.3', '75935.4', '76072.2', '76088.1', '76089.1', '76090.1', '76091.1', '76091.2', '76158.1', '76158.2', '76159.1', '76159.2', '76160.2', '76161.1', '76161.2', '77503', '77992.8', '77994.6', '77994.8', '78194', '78443.5', '78444.4', '78444.5', '78445.4', '78445.5', '78445.6', '78445.7', '78445.8', '78448.3', '78458', '78459', '78462', '79144.1', '79640.1', '79645.1', 'D208152', 'D220011', 'D220016', 'D220035', 'D220056', 'D220058', 'D220066', 'D220081', 'D220086', 'D220111', 'D220116', 'D220135', 'D220156', 'D220158', 'D220168', 'D220181', 'D220186', 'D220211', 'D220216', 'D220235', 'D220256', 'D220258', 'D220266', 'D220268', 'D220281', 'D220286', 'D220311', 'D220316', 'D220356', 'D220358', 'D220366', 'D220368', 'D220411', 'D220416', 'D220435', 'D220456', 'D220458', 'D220466', 'D220468', 'D221006', 'D221016', 'D221018', 'D221021', 'D221023', 'D221024', 'D221026', 'D221028', 'D221029', 'D221035', 'D221036', 'D221039', 'D221045', 'D221046', 'D221056', 'D221057', 'D221061', 'D221074', 'D221079', 'D221098', 'D221105', 'D221157', 'D221162', 'D221199', 'D221204', 'D221205', 'D221206', 'D221209', 'D221210', 'MO10357', 'MO10358', 'MO10359', 'MO10365', 'MO10366', 'MO10373', 'MO10380', 'MO10387', 'MO10394', 'MO10395', 'MO10396', 'MO10397', 'MO10398', 'MO10399', 'MO10400', 'MO10401', 'MO10402', 'MO10403', 'MO10404', 'MO10405', 'MO10406', 'MO10407', 'MO10408', 'MO10411', 'MO10412', 'MO10413', 'MO10414', 'MO10419', 'MO10420', 'MO10456', 'MO10464', 'MO10465', 'MO10466', 'MO10467', 'MO10592', 'MO10593', 'MO10685', 'MO10686', 'MO10689', 'MO10692', 'MO10838', 'MO10839', 'MO10841', 'MO10842', 'MO10843', 'MO10844', 'MO10845', 'MO10846', 'MO10847', 'MO10848', 'MO10849', 'MO10850', 'MO10851', 'MO10852', 'MO10853', 'MO10854', 'MO10855', 'MO10856', 'MO10857', 'PP10018', 'PP10028', 'PP10044', 'PP10050', 'PP10056', 'PP10061'];
if(in_array($product->getModel(), $refs)){
return $product->getPrice() * 0.5;
}
$refs = ['76072.2', '76088.1', '76091.1', '76091.2', '76102.2', '76103.2', '76105.2', '76106.2', '76161.1', '76161.2', '76162.1', '76162.2', '76162.3', '76170.1', '76170.2', '76170.3', '76171.1', '76171.2', '76171.3', '76172.2', '76172.3', '76173.3', '76174.2', '76174.3', '76175.2', '76175.3', '76180.1', '76180.2', '76180.3', '76181.1', '76181.2', '76181.3', '76184.1', '76185.1', '76185.2', '76186.1', '76186.2', '76187.1', '76187.2', '76188.1', '76188.2', '76189.1', '76189.2', '76190.1', '76195.1', '76197.2', '76198.1', '76199.2', '76208.1', '76208.2', '76209.1', '76209.2', '76210.2', '76213.2', '76232.1', '76232.2', '76232.3', '76240.1', '76240.2', '76240.3', '76241.1', '76241.2', '76241.3', '76242.1', '76242.2', '76242.3', '76243.1', '76243.2', '76243.3', '76244.2', '76244.3', '76245.3', '76246.3', '76247.1', '76247.2', '76247.3', '76248.1', '76248.2', '76248.3', '76252.2', '76260.1', '76260.2', '76260.3', '76261.1', '76261.2', '76261.3', '76263.2', '76265.2', '76266.2', '76269.2', '76272.2', '76273.1', '76273.2', '76273.3', '76274.1', '76274.2', '76274.3', '76278.2', '76288.1', '76288.2', '76289.1', '76289.2', '76290.1', '76290.2', '76291.1', '76291.2', '76292.1', '76292.2', '76299.1', '76299.2', '76300.1', '76300.2', '76303.1', '76305.1', '76306.1', '76307.1', '76308.1', '76310.1', '76310.2', '76318.1', '76318.2', '76319.1', '76319.2', '76320.1', '76320.2', '76321.1', '76321.2', '76322.1', '76322.2', '76323.1', '76323.2', '76324.1', '76324.2', '76325.1', '76325.2', '76326.1', '76326.2', '76327.1', '76327.2', '76328.1', '76328.2', '76329.1', '76329.2', '78458', '78459', '78462', 'CH10050', 'D208152', 'D400240', 'MO10456', 'MO10464', 'MO10465', 'MO10466', 'MO10467', '15408R', '71045.4', '71045.7', '71045.8', '71045.9', '71046.7', '71200.5', '71201.3', '71201.5', '71203.2', '71203.3', '71208.5', '71209.3', '71209.5', '71210.2', '71211.2', '76066.5', '76066.6', '76066.7', '76067.5', '76067.6', '76067.7', '76068.5', '76068.6', '76068.7', '76069.5', '76069.6', '76069.7', '76070.5', '76070.6', '76070.7', '76071.5', '76071.6', '76071.7'];
if(in_array($product->getModel(), $refs)){
if($qty >= 10){
return $product->getPrice() * 0.5;
}else if($qty >= 5){
return $product->getPrice() * 0.45;
}else if($qty >= 4){
return $product->getPrice() * 0.4;
}else if($qty >= 3){
return $product->getPrice() * 0.35;
}else if($qty >= 2){
return $product->getPrice() * 0.3;
}
}
return 0;
}
public function hasSoleilDiscount() {
if($this->customer) {
return $this->customer->hasSoleil();
}
return true;
}
public function hasWelcomeDiscount() {
$customer = $this->cartMgr->getCustomer();
if(empty($customer) || !$customer->hasBienvenue()) {
return false;
}
$date = date('Y-m-d H:i:s', time() - 365 * 24 * 60 * 60);
$sql = "select count(*) as nb from orders where customers_id = ".$customer->getId()." and date_purchased>'" . $date . "' and (orders_status = 1 OR orders_status = 2 OR orders_status = 3 OR orders_status = 88896)";
$st = $this->em->getConnection()->executeQuery($sql);
$count = $st->fetch();
return $count['nb'] == 0;
}
public function hasTVADiscount() {
//return true;
$start = mktime(10, 0, 0, 9, 27, 2019);
$end = mktime(23, 59, 59, 9, 29, 2019);
$now = time();
return ($now >= $start) && ($now <= $end);
}
public function getCartTotal() {
$cart = $this->cartMgr->getCart();
return $cart->getTotalProducts();
}
protected function round($value) {
return round($value, 2);
}
public function isLockedPrice(Product $product) {
if(!$product->isProduct())
return false;
$manufacturer = $product->getManufacturer();
return $manufacturer && ($manufacturer->getLockedPrice() == 1);
}
public function getPriceInfos(Product $product) {
$price = $this->getPrice($product, 1, true);
$normalPrice = $this->round($product->getPrice(true));
return [
'normal' => $normalPrice,
'price' => $price,
'discountType' => $this->currentDiscountType,
'percent' => $normalPrice > 0 ? number_format(round((($price-$normalPrice)/$normalPrice)*100), 2, ".", "") : ''
];
}
public function getPriceGrid(Product $product) {
$max_qty = 1;
$p_tmp = 0;
$priceLines = array();
$from = 0;
$normalPrice = $this->round($product->getPrice(true));
for ($i = 1; $i <= $max_qty; $i++) {
$p = $this->getPrice($product, $i, false);
if (count($priceLines) > 0) {
$priceLines[count($priceLines) - 1]['to'] = ($i - 1);
}
if ($p_tmp != $p) {
$p_tmp = $p;
$from = $i;
$priceLines[] = array(
'price' => $p,
'normal' => $normalPrice,
'priceFormat' => number_format($p, 2, ".", ""),
'normalFormat' => number_format($normalPrice, 2, ".", ""),
'percent' => number_format(round((($p-$normalPrice)/$normalPrice)*100), 2, ".", ""),
'from' => $from,
'to' => "",
'discountType' => $this->currentDiscountType
);
}
}
return $priceLines;
}
public function updateCartPrice(Cart $cart){
$items = $cart->getItems();
if($this->cartHasOfferedProducts($cart)) {
$this->applyDiscountsToCart($cart);
}
foreach($items as $item){
$price = $this->getPrice($item->getProduct(true, $cart->getPriceGroup()), $item->getQuantity(), true);
$this->setCartItemPrice($item);
}
$this->cartMgr->save($cart);
}
public function setCartItemPrice(\App\Entity\CartItem $item){
if($item->getQuantityOffered() > 0) {
$soleilDiscount = 0;
if($item->getMarketingRule()) {
$soleilDiscount = $item->getMarketingRule()->getSkipSoleilDiscount() === true ? 0 : $this->getSoleilDiscount($item->getProduct(), true);
}
$price = $item->getProduct()->getPrice(true, $item->getCart()->getPriceGroup()) - $this->round($soleilDiscount);
$item->setUnitPrice($price);
$item->setTotalPrice($price * ($item->getQuantity() - $item->getQuantityOffered()));
}else if($this->currentDiscountType != \App\Entity\MarketingRule::TYPE_OFFERED){
$item->setUnitPrice($this->getPrice($item->getProduct(), $item->getQuantity(true), true));
$item->setTotalPrice($this->getPrice($item->getProduct(), $item->getQuantity(), true) * $item->getQuantity());
}else{
$item->setUnitPrice($item->getProduct()->getPrice(true, $item->getCart()->getPriceGroup()));
$item->setTotalPrice($item->getProduct()->getPrice(true, $item->getCart()->getPriceGroup()) * $item->getQuantity());
}/*else{
$item->setUnitPrice($item->getProduct()->getPrice());
$qty = $item->getQuantity();
$qtyOffered = 0;
if($qty >= $this->currentMarketingRule->getQtyRequested()){
$qtyOffered = $this->currentMarketingRule->getQtyOffered() * floor($qty / $this->currentMarketingRule->getQtyRequested());
}
$item->setTotalPrice($item->getProduct()->getPrice() * ($qty - $qtyOffered));
}*/
$item->setMarketingRule($this->currentMarketingRule);
$item->setDiscountType($this->currentDiscountType);
}
protected function getPercent($discount, $normalPrice) {
return round(($discount) / $normalPrice * 100) . "%";
}
public function getDiscountsByProduct(Product $product, $onlyActive = true) {
if($this->cartMgr->isExpert())
return null;
return $this->em->getRepository(\App\Entity\MarketingRule::class)->getByProduct($product, $onlyActive);
}
public function getBestDiscountByProduct(Product $product, $onlyActive = true) {
if($this->cartMgr->isExpert())
return null;
$discounts = $this->em->getRepository(\App\Entity\MarketingRule::class)->getByProduct($product, $onlyActive);
$best = null;
$bestAmount = null;
foreach($discounts as $discount){
$discountAmount = $discount->getProductDiscountByCart($product, null);
if(empty($best) || ($bestAmount<$discountAmount)) {
$best = $discount;
$bestAmount = $discountAmount;
}
}
return empty($best) ? [] : [$best];
}
public function getDiscountsByCart(Cart $cart) {
$products = $cart->getProducts();
return $this->em->getRepository(\App\Entity\MarketingRule::class)->getByProducts($products, true);
}
public function cartHasOfferedProducts(Cart $cart) {
if($this->cartMgr->isExpert())
return false;
$discounts = $this->getDiscountsByCart($cart);
foreach($discounts as $discount) {
if($discount->getType() == \App\Entity\MarketingRule::TYPE_OFFERED) {
return true;
}
}
return false;
}
public function applyDiscountsToCart(Cart $cart) {
$discounts = $this->getDiscountsByCart($cart);
foreach($discounts as $discount) {
if($discount->getType() == \App\Entity\MarketingRule::TYPE_OFFERED) {
$cart->applyDiscount($discount);
}
}
}
public function setPrice(Product $product, $price, \App\Entity\PriceGroup $group) {
$productPrice = $this->em->getRepository(\App\Entity\ProductPrice::class)->findOneBy(
[
'product' => $product,
'group' => $group
]
);
if(empty($productPrice)) {
$productPrice = new \App\Entity\ProductPrice();
$productPrice->setGroup($group);
$productPrice->setProduct($product);
}
$productPrice->setPrice($price);
$this->em->persist($productPrice);
$this->em->flush();
}
public function removePrice(Product $product, \App\Entity\PriceGroup $group) {
$productPrice = $this->em->getRepository(\App\Entity\ProductPrice::class)->findOneBy(
[
'product' => $product,
'group' => $group
]
);
if($productPrice) {
$this->em->remove($productPrice);
$this->em->flush();
}
return true;
}
}