コード例 #1
0
 /**
  * Creates a transaction for contract payments when a payment is added to a
  * contract.
  *
  * @param  Event\EntityEvent $event event carrying information about created
  *                                  entity
  */
 public function createPaymentTransaction(Event\EntityEvent $event)
 {
     $payment = $event->getEntity();
     $order = $event->getOrder();
     if ($payment instanceof Payment && $order->status->code === Statuses::PAYMENT_PENDING && null !== $order->id) {
         $transaction = new Transaction();
         $transaction->records->add($payment);
         $transaction->type = Types::CONTRACT_PAYMENT;
         $this->get('order.transaction.create')->setDbTransaction($event->getTransaction())->create($transaction);
     }
 }
コード例 #2
0
 /**
  * Generate vouchers for any items added to an order that are voucher
  * products.
  *
  * The product ID for the item must be listed in the "product-ids" config
  * element in the "voucher" group.
  *
  * The voucher amount is set to the *list price* of the item, not the net
  * or gross amount.
  *
  * The voucher ID is then set as the personalisation key "voucher_id" on the
  * relevant item.
  *
  * The queries for adding the voucher are added to the same transaction as
  * the item creation queries.
  *
  * @param Order\Event\EntityEvent $event The event object
  */
 public function generateForSales(Order\Event\EntityEvent $event)
 {
     $item = $event->getEntity();
     if (!$item instanceof Order\Entity\Item\Item) {
         return false;
     }
     $isVoucher = $item->getProduct()->getType()->getName() === 'voucher';
     if (false === $isVoucher) {
         $this->_loadProductIDs();
         // Skip if no voucher product IDs are defined in the config
         if (!$this->_voucherProductIDs || empty($this->_voucherProductIDs)) {
             return false;
         }
         if (!in_array($item->productID, $this->_voucherProductIDs)) {
             return false;
         }
     }
     $unit = $item->getUnit();
     $voucher = new Voucher();
     if ($unit && isset($unit->options['currency']) && isset($unit->options['amount'])) {
         $voucher->currencyID = $unit->options['currency'];
         $voucher->amount = $unit->options['amount'];
     } else {
         $voucher->currencyID = $item->order->currencyID;
         $voucher->amount = $item->actualPrice;
     }
     $voucher->id = $this->_idGenerator->generate();
     $voucher->purchasedAsItem = $item;
     if ($item->order->user && !$item->order->user instanceof AnonymousUser) {
         $voucher->authorship->create(new DateTimeImmutable(), $item->order->user->id);
     }
     $this->_create->setTransaction($event->getTransaction());
     $this->_create->create($voucher);
     $item->personalisation->voucher_id = $voucher->id;
 }