Пример #1
0
 /**
  * @covers \Magento\Framework\Stdlib\String::split
  */
 public function testStrSplit()
 {
     $this->assertEquals(array(), $this->_string->split(''));
     $this->assertEquals(array('1', '2', '3', '4'), $this->_string->split('1234', 1));
     $this->assertEquals(array('1', '2', ' ', '3', '4'), $this->_string->split('12 34', 1, false, true));
     $this->assertEquals(array('12345', '123', '12345', '6789'), $this->_string->split('12345  123    123456789', 5, true, true));
 }
Пример #2
0
 /**
  * Draw item line
  *
  * @return void
  */
 public function draw()
 {
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = array();
     // draw Product name
     $lines[0] = array(array('text' => $this->string->split($item->getName(), 60, true, true), 'feed' => 100));
     // draw QTY
     $lines[0][] = array('text' => $item->getQty() * 1, 'feed' => 35);
     // draw SKU
     $lines[0][] = array('text' => $this->string->split($this->getSku($item), 25), 'feed' => 565, 'align' => 'right');
     // Custom options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = array('text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true), 'font' => 'italic', 'feed' => 110);
             // draw options value
             if ($option['value']) {
                 $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
                 $values = explode(', ', $printValue);
                 foreach ($values as $value) {
                     $lines[][] = array('text' => $this->string->split($value, 50, true, true), 'feed' => 115);
                 }
             }
         }
     }
     $lineBlock = array('lines' => $lines, 'height' => 20);
     $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
     $this->setPage($page);
 }
Пример #3
0
 /**
  * Draw item line
  *
  * @return void
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = [];
     // draw Product name
     $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
     // draw SKU
     $lines[0][] = ['text' => $this->string->split($this->getSku($item), 17), 'feed' => 290, 'align' => 'right'];
     // draw QTY
     $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 435, 'align' => 'right'];
     // draw item Prices
     $i = 0;
     $prices = $this->getItemPricesForDisplay();
     $feedPrice = 395;
     $feedSubtotal = $feedPrice + 170;
     foreach ($prices as $priceData) {
         if (isset($priceData['label'])) {
             // draw Price label
             $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
             // draw Subtotal label
             $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
             $i++;
         }
         // draw Price
         $lines[$i][] = ['text' => $priceData['price'], 'feed' => $feedPrice, 'font' => 'bold', 'align' => 'right'];
         // draw Subtotal
         $lines[$i][] = ['text' => $priceData['subtotal'], 'feed' => $feedSubtotal, 'font' => 'bold', 'align' => 'right'];
         $i++;
     }
     // draw Tax
     $lines[0][] = ['text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right'];
     // custom options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = ['text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => 35];
             if ($option['value']) {
                 if (isset($option['print_value'])) {
                     $printValue = $option['print_value'];
                 } else {
                     $printValue = $this->filterManager->stripTags($option['value']);
                 }
                 $values = explode(', ', $printValue);
                 foreach ($values as $value) {
                     $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
                 }
             }
         }
     }
     $lineBlock = ['lines' => $lines, 'height' => 20];
     $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
     $this->setPage($page);
 }
Пример #4
0
 /**
  * Draw item line
  *
  * @return void
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = array();
     // draw Product name
     $lines[0] = array(array('text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35));
     // draw SKU
     $lines[0][] = array('text' => $this->string->split($this->getSku($item), 17), 'feed' => 255, 'align' => 'right');
     // draw Total (ex)
     $lines[0][] = array('text' => $order->formatPriceTxt($item->getRowTotal()), 'feed' => 330, 'font' => 'bold', 'align' => 'right');
     // draw Discount
     $lines[0][] = array('text' => $order->formatPriceTxt(-$item->getDiscountAmount()), 'feed' => 380, 'font' => 'bold', 'align' => 'right');
     // draw QTY
     $lines[0][] = array('text' => $item->getQty() * 1, 'feed' => 445, 'font' => 'bold', 'align' => 'right');
     // draw Tax
     $lines[0][] = array('text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right');
     // draw Total (inc)
     $subtotal = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount() - $item->getDiscountAmount();
     $lines[0][] = array('text' => $order->formatPriceTxt($subtotal), 'feed' => 565, 'font' => 'bold', 'align' => 'right');
     // draw options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = array('text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => 35);
             // draw options value
             $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
             $lines[][] = array('text' => $this->string->split($printValue, 30, true, true), 'feed' => 40);
         }
     }
     // downloadable Items
     $purchasedItems = $this->getLinks()->getPurchasedItems();
     // draw Links title
     $lines[][] = array('text' => $this->string->split($this->getLinksTitle(), 70, true, true), 'font' => 'italic', 'feed' => 35);
     // draw Links
     foreach ($purchasedItems as $link) {
         $lines[][] = array('text' => $this->string->split($link->getLinkTitle(), 50, true, true), 'feed' => 40);
     }
     $lineBlock = array('lines' => $lines, 'height' => 20);
     $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
     $this->setPage($page);
 }
Пример #5
0
 /**
  * @covers \Magento\Framework\Stdlib\String::split
  */
 public function testStrSplit()
 {
     $this->assertEquals([], $this->_string->split(''));
     $this->assertEquals(['1', '2', '3', '4'], $this->_string->split('1234', 1));
     $this->assertEquals(['1', '2', ' ', '3', '4'], $this->_string->split('12 34', 1, false, true));
     $this->assertEquals(['12345', '123', '12345', '6789'], $this->_string->split('12345  123    123456789', 5, true, true));
     $this->assertEquals(['1234', '5', '123', '1234', '5678', '9'], $this->_string->split('12345  123    123456789', 4, true, true));
 }
