* @copyright Copyright (C) 2010 - 2012 Queldorei */ class Queldorei_ShopperSettings_Helper_Data extends Mage_Core_Helper_Abstract { /** * Retrieve config value for store by path * * @param string $path * @param string $section * @param int $store * @return mixed */ public function getCfg($path, $section = 'shoppersettings', $store = NULL) { if ($store == NULL) { $store = Mage::app()->getStore()->getId(); } if (empty($path)) { $path = $section; } else { $path = $section . '/' . $path; } return Mage::getStoreConfig($path, $store); } protected function _loadProduct(Mage_Catalog_Model_Product $product) { $product->load($product->getId()); } public function getLabel(Mage_Catalog_Model_Product $product) { if ('Mage_Catalog_Model_Product' != get_class($product)) return; $html = ''; if ( !$this->getCfg('labels/new_label') && !$this->getCfg('labels/sale_label') ) { return $html; } if ($this->getCfg('labels/new_label') && $this->_isNew($product)) { $html .= '
'; } if ($this->getCfg("labels/sale_label") && $this->_isOnSale($product)) { $html .= ''; } return $html; } protected function _checkDate($from, $to) { $today = strtotime( Mage::app()->getLocale()->date() ->setTime('00:00:00') ->toString(Varien_Date::DATETIME_INTERNAL_FORMAT) ); if ($from && $today < $from) { return false; } if ($to && $today > $to) { return false; } if (!$to && !$from) { return false; } return true; } protected function _isNew($product) { $from = strtotime($product->getData('news_from_date')); $to = strtotime($product->getData('news_to_date')); return $this->_checkDate($from, $to); } protected function _isOnSale($_product) { /* @var $_taxHelper Mage_Tax_Helper_Data */ $_taxHelper = Mage::helper('tax'); if (!$_product->isGrouped()) { $_price = $_taxHelper->getPrice($_product, $_product->getPrice()); $_finalPrice = $_taxHelper->getPrice($_product, $_product->getFinalPrice()); if ($_finalPrice < $_price){ return true; } /* if ($_finalPrice < $_price): */ } /* if (!$_product->isGrouped()): */ return false; } public function priceFormat($string) { if ( $this->getCfg('msrp/enabled', 'sales') ) { return $string; } $currency = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); return str_replace($currency, '' . $currency . '', $string); } /** * Returns the identifier for the currently rendered CMS page. * If current page is not from CMS, null is returned. * @return String | Null */ public function getCurrentCmsPage() { return Mage::getSingleton('cms/page')->getIdentifier(); } }