/**
  * @param Request $request
  *
  * @Rest\View(statusCode=204)
  * @Rest\Post("/webhook", defaults={"_format": "json"})
  *
  * @throws ResourceConflictException
  * @throws \Exception
  * @return null
  */
 public function handleWebHookAction(Request $request)
 {
     $this->logger->info($request->getContent());
     try {
         $event = null;
         $store = $this->storeService->getStoreByRequest($request);
         $eventId = $this->shopifyEventRetriever->verifyWebhookRequest($request, $store);
         $event = $this->shopifyEventRetriever->retrieve($eventId);
         if ($event) {
             throw new EventAlreadyProcessed(sprintf('Event Id %s has already been processed', $eventId));
         }
         //Save the event so we don't process this again
         $event = Event::createFromRequest($request, $eventId);
         $this->eventRepository->save($event);
         $cmd = $this->commandFactory->create($event, $store);
         $handler = $this->handlerFactory->create($event);
         $handler->execute($cmd);
         $event->updateStatus(Event::STATUS_PROCESSED);
         $this->logger->alert(sprintf('Completed Processing event id %s', $eventId));
     } catch (\Exception $e) {
         if ($event instanceof Event) {
             $event->updateStatus(Event::STATUS_FAILED);
         }
         $this->logger->alert($e->getMessage());
     } finally {
         if ($event instanceof Event) {
             $this->eventRepository->update($event);
         }
         return new Response('', 201);
     }
 }
 /**
  * @param AMQPMessage $msg The message
  * @return mixed false to reject and requeue, any other value to aknowledge
  */
 public function execute(AMQPMessage $msg)
 {
     $msgBody = json_decode($msg->body);
     $erpOrderId = $msgBody->payload->erpOrderId;
     $shopifyOrderId = $msgBody->payload->shopifyOrderId;
     $storeId = $msgBody->payload->storeId;
     try {
         $store = $this->store->getStore($storeId);
         $order = $this->erpClient->getOrder($store, $erpOrderId);
         $erpShipment = $this->erpClient->getShipment($store, $order);
         $shopifyOrder = $this->shopifyApiClient->getOrder($store, $shopifyOrderId);
         $isShipmentFulfilled = $this->erpShipmentService->isShipmentFulfilled($erpShipment, $shopifyOrder);
         $this->erpShipmentService->setFulfilledItems($erpShipment, $shopifyOrder);
         //Send the order off to be updated
         $this->shopifyApiClient->updateOrCreateFulfillments($store, $shopifyOrder, $erpShipment);
         if ($isShipmentFulfilled) {
             //Send the order off for completion
             $this->shopifyApiClient->completeOrder($store, $shopifyOrder);
         }
     } catch (ErpOrderNotFound $e) {
         return false;
     } catch (ErpShipmentNotFound $e) {
         return false;
     } catch (\Exception $e) {
         return false;
     }
 }
 /**
  * @param AMQPMessage $msg The message
  * @return mixed false to reject and requeue, any other value to aknowledge
  */
 public function execute(AMQPMessage $msg)
 {
     $msgBody = json_decode($msg->body);
     $catalogId = $msgBody->payload->catalog;
     $storeId = $msgBody->payload->storeId;
     $store = $this->store->getStore($storeId);
     $catalog = $this->store->getCatalog($catalogId, $store);
     $productCatalog = $this->erpClient->getProducts($store, $catalog[0], true);
     $this->productCatalog->collectProductsFromShopifyAndImport($catalog[0], $store, $productCatalog);
     $this->productCatalog->createProductsOrUpdate($productCatalog, $store);
     $this->productCatalog->addProductsToCollection($productCatalog, $store);
     $this->productCatalog->checkHandlingFeeProductAndCreateIt($store);
 }