Пример #6
0
 /**
  * Draw process
  *
  * @return void
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = [];
     // draw Product name
     $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
     // draw SKU
     $lines[0][] = ['text' => $this->string->split($this->getSku($item), 17), 'feed' => 255, 'align' => 'right'];
     // draw Total (ex)
     $lines[0][] = ['text' => $order->formatPriceTxt($item->getRowTotal()), 'feed' => 330, 'font' => 'bold', 'align' => 'right'];
     // draw Discount
     $lines[0][] = ['text' => $order->formatPriceTxt(-$item->getDiscountAmount()), 'feed' => 380, 'font' => 'bold', 'align' => 'right'];
     // draw QTY
     $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 445, 'font' => 'bold', 'align' => 'right'];
     // draw Tax
     $lines[0][] = ['text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right'];
     // draw Total (inc)
     $subtotal = $item->getRowTotal() + $item->getTaxAmount() + $item->getDiscountTaxCompensationAmount() - $item->getDiscountAmount();
     $lines[0][] = ['text' => $order->formatPriceTxt($subtotal), 'feed' => 565, 'font' => 'bold', 'align' => 'right'];
     // draw options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = ['text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => 35];
             // draw options value
             $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
             $lines[][] = ['text' => $this->string->split($printValue, 30, true, true), 'feed' => 40];
         }
     }
     $lineBlock = ['lines' => $lines, 'height' => 20];
     $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
     $this->setPage($page);
 }
Пример #7
0
 /**
  * Do rate request and handle errors
  *
  * @return Result|\Magento\Framework\Object
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _doRequest()
 {
     $rawRequest = $this->_request;
     $originRegion = $this->getCountryParams($this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_COUNTRY_ID, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $this->getStore()))->getRegion();
     if (!$originRegion) {
         throw new \Magento\Framework\Model\Exception(__('Wrong Region'));
     }
     if ($originRegion == 'AM') {
         $originRegion = '';
     }
     $xmlStr = '<?xml version="1.0" encoding="UTF-8"?>' . '<req:ShipmentValidateRequest' . $originRegion . ' xmlns:req="http://www.dhl.com"' . ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' . ' xsi:schemaLocation="http://www.dhl.com ship-val-req' . ($originRegion ? '_' . $originRegion : '') . '.xsd" />';
     $xml = $this->_xmlElFactory->create(array('data' => $xmlStr));
     $nodeRequest = $xml->addChild('Request', '', '');
     $nodeServiceHeader = $nodeRequest->addChild('ServiceHeader');
     $nodeServiceHeader->addChild('SiteID', (string) $this->getConfigData('id'));
     $nodeServiceHeader->addChild('Password', (string) $this->getConfigData('password'));
     if (!$originRegion) {
         $xml->addChild('RequestedPickupTime', 'N', '');
     }
     $xml->addChild('NewShipper', 'N', '');
     $xml->addChild('LanguageCode', 'EN', '');
     $xml->addChild('PiecesEnabled', 'Y', '');
     /** Billing */
     $nodeBilling = $xml->addChild('Billing', '', '');
     $nodeBilling->addChild('ShipperAccountNumber', (string) $this->getConfigData('account'));
     /**
      * Method of Payment:
      * S (Shipper)
      * R (Receiver)
      * T (Third Party)
      */
     $nodeBilling->addChild('ShippingPaymentType', 'S');
     /**
      * Shipment bill to account – required if Shipping PaymentType is other than 'S'
      */
     $nodeBilling->addChild('BillingAccountNumber', (string) $this->getConfigData('account'));
     $nodeBilling->addChild('DutyPaymentType', 'S');
     $nodeBilling->addChild('DutyAccountNumber', (string) $this->getConfigData('account'));
     /** Receiver */
     $nodeConsignee = $xml->addChild('Consignee', '', '');
     $companyName = $rawRequest->getRecipientContactCompanyName() ? $rawRequest->getRecipientContactCompanyName() : $rawRequest->getRecipientContactPersonName();
     $nodeConsignee->addChild('CompanyName', substr($companyName, 0, 35));
     $address = $rawRequest->getRecipientAddressStreet1() . ' ' . $rawRequest->getRecipientAddressStreet2();
     $address = $this->string->split($address, 35, false, true);
     if (is_array($address)) {
         foreach ($address as $addressLine) {
             $nodeConsignee->addChild('AddressLine', $addressLine);
         }
     } else {
         $nodeConsignee->addChild('AddressLine', $address);
     }
     $nodeConsignee->addChild('City', $rawRequest->getRecipientAddressCity());
     $nodeConsignee->addChild('Division', $rawRequest->getRecipientAddressStateOrProvinceCode());
     $nodeConsignee->addChild('PostalCode', $rawRequest->getRecipientAddressPostalCode());
     $nodeConsignee->addChild('CountryCode', $rawRequest->getRecipientAddressCountryCode());
     $nodeConsignee->addChild('CountryName', $this->getCountryParams($rawRequest->getRecipientAddressCountryCode())->getName());
     $nodeContact = $nodeConsignee->addChild('Contact');
     $nodeContact->addChild('PersonName', substr($rawRequest->getRecipientContactPersonName(), 0, 34));
     $nodeContact->addChild('PhoneNumber', substr($rawRequest->getRecipientContactPhoneNumber(), 0, 24));
     /**
      * Commodity
      * The CommodityCode element contains commodity code for shipment contents. Its
      * value should lie in between 1 to 9999.This field is mandatory.
      */
     $nodeCommodity = $xml->addChild('Commodity', '', '');
     $nodeCommodity->addChild('CommodityCode', '1');
     $this->_checkDomesticStatus($rawRequest->getShipperAddressCountryCode(), $rawRequest->getRecipientAddressCountryCode());
     /** Dutiable */
     if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC && !$this->_isDomestic) {
         $nodeDutiable = $xml->addChild('Dutiable', '', '');
         $nodeDutiable->addChild('DeclaredValue', sprintf("%.2F", $rawRequest->getOrderShipment()->getOrder()->getSubtotal()));
         $baseCurrencyCode = $this->_storeManager->getWebsite($rawRequest->getWebsiteId())->getBaseCurrencyCode();
         $nodeDutiable->addChild('DeclaredCurrency', $baseCurrencyCode);
     }
     /**
      * Reference
      * This element identifies the reference information. It is an optional field in the
      * shipment validation request. Only the first reference will be taken currently.
      */
     $nodeReference = $xml->addChild('Reference', '', '');
     $nodeReference->addChild('ReferenceID', 'shipment reference');
     $nodeReference->addChild('ReferenceType', 'St');
     /** Shipment Details */
     $this->_shipmentDetails($xml, $rawRequest, $originRegion);
     /** Shipper */
     $nodeShipper = $xml->addChild('Shipper', '', '');
     $nodeShipper->addChild('ShipperID', (string) $this->getConfigData('account'));
     $nodeShipper->addChild('CompanyName', $rawRequest->getShipperContactCompanyName());
     $nodeShipper->addChild('RegisteredAccount', (string) $this->getConfigData('account'));
     $address = $rawRequest->getShipperAddressStreet1() . ' ' . $rawRequest->getShipperAddressStreet2();
     $address = $this->string->split($address, 35, false, true);
     if (is_array($address)) {
         foreach ($address as $addressLine) {
             $nodeShipper->addChild('AddressLine', $addressLine);
         }
     } else {
         $nodeShipper->addChild('AddressLine', $address);
     }
     $nodeShipper->addChild('City', $rawRequest->getShipperAddressCity());
     $nodeShipper->addChild('Division', $rawRequest->getShipperAddressStateOrProvinceCode());
     $nodeShipper->addChild('PostalCode', $rawRequest->getShipperAddressPostalCode());
     $nodeShipper->addChild('CountryCode', $rawRequest->getShipperAddressCountryCode());
     $nodeShipper->addChild('CountryName', $this->getCountryParams($rawRequest->getShipperAddressCountryCode())->getName());
     $nodeContact = $nodeShipper->addChild('Contact', '', '');
     $nodeContact->addChild('PersonName', substr($rawRequest->getShipperContactPersonName(), 0, 34));
     $nodeContact->addChild('PhoneNumber', substr($rawRequest->getShipperContactPhoneNumber(), 0, 24));
     $xml->addChild('LabelImageFormat', 'PDF', '');
     $request = $xml->asXML();
     if (!$request && !mb_detect_encoding($request) == 'UTF-8') {
         $request = utf8_encode($request);
     }
     $responseBody = $this->_getCachedQuotes($request);
     if ($responseBody === null) {
         $debugData = array('request' => $request);
         try {
             $client = $this->_httpClientFactory->create();
             $client->setUri((string) $this->getConfigData('gateway_url'));
             $client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
             $client->setRawData($request);
             $responseBody = $client->request(\Magento\Framework\HTTP\ZendClient::POST)->getBody();
             $responseBody = utf8_decode($responseBody);
             $debugData['result'] = $responseBody;
             $this->_setCachedQuotes($request, $responseBody);
         } catch (\Exception $e) {
             $this->_errors[$e->getCode()] = $e->getMessage();
             $responseBody = '';
         }
         $this->_debug($debugData);
     }
     $this->_isShippingLabelFlag = true;
     return $this->_parseResponse($responseBody);
 }
