getLayout() ->createBlock('s1902_mgyumesphere/head') ->setTemplate('s1902_mgyumesphere/head.phtml') ->toHtml(); } public function getControllerName(){ return Mage::app()->getRequest()->getControllerName(); } public function getActionName(){ return Mage::app()->getRequest()->getActionName(); } public function getRouteName(){ return Mage::app()->getRequest()->getRouteName(); } public function getModuleName(){ return Mage::app()->getRequest()->getModuleName(); } public function getModel($modelname,$namespacemodule = null){ if($namespacemodule === null){ $namespacemodule = $this->getModuleName(); } $model = Mage::getModel($namespacemodule.'/'.$modelname); return $model; } public function clearCheckout(){ Mage::getSingleton('checkout/session')->clear(); } public function getCurrentProduct(){ return Mage::registry('current_product'); } public function getCartPriceTotals(){ /*assoc data: subtotal, grand_total, discount, tax example: $cartpricetotals['grand_total']->getValue(); */ return Mage::getSingleton('checkout/session')->getQuote()->getTotals(); } public function getFreeShippingSubTotal(){ return Mage::getStoreConfig("carriers/freeshipping/free_shipping_subtotal"); } public function getCartItems($onlyVisible = true){ $checkoutItems = array(); $checkoutSession = Mage::getSingleton('checkout/session'); $onQuote = null; if($onlyVisible){ $onQuote = $checkoutSession->getQuote()->getAllVisibleItems(); } else{ $onQuote = $checkoutSession->getQuote()->getAllItems(); } foreach ($onQuote as $item) { $_item = Mage::getModel('catalog/product')->load($item->getProductId()); array_push($checkoutItems, $_item->getData()); } return $checkoutItems; } public function getBaseUrl(){ return Mage::getBaseUrl(); } public function getUrl($url){ $url = strtolower($url); switch($url){ case 'skin': Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); break; case 'js': return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS); break; case 'media': return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA); break; case 'store': return Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB); break; default: return $this->getBaseUrl(); break; } } public function manageSession($key, $val=null){ if($val === null){ return Mage::getSingleton('core/session')->getData($key); } else{ Mage::getSingleton('core/session')->setData($key,$val); } } public function unsetSession($key){ return Mage::getSingleton('core/session')->unsetData($key); } public function getProdBySku($sku){ return Mage::getModel('catalog/product')->loadByAttribute('sku',$sku); } public function getProdById($id){ return Mage::getModel('catalog/product')->load($id); } public function setProdAttr(&$product,&$attr,&$value){ $product->setData($attr,$value) ->getResource() ->saveAttribute($product,$attr); } //new public function moneyFormat($number, $options = array()){ $options_copy = array('decimals'=>0, 'dec_point'=>'.', 'thousands'=>',', 'currency_sym'=>true, 'currency_pos'=>0); if(!isset($options['decimal'])){ $options['decimal'] = $options_copy['decimal']; } if(!isset($options['dec_point'])){ $options['dec_point'] = $options_copy['dec_point']; } if(!isset($options['thousands'])){ $options['thousands'] = $options_copy['thousands']; } if(!isset($options['currency_sym'])){ $options['currency_sym'] = $options_copy['currency_sym']; } if(!isset($options['currency_pos'])){ $options['currency_pos'] = $options_copy['currency_pos']; } $rawNumber = intval(Mage::helper('core')->currency(intval($number),false,false)); $formattedNumber = number_format($number, $options['decimal'],$options['dec_point'],$options['thousands']); if($options['currency_sym']){ $currencySymbol = $this->moneySymbol(); if(!is_bool($options['currency_sym'])){ $currency_symbol = $options['currency_sym']; } $moneyFormattedNumber = null; if($options['currency_pos'] <= 0){ $formattedNumber = $currencySymbol . ' ' . $formattedNumber; } else{ $formattedNumber = $formattedNumber . ' ' . $currencySymbol; } } return $formattedNumber; } //new public function moneySymbol($store = null){ if($store === null){ $store = Mage::app()->getStore(); } return Mage::app()->getLocale()->currency($store->getCurrentCurrencyCode())->getSymbol(); } /* *deprecated */ public function formatMoney($number, $hasSymbol = true, $hasNoDecimalAndSymbol=true){ return Mage::helper('core')->currency($number, $hasNoDecimalAndSymbol,true); } public function currency($number, $hasDecimalAndSymbol = false){ return Mage::helper('core')->currency((int)$number, $hasNoDecimalAndSymbol,false); } public function getMoneySym(){ return Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); } public function log($prefix, $dump=true, $midfix='', $filename="mage.log"){ if($dump){ Mage::log($this->dump($prefix), $midfix, $filename); } else{ Mage::log($prefix, $midfix, $filename); } } public function dump($var, $label=null, $echo = false){ if($echo){ Zend_Debug::dump($var, $label, $echo); } else{ return Zend_Debug::dump($var, $label, $echo); } } public function getAttrByCode($attrCode){ $attr_model = Mage::getModel('catalog/resource_eav_attribute'); return $attr_model->loadByCode('catalog_product', $attrCode); } public function getSelectAttrVals($attrCode){ $attribute = $this->getAttrByCode('filter_category'); $attributeOptionsModel= Mage::getModel('eav/entity_attribute_source_table') ; $attributeOptionsModel->setAttribute($attribute); $options = $attributeOptionsModel->getAllOptions(false); return $options; } public function selectAttrValExists($attrCode, $value){ foreach($this->getSelectAttrVals($attrCode) as $option){ if ($option['label'] == $value){ return $option; } } return false; } public function addSelectAttrVal($attrCode, $argValue) { $attribute_model = Mage::getModel('eav/entity_attribute'); $attributeOptionsModel= Mage::getModel('eav/entity_attribute_source_table') ; $attribute = $this->getAttrByCode($attrCode); $attributeOptionsModel->setAttribute($attribute); $options = $attributeOptionsModel->getAllOptions(false); if(!$this->selectAttrValExists($attrCode, $argValue)){ $value['option'] = array($argValue,$argValue); $result = array('value' => $value); $attribute->setData('option',$result); $attribute->save(); } foreach($options as $option){ if ($option['label'] == $argValue){ return $option; } } return true; } public function getCatById($catid){ return Mage::getModel('catalog/category')->load($catid); } public function getProdCats($prod){ $categories = array(); $catids = $prod->getCategoryIds(); foreach ($catids as $category_id){ array_push($categories, Mage::getModel('catalog/category')->load($category_id)); } return $categories; } public function getSelectAttrOptionId($attrCode,$optionLabel){ $productModel = Mage::getModel('catalog/product'); $attr = $productModel->getResource()->getAttribute($attrCode); if ($attr->usesSource()) { return $attr->getSource()->getOptionId($optionLabel); } else{ return null; } } public function setProdSelectAttrOptions($product,$attrCode,$values = array()){ $existSelection = $this->getSelectedMultiSelectOptions($product,$attrCode,true); $valuesWant = array(); $startcommit = false; foreach($values as $value){ array_push($valuesWant,(int)$this->getSelectAttrOptionId($attrCode,$value)); } if(!is_array($valuesWant) || !is_array($existSelection)){ return null; } $arrdiff1 = array_diff($valuesWant,$existSelection); $arrdiff2 = array_diff($existSelection,$valuesWant); if(count($arrdiff1) != 0 || count($arrdiff2) != 0){ $startcommit = true; } if($startcommit){ if(count($valuesWant) == 0){ $product->setData($attrCode,array()); } else{ $product->setData($attrCode,$valuesWant); } $product->save(); } else{ return null; } } public function getSelectedMultiSelectOptions($product, $attrCode,$returnIdsOnly = false){ $selectedIds = $product->getData($attrCode); if($returnIdsOnly){ return explode(',',$selectedIds); } $options = array(); foreach($this->getSelectAttrVals($attrCode) as $attr){ if(in_array((int)$attr['value'],explode(',',$selectedIds))){ array_push($options,$attr); } } return $options; } }