diff --git a/app/Mage.php b/app/Mage.php index cedb40fc10..00be66d42a 100644 --- a/app/Mage.php +++ b/app/Mage.php @@ -74,7 +74,7 @@ final class Mage { public static function getVersion() { - return '1.1.1'; + return '1.1.2'; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php index 94151f84d5..6498ca5708 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/Create/Giftmessage/Form.php @@ -104,11 +104,21 @@ public function getDefaultRecipient() return ''; } - if($this->getEntity()->getQuote()) { - return $this->getEntity()->getQuote()->getShippingAddress()->getName(); + if($this->getEntity()->getOrder()) { + if ($this->getEntity()->getOrder()->getShippingAddress()) { + return $this->getEntity()->getOrder()->getShippingAddress()->getName(); + } else if ($this->getEntity()->getOrder()->getBillingAddress()) { + return $this->getEntity()->getOrder()->getBillingAddress()->getName(); + } } - return $this->getEntity()->getShippingAddress()->getName(); + if ($this->getEntity()->getShippingAddress()) { + return $this->getEntity()->getShippingAddress()->getName(); + } else if ($this->getEntity()->getBillingAddress()) { + return $this->getEntity()->getBillingAddress()->getName(); + } + + return ''; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php index a7f6f45ca2..edf8a9c91d 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Giftmessage.php @@ -137,10 +137,20 @@ public function getDefaultRecipient() } if($this->getEntity()->getOrder()) { - return $this->getEntity()->getOrder()->getShippingAddress()->getName(); + if ($this->getEntity()->getOrder()->getShippingAddress()) { + return $this->getEntity()->getOrder()->getShippingAddress()->getName(); + } else if ($this->getEntity()->getOrder()->getBillingAddress()) { + return $this->getEntity()->getOrder()->getBillingAddress()->getName(); + } } - return $this->getEntity()->getShippingAddress()->getName(); + if ($this->getEntity()->getShippingAddress()) { + return $this->getEntity()->getShippingAddress()->getName(); + } else if ($this->getEntity()->getBillingAddress()) { + return $this->getEntity()->getBillingAddress()->getName(); + } + + return ''; } /** diff --git a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php index a1aa2ba7e4..66bc29a206 100644 --- a/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php +++ b/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Items/Renderer/Default.php @@ -69,10 +69,20 @@ public function getDefaultRecipient() } if($this->getItem()->getOrder()) { - return $this->getItem()->getOrder()->getShippingAddress()->getName(); + if ($this->getItem()->getOrder()->getShippingAddress()) { + return $this->getItem()->getOrder()->getShippingAddress()->getName(); + } else if ($this->getItem()->getOrder()->getBillingAddress()) { + return $this->getItem()->getOrder()->getBillingAddress()->getName(); + } } - return $this->getItem()->getShippingAddress()->getName(); + if ($this->getItem()->getShippingAddress()) { + return $this->getItem()->getShippingAddress()->getName(); + } else if ($this->getItem()->getBillingAddress()) { + return $this->getItem()->getBillingAddress()->getName(); + } + + return ''; } /** diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php index d26e87bb9d..5d71e674db 100644 --- a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image.php @@ -75,7 +75,7 @@ protected function _beforeSave() $file['tmp_name'] = $_FILES['groups']['tmp_name'][$this->getGroupId()]['fields'][$this->getField()]['value']; $file['name'] = $_FILES['groups']['name'][$this->getGroupId()]['fields'][$this->getField()]['value']; $uploader = new Varien_File_Uploader($file); - $uploader->setAllowedExtensions(array('jpg','jpeg','gif','png')); + $uploader->setAllowedExtensions($this->_getAllowedExtensions()); $uploader->setAllowRenameFiles(true); $uploader->save($uploadDir); } catch (Exception $e) { @@ -133,5 +133,8 @@ protected function _appendScopeInfo($path) return $path; } + protected function _getAllowedExtensions() + { + return array('jpg', 'jpeg', 'gif', 'png'); + } } - diff --git a/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php new file mode 100644 index 0000000000..b81df1812b --- /dev/null +++ b/app/code/core/Mage/Adminhtml/Model/System/Config/Backend/Image/Pdf.php @@ -0,0 +1,35 @@ + + */ +class Mage_Adminhtml_Model_System_Config_Backend_Image_Pdf extends Mage_Adminhtml_Model_System_Config_Backend_Image +{ + protected function _getAllowedExtensions() + { + return array('tif', 'tiff', 'png', 'jpg', 'jpe', 'jpeg'); + } +} \ No newline at end of file diff --git a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php index f5b7ecdb5f..0d6a11f9c5 100644 --- a/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php +++ b/app/code/core/Mage/Api/Model/Server/Adapter/Soap.php @@ -107,11 +107,16 @@ public function run() ->setHeader('Content-Type','text/xml') ->setBody($template->filter($wsdlContent)); - } else { + } elseif ($this->_extensionLoaded()) { $this->_soap = new SoapServer(Mage::getUrl('*/*/*', array('wsdl'=>1))); use_soap_error_handler(false); $this->_soap->setClass($this->getHandler()); - $this->_soap->handle(); + $this->getController()->getResponse() + ->setHeader('Content-Type', 'text/xml') + ->setBody($this->_soap->handle()); + + } else { + $this->fault('0', 'Unable to load Soap extension on the server'); } return $this; } @@ -124,6 +129,30 @@ public function run() */ public function fault($code, $message) { - throw new SoapFault($code, $message); + if ($this->_extensionLoaded()) { + throw new SoapFault($code, $message); + } else { + die(' + + + ' . $code . ' + ' . $message . ' + + + '); + } + + } + + /** + * Check whether Soap extension is loaded + * + * @param none + * @return boolean + */ + protected function _extensionLoaded () + { + return class_exists('SoapServer'); } + } // Class Mage_Api_Model_Server_Adapter_Soap End \ No newline at end of file diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php index d16fa083c1..f7c3456b65 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php @@ -36,22 +36,18 @@ public function draw() $page = $this->getPage(); $items = $this->getChilds($item); - $_prevOptionId = ''; - - $shift{0} = 0; + $shift = array(0, 0, 0); foreach ($items as $_item) { - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - + $this->_setFontRegular(); $attributes = $this->getSelectionAttributes($_item); if ($_item->getOrderItem()->getParentItem()) { if ($_prevOptionId != $attributes['option_id']) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); + $this->_setfontItalic(); $page->drawText($attributes['option_label'], 60, $pdf->y, 'UTF-8'); - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $this->_setFontRegular(); $_prevOptionId = $attributes['option_id']; $pdf->y -= 10; } @@ -69,43 +65,22 @@ public function draw() $feed = 60; $name = $_item->getName(); } - if (strlen($name) > 60) { - $drawTextValue = explode(" ", $name); - $drawTextParts = array(); - $i = 0; - foreach ($drawTextValue as $drawTextPart) { - if (!empty($drawTextParts{$i}) && - (strlen($drawTextParts{$i}) + strlen($drawTextPart)) < 60 ) { - $drawTextParts{$i} .= ' '. $drawTextPart; - } else { - $i++; - $drawTextParts{$i} = $drawTextPart; - } - } - $shift{0} = 0; - foreach ($drawTextParts as $drawTextPart) { - $page->drawText($drawTextPart, $feed, $pdf->y-$shift{0}, 'UTF-8'); - $shift{0} += 10; + foreach (Mage::helper('core/string')->str_split($name, 60, true, true) as $key => $part) { + $page->drawText($part, $feed, $pdf->y-$shift[0], 'UTF-8'); + if ($key > 0) { + $shift[0] += 10; } - - } else { - $page->drawText($name, $feed, $pdf->y, 'UTF-8'); } - if (strlen($_item->getSku()) > 30) { - $drawTextValue = str_split($_item->getSku(), 30); - $shift{2} = 0; - foreach ($drawTextValue as $drawTextPart) { - $page->drawText($drawTextPart, 265, $pdf->y-$shift{2}, 'UTF-8'); - $shift{2} += 10; + $shift[2] = 0; + foreach (Mage::helper('core/string')->str_split($item->getSku(), 30) as $key => $part) { + $page->drawText($part, 265, $pdf->y-$shift[2], 'UTF-8'); + if ($key > 0) { + $shift[2] += 10; } - - } else { - $page->drawText($_item->getSku(), 265, $pdf->y); } - - $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); - $page->setFont($font, 7); + $font = $this->_setFontBold(); + //$page->setFont($font); if ($this->canShowPriceInfo($_item)) { $page->drawText($order->formatPriceTxt($_item->getTaxAmount()), 380, $pdf->y, 'UTF-8'); @@ -121,41 +96,23 @@ public function draw() } if ($item->getOrderItem()->getProductOptions() || $item->getOrderItem()->getDescription()) { - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - - $shift{1} = 10; + $this->_setFontRegular(); + $shift[1] = 10; $options = $item->getOrderItem()->getProductOptions(); if (isset($options['options'])) { foreach ($options['options'] as $option) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); - - $optionTxt = strip_tags($option['label']); - if (strlen($optionTxt) > 80) { - $optionTxt = str_split($optionTxt, 80); - foreach ($optionTxt as $_option) { - $page->drawText($_option, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($optionTxt, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + $this->_setFontItalic(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false,true) as $_option) { + $page->drawText($_option, 60, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - + $this->_setFontRegular(); if ($option['value']) { $values = explode(', ', strip_tags($option['value'])); foreach ($values as $value) { - if (strlen($value) > 80) { - $value = str_split($value, 80); - foreach ($value as $_value) { - $page->drawText($_value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + foreach (Mage::helper('core/string')->str_split($value, 50,true,true) as $_value) { + $page->drawText($_value, 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } } } diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php index 601f6271fe..bc317dea50 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Invoice.php @@ -35,21 +35,21 @@ public function draw() $pdf = $this->getPdf(); $page = $this->getPage(); - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - + $this->_setFontRegular(); $items = $this->getChilds($item); $_prevOptionId = ''; foreach ($items as $_item) { + $shift = array(0, 0, 0); $attributes = $this->getSelectionAttributes($_item); if ($_item->getOrderItem()->getParentItem()) { if ($_prevOptionId != $attributes['option_id']) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); + $this->_setFontItalic(); $page->drawText($attributes['option_label'], 60, $pdf->y, 'UTF-8'); - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $this->_setFontRegular(); $_prevOptionId = $attributes['option_id']; $pdf->y -= 10; } @@ -67,48 +67,23 @@ public function draw() $feed = 60; $name = $_item->getName(); } - if (strlen($name) > 80) { - $drawTextValue = explode(" ", $name); - $drawTextParts = array(); - $i = 0; - - foreach ($drawTextValue as $drawTextPart) { - if (!empty($drawTextParts{$i}) && - (strlen($drawTextParts{$i}) + strlen($drawTextPart)) < 80 ) { - $drawTextParts{$i} .= ' '. $drawTextPart; - } else { - $i++; - $drawTextParts{$i} = $drawTextPart; - } - } - - $shift{0} = 0; - foreach ($drawTextParts as $drawTextPart) { - $page->drawText($drawTextPart, $feed, $pdf->y-$shift{0}, 'UTF-8'); - $shift{0} += 10; + foreach (Mage::helper('core/string')->str_split($name, 60, true, true) as $key => $part) { + $page->drawText($part, $feed, $pdf->y-$shift[0], 'UTF-8'); + if ($key > 0) { + $shift[0] += 10; } - - } else { - $page->drawText($name, $feed, $pdf->y, 'UTF-8'); } - $shift{1} = 0; - /* in case Product SKU is longer than 36 chars - it is written in a few lines */ - if (strlen($_item->getSku()) > 36) { - $drawTextValue = str_split($_item->getSku(), 36); - $shift{2} = 0; - foreach ($drawTextValue as $drawTextPart) { - $page->drawText($drawTextPart, 380, $pdf->y-$shift{2}, 'UTF-8'); - $shift{2} += 10; + foreach (Mage::helper('core/string')->str_split($item->getSku(), 30) as $key => $part) { + $page->drawText($part, 380, $pdf->y-$shift[2], 'UTF-8'); + if ($key > 0) { + $shift[2] += 10; } - - } else { - $page->drawText($_item->getSku(), 380, $pdf->y, 'UTF-8'); } if ($this->canShowPriceInfo($_item)) { - $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); + $font = $this->_setFontBold(); $row_total = $order->formatPriceTxt($_item->getRowTotal()); $page->drawText($row_total, 565-$pdf->widthForStringUsingFontSize($row_total, $font, 7), $pdf->y, 'UTF-8'); @@ -122,34 +97,18 @@ public function draw() $options = $item->getOrderItem()->getProductOptions(); if (isset($options['options'])) { foreach ($options['options'] as $option) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); - - $optionTxt = strip_tags($option['label']); - if (strlen($optionTxt) > 80) { - $optionTxt = str_split($optionTxt, 80); - foreach ($optionTxt as $_option) { - $page->drawText($_option, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($optionTxt, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + $this->_setFontItalic(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false,true) as $_option) { + $page->drawText($_option, 60, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - + $this->_setFontRegular(); if ($option['value']) { $values = explode(', ', strip_tags($option['value'])); foreach ($values as $value) { - if (strlen($value) > 80) { - $value = str_split($value, 80); - foreach ($value as $_value) { - $page->drawText($_value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + foreach (Mage::helper('core/string')->str_split($value, 70,true,true) as $_value) { + $page->drawText($_value, 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } } } diff --git a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php index 4c47b09671..b6a864082c 100644 --- a/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php +++ b/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Shipment.php @@ -35,7 +35,7 @@ public function draw() $pdf = $this->getPdf(); $page = $this->getPage(); - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $this->_setFontRegular(); $shipItems = $this->getChilds($item); $items = array_merge(array($item->getOrderItem()), $item->getOrderItem()->getChildrenItems()); @@ -43,14 +43,15 @@ public function draw() $_prevOptionId = ''; foreach ($items as $_item) { + $shift = array(0, 10, 0); $attributes = $this->getSelectionAttributes($_item); if ($_item->getParentItem()) { if ($_prevOptionId != $attributes['option_id']) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); + $this->_setFontItalic(); $page->drawText($attributes['option_label'], 60, $pdf->y, 'UTF-8'); - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $this->_setFontRegular(); $_prevOptionId = $attributes['option_id']; $pdf->y -= 10; } @@ -77,79 +78,42 @@ public function draw() $feed = 60; $name = $_item->getName(); } - if (strlen($name) > 80) { - $drawTextValue = explode(" ", $name); - $drawTextParts = array(); - $i = 0; - foreach ($drawTextValue as $drawTextPart) { - if (!empty($drawTextParts{$i}) && - (strlen($drawTextParts{$i}) + strlen($drawTextPart)) < 80 ) { - $drawTextParts{$i} .= ' '. $drawTextPart; - } else { - $i++; - $drawTextParts{$i} = $drawTextPart; - } - } - $shift{0} = 0; - foreach ($drawTextParts as $drawTextPart) { - $page->drawText($drawTextPart, $feed, $pdf->y-$shift{0}, 'UTF-8'); - $shift{0} += 10; + foreach (Mage::helper('core/string')->str_split($name, 60, true, true) as $key => $part) { + $page->drawText($part, $feed, $pdf->y-$shift[0], 'UTF-8'); + if ($key > 0) { + $shift[0] += 10; } - - } else { - $page->drawText($name, $feed, $pdf->y, 'UTF-8'); } - $shift{1} = 10; - - if (strlen($_item->getSku()) > 36) { - $drawTextValue = str_split($_item->getSku(), 36); - $shift{2} = 0; - foreach ($drawTextValue as $drawTextPart) { - $page->drawText($drawTextPart, 440, $pdf->y-$shift{2}, 'UTF-8'); - $shift{2} += 10; + foreach (Mage::helper('core/string')->str_split($item->getSku(), 30) as $key => $part) { + $page->drawText($part, 440, $pdf->y-$shift[2], 'UTF-8'); + if ($key > 0) { + $shift[2] += 10; } - - } else { - $page->drawText($_item->getSku(), 440, $pdf->y, 'UTF-8'); } $pdf->y -=max($shift)+10; } if ($item->getOrderItem()->getProductOptions() || $item->getOrderItem()->getDescription()) { - $shift{1} = 10; + $shift[1] = 10; $options = $item->getOrderItem()->getProductOptions(); if (isset($options['options'])) { foreach ($options['options'] as $option) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); - - $optionTxt = strip_tags($option['label']); - if (strlen($optionTxt) > 80) { - $optionTxt = str_split($optionTxt, 80); - foreach ($optionTxt as $_option) { - $page->drawText($_option, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($optionTxt, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + $this->_setFontItalic(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false,true) as $_option) { + $page->drawText($_option, 60, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $this->_setFontRegular(); if ($option['value']) { $values = explode(', ', strip_tags($option['value'])); foreach ($values as $value) { - if (strlen($value) > 80) { - $value = str_split($value, 80); - foreach ($value as $_value) { - $page->drawText($_value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + foreach (Mage::helper('core/string')->str_split($value, 70,true,true) as $_value) { + $page->drawText($_value, 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } } } diff --git a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php index a497954944..f5302c853e 100644 --- a/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php +++ b/app/code/core/Mage/Catalog/Model/Product/Type/Configurable.php @@ -452,4 +452,20 @@ public function hasOptions() return false; } + + /** + * Return product weight based on simple product + * weight or configurable product weight + * + * @return decimal + */ + public function getWeight() + { + if ($this->getProduct()->hasCustomOptions() && ($simpleProductOption = $this->getProduct()->getCustomOption('simple_product'))) { + $simpleProduct = $simpleProductOption->getProduct(); + return $simpleProduct->getWeight(); + } else { + return $this->getProduct()->getData('weight'); + } + } } diff --git a/app/code/core/Mage/Core/Helper/String.php b/app/code/core/Mage/Core/Helper/String.php index c6a1f0fc7e..39a05665fd 100644 --- a/app/code/core/Mage/Core/Helper/String.php +++ b/app/code/core/Mage/Core/Helper/String.php @@ -102,13 +102,13 @@ public function substr($str, $offset, $length = null) */ public function splitInjection($str, $length = 50, $needle = '-', $insert = ' ') { - $str = str_split($str, $length); + $str = $this->str_split($str, $length); $newStr = ''; foreach ($str as $part) { if ($this->strlen($part) >= $length) { - $lastDelimetr = strpos(strrev($part), $needle); + $lastDelimetr = iconv_strpos(strrev($part), $needle, null, self::ICONV_CHARSET); $tmpNewStr = ''; - $tmpNewStr = $this->substr(strrev($part), 0, $lastDelimetr).$insert.substr(strrev($part), $lastDelimetr); + $tmpNewStr = $this->substr(strrev($part), 0, $lastDelimetr) . $insert . $this->substr(strrev($part), $lastDelimetr); $newStr .= strrev($tmpNewStr); } else { $newStr .= $part; @@ -116,4 +116,103 @@ public function splitInjection($str, $length = 50, $needle = '-', $insert = ' ') } return $newStr; } + + /** + * Binary-safe strrev() + * + * @param string $str + * @return string + */ + public function strrev($str) + { + $result = ''; + $strlen = $this->strlen($str); + if (!$strlen) { + return $result; + } + for ($i = $strlen-1; $i >= 0; $i--) { + $result .= iconv_substr($str, $i, 1, self::ICONV_CHARSET); + } + return $result; + } + + /** + * Binary-safe variant of str_split() + * + option not to break words + * + option to trim spaces (between each word) + * + * @param string $str + * @param int $length + * @param bool $keepWords + * @param bool $trim + * @return array + */ + public function str_split($str, $length = 1, $keepWords = false, $trim = false) + { + $result = array(); + $strlen = $this->strlen($str); + if ((!$strlen) || (!is_int($length)) || ($length <= 0)) { + return $result; + } + // trim + if ($trim) { + $str = trim(preg_replace('/\s{2,}/is', ' ', $str)); + } + // do a usual str_split, but safe for our encoding + if ((!$keepWords) || ($length < 2)) { + for ($offset = 0; $offset < $strlen; $offset += $length) { + $result[] = iconv_substr($str, $offset, $length, self::ICONV_CHARSET); + } + } + // split smartly, keeping words + else { + $split = preg_split('/(\s+)/is', $str, null, PREG_SPLIT_DELIM_CAPTURE); + $i = 0; + $space = ''; + $spaceLen = 0; + foreach ($split as $key => $part) { + if ($trim) { + // ignore spaces (even keys) + if ($key % 2) { + continue; + } + $space = ' '; + $spaceLen = 1; + } + if (empty($result[$i])) { + $currentLength = 0; + $result[$i] = ''; + $space = ''; + $spaceLen = 0; + } + else { + $currentLength = iconv_strlen($result[$i], self::ICONV_CHARSET); + } + $partLength = iconv_strlen($part, self::ICONV_CHARSET); + // add part to current last element + if (($currentLength + $spaceLen + $partLength) <= $length) { + $result[$i] .= $space . $part; + } + // add part to new element + elseif ($partLength <= $length) { + $i++; + $result[$i] = $part; + } + // break too long part recursively + else { + foreach ($this->str_split($part, $length, false, $trim) as $subpart) { + $i++; + $result[$i] = $subpart; + } + } + } + } + // remove last element, if empty + if ($count = count($result)) { + if (empty($result[$count - 1])) { + unset($result[$count - 1]); + } + } + return $result; + } } diff --git a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php index b2728f9d8a..2f1ca37cf9 100644 --- a/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php +++ b/app/code/core/Mage/Sales/Model/Mysql4/Quote/Item/Collection.php @@ -83,9 +83,9 @@ protected function _afterLoad() * Assign parent items */ foreach ($this as $item) { - if ($item->getParentItemId()) { - $item->setParentItem($this->getItemById($item->getParentItemId())); - } + if ($item->getParentItemId()) { + $item->setParentItem($this->getItemById($item->getParentItemId())); + } } /** @@ -144,15 +144,16 @@ protected function _assignProducts() if ($product = $productCollection->getItemById($item->getProductId())) { $product->setCustomOptions(array()); - $item->setProduct($product); + foreach ($item->getOptions() as $option) { - if ($product = $productCollection->getItemById($option->getProductId())) { - $option->setProduct($product); + if ($optionProduct = $productCollection->getItemById($option->getProductId())) { + $option->setProduct($optionProduct); } else { - $option->setProduct($item->getProduct()); + $option->setProduct($product); } } + $item->setProduct($product); } else { $item->isDeleted(true); diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php index fcacfec00e..f59c2023c1 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php @@ -246,4 +246,24 @@ public function getItemOptions() { return $result; } + protected function _setFontRegular($size = 7) + { + $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf'); + $this->getPage()->setFont($font, $size); + return $font; + } + + protected function _setFontBold($size = 7) + { + $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf'); + $this->getPage()->setFont($font, $size); + return $font; + } + + protected function _setFontItalic($size = 7) + { + $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf'); + $this->getPage()->setFont($font, $size); + return $font; + } } \ No newline at end of file diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php index 3b5f2e43fe..17126a40f8 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Creditmemo/Default.php @@ -34,103 +34,56 @@ public function draw() $item = $this->getItem(); $pdf = $this->getPdf(); $page = $this->getPage(); - - $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir()."/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf"); - $page->setFont($font, 7); - //$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - - $page->drawText($item->getQty()*1, 35, $pdf->y, 'UTF-8'); + $shift = array(0, 10, 0); - if (strlen($item->getName()) > 60) { - $drawTextValue = explode(" ", $item->getName()); - $drawTextParts = array(); - $i = 0; - foreach ($drawTextValue as $drawTextPart) { - if (!empty($drawTextParts{$i}) && - (strlen($drawTextParts{$i}) + strlen($drawTextPart)) < 60 ) { - $drawTextParts{$i} .= ' '. $drawTextPart; - } else { - $i++; - $drawTextParts{$i} = $drawTextPart; - } - } - $shift{0} = 0; - foreach ($drawTextParts as $drawTextPart) { - $page->drawText($drawTextPart, 60, $pdf->y-$shift{0}, 'UTF-8'); - $shift{0} += 10; - } - - } else { - $page->drawText($item->getName(), 60, $pdf->y, 'UTF-8'); + // draw quantity & name + $this->_setFontRegular(); + $page->drawText($item->getQty()*1, 35, $pdf->y, 'UTF-8'); + foreach (Mage::helper('core/string')->str_split($item->getName(), 60, true, true) as $key => $part) { + $page->drawText($part, 60, $pdf->y-$shift[0], 'UTF-8'); + $shift[0] += 10; } - $shift{1} = 10; + // draw options $options = $this->getItemOptions(); if (isset($options)) { foreach ($options as $option) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); - - $optionTxt = strip_tags($option['label']); - if (strlen($optionTxt) > 80) { - $optionTxt = str_split($optionTxt, 80); - foreach ($optionTxt as $_option) { - $page->drawText($_option, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($optionTxt, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + // draw options label + $this->_setFontItalic(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60, false, true) as $_option) { + $page->drawText($_option, 60, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - - if ($option['value']) { - $values = explode(', ', strip_tags($option['value'])); - foreach ($values as $value) { - if (strlen($value) > 80) { - $value = str_split($value, 80); - foreach ($value as $_value) { - $page->drawText($_value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } + // draw options value + $this->_setFontRegular(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['value']), 60, true, true) as $_value) { + $page->drawText($_value, 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } } } + // draw product description foreach ($this->_parseDescription() as $description){ $page->drawText(strip_tags($description), 65, $pdf->y-$shift{1}, 'UTF-8'); $shift{1} += 10; } - if (strlen($item->getSku()) > 30) { - $drawTextValue = str_split($item->getSku(), 30); - $shift{2} = 0; - foreach ($drawTextValue as $drawTextPart) { - $page->drawText($drawTextPart, 265, $pdf->y-$shift{2}, 'UTF-8'); - $shift{2} += 10; - } - - } else { - $page->drawText($item->getSku(), 265, $pdf->y); + // draw sku + foreach (Mage::helper('core/string')->str_split($item->getSku(), 25) as $key => $part) { + $page->drawText($part, 275, $pdf->y-$shift[2], 'UTF-8'); + $shift[2] += 10; } - - $font = Zend_Pdf_Font::fontWithPath(Mage::getRoot()."/verdana.ttf"); - $page->setFont($font, 7); - - #$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); - #$page->setFont($font, 7); + + // draw amounts + $font = $this->_setFontBold(); $page->drawText($order->formatPriceTxt($item->getTaxAmount()), 380, $pdf->y, 'UTF-8'); $page->drawText($order->formatPriceTxt(-$item->getDiscountAmount()), 430, $pdf->y, 'UTF-8'); $page->drawText($order->formatPriceTxt($item->getRowTotal()), 480, $pdf->y, 'UTF-8'); - $row_total = $order->formatPriceTxt($item->getRowTotal()+$item->getTaxAmount()-$item->getDiscountAmount()); - - $page->drawText($row_total, 565-$pdf->widthForStringUsingFontSize($row_total, $font, 7), $pdf->y, 'UTF-8'); + // draw total + $rowTotal = $order->formatPriceTxt($item->getRowTotal()+$item->getTaxAmount()-$item->getDiscountAmount()); + $page->drawText($rowTotal, 565-$pdf->widthForStringUsingFontSize($rowTotal, $font, 7), $pdf->y, 'UTF-8'); $pdf->y -=max($shift)+10; } } \ No newline at end of file diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php index e0ad5ba031..6fc87e46fb 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Invoice/Default.php @@ -34,71 +34,37 @@ public function draw() $item = $this->getItem(); $pdf = $this->getPdf(); $page = $this->getPage(); - - $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir()."/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf"); - $page->setFont($font, 7); - //$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $shift = array(0, 10, 0); + + $this->_setFontRegular(); $page->drawText($item->getQty()*1, 35, $pdf->y, 'UTF-8'); /* in case Product name is longer than 80 chars - it is written in a few lines */ - if (strlen($item->getName()) > 80) { - $drawTextValue = explode(" ", $item->getName()); - $drawTextParts = array(); - $i = 0; - - foreach ($drawTextValue as $drawTextPart) { - if (!empty($drawTextParts{$i}) && - (strlen($drawTextParts{$i}) + strlen($drawTextPart)) < 80 ) { - $drawTextParts{$i} .= ' '. $drawTextPart; - } else { - $i++; - $drawTextParts{$i} = $drawTextPart; - } + foreach (Mage::helper('core/string')->str_split($item->getName(), 60, true, true) as $key => $part) { + $page->drawText($part, 60, $pdf->y-$shift[0], 'UTF-8'); + if ($key > 0) { + $shift[0] += 10; } - - $shift{0} = 0; - foreach ($drawTextParts as $drawTextPart) { - $page->drawText($drawTextPart, 60, $pdf->y-$shift{0}, 'UTF-8'); - $shift{0} += 10; - } - - } else { - $page->drawText($item->getName(), 60, $pdf->y, 'UTF-8'); } - $shift{1} = 10; $options = $this->getItemOptions(); if (isset($options)) { foreach ($options as $option) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); - - $optionTxt = strip_tags($option['label']); - if (strlen($optionTxt) > 80) { - $optionTxt = str_split($optionTxt, 80); - foreach ($optionTxt as $_option) { - $page->drawText($_option, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($optionTxt, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + // draw options label + $this->_setFontItalic(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false,true) as $_option) { + $page->drawText($_option, 60, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - + // draw options value + $this->_setFontRegular(); if ($option['value']) { $values = explode(', ', strip_tags($option['value'])); foreach ($values as $value) { - if (strlen($value) > 80) { - $value = str_split($value, 80); - foreach ($value as $_value) { - $page->drawText($_value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + foreach (Mage::helper('core/string')->str_split($value, 60,true,true) as $_value) { + $page->drawText($_value, 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } } } @@ -106,24 +72,19 @@ public function draw() } foreach ($this->_parseDescription() as $description){ - $page->drawText(strip_tags($description), 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + $page->drawText(strip_tags($description), 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } /* in case Product SKU is longer than 36 chars - it is written in a few lines */ - if (strlen($item->getSku()) > 36) { - $drawTextValue = str_split($item->getSku(), 36); - $shift{2} = 0; - foreach ($drawTextValue as $drawTextPart) { - $page->drawText($drawTextPart, 380, $pdf->y-$shift{2}, 'UTF-8'); - $shift{2} += 10; + foreach (Mage::helper('core/string')->str_split($item->getSku(), 25) as $key => $part) { + $page->drawText($part, 380, $pdf->y-$shift[2], 'UTF-8'); + if ($key > 0) { + $shift[2] += 10; } - - } else { - $page->drawText($item->getSku(), 380, $pdf->y, 'UTF-8'); } - $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); + $font = $this->_setFontBold(); $row_total = $order->formatPriceTxt($item->getRowTotal()); $page->drawText($row_total, 565-$pdf->widthForStringUsingFontSize($row_total, $font, 7), $pdf->y, 'UTF-8'); diff --git a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php index a7f3f6e777..c9f7854db5 100644 --- a/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php +++ b/app/code/core/Mage/Sales/Model/Order/Pdf/Items/Shipment/Default.php @@ -34,69 +34,35 @@ public function draw() $item = $this->getItem(); $pdf = $this->getPdf(); $page = $this->getPage(); - - $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir()."/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf"); - $page->setFont($font, 7); - - #$page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); + $shift = array(0, 10, 0); + $this->_setFontRegular(); $page->drawText($item->getQty()*1, 35, $pdf->y, 'UTF-8'); - if (strlen($item->getName()) > 80) { - $drawTextValue = explode(" ", $item->getName()); - $drawTextParts = array(); - $i = 0; - foreach ($drawTextValue as $drawTextPart) { - if (!empty($drawTextParts{$i}) && - (strlen($drawTextParts{$i}) + strlen($drawTextPart)) < 80 ) { - $drawTextParts{$i} .= ' '. $drawTextPart; - } else { - $i++; - $drawTextParts{$i} = $drawTextPart; - } - } - $shift{0} = 0; - foreach ($drawTextParts as $drawTextPart) { - $page->drawText($drawTextPart, 60, $pdf->y-$shift{0}, 'UTF-8'); - $shift{0} += 10; + foreach (Mage::helper('core/string')->str_split($item->getName(), 60, true, true) as $key => $part) { + $page->drawText($part, 60, $pdf->y-$shift[0], 'UTF-8'); + if ($key > 0) { + $shift[0] += 10; } - - } else { - $page->drawText($item->getName(), 60, $pdf->y, 'UTF-8'); } - $shift{1} = 10; $options = $this->getItemOptions(); if (isset($options)) { foreach ($options as $option) { - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_ITALIC), 7); - - $optionTxt = strip_tags($option['label']); - if (strlen($optionTxt) > 80) { - $optionTxt = str_split($optionTxt, 80); - foreach ($optionTxt as $_option) { - $page->drawText($_option, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($optionTxt, 60, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + // draw options label + $this->_setFontItalic(); + foreach (Mage::helper('core/string')->str_split(strip_tags($option['label']), 60,false,true) as $_option) { + $page->drawText($_option, 60, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } - - $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 7); - + // draw options value + $this->_setFontRegular(); if ($option['value']) { $values = explode(', ', strip_tags($option['value'])); foreach ($values as $value) { - if (strlen($value) > 80) { - $value = str_split($value, 80); - foreach ($value as $_value) { - $page->drawText($_value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; - } - } else { - $page->drawText($value, 65, $pdf->y-$shift{1}, 'UTF-8'); - $shift{1} += 10; + foreach (Mage::helper('core/string')->str_split($value, 60,true,true) as $_value) { + $page->drawText($_value, 65, $pdf->y-$shift[1], 'UTF-8'); + $shift[1] += 10; } } } @@ -108,16 +74,11 @@ public function draw() $shift{1} += 10; } - if (strlen($item->getSku()) > 36) { - $drawTextValue = str_split($item->getSku(), 36); - $shift{2} = 0; - foreach ($drawTextValue as $drawTextPart) { - $page->drawText($drawTextPart, 440, $pdf->y-$shift{2}, 'UTF-8'); - $shift{2} += 10; + foreach (Mage::helper('core/string')->str_split($item->getSku(), 25) as $key => $part) { + $page->drawText($part, 440, $pdf->y-$shift[2], 'UTF-8'); + if ($key > 0) { + $shift[2] += 10; } - - } else { - $page->drawText($item->getSku(), 440, $pdf->y, 'UTF-8'); } $pdf->y -=max($shift)+10; diff --git a/app/code/core/Mage/Sales/etc/system.xml b/app/code/core/Mage/Sales/etc/system.xml index ee71d7f62c..41664fc4ba 100644 --- a/app/code/core/Mage/Sales/etc/system.xml +++ b/app/code/core/Mage/Sales/etc/system.xml @@ -116,7 +116,7 @@ image - adminhtml/system_config_backend_image + adminhtml/system_config_backend_image_pdf sales/store/logo sales/store/logo 100 diff --git a/app/design/adminhtml/default/default/template/sales/order/shipment/view/tracking.phtml b/app/design/adminhtml/default/default/template/sales/order/shipment/view/tracking.phtml index f90be22603..6472e56612 100644 --- a/app/design/adminhtml/default/default/template/sales/order/shipment/view/tracking.phtml +++ b/app/design/adminhtml/default/default/template/sales/order/shipment/view/tracking.phtml @@ -36,7 +36,6 @@