Пример #8
0
 /**
  * Draw item line
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $this->_setFontRegular();
     $items = $this->getChilds($item);
     $prevOptionId = '';
     $drawItems = [];
     foreach ($items as $childItem) {
         $line = [];
         $attributes = $this->getSelectionAttributes($childItem);
         if (is_array($attributes)) {
             $optionId = $attributes['option_id'];
         } else {
             $optionId = 0;
         }
         if (!isset($drawItems[$optionId])) {
             $drawItems[$optionId] = ['lines' => [], 'height' => 15];
         }
         if ($childItem->getOrderItem()->getParentItem()) {
             if ($prevOptionId != $attributes['option_id']) {
                 $line[0] = ['font' => 'italic', 'text' => $this->string->split($attributes['option_label'], 45, true, true), 'feed' => 35];
                 $drawItems[$optionId] = ['lines' => [$line], 'height' => 15];
                 $line = [];
                 $prevOptionId = $attributes['option_id'];
             }
         }
         /* in case Product name is longer than 80 chars - it is written in a few lines */
         if ($childItem->getOrderItem()->getParentItem()) {
             $feed = 40;
             $name = $this->getValueHtml($childItem);
         } else {
             $feed = 35;
             $name = $childItem->getName();
         }
         $line[] = ['text' => $this->string->split($name, 35, true, true), 'feed' => $feed];
         // draw SKUs
         if (!$childItem->getOrderItem()->getParentItem()) {
             $text = [];
             foreach ($this->string->split($item->getSku(), 17) as $part) {
                 $text[] = $part;
             }
             $line[] = ['text' => $text, 'feed' => 255];
         }
         // draw prices
         if ($this->canShowPriceInfo($childItem)) {
             $price = $order->formatPriceTxt($childItem->getPrice());
             $line[] = ['text' => $price, 'feed' => 395, 'font' => 'bold', 'align' => 'right'];
             $line[] = ['text' => $childItem->getQty() * 1, 'feed' => 435, 'font' => 'bold'];
             $tax = $order->formatPriceTxt($childItem->getTaxAmount());
             $line[] = ['text' => $tax, 'feed' => 495, 'font' => 'bold', 'align' => 'right'];
             $row_total = $order->formatPriceTxt($childItem->getRowTotal());
             $line[] = ['text' => $row_total, 'feed' => 565, 'font' => 'bold', 'align' => 'right'];
         }
         $drawItems[$optionId]['lines'][] = $line;
     }
     // custom options
     $options = $item->getOrderItem()->getProductOptions();
     if ($options) {
         if (isset($options['options'])) {
             foreach ($options['options'] as $option) {
                 $lines = [];
                 $lines[][] = ['text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => 35];
                 if ($option['value']) {
                     $text = [];
                     $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
                     $values = explode(', ', $printValue);
                     foreach ($values as $value) {
                         foreach ($this->string->split($value, 30, true, true) as $subValue) {
                             $text[] = $subValue;
                         }
                     }
                     $lines[][] = ['text' => $text, 'feed' => 40];
                 }
                 $drawItems[] = ['lines' => $lines, 'height' => 15];
             }
         }
     }
     $page = $pdf->drawLineBlocks($page, $drawItems, ['table_header' => true]);
     $this->setPage($page);
 }
