|
- <?php
-
- namespace Lc\ShopBundle\Services;
-
- use App\Entity\OrderProductReductionCatalog;
- use App\Entity\OrderShop;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\ShopBundle\Context\DocumentInterface;
- use Lc\ShopBundle\Context\MerchantUtilsInterface;
- use Lc\ShopBundle\Context\OrderPaymentInterface;
- use Lc\ShopBundle\Context\OrderReductionCartInterface;
- use Lc\ShopBundle\Context\OrderProductInterface;
- use Lc\ShopBundle\Context\OrderReductionCreditInterface;
- use Lc\ShopBundle\Context\OrderShopInterface;
- use Lc\ShopBundle\Context\OrderStatusHistoryInterface;
- use Lc\ShopBundle\Context\OrderStatusInterface;
- use Lc\ShopBundle\Context\ProductFamilyUtilsInterface;
- use Lc\ShopBundle\Context\ReductionCartInterface;
- use Lc\ShopBundle\Context\ReductionCreditInterface;
- use Lc\ShopBundle\Context\UserInterface;
- use Lc\ShopBundle\Model\Document;
- use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- use Symfony\Component\Security\Core\Security;
-
- trait OrderUtilsReductionTrait
- {
- public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2)
- {
- return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2)
- || ($orderProductReductionCatalog1
- && $orderProductReductionCatalog2
- && $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit()
- && (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue()
- && $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ;
- }
-
-
- public function getSummaryOrderProductReductionCatalog($orderProductReductionCatalog)
- {
- $text = '';
-
- if ($orderProductReductionCatalog) {
- if ($orderProductReductionCatalog->getUnit() == 'amount') {
- $text .= '- ' . $orderProductReductionCatalog->getValue() . ' €';
- }
-
- if ($orderProductReductionCatalog->getUnit() == 'percent') {
- $text .= '- ' . $orderProductReductionCatalog->getValue() . ' %';
- }
- }
-
- return $text;
- }
-
-
- public function createOrderReductionCart(OrderShopInterface $orderShop, ReductionCartInterface $reductionCart)
- {
- $orderReductionCartClass = $this->em->getClassMetadata(OrderReductionCartInterface::class);
- $orderReductionCart = new $orderReductionCartClass->name;
-
- $orderReductionCart->setOrderShop($orderShop);
- $orderReductionCart->setReductionCart($reductionCart);
-
- $orderReductionCart->setTitle($reductionCart->getTitle());
- $orderReductionCart->setValue($reductionCart->getValue());
- $orderReductionCart->setUnit($reductionCart->getUnit());
- $orderReductionCart->setBehaviorTaxRate($reductionCart->getBehaviorTaxRate());
- $orderReductionCart->setFreeShipping($reductionCart->getFreeShipping());
- $orderReductionCart->setAppliedTo($reductionCart->getAppliedTo());
- $orderReductionCart->setType($reductionCart->getType());
-
- $this->em->persist($orderReductionCart) ;
- $this->em->flush() ;
-
- return $orderReductionCart;
- }
-
- public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){
-
- if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser())>0){
- return false;
- }else{
- return true;
- }
- }
-
- public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit)
- {
- $orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class);
- $orderReductionCredit = new $orderReductionCreditClass->name;
-
- $orderReductionCredit->setOrderShop($orderShop);
- $orderReductionCredit->setReductionCredit($reductionCredit);
-
- $orderReductionCredit->setTitle($reductionCredit->getTitle());
- $orderReductionCredit->setValue($reductionCredit->getValue());
- $orderReductionCredit->setUnit($reductionCredit->getUnit());
- $orderReductionCredit->setBehaviorTaxRate($reductionCredit->getBehaviorTaxRate());
-
- return $orderReductionCredit;
- }
-
-
-
-
-
-
- }
|