') { return $this->displayPrices( $dataObject, $dataObject->getData('base_'.$code), $dataObject->getData($code), $strong, $separator ); } /** * Get "double" prices html (block with base and place currency) * * @param Varien_Object $dataObject * @param float $basePrice * @param float $price * @param bool $strong * @param string $separator * @return string */ public function displayPrices($dataObject, $basePrice, $price, $strong = false, $separator = '
') { $order = false; if ($dataObject instanceof Mage_Sales_Model_Order) { $order = $dataObject; } else { $order = $dataObject->getOrder(); } if ($order && $order->isCurrencyDifferent()) { $res = ''; $res.= $order->formatBasePrice($basePrice); $res.= ''.$separator; $res.= '['.$order->formatPrice($price).']'; } elseif ($order) { $res = $order->formatPrice($price); if ($strong) { $res = ''.$res.''; } } else { $res = Mage::app()->getStore()->formatPrice($price); if ($strong) { $res = ''.$res.''; } } return $res; } /** * Filter collection by removing not available product types * * @param Mage_Core_Model_Mysql4_Collection_Abstract $collection * @return Mage_Core_Model_Mysql4_Collection_Abstract */ public function applySalableProductTypesFilter($collection) { $productTypes = Mage::getConfig()->getNode('adminhtml/sales/order/create/available_product_types')->asArray(); $productTypes = array_keys($productTypes); foreach($collection->getItems() as $key => $item) { if ($item instanceof Mage_Catalog_Model_Product) { $type = $item->getTypeId(); } else if ($item instanceof Mage_Sales_Model_Order_Item) { $type = $item->getProductType(); } else if ($item instanceof Mage_Sales_Model_Quote_Item) { $type = $item->getProductType(); } else { $type = ''; } if (!in_array($type, $productTypes)) { $collection->removeItemByKey($key); } } return $collection; } /** * Escape string preserving links * * @param array|string $data * @param null|array $allowedTags * @return string */ public function escapeHtmlWithLinks($data, $allowedTags = null) { if (!empty($data) && is_array($allowedTags) && in_array('a', $allowedTags)) { $links = array(); $i = 1; $data = str_replace('%', '%%', $data); $regexp = "/]*href\s*?=\s*?([\"\']??)([^\" >]*?)\\1[^>]*>(.*)<\/a>/siU"; while (preg_match($regexp, $data, $matches)) { //Revert the sprintf escaping $url = str_replace('%%', '%', $matches[2]); $text = str_replace('%%', '%', $matches[3]); //Check for an valid url if ($url) { $urlScheme = strtolower(parse_url($url, PHP_URL_SCHEME)); if ($urlScheme !== 'http' && $urlScheme !== 'https') { $url = null; } } //Use hash tag as fallback if (!$url) { $url = '#'; } //Recreate a minimalistic secure a tag $links[] = sprintf( '%s', htmlspecialchars($url, ENT_QUOTES, 'UTF-8', false), parent::escapeHtml($text) ); $data = str_replace($matches[0], '%' . $i . '$s', $data); ++$i; } $data = parent::escapeHtml($data, $allowedTags); return vsprintf($data, $links); } return parent::escapeHtml($data, $allowedTags); } }