Пример #9
0
 /**
  * Insert order to pdf page
  *
  * @param \Zend_Pdf_Page &$page
  * @param \Magento\Sales\Model\Order $obj
  * @param bool $putOrderId
  * @return void
  */
 protected function insertOrder(&$page, $obj, $putOrderId = true)
 {
     if ($obj instanceof \Magento\Sales\Model\Order) {
         $shipment = null;
         $order = $obj;
     } elseif ($obj instanceof \Magento\Sales\Model\Order\Shipment) {
         $shipment = $obj;
         $order = $shipment->getOrder();
     }
     $this->y = $this->y ? $this->y : 815;
     $top = $this->y;
     $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0.45));
     $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.45));
     $page->drawRectangle(25, $top, 570, $top - 55);
     $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1));
     $this->setDocHeaderCoordinates(array(25, $top, 570, $top - 55));
     $this->_setFontRegular($page, 10);
     if ($putOrderId) {
         $page->drawText(__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8');
     }
     $page->drawText(__('Order Date: ') . $this->_localeDate->formatDate($order->getCreatedAtStoreDate(), 'medium', false), 35, $top -= 15, 'UTF-8');
     $top -= 10;
     $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
     $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
     $page->setLineWidth(0.5);
     $page->drawRectangle(25, $top, 275, $top - 25);
     $page->drawRectangle(275, $top, 570, $top - 25);
     /* Calculate blocks info */
     /* Billing Address */
     $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf'));
     /* Payment */
     $paymentInfo = $this->_paymentData->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf();
     $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES);
     $payment = explode('{{pdf_row_separator}}', $paymentInfo);
     foreach ($payment as $key => $value) {
         if (strip_tags(trim($value)) == '') {
             unset($payment[$key]);
         }
     }
     reset($payment);
     /* Shipping Address and Method */
     if (!$order->getIsVirtual()) {
         /* Shipping Address */
         $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf'));
         $shippingMethod = $order->getShippingDescription();
     }
     $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
     $this->_setFontBold($page, 12);
     $page->drawText(__('Sold to:'), 35, $top - 15, 'UTF-8');
     if (!$order->getIsVirtual()) {
         $page->drawText(__('Ship to:'), 285, $top - 15, 'UTF-8');
     } else {
         $page->drawText(__('Payment Method:'), 285, $top - 15, 'UTF-8');
     }
     $addressesHeight = $this->_calcAddressHeight($billingAddress);
     if (isset($shippingAddress)) {
         $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress));
     }
     $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1));
     $page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight);
     $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
     $this->_setFontRegular($page, 10);
     $this->y = $top - 40;
     $addressesStartY = $this->y;
     foreach ($billingAddress as $value) {
         if ($value !== '') {
             $text = array();
             foreach ($this->string->split($value, 45, true, true) as $_value) {
                 $text[] = $_value;
             }
             foreach ($text as $part) {
                 $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8');
                 $this->y -= 15;
             }
         }
     }
     $addressesEndY = $this->y;
     if (!$order->getIsVirtual()) {
         $this->y = $addressesStartY;
         foreach ($shippingAddress as $value) {
             if ($value !== '') {
                 $text = array();
                 foreach ($this->string->split($value, 45, true, true) as $_value) {
                     $text[] = $_value;
                 }
                 foreach ($text as $part) {
                     $page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8');
                     $this->y -= 15;
                 }
             }
         }
         $addressesEndY = min($addressesEndY, $this->y);
         $this->y = $addressesEndY;
         $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
         $page->setLineWidth(0.5);
         $page->drawRectangle(25, $this->y, 275, $this->y - 25);
         $page->drawRectangle(275, $this->y, 570, $this->y - 25);
         $this->y -= 15;
         $this->_setFontBold($page, 12);
         $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
         $page->drawText(__('Payment Method'), 35, $this->y, 'UTF-8');
         $page->drawText(__('Shipping Method:'), 285, $this->y, 'UTF-8');
         $this->y -= 10;
         $page->setFillColor(new \Zend_Pdf_Color_GrayScale(1));
         $this->_setFontRegular($page, 10);
         $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
         $paymentLeft = 35;
         $yPayments = $this->y - 15;
     } else {
         $yPayments = $addressesStartY;
         $paymentLeft = 285;
     }
     foreach ($payment as $value) {
         if (trim($value) != '') {
             //Printing "Payment Method" lines
             $value = preg_replace('/<br[^>]*>/i', "\n", $value);
             foreach ($this->string->split($value, 45, true, true) as $_value) {
                 $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8');
                 $yPayments -= 15;
             }
         }
     }
     if ($order->getIsVirtual()) {
         // replacement of Shipments-Payments rectangle block
         $yPayments = min($addressesEndY, $yPayments);
         $page->drawLine(25, $top - 25, 25, $yPayments);
         $page->drawLine(570, $top - 25, 570, $yPayments);
         $page->drawLine(25, $yPayments, 570, $yPayments);
         $this->y = $yPayments - 15;
     } else {
         $topMargin = 15;
         $methodStartY = $this->y;
         $this->y -= 15;
         foreach ($this->string->split($shippingMethod, 45, true, true) as $_value) {
             $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8');
             $this->y -= 15;
         }
         $yShipments = $this->y;
         $totalShippingChargesText = "(" . __('Total Shipping Charges') . " " . $order->formatPriceTxt($order->getShippingAmount()) . ")";
         $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
         $yShipments -= $topMargin + 10;
         $tracks = array();
         if ($shipment) {
             $tracks = $shipment->getAllTracks();
         }
         if (count($tracks)) {
             $page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
             $page->setLineWidth(0.5);
             $page->drawRectangle(285, $yShipments, 510, $yShipments - 10);
             $page->drawLine(400, $yShipments, 400, $yShipments - 10);
             //$page->drawLine(510, $yShipments, 510, $yShipments - 10);
             $this->_setFontRegular($page, 9);
             $page->setFillColor(new \Zend_Pdf_Color_GrayScale(0));
             //$page->drawText(__('Carrier'), 290, $yShipments - 7 , 'UTF-8');
             $page->drawText(__('Title'), 290, $yShipments - 7, 'UTF-8');
             $page->drawText(__('Number'), 410, $yShipments - 7, 'UTF-8');
             $yShipments -= 20;
             $this->_setFontRegular($page, 8);
             foreach ($tracks as $track) {
                 $maxTitleLen = 45;
                 $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : '';
                 $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle;
                 $page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8');
                 $page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8');
                 $yShipments -= $topMargin - 5;
             }
         } else {
             $yShipments -= $topMargin - 5;
         }
         $currentY = min($yPayments, $yShipments);
         // replacement of Shipments-Payments rectangle block
         $page->drawLine(25, $methodStartY, 25, $currentY);
         //left
         $page->drawLine(25, $currentY, 570, $currentY);
         //bottom
         $page->drawLine(570, $currentY, 570, $methodStartY);
         //right
         $this->y = $currentY;
         $this->y -= 15;
     }
 }
