/**
  * Called after the Transaction is stored.
  * Tells the storage service to store all the information held in the ShippingHandler
  * @param \Heystack\Core\Storage\Event $event
  * @return void
  */
 public function onTransactionStored(StorageEvent $event)
 {
     $this->shippingHandler->setParentReference($event->getParentReference());
     $this->storageService->process($this->shippingHandler);
     $this->eventService->dispatch(Events::STORED);
     $this->stateService->removeByKey(ShippingHandler::IDENTIFIER);
 }
 /**
  * After the transaction is stored, store the deal.
  * @param \Heystack\Core\Storage\Event $event
  * @param string $eventName
  * @param \Heystack\Core\EventDispatcher $dispatcher
  * @return void
  */
 public function onTransactionStored(StorageEvent $event, $eventName, EventDispatcher $dispatcher)
 {
     if ($this->dealHandler->getConditionsMetCount() > 0) {
         $this->dealHandler->setParentReference($event->getParentReference());
         $results = $this->storageService->process($this->dealHandler);
         // Store the Coupons associated with the deal
         if (!empty($results[Backend::IDENTIFIER])) {
             $storedDeal = $results[Backend::IDENTIFIER];
             $coupons = $this->couponHolder->getCoupons($this->dealHandler->getIdentifier());
             foreach ($coupons as $coupon) {
                 if ($coupon instanceof CouponInterface) {
                     $coupon->setParentReference($storedDeal->ID);
                     $this->storageService->process($coupon);
                 }
             }
         }
         $this->eventService->dispatch(Events::STORED);
         $this->stateService->removeByKey($this->dealHandler->getIdentifier()->getFull());
     }
 }
 /**
  * Stores the purchasables which are attached to the purchasable holder
  * @param \Heystack\Core\Storage\Event $storageEvent
  * @param string $eventName
  * @param \Heystack\Core\EventDispatcher $dispatcher
  * @return void
  */
 public function onPurchasableHolderStored(StorageEvent $storageEvent, $eventName, EventDispatcher $dispatcher)
 {
     $parentReference = $storageEvent->getParentReference();
     $purchasables = $this->purchasableHolder->getPurchasables();
     if ($purchasables) {
         foreach ($purchasables as $purchaseable) {
             $purchaseable->setParentReference($parentReference);
             $this->storageService->process($purchaseable);
         }
     }
     $this->stateService->removeByKey(PurchasableHolder::IDENTIFIER);
 }