Beispiel #1
0
 /**
  * Get order coupon Objects
  *
  * @param OrderInterface $order Order
  *
  * @return Collection Coupons
  */
 public function getCoupons(OrderInterface $order)
 {
     $orderCoupons = $this->orderCouponRepository->createQueryBuilder('oc')->select(['o', 'oc'])->innerJoin('oc.coupon', 'c')->where('oc.order = :order')->setParameter('order', $order)->getQuery()->getResult();
     $coupons = array_map(function (OrderCouponInterface $orderCoupon) {
         return $orderCoupon->getCoupon();
     }, $orderCoupons);
     return new ArrayCollection($coupons);
 }
 /**
  * Purge existing OrderCoupons
  *
  * @param OrderInterface $order Order where to delete all coupons
  *
  * @return $this Self object
  */
 public function truncateOrderCoupons(OrderInterface $order)
 {
     $orderCoupons = $this->orderCouponRepository->findOrderCouponsByOrder($order);
     if ($orderCoupons instanceof Collection) {
         foreach ($orderCoupons as $orderCoupon) {
             $this->orderCouponObjectManager->remove($orderCoupon);
         }
         $this->orderCouponObjectManager->flush($orderCoupons->toArray());
     }
     return $this;
 }