Пример #10
0
 /**
  * Draw item line
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $items = $this->getChilds($item);
     $prevOptionId = '';
     $drawItems = [];
     $leftBound = 35;
     $rightBound = 565;
     foreach ($items as $childItem) {
         $x = $leftBound;
         $line = [];
         $attributes = $this->getSelectionAttributes($childItem);
         if (is_array($attributes)) {
             $optionId = $attributes['option_id'];
         } else {
             $optionId = 0;
         }
         if (!isset($drawItems[$optionId])) {
             $drawItems[$optionId] = ['lines' => [], 'height' => 15];
         }
         // draw selection attributes
         if ($childItem->getOrderItem()->getParentItem()) {
             if ($prevOptionId != $attributes['option_id']) {
                 $line[0] = ['font' => 'italic', 'text' => $this->string->split($attributes['option_label'], 38, true, true), 'feed' => $x];
                 $drawItems[$optionId] = ['lines' => [$line], 'height' => 15];
                 $line = [];
                 $prevOptionId = $attributes['option_id'];
             }
         }
         // draw product titles
         if ($childItem->getOrderItem()->getParentItem()) {
             $feed = $x + 5;
             $name = $this->getValueHtml($childItem);
         } else {
             $feed = $x;
             $name = $childItem->getName();
         }
         $line[] = ['text' => $this->string->split($name, 35, true, true), 'feed' => $feed];
         $x += 220;
         // draw SKUs
         if (!$childItem->getOrderItem()->getParentItem()) {
             $text = [];
             foreach ($this->string->split($item->getSku(), 17) as $part) {
                 $text[] = $part;
             }
             $line[] = ['text' => $text, 'feed' => $x];
         }
         $x += 100;
         // draw prices
         if ($this->canShowPriceInfo($childItem)) {
             // draw Total(ex)
             $text = $order->formatPriceTxt($childItem->getRowTotal());
             $line[] = ['text' => $text, 'feed' => $x, 'font' => 'bold', 'align' => 'right', 'width' => 50];
             $x += 50;
             // draw Discount
             $text = $order->formatPriceTxt(-$childItem->getDiscountAmount());
             $line[] = ['text' => $text, 'feed' => $x, 'font' => 'bold', 'align' => 'right', 'width' => 50];
             $x += 50;
             // draw QTY
             $text = $childItem->getQty() * 1;
             $line[] = ['text' => $childItem->getQty() * 1, 'feed' => $x, 'font' => 'bold', 'align' => 'center', 'width' => 30];
             $x += 30;
             // draw Tax
             $text = $order->formatPriceTxt($childItem->getTaxAmount());
             $line[] = ['text' => $text, 'feed' => $x, 'font' => 'bold', 'align' => 'right', 'width' => 45];
             $x += 45;
             // draw Total(inc)
             $text = $order->formatPriceTxt($childItem->getRowTotal() + $childItem->getTaxAmount() - $childItem->getDiscountAmount());
             $line[] = ['text' => $text, 'feed' => $rightBound, 'font' => 'bold', 'align' => 'right'];
         }
         $drawItems[$optionId]['lines'][] = $line;
     }
     // custom options
     $options = $item->getOrderItem()->getProductOptions();
     if ($options) {
         if (isset($options['options'])) {
             foreach ($options['options'] as $option) {
                 $lines = [];
                 $lines[][] = ['text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => $leftBound];
                 if ($option['value']) {
                     $text = [];
                     $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
                     $values = explode(', ', $printValue);
                     foreach ($values as $value) {
                         foreach ($this->string->split($value, 30, true, true) as $subValue) {
                             $text[] = $subValue;
                         }
                     }
                     $lines[][] = ['text' => $text, 'feed' => $leftBound + 5];
                 }
                 $drawItems[] = ['lines' => $lines, 'height' => 15];
             }
         }
     }
     $page = $pdf->drawLineBlocks($page, $drawItems, ['table_header' => true]);
     $this->setPage($page);
 }
Пример #11
0
 /**
  * Draw item line
  *
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function draw()
 {
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $this->_setFontRegular();
     $shipItems = $this->getChilds($item);
     $items = array_merge([$item->getOrderItem()], $item->getOrderItem()->getChildrenItems());
     $prevOptionId = '';
     $drawItems = [];
     foreach ($items as $childItem) {
         $line = [];
         $attributes = $this->getSelectionAttributes($childItem);
         if (is_array($attributes)) {
             $optionId = $attributes['option_id'];
         } else {
             $optionId = 0;
         }
         if (!isset($drawItems[$optionId])) {
             $drawItems[$optionId] = ['lines' => [], 'height' => 15];
         }
         if ($childItem->getParentItem()) {
             if ($prevOptionId != $attributes['option_id']) {
                 $line[0] = ['font' => 'italic', 'text' => $this->string->split($attributes['option_label'], 60, true, true), 'feed' => 60];
                 $drawItems[$optionId] = ['lines' => [$line], 'height' => 15];
                 $line = [];
                 $prevOptionId = $attributes['option_id'];
             }
         }
         if ($this->isShipmentSeparately() && $childItem->getParentItem() || !$this->isShipmentSeparately() && !$childItem->getParentItem()) {
             if (isset($shipItems[$childItem->getId()])) {
                 $qty = $shipItems[$childItem->getId()]->getQty() * 1;
             } elseif ($childItem->getIsVirtual()) {
                 $qty = __('N/A');
             } else {
                 $qty = 0;
             }
         } else {
             $qty = '';
         }
         $line[] = ['text' => $qty, 'feed' => 35];
         // draw Name
         if ($childItem->getParentItem()) {
             $feed = 65;
             $name = $this->getValueHtml($childItem);
         } else {
             $feed = 60;
             $name = $childItem->getName();
         }
         $text = [];
         foreach ($this->string->split($name, 60, true, true) as $part) {
             $text[] = $part;
         }
         $line[] = ['text' => $text, 'feed' => $feed];
         // draw SKUs
         $text = [];
         foreach ($this->string->split($childItem->getSku(), 25) as $part) {
             $text[] = $part;
         }
         $line[] = ['text' => $text, 'feed' => 440];
         $drawItems[$optionId]['lines'][] = $line;
     }
     // custom options
     $options = $item->getOrderItem()->getProductOptions();
     if ($options) {
         if (isset($options['options'])) {
             foreach ($options['options'] as $option) {
                 $lines = [];
                 $lines[][] = ['text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true), 'font' => 'italic', 'feed' => 60];
                 if ($option['value']) {
                     $text = [];
                     $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
                     $values = explode(', ', $printValue);
                     foreach ($values as $value) {
                         foreach ($this->string->split($value, 50, true, true) as $subValue) {
                             $text[] = $subValue;
                         }
                     }
                     $lines[][] = ['text' => $text, 'feed' => 65];
                 }
                 $drawItems[] = ['lines' => $lines, 'height' => 15];
             }
         }
     }
     $page = $pdf->drawLineBlocks($page, $drawItems, ['table_header' => true]);
     $this->setPage($page);
 }
Пример #12
0
 /**
  * Split SKU of an item by dashes and spaces
  * Words will not be broken, unless this length is greater than $length
  *
  * @param string $sku
  * @param int $length
  * @return string[]
  */
 public function splitSku($sku, $length = 30)
 {
     return $this->string->split($sku, $length, true, false, '[\\-\\s]');
 }