当前位置: 首页>>代码示例>>PHP>>正文


PHP StringUtils::split方法代码示例

本文整理汇总了PHP中Magento\Framework\Stdlib\StringUtils::split方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::split方法的具体用法?PHP StringUtils::split怎么用?PHP StringUtils::split使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Stdlib\StringUtils的用法示例。


在下文中一共展示了StringUtils::split方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: draw

 /**
  * Draw item line
  *
  * @return void
  */
 public function draw()
 {
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = [];
     // draw Product name
     $lines[0] = [['text' => $this->string->split($item->getName(), 60, true, true), 'feed' => 100]];
     // draw QTY
     $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 35];
     // draw SKU
     $lines[0][] = ['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[][] = ['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[][] = ['text' => $this->string->split($value, 50, true, true), 'feed' => 115];
                 }
             }
         }
     }
     $lineBlock = ['lines' => $lines, 'height' => 20];
     $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
     $this->setPage($page);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:37,代码来源:DefaultShipment.php

示例2: draw

 /**
  * 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);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:62,代码来源:DefaultInvoice.php

示例3: testStrSplit

 /**
  * @covers \Magento\Framework\Stdlib\StringUtils::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));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:StringUtilsTest.php

示例4: draw

 /**
  * 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);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:42,代码来源:DefaultCreditmemo.php

示例5: draw

 /**
  * 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->getChildren($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);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:95,代码来源:Shipment.php

示例6: draw

 /**
  * 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->getChildren($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];
//.........这里部分代码省略.........
开发者ID:whoople,项目名称:magento2-testing,代码行数:101,代码来源:Creditmemo.php

示例7: splitSku

 /**
  * 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]');
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Data.php

示例8: draw

 /**
  * 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->getChildren($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);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:91,代码来源:Invoice.php

示例9: insertOrder

 /**
  * Insert order to pdf page
  *
  * @param \Zend_Pdf_Page &$page
  * @param \Magento\Sales\Model\Order $obj
  * @param bool $putOrderId
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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([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($this->_localeDate->scopeDate($order->getStore(), $order->getCreatedAt(), true), \IntlDateFormatter::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($this->addressRenderer->format($order->getBillingAddress(), '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($this->addressRenderer->format($order->getShippingAddress(), '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 = [];
             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 = [];
                 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;
                 }
//.........这里部分代码省略.........
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:101,代码来源:AbstractPdf.php

示例10: _doRequest

 /**
  * Do rate request and handle errors
  *
  * @return Result|\Magento\Framework\DataObject
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 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\Exception\LocalizedException(__('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(['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');
     /** Dutiable */
     if ($this->isDutiable($rawRequest->getShipperAddressCountryCode(), $rawRequest->getRecipientAddressCountryCode())) {
         $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)) {
//.........这里部分代码省略.........
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:101,代码来源:Carrier.php


注:本文中的Magento\Framework\Stdlib\StringUtils::split方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。