コード例 #1
0
 /**
  * @param $observer
  * @return array
  */
 public function extract($observer)
 {
     $item = $observer['item'];
     $codes = $observer['allCodesFromProduct'];
     $numberOfKeysSent = 0;
     $links = json_decode($item['links']);
     $numberOfPreOrders = $item['number_of_preorders'];
     file_put_contents('item.txt', print_r($item, true));
     $preOrdersToRemove = NewKeysExtractorImpl::getIndicesOfPreOrders($links, $codes);
     $newCodes = NewKeysExtractorImpl::getNewCodes($links, $codes);
     $attachments = array();
     $linksToAdd = array();
     foreach ($newCodes as $code) {
         if ($code->isImage()) {
             $attachments[] = \CodesWholesale\Util\CodeImageWriter::write($code, 'Cw_Attachments');
         }
         unset($links[$preOrdersToRemove[0]]);
         unset($preOrdersToRemove[0]);
         $preOrdersToRemove = array_values($preOrdersToRemove);
         $linksToAdd[] = $code->getHref();
         $numberOfKeysSent++;
     }
     $preOrdersLeft = $numberOfPreOrders - $numberOfKeysSent;
     $total = count($links) + 1;
     $keys[] = array('item' => $item, 'codes' => $newCodes, 'preOrdersLeft' => $preOrdersLeft, 'total' => $total, 'linksToAdd' => $linksToAdd, 'links' => $links, 'attachments' => $attachments);
     return $keys;
 }
コード例 #2
0
 public function process()
 {
     $request = file_get_contents('php://input');
     if (empty($request)) {
         die("No request data");
     }
     try {
         $productOrdered = $this->connection->receiveProductOrdered();
         $allCodesFromProduct = \CodesWholesale\Resource\Order::getCodes($productOrdered);
         $orderId = $productOrdered->getOrderId();
         $item = $this->itemRetriever->retrieveItem($orderId);
         $params = array('item' => $item, 'allCodesFromProduct' => $allCodesFromProduct);
         $newKeys = $this->newKeysExtractor->extract($params);
         $this->eventDispatcher->dispatchEvent($newKeys);
     } catch (\Exception $e) {
         die('We found error. Probably this is the result of sending test POSTBACK. If your response status is: 200 OK
          it means that you are successfully connected. Error: ' . $e->getMessage());
     }
 }