/Pdf/Model/Items/Abstract.php
https://bitbucket.org/a_parkhomenko/magento-tcpdf · PHP · 305 lines · 141 code · 25 blank · 139 comment · 18 complexity · c150ba6e788f833024a330704c560301 MD5 · raw file
- <?php
- /**
- * Magento
- *
- * NOTICE OF LICENSE
- *
- * This source file is subject to the Open Software License (OSL 3.0)
- * that is bundled with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://opensource.org/licenses/osl-3.0.php
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@magentocommerce.com so we can send you a copy immediately.
- *
- * DISCLAIMER
- *
- * Do not edit or add to this file if you wish to upgrade Magento to newer
- * versions in the future. If you wish to customize Magento for your
- * needs please refer to http://www.magentocommerce.com for more information.
- *
- * @category Mage
- * @package Mage_Sales
- * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
- * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- */
- /**
- * Sales Order Pdf Items renderer Abstract
- *
- * @category Mage
- * @package Mage_Sales
- * @author Magento Core Team <core@magentocommerce.com>
- */
- abstract class Wm_Pdf_Model_Items_Abstract extends Mage_Core_Model_Abstract
- {
- /**
- * Order model
- *
- * @var Mage_Sales_Model_Order
- */
- protected $_order;
- /**
- * Source model (invoice, shipment, creditmemo)
- *
- * @var Mage_Core_Model_Abstract
- */
- protected $_source;
- /**
- * Item object
- *
- * @var Varien_Object
- */
- protected $_item;
- /**
- * Pdf object
- *
- * @var Mage_Sales_Model_Order_Pdf_Abstract
- */
- protected $_pdf;
- /**
- * Set order model
- *
- * @param Mage_Sales_Model_Order $order
- * @return Mage_Sales_Model_Order_Pdf_Items_Abstract
- */
- public function setOrder(Mage_Sales_Model_Order $order)
- {
- $this->_order = $order;
- return $this;
- }
- /**
- * Set Source model
- *
- * @param Mage_Core_Model_Abstract $source
- * @return Mage_Sales_Model_Order_Pdf_Items_Abstract
- */
- public function setSource(Mage_Core_Model_Abstract $source)
- {
- $this->_source = $source;
- return $this;
- }
- /**
- * Set item object
- *
- * @param Varien_Object $item
- * @return Mage_Sales_Model_Order_Pdf_Items_Abstract
- */
- public function setItem(Varien_Object $item)
- {
- $this->_item = $item;
- return $this;
- }
- /**
- * Set Pdf model
- *
- * @param Pdf $pdf
- * @return Wm_Pdf_Model_Items_Abstract
- */
- public function setPdf(Pdf $pdf)
- {
- $this->_pdf = $pdf;
- return $this;
- }
- /**
- * Retrieve order object
- *
- * @throws Mage_Core_Exception
- * @return Mage_Sales_Model_Order
- */
- public function getOrder()
- {
- if (is_null($this->_order)) {
- Mage::throwException(Mage::helper('sales')->__('Order object is not specified.'));
- }
- return $this->_order;
- }
- /**
- * Retrieve source object
- *
- * @throws Mage_Core_Exception
- * @return Mage_Core_Model_Abstract
- */
- public function getSource()
- {
- if (is_null($this->_source)) {
- Mage::throwException(Mage::helper('sales')->__('Source object is not specified.'));
- }
- return $this->_source;
- }
- /**
- * Retrieve item object
- *
- * @throws Mage_Core_Exception
- * @return Varien_Object
- */
- public function getItem()
- {
- if (is_null($this->_item)) {
- Mage::throwException(Mage::helper('sales')->__('Item object is not specified.'));
- }
- return $this->_item;
- }
- /**
- * Retrieve Pdf model
- *
- * @throws Mage_Core_Exception
- * @return Mage_Sales_Model_Order_Pdf_Abstract
- */
- public function getPdf()
- {
- if (is_null($this->_pdf)) {
- Mage::throwException(Mage::helper('sales')->__('PDF object is not specified.'));
- }
- return $this->_pdf;
- }
- /**
- * Draw item line
- *
- */
- abstract public function draw();
- /**
- * Format option value process
- *
- * @param $value
- * @return string
- */
- protected function _formatOptionValue($value)
- {
- $order = $this->getOrder();
- $resultValue = '';
- if (is_array($value)) {
- if (isset($value['qty'])) {
- $resultValue .= sprintf('%d', $value['qty']) . ' x ';
- }
- $resultValue .= $value['title'];
- if (isset($value['price'])) {
- $resultValue .= " " . $order->formatPrice($value['price']);
- }
- return $resultValue;
- } else {
- return $value;
- }
- }
- /**
- * Get array of arrays with item prices information for display in PDF
- * array(
- * $index => array(
- * 'label' => $label,
- * 'price' => $price,
- * 'subtotal' => $subtotal
- * )
- * )
- * @return array
- */
- public function getItemPricesForDisplay()
- {
- $order = $this->getOrder();
- $item = $this->getItem();
- if (Mage::helper('tax')->displaySalesBothPrices()) {
- $prices = array(
- array(
- 'label' => Mage::helper('tax')->__('Excl. Tax') . ':',
- 'price' => $order->formatPriceTxt($item->getPrice()),
- 'subtotal' => $order->formatPriceTxt($item->getRowTotal())
- ),
- array(
- 'label' => Mage::helper('tax')->__('Incl. Tax') . ':',
- 'price' => $order->formatPriceTxt($item->getPriceInclTax()),
- 'subtotal' => $order->formatPriceTxt($item->getRowTotalInclTax())
- ),
- );
- } elseif (Mage::helper('tax')->displaySalesPriceInclTax()) {
- $prices = array(array(
- 'price' => $order->formatPriceTxt($item->getPriceInclTax()),
- 'subtotal' => $order->formatPriceTxt($item->getRowTotalInclTax()),
- ));
- } else {
- $prices = array(array(
- 'price' => $order->formatPriceTxt($item->getPrice()),
- 'subtotal' => $order->formatPriceTxt($item->getRowTotal()),
- ));
- }
- return $prices;
- }
- /**
- * Retrieve item options
- *
- * @return Varien_Object
- */
- public function getItemOptions() {
- $result = new Varien_Object();
- if ($options = $this->getItem()->getOrderItem()->getProductOptions()) {
-
- if (isset($options['options'])) {
- $result->addData($options['options']);
- }
- if (isset($options['additional_options'])) {
-
- $result->addData($options['additional_options']);
- }
- if (isset($options['attributes_info'])) {
- /**
- * add additional options to object
- */
- $count = count($options['attributes_info']);
- for ($i=0;$i<$count;$i++) {
- if (isset($options['attributes_info'][$i]['label']) &&
- isset($options['attributes_info'][$i]['value'])) {
- $label = strtolower($options['attributes_info'][$i]['label']);
- $value = $options['attributes_info'][$i]['value'];
-
- $result->addData(array($label => $value));
- }
- }
- }
- }
- return $result;
- }
- /**
- * Return item Sku
- *
- * @param $item
- * @return string
- */
- public function getSku($item)
- {
- if ($item->getOrderItem()->getProductOptionByCode('simple_sku'))
- return $item->getOrderItem()->getProductOptionByCode('simple_sku');
- else
- return $item->getSku();
- }
-
- /**
- * Return real item name
- * @param type $item
- * @return string
- */
- public function getName($item)
- {
- if ($item->getOrderItem()->getProductOptionByCode('simple_name'))
- return $item->getOrderItem()->getProductOptionByCode('simple_name');
- else
- return $item->getName();
- }
- }