Ejemplo n.º 1
0
 public function process()
 {
     $attachments = array();
     $totalNumberOfKeys = 0;
     $totalPreOrders = 0;
     $keys = array();
     $orderDetails = $this->orderDetails;
     foreach ($orderDetails['orderedItems'] as $item_key => $item) {
         $links = $this->getLinks->links($item, $item_key);
         $codes = array();
         if (!empty($links)) {
             foreach ($links as $link) {
                 $code = \CodesWholesale\Resource\Code::get($link);
                 if ($code->isImage()) {
                     $attachments[] = \CodesWholesale\Util\CodeImageWriter::write($code, 'Cw_Attachments');
                 }
                 if ($code->isPreOrder()) {
                     $totalPreOrders++;
                 }
                 $codes[] = $code;
                 $totalNumberOfKeys++;
             }
             $keys[] = array('item' => $item, 'codes' => $codes);
         }
     }
     $this->sendMail($orderDetails['order'], $attachments, $keys, $totalPreOrders);
     $this->setCompleteStatus($orderDetails['order'], $totalNumberOfKeys);
     $this->cleanAttach($attachments);
 }
Ejemplo n.º 2
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;
 }
        if ($code->isImage()) {
            /**
             * If code is sent as IMAGE, we provide for you an image writer.
             * Image writer will decode base64 data and save it to given directory.
             *
             * Afterwards you can present the code to your customer from $fullPath,
             * which is a direct path to your image.
             *
             *  -------
             *
             * The difference between single order and batch order
             * is that in batch order - binary data for image, is fetched from server as a additional single http request.
             *
             * So, $code->getCode() will make additional request to get binary data.
             */
            $fullPath = \CodesWholesale\Util\CodeImageWriter::write($code, "./codes");
            echo $fullPath . "<br />";
        }
    }
} catch (\CodesWholesale\Resource\ResourceError $e) {
    if ($e->isInvalidToken()) {
        echo "if you are using SessionStorage refresh your session and try one more time.";
    } else {
        // handle scenario when codes details where not found
        if ($e->getStatus() == 404 && $e->getErrorCode() == 60017) {
            // error when codes where not found
            echo $e->getMessage();
        } else {
            // handle scenario when bought product was not found in order
            if ($e->getStatus() == 404 && $e->getErrorCode() == 50022) {
                // error when we receive not real product id