interscot

app/code/community/Creare/CreareSeoCore/Helper/Data.php

Apr 25th, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.98 KB | None | 0 0
  1. <?php
  2. class Creare_CreareSeoCore_Helper_Data extends Mage_Core_Helper_Abstract
  3. {
  4.  
  5.     public function getDiscontinuedProductUrl($product)
  6.     {
  7.         $type = $product->getAttributeText('creareseo_discontinued');
  8.         // check to see if we want to redirect to a product / category / homepage
  9.         if($type === '301 Redirect to Category'){
  10.             $cats = $product->getCategoryIds();
  11.             if (is_array($cats) && count($cats) > 1) {
  12.                 foreach($cats as $cat_id) {
  13.                             $cat = Mage::getModel('catalog/category')->load( $cat_id );
  14.                             if($cat->getName()) {
  15.                                 return $cat->getUrlPath();
  16.                             }
  17.                         }
  18.                         return Mage::getUrl();
  19.             } else {
  20.                 $cat = Mage::getModel('catalog/category')->load( $cats );
  21.                 return $cat->getUrlPath();
  22.             }
  23.         }
  24.  
  25.         if($type === '301 Redirect to Homepage'){
  26.             return Mage::getBaseUrl();
  27.         }  
  28.  
  29.         if($type === '301 Redirect to Product SKU'){
  30.  
  31.             $sku = $product->getCreareseoDiscontinuedProduct();
  32.             if($sku){
  33.                 $productUrl = Mage::getModel('catalog/product')->getCollection()
  34.                      ->addAttributeToSelect('sku')
  35.                      ->addFieldToFilter('sku',$sku)
  36.                       ->getFirstItem()
  37.                       ->getProductUrl();
  38.  
  39.                 if ($productUrl)
  40.                 {
  41.                     return $productUrl;
  42.                 }
  43.  
  44.             }
  45.         }
  46.  
  47.         return false;
  48.  
  49.     }
  50.  
  51.     public function getDiscontinuedCategoryUrl($category){
  52.         if($category->getLevel() == 2){
  53.             if(!$category->getIsActive()){
  54.                 return Mage::getBaseUrl();
  55.             } else {
  56.                 return Mage::getBaseUrl().$category->getUrlPath();
  57.             }
  58.         } else {
  59.             $parentCategory = Mage::getModel('catalog/category')->load($category->getParentId());
  60.             return $this->getDiscontinuedCategoryUrl($parentCategory);
  61.         }
  62.  
  63.     }
  64.  
  65.     public function getConfigPath()
  66.     {
  67.         return Mage::app()->getRequest()->getControllerName().'_'.Mage::app()->getRequest()->getParam('section');
  68.     }
  69.    
  70.    
  71.     /*
  72.      * On controller_action_predispatch called by saveConfigOnConfigLoad()
  73.      */
  74.    
  75.     public function saveFileContentToConfig($file, $field)
  76.     {
  77.         $adminsession = Mage::getSingleton('adminhtml/session');
  78.         $io = new Varien_Io_File();
  79.         $io->open(array('path' => Mage::getBaseDir()));
  80.        
  81.         if ($io->fileExists($file))
  82.         {
  83.             try
  84.             {
  85.                 $contents = $io->read($file);
  86.                 Mage::getModel('core/config')->saveConfig('creare'.$field.'/files/'.$field, $contents);
  87.                
  88.             } catch(Mage_Core_Exception $e)
  89.             {
  90.                 $adminsession->addError($e->getMessage());
  91.             }
  92.         } else {
  93.             $adminsession->addError($file." does not exist. Please create this file on your domain root to use this feature.");
  94.         }
  95.            
  96.         $io->streamClose();
  97.     }
  98.    
  99.     /*
  100.      * On admin_system_config_changed_section_ called by writeToFileOnConfigSave()
  101.      */
  102.    
  103.     public function writeFile($file, $post, $field, $robots_location = '')
  104.     {
  105.         $adminsession = Mage::getSingleton('adminhtml/session');
  106.         $io = new Varien_Io_File();
  107.         $io->open(array('path' => Mage::getBaseDir().DS.$robots_location));
  108.        
  109.         if ($io->fileExists($file))
  110.         {
  111.             if ($io->isWriteable($file))
  112.             {
  113.                 try
  114.                 {
  115.                     $io->streamOpen($file);
  116.                     $io->streamWrite($post);
  117.  
  118.                 } catch(Mage_Core_Exception $e)
  119.                 {
  120.                     $adminsession->addError($e->getMessage());
  121.                 }
  122.             } else {
  123.            
  124.                 $adminsession->addError($file." is not writable. Change permissions to 644 to use this feature.");
  125.            
  126.             }
  127.         } else {
  128.            
  129.             $adminsession->addError($file." does not exist. The file was not saved.");
  130.         }
  131.            
  132.         $io->streamClose();
  133.     }
  134.    
  135.     public function isWriteable($file)
  136.     {
  137.         $io = new Varien_Io_File();
  138.         $io->open(array('path' => Mage::getBaseDir()));
  139.         return $io->isWriteable($file);
  140.     }
  141.    
  142.     public function exists($file)
  143.     {
  144.         $io = new Varien_Io_File();
  145.         $io->open(array('path' => Mage::getBaseDir()));
  146.         return $io->fileExists($file);
  147.     }
  148.    
  149.     public function robotstxt()
  150.     {
  151.         return 'robots.txt';
  152.     }
  153.    
  154.     public function htaccess()
  155.     {
  156.         return '.htaccess';
  157.     }
  158.    
  159.     public function checkDefaultStoreNames()
  160.     {
  161.         $stores = Mage::getModel('core/store')->getCollection();
  162.         foreach($stores as $store){
  163.             if($store->getName() == "Default Store View"){
  164.                 return false;
  165.             }
  166.         }
  167.         return true;
  168.     }
  169.    
  170.     public function checkDefaultStoreGroupNames()
  171.     {
  172.         $storegroups = Mage::getModel('core/store_group')->getCollection();
  173.         foreach($storegroups as $storegroup){
  174.             if($storegroup->getName() == "Main Store"){
  175.                 return false;
  176.             }
  177.         }
  178.         return true;
  179.     }
  180.    
  181.     public function checkDefaultWebsiteNames()
  182.     {
  183.         $websites = Mage::getModel('core/website')->getCollection();
  184.         foreach($websites as $website){
  185.             if($website->getName() == "Main Website"){
  186.                 return false;
  187.             }
  188.         }
  189.         return true;
  190.     }
  191.  
  192.     public function getProductStartingprice($product)
  193.     {
  194.         if($product->getTypeId() === 'bundle')
  195.         {
  196.             return Mage::getModel('bundle/product_price')->getTotalPrices($product,'min',1);
  197.         }
  198.  
  199.         return $product->getFinalPrice();
  200.     }
  201.  
  202. }
Add Comment
Please, Sign In to add comment